public boolean dropPropertyUniquenessConstraint( String labelName, Iterable<String> propertyKeys ) { final Set<String> propertyKeysSet = Iterables.asSet( propertyKeys ); ConstraintDefinition constraint = Iterables.singleOrNull( filteredNodeConstraints( labelName, propertyUniquenessFilter( propertyKeysSet ) ) ); if ( constraint != null ) { constraint.drop(); } return constraint != null; }
public boolean dropRelationshipPropertyExistenceConstraint( String typeName, Iterable<String> propertyKeys ) { final Set<String> propertyKeysSet = Iterables.asSet( propertyKeys ); ConstraintDefinition constraint = Iterables.singleOrNull( filteredRelationshipConstraints( typeName, relationshipPropertyExistenceFilter( propertyKeysSet ) ) ); if ( constraint != null ) { constraint.drop(); } return constraint != null; }
public boolean dropNodePropertyExistenceConstraint( String labelName, Iterable<String> propertyKeys ) { final Set<String> propertyKeysSet = Iterables.asSet( propertyKeys ); ConstraintDefinition constraint = Iterables.singleOrNull( filteredNodeConstraints( labelName, nodePropertyExistenceFilter( propertyKeysSet ) ) ); if ( constraint != null ) { constraint.drop(); } return constraint != null; }
private void deleteAllConstraints() { for ( ConstraintDefinition constraint : db.schema().getConstraints() ) { constraint.drop(); } } }
private void dropConstraint( GraphDatabaseService db, ConstraintDefinition constraint ) { try ( Transaction tx = db.beginTx() ) { constraint.drop(); tx.success(); } }
@Test public void dropNonExistentConstraint() { // GIVEN String labelName = "user"; String propertyKey = "login"; ConstraintDefinition constraint = graphdbHelper.createPropertyUniquenessConstraint( labelName, asList( propertyKey ) ); // EXPECT expectedException.expect( ConstraintViolationException.class ); // WHEN try ( Transaction tx = graph.beginTx() ) { constraint.drop(); constraint.drop(); } }
private void dropConstraints() { try ( Transaction tx = db.beginTx() ) { for ( ConstraintDefinition constraint : db.schema().getConstraints( LABEL ) ) { constraint.drop(); } tx.success(); } }
@Before public void setup() { try ( org.neo4j.graphdb.Transaction tx = graphDb.beginTx() ) { for ( ConstraintDefinition definition : graphDb.schema().getConstraints() ) { definition.drop(); } tx.success(); } }
private ConstraintDefinition recreate( ConstraintDefinition constraint, int times ) { for ( int i = 0; i < times; i++ ) { constraint.drop(); constraint = graphDb.schema() .constraintFor( constraint.getLabel() ) .assertPropertyIsUnique( single( constraint.getPropertyKeys() ) ) .create(); } return constraint; }
public static void cleanupSchema( GraphDatabaseService db ) { try ( Transaction tx = db.beginTx() ) { for ( ConstraintDefinition constraint : db.schema().getConstraints() ) { constraint.drop(); } for ( IndexDefinition index : db.schema().getIndexes() ) { index.drop(); } tx.success(); } }
@Test public void shouldRemoveIndexForConstraintEvenIfDroppedInCreatingTransaction() { try ( Transaction tx = graphDb.beginTx() ) { // given graphDb.schema() .constraintFor( LABEL ).assertPropertyIsUnique( PROPERTY_KEY ) .create() .drop(); // when - rolling back tx.failure(); } // then assertNull( "Should not have constraint index", getIndex( LABEL, PROPERTY_KEY ) ); }
@Test public void shouldDropUniquenessConstraintWithBackingIndexNotInUse() { // given try ( Transaction tx = db.beginTx() ) { db.schema().constraintFor( label ).assertPropertyIsUnique( key ).create(); tx.success(); } // when intentionally breaking the schema by setting the backing index rule to unused RecordStorageEngine storageEngine = db.getDependencyResolver().resolveDependency( RecordStorageEngine.class ); SchemaStore schemaStore = storageEngine.testAccessNeoStores().getSchemaStore(); SchemaRule indexRule = single( filter( rule -> rule instanceof StoreIndexDescriptor, schemaStore.loadAllSchemaRules() ) ); setSchemaRecordNotInUse( schemaStore, indexRule.getId() ); // At this point the SchemaCache doesn't know about this change so we have to reload it storageEngine.loadSchemaCache(); try ( Transaction tx = db.beginTx() ) { single( db.schema().getConstraints( label ).iterator() ).drop(); tx.success(); } // then try ( Transaction ignore = db.beginTx() ) { assertFalse( db.schema().getConstraints().iterator().hasNext() ); assertFalse( db.schema().getIndexes().iterator().hasNext() ); } }
@Test public void shouldDropUniquenessConstraintWithBackingIndexHavingNoOwner() throws Exception { // given try ( Transaction tx = db.beginTx() ) { db.schema().constraintFor( label ).assertPropertyIsUnique( key ).create(); tx.success(); } // when intentionally breaking the schema by setting the backing index rule to unused RecordStorageEngine storageEngine = db.getDependencyResolver().resolveDependency( RecordStorageEngine.class ); SchemaStore schemaStore = storageEngine.testAccessNeoStores().getSchemaStore(); SchemaRule indexRule = single( filter( rule -> rule instanceof StoreIndexDescriptor, schemaStore.loadAllSchemaRules() ) ); setOwnerNull( schemaStore, (StoreIndexDescriptor) indexRule ); // At this point the SchemaCache doesn't know about this change so we have to reload it storageEngine.loadSchemaCache(); try ( Transaction tx = db.beginTx() ) { single( db.schema().getConstraints( label ).iterator() ).drop(); tx.success(); } // then try ( Transaction ignore = db.beginTx() ) { assertFalse( db.schema().getConstraints().iterator().hasNext() ); assertFalse( db.schema().getIndexes().iterator().hasNext() ); } }
@Test public void convertConstraintToIndex() { try ( Transaction tx = graphDb.beginTx() ) { graphDb.schema().constraintFor( LABEL ).assertPropertyIsUnique( PROPERTY_KEY ).create(); tx.success(); } try ( Transaction tx = graphDb.beginTx() ) { ConstraintDefinition constraint = firstOrNull( graphDb.schema().getConstraints( LABEL ) ); constraint.drop(); graphDb.schema().indexFor( LABEL ).on( PROPERTY_KEY ).create(); tx.success(); } // assert no exception is thrown }
.drop(); tx.success();
public List<AssertSchemaResult> assertConstraints(Map<String, List<Object>> constraints0, boolean dropExisting) throws ExecutionException, InterruptedException { Map<String, List<Object>> constraints = copyMapOfObjects(constraints0); List<AssertSchemaResult> result = new ArrayList<>(constraints.size()); Schema schema = db.schema(); for (ConstraintDefinition definition : schema.getConstraints()) { String label = definition.isConstraintType(ConstraintType.RELATIONSHIP_PROPERTY_EXISTENCE) ? definition.getRelationshipType().name() : definition.getLabel().name(); AssertSchemaResult info = new AssertSchemaResult(label, Iterables.asList(definition.getPropertyKeys())).unique(); if (!constraints.containsKey(label) || !constraints.get(label).remove(info.key)) { if (dropExisting) { definition.drop(); info.dropped(); } } result.add(info); } for (Map.Entry<String, List<Object>> constraint : constraints.entrySet()) { for (Object key : constraint.getValue()) { if (key instanceof String) { result.add(createUniqueConstraint(schema, constraint.getKey(), key.toString())); } else if (key instanceof List) { result.add(createNodeKeyConstraint(constraint.getKey(), (List<Object>) key)); } } } return result; }
@Test public void shouldBeAbleCheckExistenceOfConstraints() throws Exception { // GIVEN try ( org.neo4j.graphdb.Transaction tx = graphDb.beginTx() ) { graphDb.schema().constraintFor( label( "FOO" ) ).assertPropertyIsUnique( "prop1" ).create(); ConstraintDefinition dropped = graphDb.schema().constraintFor( label( "FOO" ) ).assertPropertyIsUnique( "prop2" ).create(); dropped.drop(); tx.success(); } try ( Transaction tx = beginTransaction() ) { int label = tx.tokenWrite().labelGetOrCreateForName( "FOO" ); int prop1 = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop1" ); int prop2 = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop2" ); // THEN assertTrue( tx.schemaRead().constraintExists( uniqueConstraintDescriptor( label, prop1 ) ) ); assertFalse( tx.schemaRead().constraintExists( uniqueConstraintDescriptor( label, prop2 ) ) ); } }
public boolean dropNodePropertyExistenceConstraint( String labelName, Iterable<String> propertyKeys ) { final Set<String> propertyKeysSet = Iterables.asSet( propertyKeys ); ConstraintDefinition constraint = Iterables.singleOrNull( filteredNodeConstraints( labelName, nodePropertyExistenceFilter( propertyKeysSet ) ) ); if ( constraint != null ) { constraint.drop(); } return constraint != null; }
public boolean dropRelationshipPropertyExistenceConstraint( String typeName, Iterable<String> propertyKeys ) { final Set<String> propertyKeysSet = Iterables.asSet( propertyKeys ); ConstraintDefinition constraint = Iterables.singleOrNull( filteredRelationshipConstraints( typeName, relationshipPropertyExistenceFilter( propertyKeysSet ) ) ); if ( constraint != null ) { constraint.drop(); } return constraint != null; }
public boolean dropPropertyUniquenessConstraint( String labelName, Iterable<String> propertyKeys ) { final Set<String> propertyKeysSet = Iterables.asSet( propertyKeys ); ConstraintDefinition constraint = Iterables.singleOrNull( filteredNodeConstraints( labelName, propertyUniquenessFilter( propertyKeysSet ) ) ); if ( constraint != null ) { constraint.drop(); } return constraint != null; }