use of org.neo4j.graphdb.RelationshipType in project neo4j by neo4j.
the class TestNeo4jCacheAndPersistence method testLowGrabSize.
@Test
public void testLowGrabSize() {
Map<String, String> config = new HashMap<>();
config.put("relationship_grab_size", "1");
File storeDir = getStorePath("neo2");
deleteFileOrDirectory(storeDir);
GraphDatabaseService graphDb = new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig(config).newGraphDatabase();
Node node1, node2;
try (Transaction tx = graphDb.beginTx()) {
node1 = graphDb.createNode();
node2 = graphDb.createNode();
node1.createRelationshipTo(node2, MyRelTypes.TEST);
node2.createRelationshipTo(node1, MyRelTypes.TEST2);
node1.createRelationshipTo(node2, MyRelTypes.TEST_TRAVERSAL);
tx.success();
}
try (Transaction tx = graphDb.beginTx()) {
RelationshipType[] types = new RelationshipType[] { MyRelTypes.TEST, MyRelTypes.TEST2, MyRelTypes.TEST_TRAVERSAL };
assertEquals(3, Iterables.count(node1.getRelationships(types)));
assertEquals(3, Iterables.count(node1.getRelationships()));
assertEquals(3, Iterables.count(node2.getRelationships(types)));
assertEquals(3, Iterables.count(node2.getRelationships()));
assertEquals(2, Iterables.count(node1.getRelationships(OUTGOING)));
assertEquals(1, Iterables.count(node1.getRelationships(INCOMING)));
assertEquals(1, Iterables.count(node2.getRelationships(OUTGOING)));
assertEquals(2, Iterables.count(node2.getRelationships(INCOMING)));
tx.success();
}
graphDb.shutdown();
}
use of org.neo4j.graphdb.RelationshipType in project neo4j by neo4j.
the class TestReadOnlyNeo4j method createSomeData.
private DbRepresentation createSomeData() {
RelationshipType type = withName("KNOWS");
GraphDatabaseService db = new TestGraphDatabaseFactory().setFileSystem(new UncloseableDelegatingFileSystemAbstraction(fs.get())).newImpermanentDatabase(PATH);
try (Transaction tx = db.beginTx()) {
Node prevNode = db.createNode();
for (int i = 0; i < 100; i++) {
Node node = db.createNode();
Relationship rel = prevNode.createRelationshipTo(node, type);
node.setProperty("someKey" + i % 10, i % 15);
rel.setProperty("since", System.currentTimeMillis());
}
tx.success();
}
DbRepresentation result = DbRepresentation.of(db);
db.shutdown();
return result;
}
use of org.neo4j.graphdb.RelationshipType in project neo4j by neo4j.
the class IdGeneratorTest method commandsGetWrittenOnceSoThatFreedIdsGetsAddedOnlyOnce.
@Test
public void commandsGetWrittenOnceSoThatFreedIdsGetsAddedOnlyOnce() throws Exception {
File storeDir = new File("target/var/free-id-once");
deleteRecursively(storeDir);
GraphDatabaseService db = createTestDatabase(storeDir);
RelationshipType type = withName("SOME_TYPE");
// This transaction will, if some commands may be executed more than
// once,
// add the freed ids to the defrag list more than once - making the id
// generator
// return the same id more than once during the next session.
Set<Long> createdNodeIds = new HashSet<>();
Set<Long> createdRelationshipIds = new HashSet<>();
Transaction tx = db.beginTx();
Node commonNode = db.createNode();
for (int i = 0; i < 20; i++) {
Node otherNode = db.createNode();
Relationship relationship = commonNode.createRelationshipTo(otherNode, type);
if (i % 5 == 0) {
otherNode.delete();
relationship.delete();
} else {
createdNodeIds.add(otherNode.getId());
createdRelationshipIds.add(relationship.getId());
}
}
tx.success();
tx.close();
db.shutdown();
// After a clean shutdown, create new nodes and relationships and see so
// that
// all ids are unique.
db = createTestDatabase(storeDir);
tx = db.beginTx();
commonNode = db.getNodeById(commonNode.getId());
for (int i = 0; i < 100; i++) {
Node otherNode = db.createNode();
if (!createdNodeIds.add(otherNode.getId())) {
fail("Managed to create a node with an id that was already in use");
}
Relationship relationship = commonNode.createRelationshipTo(otherNode, type);
if (!createdRelationshipIds.add(relationship.getId())) {
fail("Managed to create a relationship with an id that was already in use");
}
}
tx.success();
tx.close();
// Verify by loading everything from scratch
tx = db.beginTx();
for (Node node : db.getAllNodes()) {
Iterables.lastOrNull(node.getRelationships());
}
tx.close();
db.shutdown();
}
use of org.neo4j.graphdb.RelationshipType in project qi4j-sdk by Qi4j.
the class NeoEntityState method namedAssociationValueOf.
@Override
public NamedAssociationState namedAssociationValueOf(QualifiedName stateName) {
RelationshipType namedAssociation = namedAssociation(stateName);
Relationship rel = underlyingNode.getSingleRelationship(namedAssociation, Direction.OUTGOING);
if (rel != null) {
return new NeoNamedAssociationState(uow, this, rel.getEndNode());
}
Node node = uow.getNeo().createNode();
node.setProperty(NeoNamedAssociationState.COUNT, 0);
underlyingNode.createRelationshipTo(node, namedAssociation);
return new NeoNamedAssociationState(uow, this, node);
}
use of org.neo4j.graphdb.RelationshipType in project qi4j-sdk by Qi4j.
the class NeoEntityState method manyAssociationValueOf.
@Override
public ManyAssociationState manyAssociationValueOf(QualifiedName stateName) {
RelationshipType manyAssociation = manyAssociation(stateName);
Relationship rel = underlyingNode.getSingleRelationship(manyAssociation, Direction.OUTGOING);
if (rel != null) {
return new NeoManyAssociationState(uow, this, rel.getEndNode());
}
Node node = uow.getNeo().createNode();
node.setProperty(NeoManyAssociationState.COUNT, 0);
underlyingNode.createRelationshipTo(node, manyAssociation);
return new NeoManyAssociationState(uow, this, node);
}
Aggregations