Search in sources :

Example 36 with EmbeddedGraphDatabase

use of org.neo4j.kernel.EmbeddedGraphDatabase in project graphdb by neo4j-attic.

the class Inserter method main.

public static void main(String[] args) {
    String path = args[0];
    final GraphDatabaseService db = new EmbeddedGraphDatabase(path);
    final Index<Node> index = db.index().forNodes("myIndex");
    final String[] keys = new String[] { "apoc", "zion", "morpheus" };
    final String[] values = new String[] { "hej", "yo", "something", "just a value", "anything" };
    for (int i = 0; i < 5; i++) {
        new Thread() {

            @Override
            public void run() {
                while (true) {
                    Transaction tx = db.beginTx();
                    try {
                        for (int i = 0; i < 100; i++) {
                            String key = keys[i % keys.length];
                            String value = values[i % values.length] + i;
                            Node node = db.createNode();
                            node.setProperty(key, value);
                            index.add(node, key, value);
                        }
                        tx.success();
                    } finally {
                        tx.finish();
                    }
                }
            }
        }.start();
    }
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node)

Example 37 with EmbeddedGraphDatabase

use of org.neo4j.kernel.EmbeddedGraphDatabase in project graphdb by neo4j-attic.

the class TestIndexDeletion method setUpStuff.

@BeforeClass
public static void setUpStuff() {
    String storeDir = "target/var/freshindex";
    Neo4jTestCase.deleteFileOrDirectory(new File(storeDir));
    graphDb = new EmbeddedGraphDatabase(storeDir, MapUtil.stringMap("index", "lucene"));
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 38 with EmbeddedGraphDatabase

use of org.neo4j.kernel.EmbeddedGraphDatabase 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 39 with EmbeddedGraphDatabase

use of org.neo4j.kernel.EmbeddedGraphDatabase in project graphdb by neo4j-attic.

the class ImdbExampleTest method deleteIndex.

@Test
public void deleteIndex() {
    GraphDatabaseService graphDb = new EmbeddedGraphDatabase("target/graphdb-delete");
    Transaction transaction = graphDb.beginTx();
    try {
        // START SNIPPET: delete
        IndexManager index = graphDb.index();
        Index<Node> actors = index.forNodes("actors");
        actors.delete();
        // END SNIPPET: delete
        transaction.success();
    } finally {
        transaction.finish();
    }
    assertFalse(graphDb.index().existsForNodes("actors"));
    graphDb.shutdown();
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) IndexManager(org.neo4j.graphdb.index.IndexManager) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 40 with EmbeddedGraphDatabase

use of org.neo4j.kernel.EmbeddedGraphDatabase in project graphdb by neo4j-attic.

the class TestMigration method providerGetsFilledInAutomatically.

@Test
public void providerGetsFilledInAutomatically() {
    Map<String, String> correctConfig = MapUtil.stringMap("type", "exact", "provider", "lucene");
    File storeDir = new File("target/var/index");
    Neo4jTestCase.deleteFileOrDirectory(storeDir);
    GraphDatabaseService graphDb = new EmbeddedGraphDatabase(storeDir.getPath());
    assertEquals(correctConfig, graphDb.index().getConfiguration(graphDb.index().forNodes("default")));
    assertEquals(correctConfig, graphDb.index().getConfiguration(graphDb.index().forNodes("wo-provider", MapUtil.stringMap("type", "exact"))));
    assertEquals(correctConfig, graphDb.index().getConfiguration(graphDb.index().forNodes("w-provider", MapUtil.stringMap("type", "exact", "provider", "lucene"))));
    assertEquals(correctConfig, graphDb.index().getConfiguration(graphDb.index().forRelationships("default")));
    assertEquals(correctConfig, graphDb.index().getConfiguration(graphDb.index().forRelationships("wo-provider", MapUtil.stringMap("type", "exact"))));
    assertEquals(correctConfig, graphDb.index().getConfiguration(graphDb.index().forRelationships("w-provider", MapUtil.stringMap("type", "exact", "provider", "lucene"))));
    graphDb.shutdown();
    removeProvidersFromIndexDbFile(storeDir);
    graphDb = new EmbeddedGraphDatabase(storeDir.getPath());
    // Getting the index w/o exception means that the provider has been reinstated
    assertEquals(correctConfig, graphDb.index().getConfiguration(graphDb.index().forNodes("default")));
    assertEquals(correctConfig, graphDb.index().getConfiguration(graphDb.index().forNodes("wo-provider", MapUtil.stringMap("type", "exact"))));
    assertEquals(correctConfig, graphDb.index().getConfiguration(graphDb.index().forNodes("w-provider", MapUtil.stringMap("type", "exact", "provider", "lucene"))));
    assertEquals(correctConfig, graphDb.index().getConfiguration(graphDb.index().forRelationships("default")));
    assertEquals(correctConfig, graphDb.index().getConfiguration(graphDb.index().forRelationships("wo-provider", MapUtil.stringMap("type", "exact"))));
    assertEquals(correctConfig, graphDb.index().getConfiguration(graphDb.index().forRelationships("w-provider", MapUtil.stringMap("type", "exact", "provider", "lucene"))));
    graphDb.shutdown();
    removeProvidersFromIndexDbFile(storeDir);
    graphDb = new EmbeddedGraphDatabase(storeDir.getPath());
    // Getting the index w/o exception means that the provider has been reinstated
    assertEquals(correctConfig, graphDb.index().getConfiguration(graphDb.index().forNodes("default")));
    assertEquals(correctConfig, graphDb.index().getConfiguration(graphDb.index().forNodes("wo-provider")));
    assertEquals(correctConfig, graphDb.index().getConfiguration(graphDb.index().forNodes("w-provider")));
    assertEquals(correctConfig, graphDb.index().getConfiguration(graphDb.index().forRelationships("default")));
    assertEquals(correctConfig, graphDb.index().getConfiguration(graphDb.index().forRelationships("wo-provider")));
    assertEquals(correctConfig, graphDb.index().getConfiguration(graphDb.index().forRelationships("w-provider")));
    graphDb.shutdown();
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) File(java.io.File) Test(org.junit.Test)

Aggregations

EmbeddedGraphDatabase (org.neo4j.kernel.EmbeddedGraphDatabase)84 Test (org.junit.Test)50 File (java.io.File)35 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)32 Node (org.neo4j.graphdb.Node)26 Transaction (org.neo4j.graphdb.Transaction)17 Relationship (org.neo4j.graphdb.Relationship)14 BeforeClass (org.junit.BeforeClass)13 HashMap (java.util.HashMap)7 BatchInserterImpl (org.neo4j.kernel.impl.batchinsert.BatchInserterImpl)6 RandomAccessFile (java.io.RandomAccessFile)5 BatchInserter (org.neo4j.kernel.impl.batchinsert.BatchInserter)5 BatchInserterIndex (org.neo4j.graphdb.index.BatchInserterIndex)4 TransactionManager (javax.transaction.TransactionManager)3 Before (org.junit.Before)3 DynamicRelationshipType (org.neo4j.graphdb.DynamicRelationshipType)3 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)3 BatchInserterIndexProvider (org.neo4j.graphdb.index.BatchInserterIndexProvider)3 IndexManager (org.neo4j.graphdb.index.IndexManager)3 Transaction (javax.transaction.Transaction)2