@Override public void delete() { KernelTransaction ktx = txBridge.get(); try ( Statement ignore = ktx.acquireStatement() ) { type.drop( ktx.indexWrite(), name ); } catch ( InvalidTransactionTypeKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } catch ( ExplicitIndexNotFoundKernelException e ) { throw new NotFoundException( type + " index '" + name + "' doesn't exist" ); } }
@Override TransactionWriteState upgradeToSchemaWrites() throws InvalidTransactionTypeKernelException { throw new InvalidTransactionTypeKernelException( "Cannot perform schema updates in a transaction that has performed data updates." ); } },
@Override public void remove( T entity ) { KernelTransaction ktx = txBridge.get(); try ( Statement ignore = ktx.acquireStatement() ) { internalRemove( ktx, type.id( entity ) ); } catch ( InvalidTransactionTypeKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } catch ( ExplicitIndexNotFoundKernelException e ) { throw new NotFoundException( type + " index '" + name + "' doesn't exist" ); } }
@Override TransactionWriteState upgradeToDataWrites() throws InvalidTransactionTypeKernelException { throw new InvalidTransactionTypeKernelException( "Cannot perform data updates in a transaction that has performed schema updates." ); } };
@Override public void add( T entity, String key, Object value ) { KernelTransaction ktx = txBridge.get(); try ( Statement ignore = ktx.acquireStatement() ) { internalAdd( entity, key, value, ktx ); } catch ( EntityNotFoundException e ) { throw new NotFoundException( format( "%s %d not found", type, type.id( entity ) ), e ); } catch ( InvalidTransactionTypeKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } catch ( ExplicitIndexNotFoundKernelException e ) { throw new NotFoundException( type + " index '" + name + "' doesn't exist" ); } }
@Override TransactionWriteState upgradeToSchemaWrites() throws InvalidTransactionTypeKernelException { throw new InvalidTransactionTypeKernelException( "Cannot perform schema updates in a transaction that has performed data updates." ); } },
@Override public void remove( T entity, String key ) { KernelTransaction ktx = txBridge.get(); try ( Statement ignore = ktx.acquireStatement() ) { type.remove( ktx.indexWrite(), name, type.id( entity ), key ); } catch ( InvalidTransactionTypeKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } catch ( ExplicitIndexNotFoundKernelException e ) { throw new NotFoundException( type + " index '" + name + "' doesn't exist" ); } }
@Override TransactionWriteState upgradeToDataWrites() throws InvalidTransactionTypeKernelException { throw new InvalidTransactionTypeKernelException( "Cannot perform data updates in a transaction that has performed schema updates." ); } };
@Override public Long createNodeId() { KernelTransaction transaction = statementContext.getKernelTransactionBoundToThisThread( true ); try ( Statement ignore = transaction.acquireStatement() ) { return transaction.dataWrite().nodeCreate(); } catch ( InvalidTransactionTypeKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } }
@Override public void remove( T entity, String key, Object value ) { KernelTransaction ktx = txBridge.get(); try ( Statement ignore = ktx.acquireStatement() ) { type.remove( ktx.indexWrite(), name, type.id( entity ), key, value ); } catch ( InvalidTransactionTypeKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } catch ( ExplicitIndexNotFoundKernelException e ) { throw new NotFoundException( type + " index '" + name + "' doesn't exist" ); } }
@Override public String removeConfiguration( Index<? extends PropertyContainer> index, String key ) { // Configuration changes should be done transactionally. However this // has always been done non-transactionally, so it's not a regression. try { Transaction transaction = transactionBridge.get(); if ( index.getEntityType().equals( Node.class ) ) { return transaction.indexWrite().nodeExplicitIndexRemoveConfiguration( index.getName(), key ); } if ( index.getEntityType().equals( Relationship.class ) ) { return transaction.indexWrite().relationshipExplicitIndexRemoveConfiguration( index.getName(), key ); } throw new IllegalArgumentException( "Unknown entity type " + index.getEntityType().getSimpleName() ); } catch ( InvalidTransactionTypeKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } catch ( ExplicitIndexNotFoundKernelException e ) { throw new NotFoundException( e ); } }
@Override public Object removeProperty( String key ) { KernelTransaction transaction = safeAcquireTransaction(); int propertyKeyId; try { propertyKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName( key ); } catch ( IllegalTokenNameException e ) { throw new IllegalArgumentException( format( "Invalid property key '%s'.", key ), e ); } try ( Statement ignore = transaction.acquireStatement() ) { return transaction.dataWrite().graphRemoveProperty( propertyKeyId ).asObjectCopy(); } catch ( InvalidTransactionTypeKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } }
@Override public String setConfiguration( Index<? extends PropertyContainer> index, String key, String value ) { // Configuration changes should be done transactionally. However this // has always been done non-transactionally, so it's not a regression. try { Transaction transaction = transactionBridge.get(); if ( index.getEntityType().equals( Node.class ) ) { return transaction.indexWrite().nodeExplicitIndexSetConfiguration( index.getName(), key, value ); } if ( index.getEntityType().equals( Relationship.class ) ) { return transaction.indexWrite().relationshipExplicitIndexSetConfiguration( index.getName(), key, value ); } throw new IllegalArgumentException( "Unknown entity type " + index.getEntityType().getSimpleName() ); } catch ( InvalidTransactionTypeKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } catch ( ExplicitIndexNotFoundKernelException e ) { throw new NotFoundException( e ); } }
@Override public Node createNode() { KernelTransaction transaction = statementContext.getKernelTransactionBoundToThisThread( true ); try ( Statement ignore = transaction.acquireStatement() ) { return newNodeProxy( transaction.dataWrite().nodeCreate() ); } catch ( InvalidTransactionTypeKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } }
@Override public void setProperty( String key, Object value ) { KernelTransaction transaction = safeAcquireTransaction(); int propertyKeyId; try { propertyKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName( key ); } catch ( IllegalTokenNameException e ) { throw new IllegalArgumentException( format( "Invalid property key '%s'.", key ), e ); } try ( Statement ignore = transaction.acquireStatement() ) { transaction.dataWrite().graphSetProperty( propertyKeyId, Values.of( value, false ) ); } catch ( InvalidTransactionTypeKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } }
@Override public void delete() { KernelTransaction transaction = safeAcquireTransaction(); try { boolean deleted = transaction.dataWrite().nodeDelete( getId() ); if ( !deleted ) { throw new NotFoundException( "Unable to delete Node[" + nodeId + "] since it has already been deleted." ); } } catch ( InvalidTransactionTypeKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } catch ( AutoIndexingKernelException e ) { throw new IllegalStateException( "Auto indexing encountered a failure while deleting the node: " + e.getMessage(), e ); } }
@Override public Object removeProperty( String key ) { KernelTransaction transaction = spi.kernelTransaction(); try ( Statement ignore = transaction.acquireStatement() ) { int propertyKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName( key ); return transaction.dataWrite().relationshipRemoveProperty( id, propertyKeyId ).asObjectCopy(); } catch ( EntityNotFoundException e ) { throw new NotFoundException( e ); } catch ( IllegalTokenNameException e ) { throw new IllegalArgumentException( format( "Invalid property key '%s'.", key ), e ); } catch ( InvalidTransactionTypeKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } catch ( AutoIndexingKernelException e ) { throw new IllegalStateException( "Auto indexing encountered a failure while removing property: " + e.getMessage(), e ); } }
@Override public Index<Node> getOrCreateNodeIndex( String indexName, Map<String,String> customConfiguration ) { KernelTransaction ktx = transactionBridge.get(); try ( Statement ignore = ktx.acquireStatement() ) { if ( !ktx.indexRead().nodeExplicitIndexExists( indexName, customConfiguration ) ) { // There's a sub-o-meta thing here where we create index config, // and the index will itself share the same IndexConfigStore as us and pick up and use // that. We should pass along config somehow with calls. ktx.indexWrite().nodeExplicitIndexCreateLazily( indexName, customConfiguration ); } return new ExplicitIndexProxy<>( indexName, ExplicitIndexProxy.NODE, gds, transactionBridge ); } catch ( InvalidTransactionTypeKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } }
@Override public RelationshipIndex getOrCreateRelationshipIndex( String indexName, Map<String, String> customConfiguration ) { KernelTransaction ktx = transactionBridge.get(); try ( Statement ignore = ktx.acquireStatement() ) { if ( !ktx.indexRead().relationshipExplicitIndexExists( indexName, customConfiguration ) ) { // There's a sub-o-meta thing here where we create index config, // and the index will itself share the same IndexConfigStore as us and pick up and use // that. We should pass along config somehow with calls. ktx.indexWrite().relationshipExplicitIndexCreateLazily( indexName, customConfiguration ); } return new RelationshipExplicitIndexProxy( indexName, gds, transactionBridge ); } catch ( InvalidTransactionTypeKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } } }
@Override public Object removeProperty( String key ) throws NotFoundException { KernelTransaction transaction = spi.kernelTransaction(); try ( Statement ignore = transaction.acquireStatement() ) { int propertyKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName( key ); return transaction.dataWrite().nodeRemoveProperty( nodeId, propertyKeyId ).asObjectCopy(); } catch ( EntityNotFoundException e ) { throw new NotFoundException( e ); } catch ( IllegalTokenNameException e ) { throw new IllegalArgumentException( format( "Invalid property key '%s'.", key ), e ); } catch ( InvalidTransactionTypeKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } catch ( AutoIndexingKernelException e ) { throw new IllegalStateException( "Auto indexing encountered a failure while removing property: " + e.getMessage(), e ); } }