Search in sources :

Example 1 with Label

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

the class ImportToolTest method shouldSkipDuplicateNodesIfToldTo.

@Test
public void shouldSkipDuplicateNodesIfToldTo() throws Exception {
    // GIVEN
    List<String> nodeIds = asList("a", "b", "c", "d", "e", "f", "a", "g");
    Configuration config = Configuration.COMMAS;
    File nodeHeaderFile = nodeHeader(config);
    File nodeData1 = nodeData(false, config, nodeIds, lines(0, 4));
    File nodeData2 = nodeData(false, config, nodeIds, lines(4, nodeIds.size()));
    // WHEN
    importTool("--into", dbRule.getStoreDirAbsolutePath(), "--skip-duplicate-nodes", "--nodes", nodeHeaderFile.getAbsolutePath() + MULTI_FILE_DELIMITER + nodeData1.getAbsolutePath() + MULTI_FILE_DELIMITER + nodeData2.getAbsolutePath());
    // THEN
    GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
    try (Transaction tx = db.beginTx()) {
        // there should not be duplicates of any node
        Iterator<Node> nodes = db.getAllNodes().iterator();
        Iterator<String> expectedIds = FilteringIterator.noDuplicates(nodeIds.iterator());
        while (expectedIds.hasNext()) {
            assertTrue(nodes.hasNext());
            assertEquals(expectedIds.next(), nodes.next().getProperty("id"));
        }
        assertFalse(nodes.hasNext());
        // also all nodes in the label index should exist
        for (int i = 0; i < MAX_LABEL_ID; i++) {
            Label label = Label.label(labelName(i));
            try (ResourceIterator<Node> nodesByLabel = db.findNodes(label)) {
                while (nodesByLabel.hasNext()) {
                    assertTrue(nodesByLabel.next().hasLabel(label));
                }
            }
        }
        tx.success();
    } finally {
        db.shutdown();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Configuration(org.neo4j.unsafe.impl.batchimport.input.csv.Configuration) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) DynamicLabel(org.neo4j.graphdb.DynamicLabel) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) File(java.io.File) Test(org.junit.Test)

Example 2 with Label

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

the class GraphDbStructureGuide method showRelCounts.

private void showRelCounts(ReadOperations read, DbStructureVisitor visitor) {
    // all wildcards
    noSide(read, visitor, WILDCARD_REL_TYPE, ANY_RELATIONSHIP_TYPE);
    // one label only
    for (Label label : db.getAllLabels()) {
        int labelId = read.labelGetForName(label.name());
        leftSide(read, visitor, label, labelId, WILDCARD_REL_TYPE, ANY_RELATIONSHIP_TYPE);
        rightSide(read, visitor, label, labelId, WILDCARD_REL_TYPE, ANY_RELATIONSHIP_TYPE);
    }
    // fixed rel type
    for (RelationshipType relType : db.getAllRelationshipTypes()) {
        int relTypeId = read.relationshipTypeGetForName(relType.name());
        noSide(read, visitor, relType, relTypeId);
        for (Label label : db.getAllLabels()) {
            int labelId = read.labelGetForName(label.name());
            // wildcard on right
            leftSide(read, visitor, label, labelId, relType, relTypeId);
            // wildcard on left
            rightSide(read, visitor, label, labelId, relType, relTypeId);
        }
    }
}
Also used : Label(org.neo4j.graphdb.Label) RelationshipType(org.neo4j.graphdb.RelationshipType) PropertyConstraint(org.neo4j.kernel.api.constraints.PropertyConstraint) RelationshipPropertyExistenceConstraint(org.neo4j.kernel.api.constraints.RelationshipPropertyExistenceConstraint) NodePropertyExistenceConstraint(org.neo4j.kernel.api.constraints.NodePropertyExistenceConstraint) UniquenessConstraint(org.neo4j.kernel.api.constraints.UniquenessConstraint)

Example 3 with Label

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

the class NodeProxyTest method createDropNodeLongArrayProperty.

@Test
public void createDropNodeLongArrayProperty() {
    Label markerLabel = Label.label("marker");
    String testPropertyKey = "testProperty";
    byte[] propertyValue = RandomUtils.nextBytes(1024);
    try (Transaction tx = db.beginTx()) {
        Node node = db.createNode(markerLabel);
        node.setProperty(testPropertyKey, propertyValue);
        tx.success();
    }
    try (Transaction tx = db.beginTx()) {
        Node node = Iterators.single(db.findNodes(markerLabel));
        assertArrayEquals(propertyValue, (byte[]) node.getProperty(testPropertyKey));
        tx.success();
    }
    try (Transaction tx = db.beginTx()) {
        Node node = Iterators.single(db.findNodes(markerLabel));
        node.removeProperty(testPropertyKey);
        tx.success();
    }
    try (Transaction tx = db.beginTx()) {
        Node node = Iterators.single(db.findNodes(markerLabel));
        assertFalse(node.hasProperty(testPropertyKey));
        tx.success();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 4 with Label

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

the class RelationshipProxyTest method createDropRelationshipLongStringProperty.

@Test
public void createDropRelationshipLongStringProperty() {
    Label markerLabel = DynamicLabel.label("marker");
    String testPropertyKey = "testProperty";
    String propertyValue = RandomStringUtils.randomAscii(255);
    try (Transaction tx = db.beginTx()) {
        Node start = db.createNode(markerLabel);
        Node end = db.createNode(markerLabel);
        Relationship relationship = start.createRelationshipTo(end, withName("type"));
        relationship.setProperty(testPropertyKey, propertyValue);
        tx.success();
    }
    try (Transaction tx = db.beginTx()) {
        Relationship relationship = db.getRelationshipById(0);
        assertEquals(propertyValue, relationship.getProperty(testPropertyKey));
        tx.success();
    }
    try (Transaction tx = db.beginTx()) {
        Relationship relationship = db.getRelationshipById(0);
        relationship.removeProperty(testPropertyKey);
        tx.success();
    }
    try (Transaction tx = db.beginTx()) {
        Relationship relationship = db.getRelationshipById(0);
        assertFalse(relationship.hasProperty(testPropertyKey));
        tx.success();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Label(org.neo4j.graphdb.Label) DynamicLabel(org.neo4j.graphdb.DynamicLabel) Test(org.junit.Test)

Example 5 with Label

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

the class ManyMergesStressTest method shouldWorkFine.

@Test
public void shouldWorkFine() throws Throwable {
    GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
    GraphDatabaseQueryService graph = new GraphDatabaseCypherService(db);
    Label person = Label.label("Person");
    try (Transaction tx = db.beginTx()) {
        // THIS USED TO CAUSE OUT OF FILE HANDLES
        // (maybe look at:  http://stackoverflow.com/questions/6210348/too-many-open-files-error-on-lucene)
        db.schema().indexFor(person).on("id").create();
        // THIS SHOULD ALSO WORK
        db.schema().constraintFor(person).assertPropertyIsUnique("id").create();
        tx.success();
    }
    try (Transaction tx = db.beginTx()) {
        db.schema().indexFor(person).on("name").create();
        tx.success();
    }
    try (Transaction tx = db.beginTx()) {
        db.schema().awaitIndexesOnline(1, TimeUnit.MINUTES);
        tx.success();
    }
    for (int count = 0; count < TRIES; count++) {
        Pair<String, String> stringPair = getRandomName();
        String ident = stringPair.first();
        String name = stringPair.other();
        String id = Long.toString(Math.abs(random.nextLong()));
        String query = format("MERGE (%s:Person {id: %s}) ON CREATE SET %s.name = \"%s\";", ident, id, ident, name);
        try (InternalTransaction tx = graph.beginTransaction(KernelTransaction.Type.implicit, SecurityContext.AUTH_DISABLED)) {
            Result result = db.execute(query);
            result.close();
            tx.success();
        }
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Transaction(org.neo4j.graphdb.Transaction) GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) Label(org.neo4j.graphdb.Label) GraphDatabaseCypherService(org.neo4j.cypher.javacompat.internal.GraphDatabaseCypherService) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Result(org.neo4j.graphdb.Result) Test(org.junit.Test)

Aggregations

Label (org.neo4j.graphdb.Label)82 Test (org.junit.Test)55 Node (org.neo4j.graphdb.Node)48 Transaction (org.neo4j.graphdb.Transaction)44 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)12 RelationshipType (org.neo4j.graphdb.RelationshipType)8 DependencyResolver (org.neo4j.graphdb.DependencyResolver)6 DynamicLabel (org.neo4j.graphdb.DynamicLabel)6 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)6 Statement (org.neo4j.kernel.api.Statement)6 ArrayList (java.util.ArrayList)5 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)5 Relationship (org.neo4j.graphdb.Relationship)5 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)5 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)5 File (java.io.File)4 HashSet (java.util.HashSet)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)4