Skip to content

Commit

Permalink
Delay construction of IndexManager for GDBFacade
Browse files Browse the repository at this point in the history
  • Loading branch information
boggle authored and henriknyman committed Oct 26, 2016
1 parent b66115f commit eb7dd18
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
Expand Up @@ -81,10 +81,10 @@ public class SchemaImpl implements Schema
private final Supplier<Statement> statementContextSupplier; private final Supplier<Statement> statementContextSupplier;
private final InternalSchemaActions actions; private final InternalSchemaActions actions;


public SchemaImpl( Supplier<Statement> statementContextSupplier ) public SchemaImpl( Supplier<Statement> statementSupplier )
{ {
this.statementContextSupplier = statementContextSupplier; this.statementContextSupplier = statementSupplier;
this.actions = new GDBSchemaActions( statementContextSupplier ); this.actions = new GDBSchemaActions( statementSupplier );
} }


@Override @Override
Expand Down Expand Up @@ -397,9 +397,10 @@ else if ( constraint instanceof RelationshipPropertyExistenceConstraint )
private static class GDBSchemaActions implements InternalSchemaActions private static class GDBSchemaActions implements InternalSchemaActions
{ {
private final Supplier<Statement> ctxSupplier; private final Supplier<Statement> ctxSupplier;
public GDBSchemaActions( Supplier<Statement> ctxSupplier )
public GDBSchemaActions( Supplier<Statement> statementSupplier )
{ {
this.ctxSupplier = ctxSupplier; this.ctxSupplier = statementSupplier;
} }


@Override @Override
Expand Down
Expand Up @@ -28,6 +28,8 @@


import org.neo4j.collection.primitive.PrimitiveLongCollections; import org.neo4j.collection.primitive.PrimitiveLongCollections;
import org.neo4j.collection.primitive.PrimitiveLongIterator; import org.neo4j.collection.primitive.PrimitiveLongIterator;
import org.neo4j.function.Suppliers;
import org.neo4j.function.ThrowingAction;
import org.neo4j.graphdb.ConstraintViolationException; import org.neo4j.graphdb.ConstraintViolationException;
import org.neo4j.graphdb.DependencyResolver; import org.neo4j.graphdb.DependencyResolver;
import org.neo4j.graphdb.Label; import org.neo4j.graphdb.Label;
Expand Down Expand Up @@ -106,6 +108,8 @@
import static org.neo4j.function.Suppliers.*; import static org.neo4j.function.Suppliers.*;
import static org.neo4j.helpers.collection.Iterators.emptyIterator; import static org.neo4j.helpers.collection.Iterators.emptyIterator;
import static org.neo4j.kernel.api.security.SecurityContext.AUTH_DISABLED; import static org.neo4j.kernel.api.security.SecurityContext.AUTH_DISABLED;
import static org.neo4j.kernel.impl.api.legacyindex.InternalAutoIndexing.NODE_AUTO_INDEX;
import static org.neo4j.kernel.impl.api.legacyindex.InternalAutoIndexing.RELATIONSHIP_AUTO_INDEX;
import static org.neo4j.kernel.impl.api.operations.KeyReadOperations.NO_SUCH_LABEL; import static org.neo4j.kernel.impl.api.operations.KeyReadOperations.NO_SUCH_LABEL;
import static org.neo4j.kernel.impl.api.operations.KeyReadOperations.NO_SUCH_PROPERTY_KEY; import static org.neo4j.kernel.impl.api.operations.KeyReadOperations.NO_SUCH_PROPERTY_KEY;


Expand All @@ -119,7 +123,7 @@ public class GraphDatabaseFacade implements GraphDatabaseAPI
private static final PropertyContainerLocker locker = new PropertyContainerLocker(); private static final PropertyContainerLocker locker = new PropertyContainerLocker();


private Schema schema; private Schema schema;
private IndexManager indexManager; private Supplier<IndexManager> indexManager;
private NodeProxy.NodeActions nodeActions; private NodeProxy.NodeActions nodeActions;
private RelationshipProxy.RelationshipActions relActions; private RelationshipProxy.RelationshipActions relActions;
private SPI spi; private SPI spi;
Expand Down Expand Up @@ -223,24 +227,25 @@ public void init( SPI spi, Guard guard, ThreadToStatementContextBridge txBridge,
this.spi = spi; this.spi = spi;
this.defaultTransactionTimeout = config.get( GraphDatabaseSettings.transaction_timeout ); this.defaultTransactionTimeout = config.get( GraphDatabaseSettings.transaction_timeout );


// TODO: Initialize these fields lazily, esp for Procedures this makes sense Supplier<Statement> statementSupplier = spi::currentStatement;
this.schema = new SchemaImpl( spi::currentStatement ); Supplier<KernelTransaction> transactionSupplier = spi::currentTransaction;
ThrowingAction<RuntimeException> assertTransactionOpen = this::assertTransactionOpen;


this.relActions = new StandardRelationshipActions( spi::currentStatement, spi::currentTransaction, this.schema = new SchemaImpl( statementSupplier );
this::assertTransactionOpen, ( id ) -> new NodeProxy( nodeActions, id ), this ); this.relActions = new StandardRelationshipActions( statementSupplier, transactionSupplier, assertTransactionOpen, ( id ) -> new NodeProxy( nodeActions, id ), this );
this.nodeActions = new StandardNodeActions( spi::currentStatement, spi::currentTransaction, this.nodeActions = new StandardNodeActions( statementSupplier, transactionSupplier, assertTransactionOpen, relActions, this );
this::assertTransactionOpen, relActions, this );


IndexProviderImpl idxProvider = new IndexProviderImpl( this, spi::currentStatement ); this.indexManager = Suppliers.lazySingleton( () -> {
AutoIndexerFacade<Node> nodeAutoIndexer = new AutoIndexerFacade<>( IndexProviderImpl idxProvider = new IndexProviderImpl( this, statementSupplier );
() -> new ReadOnlyIndexFacade<>( AutoIndexerFacade<Node> nodeAutoIndexer = new AutoIndexerFacade<>(
idxProvider.getOrCreateNodeIndex( InternalAutoIndexing.NODE_AUTO_INDEX, null ) ), () -> new ReadOnlyIndexFacade<>( idxProvider.getOrCreateNodeIndex( NODE_AUTO_INDEX, null ) ),
spi.autoIndexing().nodes() ); spi.autoIndexing().nodes() );
RelationshipAutoIndexerFacade relAutoIndexer = new RelationshipAutoIndexerFacade( RelationshipAutoIndexerFacade relAutoIndexer = new RelationshipAutoIndexerFacade(
() -> new ReadOnlyRelationshipIndexFacade( idxProvider () -> new ReadOnlyRelationshipIndexFacade( idxProvider.getOrCreateRelationshipIndex( RELATIONSHIP_AUTO_INDEX, null ) ),
.getOrCreateRelationshipIndex( InternalAutoIndexing.RELATIONSHIP_AUTO_INDEX, null ) ),
spi.autoIndexing().relationships() ); spi.autoIndexing().relationships() );
this.indexManager = new IndexManagerImpl( spi::currentStatement, idxProvider, nodeAutoIndexer, relAutoIndexer );
return new IndexManagerImpl( statementSupplier, idxProvider, nodeAutoIndexer, relAutoIndexer );
} );


this.contextFactory = new Neo4jTransactionalContextFactory( new Neo4jTransactionalContext.Dependencies() this.contextFactory = new Neo4jTransactionalContextFactory( new Neo4jTransactionalContext.Dependencies()
{ {
Expand Down Expand Up @@ -372,7 +377,7 @@ public Relationship getRelationshipById( long id )
@Override @Override
public IndexManager index() public IndexManager index()
{ {
return indexManager; return indexManager.get();
} }


@Override @Override
Expand Down

0 comments on commit eb7dd18

Please sign in to comment.