use of org.neo4j.graphdb.RelationshipType in project neo4j by neo4j.
the class TraversalDescriptionBuilder method describeExpander.
@SuppressWarnings("unchecked")
private TraversalDescription describeExpander(TraversalDescription result, Map<String, Object> description) {
Object relationshipsDescription = description.get("relationships");
if (relationshipsDescription != null) {
Collection<Object> pairDescriptions;
if (relationshipsDescription instanceof Collection) {
pairDescriptions = (Collection<Object>) relationshipsDescription;
} else {
pairDescriptions = Arrays.asList(relationshipsDescription);
}
PathExpanderBuilder builder = createExpander(description);
for (Object pairDescription : pairDescriptions) {
Map map = (Map) pairDescription;
String name = (String) map.get("type");
RelationshipType type = RelationshipType.withName(name);
String directionName = (String) map.get("direction");
builder = directionName == null ? builder.add(type) : builder.add(type, stringToEnum(directionName, RelationshipDirection.class, true).internal);
}
PathExpander<Object> expander = builder.build();
result = result.expand(expander);
}
return result;
}
use of org.neo4j.graphdb.RelationshipType in project graphdb by neo4j-attic.
the class TestNeo4j method testBasicNodeRelationships.
@Test
public void testBasicNodeRelationships() {
Node firstNode = null;
Node secondNode = null;
Relationship rel = null;
// Create nodes and a relationship between them
firstNode = getGraphDb().createNode();
assertNotNull("Failure creating first node", firstNode);
secondNode = getGraphDb().createNode();
assertNotNull("Failure creating second node", secondNode);
rel = firstNode.createRelationshipTo(secondNode, MyRelTypes.TEST);
assertNotNull("Relationship is null", rel);
RelationshipType relType = rel.getType();
assertNotNull("Relationship's type is is null", relType);
// Verify that the node reports that it has a relationship of
// the type we created above
assertTrue(firstNode.getRelationships(relType).iterator().hasNext());
assertTrue(secondNode.getRelationships(relType).iterator().hasNext());
Iterable<Relationship> allRels = null;
// Verify that both nodes return the relationship we created above
allRels = firstNode.getRelationships();
assertTrue(this.objectExistsInIterable(rel, allRels));
allRels = firstNode.getRelationships(relType);
assertTrue(this.objectExistsInIterable(rel, allRels));
allRels = secondNode.getRelationships();
assertTrue(this.objectExistsInIterable(rel, allRels));
allRels = secondNode.getRelationships(relType);
assertTrue(this.objectExistsInIterable(rel, allRels));
// Verify that the relationship reports that it is associated with
// firstNode and secondNode
Node[] relNodes = rel.getNodes();
assertEquals("A relationship should always be connected to exactly " + "two nodes", relNodes.length, 2);
assertTrue("Relationship says that it isn't connected to firstNode", this.objectExistsInArray(firstNode, relNodes));
assertTrue("Relationship says that it isn't connected to secondNode", this.objectExistsInArray(secondNode, relNodes));
assertTrue("The other node should be secondNode but it isn't", rel.getOtherNode(firstNode).equals(secondNode));
assertTrue("The other node should be firstNode but it isn't", rel.getOtherNode(secondNode).equals(firstNode));
rel.delete();
secondNode.delete();
firstNode.delete();
}
use of org.neo4j.graphdb.RelationshipType in project graphdb by neo4j-attic.
the class TestNeo4jCacheAndPersistence method testLowGrabSize.
@Test
public void testLowGrabSize() {
Map<String, String> config = new HashMap<String, String>();
config.put("relationship_grab_size", "1");
String storePath = getStorePath("neo2");
deleteFileOrDirectory(storePath);
EmbeddedGraphDatabase graphDb = new EmbeddedGraphDatabase(storePath, config);
Transaction tx = graphDb.beginTx();
Node node1 = graphDb.createNode();
Node node2 = graphDb.createNode();
node1.createRelationshipTo(node2, MyRelTypes.TEST);
node2.createRelationshipTo(node1, MyRelTypes.TEST2);
node1.createRelationshipTo(node2, MyRelTypes.TEST_TRAVERSAL);
tx.success();
tx.finish();
tx = graphDb.beginTx();
Set<Relationship> rels = new HashSet<Relationship>();
RelationshipType[] types = new RelationshipType[] { MyRelTypes.TEST, MyRelTypes.TEST2, MyRelTypes.TEST_TRAVERSAL };
graphDb.getConfig().getGraphDbModule().getNodeManager().clearCache();
for (Relationship rel : node1.getRelationships(types)) {
assertTrue(rels.add(rel));
}
assertEquals(3, rels.size());
rels.clear();
graphDb.getConfig().getGraphDbModule().getNodeManager().clearCache();
for (Relationship rel : node1.getRelationships()) {
assertTrue(rels.add(rel));
}
assertEquals(3, rels.size());
rels.clear();
graphDb.getConfig().getGraphDbModule().getNodeManager().clearCache();
for (Relationship rel : node2.getRelationships(types)) {
assertTrue(rels.add(rel));
}
assertEquals(3, rels.size());
rels.clear();
graphDb.getConfig().getGraphDbModule().getNodeManager().clearCache();
for (Relationship rel : node2.getRelationships()) {
assertTrue(rels.add(rel));
}
assertEquals(3, rels.size());
rels.clear();
graphDb.getConfig().getGraphDbModule().getNodeManager().clearCache();
for (Relationship rel : node1.getRelationships(Direction.OUTGOING)) {
assertTrue(rels.add(rel));
}
assertEquals(2, rels.size());
rels.clear();
graphDb.getConfig().getGraphDbModule().getNodeManager().clearCache();
for (Relationship rel : node1.getRelationships(Direction.INCOMING)) {
assertTrue(rels.add(rel));
}
assertEquals(1, rels.size());
rels.clear();
graphDb.getConfig().getGraphDbModule().getNodeManager().clearCache();
for (Relationship rel : node2.getRelationships(Direction.OUTGOING)) {
assertTrue(rels.add(rel));
}
assertEquals(1, rels.size());
rels.clear();
graphDb.getConfig().getGraphDbModule().getNodeManager().clearCache();
for (Relationship rel : node2.getRelationships(Direction.INCOMING)) {
assertTrue(rels.add(rel));
}
assertEquals(2, rels.size());
tx.success();
tx.finish();
graphDb.shutdown();
}
use of org.neo4j.graphdb.RelationshipType in project neo4j-mobile-android by neo4j-contrib.
the class BatchInserterImpl method getRelationshipById.
public SimpleRelationship getRelationshipById(long relId) {
RelationshipRecord record = getRelationshipRecord(relId);
RelationshipType type = new RelationshipTypeImpl(typeHolder.getName(record.getType()));
return new SimpleRelationship(record.getId(), record.getFirstNode(), record.getSecondNode(), type);
}
use of org.neo4j.graphdb.RelationshipType in project neo4j-mobile-android by neo4j-contrib.
the class NodeImpl method getRelationships.
public Iterable<Relationship> getRelationships(NodeManager nodeManager, RelationshipType type, Direction dir) {
RelationshipType[] types = new RelationshipType[] { type };
DirectionWrapper direction = RelIdArray.wrap(dir);
return new IntArrayIterator(getAllRelationshipsOfType(nodeManager, direction, types), this, direction, nodeManager, types, !hasMoreRelationshipsToLoad());
}
Aggregations