Search in sources :

Example 1 with DynamicRelationshipType

use of org.neo4j.graphdb.DynamicRelationshipType 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 2 with DynamicRelationshipType

use of org.neo4j.graphdb.DynamicRelationshipType in project graphdb by neo4j-attic.

the class TestReadOnlyNeo4j method createSomeData.

private DbRepresentation createSomeData() {
    DynamicRelationshipType type = withName("KNOWS");
    GraphDatabaseService db = new EmbeddedGraphDatabase(PATH);
    Transaction tx = db.beginTx();
    Node prevNode = db.getReferenceNode();
    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();
    tx.finish();
    DbRepresentation result = DbRepresentation.of(db);
    db.shutdown();
    return result;
}
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) DynamicRelationshipType(org.neo4j.graphdb.DynamicRelationshipType) DbRepresentation(org.neo4j.test.DbRepresentation)

Example 3 with DynamicRelationshipType

use of org.neo4j.graphdb.DynamicRelationshipType in project neo4j by neo4j.

the class IncrementalBackupTests method createTransactiongWithWeirdRelationshipGroupRecord.

private DbRepresentation createTransactiongWithWeirdRelationshipGroupRecord(File path) {
    db = startGraphDatabase(path);
    int i = 0;
    Node node;
    DynamicRelationshipType typeToDelete = DynamicRelationshipType.withName("A");
    DynamicRelationshipType theOtherType = DynamicRelationshipType.withName("B");
    int defaultDenseNodeThreshold = Integer.parseInt(GraphDatabaseSettings.dense_node_threshold.getDefaultValue());
    try (Transaction tx = db.beginTx()) {
        node = db.createNode();
        for (; i < defaultDenseNodeThreshold - 1; i++) {
            node.createRelationshipTo(db.createNode(), theOtherType);
        }
        node.createRelationshipTo(db.createNode(), typeToDelete);
        tx.success();
    }
    try (Transaction tx = db.beginTx()) {
        node.createRelationshipTo(db.createNode(), theOtherType);
        for (Relationship relationship : node.getRelationships(Direction.BOTH, typeToDelete)) {
            relationship.delete();
        }
        tx.success();
    }
    DbRepresentation result = DbRepresentation.of(db);
    db.shutdown();
    return result;
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) DynamicRelationshipType(org.neo4j.graphdb.DynamicRelationshipType) DbRepresentation(org.neo4j.test.DbRepresentation)

Aggregations

DynamicRelationshipType (org.neo4j.graphdb.DynamicRelationshipType)3 Node (org.neo4j.graphdb.Node)3 Relationship (org.neo4j.graphdb.Relationship)3 Transaction (org.neo4j.graphdb.Transaction)3 EmbeddedGraphDatabase (org.neo4j.kernel.EmbeddedGraphDatabase)2 DbRepresentation (org.neo4j.test.DbRepresentation)2 File (java.io.File)1 BeforeClass (org.junit.BeforeClass)1 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)1 IndexManager (org.neo4j.graphdb.index.IndexManager)1 RelationshipIndex (org.neo4j.graphdb.index.RelationshipIndex)1