Search in sources :

Example 21 with ThreadToStatementContextBridge

use of org.neo4j.kernel.impl.core.ThreadToStatementContextBridge in project neo4j by neo4j.

the class StoreUpgradeIntegrationTest method checkGlobalNodeCount.

private static void checkGlobalNodeCount(Store store, GraphDatabaseAPI db) {
    try (Transaction ignored = db.beginTx()) {
        ThreadToStatementContextBridge bridge = db.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class);
        Statement statement = bridge.get();
        assertThat(statement.readOperations().countsForNode(-1), is(store.expectedNodeCount));
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Statement(org.neo4j.kernel.api.Statement) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)

Example 22 with ThreadToStatementContextBridge

use of org.neo4j.kernel.impl.core.ThreadToStatementContextBridge in project neo4j by neo4j.

the class GraphDatabaseFacade method init.

/**
     * Create a new Core API facade, backed by the given SPI and using pre-resolved dependencies
     */
public void init(SPI spi, Guard guard, ThreadToStatementContextBridge txBridge, Config config) {
    this.spi = spi;
    this.defaultTransactionTimeout = config.get(GraphDatabaseSettings.transaction_timeout);
    Supplier<Statement> statementSupplier = spi::currentStatement;
    Supplier<KernelTransaction> transactionSupplier = spi::currentTransaction;
    ThrowingAction<RuntimeException> assertTransactionOpen = this::assertTransactionOpen;
    this.schema = new SchemaImpl(statementSupplier);
    this.relActions = new StandardRelationshipActions(statementSupplier, transactionSupplier, assertTransactionOpen, (id) -> new NodeProxy(nodeActions, id), this);
    this.nodeActions = new StandardNodeActions(statementSupplier, transactionSupplier, assertTransactionOpen, relActions, this);
    this.indexManager = Suppliers.lazySingleton(() -> {
        IndexProviderImpl idxProvider = new IndexProviderImpl(this, statementSupplier);
        AutoIndexerFacade<Node> nodeAutoIndexer = new AutoIndexerFacade<>(() -> new ReadOnlyIndexFacade<>(idxProvider.getOrCreateNodeIndex(NODE_AUTO_INDEX, null)), spi.autoIndexing().nodes());
        RelationshipAutoIndexerFacade relAutoIndexer = new RelationshipAutoIndexerFacade(() -> new ReadOnlyRelationshipIndexFacade(idxProvider.getOrCreateRelationshipIndex(RELATIONSHIP_AUTO_INDEX, null)), spi.autoIndexing().relationships());
        return new IndexManagerImpl(statementSupplier, idxProvider, nodeAutoIndexer, relAutoIndexer);
    });
    this.contextFactory = Neo4jTransactionalContextFactory.create(spi, guard, txBridge, locker);
}
Also used : InternalIndexState(org.neo4j.kernel.api.index.InternalIndexState) StoreId(org.neo4j.kernel.impl.store.StoreId) RELATIONSHIP_AUTO_INDEX(org.neo4j.kernel.impl.api.legacyindex.InternalAutoIndexing.RELATIONSHIP_AUTO_INDEX) ResourceIterator(org.neo4j.graphdb.ResourceIterator) Suppliers(org.neo4j.function.Suppliers) ResourceClosingIterator(org.neo4j.helpers.collection.ResourceClosingIterator) URL(java.net.URL) ResourceIterable(org.neo4j.graphdb.ResourceIterable) Status(org.neo4j.kernel.api.exceptions.Status) TransactionEventHandler(org.neo4j.graphdb.event.TransactionEventHandler) TopLevelTransaction(org.neo4j.kernel.impl.coreapi.TopLevelTransaction) Statement(org.neo4j.kernel.api.Statement) Property(org.neo4j.kernel.api.properties.Property) RelationshipProxy(org.neo4j.kernel.impl.core.RelationshipProxy) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) RelationshipAutoIndexerFacade(org.neo4j.kernel.impl.coreapi.RelationshipAutoIndexerFacade) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) NODE_AUTO_INDEX(org.neo4j.kernel.impl.api.legacyindex.InternalAutoIndexing.NODE_AUTO_INDEX) AutoIndexerFacade(org.neo4j.kernel.impl.coreapi.AutoIndexerFacade) Map(java.util.Map) NodePropertyDescriptor(org.neo4j.kernel.api.schema.NodePropertyDescriptor) Transaction(org.neo4j.graphdb.Transaction) TransactionalContextFactory(org.neo4j.kernel.impl.query.TransactionalContextFactory) QueryExecutionException(org.neo4j.graphdb.QueryExecutionException) PrefetchingResourceIterator(org.neo4j.helpers.collection.PrefetchingResourceIterator) KernelEventHandler(org.neo4j.graphdb.event.KernelEventHandler) BidirectionalTraversalDescriptionImpl(org.neo4j.kernel.impl.traversal.BidirectionalTraversalDescriptionImpl) Result(org.neo4j.graphdb.Result) URLAccessValidationError(org.neo4j.graphdb.security.URLAccessValidationError) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) IndexProviderImpl(org.neo4j.kernel.impl.coreapi.IndexProviderImpl) BidirectionalTraversalDescription(org.neo4j.graphdb.traversal.BidirectionalTraversalDescription) InvalidTransactionTypeKernelException(org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException) KernelException(org.neo4j.kernel.api.exceptions.KernelException) StandardRelationshipActions(org.neo4j.kernel.impl.coreapi.StandardRelationshipActions) String.format(java.lang.String.format) Schema(org.neo4j.graphdb.schema.Schema) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) NO_SUCH_LABEL(org.neo4j.kernel.impl.api.operations.KeyReadOperations.NO_SUCH_LABEL) TransactionTerminatedException(org.neo4j.graphdb.TransactionTerminatedException) IndexManager(org.neo4j.graphdb.index.IndexManager) Neo4jTransactionalContextFactory(org.neo4j.kernel.impl.query.Neo4jTransactionalContextFactory) Optional(java.util.Optional) DependencyResolver(org.neo4j.graphdb.DependencyResolver) RelationshipType(org.neo4j.graphdb.RelationshipType) GraphDatabaseSettings(org.neo4j.graphdb.factory.GraphDatabaseSettings) Guard(org.neo4j.kernel.guard.Guard) Label(org.neo4j.graphdb.Label) PlaceboTransaction(org.neo4j.kernel.impl.coreapi.PlaceboTransaction) TransactionalContext(org.neo4j.kernel.impl.query.TransactionalContext) SchemaImpl(org.neo4j.kernel.impl.coreapi.schema.SchemaImpl) EntityType(org.neo4j.storageengine.api.EntityType) StandardNodeActions(org.neo4j.kernel.impl.coreapi.StandardNodeActions) SchemaKernelException(org.neo4j.kernel.api.exceptions.schema.SchemaKernelException) MonoDirectionalTraversalDescription(org.neo4j.kernel.impl.traversal.MonoDirectionalTraversalDescription) NotFoundException(org.neo4j.graphdb.NotFoundException) Supplier(java.util.function.Supplier) SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException) Node(org.neo4j.graphdb.Node) GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) IndexManagerImpl(org.neo4j.kernel.impl.coreapi.IndexManagerImpl) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) SecurityContext(org.neo4j.kernel.api.security.SecurityContext) ReadOnlyRelationshipIndexFacade(org.neo4j.kernel.impl.coreapi.ReadOnlyRelationshipIndexFacade) ThrowingAction(org.neo4j.function.ThrowingAction) NO_SUCH_PROPERTY_KEY(org.neo4j.kernel.impl.api.operations.KeyReadOperations.NO_SUCH_PROPERTY_KEY) TokenAccess(org.neo4j.kernel.impl.api.TokenAccess) AutoIndexing(org.neo4j.kernel.api.legacyindex.AutoIndexing) Config(org.neo4j.kernel.configuration.Config) ReadOnlyIndexFacade(org.neo4j.kernel.impl.coreapi.ReadOnlyIndexFacade) PrimitiveLongCollections(org.neo4j.collection.primitive.PrimitiveLongCollections) ReadOperations(org.neo4j.kernel.api.ReadOperations) IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) PrimitiveLongCollections.map(org.neo4j.collection.primitive.PrimitiveLongCollections.map) Iterators.emptyIterator(org.neo4j.helpers.collection.Iterators.emptyIterator) NodeProxy(org.neo4j.kernel.impl.core.NodeProxy) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) File(java.io.File) PropertyContainerLocker(org.neo4j.kernel.impl.coreapi.PropertyContainerLocker) TimeUnit(java.util.concurrent.TimeUnit) TraversalDescription(org.neo4j.graphdb.traversal.TraversalDescription) Relationship(org.neo4j.graphdb.Relationship) AUTH_DISABLED(org.neo4j.kernel.api.security.SecurityContext.AUTH_DISABLED) KeyReadOperations(org.neo4j.kernel.impl.api.operations.KeyReadOperations) MultipleFoundException(org.neo4j.graphdb.MultipleFoundException) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ClientConnectionInfo(org.neo4j.kernel.impl.query.clientconnection.ClientConnectionInfo) ConstraintValidationException(org.neo4j.kernel.api.exceptions.schema.ConstraintValidationException) Collections(java.util.Collections) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) RelationshipAutoIndexerFacade(org.neo4j.kernel.impl.coreapi.RelationshipAutoIndexerFacade) Statement(org.neo4j.kernel.api.Statement) RelationshipAutoIndexerFacade(org.neo4j.kernel.impl.coreapi.RelationshipAutoIndexerFacade) AutoIndexerFacade(org.neo4j.kernel.impl.coreapi.AutoIndexerFacade) ReadOnlyRelationshipIndexFacade(org.neo4j.kernel.impl.coreapi.ReadOnlyRelationshipIndexFacade) IndexProviderImpl(org.neo4j.kernel.impl.coreapi.IndexProviderImpl) NodeProxy(org.neo4j.kernel.impl.core.NodeProxy) StandardNodeActions(org.neo4j.kernel.impl.coreapi.StandardNodeActions) IndexManagerImpl(org.neo4j.kernel.impl.coreapi.IndexManagerImpl) SchemaImpl(org.neo4j.kernel.impl.coreapi.schema.SchemaImpl) StandardRelationshipActions(org.neo4j.kernel.impl.coreapi.StandardRelationshipActions) ReadOnlyIndexFacade(org.neo4j.kernel.impl.coreapi.ReadOnlyIndexFacade)

Example 23 with ThreadToStatementContextBridge

use of org.neo4j.kernel.impl.core.ThreadToStatementContextBridge in project neo4j by neo4j.

the class LabelsAcceptanceTest method shouldAllowManyLabelsAndPropertyCursor.

@Test
public void shouldAllowManyLabelsAndPropertyCursor() throws Exception {
    int propertyCount = 10;
    int labelCount = 15;
    GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI();
    Node node;
    try (Transaction tx = db.beginTx()) {
        node = db.createNode();
        for (int i = 0; i < propertyCount; i++) {
            node.setProperty("foo" + i, "bar");
        }
        for (int i = 0; i < labelCount; i++) {
            node.addLabel(label("label" + i));
        }
        tx.success();
    }
    Set<Integer> seenProperties = new HashSet<>();
    Set<Integer> seenLabels = new HashSet<>();
    try (Transaction tx = db.beginTx()) {
        DependencyResolver resolver = db.getDependencyResolver();
        ThreadToStatementContextBridge bridge = resolver.resolveDependency(ThreadToStatementContextBridge.class);
        try (Statement statement = bridge.getTopLevelTransactionBoundToThisThread(true).acquireStatement()) {
            try (Cursor<NodeItem> nodeCursor = statement.readOperations().nodeCursorById(node.getId())) {
                try (Cursor<PropertyItem> properties = statement.readOperations().nodeGetProperties(nodeCursor.get())) {
                    while (properties.next()) {
                        seenProperties.add(properties.get().propertyKeyId());
                        consume(nodeCursor.get().labels().iterator(), seenLabels::add);
                    }
                }
            }
        }
        tx.success();
    }
    assertEquals(propertyCount, seenProperties.size());
    assertEquals(labelCount, seenLabels.size());
}
Also used : Statement(org.neo4j.kernel.api.Statement) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) NodeItem(org.neo4j.storageengine.api.NodeItem) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) PropertyItem(org.neo4j.storageengine.api.PropertyItem) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 24 with ThreadToStatementContextBridge

use of org.neo4j.kernel.impl.core.ThreadToStatementContextBridge in project neo4j by neo4j.

the class TransactionStateMachineSPITest method createTxSpi.

private static TransactionStateMachineSPI createTxSpi(TransactionIdStore txIdStore, Duration txAwaitDuration, AvailabilityGuard availabilityGuard, Clock clock) {
    GraphDatabaseQueryService queryService = mock(GraphDatabaseQueryService.class);
    when(queryService.getDependencyResolver()).thenReturn(mock(DependencyResolver.class));
    return new TransactionStateMachineSPI(mock(GraphDatabaseAPI.class), new ThreadToStatementContextBridge(), mock(QueryExecutionEngine.class), txIdStore, availabilityGuard, queryService, txAwaitDuration, clock);
}
Also used : QueryExecutionEngine(org.neo4j.kernel.impl.query.QueryExecutionEngine) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) DependencyResolver(org.neo4j.graphdb.DependencyResolver)

Example 25 with ThreadToStatementContextBridge

use of org.neo4j.kernel.impl.core.ThreadToStatementContextBridge in project neo4j by neo4j.

the class TopLevelTransactionTest method shouldThrowTransientExceptionOnTransientKernelException.

@Test
public void shouldThrowTransientExceptionOnTransientKernelException() throws Exception {
    // GIVEN
    KernelTransaction kernelTransaction = mock(KernelTransaction.class);
    when(kernelTransaction.isOpen()).thenReturn(true);
    doThrow(new TransactionFailureException(Status.Transaction.ConstraintsChanged, "Proving that TopLevelTransaction does the right thing")).when(kernelTransaction).close();
    ThreadToStatementContextBridge bridge = new ThreadToStatementContextBridge();
    TopLevelTransaction transaction = new TopLevelTransaction(kernelTransaction, bridge);
    // WHEN
    transaction.success();
    try {
        transaction.close();
        fail("Should have failed");
    } catch (TransientTransactionFailureException e) {
    // THEN Good
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransientTransactionFailureException(org.neo4j.graphdb.TransientTransactionFailureException) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) TransientTransactionFailureException(org.neo4j.graphdb.TransientTransactionFailureException) TopLevelTransaction(org.neo4j.kernel.impl.coreapi.TopLevelTransaction) Test(org.junit.Test)

Aggregations

ThreadToStatementContextBridge (org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)29 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)15 Statement (org.neo4j.kernel.api.Statement)14 Test (org.junit.Test)8 Transaction (org.neo4j.graphdb.Transaction)8 DependencyResolver (org.neo4j.graphdb.DependencyResolver)6 TopLevelTransaction (org.neo4j.kernel.impl.coreapi.TopLevelTransaction)6 GraphDatabaseQueryService (org.neo4j.kernel.GraphDatabaseQueryService)5 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)5 Node (org.neo4j.graphdb.Node)4 Guard (org.neo4j.kernel.guard.Guard)4 ReadOperations (org.neo4j.kernel.api.ReadOperations)3 ExecutingQuery (org.neo4j.kernel.api.query.ExecutingQuery)3 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)3 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)3 RemoteException (java.rmi.RemoteException)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Before (org.junit.Before)2