Search in sources :

Example 1 with RelationshipTypeIdNotFoundKernelException

use of org.neo4j.kernel.api.exceptions.RelationshipTypeIdNotFoundKernelException in project neo4j by neo4j.

the class NodeProxy method createRelationshipTo.

@Override
public Relationship createRelationshipTo(Node otherNode, RelationshipType type) {
    if (otherNode == null) {
        throw new IllegalArgumentException("Other node is null.");
    }
    //}
    try (Statement statement = actions.statement()) {
        int relationshipTypeId = statement.tokenWriteOperations().relationshipTypeGetOrCreateForName(type.name());
        long relationshipId = statement.dataWriteOperations().relationshipCreate(relationshipTypeId, nodeId, otherNode.getId());
        return actions.newRelationshipProxy(relationshipId, nodeId, relationshipTypeId, otherNode.getId());
    } catch (IllegalTokenNameException | RelationshipTypeIdNotFoundKernelException e) {
        throw new IllegalArgumentException(e);
    } catch (EntityNotFoundException e) {
        throw new NotFoundException("Node[" + e.entityId() + "] is deleted and cannot be used to create a relationship");
    } catch (InvalidTransactionTypeKernelException e) {
        throw new ConstraintViolationException(e.getMessage(), e);
    }
}
Also used : Statement(org.neo4j.kernel.api.Statement) InvalidTransactionTypeKernelException(org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException) NotFoundException(org.neo4j.graphdb.NotFoundException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) PropertyNotFoundException(org.neo4j.kernel.api.exceptions.PropertyNotFoundException) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) RelationshipTypeIdNotFoundKernelException(org.neo4j.kernel.api.exceptions.RelationshipTypeIdNotFoundKernelException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) IllegalTokenNameException(org.neo4j.kernel.api.exceptions.schema.IllegalTokenNameException)

Aggregations

ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)1 NotFoundException (org.neo4j.graphdb.NotFoundException)1 Statement (org.neo4j.kernel.api.Statement)1 EntityNotFoundException (org.neo4j.kernel.api.exceptions.EntityNotFoundException)1 InvalidTransactionTypeKernelException (org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException)1 PropertyNotFoundException (org.neo4j.kernel.api.exceptions.PropertyNotFoundException)1 RelationshipTypeIdNotFoundKernelException (org.neo4j.kernel.api.exceptions.RelationshipTypeIdNotFoundKernelException)1 IllegalTokenNameException (org.neo4j.kernel.api.exceptions.schema.IllegalTokenNameException)1