Search in sources :

Example 61 with EmbeddedGraphDatabase

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

the class TestLuceneBatchInsert method testSome.

@Test
public void testSome() throws Exception {
    // Different paths for each tests because there's a bug (on Windows)
    // causing _0.cfs file to stay open 
    String path = new File(PATH, "1").getAbsolutePath();
    BatchInserter inserter = new BatchInserterImpl(path);
    BatchInserterIndexProvider provider = new LuceneBatchInserterIndexProvider(inserter);
    BatchInserterIndex index = provider.nodeIndex("users", EXACT_CONFIG);
    Map<Integer, Long> ids = new HashMap<Integer, Long>();
    for (int i = 0; i < 100; i++) {
        long id = inserter.createNode(null);
        index.add(id, map("name", "Joe" + i, "other", "Schmoe"));
        ids.put(i, id);
    }
    for (int i = 0; i < 100; i++) {
        assertContains(index.get("name", "Joe" + i), ids.get(i));
    }
    assertContains(index.query("name:Joe0 AND other:Schmoe"), ids.get(0));
    assertContains(index.query("name", "Joe*"), ids.values().toArray(new Long[ids.size()]));
    provider.shutdown();
    inserter.shutdown();
    GraphDatabaseService db = new EmbeddedGraphDatabase(path);
    assertTrue(db.index().existsForNodes("users"));
    Index<Node> dbIndex = db.index().forNodes("users");
    for (int i = 0; i < 100; i++) {
        assertContains(dbIndex.get("name", "Joe" + i), db.getNodeById(ids.get(i)));
    }
    Collection<Node> nodes = new ArrayList<Node>();
    for (long id : ids.values()) {
        nodes.add(db.getNodeById(id));
    }
    assertContains(dbIndex.query("name", "Joe*"), nodes.toArray(new Node[nodes.size()]));
    assertContains(dbIndex.query("name:Joe0 AND other:Schmoe"), db.getNodeById(ids.get(0)));
    db.shutdown();
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) BatchInserterImpl(org.neo4j.kernel.impl.batchinsert.BatchInserterImpl) HashMap(java.util.HashMap) Node(org.neo4j.graphdb.Node) ArrayList(java.util.ArrayList) BatchInserter(org.neo4j.kernel.impl.batchinsert.BatchInserter) BatchInserterIndexProvider(org.neo4j.graphdb.index.BatchInserterIndexProvider) BatchInserterIndex(org.neo4j.graphdb.index.BatchInserterIndex) File(java.io.File) Test(org.junit.Test)

Example 62 with EmbeddedGraphDatabase

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

the class TestLuceneIndex method testStartupInExistingDirectory.

@Test
public void testStartupInExistingDirectory() {
    File dir = new File("target" + File.separator + "temp" + File.separator);
    Neo4jTestCase.deleteFileOrDirectory(dir);
    dir.mkdir();
    EmbeddedGraphDatabase graphDatabase = new EmbeddedGraphDatabase(dir.getAbsolutePath());
    Index<Node> index = graphDatabase.index().forNodes("nodes");
    assertNotNull(index);
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) Node(org.neo4j.graphdb.Node) File(java.io.File) Test(org.junit.Test)

Example 63 with EmbeddedGraphDatabase

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

the class AbstractLuceneIndexTest method setUpStuff.

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

Example 64 with EmbeddedGraphDatabase

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

the class AddDeleteQuit method main.

public static void main(String[] args) {
    GraphDatabaseService db = new EmbeddedGraphDatabase(args[0]);
    Index<Node> index = db.index().forNodes("index");
    Transaction tx = db.beginTx();
    try {
        Node node = db.createNode();
        index.add(node, "key", "value");
        index.delete();
        tx.success();
    } finally {
        tx.finish();
    }
    System.exit(0);
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node)

Example 65 with EmbeddedGraphDatabase

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

the class TestIndexNames 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)

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