Search in sources :

Example 46 with Label

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

the class GraphDbStructureGuide method showLabels.

private void showLabels(ReadOperations read, DbStructureVisitor visitor) {
    for (Label label : db.getAllLabels()) {
        int labelId = read.labelGetForName(label.name());
        visitor.visitLabel(labelId, label.name());
    }
}
Also used : Label(org.neo4j.graphdb.Label) 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 47 with Label

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

the class GraphDbStructureGuide method showNodeCounts.

private void showNodeCounts(ReadOperations read, DbStructureVisitor visitor) {
    visitor.visitAllNodesCount(read.countsForNode(ANY_LABEL));
    for (Label label : db.getAllLabels()) {
        int labelId = read.labelGetForName(label.name());
        visitor.visitNodeCount(labelId, label.name(), read.countsForNode(labelId));
    }
}
Also used : Label(org.neo4j.graphdb.Label) 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 48 with Label

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

the class RecoveryIT method shouldRecoverIdsCorrectlyWhenWeCreateAndDeleteANodeInTheSameRecoveryRun.

@Test
public void shouldRecoverIdsCorrectlyWhenWeCreateAndDeleteANodeInTheSameRecoveryRun() throws IOException {
    GraphDatabaseService database = startDatabase(directory.graphDbDir());
    Label testLabel = Label.label("testLabel");
    final String propertyToDelete = "propertyToDelete";
    final String validPropertyName = "validProperty";
    try (Transaction transaction = database.beginTx()) {
        Node node = database.createNode();
        node.addLabel(testLabel);
        transaction.success();
    }
    try (Transaction transaction = database.beginTx()) {
        Node node = findNodeByLabel(database, testLabel);
        node.setProperty(propertyToDelete, createLongString());
        node.setProperty(validPropertyName, createLongString());
        transaction.success();
    }
    try (Transaction transaction = database.beginTx()) {
        Node node = findNodeByLabel(database, testLabel);
        node.removeProperty(propertyToDelete);
        transaction.success();
    }
    // copying only transaction log simulate non clean shutdown db that should be able to recover just from logs
    File restoreDbStoreDir = copyTransactionLogs();
    // database should be restored and node should have expected properties
    GraphDatabaseService recoveredDatabase = startDatabase(restoreDbStoreDir);
    try (Transaction ignored = recoveredDatabase.beginTx()) {
        Node node = findNodeByLabel(recoveredDatabase, testLabel);
        assertFalse(node.hasProperty(propertyToDelete));
        assertTrue(node.hasProperty(validPropertyName));
    }
    database.shutdown();
    recoveredDatabase.shutdown();
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) File(java.io.File) Test(org.junit.Test)

Example 49 with Label

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

the class Neo4jPackTest method shouldBeAbleToPackAndUnpackListStream.

@SuppressWarnings("unchecked")
@Test
public void shouldBeAbleToPackAndUnpackListStream() throws IOException {
    // Given
    PackedOutputArray output = new PackedOutputArray();
    Neo4jPack.Packer packer = new Neo4jPack.Packer(output);
    packer.packListStreamHeader();
    List<String> expected = new ArrayList<>();
    for (Label label : ALICE.getLabels()) {
        String labelName = label.name();
        packer.pack(labelName);
        expected.add(labelName);
    }
    packer.packEndOfStream();
    Object unpacked = unpacked(output.bytes());
    // Then
    assertThat(unpacked, instanceOf(List.class));
    List<String> unpackedList = (List<String>) unpacked;
    assertThat(unpackedList, equalTo(expected));
}
Also used : ArrayList(java.util.ArrayList) Label(org.neo4j.graphdb.Label) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) PackedOutputArray(org.neo4j.bolt.v1.packstream.PackedOutputArray) Test(org.junit.Test)

Example 50 with Label

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

the class ConsistencyCheckServiceIntegrationTest method shouldNotReportDuplicateForHugeLongValues.

@Test
public void shouldNotReportDuplicateForHugeLongValues() throws Exception {
    // given
    ConsistencyCheckService service = new ConsistencyCheckService();
    Config configuration = Config.embeddedDefaults(settings());
    GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(testDirectory.graphDbDir()).setConfig(GraphDatabaseSettings.record_format, getRecordFormatName()).newGraphDatabase();
    String propertyKey = "itemId";
    Label label = Label.label("Item");
    try (Transaction tx = db.beginTx()) {
        db.schema().constraintFor(label).assertPropertyIsUnique(propertyKey).create();
        tx.success();
    }
    try (Transaction tx = db.beginTx()) {
        set(db.createNode(label), property(propertyKey, 973305894188596880L));
        set(db.createNode(label), property(propertyKey, 973305894188596864L));
        tx.success();
    }
    db.shutdown();
    // when
    Result result = runFullConsistencyCheck(service, configuration);
    // then
    assertTrue(result.isSuccessful());
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Config(org.neo4j.kernel.configuration.Config) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Label(org.neo4j.graphdb.Label) Matchers.containsString(org.hamcrest.Matchers.containsString) Result(org.neo4j.consistency.ConsistencyCheckService.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