Search in sources :

Example 56 with Statement

use of org.neo4j.kernel.api.Statement in project neo4j by neo4j.

the class RelationshipIT method shouldReturnRelsWhenAskingForRelsWhereOnlySomeTypesExistInCurrentRel.

@Test
public void shouldReturnRelsWhenAskingForRelsWhereOnlySomeTypesExistInCurrentRel() throws Exception {
    Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
    int relType1 = statement.tokenWriteOperations().relationshipTypeGetOrCreateForName("Type1");
    int relType2 = statement.tokenWriteOperations().relationshipTypeGetOrCreateForName("Type2");
    long refNode = statement.dataWriteOperations().nodeCreate();
    long otherNode = statement.dataWriteOperations().nodeCreate();
    long theRel = statement.dataWriteOperations().relationshipCreate(relType1, refNode, otherNode);
    assertRels(statement.readOperations().nodeGetRelationships(refNode, OUTGOING, new int[] { relType2, relType1 }), theRel);
    commit();
}
Also used : Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 57 with Statement

use of org.neo4j.kernel.api.Statement in project neo4j by neo4j.

the class UniquenessConstraintValidationIT method shouldAllowRemoveAndAddConflictingDataInOneTransaction_ChangeProperty.

@Test
public void shouldAllowRemoveAndAddConflictingDataInOneTransaction_ChangeProperty() throws Exception {
    // given
    long node = constrainedNode("Label1", "key1", "value1");
    Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
    // when
    int key = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("key1");
    statement.dataWriteOperations().nodeSetProperty(node, property(key, "value2"));
    createLabeledNode(statement, "Label1", "key1", "value1");
    commit();
}
Also used : Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 58 with Statement

use of org.neo4j.kernel.api.Statement in project neo4j by neo4j.

the class UniquenessConstraintValidationIT method shouldAllowCreationOfNonConflictingData.

@Test
public void shouldAllowCreationOfNonConflictingData() throws Exception {
    // given
    constrainedNode("Label1", "key1", "value1");
    Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
    // when
    createNode(statement, "key1", "value1");
    createLabeledNode(statement, "Label2", "key1", "value1");
    createLabeledNode(statement, "Label1", "key1", "value2");
    createLabeledNode(statement, "Label1", "key2", "value1");
    commit();
    // then
    statement = statementInNewTransaction(AnonymousContext.writeToken());
    assertEquals("number of nodes", 5, count(statement.readOperations().nodesGetAll()));
    rollback();
}
Also used : Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 59 with Statement

use of org.neo4j.kernel.api.Statement in project neo4j by neo4j.

the class UniquenessConstraintValidationIT method shouldEnforceOnSetProperty.

@Test
public void shouldEnforceOnSetProperty() throws Exception {
    // given
    constrainedNode("Label1", "key1", "value1");
    Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
    // when
    long node = createLabeledNode(statement, "Label1");
    try {
        statement.dataWriteOperations().nodeSetProperty(node, property(statement.tokenWriteOperations().propertyKeyGetOrCreateForName("key1"), "value1"));
        fail("should have thrown exception");
    }// then
     catch (UniquePropertyValueValidationException e) {
        assertThat(e.getUserMessage(tokenLookup(statement)), containsString("`key1` = 'value1'"));
    }
}
Also used : UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 60 with Statement

use of org.neo4j.kernel.api.Statement in project neo4j by neo4j.

the class IndexPopulationFlipRaceIT method verifyThatThereAreExactlyOneIndexEntryPerNodeInTheIndexes.

private void verifyThatThereAreExactlyOneIndexEntryPerNodeInTheIndexes(int i, Pair<long[], long[]> data) throws Exception {
    KernelAPI kernelAPI = db.getDependencyResolver().resolveDependency(KernelAPI.class);
    try (KernelTransaction tx = kernelAPI.newTransaction(KernelTransaction.Type.implicit, AnonymousContext.read());
        Statement statement = tx.acquireStatement()) {
        int labelAId = statement.readOperations().labelGetForName(labelA(i).name());
        int keyAId = statement.readOperations().propertyKeyGetForName(keyA(i));
        int labelBId = statement.readOperations().labelGetForName(labelB(i).name());
        int keyBId = statement.readOperations().propertyKeyGetForName(keyB(i));
        NewIndexDescriptor indexA = NewIndexDescriptorFactory.forLabel(labelAId, keyAId);
        NewIndexDescriptor indexB = NewIndexDescriptorFactory.forLabel(labelBId, keyBId);
        for (int j = 0; j < NODES_PER_INDEX; j++) {
            long nodeAId = data.first()[j];
            assertEquals(1, statement.readOperations().nodesCountIndexed(indexA, nodeAId, nodeAId));
            long nodeBId = data.other()[j];
            assertEquals(1, statement.readOperations().nodesCountIndexed(indexB, nodeBId, nodeBId));
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Statement(org.neo4j.kernel.api.Statement) KernelAPI(org.neo4j.kernel.api.KernelAPI)

Aggregations

Statement (org.neo4j.kernel.api.Statement)158 Test (org.junit.Test)76 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)56 Transaction (org.neo4j.graphdb.Transaction)44 ReadOperations (org.neo4j.kernel.api.ReadOperations)40 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)30 EntityNotFoundException (org.neo4j.kernel.api.exceptions.EntityNotFoundException)23 NotFoundException (org.neo4j.graphdb.NotFoundException)21 Node (org.neo4j.graphdb.Node)20 ThreadToStatementContextBridge (org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)19 PropertyNotFoundException (org.neo4j.kernel.api.exceptions.PropertyNotFoundException)13 KeyReadOperations (org.neo4j.kernel.impl.api.operations.KeyReadOperations)11 ArrayList (java.util.ArrayList)10 DependencyResolver (org.neo4j.graphdb.DependencyResolver)10 IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)10 Label (org.neo4j.graphdb.Label)9 KernelAPI (org.neo4j.kernel.api.KernelAPI)9 ProcedureException (org.neo4j.kernel.api.exceptions.ProcedureException)9 InvalidTransactionTypeKernelException (org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException)8 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)8