Search in sources :

Example 11 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 12 with RelationshipIndex

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

the class RelatedNodesQuestionTest method question5346011.

@Test
public void question5346011() {
    GraphDatabaseService service = new EmbeddedGraphDatabase("target/soquestion-test");
    Transaction transaction = service.beginTx();
    try {
        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, DynamicRelationshipType.withName("related"));
        index.add(relationship, "uuid", a_uuid);
        // query
        IndexHits<Relationship> hits = index.get("uuid", a_uuid, node1, node2);
        assertEquals(1, hits.size());
        transaction.success();
    } finally {
        transaction.finish();
    }
    service.shutdown();
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) 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 13 with RelationshipIndex

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

the class ImdbExampleTest method setUpDb.

@BeforeClass
public static void setUpDb() {
    Neo4jTestCase.deleteFileOrDirectory(new File("target/graphdb"));
    graphDb = new EmbeddedGraphDatabase("target/graphdb");
    Transaction transaction = graphDb.beginTx();
    try {
        // START SNIPPET: createIndices
        IndexManager index = graphDb.index();
        Index<Node> actors = index.forNodes("actors");
        Index<Node> movies = index.forNodes("movies");
        RelationshipIndex roles = index.forRelationships("roles");
        // END SNIPPET: createIndices
        // START SNIPPET: createNodes
        // Actors
        Node reeves = graphDb.createNode();
        actors.add(reeves, "name", "Keanu Reeves");
        Node bellucci = graphDb.createNode();
        actors.add(bellucci, "name", "Monica Bellucci");
        // multiple values for a field
        actors.add(bellucci, "name", "La Bellucci");
        // Movies
        Node theMatrix = graphDb.createNode();
        movies.add(theMatrix, "title", "The Matrix");
        movies.add(theMatrix, "year", 1999);
        Node theMatrixReloaded = graphDb.createNode();
        movies.add(theMatrixReloaded, "title", "The Matrix Reloaded");
        movies.add(theMatrixReloaded, "year", 2003);
        Node malena = graphDb.createNode();
        movies.add(malena, "title", "Malèna");
        movies.add(malena, "year", 2000);
        // END SNIPPET: createNodes
        reeves.setProperty("name", "Keanu Reeves");
        bellucci.setProperty("name", "Monica Bellucci");
        theMatrix.setProperty("title", "The Matrix");
        theMatrix.setProperty("year", 1999);
        theMatrixReloaded.setProperty("title", "The Matrix Reloaded");
        theMatrixReloaded.setProperty("year", 2003);
        malena.setProperty("title", "Malèna");
        malena.setProperty("year", 2000);
        // START SNIPPET: createRelationships
        // we need a relationship type
        DynamicRelationshipType ACTS_IN = DynamicRelationshipType.withName("ACTS_IN");
        // create relationships
        Relationship role1 = reeves.createRelationshipTo(theMatrix, ACTS_IN);
        roles.add(role1, "name", "Neo");
        Relationship role2 = reeves.createRelationshipTo(theMatrixReloaded, ACTS_IN);
        roles.add(role2, "name", "Neo");
        Relationship role3 = bellucci.createRelationshipTo(theMatrixReloaded, ACTS_IN);
        roles.add(role3, "name", "Persephone");
        Relationship role4 = bellucci.createRelationshipTo(malena, ACTS_IN);
        roles.add(role4, "name", "Malèna Scordia");
        // END SNIPPET: createRelationships
        role1.setProperty("name", "Neo");
        role2.setProperty("name", "Neo");
        role3.setProperty("name", "Persephone");
        role4.setProperty("name", "Malèna Scordia");
        transaction.success();
    } finally {
        transaction.finish();
    }
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) IndexManager(org.neo4j.graphdb.index.IndexManager) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) RelationshipIndex(org.neo4j.graphdb.index.RelationshipIndex) DynamicRelationshipType(org.neo4j.graphdb.DynamicRelationshipType) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 14 with RelationshipIndex

use of org.neo4j.graphdb.index.RelationshipIndex in project neo4j-clean-remote-db-addon by jexp.

the class Neo4jDatabaseCleaner method clearIndex.

private void clearIndex(Map<String, Object> result) {
    IndexManager indexManager = graph.index();
    result.put("node-indexes", Arrays.asList(indexManager.nodeIndexNames()));
    result.put("relationship-indexes", Arrays.asList(indexManager.relationshipIndexNames()));
    try {
        for (String ix : indexManager.nodeIndexNames()) {
            final Index<Node> index = indexManager.forNodes(ix);
            getMutableIndex(index).delete();
        }
        for (String ix : indexManager.relationshipIndexNames()) {
            final RelationshipIndex index = indexManager.forRelationships(ix);
            getMutableIndex(index).delete();
        }
    } catch (UnsupportedOperationException uoe) {
        throw new RuntimeException("Implementation detail assumption failed for cleaning readonly indexes, please make sure that the version of this extension and the Neo4j server align");
    }
}
Also used : IndexManager(org.neo4j.graphdb.index.IndexManager) Node(org.neo4j.graphdb.Node) RelationshipIndex(org.neo4j.graphdb.index.RelationshipIndex)

Example 15 with RelationshipIndex

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

the class LegacyIndexesUpgradeTest method relationshipIndex.

private RelationshipIndex relationshipIndex(GraphDatabaseService db, String name, Map<String, String> config) {
    try (Transaction tx = db.beginTx()) {
        RelationshipIndex index = db.index().forRelationships(name, config);
        tx.success();
        return index;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) RelationshipIndex(org.neo4j.graphdb.index.RelationshipIndex)

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