[Mulgara-svn] r534 - branches/nw-interface/src/jar/itql/java/org/mulgara/itql
pag at mulgara.org
pag at mulgara.org
Tue Nov 13 22:08:40 UTC 2007
Author: pag
Date: 2007-11-13 16:08:39 -0600 (Tue, 13 Nov 2007)
New Revision: 534
Modified:
branches/nw-interface/src/jar/itql/java/org/mulgara/itql/TqlAutoInterpreter.java
Log:
Fixed up handling of transaction commands. Was doing different things for different commands, but now they are all handled consistently.
Modified: branches/nw-interface/src/jar/itql/java/org/mulgara/itql/TqlAutoInterpreter.java
===================================================================
--- branches/nw-interface/src/jar/itql/java/org/mulgara/itql/TqlAutoInterpreter.java 2007-11-13 22:02:27 UTC (rev 533)
+++ branches/nw-interface/src/jar/itql/java/org/mulgara/itql/TqlAutoInterpreter.java 2007-11-13 22:08:39 UTC (rev 534)
@@ -334,21 +334,20 @@
* @throws QueryException Can be caused by a failed change into a transaction.
*/
void updateConnectionsForTx(Connection conn, Command cmd) throws QueryException {
- // check if the transaction state changed. This will happen for setAutocommit operations.
- if (inTransaction == conn.getAutoCommit()) {
- assert cmd instanceof org.mulgara.query.operation.SetAutoCommit: "Got a state change on " + cmd.getClass() + " instead of SetAutoCommit";
- // update the client state
- inTransaction = !conn.getAutoCommit();
- if (inTransaction) {
- // Started a transaction. All connection changes set this state on the new connection.
- assert transConnections.isEmpty();
- } else {
- handleTxOp((TxOp)cmd);
- assert transConnections.isEmpty();
- }
- } else if (cmd.isTxOperation()) {
- // this is a commit or rollback. Inform every connection we've used in this transaction.
+ // check if the transaction state changed on a setAutocommit operations, or if the command is a Tx operation
+ if (inTransaction == conn.getAutoCommit() || cmd.isTxCommitRollback()) {
+ // check that transaction changes came from setAutoCommit commands
+ assert inTransaction != conn.getAutoCommit() || cmd instanceof org.mulgara.query.operation.SetAutoCommit: "Got a state change on " + cmd.getClass() + " instead of SetAutoCommit";
+ // check that if we are starting a transaction then the transConnections list is empty
+ assert conn.getAutoCommit() || transConnections.isEmpty();
+ // save the number of active connections
+ int activeConnections = transConnections.size();
+ // handle the transaction operation
handleTxOp((TxOp)cmd);
+ // check that if we have left a transaction, then the connection list is empty
+ assert inTransaction || transConnections.isEmpty();
+ // check that if we are still in a transaction, then the connection list has not changed
+ assert !inTransaction || activeConnections == transConnections.size();
}
}
@@ -365,26 +364,24 @@
QueryException qe = null;
String errorMessage = null;
- if (inTransaction) {
- // Operate on all outstanding transactions.
- Iterator<Connection> c = transConnections.iterator();
- while (c.hasNext()) {
- try {
- // do the work
- op.execute(c.next());
- } catch (QueryException e) {
- // store the details of the first exception only
- if (qe != null) logger.error("Discarding subsequent exception during operation: " + op.getClass().getSimpleName(), e);
- else {
- qe = e;
- errorMessage = op.getResultMessage();
- }
+ // Operate on all outstanding transactions.
+ Iterator<Connection> c = transConnections.iterator();
+ while (c.hasNext()) {
+ try {
+ // do the work
+ op.execute(c.next());
+ } catch (QueryException e) {
+ // store the details of the first exception only
+ if (qe != null) logger.error("Discarding subsequent exception during operation: " + op.getClass().getSimpleName(), e);
+ else {
+ qe = e;
+ errorMessage = op.getResultMessage();
}
}
- // will only get here once all connections were processed.
- inTransaction = op.stayInTx();
- if (!inTransaction) transConnections.clear();
}
+ // will only get here once all connections were processed.
+ inTransaction = op.stayInTx();
+ if (!inTransaction) transConnections.clear();
// if an exception was recorded, then throw it
if (qe != null) {
More information about the Mulgara-svn
mailing list