Search in sources :

Example 96 with Statement

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

the class GraphPropertiesProxy method getProperties.

@Override
public Map<String, Object> getProperties(String... names) {
    try (Statement statement = actions.statement()) {
        Map<String, Object> properties = new HashMap<>();
        ReadOperations readOperations = statement.readOperations();
        for (String name : names) {
            int propertyKeyId = readOperations.propertyKeyGetForName(name);
            Object value = readOperations.graphGetProperty(propertyKeyId);
            if (value != null) {
                properties.put(name, value);
            }
        }
        return properties;
    }
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) KeyReadOperations(org.neo4j.kernel.impl.api.operations.KeyReadOperations) HashMap(java.util.HashMap) Statement(org.neo4j.kernel.api.Statement)

Example 97 with Statement

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

the class SchemaImpl method getIndexPopulationProgress.

@Override
public IndexPopulationProgress getIndexPopulationProgress(IndexDefinition index) {
    actions.assertInOpenTransaction();
    try (Statement statement = statementContextSupplier.get()) {
        ReadOperations readOps = statement.readOperations();
        NewIndexDescriptor descriptor = getIndexDescriptor(readOps, index);
        PopulationProgress progress = readOps.indexGetPopulationProgress(descriptor);
        return new IndexPopulationProgress(progress.getCompleted(), progress.getTotal());
    } catch (SchemaRuleNotFoundException | IndexNotFoundKernelException e) {
        throw new NotFoundException(format("No index for label %s on property %s", index.getLabel().name(), index.getPropertyKeys()));
    }
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) KeyReadOperations(org.neo4j.kernel.impl.api.operations.KeyReadOperations) IndexPopulationProgress(org.neo4j.graphdb.index.IndexPopulationProgress) PopulationProgress(org.neo4j.storageengine.api.schema.PopulationProgress) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Statement(org.neo4j.kernel.api.Statement) IndexPopulationProgress(org.neo4j.graphdb.index.IndexPopulationProgress) NotFoundException(org.neo4j.graphdb.NotFoundException) SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException) SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)

Example 98 with Statement

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

the class SchemaImpl method getIndexState.

@Override
public IndexState getIndexState(final IndexDefinition index) {
    actions.assertInOpenTransaction();
    try (Statement statement = statementContextSupplier.get()) {
        ReadOperations readOps = statement.readOperations();
        NewIndexDescriptor descriptor = getIndexDescriptor(readOps, index);
        InternalIndexState indexState = readOps.indexGetState(descriptor);
        switch(indexState) {
            case POPULATING:
                return POPULATING;
            case ONLINE:
                return ONLINE;
            case FAILED:
                return FAILED;
            default:
                throw new IllegalArgumentException(String.format("Illegal index state %s", indexState));
        }
    } catch (SchemaRuleNotFoundException | IndexNotFoundKernelException e) {
        throw new NotFoundException(format("No index for label %s on property %s", index.getLabel().name(), index.getPropertyKeys()));
    }
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) KeyReadOperations(org.neo4j.kernel.impl.api.operations.KeyReadOperations) InternalIndexState(org.neo4j.kernel.api.index.InternalIndexState) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Statement(org.neo4j.kernel.api.Statement) NotFoundException(org.neo4j.graphdb.NotFoundException) SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException) SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)

Example 99 with Statement

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

the class GraphDatabaseFacade method init.

/**
     * Create a new Core API facade, backed by the given SPI and using pre-resolved dependencies
     */
public void init(SPI spi, Guard guard, ThreadToStatementContextBridge txBridge, Config config) {
    this.spi = spi;
    this.defaultTransactionTimeout = config.get(GraphDatabaseSettings.transaction_timeout);
    Supplier<Statement> statementSupplier = spi::currentStatement;
    Supplier<KernelTransaction> transactionSupplier = spi::currentTransaction;
    ThrowingAction<RuntimeException> assertTransactionOpen = this::assertTransactionOpen;
    this.schema = new SchemaImpl(statementSupplier);
    this.relActions = new StandardRelationshipActions(statementSupplier, transactionSupplier, assertTransactionOpen, (id) -> new NodeProxy(nodeActions, id), this);
    this.nodeActions = new StandardNodeActions(statementSupplier, transactionSupplier, assertTransactionOpen, relActions, this);
    this.indexManager = Suppliers.lazySingleton(() -> {
        IndexProviderImpl idxProvider = new IndexProviderImpl(this, statementSupplier);
        AutoIndexerFacade<Node> nodeAutoIndexer = new AutoIndexerFacade<>(() -> new ReadOnlyIndexFacade<>(idxProvider.getOrCreateNodeIndex(NODE_AUTO_INDEX, null)), spi.autoIndexing().nodes());
        RelationshipAutoIndexerFacade relAutoIndexer = new RelationshipAutoIndexerFacade(() -> new ReadOnlyRelationshipIndexFacade(idxProvider.getOrCreateRelationshipIndex(RELATIONSHIP_AUTO_INDEX, null)), spi.autoIndexing().relationships());
        return new IndexManagerImpl(statementSupplier, idxProvider, nodeAutoIndexer, relAutoIndexer);
    });
    this.contextFactory = Neo4jTransactionalContextFactory.create(spi, guard, txBridge, locker);
}
Also used : InternalIndexState(org.neo4j.kernel.api.index.InternalIndexState) StoreId(org.neo4j.kernel.impl.store.StoreId) RELATIONSHIP_AUTO_INDEX(org.neo4j.kernel.impl.api.legacyindex.InternalAutoIndexing.RELATIONSHIP_AUTO_INDEX) ResourceIterator(org.neo4j.graphdb.ResourceIterator) Suppliers(org.neo4j.function.Suppliers) ResourceClosingIterator(org.neo4j.helpers.collection.ResourceClosingIterator) URL(java.net.URL) ResourceIterable(org.neo4j.graphdb.ResourceIterable) Status(org.neo4j.kernel.api.exceptions.Status) TransactionEventHandler(org.neo4j.graphdb.event.TransactionEventHandler) TopLevelTransaction(org.neo4j.kernel.impl.coreapi.TopLevelTransaction) Statement(org.neo4j.kernel.api.Statement) Property(org.neo4j.kernel.api.properties.Property) RelationshipProxy(org.neo4j.kernel.impl.core.RelationshipProxy) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) RelationshipAutoIndexerFacade(org.neo4j.kernel.impl.coreapi.RelationshipAutoIndexerFacade) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) NODE_AUTO_INDEX(org.neo4j.kernel.impl.api.legacyindex.InternalAutoIndexing.NODE_AUTO_INDEX) AutoIndexerFacade(org.neo4j.kernel.impl.coreapi.AutoIndexerFacade) Map(java.util.Map) NodePropertyDescriptor(org.neo4j.kernel.api.schema.NodePropertyDescriptor) Transaction(org.neo4j.graphdb.Transaction) TransactionalContextFactory(org.neo4j.kernel.impl.query.TransactionalContextFactory) QueryExecutionException(org.neo4j.graphdb.QueryExecutionException) PrefetchingResourceIterator(org.neo4j.helpers.collection.PrefetchingResourceIterator) KernelEventHandler(org.neo4j.graphdb.event.KernelEventHandler) BidirectionalTraversalDescriptionImpl(org.neo4j.kernel.impl.traversal.BidirectionalTraversalDescriptionImpl) Result(org.neo4j.graphdb.Result) URLAccessValidationError(org.neo4j.graphdb.security.URLAccessValidationError) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) IndexProviderImpl(org.neo4j.kernel.impl.coreapi.IndexProviderImpl) BidirectionalTraversalDescription(org.neo4j.graphdb.traversal.BidirectionalTraversalDescription) InvalidTransactionTypeKernelException(org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException) KernelException(org.neo4j.kernel.api.exceptions.KernelException) StandardRelationshipActions(org.neo4j.kernel.impl.coreapi.StandardRelationshipActions) String.format(java.lang.String.format) Schema(org.neo4j.graphdb.schema.Schema) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) NO_SUCH_LABEL(org.neo4j.kernel.impl.api.operations.KeyReadOperations.NO_SUCH_LABEL) TransactionTerminatedException(org.neo4j.graphdb.TransactionTerminatedException) IndexManager(org.neo4j.graphdb.index.IndexManager) Neo4jTransactionalContextFactory(org.neo4j.kernel.impl.query.Neo4jTransactionalContextFactory) Optional(java.util.Optional) DependencyResolver(org.neo4j.graphdb.DependencyResolver) RelationshipType(org.neo4j.graphdb.RelationshipType) GraphDatabaseSettings(org.neo4j.graphdb.factory.GraphDatabaseSettings) Guard(org.neo4j.kernel.guard.Guard) Label(org.neo4j.graphdb.Label) PlaceboTransaction(org.neo4j.kernel.impl.coreapi.PlaceboTransaction) TransactionalContext(org.neo4j.kernel.impl.query.TransactionalContext) SchemaImpl(org.neo4j.kernel.impl.coreapi.schema.SchemaImpl) EntityType(org.neo4j.storageengine.api.EntityType) StandardNodeActions(org.neo4j.kernel.impl.coreapi.StandardNodeActions) SchemaKernelException(org.neo4j.kernel.api.exceptions.schema.SchemaKernelException) MonoDirectionalTraversalDescription(org.neo4j.kernel.impl.traversal.MonoDirectionalTraversalDescription) NotFoundException(org.neo4j.graphdb.NotFoundException) Supplier(java.util.function.Supplier) SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException) Node(org.neo4j.graphdb.Node) GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) IndexManagerImpl(org.neo4j.kernel.impl.coreapi.IndexManagerImpl) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) SecurityContext(org.neo4j.kernel.api.security.SecurityContext) ReadOnlyRelationshipIndexFacade(org.neo4j.kernel.impl.coreapi.ReadOnlyRelationshipIndexFacade) ThrowingAction(org.neo4j.function.ThrowingAction) NO_SUCH_PROPERTY_KEY(org.neo4j.kernel.impl.api.operations.KeyReadOperations.NO_SUCH_PROPERTY_KEY) TokenAccess(org.neo4j.kernel.impl.api.TokenAccess) AutoIndexing(org.neo4j.kernel.api.legacyindex.AutoIndexing) Config(org.neo4j.kernel.configuration.Config) ReadOnlyIndexFacade(org.neo4j.kernel.impl.coreapi.ReadOnlyIndexFacade) PrimitiveLongCollections(org.neo4j.collection.primitive.PrimitiveLongCollections) ReadOperations(org.neo4j.kernel.api.ReadOperations) IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) PrimitiveLongCollections.map(org.neo4j.collection.primitive.PrimitiveLongCollections.map) Iterators.emptyIterator(org.neo4j.helpers.collection.Iterators.emptyIterator) NodeProxy(org.neo4j.kernel.impl.core.NodeProxy) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) File(java.io.File) PropertyContainerLocker(org.neo4j.kernel.impl.coreapi.PropertyContainerLocker) TimeUnit(java.util.concurrent.TimeUnit) TraversalDescription(org.neo4j.graphdb.traversal.TraversalDescription) Relationship(org.neo4j.graphdb.Relationship) AUTH_DISABLED(org.neo4j.kernel.api.security.SecurityContext.AUTH_DISABLED) KeyReadOperations(org.neo4j.kernel.impl.api.operations.KeyReadOperations) MultipleFoundException(org.neo4j.graphdb.MultipleFoundException) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ClientConnectionInfo(org.neo4j.kernel.impl.query.clientconnection.ClientConnectionInfo) ConstraintValidationException(org.neo4j.kernel.api.exceptions.schema.ConstraintValidationException) Collections(java.util.Collections) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) RelationshipAutoIndexerFacade(org.neo4j.kernel.impl.coreapi.RelationshipAutoIndexerFacade) Statement(org.neo4j.kernel.api.Statement) RelationshipAutoIndexerFacade(org.neo4j.kernel.impl.coreapi.RelationshipAutoIndexerFacade) AutoIndexerFacade(org.neo4j.kernel.impl.coreapi.AutoIndexerFacade) ReadOnlyRelationshipIndexFacade(org.neo4j.kernel.impl.coreapi.ReadOnlyRelationshipIndexFacade) IndexProviderImpl(org.neo4j.kernel.impl.coreapi.IndexProviderImpl) NodeProxy(org.neo4j.kernel.impl.core.NodeProxy) StandardNodeActions(org.neo4j.kernel.impl.coreapi.StandardNodeActions) IndexManagerImpl(org.neo4j.kernel.impl.coreapi.IndexManagerImpl) SchemaImpl(org.neo4j.kernel.impl.coreapi.schema.SchemaImpl) StandardRelationshipActions(org.neo4j.kernel.impl.coreapi.StandardRelationshipActions) ReadOnlyIndexFacade(org.neo4j.kernel.impl.coreapi.ReadOnlyIndexFacade)

Example 100 with Statement

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

the class GraphDatabaseFacade method getRelationshipById.

@Override
public Relationship getRelationshipById(long id) {
    if (id < 0) {
        throw new NotFoundException(format("Relationship %d not found", id), new EntityNotFoundException(EntityType.RELATIONSHIP, id));
    }
    try (Statement statement = spi.currentStatement()) {
        try {
            RelationshipProxy relationship = new RelationshipProxy(relActions, id);
            statement.readOperations().relationshipVisit(id, relationship);
            return relationship;
        } catch (EntityNotFoundException e) {
            throw new NotFoundException(format("Relationship %d not found", id), e);
        }
    }
}
Also used : RelationshipProxy(org.neo4j.kernel.impl.core.RelationshipProxy) Statement(org.neo4j.kernel.api.Statement) NotFoundException(org.neo4j.graphdb.NotFoundException) SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException)

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