Search in sources :

Example 16 with ThreadToStatementContextBridge

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

the class NeoStoreIndexStoreViewTest method getOrCreateIds.

private void getOrCreateIds() throws KernelException {
    try (Transaction tx = graphDb.beginTx()) {
        ThreadToStatementContextBridge bridge = graphDb.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class);
        try (Statement statement = bridge.get()) {
            labelId = statement.tokenWriteOperations().labelGetOrCreateForName("Person");
            propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("name");
        }
        tx.success();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Statement(org.neo4j.kernel.api.Statement) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)

Example 17 with ThreadToStatementContextBridge

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

the class GraphDatabaseShellServer method registerTopLevelTransactionInProgress.

public void registerTopLevelTransactionInProgress(Serializable clientId) throws ShellException {
    if (!clients.containsKey(clientId)) {
        ThreadToStatementContextBridge threadToStatementContextBridge = getThreadToStatementContextBridge();
        KernelTransaction tx = threadToStatementContextBridge.getTopLevelTransactionBoundToThisThread(false);
        clients.put(clientId, tx);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)

Example 18 with ThreadToStatementContextBridge

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

the class GraphDatabaseShellServer method bindTransaction.

public void bindTransaction(Serializable clientId) throws ShellException {
    KernelTransaction tx = clients.get(clientId);
    if (tx != null) {
        try {
            ThreadToStatementContextBridge threadToStatementContextBridge = getThreadToStatementContextBridge();
            threadToStatementContextBridge.bindTransactionToCurrentThread(tx);
        } catch (Exception e) {
            throw wrapException(e);
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) RemoteException(java.rmi.RemoteException) ShellException(org.neo4j.shell.ShellException)

Example 19 with ThreadToStatementContextBridge

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

the class StoreUpgradeIntegrationTest method checkLabelCounts.

private static void checkLabelCounts(GraphDatabaseAPI db) {
    try (Transaction ignored = db.beginTx()) {
        HashMap<Label, Long> counts = new HashMap<>();
        for (Node node : db.getAllNodes()) {
            for (Label label : node.getLabels()) {
                Long count = counts.get(label);
                if (count != null) {
                    counts.put(label, count + 1);
                } else {
                    counts.put(label, 1L);
                }
            }
        }
        ThreadToStatementContextBridge bridge = db.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class);
        Statement statement = bridge.get();
        for (Map.Entry<Label, Long> entry : counts.entrySet()) {
            assertEquals(entry.getValue().longValue(), statement.readOperations().countsForNode(statement.readOperations().labelGetForName(entry.getKey().name())));
        }
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) HashMap(java.util.HashMap) Statement(org.neo4j.kernel.api.Statement) Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) Map(java.util.Map) HashMap(java.util.HashMap) MapUtil.stringMap(org.neo4j.helpers.collection.MapUtil.stringMap)

Example 20 with ThreadToStatementContextBridge

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

the class StoreUpgradeIntegrationTest method getAllIndexes.

private static Iterator<NewIndexDescriptor> getAllIndexes(GraphDatabaseAPI db) {
    try (Transaction ignored = db.beginTx()) {
        ThreadToStatementContextBridge bridge = db.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class);
        Statement statement = bridge.get();
        return Iterators.concat(statement.readOperations().indexesGetAll(), statement.readOperations().uniqueIndexesGetAll());
    }
}
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)

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