use of org.neo4j.graphdb.RelationshipType in project neo4j by neo4j.
the class TestUniqueness method nodeGlobalUniqueness.
@Test
public void nodeGlobalUniqueness() {
/*
* (a)-TO->(b)-TO->(c)
* \----TO---->/
*/
createGraph("a TO b", "a TO c", "b TO c");
RelationshipType to = withName("TO");
try (Transaction tx = beginTx()) {
Node a = getNodeWithName("a");
Node c = getNodeWithName("c");
Iterator<Path> path = getGraphDb().traversalDescription().relationships(to, OUTGOING).uniqueness(NODE_GLOBAL).evaluator(includeWhereEndNodeIs(c)).traverse(a).iterator();
Path thePath = path.next();
assertFalse(path.hasNext());
NodePathRepresentation pathRepresentation = new NodePathRepresentation(NAME_PROPERTY_REPRESENTATION);
assertEquals("a,b,c", pathRepresentation.represent(thePath));
tx.success();
}
}
use of org.neo4j.graphdb.RelationshipType in project neo4j by neo4j.
the class TestLuceneIndex method shouldNotSeeDeletedRelationshipWhenQueryingWithStartAndEndNode.
@Test
public void shouldNotSeeDeletedRelationshipWhenQueryingWithStartAndEndNode() {
// GIVEN
RelationshipIndex index = relationshipIndex(EXACT_CONFIG);
Node start = graphDb.createNode();
Node end = graphDb.createNode();
RelationshipType type = withName("REL");
Relationship rel = start.createRelationshipTo(end, type);
index.add(rel, "Type", type.name());
finishTx(true);
beginTx();
// WHEN
IndexHits<Relationship> hits = index.get("Type", type.name(), start, end);
assertEquals(1, count(hits));
assertEquals(1, hits.size());
index.remove(rel);
// THEN
hits = index.get("Type", type.name(), start, end);
assertEquals(0, count(hits));
assertEquals(0, hits.size());
}
use of org.neo4j.graphdb.RelationshipType in project neo4j by neo4j.
the class TestLuceneIndex method getOrCreateRelationshipWithUniqueFactory.
@Test
public void getOrCreateRelationshipWithUniqueFactory() throws Exception {
final String key = "name";
final String value = "Mattias";
final Node root = graphDb.createNode();
final Index<Relationship> index = relationshipIndex(LuceneIndexImplementation.EXACT_CONFIG);
final RelationshipType type = withName("SINGLE");
UniqueFactory<Relationship> factory = new UniqueFactory.UniqueRelationshipFactory(index) {
@Override
protected Relationship create(Map<String, Object> properties) {
assertEquals(value, properties.get(key));
assertEquals(1, properties.size());
return root.createRelationshipTo(graphDatabase().createNode(), type);
}
};
Relationship unique = factory.getOrCreate(key, value);
assertEquals(unique, root.getSingleRelationship(type, Direction.BOTH));
assertNotNull(unique);
assertEquals(unique, index.get(key, value).getSingle());
assertEquals(unique, factory.getOrCreate(key, value));
assertEquals(unique, root.getSingleRelationship(type, Direction.BOTH));
assertEquals(unique, index.get(key, value).getSingle());
finishTx(false);
}
use of org.neo4j.graphdb.RelationshipType in project neo4j by neo4j.
the class TestLuceneIndex method testNodeLocalRelationshipIndex.
@Test
public void testNodeLocalRelationshipIndex() {
RelationshipIndex index = relationshipIndex(LuceneIndexImplementation.EXACT_CONFIG);
RelationshipType type = withName("YO");
Node startNode = graphDb.createNode();
Node endNode1 = graphDb.createNode();
Node endNode2 = graphDb.createNode();
Relationship rel1 = startNode.createRelationshipTo(endNode1, type);
Relationship rel2 = startNode.createRelationshipTo(endNode2, type);
index.add(rel1, "name", "something");
index.add(rel2, "name", "something");
for (int i = 0; i < 2; i++) {
assertThat(index.query("name:something"), Contains.contains(rel1, rel2));
assertThat(index.query("name:something", null, endNode1), Contains.contains(rel1));
assertThat(index.query("name:something", startNode, endNode2), Contains.contains(rel2));
assertThat(index.query(null, startNode, endNode1), Contains.contains(rel1));
assertThat(index.get("name", "something", null, endNode1), Contains.contains(rel1));
assertThat(index.get("name", "something", startNode, endNode2), Contains.contains(rel2));
assertThat(index.get(null, null, startNode, endNode1), Contains.contains(rel1));
restartTx();
}
rel2.delete();
rel1.delete();
startNode.delete();
endNode1.delete();
endNode2.delete();
index.delete();
}
use of org.neo4j.graphdb.RelationshipType in project neo4j by neo4j.
the class IndexValuesValidationTest method validateLegacyIndexedRelationshipProperties.
@Test
public void validateLegacyIndexedRelationshipProperties() {
Label label = Label.label("legacyIndexedRelationshipPropertiesTestLabel");
String propertyName = "legacyIndexedRelationshipProperties";
String legacyIndexedRelationshipIndex = "legacyIndexedRelationshipIndex";
RelationshipType indexType = RelationshipType.withName("legacyIndexType");
try (Transaction transaction = database.beginTx()) {
Node source = database.createNode(label);
Node destination = database.createNode(label);
Relationship relationship = source.createRelationshipTo(destination, indexType);
database.index().forRelationships(legacyIndexedRelationshipIndex).add(relationship, propertyName, "shortString");
transaction.success();
}
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Property value bytes length: 32767 is longer then 32766, " + "which is maximum supported length of indexed property value.");
try (Transaction transaction = database.beginTx()) {
Node source = database.createNode(label);
Node destination = database.createNode(label);
Relationship relationship = source.createRelationshipTo(destination, indexType);
String longValue = StringUtils.repeat("a", IndexWriter.MAX_TERM_LENGTH + 1);
database.index().forRelationships(legacyIndexedRelationshipIndex).add(relationship, propertyName, longValue);
transaction.success();
}
}
Aggregations