private long createNode( Write write, int... labels ) throws KernelException { long nodeId = write.nodeCreate(); for ( int label : labels ) { write.nodeAddLabel( nodeId, label ); } return nodeId; } }
private long createNode() throws KernelException { return transaction.dataWrite().nodeCreate(); }
@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 createLabeledNode( int labelId ) throws KernelException { long node = transaction.dataWrite().nodeCreate(); transaction.dataWrite().nodeAddLabel( node, labelId ); return node; }
private void createNodeWithProperty( Transaction tx, int propId1 ) throws KernelException { long node = tx.dataWrite().nodeCreate(); tx.dataWrite().nodeSetProperty( node, propId1, Values.intValue( 42 ) ); }
private long createNodeWithValue( Value value ) throws KernelException { Write write = dataWriteInNewTransaction(); long nodeId = write.nodeCreate(); write.nodeAddLabel( nodeId, labelId ); write.nodeSetProperty( nodeId, propertyId1, value ); commit(); return nodeId; }
private long createNodeWithValues( Value value1, Value value2 ) throws KernelException { Write write = dataWriteInNewTransaction(); long nodeId = write.nodeCreate(); write.nodeAddLabel( nodeId, labelId ); write.nodeSetProperty( nodeId, propertyId1, value1 ); write.nodeSetProperty( nodeId, propertyId2, value2 ); commit(); return nodeId; }
private long createLabeledNode( Transaction transaction, String label ) throws KernelException { long node = transaction.dataWrite().nodeCreate(); int labelId = transaction.tokenWrite().labelGetOrCreateForName( label ); transaction.dataWrite().nodeAddLabel( node, labelId ); return node; }
private long createNode( Transaction transaction, String key, Object value ) throws KernelException { long node = transaction.dataWrite().nodeCreate(); int propertyKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName( key ); transaction.dataWrite().nodeSetProperty( node, propertyKeyId, Values.of( value ) ); return node; }
@Test public void shouldSeeNodeExistingInTxOnly() throws Exception { try ( Transaction tx = beginTransaction() ) { long node = tx.dataWrite().nodeCreate(); assertTrue( tx.dataRead().nodeExists( node ) ); } }
@Test public void shouldReturnRelsWhenAskingForRelsWhereOnlySomeTypesExistInCurrentRel() throws Exception { Transaction transaction = newTransaction( AnonymousContext.writeToken() ); int relType1 = transaction.tokenWrite().relationshipTypeGetOrCreateForName( "Type1" ); int relType2 = transaction.tokenWrite().relationshipTypeGetOrCreateForName( "Type2" ); long refNode = transaction.dataWrite().nodeCreate(); long otherNode = transaction.dataWrite().nodeCreate(); long theRel = transaction.dataWrite().relationshipCreate( refNode, relType1, otherNode ); assertRels( nodeGetRelationships( transaction, refNode, OUTGOING, new int[]{relType2,relType1} ), theRel ); commit(); }
@Parameterized.Parameters( name = "{0}" ) public static Collection<Object[]> parameters() { // Some samples of operations that should react to transaction killing. Not exhaustive. return Arrays.asList( operation( "nodeExists", ( read, write, schema ) -> read.nodeExists( 0 ) ), operation( "singleRelationship", ( read, write, schema ) -> read.singleRelationship( 0, null ) ), operation( "nodeCreate", ( read, write, schema ) -> write.nodeCreate() ), operation( "relationshipSetProperty", ( read, write, schema ) -> write.relationshipSetProperty( 0, 2, Values.longValue( 42 ) ) ), operation( "indexesGetAll", ( read, write, schema ) -> schema.indexesGetAll() ) ); }
@Test public void createIndexForAnotherLabelWhileHoldingSharedLockOnOtherLabel() throws KernelException { TokenWrite tokenWrite = tokenWriteInNewTransaction(); int label2 = tokenWrite.labelGetOrCreateForName( "Label2" ); Write write = dataWriteInNewTransaction(); long nodeId = write.nodeCreate(); write.nodeAddLabel( nodeId, label2 ); schemaWriteInNewTransaction().indexCreate( descriptor ); commit(); }
private Pair<Long,Value> nodeWithProp( Transaction tx, Object value ) throws Exception { Write write = tx.dataWrite(); long node = write.nodeCreate(); write.nodeAddLabel( node, tx.tokenWrite().labelGetOrCreateForName( "Node" ) ); Value val = Values.of( value ); write.nodeSetProperty( node, tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ), val ); return Pair.of( node, val ); }
private Pair<Long,Value> nodeWithProp( Transaction tx, Object value ) throws Exception { Write write = tx.dataWrite(); long node = write.nodeCreate(); write.nodeAddLabel( node, tx.tokenWrite().labelGetOrCreateForName( "Node" ) ); Value val = Values.of( value ); write.nodeSetProperty( node, tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ), val ); return Pair.of( node, val ); } }
@Test public void txReturnsCorrectIdWhenRolledBack() throws Exception { executeDummyTxs( db, 42 ); org.neo4j.internal.kernel.api.Transaction tx = newTransaction( AUTH_DISABLED ); tx.dataWrite().nodeCreate(); tx.failure(); assertEquals( KernelTransaction.ROLLBACK, tx.closeTransaction() ); assertFalse( tx.isOpen() ); }
@Test public void txReturnsCorrectIdWhenMarkedForTermination() throws Exception { executeDummyTxs( db, 42 ); org.neo4j.internal.kernel.api.Transaction tx = newTransaction( AUTH_DISABLED ); tx.dataWrite().nodeCreate(); tx.markForTermination( Status.Transaction.Terminated ); assertEquals( KernelTransaction.ROLLBACK, tx.closeTransaction() ); assertFalse( tx.isOpen() ); }
@Test public void txReturnsCorrectIdWhenFailedAndMarkedForTermination() throws Exception { executeDummyTxs( db, 42 ); org.neo4j.internal.kernel.api.Transaction tx = newTransaction( AUTH_DISABLED ); tx.dataWrite().nodeCreate(); tx.failure(); tx.markForTermination( Status.Transaction.Terminated ); assertEquals( KernelTransaction.ROLLBACK, tx.closeTransaction() ); assertFalse( tx.isOpen() ); }
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; }
@Test public void txReturnsCorrectIdWhenCommitted() throws Exception { executeDummyTxs( db, 42 ); org.neo4j.internal.kernel.api.Transaction tx = newTransaction( AUTH_DISABLED ); tx.dataWrite().nodeCreate(); tx.success(); long previousCommittedTxId = lastCommittedTxId( db ); assertEquals( previousCommittedTxId + 1, tx.closeTransaction() ); assertFalse( tx.isOpen() ); }