[Mulgara-svn] r1030 - in trunk/src/jar: itql/java/org/mulgara/itql query/java/org/mulgara/query/operation query/java/org/mulgara/server resolver/java/org/mulgara/resolver server-beep/java/org/mulgara/server/beep server-rmi/java/org/mulgara/server/rmi
alexhall at mulgara.org
alexhall at mulgara.org
Fri Jun 27 17:20:27 UTC 2008
Author: alexhall
Date: 2008-06-27 10:20:26 -0700 (Fri, 27 Jun 2008)
New Revision: 1030
Added:
trunk/src/jar/query/java/org/mulgara/query/operation/DataInputTx.java
trunk/src/jar/query/java/org/mulgara/query/operation/DataOutputTx.java
Modified:
trunk/src/jar/itql/java/org/mulgara/itql/ItqlInterpreterBean.java
trunk/src/jar/itql/java/org/mulgara/itql/ItqlInterpreterBeanUnitTest.java
trunk/src/jar/itql/java/org/mulgara/itql/TqlInterpreter.java
trunk/src/jar/query/java/org/mulgara/query/operation/Backup.java
trunk/src/jar/query/java/org/mulgara/query/operation/DataTx.java
trunk/src/jar/query/java/org/mulgara/query/operation/Export.java
trunk/src/jar/query/java/org/mulgara/query/operation/Load.java
trunk/src/jar/query/java/org/mulgara/query/operation/Restore.java
trunk/src/jar/query/java/org/mulgara/query/operation/ServerCommand.java
trunk/src/jar/query/java/org/mulgara/server/Session.java
trunk/src/jar/resolver/java/org/mulgara/resolver/BackupOperation.java
trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java
trunk/src/jar/resolver/java/org/mulgara/resolver/ExportOperation.java
trunk/src/jar/resolver/java/org/mulgara/resolver/RestoreOperation.java
trunk/src/jar/server-beep/java/org/mulgara/server/beep/BEEPSession.java
trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RemoteSession.java
trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RemoteSessionWrapperSession.java
trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/SessionWrapperRemoteSession.java
Log:
Refactoring of data transaction commands (Backup, Restore, Export, Load). Removed server URI as an argument to backup and restore methods in Session.
Modified: trunk/src/jar/itql/java/org/mulgara/itql/ItqlInterpreterBean.java
===================================================================
--- trunk/src/jar/itql/java/org/mulgara/itql/ItqlInterpreterBean.java 2008-06-26 20:15:09 UTC (rev 1029)
+++ trunk/src/jar/itql/java/org/mulgara/itql/ItqlInterpreterBean.java 2008-06-27 17:20:26 UTC (rev 1030)
@@ -28,23 +28,29 @@
package org.mulgara.itql;
// Java APIs
-import java.io.*;
-import java.net.MalformedURLException;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
import java.net.URI;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
import javax.xml.soap.SOAPException;
-import org.w3c.dom.*;
-// Third party packages
-import org.apache.log4j.*; // Log4J
-import org.apache.axis.utils.XMLUtils; // Apache Axis
import org.apache.axis.utils.DOM2Writer;
-import org.jrdf.graph.URIReference; // JRDF
+import org.apache.axis.utils.XMLUtils;
+import org.apache.log4j.Logger;
import org.jrdf.graph.BlankNode;
-
-// Mulgara packages
+import org.jrdf.graph.URIReference;
import org.mulgara.connection.Connection;
import org.mulgara.connection.ConnectionException;
+import org.mulgara.connection.ConnectionFactory;
import org.mulgara.itql.lexer.LexerException;
import org.mulgara.itql.parser.ParserException;
import org.mulgara.parser.Interpreter;
@@ -56,13 +62,14 @@
import org.mulgara.query.TuplesException;
import org.mulgara.query.operation.Backup;
import org.mulgara.query.operation.Command;
-import org.mulgara.query.operation.DataTx;
+import org.mulgara.query.operation.Export;
import org.mulgara.query.operation.Load;
import org.mulgara.query.operation.Restore;
import org.mulgara.query.operation.SetAutoCommit;
import org.mulgara.query.rdf.LiteralImpl;
-import org.mulgara.query.rdf.Mulgara;
import org.mulgara.server.Session;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
/**
* iTQL Interpreter Bean.
@@ -98,9 +105,6 @@
*/
private final static String TQL_NS = "http://mulgara.org/tql#";
- /** Dummy load source for RDF files on an input stream. */
- private final static URI DUMMY_RDF_SOURCE = URI.create(Mulgara.NAMESPACE+"locally-sourced-inputStream.rdf");
-
/** The ITQL interpreter Bean. */
private final TqlAutoInterpreter interpreter = new TqlAutoInterpreter();
@@ -711,20 +715,19 @@
/**
- * Backup all the data on the specified server or model to a client local file.
+ * Backup all the data on the specified server to a client local file.
* The database is not changed by this method.
*
- * @param sourceURI The URI of the server or model to backup.
+ * @param sourceURI The URI of the server to backup.
* @param destinationFile an non-existent file on the local file system to
* receive the backup contents.
* @throws QueryException if the backup cannot be completed.
*/
+ @SuppressWarnings("deprecation")
public void backup(URI sourceURI, File destinationFile) throws QueryException {
Backup backup = new Backup(sourceURI, destinationFile.toURI(), true);
try {
backup.execute(interpreter.establishConnection(backup.getServerURI()));
- } catch (MalformedURLException e) {
- throw new QueryException("Bad source graph URI: " + sourceURI, e);
} catch (ConnectionException e) {
throw new QueryException("Unable to establish connection to: " + backup.getServerURI(), e);
}
@@ -735,19 +738,57 @@
* Backup all the data on the specified server to an output stream.
* The database is not changed by this method.
*
- * @param sourceURI The URI of the server or model to backup.
+ * @param sourceURI The URI of the server to backup.
* @param outputStream The stream to receive the contents
* @throws QueryException if the backup cannot be completed.
*/
+ @SuppressWarnings("deprecation")
public void backup(URI sourceURI, OutputStream outputStream) throws QueryException {
- URI serverUri = DataTx.calcServerUri(sourceURI);
+ Backup backup = new Backup(sourceURI, null, true);
+ backup.setOverrideOutputStream(outputStream);
try {
- Connection conn = interpreter.establishConnection(serverUri);
- Backup.backup(conn, sourceURI, outputStream);
+ backup.execute(interpreter.establishConnection(backup.getServerURI()));
} catch (ConnectionException e) {
- throw new QueryException("Unable to establish connection to: " + serverUri, e);
+ throw new QueryException("Unable to establish connection to: " + backup.getServerURI(), e);
}
}
+
+
+ /**
+ * Export the data in the specified graph to a client local file.
+ * The database is not changed by this method.
+ *
+ * @param graphURI The URI of the graph to export.
+ * @param destinationFile an non-existent file on the local file system to
+ * receive the export contents.
+ * @throws QueryException if the export cannot be completed.
+ */
+ public void export(URI graphURI, File destinationFile) throws QueryException {
+ Export export = new Export(graphURI, destinationFile.toURI(), true);
+ try {
+ export.execute(interpreter.establishConnection(export.getServerURI()));
+ } catch (ConnectionException e) {
+ throw new QueryException("Unable to establish connection to: " + export.getServerURI(), e);
+ }
+ }
+
+
+ /**
+ * Export the data in the specified graph to an output stream.
+ * The database is not changed by this method.
+ *
+ * @param graphURI The URI of the graph to export.
+ * @param outputStream The stream to receive the contents
+ * @throws QueryException if the export cannot be completed.
+ */
+ public void export(URI graphURI, OutputStream outputStream) throws QueryException {
+ Export export = new Export(graphURI, outputStream);
+ try {
+ export.execute(interpreter.establishConnection(export.getServerURI()));
+ } catch (ConnectionException e) {
+ throw new QueryException("Unable to establish connection to: " + export.getServerURI(), e);
+ }
+ }
/**
@@ -763,7 +804,7 @@
* @return number of rows inserted into the destination model
*/
public long load(InputStream inputStream, URI destinationURI) throws QueryException {
- return load(inputStream, DUMMY_RDF_SOURCE, destinationURI);
+ return load(inputStream, null, destinationURI);
}
@@ -787,7 +828,7 @@
long numberOfStatements = 0;
try {
Load loadCmd = new Load(sourceURI, destinationURI, true);
- loadCmd.setOverrideStream(inputStream);
+ loadCmd.setOverrideInputStream(inputStream);
numberOfStatements = (Long)loadCmd.execute(interpreter.establishConnection(loadCmd.getServerURI()));
} catch (QueryException ex) {
throw ex;
@@ -808,7 +849,7 @@
* @throws QueryException if the restore cannot be completed.
*/
public void restore(InputStream inputStream, URI serverURI) throws QueryException {
- restore(inputStream, serverURI, DUMMY_RDF_SOURCE);
+ restore(inputStream, serverURI, null);
}
@@ -823,10 +864,11 @@
* @param sourceURI The URI of the backup file to restore from.
* @throws QueryException if the restore cannot be completed.
*/
+ @SuppressWarnings("deprecation")
public void restore(InputStream inputStream, URI serverURI, URI sourceURI) throws QueryException {
try {
Restore restoreCmd = new Restore(sourceURI, serverURI, true);
- restoreCmd.setOverrideStream(inputStream);
+ restoreCmd.setOverrideInputStream(inputStream);
restoreCmd.execute(interpreter.establishConnection(restoreCmd.getServerURI()));
} catch (QueryException ex) {
throw ex;
Modified: trunk/src/jar/itql/java/org/mulgara/itql/ItqlInterpreterBeanUnitTest.java
===================================================================
--- trunk/src/jar/itql/java/org/mulgara/itql/ItqlInterpreterBeanUnitTest.java 2008-06-26 20:15:09 UTC (rev 1029)
+++ trunk/src/jar/itql/java/org/mulgara/itql/ItqlInterpreterBeanUnitTest.java 2008-06-27 17:20:26 UTC (rev 1030)
@@ -156,8 +156,8 @@
suite.addTest(new ItqlInterpreterBeanUnitTest("testLoadApi9"));
suite.addTest(new ItqlInterpreterBeanUnitTest("testBackupApi1"));
suite.addTest(new ItqlInterpreterBeanUnitTest("testBackupApi2"));
- suite.addTest(new ItqlInterpreterBeanUnitTest("testBackupApi3"));
- suite.addTest(new ItqlInterpreterBeanUnitTest("testBackupApi4"));
+ suite.addTest(new ItqlInterpreterBeanUnitTest("testExportApi1"));
+ suite.addTest(new ItqlInterpreterBeanUnitTest("testExportApi2"));
suite.addTest(new ItqlInterpreterBeanUnitTest("testRestoreApi1"));
suite.addTest(new ItqlInterpreterBeanUnitTest("testRoundTrip1"));
suite.addTest(new ItqlInterpreterBeanUnitTest("testMultipleBeanTest"));
@@ -608,21 +608,21 @@
/**
* Test the interpreter using a backup API locally.
- * Expects the test model to exist
+ * Expects the server to exist
*
* @throws Exception if the test fails
*/
public void testBackupApi1() throws Exception {
// log that we're executing the test
- log.debug("Starting backup API test 1");
+ log.debug("Starting backup API test 2");
- File file = new File(tmpDirectory, "camera.rdf");
+ File file = new File(tmpDirectory, "server.gz");
file.delete();
- URI modelURI = new URI(testModel);
+ URI serverURI = new URI("rmi://localhost/server1");
- bean.backup(modelURI, file);
+ bean.backup(serverURI, file);
assertTrue("Excepting a backup file", file.exists());
@@ -637,58 +637,58 @@
public void testBackupApi2() throws Exception {
// log that we're executing the test
- log.debug("Starting backup API test 2");
+ log.debug("Starting backup API test 4");
- File file = new File(tmpDirectory, "server.gz");
+ File file = new File(tmpDirectory, "server2.gz");
file.delete();
URI serverURI = new URI("rmi://localhost/server1");
- bean.backup(serverURI, file);
+ bean.backup(serverURI, new FileOutputStream(file));
assertTrue("Excepting a backup file", file.exists());
}
/**
- * Test the interpreter using a backup API locally.
+ * Test the interpreter using an export API locally.
* Expects the test model to exist
*
* @throws Exception if the test fails
*/
- public void testBackupApi3() throws Exception {
+ public void testExportApi1() throws Exception {
// log that we're executing the test
- log.debug("Starting backup API test 3");
+ log.debug("Starting backup API test 1");
- File file = new File(tmpDirectory, "camera2.rdf");
+ File file = new File(tmpDirectory, "camera.rdf");
file.delete();
URI modelURI = new URI(testModel);
- bean.backup(modelURI, new FileOutputStream(file));
+ bean.export(modelURI, file);
assertTrue("Excepting a backup file", file.exists());
}
/**
- * Test the interpreter using a backup API locally.
- * Expects the server to exist
+ * Test the interpreter using an export API locally.
+ * Expects the test model to exist
*
* @throws Exception if the test fails
*/
- public void testBackupApi4() throws Exception {
+ public void testExportApi2() throws Exception {
// log that we're executing the test
- log.debug("Starting backup API test 4");
+ log.debug("Starting backup API test 3");
- File file = new File(tmpDirectory, "server2.gz");
+ File file = new File(tmpDirectory, "camera2.rdf");
file.delete();
- URI serverURI = new URI("rmi://localhost/server1");
+ URI modelURI = new URI(testModel);
- bean.backup(serverURI, new FileOutputStream(file));
+ bean.export(modelURI, new FileOutputStream(file));
assertTrue("Excepting a backup file", file.exists());
Modified: trunk/src/jar/itql/java/org/mulgara/itql/TqlInterpreter.java
===================================================================
--- trunk/src/jar/itql/java/org/mulgara/itql/TqlInterpreter.java 2008-06-26 20:15:09 UTC (rev 1029)
+++ trunk/src/jar/itql/java/org/mulgara/itql/TqlInterpreter.java 2008-06-27 17:20:26 UTC (rev 1030)
@@ -676,6 +676,7 @@
*
* @param node the backup command
*/
+ @SuppressWarnings("deprecation")
public void outABackupCommand(ABackupCommand node) {
// log the command
@@ -712,6 +713,7 @@
*
* @param node the restore command
*/
+ @SuppressWarnings("deprecation")
public void outARestoreCommand(ARestoreCommand node) {
// log the command
Modified: trunk/src/jar/query/java/org/mulgara/query/operation/Backup.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/operation/Backup.java 2008-06-26 20:15:09 UTC (rev 1029)
+++ trunk/src/jar/query/java/org/mulgara/query/operation/Backup.java 2008-06-27 17:20:26 UTC (rev 1030)
@@ -11,60 +11,80 @@
*/
package org.mulgara.query.operation;
-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;
-import java.rmi.NoSuchObjectException;
-import java.rmi.RemoteException;
-import java.rmi.server.UnicastRemoteObject;
import org.apache.log4j.Logger;
import org.mulgara.connection.Connection;
import org.mulgara.query.QueryException;
-import edu.emory.mathcs.util.remote.io.RemoteOutputStream;
-import edu.emory.mathcs.util.remote.io.server.impl.RemoteOutputStreamSrvImpl;
-
/**
- * Represents a command to back data up from a model.
+ * Represents a command to back data up from a server.
*
* @created Aug 19, 2007
* @author Paul Gearon
* @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 class Backup extends DataTx {
+public class Backup extends DataOutputTx {
/** The logger */
static final Logger logger = Logger.getLogger(Backup.class.getName());
- /** The URI for the server. */
- private URI serverUri;
-
/**
* Creates a new Backup command.
- * @param source The data to back up. May be a server or just a single graph.
+ *
+ * This constructor is deprecated. The server URI is not part of the operation
+ * and is only present to support the TqlAutoInterpreter legacy code. Use
+ * {@link #Backup(URI, boolean)} or {@link #Backup(OutputStream)} instead.
+ *
+ * @param serverURI The server to back up.
* @param destination The location where to back the data up.
* Only file URLs supported at the moment.
+ * @param local The locality of the destination URI.
*/
- public Backup(URI source, URI destination, boolean locality) {
- super(source, destination, source, locality);
- if (!destination.getScheme().equals(FILE_SCHEME)) throw new IllegalArgumentException("Backups must be sent to a file");
- updateServerUri(source);
+ @Deprecated
+ public Backup(URI serverURI, URI destination, boolean local) {
+ super(serverURI, destination, serverURI, local);
}
-
+
/**
- * @return The URI of the destination graph.
+ * Creates a command to backup a server to a destination file. This is the preferred
+ * constructor for API calls that use their own server connections. The server URI
+ * is not an argument for the backup operation, and will be specified by the existing
+ * connection.
+ * @param destination The destination file URI to receive the backup.
+ * @param locality The locality of the destination file (<code>true</code> is client
+ * file system, <code>false</code> is server file system).
*/
+ public Backup(URI destination, boolean locality) {
+ this(null, destination, locality);
+ }
+
+ /**
+ * Creates a command to backup a server to an output stream. This is the preferred
+ * constructor for API calls that use their own server connections. The server URI
+ * is not an argument for the backup operation, and will be specified by the existing
+ * connection.
+ * @param outputStream The stream which will receive the server contents.
+ */
+ public Backup(OutputStream outputStream) {
+ this(null, null, true);
+ setOverrideOutputStream(outputStream);
+ }
+
+ /**
+ * The destination of a backup command is a database, not a graph.
+ * @return The URI of the server, or <code>null</code> if the server will be found from
+ * an existing connection.
+ */
+ @Override
public URI getServerURI() {
- return serverUri;
+ return getSource();
}
-
/**
* Perform a backup on a server.
* @param conn The connection to talk to the server on.
@@ -72,26 +92,26 @@
* @throws QueryException There was an error asking the server to perform the backup.
* @throws MalformedURLException The destination is not a valid file.
*/
- public Object execute(Connection conn) throws QueryException, MalformedURLException {
- // test if the server can do all the work, or if data needs to be streamed
- if (!isLocal()) {
- // server does all the work
- conn.getSession().backup(getSource(), getDestination());
- } else {
- // need to stream data through to an output stream
- FileOutputStream fileOutputStream = null;
- String destinationFile = this.getDestination().toURL().getPath();
- try {
- fileOutputStream = new FileOutputStream(destinationFile);
- } catch (FileNotFoundException ex) {
- throw new QueryException("File " + destinationFile + " cannot be created for backup. ", ex);
+ public Object execute(Connection conn) throws QueryException {
+ URI src = getSource();
+ URI dest = getDestination();
+ if (serverTest(src)) throw new QueryException("Cannot back up a graph. Must be a server URI.");
+
+ try {
+ if (isLocal()) {
+ getMarshalledData(conn);
+ } else {
+ conn.getSession().backup(dest);
}
-
- // send to open method for backing up to a stream
- backup(conn, getSource(), fileOutputStream);
+
+ if (logger.isDebugEnabled()) logger.debug("Completed backing up " + src + " to " + dest);
+
+ return setResultMessage("Successfully backed up " + src + " to " + dest + ".");
+
+ } catch (IOException ioe) {
+ logger.error("Error attempting to back up: " + dest, ioe);
+ throw new QueryException("Error attempting to back up: " + dest, ioe);
}
-
- return setResultMessage("Successfully backed up " + getSource() + " to " + getDestination() + ".");
}
@@ -99,60 +119,23 @@
* Public interface to perform a backup into an output stream.
* This is callable directly, without an AST interface.
* @param conn The connection to a server to be backed up.
- * @param source The URI describing the graph on the server to back up.
+ * @param serverURI The URI describing the server to back up.
* @param outputStream The output which will receive the data to be backed up.
* @throws QueryException There was an error asking the server to perform the backup.
*/
- public static void backup(Connection conn, URI source, OutputStream outputStream) throws QueryException {
- // open and wrap the outputstream
- RemoteOutputStreamSrvImpl srv = new RemoteOutputStreamSrvImpl(outputStream);
-
- // prepare it for exporting
- try {
- UnicastRemoteObject.exportObject(srv);
- } catch (RemoteException rex) {
- throw new QueryException("Unable to backup "+ source + " to an output stream", rex);
- }
-
- OutputStream marshallingOutputStream = new RemoteOutputStream(srv);
-
- // perform the backup
- try {
- conn.getSession().backup(source, marshallingOutputStream);
- } finally {
- // cleanup the output
- if (marshallingOutputStream != null) {
- try {
- marshallingOutputStream.close();
- } catch (IOException ioe ) { /* ignore */ }
- }
- // cleanup the RMI for the output stream
- if (srv != null) {
- try {
- UnicastRemoteObject.unexportObject(srv, false);
- } catch (NoSuchObjectException ex) {};
- }
- try {
- srv.close();
- } catch (IOException e) {}
- }
+ public static void backup(Connection conn, URI serverURI, OutputStream outputStream) throws QueryException {
+ Backup backup = new Backup(serverURI, null, true);
+ backup.setOverrideOutputStream(outputStream);
+ backup.execute(conn);
}
-
+
/**
- * Perform the transfer with the configured datastream.
- * @return The number of statements affected, or <code>null</code> if this is not relevant.
+ * Perform the transfer with the configured data stream.
*/
- protected Long doTx(Connection conn, InputStream inputStream) throws QueryException {
- return null;
+ @Override
+ protected void doTx(Connection conn, OutputStream outputStream) throws QueryException {
+ conn.getSession().backup(outputStream);
}
- /**
- * Sets the server URI for this server operation.
- * @param uri The URI to determine the server URI from.
- */
- private URI updateServerUri(URI uri) {
- serverUri = calcServerUri(uri);
- return serverUri;
- }
}
Added: trunk/src/jar/query/java/org/mulgara/query/operation/DataInputTx.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/operation/DataInputTx.java (rev 0)
+++ trunk/src/jar/query/java/org/mulgara/query/operation/DataInputTx.java 2008-06-27 17:20:26 UTC (rev 1030)
@@ -0,0 +1,187 @@
+/*
+ * The contents of this file are subject to the Open Software License
+ * Version 3.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.opensource.org/licenses/osl-3.0.txt
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ */
+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.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 into a graph (Load) or server (Restore).
+ *
+ * @created Jun 27, 2008
+ * @author Alex Hall
+ * @copyright © 2008 <a href="http://www.revelytix.com">Revelytix, Inc.</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public abstract class DataInputTx extends DataTx {
+
+ /** 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";
+
+ /** A stream to enable an API to load or restore data directly. */
+ private InputStream overrideInputStream = null;
+
+ /**
+ * Create a new data transfer command for moving data into a graph or server.
+ * If local is <code>true</code> then source may be null, but an overriding input
+ * stream must be set before executing the operation.
+ * @param source The source of data to insert.
+ * @param destination The graph or server to load data into.
+ * @param serverGraphURI The URI of the server or graph being operated on. This
+ * parameter is primarily for use by the TqlAutoInterpreter for discovering
+ * server URI's of commands, and may be omitted if working directly with an
+ * existing {@link Connection}.
+ * @param local If <code>true</code>, the source will be a file or stream on the
+ * local system that is marshalled to the remote server. If <code>false</code>,
+ * it will be a file on the remote server filesystem.
+ */
+ public DataInputTx(URI source, URI destination, URI serverGraphURI, boolean local) {
+ super(source, destination, serverGraphURI, local);
+ if (!local && source == null) throw new IllegalArgumentException("Need a valid remote source");
+ }
+
+
+ /**
+ * Allows an API to set an input stream for loading or restoring, instead of
+ * getting it from the source URI.
+ * @param overrideStream The stream to use as the data source.
+ */
+ public void setOverrideInputStream(InputStream overrideStream) {
+ this.overrideInputStream = overrideStream;
+ }
+
+
+ /**
+ * Perform the input 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 local source data (input stream or file URI) in an RMI object for marshalling,
+ * and send over the connection. Used by Load and Restore. Delegates to the {@link #doTx(Connection, InputStream)}
+ * abstract method to send the data over the connection.
+ * @param conn The connection to the server.
+ * @param compressable If <code>true</code> and the source is a file URI, file decompression will be
+ * applied to the contents of the source file before sending over the connection.
+ * @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, boolean compressable) throws QueryException, IOException {
+ if (logger.isInfoEnabled()) logger.info("Sending local resource : " + getSource());
+
+ RemoteInputStreamSrvImpl srv = null;
+ RemoteInputStream remoteInputStream = null;
+ try {
+
+ InputStream inputStream = getLocalInputStream(compressable);
+
+ // 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 the local input stream for a Load or Restore operation. If an input stream has been
+ * specified by {@link #setOverrideInputStream(InputStream)} then it will be returned; otherwise,
+ * an input stream will be opened for the source file URI.
+ * @param compressable If <code>true</code> and the source is a file URI, file decompression will be
+ * applied to its contents before returning.
+ * @return A stream for the local data source.
+ * @throws QueryException If no valid data source was set.
+ * @throws IOException If an error occurred opening the local source.
+ */
+ private InputStream getLocalInputStream(boolean compressable) throws QueryException, IOException {
+ // Use provided input stream if there is one.
+ InputStream stream = overrideInputStream;
+
+ if (stream == null) {
+ // No input stream was provided, need to open from local source URI.
+ URI sourceUri = getSource();
+ if (sourceUri == null) {
+ throw new QueryException("Attempt to execute data operation without a valid local source");
+ }
+
+ // is the file/stream compressed?
+ URL sourceUrl = sourceUri.toURL();
+ if (compressable) {
+ stream = adjustForCompression(sourceUrl);
+ } else {
+ stream = sourceUrl.openStream();
+ }
+ }
+
+ return stream;
+ }
+
+
+ /**
+ * Gets a stream for a file URL. Determines if the stream is compressed by inspecting
+ * the fileName extension.
+ *
+ * @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 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;
+ }
+
+}
Added: trunk/src/jar/query/java/org/mulgara/query/operation/DataOutputTx.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/operation/DataOutputTx.java (rev 0)
+++ trunk/src/jar/query/java/org/mulgara/query/operation/DataOutputTx.java 2008-06-27 17:20:26 UTC (rev 1030)
@@ -0,0 +1,160 @@
+/*
+ * The contents of this file are subject to the Open Software License
+ * Version 3.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.opensource.org/licenses/osl-3.0.txt
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ */
+package org.mulgara.query.operation;
+
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.URI;
+import java.rmi.NoSuchObjectException;
+import java.rmi.server.UnicastRemoteObject;
+
+import org.mulgara.connection.Connection;
+import org.mulgara.query.QueryException;
+
+import edu.emory.mathcs.util.remote.io.RemoteOutputStream;
+import edu.emory.mathcs.util.remote.io.server.impl.RemoteOutputStreamSrvImpl;
+
+/**
+ * Represents a command to move data out of a graph (Export) or server (Backup).
+ *
+ * @created Jun 27, 2008
+ * @author Alex Hall
+ * @copyright © 2008 <a href="http://www.revelytix.com">Revelytix, Inc.</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public abstract class DataOutputTx extends DataTx {
+
+ /** String constant for the file URL protocol. */
+ protected static final String FILE_SCHEME = "file";
+
+ /** A stream to enable an API to export or backup data directly. */
+ private OutputStream overrideOutputStream = null;
+
+ /**
+ * Create a new data transfer command for moving data otu of a graph or server.
+ * If local is <code>true</code> then destination may be null, but an overriding output
+ * stream must be set before executing the operation.
+ * @param source The graph or server to get data from.
+ * @param destination The destination of the graph or server content.
+ * @param serverGraphURI The URI of the server or graph being operated on. This
+ * parameter is primarily for use by the TqlAutoInterpreter for discovering
+ * server URI's of commands, and may be omitted if working directly with an
+ * existing {@link Connection}.
+ * @param local If <code>true</code>, the destination will be a file or stream on the
+ * local system that is marshalled from the remote server. If <code>false</code>,
+ * it will be a file on the remote server filesystem.
+ */
+ public DataOutputTx(URI source, URI destination, URI serverGraphURI, boolean local) {
+ super(source, destination, serverGraphURI, local);
+ if (!local && destination == null) throw new IllegalArgumentException("Need a valid remote destination");
+ if (destination != null && !destination.getScheme().equals(FILE_SCHEME)) {
+ throw new IllegalArgumentException("Output must be sent to a file");
+ }
+ }
+
+
+ /**
+ * Allows an API to set an output stream for exporting or backing up, instead of
+ * getting it from the destination URI.
+ * @param overrideStream The stream to use as the destination.
+ */
+ public void setOverrideOutputStream(OutputStream overrideStream) {
+ this.overrideOutputStream = overrideStream;
+ }
+
+
+ /**
+ * Perform the output transfer with the configured datastream.
+ */
+ protected abstract void doTx(Connection conn, OutputStream outputStream) throws QueryException;
+
+
+ /**
+ * Wrap the local destination object data (output stream or file URI) in an RMI object for marshalling,
+ * and receive over the connection. Delegates to the {@link #doTx(Connection, OutputStream)}
+ * abstract method to send the data 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 void getMarshalledData(Connection conn) throws QueryException, IOException {
+ if (logger.isInfoEnabled()) logger.info("Receiving local resource : " + getDestination());
+
+ RemoteOutputStreamSrvImpl srv = null;
+ RemoteOutputStream remoteOutputStream = null;
+
+ try {
+ OutputStream outputStream = getLocalOutputStream();
+
+ // open and wrap the output stream
+ srv = new RemoteOutputStreamSrvImpl(outputStream);
+ UnicastRemoteObject.exportObject(srv);
+ remoteOutputStream = new RemoteOutputStream(srv);
+
+ // call back to the implementing class
+ doTx(conn, remoteOutputStream);
+
+ } finally {
+ // cleanup the output
+ if (remoteOutputStream != null) {
+ try {
+ remoteOutputStream.close();
+ } catch (IOException ioe ) { /* ignore */ }
+ }
+
+ // cleanup the RMI for the output stream
+ if (srv != null) {
+ try {
+ UnicastRemoteObject.unexportObject(srv, false);
+ } catch (NoSuchObjectException ex) {};
+ try {
+ srv.close();
+ } catch (IOException e) {}
+ }
+ }
+ }
+
+
+ /**
+ * Gets the local output stream for an Export or Backup operation. If an output stream has been
+ * specified by {@link #setOverrideOutputStream(OutputStream)} then it will be returned; otherwise,
+ * an output stream will be opened for the destination file URI.
+ * @return A stream for the local data destination.
+ * @throws QueryException If no valid data destination was set.
+ * @throws IOException If an error occurred opening the local destination.
+ */
+ private OutputStream getLocalOutputStream() throws QueryException, IOException {
+ // Use provided output stream if there is one.
+ OutputStream stream = overrideOutputStream;
+
+ if (stream == null) {
+ // No output stream was provided, need to open from local destination URI.
+ URI destUri = getDestination();
+ if (destUri == null) {
+ throw new QueryException("Attempt to execute data operation without a valid local destination");
+ }
+
+ String destinationFile = this.getDestination().toURL().getPath();
+ try {
+ stream = new FileOutputStream(destinationFile);
+ } catch (FileNotFoundException ex) {
+ throw new QueryException("File " + destinationFile + " cannot be created for output.", ex);
+ }
+ }
+
+ return stream;
+ }
+
+}
Modified: trunk/src/jar/query/java/org/mulgara/query/operation/DataTx.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/operation/DataTx.java 2008-06-26 20:15:09 UTC (rev 1029)
+++ trunk/src/jar/query/java/org/mulgara/query/operation/DataTx.java 2008-06-27 17:20:26 UTC (rev 1030)
@@ -11,25 +11,16 @@
*/
package org.mulgara.query.operation;
-import java.io.IOException;
-import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
-import java.net.URL;
-import java.rmi.NoSuchObjectException;
-import java.rmi.server.UnicastRemoteObject;
-import java.util.zip.GZIPInputStream;
-import java.util.zip.ZipInputStream;
+import java.util.HashSet;
+import java.util.Set;
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.
+ * Represents a command to move data in or out of a graph or server.
*
* @created Aug 13, 2007
* @author Paul Gearon
@@ -41,55 +32,39 @@
/** 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";
-
- protected static final String FILE_SCHEME = "file";
-
- /** The source of data to insert. */
+ /** The source of the data. */
private final URI source;
- /** The graph to load data into. */
+ /** The destination of the data. */
private final URI destination;
/** Indicates that data is to be loaded locally from the client. */
private final boolean local;
- /** A stream to enable an API to load data directly. */
- private InputStream overrideStream;
-
/**
- * Create a new data transfer command for loads and restores.
+ * Create a new data transfer command for moving data into or out of a graph or server.
+ * If local is <code>true</code> then source or destination may be null, but
+ * an overriding input or output stream must be set before executing the operation.
* @param source The source of data to insert.
* @param destination The graph or server to load data into.
+ * @param serverGraphURI The URI of the server or graph being operated on. This
+ * parameter is primarily for use by the TqlAutoInterpreter for discovering
+ * server URI's of commands, and may be omitted if working directly with an
+ * existing {@link Connection}.
+ * @param local If <code>true</code>, the source for load/restore or destination for
+ * export/backup will be a file or stream on the local system that is marshalled
+ * to/from the remote server. If <code>false</code>, it will be a file on
+ * the remote server filesystem.
*/
public DataTx(URI source, URI destination, URI serverGraphURI, boolean local) {
super(serverGraphURI);
- // make sure that the URI given to the parent was a good one
- assert source.equals(serverGraphURI) || destination.equals(serverGraphURI);
- // test and store the parameters
- 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;
- overrideStream = null;
}
/**
- * Allows an API to set the stream for loading, instead of getting it from the
- * source URI.
- * @param overrideStream The stream to use for loading data.
- */
- public void setOverrideStream(InputStream overrideStream) {
- this.overrideStream = overrideStream;
- }
-
- /**
* @return the URI of the source data.
*/
public URI getSource() {
@@ -112,84 +87,33 @@
}
- /**
- * 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.
- * Used by Load and Restore, but not Backup, which marshalls in the opposite direction.
- * @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, boolean compressable) 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;
- if (compressable) inputStream = adjustForCompression(source.toURL());
- else inputStream = (overrideStream != null) ? overrideStream : source.toURL().openStream();
-
- // 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) { }
- }
-
+ /** The known set of schemas describing servers. */
+ private static Set<String> knownSchemas = new HashSet<String>();
+ static {
+ knownSchemas.add("rmi");
+ knownSchemas.add("local");
+ knownSchemas.add("beep");
}
/**
- * 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.
+ * Tests if a URI can potentially refer to a server. This will only apply for known schemas.
+ * If the URI is null, treat this as a valid server URI. This accounts for the fact that creating
+ * a backup or restore operation with an explicit server URI is only to support legacy
+ * TqlAutoInterpreter code. Commands created directly from the API to use with an existing
+ * connection should not have server URI set.
+ *
+ * @param serverURI The URI to check.
+ * @return <code>true</code> if the URI is known to refer to a graph. <code>false</code> if we can't
+ * tell or it is known to refer to a server.
*/
- private InputStream adjustForCompression(URL fileLocation) throws IOException {
-
- if (fileLocation == null) throw new IllegalArgumentException("File name is null");
-
- InputStream stream = (overrideStream == null) ? fileLocation.openStream() : overrideStream;
-
- // 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;
+ protected boolean serverTest(URI serverURI) {
+ if (serverURI == null) return false;
+ if (knownSchemas.contains(serverURI.getScheme())) return serverURI.getFragment() != null;
+ return true;
}
-
+
/**
* Determine the URI to be used for a server when processing a backup.
* @param uri Can contain the URI of a graph, or of an entire server.
Modified: trunk/src/jar/query/java/org/mulgara/query/operation/Export.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/operation/Export.java 2008-06-26 20:15:09 UTC (rev 1029)
+++ trunk/src/jar/query/java/org/mulgara/query/operation/Export.java 2008-06-27 17:20:26 UTC (rev 1030)
@@ -11,23 +11,13 @@
*/
package org.mulgara.query.operation;
-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;
-import java.rmi.NoSuchObjectException;
-import java.rmi.RemoteException;
-import java.rmi.server.UnicastRemoteObject;
import org.mulgara.connection.Connection;
import org.mulgara.query.QueryException;
-import edu.emory.mathcs.util.remote.io.RemoteOutputStream;
-import edu.emory.mathcs.util.remote.io.server.impl.RemoteOutputStreamSrvImpl;
-
/**
* Represents a command to export data from a graph.
*
@@ -36,98 +26,78 @@
* @copyright © 2008 <a href="http://www.revelytix.com">Revelytix, Inc.</a>
* @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
*/
-public class Export extends DataTx {
+public class Export extends DataOutputTx {
/**
- * Creates a new Export command.
- * @param source The graph to export.
- * @param destination The location where to export the data.
- * Only file URLs supported at the moment.
+ * Creates a new Export command, exporting data from the graph URI to a file or output stream.
+ * @param graphURI The graph to export.
+ * @param destination The location to export the data. Only file URLs supported at the moment.
+ * May be null if an output stream will be provided.
+ * @param local Set to <code>true</code> to indicate that the source is on the client system.
*/
- public Export(URI source, URI destination, boolean locality) {
- super(source, destination, source, locality);
- if (!destination.getScheme().equals(FILE_SCHEME)) throw new IllegalArgumentException("Exports must be sent to a file");
+ public Export(URI graphURI, URI destination, boolean local) {
+ super(graphURI, destination, graphURI, local);
+ if (graphURI == null) throw new IllegalArgumentException("Need a valid source graph URI");
}
/**
+ * Alternate constructor for creating a command to export data from a graph to an output stream.
+ * @param graphURI The graph to export.
+ * @param outputStream The stream that will receive the contents of the exported graph.
+ */
+ public Export(URI graphURI, OutputStream outputStream) {
+ this(graphURI, null, true);
+ setOverrideOutputStream(outputStream);
+ }
+
+ /**
* Perform an export on a graph.
* @param conn The connection to talk to the server on.
* @return The text describing the graph that was exported.
* @throws QueryException There was an error asking the server to perform the export.
- * @throws MalformedURLException The destination is not a valid file.
*/
- public Object execute(Connection conn) throws Exception {
- // test if the server can do all the work, or if data needs to be streamed
- if (!isLocal()) {
- // server does all the work
- conn.getSession().export(getSource(), getDestination());
- } else {
- // need to stream data through to an output stream
- FileOutputStream fileOutputStream = null;
- String destinationFile = this.getDestination().toURL().getPath();
- try {
- fileOutputStream = new FileOutputStream(destinationFile);
- } catch (FileNotFoundException ex) {
- throw new QueryException("File " + destinationFile + " cannot be created for export. ", ex);
- }
-
- // send to open method for exporting to a stream
- export(conn, getSource(), fileOutputStream);
+ public Object execute(Connection conn) throws QueryException {
+ URI src = getSource();
+ URI dest = getDestination();
+
+ try {
+ if (isLocal()) {
+ getMarshalledData(conn);
+ } else {
+ conn.getSession().export(src, dest);
+ }
+
+ if (logger.isDebugEnabled()) logger.debug("Completed backing up " + src + " to " + dest);
+
+ return setResultMessage("Successfully exported " + src + " to " +
+ (dest != null ? dest : "output stream") + ".");
}
-
- return setResultMessage("Successfully exported " + getSource() + " to " + getDestination() + ".");
+ catch (IOException ioe) {
+ logger.error("Error attempting to export: " + src, ioe);
+ throw new QueryException("Error attempting to export: " + src, ioe);
+ }
}
/**
* Public interface to perform an export into an output stream.
* This is callable directly, without an AST interface.
* @param conn The connection to a server to perform the export.
- * @param source The URI describing the graph on the server to export.
+ * @param graphURI The URI describing the graph on the server to export.
* @param outputStream The output which will receive the data to be exported.
* @throws QueryException There was an error asking the server to perform the export.
*/
- public static void export(Connection conn, URI source, OutputStream outputStream) throws QueryException {
- // open and wrap the outputstream
- RemoteOutputStreamSrvImpl srv = new RemoteOutputStreamSrvImpl(outputStream);
-
- // prepare it for exporting
- try {
- UnicastRemoteObject.exportObject(srv);
- } catch (RemoteException rex) {
- throw new QueryException("Unable to export "+ source + " to an output stream", rex);
- }
-
- OutputStream marshallingOutputStream = new RemoteOutputStream(srv);
-
- // perform the export
- try {
- conn.getSession().export(source, marshallingOutputStream);
- } finally {
- // cleanup the output
- if (marshallingOutputStream != null) {
- try {
- marshallingOutputStream.close();
- } catch (IOException ioe ) { /* ignore */ }
- }
- // cleanup the RMI for the output stream
- if (srv != null) {
- try {
- UnicastRemoteObject.unexportObject(srv, false);
- } catch (NoSuchObjectException ex) {};
- }
- try {
- srv.close();
- } catch (IOException e) {}
- }
+ public static void export(Connection conn, URI graphURI, OutputStream outputStream) throws QueryException {
+ Export export = new Export(graphURI, null, true);
+ export.setOverrideOutputStream(outputStream);
+ export.execute(conn);
}
/**
- * Perform the transfer with the configured datastream.
- * @return The number of statements affected, or <code>null</code> if this is not relevant.
+ * Perform the transfer with the configured data stream.
*/
@Override
- protected Long doTx(Connection conn, InputStream inputStream) throws QueryException {
- return null;
+ protected void doTx(Connection conn, OutputStream outputStream) throws QueryException {
+ conn.getSession().export(getSource(), outputStream);
}
}
Modified: trunk/src/jar/query/java/org/mulgara/query/operation/Load.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/operation/Load.java 2008-06-26 20:15:09 UTC (rev 1029)
+++ trunk/src/jar/query/java/org/mulgara/query/operation/Load.java 2008-06-27 17:20:26 UTC (rev 1030)
@@ -19,6 +19,7 @@
import org.mulgara.connection.Connection;
import org.mulgara.query.ModelResource;
import org.mulgara.query.QueryException;
+import org.mulgara.query.rdf.Mulgara;
/**
* Represents a command to load data into a model.
@@ -28,27 +29,45 @@
* @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 class Load extends DataTx {
+public class Load extends DataInputTx {
/** The logger */
static final Logger logger = Logger.getLogger(Load.class.getName());
+ /** Dummy source model URI to pass to the server when overriding with local stream. */
+ protected static final URI DUMMY_RDF_SOURCE = URI.create(Mulgara.NAMESPACE+"locally-sourced-inputStream.rdf");
+
/** Model resource form of the source URI */
private final ModelResource srcRsc;
-
+
/**
* Build a load operation, loading data from one URI into a graph specified by another URI.
* @param source The URI of the source of the RDF data.
- * @param destination The URI of the graph to receive the data.
+ * @param graphURI The URI of the graph to receive the data.
* @param local Set to <code>true</code> to indicate that the source is on the client system.
*/
- public Load(URI source, URI destination, boolean local) {
- super(source, destination, destination, local);
- srcRsc = new ModelResource(source);
+ public Load(URI source, URI graphURI, boolean local) {
+ super(source, graphURI, graphURI, local);
+
+ // Validate arguments.
+ if (graphURI == null) throw new IllegalArgumentException("Need a valid destination graph URI");
+
+ srcRsc = new ModelResource(source == null ? DUMMY_RDF_SOURCE : source);
}
/**
+ * Alternate constructor for creating a load operation whose source will be a local input stream.
+ * @param graphURI The URI of the graph to receive the data.
+ * @param stream The local input stream that is the source of data to load.
+ */
+ public Load(URI graphURI, InputStream stream) {
+ this(null, graphURI, true);
+ setOverrideInputStream(stream);
+ }
+
+
+ /**
* Load the data into the destination graph through the given connection.
* @param conn The connection to load the data over.
* @return The number of statements that were inserted.
@@ -60,8 +79,9 @@
long stmtCount = isLocal() ? sendMarshalledData(conn, true) : conn.getSession().setModel(dest, srcRsc);
if (logger.isDebugEnabled()) logger.debug("Loaded " + stmtCount + " statements from " + src + " into " + dest);
- if (stmtCount > 0L) setResultMessage("Successfully loaded " + stmtCount + " statements from " + src + " into " + dest);
- else setResultMessage("WARNING: No valid RDF statements found in " + src);
+ if (stmtCount > 0L) setResultMessage("Successfully loaded " + stmtCount + " statements from " +
+ (src != null ? src : "input stream") + " into " + dest);
+ else setResultMessage("WARNING: No valid RDF statements found in " + (src != null ? src : "input stream"));
return stmtCount;
@@ -76,6 +96,7 @@
* Perform the transfer with the configured datastream.
* @return The number of statements affected, or <code>null</code> if this is not relevant.
*/
+ @Override
protected Long doTx(Connection conn, InputStream inputStream) throws QueryException {
return conn.getSession().setModel(inputStream, getDestination(), srcRsc);
}
Modified: trunk/src/jar/query/java/org/mulgara/query/operation/Restore.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/operation/Restore.java 2008-06-26 20:15:09 UTC (rev 1029)
+++ trunk/src/jar/query/java/org/mulgara/query/operation/Restore.java 2008-06-27 17:20:26 UTC (rev 1030)
@@ -14,30 +14,68 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
-import java.util.HashSet;
-import java.util.Set;
import org.mulgara.connection.Connection;
import org.mulgara.query.QueryException;
/**
- * Represents a command to reload backup data.
+ * Represents a command to restore a server from backup data.
*
* @created Aug 19, 2007
* @author Paul Gearon
* @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 class Restore extends DataTx {
+public class Restore extends DataInputTx {
- public Restore(URI source, URI destination, boolean local) {
- super(source, destination, destination, local);
+ /**
+ * Creates a restore operation, restoring the server from backup data at the given location.
+ *
+ * This constructor is deprecated. The server URI is not part of the operation
+ * and is only present to support the TqlAutoInterpreter legacy code. Use
+ * {@link #Restore(URI, boolean)} or {@link #Restore(InputStream)} instead.
+ *
+ * @param source The location of the backup data to restore from.
+ * @param serverURI The URI of the server to restore (may be null if the operation is being
+ * executed on an existing connection).
+ * @param local Locality of the backup data.
+ */
+ @Deprecated
+ public Restore(URI source, URI serverURI, boolean local) {
+ super(source, serverURI, serverURI, local);
}
+
+ /**
+ * Creates a command to restore a server from a source file. This is the preferred
+ * constructor for API calls that use their own server connections. The server URI
+ * is not an argument for the restore operation, and will be specified by the existing
+ * connection.
+ * @param source The source file URI for the restore data.
+ * @param local The locality of the source file (<code>true</code> is client
+ * file system, <code>false</code> is server file system).
+ */
+ public Restore(URI source, boolean local) {
+ this(source, null, local);
+ }
+
+ /**
+ * Creates a command to restore a server from an input stream. This is the preferred
+ * constructor for API calls that use their own server connections. The server URI
+ * is not an argument for the restore operation, and will be specified by the existing
+ * connection.
+ * @param source The input stream that will provide the restore contents.
+ */
+ public Restore(InputStream inputStream) {
+ this(null, null, true);
+ setOverrideInputStream(inputStream);
+ }
/**
* The destination of a restore command is a database, not a graph.
- * @return The URI of the destination server.
+ * @return The URI of the destination server, or <code>null</code> if the server will be found from
+ * an existing connection.
*/
+ @Override
public URI getServerURI() {
return getDestination();
}
@@ -53,7 +91,7 @@
if (serverTest(dest)) throw new QueryException("Cannot restore to a graph. Must be a server URI.");
try {
if (isLocal()) sendMarshalledData(conn, false);
- else conn.getSession().restore(dest, src);
+ else conn.getSession().restore(src);
if (logger.isDebugEnabled()) logger.debug("Completed restoring " + dest + " from " + src);
@@ -65,33 +103,14 @@
}
}
-
/**
* Perform the transfer with the configured datastream.
- * @return <code>null</code>, as this operation does not return a number.
+ * @return <code>0</code>, as this operation does not return a number.
*/
+ @Override
protected Long doTx(Connection conn, InputStream inputStream) throws QueryException {
- conn.getSession().restore(inputStream, getDestination(), getSource());
+ conn.getSession().restore(inputStream, getSource());
return 0L;
}
- /** The known set of schemas describing servers. */
- private static Set<String> knownSchemas = new HashSet<String>();
- static {
- knownSchemas.add("rmi");
- knownSchemas.add("local");
- knownSchemas.add("beep");
- }
-
-
- /**
- * Tests if a URI can potentially refer to a server. This will only apply for known schemas.
- * @param serverURI The URI to check.
- * @return <code>false</code> if the URI refers to a known graph. <code>true</code> if we can't
- * tell or it is known to refer to a server.
- */
- protected boolean serverTest(URI serverURI) {
- if (knownSchemas.contains(serverURI.getScheme())) return serverURI.getFragment() != null;
- return true;
- }
}
Modified: trunk/src/jar/query/java/org/mulgara/query/operation/ServerCommand.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/operation/ServerCommand.java 2008-06-26 20:15:09 UTC (rev 1029)
+++ trunk/src/jar/query/java/org/mulgara/query/operation/ServerCommand.java 2008-06-27 17:20:26 UTC (rev 1030)
@@ -38,7 +38,7 @@
* @param serverGraphUri The URI of the graph.
*/
public ServerCommand(URI serverGraphUri) {
- serverGraph = new ModelResource(serverGraphUri);
+ serverGraph = (serverGraphUri != null) ? new ModelResource(serverGraphUri) : null;
resultMessage = "";
}
@@ -48,6 +48,11 @@
* @return The URI used to find the server.
*/
public URI getServerURI() {
+ // Short-circuit for backup and restore (don't need a server URI if executed with an existing connection)
+ if (serverGraph == null) {
+ return null;
+ }
+
Set<URI> gs = serverGraph.getDatabaseURIs();
URI serverUri = null;
Iterator<URI> iter = gs.iterator();
Modified: trunk/src/jar/query/java/org/mulgara/server/Session.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/server/Session.java 2008-06-26 20:15:09 UTC (rev 1029)
+++ trunk/src/jar/query/java/org/mulgara/server/Session.java 2008-06-27 17:20:26 UTC (rev 1030)
@@ -110,27 +110,25 @@
public void delete(URI modelURI, Query query) throws QueryException;
/**
- * Backup all the data on the specified server. The database is not changed by
+ * Backup all the data on the server. The database is not changed by
* this method. Does not require an exclusive lock on the database and will
* begin with the currently committed state.
*
- * @param sourceURI The URI of the server or model to backup.
* @param destinationURI The URI of the file to backup into.
* @throws QueryException if the backup cannot be completed.
*/
- public void backup(URI sourceURI, URI destinationURI)
+ public void backup(URI destinationURI)
throws QueryException;
/**
- * Backup all the data on the specified server to an output stream.
+ * Backup all the data on the server to an output stream.
* The database is not changed by this method. Does not require an exclusive
* lock on the database and will begin with the currently committed state.
*
- * @param sourceURI The URI of the server or model to backup.
* @param outputStream The stream to receive the contents
* @throws QueryException if the backup cannot be completed.
*/
- public void backup(URI sourceURI, OutputStream outputStream)
+ public void backup(OutputStream outputStream)
throws QueryException;
/**
@@ -156,28 +154,26 @@
public void export(URI graphURI, OutputStream outputStream) throws QueryException;
/**
- * Restore all the data on the specified server. If the database is not
- * currently empty then the database will contain the union of its current
- * content and the content of the backup file when this method returns.
+ * Restore all the data on the server. If the database is not
+ * currently empty then the current contents of the database will be replaced
+ * with the content of the backup file when this method returns.
*
- * @param serverURI The URI of the server to restore.
* @param sourceURI The URI of the backup file to restore from.
* @throws QueryException if the restore cannot be completed.
*/
- public void restore(URI serverURI, URI sourceURI) throws QueryException;
+ public void restore(URI sourceURI) throws QueryException;
/**
- * Restore all the data on the specified server. If the database is not
- * currently empty then the database will contain the union of its current
- * content and the content of the backup file when this method returns.
+ * Restore all the data on the server. If the database is not
+ * currently empty then the current contents of the database will be replaced
+ * with the content of the backup file when this method returns.
*
* @param inputStream a client supplied inputStream to obtain the restore
* content from. If null assume the sourceURI has been supplied.
- * @param serverURI The URI of the server to restore.
* @param sourceURI The URI of the backup file to restore from.
* @throws QueryException if the restore cannot be completed.
*/
- public void restore(InputStream inputStream, URI serverURI, URI sourceURI)
+ public void restore(InputStream inputStream, URI sourceURI)
throws QueryException;
/**
Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/BackupOperation.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/BackupOperation.java 2008-06-26 20:15:09 UTC (rev 1029)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/BackupOperation.java 2008-06-27 17:20:26 UTC (rev 1030)
@@ -36,20 +36,9 @@
import java.util.Date;
import java.util.zip.GZIPOutputStream;
-import org.jrdf.graph.URIReference;
-import org.mulgara.content.rdfxml.writer.RDFXMLWriter;
-import org.mulgara.query.Constraint;
import org.mulgara.query.ConstraintImpl;
-import org.mulgara.query.LocalNode;
-import org.mulgara.query.Variable;
-import org.mulgara.query.rdf.URIReferenceImpl;
import org.mulgara.resolver.spi.DatabaseMetadata;
-import org.mulgara.resolver.spi.Resolution;
-import org.mulgara.resolver.spi.Resolver;
-import org.mulgara.resolver.spi.ResolverSession;
-import org.mulgara.resolver.spi.Statements;
import org.mulgara.resolver.spi.SystemResolver;
-import org.mulgara.resolver.spi.TuplesWrapperStatements;
import org.mulgara.store.statement.StatementStore;
import org.mulgara.store.stringpool.SPObject;
import org.mulgara.store.tuples.Tuples;
@@ -69,8 +58,6 @@
*/
class BackupOperation extends OutputOperation implements BackupConstants, Operation {
- private final URI serverURI;
-
//
// Constructor
//
@@ -84,13 +71,11 @@
*
* @param outputStream output stream to receive the contents, may be
* <code>null</code> if a <var>destinationURI</var> is specified
- * @param serverURI The URI of the server to backup, never <code>null</code>
* @param destinationURI URI of the file to backup into, may be
* <code>null</code> if an <var>outputStream</var> is specified
*/
- public BackupOperation(OutputStream outputStream, URI serverURI, URI destinationURI) {
+ public BackupOperation(OutputStream outputStream, URI destinationURI) {
super(outputStream, destinationURI);
- this.serverURI = serverURI;
}
//
@@ -100,26 +85,16 @@
public void execute(OperationContext operationContext,
SystemResolver systemResolver,
DatabaseMetadata metadata) throws Exception {
- OutputStream os = outputStream;
+ OutputStream os = getOutputStream();;
Writer writer = null;
try {
- os = getOutputStream();
-
// The existence of a fragment indicates that a model is to be backed
// up otherwise the entire database is to be backed up.
- if (serverURI != null && serverURI.getFragment() != null) {
- OutputStreamWriter osw = new OutputStreamWriter(os, "UTF-8");
- writer = osw;
-
- // Export as RDF/XML.
- backupModel(systemResolver, systemResolver, serverURI, osw);
- } else {
- writer = new BufferedWriter(new OutputStreamWriter(
- new GZIPOutputStream(os), "UTF-8"
- ));
-
- backupDatabase(systemResolver, metadata, writer);
- }
+ writer = new BufferedWriter(new OutputStreamWriter(
+ new GZIPOutputStream(os), "UTF-8"
+ ));
+
+ backupDatabase(systemResolver, metadata, writer);
} finally {
// Clean up.
if (writer != null) {
@@ -206,57 +181,4 @@
writer.write("END\n");
}
-
- /**
- * Obtains statements for the model and writes to an RDFXMLWriter.
- *
- * @param resolver Resolver
- * @param session ResolverSession
- * @param modelURI URI
- * @param writer OutputStreamWriter
- * @throws Exception
- */
- private void backupModel(
- Resolver resolver, ResolverSession session, URI modelURI,
- OutputStreamWriter writer
- ) throws Exception {
- // get the meta node for the model
- URIReference modelValue = new URIReferenceImpl(modelURI);
- LocalNode modelNode = new LocalNode(
- session.lookupPersistent(modelValue)
- );
-
- // create a constraint to get all statements
- Variable[] vars = new Variable[] {
- StatementStore.VARIABLES[0],
- StatementStore.VARIABLES[1],
- StatementStore.VARIABLES[2]
- };
-
- // get all statements for the model
- Constraint constraint = new ConstraintImpl(vars[0], vars[1], vars[2],
- modelNode);
- Resolution resolution = resolver.resolve(constraint);
-
- // convert to Statements Object
- Statements modelStatements = new TuplesWrapperStatements(
- resolution, vars[0], vars[1], vars[2]
- );
-
- // do the writing
- try {
- RDFXMLWriter rdfWriter = new RDFXMLWriter();
- rdfWriter.write(modelStatements, session, writer);
- } finally {
- modelStatements.close();
- }
- }
-
- /**
- * @return <code>false</code>
- */
- public boolean isWriteOperation() {
- return false;
- }
-
}
Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java 2008-06-26 20:15:09 UTC (rev 1029)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/DatabaseSession.java 2008-06-27 17:20:26 UTC (rev 1030)
@@ -321,25 +321,23 @@
/**
- * Backup all the data on the specified server. The database is not changed by this method.
- * @param sourceURI The URI of the server or model to backup.
+ * Backup all the data on the server. The database is not changed by this method.
* @param destinationURI The URI of the file to backup into.
* @throws QueryException if the backup cannot be completed.
*/
- public void backup(URI sourceURI, URI destinationURI) throws QueryException {
- this.backup(null, sourceURI, destinationURI);
+ public void backup(URI destinationURI) throws QueryException {
+ this.backup(null, destinationURI);
}
/**
* Backup all the data on the specified server to an output stream.
* The database is not changed by this method.
- * @param sourceURI The URI of the server or model to backup.
* @param outputStream The stream to receive the contents
* @throws QueryException if the backup cannot be completed.
*/
- public void backup(URI sourceURI, OutputStream outputStream) throws QueryException {
- this.backup(outputStream, sourceURI, null);
+ public void backup(OutputStream outputStream) throws QueryException {
+ this.backup(outputStream, null);
}
@@ -367,30 +365,28 @@
/**
- * Restore all the data on the specified server. If the database is not
- * currently empty then the database will contain the union of its current
- * content and the content of the backup file when this method returns.
- * @param serverURI The URI of the server to restore.
+ * Restore all the data on the server. If the database is not
+ * currently empty then the current contents of the database will be replaced
+ * with the content of the backup file when this method returns.
* @param sourceURI The URI of the backup file to restore from.
* @throws QueryException if the restore cannot be completed.
*/
- public void restore(URI serverURI, URI sourceURI) throws QueryException {
- this.restore(null, serverURI, sourceURI);
+ public void restore(URI sourceURI) throws QueryException {
+ this.restore(null, sourceURI);
}
/**
- * Restore all the data on the specified server. If the database is not
- * currently empty then the database will contain the union of its current
- * content and the content of the backup file when this method returns.
+ * Restore all the data on the server. If the database is not
+ * currently empty then the current contents of the database will be replaced
+ * with the content of the backup file when this method returns.
* @param inputStream a client supplied inputStream to obtain the restore
* content from. If null assume the sourceURI has been supplied.
- * @param serverURI The URI of the server to restore.
* @param sourceURI The URI of the backup file to restore from.
* @throws QueryException if the restore cannot be completed.
*/
- public void restore(InputStream inputStream, URI serverURI, URI sourceURI) throws QueryException {
- execute(new RestoreOperation(inputStream, serverURI, sourceURI), "Unable to restore from " + sourceURI);
+ public void restore(InputStream inputStream, URI sourceURI) throws QueryException {
+ execute(new RestoreOperation(inputStream, sourceURI), "Unable to restore from " + sourceURI);
for (ResolverFactory resFactory: resolverFactoryList) {
createDefaultGraphs(resFactory.getDefaultGraphs());
}
@@ -595,13 +591,12 @@
* If an outputstream is supplied then the destinationURI is ignored.
*
* @param outputStream Optional output stream to receive the contents
- * @param serverURI The URI of the server to backup.
* @param destinationURI Option URI of the file to backup into.
* @throws QueryException if the backup cannot be completed.
*/
- private synchronized void backup(OutputStream outputStream, URI serverURI, URI destinationURI)
+ private synchronized void backup(OutputStream outputStream, URI destinationURI)
throws QueryException {
- execute(new BackupOperation(outputStream, serverURI, destinationURI),
+ execute(new BackupOperation(outputStream, destinationURI),
"Unable to backup to " + destinationURI);
}
Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/ExportOperation.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/ExportOperation.java 2008-06-26 20:15:09 UTC (rev 1029)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/ExportOperation.java 2008-06-27 17:20:26 UTC (rev 1030)
@@ -40,7 +40,7 @@
* @copyright © 2008 <a href="http://www.revelytix.com">Revelytix, Inc.</a>
* @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
*/
-public class ExportOperation extends OutputOperation {
+class ExportOperation extends OutputOperation {
private final URI graphURI;
Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/RestoreOperation.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/RestoreOperation.java 2008-06-26 20:15:09 UTC (rev 1029)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/RestoreOperation.java 2008-06-27 17:20:26 UTC (rev 1030)
@@ -28,31 +28,33 @@
package org.mulgara.resolver;
// Java 2 standard packages
-import java.io.*;
+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.RandomAccessFile;
+import java.net.URI;
import java.nio.ByteBuffer;
import java.nio.LongBuffer;
import java.nio.channels.FileChannel;
-import java.net.URI;
-import java.util.*;
-import javax.transaction.xa.XAResource;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
import java.util.zip.GZIPInputStream;
-import java.util.zip.GZIPOutputStream;
-// Java 2 enterprise packages
-import javax.transaction.RollbackException;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-import javax.transaction.xa.XAException;
-import javax.transaction.InvalidTransactionException;
-
-// Third party packages
import org.apache.log4j.Logger;
-import org.jrdf.graph.*;
-
-// Local packages
-import org.mulgara.query.*;
-import org.mulgara.resolver.spi.*;
+import org.mulgara.query.ConstraintImpl;
+import org.mulgara.query.QueryException;
+import org.mulgara.resolver.spi.BackupRestoreSession;
+import org.mulgara.resolver.spi.DatabaseMetadata;
+import org.mulgara.resolver.spi.Resolver;
+import org.mulgara.resolver.spi.ResolverSession;
+import org.mulgara.resolver.spi.SingletonStatements;
+import org.mulgara.resolver.spi.SystemResolver;
import org.mulgara.store.statement.StatementStore;
import org.mulgara.store.stringpool.SPObject;
import org.mulgara.store.stringpool.SPObjectFactory;
@@ -64,8 +66,8 @@
* An {@link Operation} that restores the state of the database from a backup
* file generated using the complementary {@link BackupOperation}.
*
- * If the database is not currently empty then the database will contain the
- * union of its current content and the content of the backup file when this
+ * If the database is not currently empty then the current contents of the database
+ * will be repalced with the content of the backup file when this
* method returns.
*
* @created 2004-10-07
@@ -85,7 +87,6 @@
Logger.getLogger(RestoreOperation.class.getName());
private final InputStream inputStream;
- private final URI serverURI;
private final URI sourceURI;
//
@@ -97,12 +98,11 @@
*
* @param inputStream a client supplied inputStream to obtain the restore
* content from. If null assume the sourceURI has been supplied.
- * @param serverURI The URI of the server to restore.
* @param sourceURI The URI of the backup file to restore from.
* @throws IllegalArgumentException if the <var>sourceURI</var> is a
* relative URI
*/
- public RestoreOperation(InputStream inputStream, URI serverURI, URI sourceURI)
+ public RestoreOperation(InputStream inputStream, URI sourceURI)
{
// Validate "sourceURI" parameter
if (sourceURI != null && sourceURI.getScheme() == null) {
@@ -111,7 +111,6 @@
}
this.inputStream = inputStream;
- this.serverURI = serverURI;
this.sourceURI = sourceURI;
}
@@ -184,7 +183,6 @@
}
- private static final int SIZEOF_LONG = 8;
private static final String TKS_NAMESPACE = "<http://pisoftware.com/tks";
private static final String TUCANA_NAMESPACE = "<http://tucana.org/tucana";
private static final String TKS_INT_MODEL_URI = TKS_NAMESPACE + "-int#model>";
@@ -197,6 +195,7 @@
* @param metadata DatabaseMetadata
* @param br BufferedReader
*/
+ @SuppressWarnings("unchecked")
private void restoreDatabaseV4(
Resolver resolver, ResolverSession resolverSession,
DatabaseMetadata metadata, BufferedReader br
Modified: trunk/src/jar/server-beep/java/org/mulgara/server/beep/BEEPSession.java
===================================================================
--- trunk/src/jar/server-beep/java/org/mulgara/server/beep/BEEPSession.java 2008-06-26 20:15:09 UTC (rev 1029)
+++ trunk/src/jar/server-beep/java/org/mulgara/server/beep/BEEPSession.java 2008-06-27 17:20:26 UTC (rev 1030)
@@ -187,11 +187,10 @@
* Backup all the data on the specified server. The database is not changed by
* this method.
*
- * @param serverURI The URI of the server to backup.
* @param destinationURI The URI of the file to backup into.
* @throws QueryException if the backup cannot be completed.
*/
- public void backup(URI serverURI, URI destinationURI) throws QueryException {
+ public void backup(URI destinationURI) throws QueryException {
throw new QueryException("Backup not implemented");
}
@@ -200,11 +199,10 @@
* Backup all the data on the specified server to an output stream.
* The database is not changed by this method.
*
- * @param serverURI The URI of the server to backup.
* @param outputStream The stream to receive the contents
* @throws QueryException if the backup cannot be completed.
*/
- public void backup(URI serverURI, OutputStream outputStream) throws QueryException {
+ public void backup(OutputStream outputStream) throws QueryException {
throw new QueryException("Backup not implemented");
}
@@ -235,30 +233,28 @@
/**
- * Restore all the data on the specified server. If the database is not
- * currently empty then the database will contain the union of its current
- * content and the content of the backup file when this method returns.
+ * Restore all the data on the server. If the database is not
+ * currently empty then the current contents of the database will be replaced
+ * with the content of the backup file when this method returns.
*
- * @param serverURI The URI of the server to restore.
* @param sourceURI The URI of the backup file to restore from.
* @throws QueryException if the restore cannot be completed.
*/
- public void restore(URI serverURI, URI sourceURI) throws QueryException {
+ public void restore(URI sourceURI) throws QueryException {
throw new QueryException("Restore not implemented");
}
/**
- * Restore all the data on the specified server. If the database is not
- * currently empty then the database will contain the union of its current
- * content and the content of the backup file when this method returns.
+ * Restore all the data on the server. If the database is not
+ * currently empty then the current contents of the database will be replaced
+ * with the content of the backup file when this method returns.
*
* @param inputStream a client supplied inputStream to obtain the restore
* content from. If null assume the sourceURI has been supplied.
- * @param serverURI The URI of the server to restore.
* @param sourceURI The URI of the backup file to restore from.
* @throws QueryException if the restore cannot be completed.
*/
- public void restore(InputStream inputStream, URI serverURI, URI sourceURI) throws QueryException {
+ public void restore(InputStream inputStream, URI sourceURI) throws QueryException {
throw new QueryException("Restore not implemented");
}
Modified: trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RemoteSession.java
===================================================================
--- trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RemoteSession.java 2008-06-26 20:15:09 UTC (rev 1029)
+++ trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RemoteSession.java 2008-06-27 17:20:26 UTC (rev 1030)
@@ -113,23 +113,21 @@
/**
* Backup the specified server. The database is not changed by this method.
*
- * @param sourceURI The URI of the server or model to backup.
* @param destinationURI The URI of the backup file to dump into.
* @throws QueryException if the backup cannot be completed.
* @throws RemoteException EXCEPTION TO DO
*/
- public void backup(URI sourceURI, URI destinationURI) throws QueryException,
+ public void backup(URI destinationURI) throws QueryException,
RemoteException;
/**
* Backup all the data on the specified server to an output stream.
* The database is not changed by this method.
*
- * @param sourceURI The URI of the server or model to backup.
* @param outputStream The stream to receive the contents
* @throws QueryException if the backup cannot be completed.
*/
- public void backup(URI sourceURI, OutputStream outputStream)
+ public void backup(OutputStream outputStream)
throws QueryException, RemoteException;
@@ -156,27 +154,25 @@
/**
* Restore the specified server.
*
- * @param serverURI The URI of the model to dump from.
* @param sourceURI The URI of the backup file to restore from.
* @throws QueryException if the restore cannot be completed.
* @throws RemoteException EXCEPTION TO DO
*/
- public void restore(URI serverURI, URI sourceURI) throws QueryException,
+ public void restore(URI sourceURI) throws QueryException,
RemoteException;
/**
- * Restore all the data on the specified server. If the database is not
- * currently empty then the database will contain the union of its current
- * content and the content of the backup file when this method returns.
+ * Restore all the data on the server. If the database is not
+ * currently empty then the current contents of the database will be replaced
+ * with the content of the backup file when this method returns.
*
* @param inputStream a client supplied inputStream to obtain the restore
* content from. If null assume the sourceURI has been supplied.
- * @param serverURI The URI of the server to restore.
* @param sourceURI The URI of the backup file to restore from.
* @throws QueryException if the restore cannot be completed.
*/
- public void restore(InputStream inputStream, URI serverURI, URI sourceURI)
+ public void restore(InputStream inputStream, URI sourceURI)
throws QueryException, RemoteException;
/**
Modified: trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RemoteSessionWrapperSession.java
===================================================================
--- trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RemoteSessionWrapperSession.java 2008-06-26 20:15:09 UTC (rev 1029)
+++ trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RemoteSessionWrapperSession.java 2008-06-27 17:20:26 UTC (rev 1030)
@@ -272,18 +272,17 @@
* Backup all the data on the specified server. The database is not changed by
* this method.
*
- * @param sourceURI The URI of the server or model to backup.
* @param destinationURI The URI of the file to backup into.
* @throws QueryException if the backup cannot be completed.
*/
- public void backup(URI sourceURI, URI destinationURI) throws QueryException {
+ public void backup(URI destinationURI) throws QueryException {
try {
- remoteSession.backup(sourceURI, destinationURI);
+ remoteSession.backup(destinationURI);
resetRetries();
} catch (RemoteException e) {
testRetry(e);
- backup(sourceURI, destinationURI);
+ backup(destinationURI);
}
}
@@ -292,18 +291,17 @@
* Backup all the data on the specified server to an output stream.
* The database is not changed by this method.
*
- * @param sourceURI The URI of the server or model to backup.
* @param outputStream The stream to receive the contents
* @throws QueryException if the backup cannot be completed.
*/
- public void backup(URI sourceURI, OutputStream outputStream) throws QueryException {
+ public void backup(OutputStream outputStream) throws QueryException {
try {
- remoteSession.backup(sourceURI, outputStream);
+ remoteSession.backup(outputStream);
resetRetries();
} catch (RemoteException e) {
testRetry(e);
- backup(sourceURI, outputStream);
+ backup(outputStream);
}
}
@@ -346,46 +344,44 @@
/**
- * Restore all the data on the specified server. If the database is not
- * currently empty then the database will contain the union of its current
- * content and the content of the backup file when this method returns.
+ * Restore all the data on the server. If the database is not
+ * currently empty then the current contents of the database will be replaced
+ * with the content of the backup file when this method returns.
*
- * @param serverURI The URI of the server to restore.
* @param sourceURI The URI of the backup file to restore from.
* @throws QueryException if the restore cannot be completed.
*/
- public void restore(URI serverURI, URI sourceURI) throws QueryException {
+ public void restore(URI sourceURI) throws QueryException {
try {
- remoteSession.restore(serverURI, sourceURI);
+ remoteSession.restore(sourceURI);
resetRetries();
} catch (RemoteException e) {
testRetry(e);
- restore(serverURI, sourceURI);
+ restore(sourceURI);
}
}
/**
- * Restore all the data on the specified server. If the database is not
- * currently empty then the database will contain the union of its current
- * content and the content of the backup file when this method returns.
+ * Restore all the data on the server. If the database is not
+ * currently empty then the current contents of the database will be replaced
+ * with the content of the backup file when this method returns.
*
* @param inputStream a client supplied inputStream to obtain the restore
* content from. If null assume the sourceURI has been supplied.
- * @param serverURI The URI of the server to restore.
* @param sourceURI The URI of the backup file to restore from.
* @throws QueryException if the restore cannot be completed.
*/
- public void restore(InputStream inputStream, URI serverURI, URI sourceURI)
+ public void restore(InputStream inputStream, URI sourceURI)
throws QueryException {
try {
- remoteSession.restore(inputStream, serverURI, sourceURI);
+ remoteSession.restore(inputStream, sourceURI);
resetRetries();
} catch (RemoteException e) {
testRetry(e);
- restore(inputStream, serverURI, sourceURI);
+ restore(inputStream, sourceURI);
}
}
Modified: trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/SessionWrapperRemoteSession.java
===================================================================
--- trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/SessionWrapperRemoteSession.java 2008-06-26 20:15:09 UTC (rev 1029)
+++ trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/SessionWrapperRemoteSession.java 2008-06-27 17:20:26 UTC (rev 1030)
@@ -180,13 +180,12 @@
* Backup all the data on the specified server. The database is not changed by
* this method.
*
- * @param sourceURI The URI of the server or model to backup.
* @param destinationURI The URI of the file to backup into.
* @throws QueryException if the backup cannot be completed.
*/
- public void backup(URI sourceURI, URI destinationURI) throws QueryException, RemoteException {
+ public void backup(URI destinationURI) throws QueryException, RemoteException {
try {
- session.backup(sourceURI, destinationURI);
+ session.backup(destinationURI);
} catch (Throwable t) {
throw convertToQueryException(t);
}
@@ -196,13 +195,12 @@
* Backup all the data on the specified server to an output stream.
* The database is not changed by this method.
*
- * @param sourceURI The URI of the server or model to backup.
* @param outputStream The stream to receive the contents
* @throws QueryException if the backup cannot be completed.
*/
- public void backup(URI sourceURI, OutputStream outputStream) throws QueryException, RemoteException {
+ public void backup(OutputStream outputStream) throws QueryException, RemoteException {
try {
- session.backup(sourceURI, outputStream);
+ session.backup(outputStream);
} catch (Throwable t) {
throw convertToQueryException(t);
}
@@ -240,36 +238,35 @@
}
/**
- * Restore all the data on the specified server. If the database is not
- * currently empty then the database will contain the union of its current
- * content and the content of the backup file when this method returns.
+ * Restore all the data on the server. If the database is not
+ * currently empty then the current contents of the database will be replaced
+ * with the content of the backup file when this method returns.
*
* @param serverURI The URI of the server to restore.
* @param sourceURI The URI of the backup file to restore from.
* @throws QueryException if the restore cannot be completed.
*/
- public void restore(URI serverURI, URI sourceURI) throws QueryException, RemoteException {
+ public void restore(URI sourceURI) throws QueryException, RemoteException {
try {
- session.restore(serverURI, sourceURI);
+ session.restore(sourceURI);
} catch (Throwable t) {
throw convertToQueryException(t);
}
}
/**
- * Restore all the data on the specified server. If the database is not
- * currently empty then the database will contain the union of its current
- * content and the content of the backup file when this method returns.
+ * Restore all the data on the server. If the database is not
+ * currently empty then the current contents of the database will be replaced
+ * with the content of the backup file when this method returns.
*
* @param inputStream a client supplied inputStream to obtain the restore
* content from. If null assume the sourceURI has been supplied.
- * @param serverURI The URI of the server to restore.
* @param sourceURI The URI of the backup file to restore from.
* @throws QueryException if the restore cannot be completed.
*/
- public void restore(InputStream inputStream, URI serverURI, URI sourceURI) throws QueryException, RemoteException {
+ public void restore(InputStream inputStream, URI sourceURI) throws QueryException, RemoteException {
try {
- session.restore(inputStream, serverURI, sourceURI);
+ session.restore(inputStream, sourceURI);
} catch (Throwable t) {
throw convertToQueryException(t);
}
More information about the Mulgara-svn
mailing list