Search in sources :

Example 31 with EmbeddedGraphDatabase

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

the class TestRecovery method newGraphDbService.

private GraphDatabaseService newGraphDbService() {
    String path = getDbPath();
    Neo4jTestCase.deleteFileOrDirectory(new File(path));
    return new EmbeddedGraphDatabase(path);
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) File(java.io.File)

Example 32 with EmbeddedGraphDatabase

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

the class TestLuceneBatchInsert method testNumericValues.

@Test
public void testNumericValues() {
    String path = new File(PATH, "7").getAbsolutePath();
    BatchInserter inserter = new BatchInserterImpl(path);
    BatchInserterIndexProvider provider = new LuceneBatchInserterIndexProvider(inserter);
    BatchInserterIndex index = provider.nodeIndex("mine", EXACT_CONFIG);
    long node1 = inserter.createNode(null);
    index.add(node1, map("number", numeric(45)));
    long node2 = inserter.createNode(null);
    index.add(node2, map("number", numeric(21)));
    assertContains(index.query("number", newIntRange("number", 21, 50, true, true)), node1, node2);
    provider.shutdown();
    inserter.shutdown();
    GraphDatabaseService db = new EmbeddedGraphDatabase(path);
    Node n1 = db.getNodeById(node1);
    Node n2 = db.getNodeById(node2);
    Index<Node> idx = db.index().forNodes("mine");
    assertContains(idx.query("number", newIntRange("number", 21, 45, false, true)), n1);
    db.shutdown();
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) BatchInserter(org.neo4j.kernel.impl.batchinsert.BatchInserter) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) BatchInserterImpl(org.neo4j.kernel.impl.batchinsert.BatchInserterImpl) BatchInserterIndexProvider(org.neo4j.graphdb.index.BatchInserterIndexProvider) BatchInserterIndex(org.neo4j.graphdb.index.BatchInserterIndex) Node(org.neo4j.graphdb.Node) File(java.io.File) Test(org.junit.Test)

Example 33 with EmbeddedGraphDatabase

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

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

the class Neo4jTestCase method setUpDb.

@BeforeClass
public static void setUpDb() throws Exception {
    deleteFileOrDirectory(dbPath);
    graphDb = new EmbeddedGraphDatabase(dbPath.getAbsolutePath());
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) BeforeClass(org.junit.BeforeClass)

Example 35 with EmbeddedGraphDatabase

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

the class AddRelToIndex method main.

public static void main(String[] args) {
    String path = args[0];
    String indexName = "myIndex";
    GraphDatabaseService db = new EmbeddedGraphDatabase(path);
    Index<Relationship> index = db.index().forRelationships(indexName);
    Transaction tx = db.beginTx();
    Node node = db.createNode();
    Relationship relationship = db.getReferenceNode().createRelationshipTo(node, DynamicRelationshipType.withName("KNOWS"));
    index.add(relationship, "key", "value");
    tx.success();
    tx.finish();
// Skip shutdown
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Relationship(org.neo4j.graphdb.Relationship) Node(org.neo4j.graphdb.Node)

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