@Override public SchemaRead schemaRead() { return internal.schemaRead(); }
private IndexReference getValidIndexReference( @Name( "indexName" ) String name ) { IndexReference indexReference = tx.schemaRead().indexGetForName( name ); if ( indexReference == IndexReference.NO_INDEX ) { throw new IllegalArgumentException( "There is no such fulltext schema index: " + name ); } return indexReference; }
private String getFailure( IndexSpecifier indexDescription, IndexReference index ) throws ProcedureException { try { return ktx.schemaRead().indexGetFailure( index ); } catch ( IndexNotFoundKernelException e ) { throw new ProcedureException( Status.Schema.IndexNotFound, e, "No such index %s", indexDescription ); } }
private InternalIndexState getState( IndexSpecifier specifier, IndexReference index ) throws ProcedureException { try { return ktx.schemaRead().indexGetState( index ); } catch ( IndexNotFoundKernelException e ) { throw new ProcedureException( Status.Schema.IndexNotFound, e, "No such index %s", specifier ); } }
@Override boolean inUse( KernelTransaction transaction, int tokenId ) { return hasAny( transaction.schemaRead().constraintsGetForRelationshipType( tokenId ) ) || // used by constraint transaction.dataRead().countsForRelationship( ANY_LABEL, tokenId, ANY_LABEL ) > 0; // used by data } };
@Description( "List all constraints in the database." ) @Procedure( name = "db.constraints", mode = READ ) public Stream<ConstraintResult> listConstraints() { SchemaRead schemaRead = tx.schemaRead(); TokenNameLookup tokens = new SilentTokenNameLookup( tx.tokenRead() ); return asList( schemaRead.constraintsGetAll() ) .stream() .map( constraint -> constraint.prettyPrint( tokens ) ) .sorted() .map( ConstraintResult::new ); }
@Override public Iterable<IndexDefinition> getIndexes() { KernelTransaction transaction = transactionSupplier.get(); SchemaRead schemaRead = transaction.schemaRead(); try ( Statement ignore = transaction.acquireStatement() ) { List<IndexDefinition> definitions = new ArrayList<>(); Iterator<IndexReference> indexes = schemaRead.indexesGetAll(); addDefinitions( definitions, transaction.tokenRead(), IndexReference.sortByType( indexes ) ); return definitions; } }
@Override boolean inUse( KernelTransaction transaction, int tokenId ) { SchemaRead schemaRead = transaction.schemaRead(); return hasAny( schemaRead.indexesGetForLabel( tokenId ) ) || // used by index hasAny( schemaRead.constraintsGetForLabel( tokenId ) ) || // used by constraint transaction.dataRead().countsForNode( tokenId ) > 0; // used by data } };
private static KernelTransaction mockKernelTransaction() throws IndexNotFoundKernelException { SchemaRead schemaRead = mock( SchemaRead.class ); when( schemaRead.indexGetState( any( IndexReference.class ) ) ).thenReturn( InternalIndexState.FAILED ); when( schemaRead.indexGetFailure( any( IndexReference.class ) ) ).thenReturn( Exceptions.stringify( cause ) ); KernelTransaction kt = mock( KernelTransaction.class ); when( kt.tokenRead() ).thenReturn( mock( TokenRead.class ) ); when( kt.schemaRead() ).thenReturn( schemaRead ); when( kt.isTerminated() ).thenReturn( false ); when( kt.acquireStatement() ).thenReturn( mock( Statement.class ) ); return kt; } }
@Before public void setup() { KernelTransaction transaction = mock( KernelTransaction.class ); tokenRead = mock( TokenRead.class ); schemaRead = mock( SchemaRead.class ); procedure = new IndexProcedures( transaction, null ); when( transaction.tokenRead() ).thenReturn( tokenRead ); when( transaction.schemaRead() ).thenReturn( schemaRead ); indexingService = mock( IndexingService.class ); procedure = new IndexProcedures( transaction, indexingService ); }
@Override public Iterable<ConstraintDefinition> getConstraints() { KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); try ( Statement ignore = transaction.acquireStatement() ) { return asConstraintDefinitions( transaction.schemaRead().constraintsGetAll(), transaction.tokenRead() ); } }
private double getSelectivity( IndexReference reference ) throws IndexNotFoundKernelException { return bridge.getKernelTransactionBoundToThisThread( true ).schemaRead().indexUniqueValuesSelectivity( reference ); }
@Before public void setup() { transaction = mock( KernelTransaction.class ); tokenRead = mock( TokenRead.class ); schemaRead = mock( SchemaRead.class ); procedure = new IndexProcedures( transaction, null ); descriptor = SchemaDescriptorFactory.forLabel( 123, 456 ); anyDescriptor = SchemaDescriptorFactory.forLabel( 0, 0 ); anyIndex = forSchema( anyDescriptor ); when( transaction.tokenRead() ).thenReturn( tokenRead ); when( transaction.schemaRead() ).thenReturn( schemaRead ); }
@Override public String getIndexFailure( IndexDefinition index ) { KernelTransaction transaction = safeAcquireTransaction( transactionSupplier ); try ( Statement ignore = transaction.acquireStatement() ) { SchemaRead schemaRead = transaction.schemaRead(); IndexReference descriptor = getIndexReference( schemaRead, transaction.tokenRead(), (IndexDefinitionImpl) index ); return schemaRead.indexGetFailure( descriptor ); } catch ( SchemaRuleNotFoundException | IndexNotFoundKernelException e ) { throw newIndexNotFoundException( index, e ); } }
@Override void lockAcquired( boolean exclusive, ResourceType resourceType, long... ids ) { if ( !executed ) { ThreadToStatementContextBridge bridge = databaseRule.resolveDependency( ThreadToStatementContextBridge.class ); KernelTransaction ktx = bridge.getKernelTransactionBoundToThisThread( true ); ktx.schemaRead().schemaStateFlush(); } executed = true; } }
private void showIndices( DbStructureVisitor visitor, KernelTransaction ktx, TokenNameLookup nameLookup ) throws IndexNotFoundKernelException { SchemaRead schemaRead = ktx.schemaRead(); for ( IndexReference reference : loop( sortByType( schemaRead.indexesGetAll() ) ) ) { String userDescription = reference.schema().userDescription( nameLookup ); double uniqueValuesPercentage = schemaRead.indexUniqueValuesSelectivity( reference ); long size = schemaRead.indexSize( reference ); visitor.visitIndex( (IndexDescriptor) reference, userDescription, uniqueValuesPercentage, size ); } }
private String getOrCreateSchemaState( String key, final String maybeSetThisState ) { try ( Transaction tx = db.beginTx() ) { KernelTransaction ktx = statementContextSupplier.getKernelTransactionBoundToThisThread( true ); String state = ktx.schemaRead().schemaStateGetOrCreate( key, s -> maybeSetThisState ); tx.success(); return state; } }
@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( 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() ); }