Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/tinkerpop/blueprints
Browse files Browse the repository at this point in the history
  • Loading branch information
lvca committed Jul 26, 2012
2 parents a13663d + a9d145f commit 0fced7a
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 74 deletions.
Expand Up @@ -7,7 +7,6 @@
import com.tinkerpop.blueprints.util.ExceptionFactory;
import com.tinkerpop.blueprints.util.StringFactory;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.NotFoundException;
import org.neo4j.graphdb.PropertyContainer;
import org.neo4j.graphdb.Relationship;

Expand Down Expand Up @@ -44,26 +43,31 @@ public void setProperty(final String key, final Object value) {
if (key.equals(StringFactory.EMPTY_STRING))
throw ExceptionFactory.elementKeyCanNotBeEmpty();

try {
// attempts to take a collection and convert it to an array so that Neo4j can consume it
this.graph.autoStartTransaction();
this.rawElement.setProperty(key, tryConvertCollectionToArray(value));
} catch (IllegalArgumentException iae) {
throw iae;
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
//try {
// attempts to take a collection and convert it to an array so that Neo4j can consume it
this.graph.autoStartTransaction();
this.rawElement.setProperty(key, tryConvertCollectionToArray(value));
//} catch (IllegalArgumentException iae) {
// throw iae;
//} catch (Exception e) {
// throw new RuntimeException(e.getMessage(), e);
//}
}

public Object removeProperty(final String key) {
try {
//try {

if (!this.rawElement.hasProperty(key))
return null;
else {
this.graph.autoStartTransaction();
return this.rawElement.removeProperty(key);
} catch (NotFoundException e) {
return null;
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
//} catch (NotFoundException e) {
// return null;
//} catch (Exception e) {
// throw new RuntimeException(e.getMessage(), e);
//}
}

public Set<String> getPropertyKeys() {
Expand Down Expand Up @@ -111,7 +115,7 @@ private Object tryConvertCollectionToArray(final Object value) {
array[i] = object;
}
return array;
} catch (ArrayStoreException ase) {
} catch (final ArrayStoreException ase) {
// this fires off if the collection is not all of the same type
return value;
}
Expand Down
Expand Up @@ -263,21 +263,21 @@ public <T extends Element> Index<T> getIndex(final String indexName, final Class
*/
public synchronized void dropIndex(final String indexName) {
this.autoStartTransaction();
try {
if (this.rawGraph.index().existsForNodes(indexName)) {
org.neo4j.graphdb.index.Index<Node> nodeIndex = this.rawGraph.index().forNodes(indexName);
if (nodeIndex.isWriteable()) {
nodeIndex.delete();
}
} else if (this.rawGraph.index().existsForRelationships(indexName)) {
RelationshipIndex relationshipIndex = this.rawGraph.index().forRelationships(indexName);
if (relationshipIndex.isWriteable()) {
relationshipIndex.delete();
}
//try {
if (this.rawGraph.index().existsForNodes(indexName)) {
org.neo4j.graphdb.index.Index<Node> nodeIndex = this.rawGraph.index().forNodes(indexName);
if (nodeIndex.isWriteable()) {
nodeIndex.delete();
}
} else if (this.rawGraph.index().existsForRelationships(indexName)) {
RelationshipIndex relationshipIndex = this.rawGraph.index().forRelationships(indexName);
if (relationshipIndex.isWriteable()) {
relationshipIndex.delete();
}
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
//} catch (Exception e) {
// throw new RuntimeException(e.getMessage(), e);
//}
this.stopTransaction(Conclusion.SUCCESS);
}

Expand All @@ -297,14 +297,14 @@ public Iterable<Index<? extends Element>> getIndices() {


public Vertex addVertex(final Object id) {
try {
this.autoStartTransaction();
return new Neo4jVertex(this.rawGraph.createNode(), this);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
//try {
this.autoStartTransaction();
return new Neo4jVertex(this.rawGraph.createNode(), this);
//} catch (RuntimeException e) {
// throw e;
//} catch (Exception e) {
// throw new RuntimeException(e.getMessage(), e);
//}
}

public Vertex getVertex(final Object id) {
Expand Down Expand Up @@ -427,27 +427,27 @@ public void removeVertex(final Vertex vertex) {
final Long id = (Long) vertex.getId();
final Node node = this.rawGraph.getNodeById(id);
if (null != node) {
try {
for (final Edge edge : vertex.getEdges(Direction.BOTH)) {
((Relationship) ((Neo4jEdge) edge).getRawElement()).delete();
}
node.delete();
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
//try {
for (final Edge edge : vertex.getEdges(Direction.BOTH)) {
((Relationship) ((Neo4jEdge) edge).getRawElement()).delete();
}
node.delete();
//} catch (Exception e) {
// throw new RuntimeException(e.getMessage(), e);
//}
}
}

public Edge addEdge(final Object id, final Vertex outVertex, final Vertex inVertex, final String label) {
try {
this.autoStartTransaction();
final Node outNode = ((Neo4jVertex) outVertex).getRawVertex();
final Node inNode = ((Neo4jVertex) inVertex).getRawVertex();
final Relationship relationship = outNode.createRelationshipTo(inNode, DynamicRelationshipType.withName(label));
return new Neo4jEdge(relationship, this);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
//try {
this.autoStartTransaction();
final Node outNode = ((Neo4jVertex) outVertex).getRawVertex();
final Node inNode = ((Neo4jVertex) inVertex).getRawVertex();
final Relationship relationship = outNode.createRelationshipTo(inNode, DynamicRelationshipType.withName(label));
return new Neo4jEdge(relationship, this);
// } catch (Exception e) {
// throw new RuntimeException(e.getMessage(), e);
//}
}

public Edge getEdge(final Object id) {
Expand All @@ -470,12 +470,12 @@ public Edge getEdge(final Object id) {


public void removeEdge(final Edge edge) {
try {
this.autoStartTransaction();
((Relationship) ((Neo4jEdge) edge).getRawElement()).delete();
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
// try {
this.autoStartTransaction();
((Relationship) ((Neo4jEdge) edge).getRawElement()).delete();
// } catch (Exception e) {
// throw new RuntimeException(e.getMessage(), e);
// }
}

public void stopTransaction(final Conclusion conclusion) {
Expand All @@ -497,13 +497,10 @@ public void stopTransaction(final Conclusion conclusion) {
public void shutdown() {
//todo inspect why certain transactions fail
try {
if (null != tx.get()) {
tx.get().success();
tx.get().finish();
tx.remove();
}
this.stopTransaction(Conclusion.SUCCESS);
} catch (TransactionFailureException e) {
}

this.rawGraph.shutdown();
}

Expand Down
@@ -1,10 +1,8 @@
package com.tinkerpop.blueprints;

import com.tinkerpop.blueprints.impls.GraphTest;
import com.tinkerpop.blueprints.impls.tg.TinkerGraph;
import com.tinkerpop.blueprints.util.io.MockSerializable;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
Expand Down Expand Up @@ -101,10 +99,10 @@ public void testSemanticallyCorrectIterables() {
}
assertEquals(counter, 15);
}

graph.shutdown();
}


public void testGettingVerticesAndEdgesWithKeyValue() {
Graph graph = graphTest.generateGraph();
Expand Down Expand Up @@ -164,16 +162,18 @@ public void testAddingVerticesAndEdges() {
}
try {
graph.removeEdge(edge);
if (graph.getFeatures().supportsEdgeIteration) {
assertEquals(0, count(graph.getEdges()));
}
if (graph.getFeatures().supportsVertexIteration) {
assertEquals(1, count(graph.getVertices()));
}
//TODO: doesn't work with wrapper graphs assertTrue(false);
} catch (Exception e) {
assertTrue(true);
}

if (graph.getFeatures().supportsEdgeIteration) {
assertEquals(0, count(graph.getEdges()));
}
if (graph.getFeatures().supportsVertexIteration) {
assertEquals(1, count(graph.getVertices()));
}

graph.shutdown();
}

Expand Down

0 comments on commit 0fced7a

Please sign in to comment.