diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/coreapi/schema/SchemaImpl.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/coreapi/schema/SchemaImpl.java index c03502df77755..4509225ed2461 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/coreapi/schema/SchemaImpl.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/coreapi/schema/SchemaImpl.java @@ -43,21 +43,19 @@ import org.neo4j.internal.kernel.api.InternalIndexState; import org.neo4j.internal.kernel.api.SchemaRead; import org.neo4j.internal.kernel.api.TokenRead; -import org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException; +import org.neo4j.internal.kernel.api.TokenWrite; import org.neo4j.internal.kernel.api.exceptions.KernelException; import org.neo4j.internal.kernel.api.exceptions.LabelNotFoundKernelException; import org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException; import org.neo4j.internal.kernel.api.exceptions.schema.IllegalTokenNameException; +import org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException; import org.neo4j.internal.kernel.api.exceptions.schema.TooManyLabelsException; import org.neo4j.internal.kernel.api.schema.LabelSchemaDescriptor; import org.neo4j.internal.kernel.api.schema.RelationTypeSchemaDescriptor; import org.neo4j.internal.kernel.api.schema.constraints.ConstraintDescriptor; import org.neo4j.kernel.api.KernelTransaction; -import org.neo4j.kernel.api.ReadOperations; import org.neo4j.kernel.api.SilentTokenNameLookup; import org.neo4j.kernel.api.Statement; -import org.neo4j.kernel.api.StatementTokenNameLookup; -import org.neo4j.kernel.api.TokenWriteOperations; import org.neo4j.kernel.api.exceptions.Status; import org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException; import org.neo4j.kernel.api.exceptions.schema.AlreadyConstrainedException; @@ -96,8 +94,7 @@ public class SchemaImpl implements Schema public SchemaImpl( Supplier transactionSupplier ) { this.transactionSupplier = transactionSupplier; - //TODO this should be updated once writes are ported - this.actions = new GDBSchemaActions( () -> transactionSupplier.get().acquireStatement() ); + this.actions = new GDBSchemaActions( transactionSupplier ); } @Override @@ -157,7 +154,7 @@ private IndexDefinition descriptorToDefinition( final TokenRead tokenRead, Capab } private void addDefinitions( List definitions, final TokenRead tokenRead, - Iterator indexes ) + Iterator indexes ) { addToCollection( map( index -> descriptorToDefinition( tokenRead, index ), indexes ), @@ -220,7 +217,7 @@ public void awaitIndexesOnline( long duration, TimeUnit unit ) @Override public IndexState getIndexState( final IndexDefinition index ) { - KernelTransaction transaction = safeAcquireTransaction(); + KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); try ( Statement ignore = transaction.acquireStatement() ) { @@ -229,14 +226,14 @@ public IndexState getIndexState( final IndexDefinition index ) InternalIndexState indexState = schemaRead.indexGetState( reference ); switch ( indexState ) { - case POPULATING: - return POPULATING; - case ONLINE: - return ONLINE; - case FAILED: - return FAILED; - default: - throw new IllegalArgumentException( String.format( "Illegal index state %s", indexState ) ); + case POPULATING: + return POPULATING; + case ONLINE: + return ONLINE; + case FAILED: + return FAILED; + default: + throw new IllegalArgumentException( String.format( "Illegal index state %s", indexState ) ); } } catch ( SchemaRuleNotFoundException | IndexNotFoundKernelException e ) @@ -249,7 +246,7 @@ public IndexState getIndexState( final IndexDefinition index ) @Override public IndexPopulationProgress getIndexPopulationProgress( IndexDefinition index ) { - KernelTransaction transaction = safeAcquireTransaction(); + KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); try ( Statement ignore = transaction.acquireStatement() ) { SchemaRead schemaRead = transaction.schemaRead(); @@ -267,7 +264,7 @@ public IndexPopulationProgress getIndexPopulationProgress( IndexDefinition index @Override public String getIndexFailure( IndexDefinition index ) { - KernelTransaction transaction = safeAcquireTransaction(); + KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); try ( Statement ignore = transaction.acquireStatement() ) { SchemaRead schemaRead = transaction.schemaRead(); @@ -291,7 +288,7 @@ public ConstraintCreator constraintFor( Label label ) @Override public Iterable getConstraints() { - KernelTransaction transaction = safeAcquireTransaction(); + KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); try ( Statement ignore = transaction.acquireStatement() ) { return asConstraintDefinitions( transaction.schemaRead().constraintsGetAll(), transaction.tokenRead() ); @@ -301,7 +298,7 @@ public Iterable getConstraints() @Override public Iterable getConstraints( final Label label ) { - KernelTransaction transaction = safeAcquireTransaction(); + KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); try ( Statement ignore = transaction.acquireStatement() ) { TokenRead tokenRead = transaction.tokenRead(); @@ -318,7 +315,7 @@ public Iterable getConstraints( final Label label ) @Override public Iterable getConstraints( RelationshipType type ) { - KernelTransaction transaction = safeAcquireTransaction(); + KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); try ( Statement ignore = transaction.acquireStatement() ) { TokenRead tokenRead = transaction.tokenRead(); @@ -332,17 +329,9 @@ public Iterable getConstraints( RelationshipType type ) } } - private static SchemaIndexDescriptor getIndexDescriptor( ReadOperations readOperations, IndexDefinition index ) - throws SchemaRuleNotFoundException - { - int labelId = readOperations.labelGetForName( index.getLabel().name() ); - int[] propertyKeyIds = PropertyNameUtils.getPropertyIds( readOperations, index.getPropertyKeys() ); - assertValidLabel( index.getLabel(), labelId ); - assertValidProperties( index.getPropertyKeys(), propertyKeyIds ); - return readOperations.indexGetForSchema( SchemaDescriptorFactory.forLabel( labelId, propertyKeyIds ) ); - } - private static CapableIndexReference getIndexReference( SchemaRead schemaRead, TokenRead tokenRead, IndexDefinition index ) + private static CapableIndexReference getIndexReference( SchemaRead schemaRead, TokenRead tokenRead, + IndexDefinition index ) throws SchemaRuleNotFoundException { int labelId = tokenRead.nodeLabel( index.getLabel().name() ); @@ -360,7 +349,7 @@ private static void assertValidLabel( Label label, int labelId ) } } - private static void assertValidProperties( Iterable properties , int[] propertyIds ) + private static void assertValidProperties( Iterable properties, int[] propertyIds ) { for ( int i = 0; i < propertyIds.length; i++ ) { @@ -373,7 +362,8 @@ private static void assertValidProperties( Iterable properties , int[] p } private Iterable asConstraintDefinitions( - Iterator constraints, TokenRead tokenRead ) + Iterator constraints, + TokenRead tokenRead ) { // Intentionally create an eager list so that used statement can be closed List definitions = new ArrayList<>(); @@ -403,7 +393,7 @@ private ConstraintDefinition asConstraintDefinition( ConstraintDescriptor constr LabelSchemaDescriptor schemaDescriptor = (LabelSchemaDescriptor) constraint.schema(); Label label = Label.label( lookup.labelGetName( schemaDescriptor.getLabelId() ) ); String[] propertyKeys = Arrays.stream( schemaDescriptor.getPropertyIds() ) - .mapToObj( lookup::propertyKeyGetName ).toArray(String[]::new); + .mapToObj( lookup::propertyKeyGetName ).toArray( String[]::new ); if ( constraint instanceof NodeExistenceConstraintDescriptor ) { return new NodePropertyExistenceConstraintDefinition( actions, label, propertyKeys ); @@ -429,7 +419,7 @@ else if ( constraint instanceof RelExistenceConstraintDescriptor ) throw new IllegalArgumentException( "Unknown constraint " + constraint ); } - private KernelTransaction safeAcquireTransaction() + private static KernelTransaction safeAcquireTransaction( Supplier transactionSupplier ) { KernelTransaction transaction = transactionSupplier.get(); if ( transaction.isTerminated() ) @@ -442,44 +432,38 @@ private KernelTransaction safeAcquireTransaction() private static class GDBSchemaActions implements InternalSchemaActions { - private final Supplier ctxSupplier; + private final Supplier transactionSupplier; - GDBSchemaActions( Supplier statementSupplier ) + GDBSchemaActions( Supplier transactionSupplier ) { - this.ctxSupplier = statementSupplier; + this.transactionSupplier = transactionSupplier; } @Override public IndexDefinition createIndexDefinition( Label label, String... propertyKeys ) { - try ( Statement statement = ctxSupplier.get() ) + KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); + try ( Statement ignore = transaction.acquireStatement() ) { try { IndexDefinition indexDefinition = new IndexDefinitionImpl( this, label, propertyKeys, false ); - TokenWriteOperations tokenWriteOperations = statement.tokenWriteOperations(); - int labelId = tokenWriteOperations.labelGetOrCreateForName( indexDefinition.getLabel().name() ); - int[] propertyKeyIds = getOrCreatePropertyKeyIds( tokenWriteOperations, indexDefinition ); + TokenWrite tokenWrite = transaction.tokenWrite(); + int labelId = tokenWrite.labelGetOrCreateForName( indexDefinition.getLabel().name() ); + int[] propertyKeyIds = getOrCreatePropertyKeyIds( tokenWrite, indexDefinition ); LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel( labelId, propertyKeyIds ); - statement.schemaWriteOperations().indexCreate( descriptor ); + transaction.schemaWrite().indexCreate( descriptor ); return indexDefinition; } - catch ( AlreadyIndexedException | AlreadyConstrainedException | RepeatedPropertyInCompositeSchemaException e ) - { - throw new ConstraintViolationException( - e.getUserMessage( new StatementTokenNameLookup( statement.readOperations() ) ), e ); - } + catch ( IllegalTokenNameException e ) { throw new IllegalArgumentException( e ); } - catch ( TooManyLabelsException e ) - { - throw new IllegalStateException( e ); - } - catch ( InvalidTransactionTypeKernelException e ) + catch ( SchemaKernelException e ) { - throw new ConstraintViolationException( e.getMessage(), e ); + throw new ConstraintViolationException( + e.getUserMessage( new SilentTokenNameLookup( transaction.tokenRead() ) ), e ); } } } @@ -487,12 +471,13 @@ public IndexDefinition createIndexDefinition( Label label, String... propertyKey @Override public void dropIndexDefinitions( IndexDefinition indexDefinition ) { - try ( Statement statement = ctxSupplier.get() ) + KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); + try ( Statement ignore = transaction.acquireStatement() ) { try { - statement.schemaWriteOperations().indexDrop( - getIndexDescriptor( statement.readOperations(), indexDefinition ) ); + transaction.schemaWrite().indexDrop( getIndexReference( + transaction.schemaRead(), transaction.tokenRead(), indexDefinition ) ); } catch ( NotFoundException e ) { @@ -501,9 +486,9 @@ public void dropIndexDefinitions( IndexDefinition indexDefinition ) catch ( SchemaRuleNotFoundException | DropIndexFailureException e ) { throw new ConstraintViolationException( e.getUserMessage( - new StatementTokenNameLookup( statement.readOperations() ) ) ); + new SilentTokenNameLookup( transaction.tokenRead() ) ) ); } - catch ( InvalidTransactionTypeKernelException e ) + catch ( SchemaKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } @@ -513,15 +498,15 @@ public void dropIndexDefinitions( IndexDefinition indexDefinition ) @Override public ConstraintDefinition createPropertyUniquenessConstraint( IndexDefinition indexDefinition ) { - try ( Statement statement = ctxSupplier.get() ) + KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); + try ( Statement ignore = transaction.acquireStatement() ) { try { - int labelId = statement.tokenWriteOperations().labelGetOrCreateForName( - indexDefinition.getLabel().name() ); - int[] propertyKeyIds = getOrCreatePropertyKeyIds( - statement.tokenWriteOperations(), indexDefinition ); - statement.schemaWriteOperations().uniquePropertyConstraintCreate( + TokenWrite tokenWrite = transaction.tokenWrite(); + int labelId = tokenWrite.labelGetOrCreateForName( indexDefinition.getLabel().name() ); + int[] propertyKeyIds = getOrCreatePropertyKeyIds( tokenWrite, indexDefinition ); + transaction.schemaWrite().uniquePropertyConstraintCreate( SchemaDescriptorFactory.forLabel( labelId, propertyKeyIds ) ); return new UniquenessConstraintDefinition( this, indexDefinition ); } @@ -529,7 +514,7 @@ public ConstraintDefinition createPropertyUniquenessConstraint( IndexDefinition RepeatedPropertyInCompositeSchemaException e ) { throw new ConstraintViolationException( - e.getUserMessage( new StatementTokenNameLookup( statement.readOperations() ) ), e ); + e.getUserMessage( new SilentTokenNameLookup( transaction.tokenRead() ) ), e ); } catch ( IllegalTokenNameException e ) { @@ -539,7 +524,7 @@ public ConstraintDefinition createPropertyUniquenessConstraint( IndexDefinition { throw new IllegalStateException( e ); } - catch ( InvalidTransactionTypeKernelException e ) + catch ( SchemaKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } @@ -549,15 +534,15 @@ public ConstraintDefinition createPropertyUniquenessConstraint( IndexDefinition @Override public ConstraintDefinition createNodeKeyConstraint( IndexDefinition indexDefinition ) { - try ( Statement statement = ctxSupplier.get() ) + KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); + try ( Statement ignore = transaction.acquireStatement() ) { try { - int labelId = statement.tokenWriteOperations().labelGetOrCreateForName( - indexDefinition.getLabel().name() ); - int[] propertyKeyIds = getOrCreatePropertyKeyIds( - statement.tokenWriteOperations(), indexDefinition ); - statement.schemaWriteOperations().nodeKeyConstraintCreate( + TokenWrite tokenWrite = transaction.tokenWrite(); + int labelId = tokenWrite.labelGetOrCreateForName( indexDefinition.getLabel().name() ); + int[] propertyKeyIds = getOrCreatePropertyKeyIds( tokenWrite, indexDefinition ); + transaction.schemaWrite().nodeKeyConstraintCreate( SchemaDescriptorFactory.forLabel( labelId, propertyKeyIds ) ); return new NodeKeyConstraintDefinition( this, indexDefinition ); } @@ -565,7 +550,7 @@ public ConstraintDefinition createNodeKeyConstraint( IndexDefinition indexDefini RepeatedPropertyInCompositeSchemaException e ) { throw new ConstraintViolationException( - e.getUserMessage( new StatementTokenNameLookup( statement.readOperations() ) ), e ); + e.getUserMessage( new SilentTokenNameLookup( transaction.tokenRead() ) ), e ); } catch ( IllegalTokenNameException e ) { @@ -575,7 +560,7 @@ public ConstraintDefinition createNodeKeyConstraint( IndexDefinition indexDefini { throw new IllegalStateException( e ); } - catch ( InvalidTransactionTypeKernelException e ) + catch ( SchemaKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } @@ -585,22 +570,23 @@ public ConstraintDefinition createNodeKeyConstraint( IndexDefinition indexDefini @Override public ConstraintDefinition createPropertyExistenceConstraint( Label label, String... propertyKeys ) { - try ( Statement statement = ctxSupplier.get() ) + KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); + try ( Statement ignore = transaction.acquireStatement() ) { try { - int labelId = statement.tokenWriteOperations().labelGetOrCreateForName( label.name() ); - int[] propertyKeyIds = getOrCreatePropertyKeyIds( - statement.tokenWriteOperations(), propertyKeys ); - statement.schemaWriteOperations().nodePropertyExistenceConstraintCreate( - SchemaDescriptorFactory.forLabel( labelId, propertyKeyIds ) ); + TokenWrite tokenWrite = transaction.tokenWrite(); + int labelId = tokenWrite.labelGetOrCreateForName( label.name() ); + int[] propertyKeyIds = getOrCreatePropertyKeyIds( tokenWrite, propertyKeys ); + transaction.schemaWrite().nodePropertyExistenceConstraintCreate( + SchemaDescriptorFactory.forLabel( labelId, propertyKeyIds ) ); return new NodePropertyExistenceConstraintDefinition( this, label, propertyKeys ); } catch ( AlreadyConstrainedException | CreateConstraintFailureException | RepeatedPropertyInCompositeSchemaException e ) { throw new ConstraintViolationException( - e.getUserMessage( new StatementTokenNameLookup( statement.readOperations() ) ), e ); + e.getUserMessage( new SilentTokenNameLookup( transaction.tokenRead() ) ), e ); } catch ( IllegalTokenNameException e ) { @@ -610,7 +596,7 @@ public ConstraintDefinition createPropertyExistenceConstraint( Label label, Stri { throw new IllegalStateException( e ); } - catch ( InvalidTransactionTypeKernelException e ) + catch ( SchemaKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } @@ -620,13 +606,15 @@ public ConstraintDefinition createPropertyExistenceConstraint( Label label, Stri @Override public ConstraintDefinition createPropertyExistenceConstraint( RelationshipType type, String propertyKey ) { - try ( Statement statement = ctxSupplier.get() ) + KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); + try ( Statement ignore = transaction.acquireStatement() ) { try { - int typeId = statement.tokenWriteOperations().relationshipTypeGetOrCreateForName( type.name() ); - int[] propertyKeyId = getOrCreatePropertyKeyIds( statement.tokenWriteOperations(), propertyKey ); - statement.schemaWriteOperations().relationshipPropertyExistenceConstraintCreate( + TokenWrite tokenWrite = transaction.tokenWrite(); + int typeId = tokenWrite.relationshipTypeGetOrCreateForName( type.name() ); + int[] propertyKeyId = getOrCreatePropertyKeyIds( tokenWrite, propertyKey ); + transaction.schemaWrite().relationshipPropertyExistenceConstraintCreate( SchemaDescriptorFactory.forRelType( typeId, propertyKeyId ) ); return new RelationshipPropertyExistenceConstraintDefinition( this, type, propertyKey ); } @@ -634,13 +622,13 @@ public ConstraintDefinition createPropertyExistenceConstraint( RelationshipType RepeatedPropertyInCompositeSchemaException e ) { throw new ConstraintViolationException( - e.getUserMessage( new StatementTokenNameLookup( statement.readOperations() ) ), e ); + e.getUserMessage( new SilentTokenNameLookup( transaction.tokenRead() ) ), e ); } catch ( IllegalTokenNameException e ) { throw new IllegalArgumentException( e ); } - catch ( InvalidTransactionTypeKernelException e ) + catch ( SchemaKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } @@ -650,21 +638,23 @@ public ConstraintDefinition createPropertyExistenceConstraint( RelationshipType @Override public void dropPropertyUniquenessConstraint( Label label, String[] properties ) { - try ( Statement statement = ctxSupplier.get() ) + KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); + try ( Statement ignore = transaction.acquireStatement() ) { try { - int labelId = statement.readOperations().labelGetForName( label.name() ); - int[] propertyKeyIds = PropertyNameUtils.getPropertyIds( statement.readOperations(), properties ); - statement.schemaWriteOperations().constraintDrop( + TokenRead tokenRead = transaction.tokenRead(); + int labelId = tokenRead.nodeLabel( label.name() ); + int[] propertyKeyIds = PropertyNameUtils.getPropertyIds( tokenRead, properties ); + transaction.schemaWrite().constraintDrop( ConstraintDescriptorFactory.uniqueForLabel( labelId, propertyKeyIds ) ); } catch ( DropConstraintFailureException e ) { throw new ConstraintViolationException( - e.getUserMessage( new StatementTokenNameLookup( statement.readOperations() ) ), e ); + e.getUserMessage( new SilentTokenNameLookup( transaction.tokenRead() ) ), e ); } - catch ( InvalidTransactionTypeKernelException e ) + catch ( SchemaKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } @@ -674,21 +664,23 @@ public void dropPropertyUniquenessConstraint( Label label, String[] properties ) @Override public void dropNodeKeyConstraint( Label label, String[] properties ) { - try ( Statement statement = ctxSupplier.get() ) + KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); + try ( Statement ignore = transaction.acquireStatement() ) { try { - int labelId = statement.readOperations().labelGetForName( label.name() ); - int[] propertyKeyIds = PropertyNameUtils.getPropertyIds( statement.readOperations(), properties ); - statement.schemaWriteOperations().constraintDrop( + TokenRead tokenRead = transaction.tokenRead(); + int labelId = tokenRead.nodeLabel( label.name() ); + int[] propertyKeyIds = PropertyNameUtils.getPropertyIds( tokenRead, properties ); + transaction.schemaWrite().constraintDrop( ConstraintDescriptorFactory.nodeKeyForLabel( labelId, propertyKeyIds ) ); } catch ( DropConstraintFailureException e ) { throw new ConstraintViolationException( - e.getUserMessage( new StatementTokenNameLookup( statement.readOperations() ) ), e ); + e.getUserMessage( new SilentTokenNameLookup( transaction.tokenRead() ) ), e ); } - catch ( InvalidTransactionTypeKernelException e ) + catch ( SchemaKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } @@ -698,21 +690,23 @@ public void dropNodeKeyConstraint( Label label, String[] properties ) @Override public void dropNodePropertyExistenceConstraint( Label label, String[] properties ) { - try ( Statement statement = ctxSupplier.get() ) + KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); + try ( Statement ignore = transaction.acquireStatement() ) { try { - int labelId = statement.readOperations().labelGetForName( label.name() ); - int[] propertyKeyIds = PropertyNameUtils.getPropertyIds( statement.readOperations(), properties ); - statement.schemaWriteOperations().constraintDrop( + TokenRead tokenRead = transaction.tokenRead(); + int labelId = tokenRead.nodeLabel( label.name() ); + int[] propertyKeyIds = PropertyNameUtils.getPropertyIds( tokenRead, properties ); + transaction.schemaWrite().constraintDrop( ConstraintDescriptorFactory.existsForLabel( labelId, propertyKeyIds ) ); } catch ( DropConstraintFailureException e ) { throw new ConstraintViolationException( - e.getUserMessage( new StatementTokenNameLookup( statement.readOperations() ) ), e ); + e.getUserMessage( new SilentTokenNameLookup( transaction.tokenRead() ) ), e ); } - catch ( InvalidTransactionTypeKernelException e ) + catch ( SchemaKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } @@ -722,21 +716,24 @@ public void dropNodePropertyExistenceConstraint( Label label, String[] propertie @Override public void dropRelationshipPropertyExistenceConstraint( RelationshipType type, String propertyKey ) { - try ( Statement statement = ctxSupplier.get() ) + KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); + try ( Statement ignore = transaction.acquireStatement() ) { try { - int typeId = statement.readOperations().relationshipTypeGetForName( type.name() ); - int propertyKeyId = statement.readOperations().propertyKeyGetForName( propertyKey ); - statement.schemaWriteOperations().constraintDrop( + TokenRead tokenRead = transaction.tokenRead(); + + int typeId = tokenRead.relationshipType( type.name() ); + int propertyKeyId = tokenRead.propertyKey( propertyKey ); + transaction.schemaWrite().constraintDrop( ConstraintDescriptorFactory.existsForRelType( typeId, propertyKeyId ) ); } catch ( DropConstraintFailureException e ) { throw new ConstraintViolationException( - e.getUserMessage( new StatementTokenNameLookup( statement.readOperations() ) ), e ); + e.getUserMessage( new SilentTokenNameLookup( transaction.tokenRead() ) ), e ); } - catch ( InvalidTransactionTypeKernelException e ) + catch ( SchemaKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } @@ -746,16 +743,22 @@ public void dropRelationshipPropertyExistenceConstraint( RelationshipType type, @Override public String getUserMessage( KernelException e ) { - try ( Statement statement = ctxSupplier.get() ) + KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); + try ( Statement ignore = transaction.acquireStatement() ) { - return e.getUserMessage( new StatementTokenNameLookup( statement.readOperations() ) ); + return e.getUserMessage( new SilentTokenNameLookup( transaction.tokenRead() ) ); } } @Override public void assertInOpenTransaction() { - ctxSupplier.get().close(); + KernelTransaction transaction = transactionSupplier.get(); + if ( transaction.isTerminated() ) + { + Status terminationReason = transaction.getReasonIfTerminated().orElse( Status.Transaction.Terminated ); + throw new TransactionTerminatedException( terminationReason ); + } } } }