Search in sources :

Example 1 with BatchRelationship

use of org.neo4j.unsafe.batchinsert.BatchRelationship in project neo4j by neo4j.

the class BatchInsertTest method testMore.

@Test
public void testMore() throws Exception {
    BatchInserter graphDb = globalInserter;
    long startNode = graphDb.createNode(properties);
    long[] endNodes = new long[25];
    Set<Long> rels = new HashSet<>();
    for (int i = 0; i < 25; i++) {
        endNodes[i] = graphDb.createNode(properties);
        rels.add(graphDb.createRelationship(startNode, endNodes[i], relTypeArray[i % 5], properties));
    }
    for (BatchRelationship rel : graphDb.getRelationships(startNode)) {
        assertTrue(rels.contains(rel.getId()));
        assertEquals(rel.getStartNode(), startNode);
    }
    graphDb.setNodeProperties(startNode, properties);
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) Matchers.anyLong(org.mockito.Matchers.anyLong) BatchRelationship(org.neo4j.unsafe.batchinsert.BatchRelationship) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with BatchRelationship

use of org.neo4j.unsafe.batchinsert.BatchRelationship in project neo4j by neo4j.

the class BatchInserterImpl method getRelationshipById.

@Override
public BatchRelationship getRelationshipById(long relId) {
    RelationshipRecord record = getRelationshipRecord(relId).forReadingData();
    RelationshipType type = (RelationshipType) relationshipTypeTokens.byId(record.getType());
    return new BatchRelationship(record.getId(), record.getFirstNode(), record.getSecondNode(), type);
}
Also used : RelationshipType(org.neo4j.graphdb.RelationshipType) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) BatchRelationship(org.neo4j.unsafe.batchinsert.BatchRelationship)

Example 3 with BatchRelationship

use of org.neo4j.unsafe.batchinsert.BatchRelationship in project neo4j by neo4j.

the class BatchInsertTest method testSimple.

@Test
public void testSimple() throws Exception {
    BatchInserter graphDb = globalInserter;
    long node1 = graphDb.createNode(null);
    long node2 = graphDb.createNode(null);
    long rel1 = graphDb.createRelationship(node1, node2, RelTypes.BATCH_TEST, null);
    BatchRelationship rel = graphDb.getRelationshipById(rel1);
    assertEquals(rel.getStartNode(), node1);
    assertEquals(rel.getEndNode(), node2);
    assertEquals(RelTypes.BATCH_TEST.name(), rel.getType().name());
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) BatchRelationship(org.neo4j.unsafe.batchinsert.BatchRelationship) Test(org.junit.Test)

Example 4 with BatchRelationship

use of org.neo4j.unsafe.batchinsert.BatchRelationship in project neo4j by neo4j.

the class BatchInsertTest method makeSureLoopsCanBeCreated.

@Test
public void makeSureLoopsCanBeCreated() throws Exception {
    BatchInserter graphDb = newBatchInserter();
    long startNode = graphDb.createNode(properties);
    long otherNode = graphDb.createNode(properties);
    long selfRelationship = graphDb.createRelationship(startNode, startNode, relTypeArray[0], properties);
    long relationship = graphDb.createRelationship(startNode, otherNode, relTypeArray[0], properties);
    for (BatchRelationship rel : graphDb.getRelationships(startNode)) {
        if (rel.getId() == selfRelationship) {
            assertEquals(startNode, rel.getStartNode());
            assertEquals(startNode, rel.getEndNode());
        } else if (rel.getId() == relationship) {
            assertEquals(startNode, rel.getStartNode());
            assertEquals(otherNode, rel.getEndNode());
        } else {
            fail("Unexpected relationship " + rel.getId());
        }
    }
    GraphDatabaseService db = switchToEmbeddedGraphDatabaseService(graphDb);
    try (Transaction ignored = db.beginTx()) {
        Node realStartNode = db.getNodeById(startNode);
        Relationship realSelfRelationship = db.getRelationshipById(selfRelationship);
        Relationship realRelationship = db.getRelationshipById(relationship);
        assertEquals(realSelfRelationship, realStartNode.getSingleRelationship(RelTypes.REL_TYPE1, Direction.INCOMING));
        assertEquals(asSet(realSelfRelationship, realRelationship), Iterables.asSet(realStartNode.getRelationships(Direction.OUTGOING)));
        assertEquals(asSet(realSelfRelationship, realRelationship), Iterables.asSet(realStartNode.getRelationships()));
    } finally {
        db.shutdown();
    }
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) BatchRelationship(org.neo4j.unsafe.batchinsert.BatchRelationship) Relationship(org.neo4j.graphdb.Relationship) BatchRelationship(org.neo4j.unsafe.batchinsert.BatchRelationship) Test(org.junit.Test)

Aggregations

BatchRelationship (org.neo4j.unsafe.batchinsert.BatchRelationship)4 Test (org.junit.Test)3 BatchInserter (org.neo4j.unsafe.batchinsert.BatchInserter)3 HashSet (java.util.HashSet)1 Matchers.anyLong (org.mockito.Matchers.anyLong)1 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)1 Node (org.neo4j.graphdb.Node)1 Relationship (org.neo4j.graphdb.Relationship)1 RelationshipType (org.neo4j.graphdb.RelationshipType)1 Transaction (org.neo4j.graphdb.Transaction)1 RelationshipRecord (org.neo4j.kernel.impl.store.record.RelationshipRecord)1