@Override public Write dataWrite() throws InvalidTransactionTypeKernelException { return internal.dataWrite(); }
@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 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 ); } }
private long createPersonNode( KernelTransaction ktx, Object value ) throws KernelException { int labelId = ktx.tokenWrite().labelGetOrCreateForName( PERSON_LABEL ); int propertyKeyId = ktx.tokenWrite().propertyKeyGetOrCreateForName( NAME_PROPERTY ); long nodeId = ktx.dataWrite().nodeCreate(); ktx.dataWrite().nodeAddLabel( nodeId, labelId ); ktx.dataWrite().nodeSetProperty( nodeId, propertyKeyId, Values.of( value ) ); return nodeId; }
@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 ); } }
@Test public void shouldAllowReadStatementAfterDataStatement() throws Exception { // given KernelTransaction tx = kernelTransaction( AnonymousContext.write() ); tx.dataWrite(); // when / then tx.dataRead(); }
@Test public void shouldAllowDataStatementAfterReadStatement() throws Exception { // given KernelTransaction tx = kernelTransaction( AnonymousContext.write() ); tx.dataRead(); // when / then tx.dataWrite(); }
public long makeNode( String label ) throws ProcedureException { long result; try ( Transaction tx = graph.beginTransaction( KernelTransaction.Type.explicit, AnonymousContext.write() ) ) { KernelTransaction ktx = txBridge.getKernelTransactionBoundToThisThread( true ); long nodeId = ktx.dataWrite().nodeCreate(); int labelId = ktx.tokenWrite().labelGetOrCreateForName( label ); ktx.dataWrite().nodeAddLabel( nodeId, labelId ); result = nodeId; tx.success(); } catch ( Exception e ) { log.error( "Failed to create node: " + e.getMessage() ); throw new ProcedureException( Status.Procedure.ProcedureCallFailed, "Failed to create node: " + e.getMessage(), e ); } return result; }
@Test public void shouldHandleNodeDetachDeleteConcurrentlyWithIndexDrop() throws Throwable { shouldHandleIndexDropConcurrentlyWithOperation( nodeId -> { ThreadToStatementContextBridge txBridge = db.getDependencyResolver().resolveDependency( ThreadToStatementContextBridge.class ); txBridge.getKernelTransactionBoundToThisThread( true ).dataWrite().nodeDetachDelete( nodeId ); } ); }
@Test public void shouldRejectDataStatementAfterSchemaStatement() throws Exception { // given KernelTransaction tx = kernelTransaction( AUTH_DISABLED ); tx.schemaWrite(); // when try { tx.dataWrite(); fail( "expected exception" ); } // then catch ( InvalidTransactionTypeKernelException e ) { assertEquals( "Cannot perform data updates in a transaction that has performed schema updates.", e.getMessage() ); } }
@Test( expected = TransactionTerminatedException.class ) public void shouldThrowTerminateExceptionWhenTransactionTerminated() throws KernelException { KernelTransaction transaction = newTransaction( AnonymousContext.write() ); transaction.success(); transaction.markForTermination( Status.General.UnknownError ); transactionOperation.operate( transaction.dataRead(), transaction.dataWrite(), transaction.schemaRead() ); }
@Test( expected = NotInTransactionException.class ) public void shouldThrowNotInTransactionWhenTransactionClosedAndAttemptingOperations() throws KernelException { KernelTransaction transaction = newTransaction( AnonymousContext.write() ); Read read = transaction.dataRead(); Write write = transaction.dataWrite(); SchemaRead schemaRead = transaction.schemaRead(); transaction.success(); transaction.close(); transactionOperation.operate( read, write, schemaRead ); }
@Test public void shouldRejectSchemaStatementAfterDataStatement() throws Exception { // given KernelTransaction tx = kernelTransaction( AUTH_DISABLED ); tx.dataWrite(); // when try { tx.schemaWrite(); fail( "expected exception" ); } // then catch ( InvalidTransactionTypeKernelException e ) { assertEquals( "Cannot perform schema updates in a transaction that has performed data updates.", e.getMessage() ); } }
@Test( expected = NotInTransactionException.class ) public void shouldThrowNotInTransactionWhenTransactionClosedAndAccessingOperations() throws KernelException { KernelTransaction transaction = newTransaction( AnonymousContext.write() ); transaction.success(); transaction.close(); transactionOperation.operate( transaction.dataRead(), transaction.dataWrite(), transaction.schemaRead() ); }
@Test public void shouldNotSeeNodeThatWasDeletedInTransaction() throws Exception { long nodeID = createNode(); try ( Transaction ignore = graphDatabaseAPI.beginTx() ) { KernelTransaction ktx = ktx(); ktx.dataWrite().nodeDelete( nodeID ); try ( NodeValueIndexCursor cursor = seek( ktx ) ) { assertFalse( cursor.next() ); } } }
@Test public void shouldNotSeeNodeThatHasItsLabelRemovedInTransaction() throws Exception { long nodeID = createNode(); try ( Transaction ignore = graphDatabaseAPI.beginTx() ) { KernelTransaction ktx = ktx(); ktx.dataWrite().nodeRemoveLabel( nodeID, LABEL_ID ); try ( NodeValueIndexCursor cursor = seek( ktx ) ) { assertFalse( cursor.next() ); } } }
private long createNode() throws KernelException { long nodeID; try ( Transaction tx = graphDatabaseAPI.beginTx() ) { KernelTransaction ktx = ktx(); Write write = ktx.dataWrite(); nodeID = write.nodeCreate(); write.nodeAddLabel( nodeID, LABEL_ID ); for ( int propID : index.schema().getPropertyIds() ) { write.nodeSetProperty( nodeID, propID, Values.intValue( propID ) ); } tx.success(); } return nodeID; }
@Test public void shouldNotSeeNodeThatHasAPropertyRemovedInTransaction() throws Exception { long nodeID = createNode(); try ( Transaction ignore = graphDatabaseAPI.beginTx() ) { KernelTransaction ktx = ktx(); ktx.dataWrite().nodeRemoveProperty( nodeID, index.schema().getPropertyIds()[0] ); try ( NodeValueIndexCursor cursor = seek( ktx ) ) { assertFalse( cursor.next() ); } } }
@Test public void mixingBeansApiWithKernelAPI() throws Exception { // 1: Start your transactions through the Beans API Transaction transaction = db.beginTx(); // 2: Get a hold of a KernelAPI transaction this way: KernelTransaction ktx = statementContextSupplier.getKernelTransactionBoundToThisThread( true ); // 3: Now you can interact through both the statement context and the kernel API to manipulate the // same transaction. Node node = db.createNode(); int labelId = ktx.tokenWrite().labelGetOrCreateForName( "labello" ); ktx.dataWrite().nodeAddLabel( node.getId(), labelId ); // 4: Commit through the beans API transaction.success(); transaction.close(); }