Search in sources :

Example 81 with KernelTransaction

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

the class NodeEntity method getAllProperties.

public Map<String, Object> getAllProperties(NodeCursor nodes, PropertyCursor propertyCursor) {
    KernelTransaction transaction = internalTransaction.kernelTransaction();
    Map<String, Object> properties = new HashMap<>();
    try {
        TokenRead token = transaction.tokenRead();
        if (nodes.isClosed() || nodes.nodeReference() != getId()) {
            singleNode(transaction, nodes);
        }
        nodes.properties(propertyCursor);
        while (propertyCursor.next()) {
            properties.put(token.propertyKeyName(propertyCursor.propertyKey()), propertyCursor.propertyValue().asObjectCopy());
        }
    } catch (PropertyKeyIdNotFoundKernelException e) {
        throw new IllegalStateException("Property key retrieved through kernel API should exist.", e);
    }
    return properties;
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) HashMap(java.util.HashMap) TokenRead(org.neo4j.internal.kernel.api.TokenRead) PropertyKeyIdNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)

Example 82 with KernelTransaction

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

the class NodeEntity method getRelationshipTypes.

@Override
public Iterable<RelationshipType> getRelationshipTypes() {
    KernelTransaction transaction = internalTransaction.kernelTransaction();
    try {
        NodeCursor nodes = transaction.ambientNodeCursor();
        TokenRead tokenRead = transaction.tokenRead();
        singleNode(transaction, nodes);
        Degrees degrees = nodes.degrees(ALL_RELATIONSHIPS);
        List<RelationshipType> types = new ArrayList<>();
        for (int type : degrees.types()) {
            // only include this type if there are any relationships with this type
            if (degrees.totalDegree(type) > 0) {
                types.add(RelationshipType.withName(tokenRead.relationshipTypeName(type)));
            }
        }
        return types;
    } catch (KernelException e) {
        throw new NotFoundException("Relationship name not found.", e);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Degrees(org.neo4j.storageengine.api.Degrees) RelationshipType(org.neo4j.graphdb.RelationshipType) ArrayList(java.util.ArrayList) NotFoundException(org.neo4j.graphdb.NotFoundException) EntityNotFoundException(org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) PropertyKeyIdNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) TokenCapacityExceededKernelException(org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException) LabelNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.LabelNotFoundKernelException) KernelException(org.neo4j.exceptions.KernelException) TokenRead(org.neo4j.internal.kernel.api.TokenRead)

Example 83 with KernelTransaction

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

the class NodeEntity method removeProperty.

@Override
public Object removeProperty(String key) throws NotFoundException {
    KernelTransaction transaction = internalTransaction.kernelTransaction();
    int propertyKeyId;
    try {
        propertyKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName(key);
    } catch (IllegalTokenNameException e) {
        throw new IllegalArgumentException(format("Invalid property key '%s'.", key), e);
    } catch (KernelException e) {
        throw new TransactionFailureException("Unknown error trying to get property key token", e);
    }
    try {
        return transaction.dataWrite().nodeRemoveProperty(nodeId, propertyKeyId).asObjectCopy();
    } catch (EntityNotFoundException e) {
        throw new NotFoundException(e);
    } catch (InvalidTransactionTypeKernelException e) {
        throw new ConstraintViolationException(e.getMessage(), e);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) NotFoundException(org.neo4j.graphdb.NotFoundException) EntityNotFoundException(org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) EntityNotFoundException(org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException) IllegalTokenNameException(org.neo4j.internal.kernel.api.exceptions.schema.IllegalTokenNameException) PropertyKeyIdNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) TokenCapacityExceededKernelException(org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException) LabelNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.LabelNotFoundKernelException) KernelException(org.neo4j.exceptions.KernelException)

Example 84 with KernelTransaction

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

the class NodeEntity method isDeletedInCurrentTransaction.

public static boolean isDeletedInCurrentTransaction(Node node) {
    if (node instanceof NodeEntity) {
        NodeEntity proxy = (NodeEntity) node;
        KernelTransaction ktx = proxy.internalTransaction.kernelTransaction();
        return ktx.dataRead().nodeDeletedInTransaction(proxy.nodeId);
    }
    return false;
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction)

Example 85 with KernelTransaction

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

the class NodeEntity method getProperty.

@Override
public Object getProperty(String key, Object defaultValue) {
    if (null == key) {
        throw new IllegalArgumentException("(null) property key is not allowed");
    }
    KernelTransaction transaction = internalTransaction.kernelTransaction();
    NodeCursor nodes = transaction.ambientNodeCursor();
    PropertyCursor properties = transaction.ambientPropertyCursor();
    int propertyKey = transaction.tokenRead().propertyKey(key);
    if (propertyKey == TokenRead.NO_TOKEN) {
        return defaultValue;
    }
    singleNode(transaction, nodes);
    nodes.properties(properties);
    return properties.seekProperty(propertyKey) ? properties.propertyValue().asObjectCopy() : defaultValue;
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor)

Aggregations

KernelTransaction (org.neo4j.kernel.api.KernelTransaction)581 Test (org.junit.jupiter.api.Test)349 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)74 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)66 Transaction (org.neo4j.graphdb.Transaction)64 NodeCursor (org.neo4j.internal.kernel.api.NodeCursor)62 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)57 Write (org.neo4j.internal.kernel.api.Write)51 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)47 TokenRead (org.neo4j.internal.kernel.api.TokenRead)42 ArrayList (java.util.ArrayList)37 SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)35 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)34 PropertyCursor (org.neo4j.internal.kernel.api.PropertyCursor)33 Node (org.neo4j.graphdb.Node)31 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)30 MethodSource (org.junit.jupiter.params.provider.MethodSource)28 Read (org.neo4j.internal.kernel.api.Read)28 RelationshipScanCursor (org.neo4j.internal.kernel.api.RelationshipScanCursor)28 NodeValueIndexCursor (org.neo4j.internal.kernel.api.NodeValueIndexCursor)25