[Mulgara-svn] r444 - branches/nw-interface/src/jar/itql/java/org/mulgara/itql

pag at mulgara.org pag at mulgara.org
Wed Sep 19 20:37:02 UTC 2007


Author: pag
Date: 2007-09-19 15:37:00 -0500 (Wed, 19 Sep 2007)
New Revision: 444

Modified:
   branches/nw-interface/src/jar/itql/java/org/mulgara/itql/TqlAutoInterpreter.java
Log:
Now establishing connections

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-09-19 10:30:55 UTC (rev 443)
+++ branches/nw-interface/src/jar/itql/java/org/mulgara/itql/TqlAutoInterpreter.java	2007-09-19 20:37:00 UTC (rev 444)
@@ -17,6 +17,7 @@
 
 import org.apache.log4j.Logger;
 import org.mulgara.connection.Connection;
+import org.mulgara.connection.ConnectionException;
 import org.mulgara.parser.Interpreter;
 import org.mulgara.query.Answer;
 import org.mulgara.query.QueryException;
@@ -36,17 +37,25 @@
   /** The logger. */
   private final static Logger logger = Logger.getLogger(TqlAutoInterpreter.class.getName());
 
+  /** The parser and AST builder for commands. */
   private Interpreter interpreter = new TqlInterpreter();
 
+  /** A user readable message resulting from the most recent command. */
   private String lastMessage;
-  
+
+  /** The most answer returned from the most recent command, if it was a query. */
   private Answer lastAnswer;
-  
+
+  /** The most recent exception, if there was one. */
   private Exception lastException;
-  
+
+  /** Cached connections to servers. Duplicates may exist if more than one URI is used to refer to the same server. */
   private Map<URI,Connection> establishedConnections = new HashMap<URI,Connection>();
   
-  
+
+  /**
+   * Creates a new autointerpreter with no prior connections.
+   */
   public TqlAutoInterpreter() {
     resetState();
   }
@@ -69,14 +78,10 @@
       lastException = e;
     }
 
-    // set up a connection, if required
-    Connection conn = null;
-    if (!cmd.isLocalOperation()) {
-      conn = establishConnection(cmd.getServerURI());
-    }
-
     // execute the operation
     try {
+      // set up a connection, if required
+      Connection conn = cmd.isLocalOperation() ? null : establishConnection(cmd.getServerURI());
       cmd.execute(conn);
       lastMessage = cmd.getResultMessage();
     } catch (Exception e) {
@@ -123,13 +128,19 @@
   }
 
 
-  private Connection establishConnection(URI serverUri) {
+  /**
+   * Returns a connection to the server with the given URI.
+   * @param serverUri The URI for the server to get a connection to.
+   * @return A connection to the server, cached if available.
+   * @throws ConnectionException It was not possible to create a connection to the described server.
+   */
+  private Connection establishConnection(URI serverUri) throws ConnectionException {
     if (serverUri == null) throw new IllegalArgumentException("Server URI may not be null.");
     Connection connection = establishedConnections.get(serverUri);
     if (connection == null) {
-      // RMI here
+      connection = new Connection(serverUri);
+      establishedConnections.put(serverUri, connection);
     }
-    
     return connection;
   }
 }




More information about the Mulgara-svn mailing list