Search in sources :

Example 1 with UnspecifiedKernelException

use of org.neo4j.exceptions.UnspecifiedKernelException in project neo4j by neo4j.

the class Operations method ensureIndexPrototypeHasName.

private IndexPrototype ensureIndexPrototypeHasName(IndexPrototype prototype) throws KernelException {
    if (prototype.getName().isEmpty()) {
        SchemaDescriptor schema = prototype.schema();
        int[] entityTokenIds = schema.getEntityTokenIds();
        String[] entityTokenNames;
        switch(schema.entityType()) {
            case NODE:
                entityTokenNames = resolveTokenNames(token::nodeLabelName, entityTokenIds);
                break;
            case RELATIONSHIP:
                entityTokenNames = resolveTokenNames(token::relationshipTypeName, entityTokenIds);
                break;
            default:
                throw new UnspecifiedKernelException(Status.General.UnknownError, "Cannot create index for entity type %s in the schema %s.", schema.entityType(), schema);
        }
        int[] propertyIds = schema.getPropertyIds();
        String[] propertyNames = resolveTokenNames(token::propertyKeyName, propertyIds);
        prototype = prototype.withName(SchemaRule.generateName(prototype, entityTokenNames, propertyNames));
    }
    return prototype;
}
Also used : RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) UnspecifiedKernelException(org.neo4j.exceptions.UnspecifiedKernelException)

Example 2 with UnspecifiedKernelException

use of org.neo4j.exceptions.UnspecifiedKernelException in project neo4j by neo4j.

the class Operations method ensureConstraintHasName.

@SuppressWarnings("unchecked")
private <T extends ConstraintDescriptor> T ensureConstraintHasName(T constraint) throws KernelException {
    if (constraint.getName() == null) {
        SchemaDescriptor schema = constraint.schema();
        int[] entityTokenIds = schema.getEntityTokenIds();
        String[] entityTokenNames;
        switch(schema.entityType()) {
            case NODE:
                entityTokenNames = resolveTokenNames(token::nodeLabelName, entityTokenIds);
                break;
            case RELATIONSHIP:
                entityTokenNames = resolveTokenNames(token::relationshipTypeName, entityTokenIds);
                break;
            default:
                throw new UnspecifiedKernelException(Status.General.UnknownError, "Cannot create constraint for entity type %s in the schema %s.", schema.entityType(), schema);
        }
        int[] propertyIds = schema.getPropertyIds();
        String[] propertyNames = resolveTokenNames(token::propertyKeyName, propertyIds);
        constraint = (T) constraint.withName(SchemaRule.generateName(constraint, entityTokenNames, propertyNames));
    }
    return constraint;
}
Also used : RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) UnspecifiedKernelException(org.neo4j.exceptions.UnspecifiedKernelException)

Example 3 with UnspecifiedKernelException

use of org.neo4j.exceptions.UnspecifiedKernelException in project neo4j by neo4j.

the class DelegatingTokenHolder method createToken.

/**
 * Create and put new token in cache.
 *
 * @param name token name
 * @return newly created token id
 */
@Override
protected synchronized int createToken(String name, boolean internal) throws KernelException {
    Integer id = internal ? tokenRegistry.getIdInternal(name) : tokenRegistry.getId(name);
    if (id != null) {
        return id;
    }
    id = tokenCreator.createToken(name, internal);
    try {
        tokenRegistry.put(new NamedToken(name, id, internal));
    } catch (NonUniqueTokenException e) {
        throw new UnspecifiedKernelException(Status.General.UnknownError, e, "Newly created token should be unique.");
    }
    return id;
}
Also used : NonUniqueTokenException(org.neo4j.token.api.NonUniqueTokenException) UnspecifiedKernelException(org.neo4j.exceptions.UnspecifiedKernelException) NamedToken(org.neo4j.token.api.NamedToken)

Aggregations

UnspecifiedKernelException (org.neo4j.exceptions.UnspecifiedKernelException)3 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)2 RelationTypeSchemaDescriptor (org.neo4j.internal.schema.RelationTypeSchemaDescriptor)2 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)2 NamedToken (org.neo4j.token.api.NamedToken)1 NonUniqueTokenException (org.neo4j.token.api.NonUniqueTokenException)1