[Mulgara-svn] r273 - branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/rmi

pag at mulgara.org pag at mulgara.org
Mon May 14 18:09:43 UTC 2007


Author: pag
Date: 2007-05-14 13:09:43 -0500 (Mon, 14 May 2007)
New Revision: 273

Added:
   branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/rmi/RemoteGlobalStatementSet.java
   branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/rmi/ShortGlobalStatementSet.java
Log:
Initial code for Serial and RMI Set implementations for remote insertions

Added: branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/rmi/RemoteGlobalStatementSet.java
===================================================================
--- branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/rmi/RemoteGlobalStatementSet.java	2007-05-14 18:09:11 UTC (rev 272)
+++ branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/rmi/RemoteGlobalStatementSet.java	2007-05-14 18:09:43 UTC (rev 273)
@@ -0,0 +1,67 @@
+package org.mulgara.resolver.distributed.rmi;
+
+import java.io.Serializable;
+import java.util.AbstractSet;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.apache.log4j.Logger;
+import org.jrdf.graph.ObjectNode;
+import org.jrdf.graph.PredicateNode;
+import org.jrdf.graph.SubjectNode;
+import org.jrdf.graph.Triple;
+import org.mulgara.itql.ItqlInterpreter;
+import org.mulgara.query.TuplesException;
+import org.mulgara.query.rdf.TripleImpl;
+import org.mulgara.resolver.spi.GlobalizeException;
+import org.mulgara.resolver.spi.ResolverSession;
+import org.mulgara.resolver.spi.Statements;
+
+/**
+ * Creates a small Set of statements that be be shipped across a network.
+ *
+ * @created 2007-04-23
+ * @author <a href="mailto:gearon at users.sourceforge.net">Paul Gearon</a>
+ * @copyright &copy; 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 GlobalStatementSet extends AbstractSet<Triple> implements RemoteGlobalStatementSet {
+  
+  private static final Logger logger = Logger.getLogger(GlobalStatementSet.class.getName());
+  
+  /**
+   * Allow newer compiled version of the stub to operate when changes
+   * have not occurred with the class.
+   * NOTE : update this serialVersionUID when a method or a public member is
+   * deleted.
+   */
+  private static final long serialVersionUID = 896369800817370415L;
+  
+  
+  /** Reference to the underlying statements. */
+  private Statements statements;
+  
+  
+  /**
+   * Builds the set of Triple data, containing globalized triples.
+   * @param statements Contains the data for the set.  This must not contain duplicates.
+   * @throws TuplesException There was an error accessing the statements.
+   * @throws GlobalizeException Some of the statements could not be globalized.
+   */
+  GlobalStatementSet(Statements statements, ResolverSession session) throws TuplesException, GlobalizeException {
+    this.statements = statements;
+  }
+
+  @Override
+  public Iterator<Triple> iterator() {
+    return null;
+  }
+
+  @Override
+  public int size() {
+    long statementSize = statements.getRowCount();
+    if (statementSize > Integer.MAX_VALUE) logger.error("Getting a set size for Statements of more than 32 bits in size");
+    return statementSize > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int)statements.getRowCount();
+  }
+
+}

Added: branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/rmi/ShortGlobalStatementSet.java
===================================================================
--- branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/rmi/ShortGlobalStatementSet.java	2007-05-14 18:09:11 UTC (rev 272)
+++ branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/rmi/ShortGlobalStatementSet.java	2007-05-14 18:09:43 UTC (rev 273)
@@ -0,0 +1,75 @@
+package org.mulgara.resolver.distributed.rmi;
+
+import java.io.Serializable;
+import java.util.AbstractSet;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.jrdf.graph.ObjectNode;
+import org.jrdf.graph.PredicateNode;
+import org.jrdf.graph.SubjectNode;
+import org.jrdf.graph.Triple;
+import org.mulgara.query.TuplesException;
+import org.mulgara.query.rdf.TripleImpl;
+import org.mulgara.resolver.spi.GlobalizeException;
+import org.mulgara.resolver.spi.ResolverSession;
+import org.mulgara.resolver.spi.Statements;
+
+/**
+ * Creates a small Set of statements that be be shipped across a network.
+ *
+ * @created 2007-04-23
+ * @author <a href="mailto:gearon at users.sourceforge.net">Paul Gearon</a>
+ * @copyright &copy; 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 ShortGlobalStatementSet extends AbstractSet<Triple> implements Serializable {
+  
+  /**
+   * Allow newer compiled version of the stub to operate when changes
+   * have not occurred with the class.
+   * NOTE : update this serialVersionUID when a method or a public member is
+   * deleted.
+   */
+  private static final long serialVersionUID = 896369800817370415L;
+  
+  
+  /** Internally, use a list as this has a shorter serialization. */
+  private ArrayList<Triple> data;
+  
+  
+  /**
+   * Builds the set of Triple data, containing globalized triples.
+   * @param statements Contains the data for the set.  This must not contain duplicates.
+   * @throws TuplesException There was an error accessing the statements.
+   * @throws GlobalizeException Some of the statements could not be globalized.
+   */
+  ShortGlobalStatementSet(Statements statements, ResolverSession session) throws TuplesException, GlobalizeException {
+    // build the array
+    long rowCount = statements.getRowCount();
+    assert rowCount < StatementSetFactory.WATER_MARK;
+    data = new ArrayList<Triple>((int)rowCount);
+    // populate the array
+    statements.beforeFirst();
+    int i = 0;
+    while (statements.next()) {
+      Triple t = new TripleImpl(
+          (SubjectNode)session.globalize(statements.getSubject()),
+          (PredicateNode)session.globalize(statements.getPredicate()),
+          (ObjectNode)session.globalize(statements.getObject())
+      );
+      data.set(i++, t);
+    }
+  }
+
+  @Override
+  public Iterator<Triple> iterator() {
+    return data.iterator();
+  }
+
+  @Override
+  public int size() {
+    return data.size();
+  }
+
+}




More information about the Mulgara-svn mailing list