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();
}
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();
}
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();
}
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'"));
}
}
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));
}
}
}
Aggregations