use of org.neo4j.kernel.api.Statement in project neo4j by neo4j.
the class IndexIT method shouldListConstraintIndexesInTheBeansAPI.
@Test
public void shouldListConstraintIndexesInTheBeansAPI() throws Exception {
// given
Statement statement = statementInNewTransaction(SecurityContext.AUTH_DISABLED);
statement.schemaWriteOperations().uniquePropertyConstraintCreate(SchemaDescriptorFactory.forLabel(statement.tokenWriteOperations().labelGetOrCreateForName("Label1"), statement.tokenWriteOperations().propertyKeyGetOrCreateForName("property1")));
commit();
// when
try (Transaction tx = db.beginTx()) {
Set<IndexDefinition> indexes;
IndexDefinition index;
indexes = Iterables.asSet(db.schema().getIndexes());
// then
assertEquals(1, indexes.size());
index = indexes.iterator().next();
assertEquals("Label1", index.getLabel().name());
assertEquals(asSet("property1"), Iterables.asSet(index.getPropertyKeys()));
assertTrue("index should be a constraint index", index.isConstraintIndex());
// when
try {
index.drop();
fail("expected exception");
}// then
catch (IllegalStateException e) {
assertEquals("Constraint indexes cannot be dropped directly, " + "instead drop the owning uniqueness constraint.", e.getMessage());
}
}
}
use of org.neo4j.kernel.api.Statement in project neo4j by neo4j.
the class IndexPopulationJobTest method indexDescriptor.
private NewIndexDescriptor indexDescriptor(Label label, String propertyKey, boolean constraint) throws TransactionFailureException {
try (KernelTransaction tx = kernel.newTransaction(KernelTransaction.Type.implicit, AnonymousContext.read());
Statement statement = tx.acquireStatement()) {
int labelId = statement.readOperations().labelGetForName(label.name());
int propertyKeyId = statement.readOperations().propertyKeyGetForName(propertyKey);
NewIndexDescriptor descriptor = constraint ? NewIndexDescriptorFactory.uniqueForLabel(labelId, propertyKeyId) : NewIndexDescriptorFactory.forLabel(labelId, propertyKeyId);
tx.success();
return descriptor;
}
}
use of org.neo4j.kernel.api.Statement in project neo4j by neo4j.
the class IndexStatisticsTest method awaitOnline.
private NewIndexDescriptor awaitOnline(NewIndexDescriptor index) throws KernelException {
long start = System.currentTimeMillis();
long end = start + 20_000;
while (System.currentTimeMillis() < end) {
try (Transaction tx = db.beginTx()) {
Statement statement = bridge.get();
switch(statement.readOperations().indexGetState(index)) {
case ONLINE:
return index;
case FAILED:
throw new IllegalStateException("Index failed instead of becoming ONLINE");
default:
break;
}
tx.success();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// ignored
}
}
}
throw new IllegalStateException("Index did not become ONLINE within reasonable time");
}
use of org.neo4j.kernel.api.Statement in project neo4j by neo4j.
the class IndexStatisticsTest method createSomePersons.
private void createSomePersons() throws KernelException {
try (Transaction tx = db.beginTx()) {
Statement statement = bridge.get();
createNode(statement, "Person", "name", "Davide");
createNode(statement, "Person", "name", "Stefan");
createNode(statement, "Person", "name", "John");
createNode(statement, "Person", "name", "John");
tx.success();
}
}
use of org.neo4j.kernel.api.Statement in project neo4j by neo4j.
the class IndexStatisticsTest method createIndex.
private NewIndexDescriptor createIndex(String labelName, String propertyKeyName) throws KernelException {
try (Transaction tx = db.beginTx()) {
Statement statement = bridge.get();
int labelId = statement.tokenWriteOperations().labelGetOrCreateForName(labelName);
int propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName(propertyKeyName);
LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel(labelId, propertyKeyId);
NewIndexDescriptor index = statement.schemaWriteOperations().indexCreate(descriptor);
tx.success();
return index;
}
}
Aggregations