Search in sources :

Example 81 with RelationshipType

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();
    }
}
Also used : Path(org.neo4j.graphdb.Path) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) RelationshipType(org.neo4j.graphdb.RelationshipType) Test(org.junit.Test)

Example 82 with RelationshipType

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());
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) RelationshipType(org.neo4j.graphdb.RelationshipType) RelationshipIndex(org.neo4j.graphdb.index.RelationshipIndex) Test(org.junit.Test)

Example 83 with RelationshipType

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);
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) RelationshipType(org.neo4j.graphdb.RelationshipType) Map(java.util.Map) HashMap(java.util.HashMap) MapUtil.stringMap(org.neo4j.helpers.collection.MapUtil.stringMap) Test(org.junit.Test)

Example 84 with RelationshipType

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();
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) RelationshipType(org.neo4j.graphdb.RelationshipType) RelationshipIndex(org.neo4j.graphdb.index.RelationshipIndex) Test(org.junit.Test)

Example 85 with RelationshipType

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();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Label(org.neo4j.graphdb.Label) RelationshipType(org.neo4j.graphdb.RelationshipType) Test(org.junit.Test)

Aggregations

RelationshipType (org.neo4j.graphdb.RelationshipType)97 Node (org.neo4j.graphdb.Node)53 Test (org.junit.Test)45 Relationship (org.neo4j.graphdb.Relationship)38 Transaction (org.neo4j.graphdb.Transaction)18 Direction (org.neo4j.graphdb.Direction)15 Traverser (org.neo4j.graphdb.Traverser)10 NotFoundException (org.neo4j.graphdb.NotFoundException)9 DynamicRelationshipType (org.neo4j.graphdb.DynamicRelationshipType)7 Label (org.neo4j.graphdb.Label)7 RelationshipRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)7 Collection (java.util.Collection)6 HashSet (java.util.HashSet)6 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)6 Path (org.neo4j.graphdb.Path)6 StopEvaluator (org.neo4j.graphdb.StopEvaluator)6 TraversalPosition (org.neo4j.graphdb.TraversalPosition)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 LinkedList (java.util.LinkedList)4