@Test public void shouldCreateRelationshipPropertyExistenceConstraint() throws Exception { ConstraintDescriptor constraint; try ( Transaction transaction = beginTransaction() ) { constraint = transaction.schemaWrite() .relationshipPropertyExistenceConstraintCreate( typeDescriptor( type, prop1 ) ); transaction.success(); } try ( Transaction transaction = beginTransaction() ) { SchemaRead schemaRead = transaction.schemaRead(); assertTrue( schemaRead.constraintExists( constraint ) ); Iterator<ConstraintDescriptor> constraints = schemaRead.constraintsGetForRelationshipType( type ); assertThat( asList( constraints ), equalTo( singletonList( constraint ) ) ); } }
@Test public void shouldNotSeeDroppedRelationshipPropertyExistenceConstraintFromTransaction() throws Exception { ConstraintDescriptor existing; try ( Transaction transaction = beginTransaction() ) { existing = transaction.schemaWrite() .relationshipPropertyExistenceConstraintCreate( typeDescriptor( type, prop1 ) ); transaction.success(); } try ( Transaction transaction = beginTransaction() ) { transaction.schemaWrite().constraintDrop( existing ); SchemaRead schemaRead = transaction.schemaRead(); assertFalse( schemaRead.constraintExists( existing ) ); assertThat( schemaRead.index( type, prop2 ), equalTo( NO_INDEX ) ); assertThat( asList( schemaRead.constraintsGetForLabel( label ) ), empty() ); } }
@Test public void shouldSeeRelationshipPropertyExistenceConstraintFromTransaction() throws Exception { ConstraintDescriptor existing; try ( Transaction transaction = beginTransaction() ) { existing = transaction.schemaWrite().relationshipPropertyExistenceConstraintCreate( typeDescriptor( type, prop1 ) ); transaction.success(); } try ( Transaction transaction = beginTransaction() ) { ConstraintDescriptor newConstraint = transaction.schemaWrite().relationshipPropertyExistenceConstraintCreate( typeDescriptor( type, prop2 ) ); SchemaRead schemaRead = transaction.schemaRead(); assertTrue( schemaRead.constraintExists( existing ) ); assertTrue( schemaRead.constraintExists( newConstraint ) ); assertThat( asList( schemaRead.constraintsGetForRelationshipType( type ) ), containsInAnyOrder( existing, newConstraint ) ); } }
int typeId = tokenWrite.relationshipTypeGetOrCreateForName( type.name() ); int[] propertyKeyId = getOrCreatePropertyKeyIds( tokenWrite, propertyKey ); transaction.schemaWrite().relationshipPropertyExistenceConstraintCreate( SchemaDescriptorFactory.forRelType( typeId, propertyKeyId ) ); return new RelationshipPropertyExistenceConstraintDefinition( this, type, propertyKey );
@Test public void shouldDropRelationshipPropertyExistenceConstraint() throws Exception { ConstraintDescriptor constraint; try ( Transaction transaction = beginTransaction() ) { constraint = transaction.schemaWrite() .relationshipPropertyExistenceConstraintCreate( typeDescriptor( type, prop1 ) ); transaction.success(); } try ( Transaction transaction = beginTransaction() ) { transaction.schemaWrite().constraintDrop( constraint ); transaction.success(); } try ( Transaction transaction = beginTransaction() ) { SchemaRead schemaRead = transaction.schemaRead(); assertFalse( schemaRead.constraintExists( constraint ) ); assertThat( asList( schemaRead.constraintsGetForRelationshipType( type ) ), empty() ); } }
@Test public void shouldFailToCreateRelationshipPropertyExistenceConstraintIfConstraintNotSatisfied() throws Exception { //Given try ( Transaction transaction = beginTransaction() ) { Write write = transaction.dataWrite(); write.relationshipCreate( write.nodeCreate(), type, write.nodeCreate() ); transaction.success(); } //Expect exception.expect( SchemaKernelException.class ); //When try ( Transaction transaction = beginTransaction() ) { transaction.schemaWrite().relationshipPropertyExistenceConstraintCreate( typeDescriptor( type, prop1 ) ); } }
int typeId = tokenWrite.relationshipTypeGetOrCreateForName( type.name() ); int[] propertyKeyId = getOrCreatePropertyKeyIds( tokenWrite, propertyKey ); transaction.schemaWrite().relationshipPropertyExistenceConstraintCreate( SchemaDescriptorFactory.forRelType( typeId, propertyKeyId ) ); return new RelationshipPropertyExistenceConstraintDefinition( this, type, propertyKey );