[Mulgara-svn] r407 - branches/nw-interface/src/jar/query/java/org/mulgara/query/operation

pag at mulgara.org pag at mulgara.org
Fri Sep 7 21:11:24 UTC 2007


Author: pag
Date: 2007-09-07 16:11:23 -0500 (Fri, 07 Sep 2007)
New Revision: 407

Modified:
   branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/ApplyRules.java
   branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Backup.java
   branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Commit.java
   branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/CreateGraph.java
   branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Deletion.java
   branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/DropGraph.java
   branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/ExecuteScript.java
   branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Insertion.java
Log:
Added some functionality from ItqlInterpreter

Modified: branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/ApplyRules.java
===================================================================
--- branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/ApplyRules.java	2007-09-07 02:14:03 UTC (rev 406)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/ApplyRules.java	2007-09-07 21:11:23 UTC (rev 407)
@@ -102,8 +102,7 @@
     RulesRef rules = ruleConn.getSession().buildRules(ruleGraph, baseGraph, destGraph);
     // create apply the rules to the model
     conn.getSession().applyRules(rules);
-    resultMessage = "Successfully applied " + ruleGraph + " to " + baseGraph + (destGraph == baseGraph ? "" : " => " + destGraph);
-    return resultMessage;
+    return resultMessage = "Successfully applied " + ruleGraph + " to " + baseGraph + (destGraph == baseGraph ? "" : " => " + destGraph);
   }
 
 }

Modified: branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Backup.java
===================================================================
--- branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Backup.java	2007-09-07 02:14:03 UTC (rev 406)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Backup.java	2007-09-07 21:11:23 UTC (rev 407)
@@ -85,8 +85,7 @@
 
     backup(conn, serverUri, fileOutputStream);
 
-    resultMessage = "Successfully backed up: " + serverUri;
-    return resultMessage;
+    return resultMessage = "Successfully backed up: " + serverUri;
   }
 
 

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-09-07 02:14:03 UTC (rev 406)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Commit.java	2007-09-07 21:11:23 UTC (rev 407)
@@ -34,8 +34,7 @@
    */
   public Object execute(Connection conn) throws QueryException {
     conn.getSession().commit();
-    resultMessage = "Successfully committed transaction";
-    return resultMessage;
+    return resultMessage = "Successfully committed transaction";
   }
 
 }

Modified: branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/CreateGraph.java
===================================================================
--- branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/CreateGraph.java	2007-09-07 02:14:03 UTC (rev 406)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/CreateGraph.java	2007-09-07 21:11:23 UTC (rev 407)
@@ -15,7 +15,6 @@
 
 import org.apache.log4j.Logger;
 import org.mulgara.connection.Connection;
-import org.mulgara.itql.ItqlInterpreter;
 
 /**
  * Represents a command to create a new graph.
@@ -32,9 +31,6 @@
   /** The URI for the graph. */
   private URI graphUri;
   
-  /** The canonical URI for the graph. */
-  private URI canonicalGraphUri;
-  
   /** The URI for the type of the graph. */
   private URI type;
   
@@ -42,7 +38,6 @@
     super(graphUri);
     this.graphUri = graphUri;
     this.type = type;
-    canonicalGraphUri = getCanonicalUriAlias(graphUri);
   }
   
   /**
@@ -63,14 +58,8 @@
 
   public Object execute(Connection conn) throws Exception {
     if (logger.isDebugEnabled()) logger.debug("Creating new model " + graphUri);
-    if (logger.isDebugEnabled()) logger.debug("Model is alias for " + canonicalGraphUri);
-    // TODO: this is not yet complete
-    conn.getSession().createModel(canonicalGraphUri, type);
-    return null;
+    conn.getSession().createModel(graphUri, type);
+    return resultMessage = "Successfully created model " + graphUri;
   }
 
-  // TODO: get from ItqlInterpreter
-  private URI getCanonicalUriAlias(URI uri) {
-    return uri;
-  }
 }

Modified: branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Deletion.java
===================================================================
--- branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Deletion.java	2007-09-07 02:14:03 UTC (rev 406)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Deletion.java	2007-09-07 21:11:23 UTC (rev 407)
@@ -48,7 +48,7 @@
   public Object execute(Connection conn) throws Exception {
     if (isSelectBased()) conn.getSession().delete(graph, getSelectQuery());
     else conn.getSession().delete(graph, getStatements());
-    return null;
+    return resultMessage = "Successfully deleted statements from: " + graph;
   }
 
 }

Modified: branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/DropGraph.java
===================================================================
--- branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/DropGraph.java	2007-09-07 02:14:03 UTC (rev 406)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/DropGraph.java	2007-09-07 21:11:23 UTC (rev 407)
@@ -41,8 +41,8 @@
   }
 
   public Object execute(Connection conn) throws Exception {
-    // TODO Auto-generated method stub
-    return null;
+    conn.getSession().removeModel(graphUri);
+    return resultMessage = "Successfully dropped model " + graphUri;
   }
 
 }

Modified: branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/ExecuteScript.java
===================================================================
--- branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/ExecuteScript.java	2007-09-07 02:14:03 UTC (rev 406)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/ExecuteScript.java	2007-09-07 21:11:23 UTC (rev 407)
@@ -11,9 +11,15 @@
  */
 package org.mulgara.query.operation;
 
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
 import java.net.URL;
 
+import org.apache.log4j.Logger;
 import org.mulgara.connection.Connection;
+import org.mulgara.itql.lexer.LexerException;
+import org.mulgara.parser.Interpreter;
+import org.mulgara.parser.MulgaraParserException;
 
 /**
  * An AST element for running an external script.
@@ -24,15 +30,23 @@
  */
 public class ExecuteScript extends LocalCommand {
 
+  /** The logger */
+  static final Logger logger = Logger.getLogger(ExecuteScript.class.getName());
+
   /** The script to be executed. */
   private URL script;
   
+  /** The interpreter for the script. */
+  Interpreter interpreter;
+  
+  
   /**
    * Creates a script execution command.
    * @param script The script to execute.
    */
-  public ExecuteScript(URL script) {
+  public ExecuteScript(URL script, Interpreter interpreter) {
     this.script = script;
+    this.interpreter = interpreter;
   }
 
   /**
@@ -51,8 +65,33 @@
   }
 
   public Object execute(Connection conn) throws Exception {
-    // TODO Auto-generated method stub
-    return null;
+    // create a buffer to hold the results in
+    StringBuffer resultsMsg = new StringBuffer();
+
+    // create a reader to read the contents of the script
+    BufferedReader scriptIn = new BufferedReader(new InputStreamReader(script.openStream()));
+
+    // execute the script!
+    int line = 0;
+    try {
+      String commandLine;
+      while (null != (commandLine = scriptIn.readLine())) {
+        line++;
+        if (!commandLine.equals("")) {
+          resultsMsg.append(interpreter.parseCommand(commandLine).execute(conn));
+        }
+      }
+      resultsMsg.append("Completed execution of script " + script);
+      resultMessage = resultsMsg.toString();
+    } catch (MulgaraParserException pe) {
+      resultMessage = "Syntax error in script (line " + line + "): " + pe.getMessage();
+      logger.warn("Unable to execute script - " + script + "\n" + pe.getMessage());
+    } catch (LexerException le) {
+      resultMessage = "Syntax error in script (line " + line + "): " + le.getMessage();
+      logger.warn("Unable to execute script - " + script + "\n" + le.getMessage());
+    }
+
+    return resultMessage;
   }
 
 }

Modified: branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Insertion.java
===================================================================
--- branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Insertion.java	2007-09-07 02:14:03 UTC (rev 406)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Insertion.java	2007-09-07 21:11:23 UTC (rev 407)
@@ -48,7 +48,7 @@
   public Object execute(Connection conn) throws Exception {
     if (isSelectBased()) conn.getSession().insert(graph, getSelectQuery());
     else conn.getSession().insert(graph, getStatements());
-    return null;
+    return resultMessage = "Successfully inserted statements into: " + graph;
   }
 
 }




More information about the Mulgara-svn mailing list