[Mulgara-svn] r636 - trunk/src/jar/itql/java/org/mulgara/itql

ronald at mulgara.org ronald at mulgara.org
Mon Feb 11 07:36:08 UTC 2008


Author: ronald
Date: 2008-02-10 23:36:07 -0800 (Sun, 10 Feb 2008)
New Revision: 636

Modified:
   trunk/src/jar/itql/java/org/mulgara/itql/ItqlInterpreterBean.java
   trunk/src/jar/itql/java/org/mulgara/itql/ItqlInterpreterBeanUnitTest.java
Log:
Fix legacy-session use: don't invoke setAutoCommit, commit, or rollback on
the legacy-session, but let the interpreter object and its connections take
care of that. Otherwise, if the legacy-session is local: then the operations
will be done twice on the same session leading to errors on commit and
rollback; if the legacy-session is rmi: then the app will hang on the first
server-operation because interpreter uses a separate session from the
legacy-session and hence the setAutoCommit(false) will block.

There is still a problem in that the legacy-session will only be used properly
if it's a local: session, because if it's an rmi: session then the
legacy-session will get cached in the connection-factory without an associated
server-uri but the server-commands will look up the session by the uri and
hence will get a new session.


Modified: trunk/src/jar/itql/java/org/mulgara/itql/ItqlInterpreterBean.java
===================================================================
--- trunk/src/jar/itql/java/org/mulgara/itql/ItqlInterpreterBean.java	2008-02-11 07:25:02 UTC (rev 635)
+++ trunk/src/jar/itql/java/org/mulgara/itql/ItqlInterpreterBean.java	2008-02-11 07:36:07 UTC (rev 636)
@@ -278,7 +278,6 @@
 
     if (log.isDebugEnabled()) log.debug("Begin transaction for :" + name);
 
-    if (legacySession != null) legacySession.setAutoCommit(false);
     SetAutoCommit autocommitCmd = new SetAutoCommit(false);
     try {
       // do what the autointerpreter does, but don't worry about the result
@@ -303,8 +302,6 @@
 
     if (log.isDebugEnabled()) log.debug("Commit transaction for :" + name);
 
-    // this is the same as a commit call
-    if (legacySession != null) legacySession.setAutoCommit(true);
     interpreter.commitAll();
   }
 
@@ -320,10 +317,6 @@
 
     log.warn("Rollback transaction for :" + name);
 
-    if (legacySession != null) {
-      legacySession.rollback();
-      legacySession.setAutoCommit(true);
-    }
     interpreter.rollbackAll();
   }
 

Modified: trunk/src/jar/itql/java/org/mulgara/itql/ItqlInterpreterBeanUnitTest.java
===================================================================
--- trunk/src/jar/itql/java/org/mulgara/itql/ItqlInterpreterBeanUnitTest.java	2008-02-11 07:25:02 UTC (rev 635)
+++ trunk/src/jar/itql/java/org/mulgara/itql/ItqlInterpreterBeanUnitTest.java	2008-02-11 07:36:07 UTC (rev 636)
@@ -29,6 +29,8 @@
 
 import org.mulgara.query.Answer;
 import org.mulgara.query.QueryException;
+import org.mulgara.server.SessionFactory;
+import org.mulgara.server.driver.SessionFactoryFinder;
 import org.mulgara.util.TempDir;
 
 // third party packages
@@ -159,6 +161,7 @@
     suite.addTest(new ItqlInterpreterBeanUnitTest("testRestoreApi1"));
     suite.addTest(new ItqlInterpreterBeanUnitTest("testRoundTrip1"));
     suite.addTest(new ItqlInterpreterBeanUnitTest("testMultipleBeanTest"));
+    suite.addTest(new ItqlInterpreterBeanUnitTest("testExplicitSession"));
 
     return suite;
   }
@@ -825,6 +828,76 @@
      */
   }
 
+  /**
+   * Test giving ItqlInterpreterBean an explicit session.
+   *
+   * @throws Exception if the test fails
+   */
+  public void testExplicitSession() throws Exception {
+
+    // log that we're executing the test
+    log.debug("Starting explicit session test");
+
+    URI serverURI = new URI("rmi://" + hostName + "/server1");
+    SessionFactory sessionFactory =
+                      SessionFactoryFinder.newSessionFactory(serverURI, true);
+
+    bean.close();
+    bean = new ItqlInterpreterBean(sessionFactory.newSession(),
+                                   sessionFactory.getSecurityDomain());
+
+    // auto-commit = true
+    bean.executeQuery(
+        "insert <es:foo1> <es:bar1> 'foo' into <" + testModel + ">;");
+
+    Answer answer = bean.executeQuery(
+        "select $p $o from <" + testModel + "> " + "where <es:foo1> $p $o;");
+    assertEquals("Expecting a single result", 1, answer.getRowCount());
+
+    bean.executeQuery(
+        "delete <es:foo1> <es:bar1> 'foo' from <" + testModel + ">;");
+
+    answer = bean.executeQuery(
+        "select $p $o from <" + testModel + "> " + "where <es:foo1> $p $o;");
+    assertEquals("Expecting no results", 0, answer.getRowCount());
+
+    // explicit tx with commit
+    bean.beginTransaction("explicit-session-test-commit");
+
+    bean.executeQuery(
+        "insert <es:foo1> <es:bar1> 'foo' into <" + testModel + ">;");
+
+    answer = bean.executeQuery(
+        "select $p $o from <" + testModel + "> " + "where <es:foo1> $p $o;");
+    assertEquals("Expecting a single result", 1, answer.getRowCount());
+
+    bean.executeQuery(
+        "delete <es:foo1> <es:bar1> 'foo' from <" + testModel + ">;");
+
+    bean.commit("explicit-session-test-commit");
+
+    answer = bean.executeQuery(
+        "select $p $o from <" + testModel + "> " + "where <es:foo1> $p $o;");
+    assertEquals("Expecting no results", 0, answer.getRowCount());
+
+    // explicit tx with rollback
+    bean.beginTransaction("explicit-session-test-rollback");
+
+    bean.executeQuery(
+        "insert <es:foo1> <es:bar1> 'foo' into <" + testModel + ">;");
+
+    answer = bean.executeQuery(
+        "select $p $o from <" + testModel + "> " + "where <es:foo1> $p $o;");
+    assertEquals("Expecting a single result", 1, answer.getRowCount());
+
+    bean.rollback("explicit-session-test-rollback");
+
+    answer = bean.executeQuery(
+        "select $p $o from <" + testModel + "> " + "where <es:foo1> $p $o;");
+    assertEquals("Expecting no results", 0, answer.getRowCount());
+  }
+
+
   // ItqlInt
 
   /**




More information about the Mulgara-svn mailing list