public IndexDescriptor createConstraintIndex( final SchemaDescriptor schema, String provider ) { try ( Transaction transaction = kernelSupplier.get().beginTransaction( implicit, AUTH_DISABLED ) ) { IndexDescriptor index = ((KernelTransaction) transaction).indexUniqueCreate( schema, provider ); transaction.success(); return index; } catch ( TransactionFailureException | SchemaKernelException e ) { throw new RuntimeException( e ); } } }
@Override public synchronized int createToken( String name ) throws KernelException { Kernel kernel = kernelSupplier.get(); try ( Transaction tx = kernel.beginTransaction( Type.implicit, LoginContext.AUTH_DISABLED ) ) { int id = createKey( tx, name ); tx.success(); return id; } }
protected void commit() throws TransactionFailureException { transaction.success(); try { transaction.close(); } finally { transaction = null; } }
protected void commit() throws TransactionFailureException { transaction.success(); try { transaction.close(); } finally { transaction = null; } }
/** * You MUST hold a schema write lock before you call this method. */ public void dropUniquenessConstraintIndex( IndexDescriptor descriptor ) throws TransactionFailureException { try ( Transaction transaction = kernelSupplier.get().beginTransaction( implicit, AUTH_DISABLED ); Statement ignore = ((KernelTransaction)transaction).acquireStatement() ) { ((KernelTransactionImplementation) transaction).txState().indexDoDrop( descriptor ); transaction.success(); } }
@After public void closeTransaction() throws Exception { tx.success(); tx.close(); }
private void awaitSchemaStateCleared( String keyForProbing ) throws TransactionFailureException { try ( Transaction transaction = kernel.beginTransaction( implicit, AUTH_DISABLED ) ) { while ( transaction.schemaRead().schemaStateGetOrCreate( keyForProbing, ignored -> null ) != null ) { LockSupport.parkNanos( MILLISECONDS.toNanos( 10 ) ); } transaction.success(); } }
private String commitToSchemaState( String key, String value ) throws TransactionFailureException { try ( Transaction transaction = kernel.beginTransaction( implicit, AUTH_DISABLED ) ) { String result = getOrCreateFromState( transaction, key, value ); transaction.success(); return result; } }
private int getPropertyKeyForName( String name ) throws TransactionFailureException { try ( Transaction tx = kernel.beginTransaction( implicit, AUTH_DISABLED ) ) { int result = tx.tokenRead().propertyKey( name ); tx.success(); return result; } }
private void dropConstraint( ConstraintDescriptor descriptor ) throws KernelException { try ( Transaction transaction = kernel.beginTransaction( implicit, AUTH_DISABLED ) ) { transaction.schemaWrite().constraintDrop( descriptor ); transaction.success(); } }
private void dropIndex( IndexReference reference ) throws KernelException { try ( Transaction transaction = kernel.beginTransaction( implicit, AUTH_DISABLED ) ) { transaction.schemaWrite().indexDrop( reference ); transaction.success(); } }
private IndexReference createIndex() throws KernelException { try ( Transaction transaction = kernel.beginTransaction( implicit, AUTH_DISABLED ) ) { IndexReference reference = transaction.schemaWrite().indexCreate( SchemaDescriptorFactory.forLabel( 1, 1 ) ); transaction.success(); return reference; } }
private void awaitIndexOnline( IndexReference descriptor, String keyForProbing ) throws IndexNotFoundKernelException, TransactionFailureException { try ( Transaction transaction = kernel.beginTransaction( implicit, AUTH_DISABLED ) ) { SchemaIndexTestHelper.awaitIndexOnline( transaction.schemaRead(), descriptor ); transaction.success(); } awaitSchemaStateCleared( keyForProbing ); }
@Test public void createdIndexShouldPopulateInTx() throws Exception { IndexReference index; try ( Transaction tx = beginTransaction() ) { index = tx.schemaWrite().indexCreate( labelDescriptor( label, prop1 ) ); assertThat( tx.schemaRead().indexGetState( index ), equalTo( InternalIndexState.POPULATING ) ); tx.success(); } }
private ConstraintDescriptor createConstraint() throws KernelException { try ( Transaction transaction = kernel.beginTransaction( implicit, AUTH_DISABLED ) ) { ConstraintDescriptor descriptor = transaction.schemaWrite().uniquePropertyConstraintCreate( SchemaDescriptorFactory.forLabel( 1, 1 ) ); transaction.success(); return descriptor; } }
@Test public void shouldNotWriteWhenSettingPropertyToSameValue() throws Exception { // Given Value theValue = stringValue( "The Value" ); long nodeId = createNodeWithProperty( propertyKey, theValue.asObject() ); // When Transaction tx = beginTransaction(); int property = tx.token().propertyKeyGetOrCreateForName( propertyKey ); assertThat( tx.dataWrite().nodeSetProperty( nodeId, property, theValue ), equalTo( theValue ) ); tx.success(); assertThat( tx.closeTransaction(), equalTo( Transaction.READ_ONLY ) ); }
@Test public void shouldFailToDropNoIndex() throws Exception { //Expect exception.expect( SchemaKernelException.class ); try ( Transaction transaction = beginTransaction() ) { transaction.schemaWrite().indexDrop( IndexReference.NO_INDEX ); transaction.success(); } }
@Test public void shouldAddLabelNodeOnce() throws Exception { long node = createNodeWithLabel( labelName ); try ( Transaction tx = beginTransaction() ) { int labelId = tx.token().labelGetOrCreateForName( labelName ); assertFalse( tx.dataWrite().nodeAddLabel( node, labelId ) ); tx.success(); } assertLabels( node, labelName ); }
@Test public void shouldRemoveLabel() throws Exception { long nodeId = createNodeWithLabel( labelName ); try ( Transaction tx = beginTransaction() ) { int labelId = tx.token().labelGetOrCreateForName( labelName ); assertTrue( tx.dataWrite().nodeRemoveLabel( nodeId, labelId ) ); tx.success(); } assertNoLabels( 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() ); }