[Mulgara-svn] r416 - branches/nw-interface/src/jar/query/java/org/mulgara/query/operation
pag at mulgara.org
pag at mulgara.org
Tue Sep 11 04:14:54 UTC 2007
Author: pag
Date: 2007-09-10 23:14:54 -0500 (Mon, 10 Sep 2007)
New Revision: 416
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/BooleanSetCommand.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/DataTx.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/Help.java
branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Insertion.java
branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Load.java
branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/LocalCommand.java
branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Quit.java
branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Restore.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/ServerCommand.java
branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/SetAutoCommit.java
branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/SetTime.java
branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/SetUser.java
branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/TransactionCommand.java
Log:
First implementation. Still needs to be called, so some restrucuring of the interfaces may be needed. Backup still needs refactoring with respect to the classes for Load/Restore
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-10 15:03:41 UTC (rev 415)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/ApplyRules.java 2007-09-11 04:14:54 UTC (rev 416)
@@ -102,7 +102,7 @@
RulesRef rules = ruleConn.getSession().buildRules(ruleGraph, baseGraph, destGraph);
// create apply the rules to the model
conn.getSession().applyRules(rules);
- return resultMessage = "Successfully applied " + ruleGraph + " to " + baseGraph + (destGraph == baseGraph ? "" : " => " + destGraph);
+ return setResultMessage("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-10 15:03:41 UTC (rev 415)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Backup.java 2007-09-11 04:14:54 UTC (rev 416)
@@ -14,6 +14,7 @@
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URI;
@@ -54,7 +55,7 @@
* Only file URLs supported at the moment.
*/
public Backup(URI source, URI destination) {
- super(source, destination);
+ super(source, destination, false);
if (!destination.getScheme().equals(FILE)) throw new IllegalArgumentException("Backups must be sent to a file");
calcServerUri(source);
}
@@ -70,7 +71,7 @@
/**
* Perform a backup on a server.
* @param conn The connection to talk to the server on.
- * @return Nothing.
+ * @return The text describing the server that was backed up.
* @throws QueryException There was an error asking the server to perform the backup.
* @throws MalformedURLException The destination is not a valid file.
*/
@@ -85,7 +86,7 @@
backup(conn, serverUri, fileOutputStream);
- return resultMessage = "Successfully backed up: " + serverUri;
+ return setResultMessage("Successfully backed up: " + serverUri);
}
@@ -131,6 +132,15 @@
/**
+ * Perform the transfer with the configured datastream.
+ * @return The number of statements affected, or <code>null</code> if this is not relevant.
+ */
+ protected Long doTx(Connection conn, InputStream inputStream) throws QueryException {
+ // TODO: Attempt to factor out any common so that this becomes a call to Session.backup.
+ return null;
+ }
+
+ /**
* Sets the server URI for this server operation.
* @param uri The URI to determine the server URI from.
*/
Modified: branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/BooleanSetCommand.java
===================================================================
--- branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/BooleanSetCommand.java 2007-09-10 15:03:41 UTC (rev 415)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/BooleanSetCommand.java 2007-09-11 04:14:54 UTC (rev 416)
@@ -20,6 +20,9 @@
*/
public abstract class BooleanSetCommand extends SetCommand {
+ protected static final String ON = "on";
+ protected static final String OFF = "off";
+
/** Indicates that option has been set on or off. */
private boolean on;
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-10 15:03:41 UTC (rev 415)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Commit.java 2007-09-11 04:14:54 UTC (rev 416)
@@ -34,7 +34,7 @@
*/
public Object execute(Connection conn) throws QueryException {
conn.getSession().commit();
- return resultMessage = "Successfully committed transaction";
+ return setResultMessage("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-10 15:03:41 UTC (rev 415)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/CreateGraph.java 2007-09-11 04:14:54 UTC (rev 416)
@@ -56,10 +56,15 @@
return type;
}
+ /**
+ * Perform the action of creating the graph.
+ * @param The connection to a session to create the graph in.
+ * @return Text describing the outcome.
+ */
public Object execute(Connection conn) throws Exception {
if (logger.isDebugEnabled()) logger.debug("Creating new model " + graphUri);
conn.getSession().createModel(graphUri, type);
- return resultMessage = "Successfully created model " + graphUri;
+ return setResultMessage("Successfully created model " + graphUri);
}
}
Modified: branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/DataTx.java
===================================================================
--- branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/DataTx.java 2007-09-10 15:03:41 UTC (rev 415)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/DataTx.java 2007-09-11 04:14:54 UTC (rev 416)
@@ -11,8 +11,22 @@
*/
package org.mulgara.query.operation;
+import java.io.IOException;
+import java.io.InputStream;
import java.net.URI;
+import java.net.URL;
+import java.rmi.NoSuchObjectException;
+import java.rmi.server.UnicastRemoteObject;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.ZipInputStream;
+import org.apache.log4j.Logger;
+import org.mulgara.connection.Connection;
+import org.mulgara.query.QueryException;
+
+import edu.emory.mathcs.util.remote.io.RemoteInputStream;
+import edu.emory.mathcs.util.remote.io.server.impl.RemoteInputStreamSrvImpl;
+
/**
* Represents a command to move data in or out of a model.
*
@@ -23,23 +37,36 @@
*/
public abstract class DataTx extends ServerCommand {
+ /** The logger */
+ static final Logger logger = Logger.getLogger(DataTx.class.getName());
+
+ /** String constant for the extension of gzip files. */
+ private static final String GZIP_EXTENSION = ".gz";
+
+ /** String constant for the extension of zip files. */
+ private static final String ZIP_EXTENSION = ".zip";
+
/** The source of data to insert. */
private URI source;
/** The graph to load data into. */
private URI destination;
-
+
+ /** Indicates that data is to be loaded locally from the client. */
+ private boolean local;
+
/**
* Create a new load command.
* @param source The source of data to insert.
* @param destination The graph to load data into.
*/
- public DataTx(URI source, URI destination) {
+ public DataTx(URI source, URI destination, boolean local) {
super(destination);
if (source == null) throw new IllegalArgumentException("Need a valid source of data");
if (destination == null) throw new IllegalArgumentException("Need a valid destination for data");
this.source = source;
this.destination = destination;
+ this.local = local;
}
/**
@@ -63,4 +90,87 @@
return destination;
}
+
+ /**
+ * @return the locality flag for the data.
+ */
+ public boolean isLocal() {
+ return local;
+ }
+
+
+ /**
+ * Perform the transfer with the configured datastream.
+ * @return The number of statements affected, or <code>null</code> if this is not relevant.
+ */
+ protected abstract Long doTx(Connection conn, InputStream inputStream) throws QueryException;
+
+
+ /**
+ * Wrap the file at the source URI in an RMI object for marshalling, and send over the connection.
+ * @param conn The connection to the server.
+ * @return The number of statements inserted.
+ * @throws QueryException There was an error working with data at the server end.
+ * @throws IOException There was an error transferring data over the network.
+ */
+ protected long sendMarshalledData(Connection conn) throws QueryException, IOException {
+ if (logger.isInfoEnabled()) logger.info("loading local resource : " + source);
+
+ RemoteInputStreamSrvImpl srv = null;
+ RemoteInputStream remoteInputStream = null;
+ try {
+
+ // is the file/stream compressed?
+ InputStream inputStream = adjustForCompression(source.toURL());
+
+ // open and wrap the inputstream
+ srv = new RemoteInputStreamSrvImpl(inputStream);
+ UnicastRemoteObject.exportObject(srv);
+ remoteInputStream = new RemoteInputStream(srv);
+
+ // call back to the implementing class
+ return doTx(conn, remoteInputStream);
+
+ } finally {
+ // clean up the RMI object
+ if (srv != null) {
+ try {
+ UnicastRemoteObject.unexportObject(srv, false);
+ } catch (NoSuchObjectException ex) {};
+ }
+ try {
+ if (remoteInputStream != null) remoteInputStream.close();
+ } catch (Exception e) { }
+ }
+
+ }
+
+
+ /**
+ * Gets a stream for a file. Determines if the stream is compressed by inspecting
+ * the fileName extension.
+ *
+ * @return a new stream which supplies uncompressed data from the file location.
+ * @param fileLocation String The URL for the file being loaded
+ * @throws IOException An error while reading from the input stream.
+ * @return InputStream A new input stream which supplies uncompressed data.
+ */
+ private static InputStream adjustForCompression(URL fileLocation) throws IOException {
+
+ if (fileLocation == null) throw new IllegalArgumentException("File name is null");
+
+ InputStream stream = fileLocation.openStream();
+
+ // wrap the stream in a decompressor if the suffixes indicate this should happen.
+ String fileName = fileLocation.toString();
+ if (fileName.toLowerCase().endsWith(GZIP_EXTENSION)) {
+ stream = new GZIPInputStream(stream);
+ } else if (fileName.toLowerCase().endsWith(ZIP_EXTENSION)) {
+ stream = new ZipInputStream(stream);
+ }
+
+ assert stream != null;
+ return stream;
+ }
+
}
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-10 15:03:41 UTC (rev 415)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Deletion.java 2007-09-11 04:14:54 UTC (rev 416)
@@ -45,10 +45,15 @@
super(graph, selectQuery);
}
+ /**
+ * Performs the deletion.
+ * @param conn the session to delete the data from the graph in.
+ * @return Text describing the action.
+ */
public Object execute(Connection conn) throws Exception {
if (isSelectBased()) conn.getSession().delete(graph, getSelectQuery());
else conn.getSession().delete(graph, getStatements());
- return resultMessage = "Successfully deleted statements from: " + graph;
+ return setResultMessage("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-10 15:03:41 UTC (rev 415)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/DropGraph.java 2007-09-11 04:14:54 UTC (rev 416)
@@ -40,9 +40,14 @@
return graphUri;
}
+ /**
+ * Performs the deletion.
+ * @param conn the session to delete the graph in.
+ * @return Text describing the action.
+ */
public Object execute(Connection conn) throws Exception {
conn.getSession().removeModel(graphUri);
- return resultMessage = "Successfully dropped model " + graphUri;
+ return setResultMessage("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-10 15:03:41 UTC (rev 415)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/ExecuteScript.java 2007-09-11 04:14:54 UTC (rev 416)
@@ -64,6 +64,12 @@
return script;
}
+ /**
+ * Perform a series of actions, read from a file.
+ * @param conn The connection to perform the actions on. Only one connection can be used.
+ * @return A string containing the accumulation of output messages from all commands in the
+ * script, separated by newlines.
+ */
public Object execute(Connection conn) throws Exception {
// create a buffer to hold the results in
StringBuffer resultsMsg = new StringBuffer();
@@ -78,20 +84,22 @@
while (null != (commandLine = scriptIn.readLine())) {
line++;
if (!commandLine.equals("")) {
- resultsMsg.append(interpreter.parseCommand(commandLine).execute(conn));
+ Command cmd = interpreter.parseCommand(commandLine);
+ cmd.execute(conn);
+ resultsMsg.append(cmd.getResultMessage()).append("\n");
}
}
resultsMsg.append("Completed execution of script " + script);
- resultMessage = resultsMsg.toString();
+ setResultMessage(resultsMsg.toString());
} catch (MulgaraParserException pe) {
- resultMessage = "Syntax error in script (line " + line + "): " + pe.getMessage();
+ setResultMessage("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();
+ setResultMessage("Syntax error in script (line " + line + "): " + le.getMessage());
logger.warn("Unable to execute script - " + script + "\n" + le.getMessage());
}
- return resultMessage;
+ return getResultMessage();
}
}
Modified: branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Help.java
===================================================================
--- branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Help.java 2007-09-10 15:03:41 UTC (rev 415)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Help.java 2007-09-11 04:14:54 UTC (rev 416)
@@ -39,14 +39,22 @@
return true;
}
+ /**
+ * Get the text that was requested from this object.
+ * @return The help text requested.
+ */
public String getOutput() {
// let the user know the help for the selected command
return helpText;
}
+ /**
+ * Asks for the help text associated with the creation of this object.
+ * @param conn ignored.
+ * @return The text of the help request.
+ */
public Object execute(Connection conn) throws Exception {
- // TODO Auto-generated method stub
- return null;
+ return setResultMessage(helpText);
}
}
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-10 15:03:41 UTC (rev 415)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Insertion.java 2007-09-11 04:14:54 UTC (rev 416)
@@ -45,10 +45,15 @@
super(graph, selectQuery);
}
+ /**
+ * Performs the insertion.
+ * @param conn the session for the graph to insert the data into.
+ * @return Text describing the action.
+ */
public Object execute(Connection conn) throws Exception {
if (isSelectBased()) conn.getSession().insert(graph, getSelectQuery());
else conn.getSession().insert(graph, getStatements());
- return resultMessage = "Successfully inserted statements into: " + graph;
+ return setResultMessage("Successfully inserted statements into: " + graph);
}
}
Modified: branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Load.java
===================================================================
--- branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Load.java 2007-09-10 15:03:41 UTC (rev 415)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Load.java 2007-09-11 04:14:54 UTC (rev 416)
@@ -11,9 +11,14 @@
*/
package org.mulgara.query.operation;
+import java.io.IOException;
+import java.io.InputStream;
import java.net.URI;
+import org.apache.log4j.Logger;
import org.mulgara.connection.Connection;
+import org.mulgara.query.ModelResource;
+import org.mulgara.query.QueryException;
/**
* Represents a command to load data into a model.
@@ -25,13 +30,46 @@
*/
public class Load extends DataTx {
- public Load(URI source, URI destination) {
- super(source, destination);
+ /** The logger */
+ static final Logger logger = Logger.getLogger(Load.class.getName());
+
+ /** Model resource form of the source URI */
+ private ModelResource srcRsc;
+
+ public Load(URI source, URI destination, boolean local) {
+ super(source, destination, local);
+ srcRsc = new ModelResource(source);
}
+
+ /**
+ * Load the data into the destination graph through the given connection.
+ * @param conn The connection to load the data over.
+ * @return A text string describing how many statements were inserted.
+ */
public Object execute(Connection conn) throws Exception {
- // TODO Auto-generated method stub
- return null;
+ URI src = getSource();
+ URI dest = getDestination();
+ try {
+ long stmtCount = isLocal() ? sendMarshalledData(conn) : conn.getSession().setModel(dest, srcRsc);
+ if (logger.isDebugEnabled()) logger.debug("Loaded " + stmtCount + " statements from " + src + " into " + dest);
+
+ return (stmtCount > 0L) ? setResultMessage("Successfully loaded " + stmtCount + " statements from " + src + " into " + dest)
+ : setResultMessage("WARNING: No valid RDF statements found in " + src);
+
+ } catch (IOException ex) {
+ logger.error("Error attempting to load : " + src, ex);
+ throw new QueryException("Error attempting to load : " + src, ex);
+ }
}
+
+ /**
+ * Perform the transfer with the configured datastream.
+ * @return The number of statements affected, or <code>null</code> if this is not relevant.
+ */
+ protected Long doTx(Connection conn, InputStream inputStream) throws QueryException {
+ return conn.getSession().setModel(inputStream, getDestination(), srcRsc);
+ }
+
}
Modified: branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/LocalCommand.java
===================================================================
--- branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/LocalCommand.java 2007-09-10 15:03:41 UTC (rev 415)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/LocalCommand.java 2007-09-11 04:14:54 UTC (rev 416)
@@ -25,8 +25,8 @@
public abstract class LocalCommand implements Command {
/** The message set by the result of this command. */
- protected String resultMessage = "";
-
+ private String resultMessage = "";
+
/**
* Indicates that this operation is local.
* @return Always <code>true</code> to indicate this command is local.
@@ -61,4 +61,11 @@
return resultMessage;
}
+ /**
+ * Sets message text relevant to the operation. Useful for the UI.
+ * @return The set text.
+ */
+ protected String setResultMessage(String resultMessage) {
+ return this.resultMessage = resultMessage;
+ }
}
Modified: branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Quit.java
===================================================================
--- branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Quit.java 2007-09-10 15:03:41 UTC (rev 415)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Quit.java 2007-09-11 04:14:54 UTC (rev 416)
@@ -24,6 +24,8 @@
* @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
*/
public class Quit extends LocalCommand {
+
+ static final String finalMessage = "Exiting.";
/**
* Indicates that this operation is for a UI.
@@ -33,9 +35,12 @@
return true;
}
+ /**
+ * No specific action to be taken here. The client needs to know that this message
+ * requires exiting of the main process.
+ */
public Object execute(Connection conn) throws Exception {
- // TODO Auto-generated method stub
- return null;
+ return finalMessage;
}
}
Modified: branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Restore.java
===================================================================
--- branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Restore.java 2007-09-10 15:03:41 UTC (rev 415)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Restore.java 2007-09-11 04:14:54 UTC (rev 416)
@@ -11,9 +11,12 @@
*/
package org.mulgara.query.operation;
+import java.io.IOException;
+import java.io.InputStream;
import java.net.URI;
import org.mulgara.connection.Connection;
+import org.mulgara.query.QueryException;
/**
* Represents a command to reload backup data.
@@ -25,12 +28,40 @@
*/
public class Restore extends DataTx {
- public Restore(URI source, URI destination) {
- super(source, destination);
+ public Restore(URI source, URI destination, boolean local) {
+ super(source, destination, local);
}
+
+ /**
+ * Restore the data into the destination graph through the given connection.
+ * @param conn The connection to restore the data over.
+ * @return A text string describing the operation.
+ */
public Object execute(Connection conn) throws Exception {
- // TODO Auto-generated method stub
+ URI src = getSource();
+ URI dest = getDestination();
+ try {
+ if (isLocal()) sendMarshalledData(conn);
+ else conn.getSession().restore(dest, src);
+
+ if (logger.isDebugEnabled()) logger.debug("Completed restoring " + dest + " from " + src);
+
+ return setResultMessage("Successfully restored " + dest + " from " + src);
+
+ } catch (IOException ex) {
+ logger.error("Error attempting to restore: " + src, ex);
+ throw new QueryException("Error attempting to restore: " + src, ex);
+ }
+ }
+
+
+ /**
+ * Perform the transfer with the configured datastream.
+ * @return <code>null</code>, as this operation does not return a number.
+ */
+ protected Long doTx(Connection conn, InputStream inputStream) throws QueryException {
+ conn.getSession().restore(inputStream, getDestination(), getSource());
return null;
}
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-09-10 15:03:41 UTC (rev 415)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Rollback.java 2007-09-11 04:14:54 UTC (rev 416)
@@ -34,8 +34,7 @@
*/
public Object execute(Connection conn) throws QueryException {
conn.getSession().rollback();
- resultMessage = "Successfully committed transaction";
- return resultMessage;
+ return setResultMessage("Successfully committed transaction");
}
}
Modified: branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/ServerCommand.java
===================================================================
--- branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/ServerCommand.java 2007-09-10 15:03:41 UTC (rev 415)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/ServerCommand.java 2007-09-11 04:14:54 UTC (rev 416)
@@ -30,7 +30,7 @@
private ModelResource serverGraph;
/** The message set by the result of this command. */
- protected String resultMessage;
+ private String resultMessage;
/**
* Creates a new command, with a principle graph URI.
@@ -80,4 +80,13 @@
public String getResultMessage() {
return resultMessage;
}
+
+
+ /**
+ * Sets message text relevant to the operation. Useful for the UI.
+ * @return The set text.
+ */
+ protected String setResultMessage(String resultMessage) {
+ return this.resultMessage = resultMessage;
+ }
}
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-09-10 15:03:41 UTC (rev 415)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/SetAutoCommit.java 2007-09-11 04:14:54 UTC (rev 416)
@@ -22,6 +22,8 @@
*/
public class SetAutoCommit extends BooleanSetCommand {
+ private static final String MESSAGE = "Autocommit has been set: ";
+
/**
* Create a command to set autocommit on or off.
* @param option The value to set the time recording to.
@@ -31,8 +33,9 @@
}
public Object execute(Connection conn) throws Exception {
- // TODO Auto-generated method stub
- return null;
+ boolean on = isOn();
+ conn.getSession().setAutoCommit(on);
+ return setResultMessage(MESSAGE + (on ? ON : OFF));
}
}
Modified: branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/SetTime.java
===================================================================
--- branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/SetTime.java 2007-09-10 15:03:41 UTC (rev 415)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/SetTime.java 2007-09-11 04:14:54 UTC (rev 416)
@@ -21,6 +21,8 @@
* @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
*/
public class SetTime extends BooleanSetCommand {
+
+ private static final String SET_TIME = "Time keeping has been set: ";
/**
* Create a command to set timing on or off.
@@ -30,8 +32,10 @@
super(option);
}
+ /**
+ * Does nothing at the client, except to indicate that time keeping records are required.
+ */
public Object execute(Connection conn) throws Exception {
- // TODO Auto-generated method stub
- return null;
+ return setResultMessage(SET_TIME + (isOn() ? ON : OFF));
}
}
Modified: branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/SetUser.java
===================================================================
--- branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/SetUser.java 2007-09-10 15:03:41 UTC (rev 415)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/SetUser.java 2007-09-11 04:14:54 UTC (rev 416)
@@ -27,6 +27,8 @@
*/
public class SetUser extends LocalCommand {
+ private static final String MESSAGE = "Set credentials for: ";
+
/** The user logging in. */
private String user;
@@ -85,9 +87,11 @@
}
+ /**
+ * Does nothing at the client, except to indicate that a user record has been created
+ */
public Object execute(Connection conn) throws Exception {
- // TODO Auto-generated method stub
- return null;
+ return setResultMessage(MESSAGE + user);
}
}
Modified: branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/TransactionCommand.java
===================================================================
--- branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/TransactionCommand.java 2007-09-10 15:03:41 UTC (rev 415)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/TransactionCommand.java 2007-09-11 04:14:54 UTC (rev 416)
@@ -22,10 +22,10 @@
* @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 abstract class TransactionCommand {
+public abstract class TransactionCommand implements Command {
/** An optional message that can be returned to a UI after execution. */
- protected String resultMessage = "";
+ private String resultMessage = "";
/**
* Indicates that this operation may require network access.
@@ -61,4 +61,11 @@
return resultMessage;
}
+ /**
+ * Sets message text relevant to the operation. Useful for the UI.
+ * @return The set text.
+ */
+ protected String setResultMessage(String resultMessage) {
+ return this.resultMessage = resultMessage;
+ }
}
More information about the Mulgara-svn
mailing list