[Mulgara-svn] r496 - branches/nw-interface/src/jar/query/java/org/mulgara/query/operation
pag at mulgara.org
pag at mulgara.org
Wed Oct 24 21:53:13 UTC 2007
Author: pag
Date: 2007-10-24 16:53:12 -0500 (Wed, 24 Oct 2007)
New Revision: 496
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/DataTx.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/Restore.java
Log:
Fixed the lack of local backups, and also setting backup to use source instead of serverURI
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-10-24 15:03:08 UTC (rev 495)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Backup.java 2007-10-24 21:53:12 UTC (rev 496)
@@ -53,8 +53,8 @@
* @param destination The location where to back the data up.
* Only file URLs supported at the moment.
*/
- public Backup(URI source, URI destination) {
- super(source, destination);
+ public Backup(URI source, URI destination, boolean locality) {
+ super(source, destination, source, locality);
if (!destination.getScheme().equals(FILE)) throw new IllegalArgumentException("Backups must be sent to a file");
updateServerUri(source);
}
@@ -75,17 +75,26 @@
* @throws MalformedURLException The destination is not a valid file.
*/
public Object execute(Connection conn) throws QueryException, MalformedURLException {
- 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);
+ // test if the server can do all the work, or if data needs to be streamed
+ if (isLocal()) {
+ // server does all the work
+ System.out.println("Requesting backup of: " + getSource() + " to a output: " + getDestination());
+ 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);
+ }
+
+ // send to open method for backing up to a stream
+ backup(conn, getSource(), fileOutputStream);
}
-
- backup(conn, serverUri, fileOutputStream);
-
- return setResultMessage("Successfully backed up: " + serverUri);
+
+ return setResultMessage("Successfully backed up: " + getSource());
}
@@ -108,17 +117,17 @@
throw new QueryException("Unable to backup "+ source + " to an output stream", rex);
}
- outputStream = new RemoteOutputStream(srv);
+ OutputStream marshallingOutputStream = new RemoteOutputStream(srv);
// perform the backup
try {
- conn.getSession().backup(source, outputStream);
+ conn.getSession().backup(source, marshallingOutputStream);
} finally {
// cleanup the output
- if (outputStream != null) {
+ if (marshallingOutputStream != null) {
try {
- outputStream.close();
- } catch (IOException ioe ) {};
+ marshallingOutputStream.close();
+ } catch (IOException ioe ) { /* ignore */ }
}
// cleanup the RMI for the output stream
if (srv != null) {
@@ -126,6 +135,9 @@
UnicastRemoteObject.unexportObject(srv, false);
} catch (NoSuchObjectException ex) {};
}
+ try {
+ srv.close();
+ } catch (IOException e) {}
}
}
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-10-24 15:03:08 UTC (rev 495)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/DataTx.java 2007-10-24 21:53:12 UTC (rev 496)
@@ -64,29 +64,11 @@
* @param source The source of data to insert.
* @param destination The graph or server to load data into.
*/
- public DataTx(URI source, URI destination, boolean local) {
- super(destination);
- init(source, destination, local);
- }
-
-
- /**
- * Create a new data transfer command for backup only.
- * @param source The source model or server for the data.
- * @param destination The destination for the data, currently file URLs only.
- */
- public DataTx(URI source, URI destination) {
- super(source);
- init(source, destination, false);
- }
-
- /**
- * Initializes the data structures for the constructor methods.
- * @param source The source of the data transfer.
- * @param destination The destination of the data transfer.
- * @param local Indicates if the data is local to the server, and not the client.
- */
- private void init(URI source, URI destination, boolean local) {
+ 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;
@@ -95,6 +77,7 @@
overrideStream = null;
}
+
/**
* Allows an API to set the stream for loading, instead of getting it from the
* source URI.
@@ -136,6 +119,7 @@
/**
* 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.
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-10-24 15:03:08 UTC (rev 495)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Load.java 2007-10-24 21:53:12 UTC (rev 496)
@@ -36,8 +36,14 @@
/** Model resource form of the source URI */
private 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 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, local);
+ super(source, destination, destination, local);
srcRsc = new ModelResource(source);
}
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-10-24 15:03:08 UTC (rev 495)
+++ branches/nw-interface/src/jar/query/java/org/mulgara/query/operation/Restore.java 2007-10-24 21:53:12 UTC (rev 496)
@@ -29,7 +29,7 @@
public class Restore extends DataTx {
public Restore(URI source, URI destination, boolean local) {
- super(source, destination, local);
+ super(source, destination, destination, local);
}
/**
More information about the Mulgara-svn
mailing list