[Mulgara-svn] r525 - branches/nw-interface/src/jar/query/java/org/mulgara/query/operation
pag at mulgara.org
pag at mulgara.org
Thu Nov 8 21:10:57 UTC 2007
Author: pag
Date: 2007-11-08 15:10:56 -0600 (Thu, 08 Nov 2007)
New Revision: 525
Added:
branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/TxOp.java
Modified:
branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Commit.java
branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Rollback.java
branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/SetAutoCommit.java
Log:
Created new interface for commands that affect transactions, and added methods relevant to TqlAutoInterpreter
Modified: branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Commit.java
===================================================================
--- branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Commit.java 2007-11-06 21:59:44 UTC (rev 524)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Commit.java 2007-11-08 21:10:56 UTC (rev 525)
@@ -13,20 +13,28 @@
package org.mulgara.query.operation;
+import java.util.Iterator;
+
import org.mulgara.connection.Connection;
import org.mulgara.query.QueryException;
import org.mulgara.server.Session;
/**
- * An AST element for the COMMIT command.
+ * An AST element for the COMMIT command. Not called directly for a TQL commit, as that
+ * would have to go to all open connections. Consequently, TqlAutoInterpreter handles
+ * commits through a different method to the standard call path, while the normal
+ * call will pass in a {@link org.mulgara.connection.DummyConnection}.
*
+ * After performing a commit, all connections are left in place {@link #cleanup(Iterator)} and
+ * the transaction is kept open {@link #stayInTx()}.
+ *
* @created 2007-08-09
* @author Paul Gearon
* @copyright © 2007 <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
* @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
*/
-public class Commit extends TransactionCommand implements Command {
+public class Commit extends TransactionCommand implements Command, TxOp {
/**
* Commits the transaction on a connection.
@@ -44,4 +52,20 @@
}
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public void cleanup(Iterator<?> it) {
+ /* no-op */
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean stayInTx() {
+ return true;
+ }
+
}
Modified: branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Rollback.java
===================================================================
--- branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Rollback.java 2007-11-06 21:59:44 UTC (rev 524)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Rollback.java 2007-11-08 21:10:56 UTC (rev 525)
@@ -13,19 +13,27 @@
package org.mulgara.query.operation;
+import java.util.Iterator;
+
import org.mulgara.connection.Connection;
import org.mulgara.query.QueryException;
/**
- * An AST element for the ROLLBACK command.
+ * An AST element for the ROLLBACK command. Not called directly for a TQL rollback, as
+ * that would have to go to all open connections. Consequently, TqlAutoInterpreter handles
+ * rollbacks through a different method to the standard call path, while the normal
+ * call will pass in a {@link org.mulgara.connection.DummyConnection}.
*
+ * After performing a rollback, all connections are removed {@link #cleanup(Iterator)} and
+ * the transaction is closed {@link #stayInTx()}.
+ *
* @created 2007-08-09
* @author Paul Gearon
* @copyright © 2007 <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
* @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
*/
-public class Rollback extends TransactionCommand implements Command {
+public class Rollback extends TransactionCommand implements Command, TxOp {
/**
* Commits the transaction on a connection.
@@ -34,7 +42,23 @@
*/
public Object execute(Connection conn) throws QueryException {
conn.getSession().rollback();
- return setResultMessage("Successfully committed transaction");
+ return setResultMessage("Successfully rolled back transaction");
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public void cleanup(Iterator<?> it) {
+ it.remove();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean stayInTx() {
+ return false;
+ }
+
}
Modified: branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/SetAutoCommit.java
===================================================================
--- branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/SetAutoCommit.java 2007-11-06 21:59:44 UTC (rev 524)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/SetAutoCommit.java 2007-11-08 21:10:56 UTC (rev 525)
@@ -11,16 +11,21 @@
*/
package org.mulgara.query.operation;
+import java.util.Iterator;
+
import org.mulgara.connection.Connection;
+import org.mulgara.query.QueryException;
/**
* Indicates a UI request to automatically commit after executing a write operation.
+ * {@link #isOn()} indicates that a transaction is being closed.
+ *
* @created Aug 17, 2007
* @author Paul Gearon
* @copyright © 2007 <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
* @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
*/
-public class SetAutoCommit extends BooleanSetCommand {
+public class SetAutoCommit extends BooleanSetCommand implements TxOp {
private static final String MESSAGE = "Auto commit is ";
@@ -32,10 +37,35 @@
super(option);
}
- public Object execute(Connection conn) throws Exception {
+
+ /**
+ * Set the autocommit state on a connection.
+ * @param conn The connection to set the state of.
+ * @return The resulting message text.
+ * @throws QueryException if unable to set the autocommit state.
+ */
+ public Object execute(Connection conn) throws QueryException {
boolean on = isOn();
if (conn != null) conn.setAutoCommit(on);
return setResultMessage(MESSAGE + (on ? ON : OFF));
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public void cleanup(Iterator<?> it) {
+ // if leaving a transaction, then remove the item.
+ if (isOn()) it.remove();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean stayInTx() {
+ // only stay in a transaction if autocommit is not on
+ return !isOn();
+ }
+
}
Added: branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/TxOp.java
===================================================================
--- branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/TxOp.java 2007-11-06 21:59:44 UTC (rev 524)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/TxOp.java 2007-11-08 21:10:56 UTC (rev 525)
@@ -0,0 +1,51 @@
+/**
+ * The contents of this file are subject to the Open Software License
+ * Version 3.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.opensource.org/licenses/osl-3.0.txt
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ */
+package org.mulgara.query.operation;
+
+import java.util.Iterator;
+
+import org.mulgara.connection.Connection;
+import org.mulgara.query.QueryException;
+
+/**
+ * This interface is for use by TqlAutoInterpreter for managing operations that
+ * operate on transactions in some way.
+ *
+ * @created Nov 8, 2007
+ * @author Paul Gearon
+ * @copyright © 2007 <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public interface TxOp {
+
+ /**
+ * Perform the operation for manipulating this transaction.
+ * @param s The session to perform the operation on.
+ * @return The resulting message.
+ * @throws QueryException The operation failed.
+ */
+ Object execute(Connection conn) throws QueryException;
+
+ /**
+ * This operation is to be performed on a collection of items. The cleanup method
+ * describes what to do with that item once the operation has completed.
+ * @param it the iterator item. Expect either a no-op or a {@link java.util.Iterator#remove()}.
+ */
+ void cleanup(Iterator<?> it);
+
+ /**
+ * Indicates if this operation should result in the transaction finishing or continuing.
+ * @return <code>true</code> if the transaction stays open, <code>false</code> if it closes.
+ */
+ boolean stayInTx();
+
+}
More information about the Mulgara-svn
mailing list