protected SchemaWrite schemaWriteInNewTransaction() throws KernelException { transaction = kernel.beginTransaction( implicit, AUTH_DISABLED ); return transaction.schemaWrite(); }
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(); } }
@Test public void shouldNotSeeDroppedIndexFromTransaction() throws Exception { IndexReference index; try ( Transaction transaction = beginTransaction() ) { index = transaction.schemaWrite().indexCreate( labelDescriptor( label, prop1 ) ); transaction.success(); } try ( Transaction transaction = beginTransaction() ) { transaction.schemaWrite().indexDrop( index ); SchemaRead schemaRead = transaction.schemaRead(); assertThat( schemaRead.index( label, prop2 ), equalTo( NO_INDEX ) ); } }
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; } }
@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(); } }
@Test( expected = SchemaKernelException.class ) public void shouldFailUniquenessConstraintCreateForRepeatedProperties() throws Exception { try ( Transaction tx = beginTransaction() ) { tx.schemaWrite().uniquePropertyConstraintCreate( labelDescriptor( label, prop1, prop1 ) ); } }
@Test( expected = SchemaKernelException.class ) public void shouldFailNodeKeyCreateForRepeatedProperties() throws Exception { try ( Transaction tx = beginTransaction() ) { tx.schemaWrite().nodeKeyConstraintCreate( labelDescriptor( label, prop1, prop1 ) ); } }
@Test( expected = SchemaKernelException.class ) public void shouldFailIndexCreateForRepeatedProperties() throws Exception { try ( Transaction tx = beginTransaction() ) { tx.schemaWrite().indexCreate( labelDescriptor( label, prop1, prop1 ) ); } }
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 shouldNotSeeDroppedNodeKeyConstraintFromTransaction() throws Exception { ConstraintDescriptor existing; try ( Transaction transaction = beginTransaction() ) { existing = transaction.schemaWrite().nodeKeyConstraintCreate( labelDescriptor( label, prop1 ) ); transaction.success(); } try ( Transaction transaction = beginTransaction() ) { transaction.schemaWrite().constraintDrop( existing ); SchemaRead schemaRead = transaction.schemaRead(); assertFalse( schemaRead.constraintExists( existing ) ); assertThat( asList( schemaRead.constraintsGetForLabel( label ) ), empty() ); } }
private IndexReference createIndex( org.neo4j.internal.kernel.api.Transaction transaction ) throws SchemaKernelException, InvalidTransactionTypeKernelException { TokenWrite tokenWrite = transaction.tokenWrite(); SchemaWrite schemaWrite = transaction.schemaWrite(); LabelSchemaDescriptor schemaDescriptor = forLabel( tokenWrite.labelGetOrCreateForName( "hello" ), tokenWrite.propertyKeyGetOrCreateForName( "hepp" ) ); return schemaWrite.indexCreate( schemaDescriptor ); }
@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 shouldNotSeeDroppedUniqueConstraintFromTransaction() throws Exception { ConstraintDescriptor existing; try ( Transaction transaction = beginTransaction() ) { existing = transaction.schemaWrite().uniquePropertyConstraintCreate( labelDescriptor( label, prop1 ) ); transaction.success(); } try ( Transaction transaction = beginTransaction() ) { transaction.schemaWrite().constraintDrop( existing ); SchemaRead schemaRead = transaction.schemaRead(); assertFalse( schemaRead.constraintExists( existing ) ); assertThat( asList( schemaRead.constraintsGetForLabel( label ) ), empty() ); } }
@Test public void shouldCreateIndex() throws Exception { IndexReference index; try ( Transaction transaction = beginTransaction() ) { index = transaction.schemaWrite().indexCreate( labelDescriptor( label, prop1 ) ); transaction.success(); } try ( Transaction transaction = beginTransaction() ) { SchemaRead schemaRead = transaction.schemaRead(); assertThat( schemaRead.index( label, prop1 ), equalTo( index ) ); } }
@Test public void shouldCreateNodePropertyExistenceConstraint() throws Exception { ConstraintDescriptor constraint; try ( Transaction transaction = beginTransaction() ) { constraint = transaction.schemaWrite().nodePropertyExistenceConstraintCreate( labelDescriptor( label, prop1 ) ); transaction.success(); } try ( Transaction transaction = beginTransaction() ) { SchemaRead schemaRead = transaction.schemaRead(); assertTrue( schemaRead.constraintExists( constraint ) ); Iterator<ConstraintDescriptor> constraints = schemaRead.constraintsGetForLabel( label ); assertThat( asList( constraints ), equalTo( singletonList( constraint ) ) ); } }
@Test public void shouldFailIfExistingIndex() throws Exception { //Given try ( Transaction transaction = beginTransaction() ) { transaction.schemaWrite().indexCreate( labelDescriptor( label, prop1 ) ); transaction.success(); } //Expect exception.expect( SchemaKernelException.class ); //When try ( Transaction transaction = beginTransaction() ) { transaction.schemaWrite().indexCreate( labelDescriptor( label, prop1 ) ); transaction.success(); } }
private IndexReference createUniquenessConstraint( int labelId, int... propertyIds ) throws Exception { Transaction transaction = newTransaction( LoginContext.AUTH_DISABLED ); LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel( labelId, propertyIds ); transaction.schemaWrite().uniquePropertyConstraintCreate( descriptor ); IndexReference result = transaction.schemaRead().index( descriptor.getLabelId(), descriptor.getPropertyIds() ); commit(); return result; } }
@Before public void setup() throws Exception { graphDatabaseAPI = dbRule.getGraphDatabaseAPI(); kernel = graphDatabaseAPI.getDependencyResolver().resolveDependency( Kernel.class ); newTransaction(); transaction.schemaWrite().uniquePropertyConstraintCreate( forLabel( label, propertyIds() ) ); commit(); }
@Test public void committedAndTransactionalIndexRulesShouldBeMerged() throws Exception { // GIVEN SchemaWrite schemaWriteOperations = schemaWriteInNewTransaction(); IndexReference existingRule = schemaWriteOperations.indexCreate( descriptor ); commit(); // WHEN Transaction transaction = newTransaction( AUTH_DISABLED ); IndexReference addedRule = transaction.schemaWrite() .indexCreate( SchemaDescriptorFactory.forLabel( labelId, 10 ) ); Set<IndexReference> indexRulesInTx = asSet( transaction.schemaRead().indexesGetForLabel( labelId ) ); commit(); // THEN assertEquals( asSet( existingRule, addedRule ), indexRulesInTx ); }