Search in sources :

Example 11 with ThreadToStatementContextBridge

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

the class MultiIndexPopulationConcurrentUpdatesIT method launchCustomIndexPopulation.

private void launchCustomIndexPopulation(Map<String, Integer> labelNameIdMap, int propertyId, List<NodeUpdates> updates) throws Exception {
    NeoStores neoStores = getNeoStores();
    LabelScanStore labelScanStore = getLabelScanStore();
    ThreadToStatementContextBridge transactionStatementContextBridge = getTransactionStatementContextBridge();
    try (Transaction transaction = embeddedDatabase.beginTx()) {
        Statement statement = transactionStatementContextBridge.get();
        DynamicIndexStoreView storeView = new DynamicIndexStoreViewWrapper(labelScanStore, LockService.NO_LOCK_SERVICE, neoStores, updates);
        SchemaIndexProviderMap providerMap = new DefaultSchemaIndexProviderMap(getSchemaIndexProvider());
        JobScheduler scheduler = getJobScheduler();
        StatementTokenNameLookup tokenNameLookup = new StatementTokenNameLookup(statement.readOperations());
        indexService = IndexingServiceFactory.createIndexingService(Config.empty(), scheduler, providerMap, storeView, tokenNameLookup, getIndexRules(neoStores), NullLogProvider.getInstance(), IndexingService.NO_MONITOR, () -> {
        });
        indexService.start();
        IndexRule[] rules = createIndexRules(labelNameIdMap, propertyId);
        indexService.createIndexes(rules);
        transaction.success();
    }
}
Also used : JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) LabelScanStore(org.neo4j.kernel.api.labelscan.LabelScanStore) StatementTokenNameLookup(org.neo4j.kernel.api.StatementTokenNameLookup) Statement(org.neo4j.kernel.api.Statement) DefaultSchemaIndexProviderMap(org.neo4j.kernel.impl.transaction.state.DefaultSchemaIndexProviderMap) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) DynamicIndexStoreView(org.neo4j.kernel.impl.transaction.state.storeview.DynamicIndexStoreView) DefaultSchemaIndexProviderMap(org.neo4j.kernel.impl.transaction.state.DefaultSchemaIndexProviderMap) SchemaIndexProviderMap(org.neo4j.kernel.impl.api.index.SchemaIndexProviderMap) Transaction(org.neo4j.graphdb.Transaction) NeoStores(org.neo4j.kernel.impl.store.NeoStores)

Example 12 with ThreadToStatementContextBridge

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

the class MultiIndexPopulationConcurrentUpdatesIT method getLabelIdsByName.

private Map<String, Integer> getLabelIdsByName(String... names) {
    ThreadToStatementContextBridge transactionStatementContextBridge = getTransactionStatementContextBridge();
    ReadOperations readOperations = transactionStatementContextBridge.get().readOperations();
    Map<String, Integer> labelNameIdMap = new HashMap<>();
    for (String name : names) {
        labelNameIdMap.put(name, readOperations.labelGetForName(name));
    }
    return labelNameIdMap;
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) HashMap(java.util.HashMap) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)

Example 13 with ThreadToStatementContextBridge

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

the class MultiIndexPopulationConcurrentUpdatesIT method getPropertyIdByName.

private int getPropertyIdByName(String name) {
    ThreadToStatementContextBridge transactionStatementContextBridge = getTransactionStatementContextBridge();
    ReadOperations readOperations = transactionStatementContextBridge.get().readOperations();
    return readOperations.propertyKeyGetForName(name);
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)

Example 14 with ThreadToStatementContextBridge

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

the class ExecutionResultTest method activeTransaction.

private TopLevelTransaction activeTransaction() {
    ThreadToStatementContextBridge bridge = db.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class);
    KernelTransaction kernelTransaction = bridge.getTopLevelTransactionBoundToThisThread(false);
    return kernelTransaction == null ? null : new TopLevelTransaction(kernelTransaction, null);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) TopLevelTransaction(org.neo4j.kernel.impl.coreapi.TopLevelTransaction)

Example 15 with ThreadToStatementContextBridge

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

the class IndexRecoveryIT method createSomeBananas.

private Set<IndexEntryUpdate> createSomeBananas(Label label) {
    Set<IndexEntryUpdate> updates = new HashSet<>();
    try (Transaction tx = db.beginTx()) {
        ThreadToStatementContextBridge ctxSupplier = db.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class);
        try (Statement statement = ctxSupplier.get()) {
            int labelId = statement.readOperations().labelGetForName(label.name());
            int propertyKeyId = statement.readOperations().propertyKeyGetForName(key);
            LabelSchemaDescriptor schemaDescriptor = SchemaDescriptorFactory.forLabel(labelId, propertyKeyId);
            for (int number : new int[] { 4, 10 }) {
                Node node = db.createNode(label);
                node.setProperty(key, number);
                updates.add(IndexEntryUpdate.add(node.getId(), schemaDescriptor, number));
            }
        }
        tx.success();
        return updates;
    }
}
Also used : IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) Transaction(org.neo4j.graphdb.Transaction) Statement(org.neo4j.kernel.api.Statement) Node(org.neo4j.graphdb.Node) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor) HashSet(java.util.HashSet)

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