Search in sources :

Example 61 with Statement

use of org.neo4j.kernel.api.Statement 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 62 with Statement

use of org.neo4j.kernel.api.Statement in project neo4j by neo4j.

the class MyCoreAPI method makeNode.

public long makeNode(String label) throws ProcedureException {
    long result;
    try (Transaction tx = graph.beginTransaction(KernelTransaction.Type.explicit, AnonymousContext.write())) {
        Statement statement = this.txBridge.get();
        long nodeId = statement.dataWriteOperations().nodeCreate();
        int labelId = statement.tokenWriteOperations().labelGetOrCreateForName(label);
        statement.dataWriteOperations().nodeAddLabel(nodeId, labelId);
        result = nodeId;
        tx.success();
    } catch (Exception e) {
        log.error("Failed to create node: " + e.getMessage());
        throw new ProcedureException(Status.Procedure.ProcedureCallFailed, "Failed to create node: " + e.getMessage(), e);
    }
    return result;
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Transaction(org.neo4j.graphdb.Transaction) Statement(org.neo4j.kernel.api.Statement) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException)

Example 63 with Statement

use of org.neo4j.kernel.api.Statement in project neo4j by neo4j.

the class BuiltInProcedures method listConstraints.

@Description("List all constraints in the database.")
@Procedure(name = "db.constraints", mode = READ)
public Stream<ConstraintResult> listConstraints() {
    Statement statement = tx.acquireStatement();
    ReadOperations operations = statement.readOperations();
    TokenNameLookup tokens = new StatementTokenNameLookup(operations);
    return asList(operations.constraintsGetAll()).stream().map((constraint) -> constraint.prettyPrint(tokens)).sorted().map(ConstraintResult::new).onClose(statement::close);
}
Also used : IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Label(org.neo4j.graphdb.Label) Context(org.neo4j.procedure.Context) Status(org.neo4j.kernel.api.exceptions.Status) Iterators.asSet(org.neo4j.helpers.collection.Iterators.asSet) StatementTokenNameLookup(org.neo4j.kernel.api.StatementTokenNameLookup) Statement(org.neo4j.kernel.api.Statement) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) ArrayList(java.util.ArrayList) TokenNameLookup(org.neo4j.kernel.api.TokenNameLookup) Procedure(org.neo4j.procedure.Procedure) TokenAccess(org.neo4j.kernel.impl.api.TokenAccess) ReadOperations(org.neo4j.kernel.api.ReadOperations) Set(java.util.Set) READ(org.neo4j.procedure.Mode.READ) Description(org.neo4j.procedure.Description) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Stream(java.util.stream.Stream) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Iterators.asList(org.neo4j.helpers.collection.Iterators.asList) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Name(org.neo4j.procedure.Name) RelationshipType(org.neo4j.graphdb.RelationshipType) Comparator(java.util.Comparator) ReadOperations(org.neo4j.kernel.api.ReadOperations) StatementTokenNameLookup(org.neo4j.kernel.api.StatementTokenNameLookup) TokenNameLookup(org.neo4j.kernel.api.TokenNameLookup) StatementTokenNameLookup(org.neo4j.kernel.api.StatementTokenNameLookup) Statement(org.neo4j.kernel.api.Statement) Description(org.neo4j.procedure.Description) Procedure(org.neo4j.procedure.Procedure)

Example 64 with Statement

use of org.neo4j.kernel.api.Statement in project neo4j by neo4j.

the class IndexPopulationJobTest method before.

@Before
public void before() throws Exception {
    db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabase();
    kernel = db.getDependencyResolver().resolveDependency(KernelAPI.class);
    stateHolder = new KernelSchemaStateStore(NullLogProvider.getInstance());
    indexStoreView = indexStoreView();
    try (KernelTransaction tx = kernel.newTransaction(KernelTransaction.Type.implicit, AUTH_DISABLED);
        Statement statement = tx.acquireStatement()) {
        labelId = statement.tokenWriteOperations().labelGetOrCreateForName(FIRST.name());
        statement.tokenWriteOperations().labelGetOrCreateForName(SECOND.name());
        tx.success();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Statement(org.neo4j.kernel.api.Statement) KernelSchemaStateStore(org.neo4j.kernel.impl.api.KernelSchemaStateStore) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) KernelAPI(org.neo4j.kernel.api.KernelAPI) Before(org.junit.Before)

Example 65 with Statement

use of org.neo4j.kernel.api.Statement 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

Statement (org.neo4j.kernel.api.Statement)158 Test (org.junit.Test)76 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)56 Transaction (org.neo4j.graphdb.Transaction)44 ReadOperations (org.neo4j.kernel.api.ReadOperations)40 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)30 EntityNotFoundException (org.neo4j.kernel.api.exceptions.EntityNotFoundException)23 NotFoundException (org.neo4j.graphdb.NotFoundException)21 Node (org.neo4j.graphdb.Node)20 ThreadToStatementContextBridge (org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)19 PropertyNotFoundException (org.neo4j.kernel.api.exceptions.PropertyNotFoundException)13 KeyReadOperations (org.neo4j.kernel.impl.api.operations.KeyReadOperations)11 ArrayList (java.util.ArrayList)10 DependencyResolver (org.neo4j.graphdb.DependencyResolver)10 IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)10 Label (org.neo4j.graphdb.Label)9 KernelAPI (org.neo4j.kernel.api.KernelAPI)9 ProcedureException (org.neo4j.kernel.api.exceptions.ProcedureException)9 InvalidTransactionTypeKernelException (org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException)8 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)8