Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<blueprints.version>2.1.0</blueprints.version>
<rexster.version>2.1.0</rexster.version>
<blueprints.version>2.5.0-SNAPSHOT</blueprints.version>
<rexster.version>2.5.0-SNAPSHOT</rexster.version>
<datomic-free.version>0.8.3538</datomic-free.version>
<joda-time.version>2.1</joda-time.version>
</properties>
Expand Down Expand Up @@ -127,4 +127,4 @@
</plugins>
</build>

</project>
</project>
4 changes: 4 additions & 0 deletions src/main/java/com/jnj/fluxgraph/FluxEdge.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,8 @@ public Set<Object> getFacts() {
return theFacts;
}

@Override
public void remove() {
fluxGraph.removeEdge(this);
}
}
12 changes: 6 additions & 6 deletions src/main/java/com/jnj/fluxgraph/FluxElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public Set<String> getPropertyKeys() {
}

@Override
public Object getProperty(final String key) {
public <T> T getProperty(final String key) {
if (isDeleted()) {
throw new IllegalArgumentException("It is not possible to get properties on a deleted element");
}
Expand All @@ -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);
}
}

Expand All @@ -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
Expand Down Expand Up @@ -152,7 +152,7 @@ public Interval getTimeInterval() {
}

@Override
public Object removeProperty(final String key) {
public <T> T removeProperty(final String key) {
validate();
Object oldvalue = getProperty(key);
if (oldvalue != null) {
Expand All @@ -163,7 +163,7 @@ public Object removeProperty(final String key) {
}
fluxGraph.addTransactionInfo(this);
fluxGraph.transact();
return oldvalue;
return (T)oldvalue;
}

@Override
Expand Down
52 changes: 38 additions & 14 deletions src/main/java/com/jnj/fluxgraph/FluxGraph.java
Original file line number Diff line number Diff line change
@@ -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.*;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -144,24 +146,37 @@ public Iterable<Edge> 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
Expand Down Expand Up @@ -286,16 +301,25 @@ public String toString() {

@Override
public <T extends Element> void dropKeyIndex(String key, Class<T> elementClass) {
if (elementClass == null) {
throw ExceptionFactory.classForElementCannotBeNull();
}
FluxUtil.removeAttributeIndex(key, elementClass, this);
}

@Override
public <T extends Element> void createKeyIndex(String key, Class<T> elementClass) {
public <T extends Element> void createKeyIndex(String key, Class<T> elementClass, Parameter... parameter) {
if (elementClass == null) {
throw ExceptionFactory.classForElementCannotBeNull();
}
FluxUtil.createAttributeIndex(key, elementClass, this);
}

@Override
public <T extends Element> Set<String> getIndexedKeys(Class<T> elementClass) {
if (elementClass == null) {
throw ExceptionFactory.classForElementCannotBeNull();
}
return FluxUtil.getIndexedAttributes(elementClass, this);
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/jnj/fluxgraph/FluxUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand All @@ -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);
}
}
}
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/com/jnj/fluxgraph/FluxVertex.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -179,4 +185,8 @@ private Iterable<Edge> getOutEdges() {
return new FluxIterable(outEdges, fluxGraph, database, Edge.class);
}

@Override
public void remove() {
fluxGraph.removeVertex(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 8 additions & 3 deletions src/test/java/com/jnj/fluxgraph/FluxGraphTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down Expand Up @@ -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")) {
Expand Down