[Mulgara-svn] r510 - branches/nw-interface/src/jar/itql/java/org/mulgara/itql
pag at mulgara.org
pag at mulgara.org
Fri Nov 2 21:15:45 UTC 2007
Author: pag
Date: 2007-11-02 15:15:45 -0600 (Fri, 02 Nov 2007)
New Revision: 510
Modified:
branches/nw-interface/src/jar/itql/java/org/mulgara/itql/TqlAutoInterpreter.java
Log:
addressed the need to establish connections to local servers when there is no valid URI
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-02 21:14:52 UTC (rev 509)
+++ branches/nw-interface/src/jar/itql/java/org/mulgara/itql/TqlAutoInterpreter.java 2007-11-02 21:15:45 UTC (rev 510)
@@ -24,6 +24,7 @@
import org.mulgara.connection.DummyConnection;
import org.mulgara.parser.Interpreter;
import org.mulgara.query.Answer;
+import org.mulgara.query.Query;
import org.mulgara.query.QueryException;
import org.mulgara.query.operation.Command;
import org.mulgara.query.operation.LocalCommand;
@@ -107,7 +108,7 @@
// execute the operation
try {
// set up a connection, if required
- Connection conn = establishConnection(cmd.getServerURI());
+ Connection conn = establishConnection(cmd);
handleResult(cmd.execute(conn), cmd);
updateOnConnectionState(conn);
lastMessage = cmd.getResultMessage();
@@ -205,6 +206,26 @@
/**
+ * Returns a connection to a server for a given command.
+ * @param cmd The command to get a connection to execute on.
+ * @return A connection to the server, cached if available.
+ * @throws ConnectionException It was not possible to create a connection to the described server.
+ * @throws QueryException There is a transaction underway, but the new connection cannot turn off autocommit.
+ */
+ private Connection establishConnection(Command cmd) throws ConnectionException, QueryException {
+ URI serverUri = cmd.getServerURI();
+
+ if (serverUri == null && cmd.isLocalOperation()) {
+ // no server URI, but not local. Get a connection for a null URI
+ Connection connection = connectionFactory.newConnection(serverUri);
+ configureForTransaction(connection);
+ return connection;
+ }
+
+ return establishConnection(cmd.getServerURI());
+ }
+
+ /**
* Returns a connection to the server with the given URI.
* NB: Not for general use. Available to ItqlInterpreterBean only to support
* legacy requests to get a session.
@@ -215,13 +236,18 @@
*/
Connection establishConnection(URI serverUri) throws ConnectionException, QueryException {
Connection connection = (serverUri == null) ? localStateConnection : connectionFactory.newConnection(serverUri);
+ configureForTransaction(connection);
+ return connection;
+ }
+
+
+ private void configureForTransaction(Connection connection) throws QueryException {
// If in a transaction, turn off autocommit - ignore the dummy connection
if (inTransaction && connection.getAutoCommit() && connection != localStateConnection) {
connection.setAutoCommit(false);
assert !transConnections.contains(connection);
transConnections.add(connection);
}
- return connection;
}
More information about the Mulgara-svn
mailing list