[Mulgara-svn] r735 - trunk/src/jar/query/java/org/mulgara/query/operation

pag at mulgara.org pag at mulgara.org
Fri Apr 4 03:59:41 UTC 2008


Author: pag
Date: 2008-04-03 20:59:41 -0700 (Thu, 03 Apr 2008)
New Revision: 735

Modified:
   trunk/src/jar/query/java/org/mulgara/query/operation/DataTx.java
   trunk/src/jar/query/java/org/mulgara/query/operation/Load.java
   trunk/src/jar/query/java/org/mulgara/query/operation/Restore.java
Log:
Changed marshalled data transfer to decompress LOAD files, but to send RESTORE data raw (which is always compressed). LOADS cannot be done compressed, as the Session interface does not allow for a compressed 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-04-04 03:56:34 UTC (rev 734)
+++ trunk/src/jar/query/java/org/mulgara/query/operation/DataTx.java	2008-04-04 03:59:41 UTC (rev 735)
@@ -125,7 +125,7 @@
    * @throws QueryException There was an error working with data at the server end.
    * @throws IOException There was an error transferring data over the network.
    */
-  protected long sendMarshalledData(Connection conn) throws QueryException, IOException {
+  protected long sendMarshalledData(Connection conn, boolean compressable) throws QueryException, IOException {
     if (logger.isInfoEnabled()) logger.info("loading local resource : " + source);
 
     RemoteInputStreamSrvImpl srv = null;
@@ -133,7 +133,9 @@
     try {
 
       // is the file/stream compressed?
-      InputStream inputStream = adjustForCompression(source.toURL());
+      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);

Modified: trunk/src/jar/query/java/org/mulgara/query/operation/Load.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/operation/Load.java	2008-04-04 03:56:34 UTC (rev 734)
+++ trunk/src/jar/query/java/org/mulgara/query/operation/Load.java	2008-04-04 03:59:41 UTC (rev 735)
@@ -57,7 +57,7 @@
     URI src = getSource();
     URI dest = getDestination();
     try {
-      long stmtCount = isLocal() ? sendMarshalledData(conn) : conn.getSession().setModel(dest, srcRsc);
+      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);

Modified: trunk/src/jar/query/java/org/mulgara/query/operation/Restore.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/operation/Restore.java	2008-04-04 03:56:34 UTC (rev 734)
+++ trunk/src/jar/query/java/org/mulgara/query/operation/Restore.java	2008-04-04 03:59:41 UTC (rev 735)
@@ -14,6 +14,8 @@
 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;
@@ -48,8 +50,9 @@
   public Object execute(Connection conn) throws QueryException {
     URI src = getSource();
     URI dest = getDestination();
+    if (serverTest(dest)) throw new QueryException("Cannot restore to a graph. Must be a server URI.");
     try {
-      if (isLocal()) sendMarshalledData(conn);
+      if (isLocal()) sendMarshalledData(conn, false);
       else conn.getSession().restore(dest, src);
 
       if (logger.isDebugEnabled()) logger.debug("Completed restoring " + dest + " from " + src);
@@ -72,4 +75,23 @@
     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;
+  }
 }




More information about the Mulgara-svn mailing list