Search in sources :

Example 1 with RelationshipIndex

use of org.neo4j.graphdb.index.RelationshipIndex in project neo4j by neo4j.

the class TestAutoIndexing method testGettingAutoIndexByNameReturnsSomethingReadOnly.

@Test
public void testGettingAutoIndexByNameReturnsSomethingReadOnly() {
    // Create the node and relationship auto-indexes
    graphDb.index().getNodeAutoIndexer().setEnabled(true);
    graphDb.index().getNodeAutoIndexer().startAutoIndexingProperty("nodeProp");
    graphDb.index().getRelationshipAutoIndexer().setEnabled(true);
    graphDb.index().getRelationshipAutoIndexer().startAutoIndexingProperty("relProp");
    newTransaction();
    Node node1 = graphDb.createNode();
    Node node2 = graphDb.createNode();
    Relationship rel = node1.createRelationshipTo(node2, RelationshipType.withName("FOO"));
    node1.setProperty("nodeProp", "nodePropValue");
    rel.setProperty("relProp", "relPropValue");
    newTransaction();
    assertEquals(1, graphDb.index().nodeIndexNames().length);
    assertEquals(1, graphDb.index().relationshipIndexNames().length);
    assertEquals("node_auto_index", graphDb.index().nodeIndexNames()[0]);
    assertEquals("relationship_auto_index", graphDb.index().relationshipIndexNames()[0]);
    Index<Node> nodeIndex = graphDb.index().forNodes("node_auto_index");
    RelationshipIndex relIndex = graphDb.index().forRelationships("relationship_auto_index");
    assertEquals(node1, nodeIndex.get("nodeProp", "nodePropValue").getSingle());
    assertEquals(rel, relIndex.get("relProp", "relPropValue").getSingle());
    try {
        nodeIndex.add(null, null, null);
        fail("Auto indexes should not allow external manipulation");
    } catch (UnsupportedOperationException e) {
    // good
    }
    try {
        relIndex.add(null, null, null);
        fail("Auto indexes should not allow external manipulation");
    } catch (UnsupportedOperationException e) {
    // good
    }
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) RelationshipIndex(org.neo4j.graphdb.index.RelationshipIndex) Test(org.junit.Test)

Example 2 with RelationshipIndex

use of org.neo4j.graphdb.index.RelationshipIndex in project neo4j by neo4j.

the class TestLuceneIndex method makeSureYouCanRemoveFromRelationshipIndex.

@Test
public void makeSureYouCanRemoveFromRelationshipIndex() {
    Node n1 = graphDb.createNode();
    Node n2 = graphDb.createNode();
    Relationship r = n1.createRelationshipTo(n2, withName("foo"));
    RelationshipIndex index = graphDb.index().forRelationships("rel-index");
    String key = "bar";
    index.remove(r, key, "value");
    index.add(r, key, "otherValue");
    for (int i = 0; i < 2; i++) {
        assertThat(index.get(key, "value"), emptyIterable());
        assertThat(index.get(key, "otherValue"), Contains.contains(r));
        restartTx();
    }
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) RelationshipIndex(org.neo4j.graphdb.index.RelationshipIndex) Test(org.junit.Test)

Example 3 with RelationshipIndex

use of org.neo4j.graphdb.index.RelationshipIndex in project neo4j by neo4j.

the class TestLuceneIndex method shouldNotBeAbleToAddNullValuesToRelationshipIndex.

@Test
public void shouldNotBeAbleToAddNullValuesToRelationshipIndex() throws Exception {
    // GIVEN
    RelationshipIndex index = relationshipIndex(EXACT_CONFIG);
    // WHEN single null
    try {
        index.add(graphDb.createNode().createRelationshipTo(graphDb.createNode(), MyRelTypes.TEST), "key", null);
        fail("Should have failed");
    } catch (IllegalArgumentException e) {
    // THEN Good
    }
    // WHEN null in array
    try {
        index.add(graphDb.createNode().createRelationshipTo(graphDb.createNode(), MyRelTypes.TEST), "key", new String[] { "a", null, "c" });
        fail("Should have failed");
    } catch (IllegalArgumentException e) {
    // THEN Good
    }
}
Also used : RelationshipIndex(org.neo4j.graphdb.index.RelationshipIndex) Test(org.junit.Test)

Example 4 with RelationshipIndex

use of org.neo4j.graphdb.index.RelationshipIndex in project neo4j by neo4j.

the class GraphDbHelper method createRelationshipIndex.

public Index<Relationship> createRelationshipIndex(String named) {
    try (Transaction transaction = database.getGraph().beginTransaction(implicit, AUTH_DISABLED)) {
        RelationshipIndex relationshipIndex = database.getGraph().index().forRelationships(named);
        transaction.success();
        return relationshipIndex;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) RelationshipIndex(org.neo4j.graphdb.index.RelationshipIndex)

Example 5 with RelationshipIndex

use of org.neo4j.graphdb.index.RelationshipIndex in project neo4j-mobile-android by neo4j-contrib.

the class DbWrapper method removeRelationshipFromIndex.

@Override
public void removeRelationshipFromIndex(String name, long relationshipId, ParcelableError err) throws RemoteException {
    try {
        checkCallerHasWritePermission();
        resumeTrx();
        try {
            Relationship rel = mDb.getRelationshipById(relationshipId);
            // this
            RelationshipIndex index = mDb.index().forRelationships(name);
            // will
            // create
            // the
            // index
            index.remove(rel);
        } finally {
            suspendCurrentTrx("removeRelationshipFromIndex");
        }
    } catch (Exception e) {
        Log.e(TAG, "Failed to add relationship to index '" + name + "'", e);
        err.setError(Errors.TRANSACTION, e.getMessage());
    }
}
Also used : ParcelableRelationship(org.neo4j.android.common.ParcelableRelationship) Relationship(org.neo4j.graphdb.Relationship) RelationshipIndex(org.neo4j.graphdb.index.RelationshipIndex) RemoteException(android.os.RemoteException) InvalidTransactionException(org.neo4j.javax.transaction.InvalidTransactionException) SystemException(org.neo4j.javax.transaction.SystemException)

Aggregations

RelationshipIndex (org.neo4j.graphdb.index.RelationshipIndex)26 Relationship (org.neo4j.graphdb.Relationship)18 Test (org.junit.Test)13 Node (org.neo4j.graphdb.Node)13 RemoteException (android.os.RemoteException)7 Transaction (org.neo4j.graphdb.Transaction)7 InvalidTransactionException (org.neo4j.javax.transaction.InvalidTransactionException)7 SystemException (org.neo4j.javax.transaction.SystemException)7 ParcelableRelationship (org.neo4j.android.common.ParcelableRelationship)6 RelationshipType (org.neo4j.graphdb.RelationshipType)3 IndexManager (org.neo4j.graphdb.index.IndexManager)3 DynamicRelationshipType (org.neo4j.graphdb.DynamicRelationshipType)2 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)2 EmbeddedGraphDatabase (org.neo4j.kernel.EmbeddedGraphDatabase)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 BeforeClass (org.junit.BeforeClass)1 LuceneTimeline (org.neo4j.index.lucene.LuceneTimeline)1 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)1 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)1