Search in sources :

Example 76 with Statement

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());
    }
}
Also used : IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) Statement(org.neo4j.kernel.api.Statement) IndexSamplingMode(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) ShellException(org.neo4j.shell.ShellException)

Example 77 with Statement

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]));
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Statement(org.neo4j.kernel.api.Statement) KernelAPI(org.neo4j.kernel.api.KernelAPI)

Example 78 with Statement

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;
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Statement(org.neo4j.kernel.api.Statement) ArrayList(java.util.ArrayList) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) KernelAPI(org.neo4j.kernel.api.KernelAPI)

Example 79 with Statement

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())));
        }
    }
}
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 80 with Statement

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);
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Statement(org.neo4j.kernel.api.Statement) DoubleLongRegister(org.neo4j.register.Register.DoubleLongRegister) KernelAPI(org.neo4j.kernel.api.KernelAPI)

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