Search in sources :

Example 6 with RelationshipIndex

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

the class DbWrapper method updateRelationshipInIndex.

@Override
public void updateRelationshipInIndex(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
            // See http://docs.neo4j.org/chunked/stable/indexing-update.html
            index.remove(rel, key, value.get());
            index.add(rel, key, value.get());
        } finally {
            suspendCurrentTrx("updateRelationshipInIndex");
        }
    } catch (Exception e) {
        Log.e(TAG, "Failed to update relationship in 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 7 with RelationshipIndex

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

the class DbWrapper method removeRelationshipKeyFromIndex.

@Override
public void removeRelationshipKeyFromIndex(String name, long relationshipId, String key, 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, key);
        } finally {
            suspendCurrentTrx("removeRelationshipKeyFromIndex");
        }
    } 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 8 with RelationshipIndex

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

the class DbWrapper method getRelationshipsFromIndex.

@Override
public IRelationshipIterator getRelationshipsFromIndex(String name, String key, ParcelableIndexValue value, ParcelableError err) throws RemoteException {
    try {
        resumeTrxIfExists();
        try {
            // this
            RelationshipIndex index = mDb.index().forRelationships(name);
            // will
            // create
            // the
            // index
            IndexHits<Relationship> hits = index.get(key, value.get());
            return new RelationshipIteratorWrapper(hits);
        } finally {
            suspendCurrentTrx("getRelationshipsFromIndex");
        }
    } catch (Exception e) {
        Log.e(TAG, "Failed to add relationship to index '" + name + "'", e);
        err.setError(Errors.TRANSACTION, e.getMessage());
        return null;
    }
}
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 9 with RelationshipIndex

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

the class TestTimeline method relationshipTimeline.

private TimelineIndex<PropertyContainer> relationshipTimeline() {
    try (Transaction tx = db.beginTx()) {
        RelationshipIndex relationshipIndex = db.index().forRelationships("timeline");
        tx.success();
        return new LuceneTimeline(db, relationshipIndex);
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) RelationshipIndex(org.neo4j.graphdb.index.RelationshipIndex) LuceneTimeline(org.neo4j.index.lucene.LuceneTimeline)

Example 10 with RelationshipIndex

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

the class TestLuceneIndex method tooLongValuesAreNotAllowedInRelationshipIndex.

@Test
public void tooLongValuesAreNotAllowedInRelationshipIndex() {
    RelationshipIndex index = relationshipIndex(EXACT_CONFIG);
    String tooLongValue = RandomStringUtils.randomAlphabetic(36000);
    try {
        index.add(graphDb.createNode().createRelationshipTo(graphDb.createNode(), MyRelTypes.TEST), "key", tooLongValue);
        fail("Validation exception expected. Such long values are not allowed in the index.");
    } catch (IllegalArgumentException e) {
    // expected
    }
    try {
        index.add(graphDb.createNode().createRelationshipTo(graphDb.createNode(), MyRelTypes.TEST), "key", new String[] { "a", tooLongValue, "c" });
        fail("Validation exception expected. Such long values are not allowed in the index.");
    } catch (IllegalArgumentException e) {
    // expected
    }
}
Also used : 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