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;
}
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;
}
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;
}
Aggregations