use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class SchemaAcceptanceTest method shouldListAddedConstraintsByLabel.
@Test
void shouldListAddedConstraintsByLabel() {
// GIVEN
ConstraintDefinition constraint1 = createUniquenessConstraint(label, propertyKey);
createUniquenessConstraint(otherLabel, propertyKey);
// WHEN THEN
try (Transaction tx = db.beginTx()) {
assertThat(getConstraints(tx, label)).containsOnly(constraint1);
}
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class SchemaAcceptanceTest method mustBeAbleToCreateUniquenessConstraintWithBtreeIndexType.
@Test
void mustBeAbleToCreateUniquenessConstraintWithBtreeIndexType() {
String name;
try (Transaction tx = db.beginTx()) {
ConstraintDefinition constraint = tx.schema().constraintFor(label).assertPropertyIsUnique(propertyKey).withIndexType(BTREE).create();
name = constraint.getName();
IndexDefinition index = getIndex(tx, name);
assertThat(index.getIndexType()).isEqualTo(BTREE);
tx.commit();
}
try (Transaction tx = db.beginTx()) {
IndexDefinition index = getIndex(tx, name);
assertThat(index.getIndexType()).isEqualTo(BTREE);
}
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class SchemaAcceptanceTest method mustBeAbleToSpecifyIndexConfigurationForUniquenessConstraint.
@Test
void mustBeAbleToSpecifyIndexConfigurationForUniquenessConstraint() {
try (Transaction tx = db.beginTx()) {
ConstraintDefinition constraint = tx.schema().constraintFor(label).withName("my constraint").assertPropertyIsUnique(propertyKey).withIndexConfiguration(Map.of(IndexSettingImpl.SPATIAL_CARTESIAN_MAX, new double[] { 200.0, 200.0 }, IndexSettingImpl.SPATIAL_WGS84_MIN, new double[] { -90.0, -90.0 })).create();
IndexDefinition index = getIndex(tx, constraint.getName());
Map<IndexSetting, Object> config = index.getIndexConfiguration();
assertArrayEquals(new double[] { 200.0, 200.0 }, (double[]) config.get(IndexSettingImpl.SPATIAL_CARTESIAN_MAX));
assertArrayEquals(new double[] { -90.0, -90.0 }, (double[]) config.get(IndexSettingImpl.SPATIAL_WGS84_MIN));
tx.commit();
}
try (Transaction tx = db.beginTx()) {
IndexDefinition index = getIndex(tx, "my constraint");
Map<IndexSetting, Object> config = index.getIndexConfiguration();
assertArrayEquals(new double[] { 200.0, 200.0 }, (double[]) config.get(IndexSettingImpl.SPATIAL_CARTESIAN_MAX));
assertArrayEquals(new double[] { -90.0, -90.0 }, (double[]) config.get(IndexSettingImpl.SPATIAL_WGS84_MIN));
tx.commit();
}
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class SchemaAcceptanceTest method createAndDropConstraintInSameTx.
@Test
void createAndDropConstraintInSameTx() {
// When
try (Transaction tx = db.beginTx()) {
ConstraintDefinition constraint = tx.schema().constraintFor(label).assertPropertyIsUnique(propertyKey).withName(nameA).create();
constraint.drop();
tx.commit();
}
// Then
try (Transaction tx = db.beginTx()) {
assertThat(count(tx.schema().getConstraints())).isEqualTo(0);
assertThat(count(tx.schema().getIndexes())).isEqualTo(0);
tx.commit();
}
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j-nlp by graphaware.
the class SchemaProcedureTest method schemaAssert.
private void schemaAssert(Label label, String s, String type) {
boolean exist = false;
try (Transaction tx = getDatabase().beginTx()) {
if (type.equals(UNIQUE)) {
for (ConstraintDefinition constraintDefinition : getDatabase().schema().getConstraints(label)) {
for (String p : constraintDefinition.getPropertyKeys()) {
if (p.equals(s)) {
exist = true;
}
}
}
} else {
for (IndexDefinition indexDefinition : getDatabase().schema().getIndexes()) {
for (String p : indexDefinition.getPropertyKeys()) {
if (p.equals(s)) {
exist = true;
}
}
}
}
tx.success();
}
assertTrue(exist);
}
Aggregations