use of org.neo4j.kernel.impl.api.KernelStatement in project neo4j by neo4j.
the class FullCheckIntegrationTest method statementOn.
private static KernelStatement statementOn(GraphDatabaseService db) {
DependencyResolver resolver = ((GraphDatabaseAPI) db).getDependencyResolver();
ThreadToStatementContextBridge bridge = resolver.resolveDependency(ThreadToStatementContextBridge.class);
return (KernelStatement) bridge.get();
}
use of org.neo4j.kernel.impl.api.KernelStatement in project neo4j by neo4j.
the class NeoStoresTest method validateAndCountRelationships.
private int validateAndCountRelationships(long node, long rel1, long rel2, int relType1, int relType2) throws IOException {
int count = 0;
try (KernelStatement statement = (KernelStatement) tx.acquireStatement();
Cursor<NodeItem> nodeCursor = statement.getStoreStatement().acquireSingleNodeCursor(node)) {
nodeCursor.next();
NodeItem nodeItem = nodeCursor.get();
try (Cursor<RelationshipItem> relationships = statement.getStoreStatement().acquireNodeRelationshipCursor(nodeItem.isDense(), nodeItem.id(), nodeItem.nextRelationshipId(), BOTH, ALWAYS_TRUE_INT)) {
while (relationships.next()) {
long rel = relationships.get().id();
if (rel == rel1) {
assertEquals(node, relationships.get().startNode());
assertEquals(relType1, relationships.get().type());
} else if (rel == rel2) {
assertEquals(node, relationships.get().endNode());
assertEquals(relType2, relationships.get().type());
} else {
throw new IOException();
}
count++;
}
}
}
return count;
}
use of org.neo4j.kernel.impl.api.KernelStatement in project neo4j by neo4j.
the class NeoStoresTest method validateNodeRel2.
private void validateNodeRel2(final long node, DefinedProperty prop1, DefinedProperty prop2, DefinedProperty prop3, long rel1, long rel2, final int relType1, final int relType2) throws IOException, RuntimeException {
assertTrue(nodeExists(node));
ArrayMap<Integer, Pair<DefinedProperty, Long>> props = new ArrayMap<>();
propertyLoader.nodeLoadProperties(node, newPropertyReceiver(props));
int count = 0;
for (int keyId : props.keySet()) {
long id = props.get(keyId).other();
PropertyRecord record = getRecord(pStore, id);
PropertyBlock block = record.getPropertyBlock(props.get(keyId).first().propertyKeyId());
DefinedProperty data = block.newPropertyData(pStore);
if (data.propertyKeyId() == prop1.propertyKeyId()) {
assertEquals("prop1", MyPropertyKeyToken.getIndexFor(keyId).name());
assertEquals("string2", data.value());
nodeAddProperty(node, prop1.propertyKeyId(), "-string2");
} else if (data.propertyKeyId() == prop2.propertyKeyId()) {
assertEquals("prop2", MyPropertyKeyToken.getIndexFor(keyId).name());
assertEquals(2, data.value());
nodeAddProperty(node, prop2.propertyKeyId(), -2);
} else if (data.propertyKeyId() == prop3.propertyKeyId()) {
assertEquals("prop3", MyPropertyKeyToken.getIndexFor(keyId).name());
assertEquals(false, data.value());
nodeAddProperty(node, prop3.propertyKeyId(), true);
} else {
throw new IOException();
}
count++;
}
assertEquals(3, count);
count = 0;
try (KernelStatement statement = (KernelStatement) tx.acquireStatement();
Cursor<NodeItem> nodeCursor = statement.getStoreStatement().acquireSingleNodeCursor(node)) {
nodeCursor.next();
NodeItem nodeItem = nodeCursor.get();
try (Cursor<RelationshipItem> relationships = statement.getStoreStatement().acquireNodeRelationshipCursor(nodeItem.isDense(), nodeItem.id(), nodeItem.nextRelationshipId(), BOTH, ALWAYS_TRUE_INT)) {
while (relationships.next()) {
long rel = relationships.get().id();
if (rel == rel1) {
assertEquals(node, relationships.get().endNode());
assertEquals(relType1, relationships.get().type());
} else if (rel == rel2) {
assertEquals(node, relationships.get().startNode());
assertEquals(relType2, relationships.get().type());
} else {
throw new IOException();
}
count++;
}
}
}
assertEquals(2, count);
}
use of org.neo4j.kernel.impl.api.KernelStatement in project neo4j by neo4j.
the class ConstraintIndexCreator method dropUniquenessConstraintIndex.
/**
* You MUST hold a schema write lock before you call this method.
*/
public void dropUniquenessConstraintIndex(NewIndexDescriptor descriptor) throws TransactionFailureException, DropIndexFailureException {
try (KernelTransaction transaction = kernelSupplier.get().newTransaction(KernelTransaction.Type.implicit, AUTH_DISABLED);
Statement statement = transaction.acquireStatement()) {
// NOTE: This creates the index (obviously) but it DOES NOT grab a schema
// write lock. It is assumed that the transaction that invoked this "inner" transaction
// holds a schema write lock, and that it will wait for this inner transaction to do its
// work.
// TODO (Ben+Jake): The Transactor is really part of the kernel internals, so it needs access to the
// internal implementation of Statement. However it is currently used by the external
// RemoveOrphanConstraintIndexesOnStartup job. This needs revisiting.
((KernelStatement) statement).txState().indexDoDrop(descriptor);
transaction.success();
}
}
use of org.neo4j.kernel.impl.api.KernelStatement in project neo4j by neo4j.
the class ConstraintIndexCreator method createConstraintIndex.
public NewIndexDescriptor createConstraintIndex(final LabelSchemaDescriptor schema) {
try (KernelTransaction transaction = kernelSupplier.get().newTransaction(KernelTransaction.Type.implicit, AUTH_DISABLED);
Statement statement = transaction.acquireStatement()) {
// NOTE: This creates the index (obviously) but it DOES NOT grab a schema
// write lock. It is assumed that the transaction that invoked this "inner" transaction
// holds a schema write lock, and that it will wait for this inner transaction to do its
// work.
// TODO (Ben+Jake): The Transactor is really part of the kernel internals, so it needs access to the
// internal implementation of Statement. However it is currently used by the external
// RemoveOrphanConstraintIndexesOnStartup job. This needs revisiting.
NewIndexDescriptor index = NewIndexDescriptorFactory.uniqueForSchema(schema);
((KernelStatement) statement).txState().indexRuleDoAdd(index);
transaction.success();
return index;
} catch (TransactionFailureException e) {
throw new RuntimeException(e);
}
}
Aggregations