Search in sources :

Example 21 with RelationshipIndex

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

the class DbWrapper method deleteRelationshipIndex.

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

Example 22 with RelationshipIndex

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

the class DbWrapper method addRelationshipToIndex.

@Override
public void addRelationshipToIndex(String name, long relationshipId, String key, ParcelableIndexValue value, 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.add(rel, key, value.get());
        } finally {
            suspendCurrentTrx("addRelationshipToIndex");
        }
    } 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)

Example 23 with RelationshipIndex

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

the class RelatedNodesQuestionTest method question5346011.

@Test
public void question5346011() {
    GraphDatabaseService service = new TestGraphDatabaseFactory().newImpermanentDatabase();
    try (Transaction tx = service.beginTx()) {
        RelationshipIndex index = service.index().forRelationships("exact");
        // ...creation of the nodes and relationship
        Node node1 = service.createNode();
        Node node2 = service.createNode();
        String a_uuid = "xyz";
        Relationship relationship = node1.createRelationshipTo(node2, RelationshipType.withName("related"));
        index.add(relationship, "uuid", a_uuid);
        // query
        IndexHits<Relationship> hits = index.get("uuid", a_uuid, node1, node2);
        assertEquals(1, hits.size());
        tx.success();
    }
    service.shutdown();
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) RelationshipIndex(org.neo4j.graphdb.index.RelationshipIndex) Test(org.junit.Test)

Example 24 with RelationshipIndex

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

the class RecoveryTest method shouldNotAcceptValuesWithNullToString.

@Test
public void shouldNotAcceptValuesWithNullToString() throws Exception {
    try (Transaction tx = db.beginTx()) {
        Node node = db.createNode();
        Node otherNode = db.createNode();
        Relationship rel = node.createRelationshipTo(otherNode, DynamicRelationshipType.withName("recovery"));
        Index<Node> nodeIndex = db.index().forNodes("node-index");
        RelationshipIndex relationshipIndex = db.index().forRelationships("rel-index");
        // Add
        assertAddFailsWithIllegalArgument(nodeIndex, node, "key1", new ClassWithToStringAlwaysNull());
        assertAddFailsWithIllegalArgument(relationshipIndex, rel, "key1", new ClassWithToStringAlwaysNull());
        // Remove
        assertRemoveFailsWithIllegalArgument(nodeIndex, node, "key1", new ClassWithToStringAlwaysNull());
        assertRemoveFailsWithIllegalArgument(relationshipIndex, rel, "key1", new ClassWithToStringAlwaysNull());
        tx.success();
    }
    forceRecover();
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) RelationshipIndex(org.neo4j.graphdb.index.RelationshipIndex) Test(org.junit.Test)

Example 25 with RelationshipIndex

use of org.neo4j.graphdb.index.RelationshipIndex 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)

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