 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
kei Guest
|
Posted: Fri May 19, 2006 7:15 am Post subject: how to save several dataset in a transaction |
|
|
suppose there is two dataset (one header and one detail), I want to save these two datasets in a transaction so that if any dataset can apply the update to the SQL server, then rollback all changes in both dataset, how can I do this (is there any code sample)?
I have seen there is savechange(dataset[], boolean,boolean,boolean), is this method help to save all dataset in one transaction and can commit or rollback all?
thx!! |
|
| Back to top |
|
 |
kei Guest
|
Posted: Fri May 19, 2006 9:15 am Post subject: Re: how to save several dataset in a transaction |
|
|
I try to use the follow method:
Database.setAutoCommit(false);
try{
// some change made on ds;
database.saveChanges(ds);
throw new Exception("test rollback()");
database..commit();
}
catch(Exception ex){
Database.rollback();
}
finally{
Database.setAutoCommit(true);
}
but I find that even I set autocommit to false, when database.savechanges(ds) is called, the change is already written to database (I check using SQL analyzer), and even there is exception and rollback() is run, the record has not really rollback(), so the change is still written to the database table, why??
Thx!!
"kei" <kei (AT) oxl (DOT) com> wrote:
| Quote: |
suppose there is two dataset (one header and one detail), I want to save these two datasets in a transaction so that if any dataset can apply the update to the SQL server, then rollback all changes in both dataset, how can I do this (is there any code sample)?
I have seen there is savechange(dataset[], boolean,boolean,boolean), is this method help to save all dataset in one transaction and can commit or rollback all?
thx!! |
|
|
| Back to top |
|
 |
kei Guest
|
Posted: Fri May 19, 2006 11:15 am Post subject: Re: how to save several dataset in a transaction |
|
|
I have try to change the savechanges method as follows:
database.saveChanges(ds, false); // use false parameter
now the database can rollback, but an error " DataSet has no unique row identifiers. " is prompted, why?
"kei" <kei (AT) oxl (DOT) com> wrote:
| Quote: |
I try to use the follow method:
Database.setAutoCommit(false);
try{
// some change made on ds;
database.saveChanges(ds);
throw new Exception("test rollback()");
database..commit();
}
catch(Exception ex){
Database.rollback();
}
finally{
Database.setAutoCommit(true);
}
but I find that even I set autocommit to false, when database.savechanges(ds) is called, the change is already written to database (I check using SQL analyzer), and even there is exception and rollback() is run, the record has not really rollback(), so the change is still written to the database table, why??
Thx!!
"kei" <kei (AT) oxl (DOT) com> wrote:
suppose there is two dataset (one header and one detail), I want to save these two datasets in a transaction so that if any dataset can apply the update to the SQL server, then rollback all changes in both dataset, how can I do this (is there any code sample)?
I have seen there is savechange(dataset[], boolean,boolean,boolean), is this method help to save all dataset in one transaction and can commit or rollback all?
thx!!
|
|
|
| Back to top |
|
 |
kei Guest
|
Posted: Sat May 20, 2006 6:14 am Post subject: Re: how to save several dataset in a transaction |
|
|
anyone willing to help?
"kei" <kei (AT) oxl (DOT) com> wrote in message
news:446d9d4c$1 (AT) newsgroups (DOT) borland.com...
| Quote: |
I have try to change the savechanges method as follows:
database.saveChanges(ds, false); // use false parameter
now the database can rollback, but an error " DataSet has no unique row
identifiers. " is prompted, why?
"kei" <kei (AT) oxl (DOT) com> wrote:
I try to use the follow method:
Database.setAutoCommit(false);
try{
// some change made on ds;
database.saveChanges(ds);
throw new Exception("test rollback()");
database..commit();
}
catch(Exception ex){
Database.rollback();
}
finally{
Database.setAutoCommit(true);
}
but I find that even I set autocommit to false, when
database.savechanges(ds) is called, the change is already written to
database (I check using SQL analyzer), and even there is exception and
rollback() is run, the record has not really rollback(), so the change is
still written to the database table, why??
Thx!!
"kei" <kei (AT) oxl (DOT) com> wrote:
suppose there is two dataset (one header and one detail), I want to save
these two datasets in a transaction so that if any dataset can apply the
update to the SQL server, then rollback all changes in both dataset, how
can I do this (is there any code sample)?
I have seen there is savechange(dataset[], boolean,boolean,boolean), is
this method help to save all dataset in one transaction and can commit or
rollback all?
thx!!
|
|
|
| Back to top |
|
 |
John Moore (TeamB) Guest
|
Posted: Mon May 22, 2006 7:16 pm Post subject: Re: how to save several dataset in a transaction |
|
|
kei wrote:
| Quote: | I have try to change the savechanges method as follows:
database.saveChanges(ds, false); // use false parameter
now the database can rollback, but an error " DataSet has no unique row identifiers. " is prompted, why?
|
Not seeing your SQL it is hard to provide a specific answer.. Generally
this is caused by having a JOIN in the SQL such that DataExpress can not
reliably determine which fields are the "key" fields.. (Since the meta
data for a JOIN does not return this info.. I'm assuming..)
Following is an example of the various things you might need to do to
solve this..
// A query with a join..
StringBuffer _sb = new StringBuffer();
_sb.append("SELECT DISTINCT
S.INVOICE_NO,S.PLANT_ID,S.SEQ,S.DISCOUNT_CODE,");
_sb.append("S.DATE_SOLD,S.QUANTITY_SOLD,S.BASE_PRICE,S.EXTENSION,");
_sb.append("S.POSTED,S.LOADUNIT,S.EXTLOAD,S.CHOICECODE,S.LINEDISC,");
_sb.append("S.SKU,MIV.CATEGORY_NO,MIV.COMMON_NAME, MIV.DISPLAY_SORT ");
_sb.append("FROM SALES S JOIN MASTERINV MIV ON S.PLANT_ID =
MIV.PLANT_ID ");
_sb.append("WHERE S.INVOICE_NO = "+(new
Double(arg_dInvNo)).intValue());
_sb.append(" ORDER BY MIV.DISPLAY_SORT");
//Using the above query as an example the following MIGHT be required.
// Your milage may vary..
QueryDataSet _qds = (QueryDataSet)this.getData(_sb.toString());
// set the table name that you intend to update
_qds.setTableName("SALES");
// set the row IDs
_qds.setRowId("INVOICE_NO", true);
_qds.setRowId("PLANT_ID", true);
_qds.setRowId("SEQ", true);
// set which fields came from the join and should be ignored on an update
_qds.getColumn("COMMON_NAME").setResolvable(false);
_qds.getColumn("CATEGORY_NO").setResolvable(false);
_qds.getColumn("DISPLAY_SORT").setResolvable(false);
// optional sort..
_qds.setSort(new SortDescriptor(new String[] {"DISPLAY_SORT"}
, true, false));
--
=============================================
TeamB are volunteer helpers. Please DO NOT REPLY VIA EMAIL!
Post all questions and replies to this newsgroup ONLY
For papers on DataExpress, Applets, JSP, and Web Development go to:
http://www.microps.com/mps/paperFAQ.html
==================================================== |
|
| Back to top |
|
 |
John Moore (TeamB) Guest
|
Posted: Mon May 22, 2006 8:15 pm Post subject: Re: how to save several dataset in a transaction |
|
|
kei wrote:
| Quote: |
but I find that even I set autocommit to false, when database.savechanges(ds) is called, the change is already written to database (I check using SQL analyzer), and even there is exception and rollback() is run, the record has not really rollback(), so the change is still written to the database table, why??
Thx!!
|
try..
public final void saveChanges(DataSet[] dataSets,
boolean doTransactions,
boolean postEdits,
boolean resetPendingStatus)
Parameters:
dataSets - Array of dataSets to save changes for.
doTransactions - true: All changes will be in 1 transaction. (default)
false: No transactions calls will be made.
postEdits - true: All edits are posted before changes are saved.
(default) false: No edits are saved.
--
=============================================
TeamB are volunteer helpers. Please DO NOT REPLY VIA EMAIL!
Post all questions and replies to this newsgroup ONLY
For papers on DataExpress, Applets, JSP, and Web Development go to:
http://www.microps.com/mps/paperFAQ.html
==================================================== |
|
| Back to top |
|
 |
kei Guest
|
Posted: Wed May 24, 2006 2:15 am Post subject: Re: how to save several dataset in a transaction |
|
|
"John Moore (TeamB)" <jbm (AT) microps (DOT) com> wrote:
| Quote: | kei wrote:
but I find that even I set autocommit to false, when database.savechanges(ds) is called, the change is already written to database (I check using SQL analyzer), and even there is exception and rollback() is run, the record has not really rollback(), so the change is still written to the database table, why??
Thx!!
try..
public final void saveChanges(DataSet[] dataSets,
boolean doTransactions,
boolean postEdits,
boolean resetPendingStatus)
Parameters:
dataSets - Array of dataSets to save changes for.
doTransactions - true: All changes will be in 1 transaction. (default)
false: No transactions calls will be made.
postEdits - true: All edits are posted before changes are saved.
(default) false: No edits are saved.
yes, now I use saveChanges(DataSet[] dataSets, |
boolean doTransactions) and set the doTransactions to false, then the transaction can rollback(), just feel strange why I need to set the doTransactions paramters to false!! (from the help manual, false means No transactions calls will be made, but for using transaction,it seems that the paramter must be set to false!!) |
|
| Back to top |
|
 |
kei Guest
|
Posted: Wed May 24, 2006 3:15 am Post subject: Re: how to save several dataset in a transaction |
|
|
"John Moore (TeamB)" <jbm (AT) microps (DOT) com> wrote:
| Quote: | Not seeing your SQL it is hard to provide a specific answer.. Generally
this is caused by having a JOIN in the SQL such that DataExpress can not
reliably determine which fields are the "key" fields.. (Since the meta
data for a JOIN does not return this info.. I'm assuming..)
|
my SQL is only retrieve one table, no join, anyway,I can fix it now by
dsDetail.setMetaDataUpdate(MetaDataUpdate.NONE);
and then set a column rowID to true.
Thx!! |
|
| Back to top |
|
 |
John Moore (TeamB) Guest
|
Posted: Thu May 25, 2006 7:15 pm Post subject: Re: how to save several dataset in a transaction |
|
|
kei wrote:
| Quote: | "John Moore (TeamB)" <jbm (AT) microps (DOT) com> wrote:
yes, now I use saveChanges(DataSet[] dataSets,
boolean doTransactions) and set the doTransactions to false, then the transaction can rollback(), just feel strange why I need to set the doTransactions paramters to false!! (from the help manual, false means No transactions calls will be made, but for using transaction,it seems that the paramter must be set to false!!)
|
What it means is that that call to "saveChanges" WILL NOT commit the
transaction. You have told it you will handle it MANUALLY..
John..
--
=============================================
TeamB are volunteer helpers. Please DO NOT REPLY VIA EMAIL!
Post all questions and replies to this newsgroup ONLY
For papers on DataExpress, Applets, JSP, and Web Development go to:
http://www.microps.com/mps/paperFAQ.html
==================================================== |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|