use of org.neo4j.graphdb.schema.IndexCreator in project neo4j by neo4j.
the class SchemaAcceptanceTest method constraintAndIndexNamesInTransactionStateMustBeUnique.
@Test
void constraintAndIndexNamesInTransactionStateMustBeUnique() {
try (Transaction tx = db.beginTx()) {
tx.schema().constraintFor(label).assertPropertyIsUnique(propertyKey).withName("MySchema").create();
IndexCreator creator = tx.schema().indexFor(otherLabel).on(secondPropertyKey).withName("MySchema");
ConstraintViolationException exception = assertThrows(ConstraintViolationException.class, creator::create);
assertThat(exception).hasMessageContaining("MySchema");
tx.commit();
}
}
use of org.neo4j.graphdb.schema.IndexCreator in project neo4j by neo4j.
the class SchemaAcceptanceTest method indexCreatorThrowsOnUnsupportedIndexType.
@Test
void indexCreatorThrowsOnUnsupportedIndexType() {
try (var tx = db.beginTx()) {
IndexCreator indexCreator = tx.schema().indexFor(label).withName("my_index").on(propertyKey);
assertThatThrownBy(() -> indexCreator.withIndexType(IndexType.LOOKUP).create()).isInstanceOf(ConstraintViolationException.class).hasMessageContaining("Index type LOOKUP is not supported for property indexes.");
}
}
use of org.neo4j.graphdb.schema.IndexCreator in project neo4j by neo4j.
the class SchemaAcceptanceTest method createIndex.
public static IndexDefinition createIndex(GraphDatabaseService db, AnyTokens tokens, String name) {
IndexDefinition index;
try (var tx = db.beginTx()) {
IndexCreator creator = tx.schema().indexFor(tokens);
if (name != null) {
creator = creator.withName(name);
}
index = creator.create();
tx.commit();
}
waitForIndex(db, index);
return index;
}
use of org.neo4j.graphdb.schema.IndexCreator in project neo4j by neo4j.
the class SchemaAcceptanceTest method indexNamesCanContainBackTicks.
@Test
void indexNamesCanContainBackTicks() {
try (Transaction tx = db.beginTx()) {
IndexCreator creator = tx.schema().indexFor(label).withName("`a`b``").on(propertyKey);
creator.create();
tx.commit();
}
try (Transaction tx = db.beginTx()) {
final Iterable<IndexDefinition> indexes = tx.schema().getIndexes();
assertThat(count(indexes)).isEqualTo(1L);
assertEquals("`a`b``", indexes.iterator().next().getName());
assertThat(count(tx.schema().getConstraints())).isEqualTo(0L);
tx.commit();
}
}
use of org.neo4j.graphdb.schema.IndexCreator in project neo4j by neo4j.
the class SchemaAcceptanceTest method indexNamesInTransactionStateMustBeUnique.
@Test
void indexNamesInTransactionStateMustBeUnique() {
try (Transaction tx = db.beginTx()) {
final String indexName = "MyIndex";
tx.schema().indexFor(label).on(propertyKey).withName(indexName).create();
IndexCreator creator = tx.schema().indexFor(otherLabel).on(secondPropertyKey).withName(indexName);
ConstraintViolationException exception = assertThrows(ConstraintViolationException.class, creator::create);
assertThat(exception).hasMessageContaining(alreadyExistsIndexMessage(indexName));
tx.commit();
}
}
Aggregations