diff --git a/pom.xml b/pom.xml index 0bf6941..f8f7173 100644 --- a/pom.xml +++ b/pom.xml @@ -12,8 +12,8 @@ UTF-8 - 2.1.0 - 2.1.0 + 2.5.0-SNAPSHOT + 2.5.0-SNAPSHOT 0.8.3538 2.1 @@ -127,4 +127,4 @@ - \ No newline at end of file + diff --git a/src/main/java/com/jnj/fluxgraph/FluxEdge.java b/src/main/java/com/jnj/fluxgraph/FluxEdge.java index 5b9009e..59174bf 100644 --- a/src/main/java/com/jnj/fluxgraph/FluxEdge.java +++ b/src/main/java/com/jnj/fluxgraph/FluxEdge.java @@ -104,4 +104,8 @@ public Set getFacts() { return theFacts; } + @Override + public void remove() { + fluxGraph.removeEdge(this); + } } diff --git a/src/main/java/com/jnj/fluxgraph/FluxElement.java b/src/main/java/com/jnj/fluxgraph/FluxElement.java index 047b2a0..9f02121 100644 --- a/src/main/java/com/jnj/fluxgraph/FluxElement.java +++ b/src/main/java/com/jnj/fluxgraph/FluxElement.java @@ -73,7 +73,7 @@ public Set getPropertyKeys() { } @Override - public Object getProperty(final String key) { + public T getProperty(final String key) { if (isDeleted()) { throw new IllegalArgumentException("It is not possible to get properties on a deleted element"); } @@ -85,14 +85,14 @@ public Object getProperty(final String key) { Keyword property = propertiesit.next(); String propertyname = FluxUtil.getPropertyName(property); if (key.equals(propertyname)) { - return getDatabase().entity(id).get(property); + return (T)getDatabase().entity(id).get(property); } } // We didn't find the value return null; } else { - return getDatabase().entity(id).get(key); + return (T)getDatabase().entity(id).get(key); } } @@ -104,7 +104,7 @@ public void setProperty(final String key, final Object value) { if (key.equals(StringFactory.LABEL)) throw new IllegalArgumentException("Property key is reserved for all nodes and edges: " + StringFactory.LABEL); if (key.equals(StringFactory.EMPTY_STRING)) - throw ExceptionFactory.elementKeyCanNotBeEmpty(); + throw ExceptionFactory.propertyKeyCanNotBeEmpty(); // A user-defined property if (!FluxUtil.isReservedKey(key)) { // If the property does not exist yet, create the attribute if required and create the appropriate transaction @@ -152,7 +152,7 @@ public Interval getTimeInterval() { } @Override - public Object removeProperty(final String key) { + public T removeProperty(final String key) { validate(); Object oldvalue = getProperty(key); if (oldvalue != null) { @@ -163,7 +163,7 @@ public Object removeProperty(final String key) { } fluxGraph.addTransactionInfo(this); fluxGraph.transact(); - return oldvalue; + return (T)oldvalue; } @Override diff --git a/src/main/java/com/jnj/fluxgraph/FluxGraph.java b/src/main/java/com/jnj/fluxgraph/FluxGraph.java index 37374a3..df23d4b 100644 --- a/src/main/java/com/jnj/fluxgraph/FluxGraph.java +++ b/src/main/java/com/jnj/fluxgraph/FluxGraph.java @@ -1,6 +1,8 @@ package com.jnj.fluxgraph; +import clojure.lang.ExceptionInfo; import com.tinkerpop.blueprints.*; +import com.tinkerpop.blueprints.util.DefaultGraphQuery; import com.tinkerpop.blueprints.util.ExceptionFactory; import com.tinkerpop.blueprints.util.StringFactory; import datomic.*; @@ -51,7 +53,7 @@ protected Date initialValue() { FEATURES.supportsDuplicateEdges = true; FEATURES.supportsSelfLoops = true; FEATURES.isPersistent = false; - FEATURES.isRDFModel = false; + //FEATURES.isRDFModel = false; FEATURES.supportsVertexIteration = true; FEATURES.supportsEdgeIteration = true; FEATURES.supportsVertexIndex = false; @@ -144,24 +146,37 @@ public Iterable getEdges(String key, Object value) { return edgeIndex.get(key, value); } + @Override + public GraphQuery query() { + return new DefaultGraphQuery(this); + } + @Override public TimeAwareEdge addEdge(final Object id, final Vertex outVertex, final Vertex inVertex, final String label) { // Create the new edge - final FluxEdge edge = new FluxEdge(this, null); - tx.get().add(Util.map(":db/id", edge.id, - ":graph.edge/label", label, - ":graph.edge/inVertex", inVertex.getId(), - ":graph.edge/outVertex", outVertex.getId())); + try { + final FluxEdge edge = new FluxEdge(this, null); + tx.get().add(Util.map(":db/id", edge.id, + ":graph.edge/label", label, + ":graph.edge/inVertex", inVertex.getId(), + ":graph.edge/outVertex", outVertex.getId())); - // Update the transaction info of both vertices (moving up their current transaction) - addTransactionInfo((TimeAwareVertex)inVertex, (TimeAwareVertex)outVertex); + // Update the transaction info of both vertices (moving up their current transaction) + addTransactionInfo((TimeAwareVertex)inVertex, (TimeAwareVertex)outVertex); - // Transact - transact(); + // Transact + transact(); - // Set the real id on the entity - edge.id = getRawGraph().entid(edge.uuid); - return edge; + // Set the real id on the entity + edge.id = getRawGraph().entid(edge.uuid); + return edge; + } catch (ExceptionInfo e) { + if (e.toString().contains("not a valid :string for attribute")) { + throw new IllegalArgumentException(e.toString()); + } else { + throw e; + } + } } @Override @@ -286,16 +301,25 @@ public String toString() { @Override public void dropKeyIndex(String key, Class elementClass) { + if (elementClass == null) { + throw ExceptionFactory.classForElementCannotBeNull(); + } FluxUtil.removeAttributeIndex(key, elementClass, this); } @Override - public void createKeyIndex(String key, Class elementClass) { + public void createKeyIndex(String key, Class elementClass, Parameter... parameter) { + if (elementClass == null) { + throw ExceptionFactory.classForElementCannotBeNull(); + } FluxUtil.createAttributeIndex(key, elementClass, this); } @Override public Set getIndexedKeys(Class elementClass) { + if (elementClass == null) { + throw ExceptionFactory.classForElementCannotBeNull(); + } return FluxUtil.getIndexedAttributes(elementClass, this); } diff --git a/src/main/java/com/jnj/fluxgraph/FluxUtil.java b/src/main/java/com/jnj/fluxgraph/FluxUtil.java index db83016..e613d60 100644 --- a/src/main/java/com/jnj/fluxgraph/FluxUtil.java +++ b/src/main/java/com/jnj/fluxgraph/FluxUtil.java @@ -73,9 +73,9 @@ public static void createAttributeDefinition(final String key, final Class value ":db.install/_attribute", ":db.part/db"), datomic.Util.map(":db/id", datomic.Peer.tempid(":db.part/tx"), ":db/txInstant", graph.getTransactionTime()))).get(); } } catch (InterruptedException e) { - throw new RuntimeException(FluxGraph.DATOMIC_ERROR_EXCEPTION_MESSAGE); + throw new RuntimeException(FluxGraph.DATOMIC_ERROR_EXCEPTION_MESSAGE, e); } catch (ExecutionException e) { - throw new RuntimeException(FluxGraph.DATOMIC_ERROR_EXCEPTION_MESSAGE); + throw new RuntimeException(FluxGraph.DATOMIC_ERROR_EXCEPTION_MESSAGE, e); } } } @@ -94,11 +94,11 @@ public static void setAttributeIndex(final String key, final Class elementClazz, graph.getConnection().transact(Util.list(Util.map(":db/id", attribute, ":db/index", index))).get(); } catch(ClassNotFoundException e) { - throw new RuntimeException(FluxGraph.DATOMIC_ERROR_EXCEPTION_MESSAGE); + throw new RuntimeException(FluxGraph.DATOMIC_ERROR_EXCEPTION_MESSAGE, e); } catch (InterruptedException e) { - throw new RuntimeException(FluxGraph.DATOMIC_ERROR_EXCEPTION_MESSAGE); + throw new RuntimeException(FluxGraph.DATOMIC_ERROR_EXCEPTION_MESSAGE, e); } catch (ExecutionException e) { - throw new RuntimeException(FluxGraph.DATOMIC_ERROR_EXCEPTION_MESSAGE); + throw new RuntimeException(FluxGraph.DATOMIC_ERROR_EXCEPTION_MESSAGE, e); } } } diff --git a/src/main/java/com/jnj/fluxgraph/FluxVertex.java b/src/main/java/com/jnj/fluxgraph/FluxVertex.java index 7fb5fd0..badcc2b 100644 --- a/src/main/java/com/jnj/fluxgraph/FluxVertex.java +++ b/src/main/java/com/jnj/fluxgraph/FluxVertex.java @@ -2,6 +2,7 @@ import com.tinkerpop.blueprints.*; import com.tinkerpop.blueprints.util.DefaultQuery; +import com.tinkerpop.blueprints.util.DefaultVertexQuery; import com.tinkerpop.blueprints.util.MultiIterable; import com.tinkerpop.blueprints.util.StringFactory; import datomic.*; @@ -122,8 +123,13 @@ public String toString() { } @Override - public Query query() { - return new DefaultQuery(this); + public VertexQuery query() { + return new DefaultVertexQuery(this); + } + + @Override + public Edge addEdge(String label, Vertex vertex) { + return fluxGraph.addEdge(null, this, vertex, label); } @Override @@ -179,4 +185,8 @@ private Iterable getOutEdges() { return new FluxIterable(outEdges, fluxGraph, database, Edge.class); } + @Override + public void remove() { + fluxGraph.removeVertex(this); + } } diff --git a/src/main/java/com/tinkerpop/rexster/config/FluxGraphConfiguration.java b/src/main/java/com/tinkerpop/rexster/config/FluxGraphConfiguration.java index 2f684e5..eae71fe 100644 --- a/src/main/java/com/tinkerpop/rexster/config/FluxGraphConfiguration.java +++ b/src/main/java/com/tinkerpop/rexster/config/FluxGraphConfiguration.java @@ -24,8 +24,8 @@ public class FluxGraphConfiguration implements GraphConfiguration { @Override - public Graph configureGraphInstance(Configuration properties) throws GraphConfigurationException { - final String graphFile = properties.getString(Tokens.REXSTER_GRAPH_LOCATION); + public Graph configureGraphInstance(GraphConfigurationContext context) throws GraphConfigurationException { + final String graphFile = context.getProperties().getString(Tokens.REXSTER_GRAPH_LOCATION); if (graphFile == null || graphFile.length() == 0) { throw new GraphConfigurationException("Check graph configuration. Missing or empty configuration element: " + Tokens.REXSTER_GRAPH_LOCATION); diff --git a/src/test/java/com/jnj/fluxgraph/FluxGraphTest.java b/src/test/java/com/jnj/fluxgraph/FluxGraphTest.java index 1415847..522f85f 100644 --- a/src/test/java/com/jnj/fluxgraph/FluxGraphTest.java +++ b/src/test/java/com/jnj/fluxgraph/FluxGraphTest.java @@ -44,7 +44,7 @@ public void testGraphTestSuite() throws Exception { public void testQueryTestSuite() throws Exception { this.stopWatch(); - doTestSuite(new QueryTestSuite(this)); + doTestSuite(new GraphQueryTestSuite(this)); printTestPerformance("QueryTestSuite", this.stopWatch()); } @@ -72,11 +72,16 @@ public void testGMLReaderTestSuite() throws Exception { printTestPerformance("GMLReaderTestSuite", this.stopWatch()); } - public Graph generateGraph() { - this.currentGraph = new FluxGraph("datomic:mem://tinkerpop" + UUID.randomUUID()); + public Graph generateGraph(String name) { + this.currentGraph = new FluxGraph("datomic:mem://tinkerpop" + name + UUID.randomUUID()); return this.currentGraph; } + @Override + public Graph generateGraph() { + return generateGraph(""); + } + public void doTestSuite(final TestSuite testSuite) throws Exception { for (Method method : testSuite.getClass().getDeclaredMethods()) { if (method.getName().startsWith("test")) {