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();
}
}
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;
}
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);
}
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();
}
}
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;
}
}
Aggregations