use of org.neo4j.kernel.api.Statement in project neo4j by neo4j.
the class Schema method sampleIndexes.
private void sampleIndexes(Label[] labels, String property, boolean sampleAll, boolean forceSample) throws ShellException {
IndexingService indexingService = getServer().getDb().getDependencyResolver().resolveDependency(IndexingService.class);
if (indexingService == null) {
throw new ShellException("Internal error: failed to resolve IndexingService");
}
IndexSamplingMode samplingMode = getSamplingMode(forceSample);
// Trigger sampling for all indices
if (sampleAll) {
indexingService.triggerIndexSampling(samplingMode);
return;
}
validateLabelsAndProperty(labels, property);
Statement statement = getServer().getStatement();
int labelKey = statement.readOperations().labelGetForName(labels[0].name());
int propertyKey = statement.readOperations().propertyKeyGetForName(property);
if (labelKey == -1) {
throw new ShellException("No label associated with '" + labels[0].name() + "' was found");
}
if (propertyKey == -1) {
throw new ShellException("No property associated with '" + property + "' was found");
}
try {
indexingService.triggerIndexSampling(SchemaDescriptorFactory.forLabel(labelKey, propertyKey), samplingMode);
} catch (IndexNotFoundKernelException e) {
throw new ShellException(e.getMessage());
}
}
use of org.neo4j.kernel.api.Statement in project neo4j by neo4j.
the class ClusterMembershipChangeIT method discoverClusterMembers.
private List<Object[]> discoverClusterMembers(GraphDatabaseFacade db) throws TransactionFailureException, org.neo4j.kernel.api.exceptions.ProcedureException {
KernelAPI kernel = db.getDependencyResolver().resolveDependency(KernelAPI.class);
KernelTransaction transaction = kernel.newTransaction(KernelTransaction.Type.implicit, AnonymousContext.read());
Statement statement = transaction.acquireStatement();
// when
return asList(statement.procedureCallOperations().procedureCallRead(procedureName(GET_SERVERS_V1.fullyQualifiedProcedureName()), new Object[0]));
}
use of org.neo4j.kernel.api.Statement in project neo4j by neo4j.
the class ClusterOverviewIT method clusterOverview.
private List<MemberInfo> clusterOverview(GraphDatabaseFacade db) throws TransactionFailureException, ProcedureException {
KernelAPI kernel = db.getDependencyResolver().resolveDependency(KernelAPI.class);
KernelTransaction transaction = kernel.newTransaction(Type.implicit, AnonymousContext.read());
List<MemberInfo> infos = new ArrayList<>();
try (Statement statement = transaction.acquireStatement()) {
RawIterator<Object[], ProcedureException> itr = statement.procedureCallOperations().procedureCallRead(procedureName("dbms", "cluster", ClusterOverviewProcedure.PROCEDURE_NAME), null);
while (itr.hasNext()) {
Object[] row = itr.next();
Object[] addresses = (Object[]) row[1];
infos.add(new MemberInfo(Arrays.copyOf(addresses, addresses.length, String[].class), Role.valueOf((String) row[2])));
}
}
return infos;
}
use of org.neo4j.kernel.api.Statement 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())));
}
}
}
use of org.neo4j.kernel.api.Statement in project neo4j by neo4j.
the class StoreUpgradeIntegrationTest method checkIndexCounts.
private static void checkIndexCounts(Store store, GraphDatabaseAPI db) throws KernelException {
KernelAPI kernel = db.getDependencyResolver().resolveDependency(KernelAPI.class);
try (KernelTransaction tx = kernel.newTransaction(KernelTransaction.Type.implicit, AnonymousContext.read());
Statement statement = tx.acquireStatement()) {
Iterator<NewIndexDescriptor> indexes = getAllIndexes(db);
DoubleLongRegister register = Registers.newDoubleLongRegister();
for (int i = 0; indexes.hasNext(); i++) {
NewIndexDescriptor descriptor = indexes.next();
// wait index to be online since sometimes we need to rebuild the indexes on migration
awaitOnline(statement.readOperations(), descriptor);
assertDoubleLongEquals(store.indexCounts[i][0], store.indexCounts[i][1], statement.readOperations().indexUpdatesAndSize(descriptor, register));
assertDoubleLongEquals(store.indexCounts[i][2], store.indexCounts[i][3], statement.readOperations().indexSample(descriptor, register));
double selectivity = statement.readOperations().indexUniqueValuesSelectivity(descriptor);
assertEquals(store.indexSelectivity[i], selectivity, 0.0000001d);
}
}
}
Aggregations