@Override public SchemaWrite schemaWrite() throws InvalidTransactionTypeKernelException { return internal.schemaWrite(); }
@Test public void shouldAllowSchemaStatementAfterSchemaStatement() throws Exception { // given KernelTransaction tx = kernelTransaction( AUTH_DISABLED ); tx.schemaWrite(); // when / then tx.schemaWrite(); }
@Description( "Drop the specified index." ) @Procedure( name = "db.index.fulltext.drop", mode = SCHEMA ) public void drop( @Name( "indexName" ) String name ) throws InvalidTransactionTypeKernelException, SchemaKernelException { IndexReference indexReference = getValidIndexReference( name ); tx.schemaWrite().indexDrop( indexReference ); }
@Description( "Create a relationship fulltext index for the given relationship types and properties. " + "The optional 'config' map parameter can be used to supply settings to the index. " + "Note: index specific settings are currently experimental, and might not replicated correctly in a cluster, or during backup. " + "Supported settings are '" + INDEX_CONFIG_ANALYZER + "', for specifying what analyzer to use " + "when indexing and querying. Use the `db.index.fulltext.listAvailableAnalyzers` procedure to see what options are available. " + "And '" + INDEX_CONFIG_EVENTUALLY_CONSISTENT + "' which can be set to 'true' to make this index eventually consistent, " + "such that updates from committing transactions are applied in a background thread." ) @Procedure( name = "db.index.fulltext.createRelationshipIndex", mode = SCHEMA ) public void createRelationshipFulltextIndex( @Name( "indexName" ) String name, @Name( "relationshipTypes" ) List<String> relTypes, @Name( "propertyNames" ) List<String> properties, @Name( value = "config", defaultValue = "" ) Map<String,String> config ) throws InvalidTransactionTypeKernelException, SchemaKernelException { Properties settings = new Properties(); settings.putAll( config ); SchemaDescriptor schemaDescriptor = accessor.schemaFor( EntityType.RELATIONSHIP, stringArray( relTypes ), settings, stringArray( properties ) ); tx.schemaWrite().indexCreate( schemaDescriptor, DESCRIPTOR.name(), Optional.of( name ) ); }
@Description( "Create a node fulltext index for the given labels and properties. " + "The optional 'config' map parameter can be used to supply settings to the index. " + "Note: index specific settings are currently experimental, and might not replicated correctly in a cluster, or during backup. " + "Supported settings are '" + INDEX_CONFIG_ANALYZER + "', for specifying what analyzer to use " + "when indexing and querying. Use the `db.index.fulltext.listAvailableAnalyzers` procedure to see what options are available. " + "And '" + INDEX_CONFIG_EVENTUALLY_CONSISTENT + "' which can be set to 'true' to make this index eventually consistent, " + "such that updates from committing transactions are applied in a background thread." ) @Procedure( name = "db.index.fulltext.createNodeIndex", mode = SCHEMA ) public void createNodeFulltextIndex( @Name( "indexName" ) String name, @Name( "labels" ) List<String> labels, @Name( "propertyNames" ) List<String> properties, @Name( value = "config", defaultValue = "" ) Map<String,String> indexConfigurationMap ) throws InvalidTransactionTypeKernelException, SchemaKernelException { Properties indexConfiguration = new Properties(); indexConfiguration.putAll( indexConfigurationMap ); SchemaDescriptor schemaDescriptor = accessor.schemaFor( EntityType.NODE, stringArray( labels ), indexConfiguration, stringArray( properties ) ); tx.schemaWrite().indexCreate( schemaDescriptor, DESCRIPTOR.name(), Optional.of( name ) ); }
@Test public void shouldAllowSchemaStatementAfterReadStatement() throws Exception { // given KernelTransaction tx = kernelTransaction( AUTH_DISABLED ); tx.dataRead(); // when / then tx.schemaWrite(); }
@Test public void shouldAllowReadStatementAfterSchemaStatement() throws Exception { // given KernelTransaction tx = kernelTransaction( AUTH_DISABLED ); tx.schemaWrite(); // when / then tx.dataRead(); } }
private Stream<BuiltInProcedures.SchemaIndexInfo> createIndex( String indexSpecification, String providerName, String statusMessage, IndexCreator indexCreator ) throws ProcedureException { assertProviderNameNotNull( providerName ); IndexSpecifier index = IndexSpecifier.byPattern( indexSpecification ); int labelId = getOrCreateLabelId( index.label() ); int[] propertyKeyIds = getOrCreatePropertyIds( index.properties() ); try { SchemaWrite schemaWrite = ktx.schemaWrite(); LabelSchemaDescriptor labelSchemaDescriptor = SchemaDescriptorFactory.forLabel( labelId, propertyKeyIds ); indexCreator.create( schemaWrite, labelSchemaDescriptor, providerName ); return Stream.of( new BuiltInProcedures.SchemaIndexInfo( indexSpecification, providerName, statusMessage ) ); } catch ( InvalidTransactionTypeKernelException | SchemaKernelException e ) { throw new ProcedureException( e.status(), e, e.getMessage() ); } }
private void dropIndex( IndexReference index ) throws KernelException { try ( Transaction tx = db.beginTx() ) { KernelTransaction ktx = bridge.getKernelTransactionBoundToThisThread( true ); try ( Statement ignore = ktx.acquireStatement() ) { ktx.schemaWrite().indexDrop( index ); } tx.success(); } }
@Override public IndexDefinition createIndexDefinition( Label label, Optional<String> indexName, String... propertyKeys ) { KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); try ( Statement ignore = transaction.acquireStatement() ) { try { TokenWrite tokenWrite = transaction.tokenWrite(); int labelId = tokenWrite.labelGetOrCreateForName( label.name() ); int[] propertyKeyIds = getOrCreatePropertyKeyIds( tokenWrite, propertyKeys ); LabelSchemaDescriptor descriptor = forLabel( labelId, propertyKeyIds ); IndexReference indexReference = transaction.schemaWrite().indexCreate( descriptor, indexName ); return new IndexDefinitionImpl( this, indexReference, new Label[]{label}, propertyKeys, false ); } catch ( IllegalTokenNameException e ) { throw new IllegalArgumentException( e ); } catch ( InvalidTransactionTypeKernelException | SchemaKernelException e ) { throw new ConstraintViolationException( e.getUserMessage( new SilentTokenNameLookup( transaction.tokenRead() ) ), e ); } } }
@Override public void dropIndexDefinitions( IndexDefinition indexDefinition ) { KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); try ( Statement ignore = transaction.acquireStatement() ) { try { IndexReference reference = getIndexReference( transaction.schemaRead(), transaction.tokenRead(), (IndexDefinitionImpl) indexDefinition ); transaction.schemaWrite().indexDrop( reference ); } catch ( NotFoundException e ) { // Silently ignore invalid label and property names } catch ( SchemaRuleNotFoundException | DropIndexFailureException e ) { throw new ConstraintViolationException( e.getUserMessage( new SilentTokenNameLookup( transaction.tokenRead() ) ), e ); } catch ( InvalidTransactionTypeKernelException | SchemaKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } } }
@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 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() ); } }
@Override public void dropNodePropertyExistenceConstraint( Label label, String[] properties ) { KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); try ( Statement ignore = transaction.acquireStatement() ) { try { TokenRead tokenRead = transaction.tokenRead(); int labelId = tokenRead.nodeLabel( label.name() ); int[] propertyKeyIds = resolveAndValidatePropertyKeys( tokenRead, properties ); transaction.schemaWrite().constraintDrop( ConstraintDescriptorFactory.existsForLabel( labelId, propertyKeyIds ) ); } catch ( DropConstraintFailureException e ) { throw new ConstraintViolationException( e.getUserMessage( new SilentTokenNameLookup( transaction.tokenRead() ) ), e ); } catch ( InvalidTransactionTypeKernelException | SchemaKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } } }
@Override public void dropNodeKeyConstraint( Label label, String[] properties ) { KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); try ( Statement ignore = transaction.acquireStatement() ) { try { TokenRead tokenRead = transaction.tokenRead(); int labelId = tokenRead.nodeLabel( label.name() ); int[] propertyKeyIds = resolveAndValidatePropertyKeys( tokenRead, properties ); transaction.schemaWrite().constraintDrop( ConstraintDescriptorFactory.nodeKeyForLabel( labelId, propertyKeyIds ) ); } catch ( DropConstraintFailureException e ) { throw new ConstraintViolationException( e.getUserMessage( new SilentTokenNameLookup( transaction.tokenRead() ) ), e ); } catch ( InvalidTransactionTypeKernelException | SchemaKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } } }
@Override public void dropPropertyUniquenessConstraint( Label label, String[] properties ) { KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); try ( Statement ignore = transaction.acquireStatement() ) { try { TokenRead tokenRead = transaction.tokenRead(); int labelId = tokenRead.nodeLabel( label.name() ); int[] propertyKeyIds = resolveAndValidatePropertyKeys( tokenRead, properties ); transaction.schemaWrite().constraintDrop( ConstraintDescriptorFactory.uniqueForLabel( labelId, propertyKeyIds ) ); } catch ( DropConstraintFailureException e ) { throw new ConstraintViolationException( e.getUserMessage( new SilentTokenNameLookup( transaction.tokenRead() ) ), e ); } catch ( InvalidTransactionTypeKernelException | SchemaKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } } }
@Override public void dropRelationshipPropertyExistenceConstraint( RelationshipType type, String propertyKey ) { KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); try ( Statement ignore = transaction.acquireStatement() ) { try { TokenRead tokenRead = transaction.tokenRead(); int typeId = tokenRead.relationshipType( type.name() ); int propertyKeyId = tokenRead.propertyKey( propertyKey ); transaction.schemaWrite().constraintDrop( ConstraintDescriptorFactory.existsForRelType( typeId, propertyKeyId ) ); } catch ( DropConstraintFailureException e ) { throw new ConstraintViolationException( e.getUserMessage( new SilentTokenNameLookup( transaction.tokenRead() ) ), e ); } catch ( InvalidTransactionTypeKernelException | SchemaKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } } }
@Override protected void createCompositeIndex( GraphDatabaseService graphDb, String label, String... properties ) throws Exception { GraphDatabaseAPI internal = (GraphDatabaseAPI) graphDb; KernelTransaction ktx = internal.getDependencyResolver() .resolveDependency( ThreadToStatementContextBridge.class ) .getKernelTransactionBoundToThisThread( true ); SchemaWrite schemaWrite = ktx.schemaWrite(); TokenWrite token = ktx.tokenWrite(); schemaWrite.indexCreate( SchemaDescriptorFactory.forLabel( token.labelGetOrCreateForName( "Person" ), token.propertyKeyGetOrCreateForName( "firstname" ), token.propertyKeyGetOrCreateForName( "surname" ) ) ); } }
@Test public void shouldNotAllowCreationOfConstraintsWhenInHA() throws Exception { //noinspection deprecation GraphDatabaseAPI db = new FakeHaDatabase(); ThreadToStatementContextBridge stmtBridge = db.getDependencyResolver().resolveDependency( ThreadToStatementContextBridge.class ); try ( Transaction ignored = db.beginTx() ) { KernelTransaction ktx = stmtBridge.getKernelTransactionBoundToThisThread( true ); try { ktx.schemaWrite().uniquePropertyConstraintCreate( forLabel( 1, 1 ) ); fail( "expected exception here" ); } catch ( InvalidTransactionTypeKernelException e ) { assertThat( e.getMessage(), containsString( "HA" ) ); } } db.shutdown(); }
private IndexReference createPersonNameIndex() throws KernelException { try ( Transaction tx = db.beginTx() ) { IndexReference index; KernelTransaction ktx = bridge.getKernelTransactionBoundToThisThread( true ); try ( Statement ignore = ktx.acquireStatement() ) { int labelId = ktx.tokenWrite().labelGetOrCreateForName( PERSON_LABEL ); int propertyKeyId = ktx.tokenWrite().propertyKeyGetOrCreateForName( NAME_PROPERTY ); LabelSchemaDescriptor descriptor = forLabel( labelId, propertyKeyId ); index = ktx.schemaWrite().indexCreate( descriptor ); } tx.success(); return index; } }