public String getUserMessage( TokenNameLookup tokenNameLookup ) { return getMessage(); } }
public AutoIndexingKernelException( KernelException cause ) { super( cause.status(), cause, cause.getMessage() ); } }
private void forToken( ThrowingConsumer<Token, KernelException> f ) { try ( Transaction tx = beginTransaction() ) { f.accept( tx.token() ); } catch ( KernelException e ) { fail( "Unwanted exception: " + e.getMessage() ); } } }
private int mapToken( ThrowingFunction<Token, Integer, KernelException> f ) { try ( Transaction tx = beginTransaction() ) { return f.apply( tx.token() ); } catch ( KernelException e ) { fail( "Unwanted exception: " + e.getMessage() ); return -1; // unreachable } }
@Override public long countsForRelationship( int startLabelId, int typeId, int endLabelId ) { long count = countsForRelationshipWithoutTxState( startLabelId, typeId, endLabelId ); if ( ktx.hasTxStateWithChanges() ) { CountsRecordState counts = new CountsRecordState(); try { TransactionState txState = ktx.txState(); txState.accept( new TransactionCountingStateVisitor( EMPTY, storageReader, txState, counts ) ); if ( counts.hasChanges() ) { count += counts.relationshipCount( startLabelId, typeId, endLabelId, newDoubleLongRegister() ) .readSecond(); } } catch ( ConstraintValidationException | CreateConstraintFailureException e ) { throw new IllegalArgumentException( "Unexpected error: " + e.getMessage() ); } } return count; }
@Override public long countsForNode( int labelId ) { long count = countsForNodeWithoutTxState( labelId ); if ( ktx.hasTxStateWithChanges() ) { CountsRecordState counts = new CountsRecordState(); try { TransactionState txState = ktx.txState(); txState.accept( new TransactionCountingStateVisitor( EMPTY, storageReader, txState, counts ) ); if ( counts.hasChanges() ) { count += counts.nodeCount( labelId, newDoubleLongRegister() ).readSecond(); } } catch ( ConstraintValidationException | CreateConstraintFailureException e ) { throw new IllegalArgumentException( "Unexpected error: " + e.getMessage() ); } } return count; }
private Stream<BuiltInProcedures.SchemaIndexInfo> createIndex( String indexSpecification, String providerName, String statusMessage, IndexCreator indexCreator ) throws ProcedureException { assertProviderNameNotNull( providerName ); IndexSpecifier index = IndexSpecifier.byPattern( indexSpecification ); int labelId = getOrCreateLabelId( index.label() ); int[] propertyKeyIds = getOrCreatePropertyIds( index.properties() ); try { SchemaWrite schemaWrite = ktx.schemaWrite(); LabelSchemaDescriptor labelSchemaDescriptor = SchemaDescriptorFactory.forLabel( labelId, propertyKeyIds ); indexCreator.create( schemaWrite, labelSchemaDescriptor, providerName ); return Stream.of( new BuiltInProcedures.SchemaIndexInfo( indexSpecification, providerName, statusMessage ) ); } catch ( InvalidTransactionTypeKernelException | SchemaKernelException e ) { throw new ProcedureException( e.status(), e, e.getMessage() ); } }
throw new ConstraintViolationException( e.getMessage(), e );
throw new ConstraintViolationException( e.getMessage(), e );
private void assertIllegalToken( ThrowingConsumer<Token, KernelException> f ) { try ( Transaction tx = beginTransaction() ) { f.accept( tx.token() ); fail( "Expected IllegalTokenNameException" ); } catch ( IllegalTokenNameException e ) { // wanted } catch ( KernelException e ) { fail( "Unwanted exception: " + e.getMessage() ); } }
@Override public void removeLabel( Label label ) { KernelTransaction transaction = spi.kernelTransaction(); try ( Statement ignore = transaction.acquireStatement() ) { int labelId = transaction.tokenRead().nodeLabel( label.name() ); if ( labelId != TokenRead.NO_TOKEN ) { transaction.dataWrite().nodeRemoveLabel( getId(), labelId ); } } catch ( EntityNotFoundException e ) { throw new NotFoundException( "No node with id " + getId() + " found.", e ); } catch ( KernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } }
throw new ConstraintViolationException( e.getMessage(), e );
@Override public void dropIndexDefinitions( IndexDefinition indexDefinition ) { KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); try ( Statement ignore = transaction.acquireStatement() ) { try { IndexReference reference = getIndexReference( transaction.schemaRead(), transaction.tokenRead(), (IndexDefinitionImpl) indexDefinition ); transaction.schemaWrite().indexDrop( reference ); } catch ( NotFoundException e ) { // Silently ignore invalid label and property names } catch ( SchemaRuleNotFoundException | DropIndexFailureException e ) { throw new ConstraintViolationException( e.getUserMessage( new SilentTokenNameLookup( transaction.tokenRead() ) ), e ); } catch ( InvalidTransactionTypeKernelException | SchemaKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } } }
@Override public void dropNodePropertyExistenceConstraint( Label label, String[] properties ) { KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); try ( Statement ignore = transaction.acquireStatement() ) { try { TokenRead tokenRead = transaction.tokenRead(); int labelId = tokenRead.nodeLabel( label.name() ); int[] propertyKeyIds = resolveAndValidatePropertyKeys( tokenRead, properties ); transaction.schemaWrite().constraintDrop( ConstraintDescriptorFactory.existsForLabel( labelId, propertyKeyIds ) ); } catch ( DropConstraintFailureException e ) { throw new ConstraintViolationException( e.getUserMessage( new SilentTokenNameLookup( transaction.tokenRead() ) ), e ); } catch ( InvalidTransactionTypeKernelException | SchemaKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } } }
throw new ConstraintViolationException( e.getMessage(), e );
@Override public void dropPropertyUniquenessConstraint( Label label, String[] properties ) { KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); try ( Statement ignore = transaction.acquireStatement() ) { try { TokenRead tokenRead = transaction.tokenRead(); int labelId = tokenRead.nodeLabel( label.name() ); int[] propertyKeyIds = resolveAndValidatePropertyKeys( tokenRead, properties ); transaction.schemaWrite().constraintDrop( ConstraintDescriptorFactory.uniqueForLabel( labelId, propertyKeyIds ) ); } catch ( DropConstraintFailureException e ) { throw new ConstraintViolationException( e.getUserMessage( new SilentTokenNameLookup( transaction.tokenRead() ) ), e ); } catch ( InvalidTransactionTypeKernelException | SchemaKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } } }
@Override public void dropNodeKeyConstraint( Label label, String[] properties ) { KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); try ( Statement ignore = transaction.acquireStatement() ) { try { TokenRead tokenRead = transaction.tokenRead(); int labelId = tokenRead.nodeLabel( label.name() ); int[] propertyKeyIds = resolveAndValidatePropertyKeys( tokenRead, properties ); transaction.schemaWrite().constraintDrop( ConstraintDescriptorFactory.nodeKeyForLabel( labelId, propertyKeyIds ) ); } catch ( DropConstraintFailureException e ) { throw new ConstraintViolationException( e.getUserMessage( new SilentTokenNameLookup( transaction.tokenRead() ) ), e ); } catch ( InvalidTransactionTypeKernelException | SchemaKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } } }
throw new ConstraintViolationException( e.getMessage(), e );
@Override public void dropRelationshipPropertyExistenceConstraint( RelationshipType type, String propertyKey ) { KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); try ( Statement ignore = transaction.acquireStatement() ) { try { 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 SilentTokenNameLookup( transaction.tokenRead() ) ), e ); } catch ( InvalidTransactionTypeKernelException | SchemaKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } } }
throw new ConstraintViolationException( e.getMessage(), e );