use of org.neo4j.exceptions.KernelException 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);
}
}
use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.
the class ParallelNodeLabelScanTestBase method createTestGraph.
@Override
public void createTestGraph(GraphDatabaseService graphDb) {
MutableLongSet fooNodes = LongSets.mutable.empty();
MutableLongSet barNodes = LongSets.mutable.empty();
try (KernelTransaction tx = beginTransaction()) {
TokenWrite tokenWrite = tx.tokenWrite();
FOO_LABEL = tokenWrite.labelGetOrCreateForName("foo");
BAR_LABEL = tokenWrite.labelGetOrCreateForName("bar");
Write write = tx.dataWrite();
for (int i = 0; i < NUMBER_OF_NODES; i++) {
long node = write.nodeCreate();
if (i % 2 == 0) {
write.nodeAddLabel(node, FOO_LABEL);
fooNodes.add(node);
} else {
write.nodeAddLabel(node, BAR_LABEL);
barNodes.add(node);
}
}
FOO_NODES = fooNodes;
BAR_NODES = barNodes;
tx.commit();
} catch (KernelException e) {
throw new AssertionError(e);
}
}
use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.
the class ProcedureCompiler method compileProcedure.
List<CallableProcedure> compileProcedure(Class<?> procDefinition, String warning, boolean fullAccess) throws KernelException {
try {
List<Method> procedureMethods = Arrays.stream(procDefinition.getDeclaredMethods()).filter(m -> m.isAnnotationPresent(Procedure.class)).collect(Collectors.toList());
if (procedureMethods.isEmpty()) {
return emptyList();
}
assertValidConstructor(procDefinition);
List<CallableProcedure> out = new ArrayList<>(procedureMethods.size());
for (Method method : procedureMethods) {
String valueName = method.getAnnotation(Procedure.class).value();
String definedName = method.getAnnotation(Procedure.class).name();
QualifiedName procName = extractName(procDefinition, method, valueName, definedName);
if (fullAccess || config.isWhitelisted(procName.toString())) {
out.add(compileProcedure(procDefinition, method, warning, fullAccess, procName));
} else {
log.warn(String.format("The procedure '%s' is not on the allowlist and won't be loaded.", procName.toString()));
}
}
out.sort(Comparator.comparing(a -> a.signature().name().toString()));
return out;
} catch (KernelException e) {
throw e;
} catch (Exception e) {
throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, e, "Failed to compile procedure defined in `%s`: %s", procDefinition.getSimpleName(), e.getMessage());
}
}
use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.
the class ProcedureCompiler method compileFunction.
List<CallableUserFunction> compileFunction(Class<?> fcnDefinition, boolean isBuiltin) throws KernelException {
try {
List<Method> functionMethods = Arrays.stream(fcnDefinition.getDeclaredMethods()).filter(m -> m.isAnnotationPresent(UserFunction.class)).collect(Collectors.toList());
if (functionMethods.isEmpty()) {
return emptyList();
}
// used for proper error handling
assertValidConstructor(fcnDefinition);
List<CallableUserFunction> out = new ArrayList<>(functionMethods.size());
for (Method method : functionMethods) {
String valueName = method.getAnnotation(UserFunction.class).value();
String definedName = method.getAnnotation(UserFunction.class).name();
QualifiedName funcName = extractName(fcnDefinition, method, valueName, definedName);
if (isBuiltin || config.isWhitelisted(funcName.toString())) {
out.add(compileFunction(fcnDefinition, method, funcName));
} else {
log.warn(String.format("The function '%s' is not on the allowlist and won't be loaded.", funcName.toString()));
}
}
out.sort(Comparator.comparing(a -> a.signature().name().toString()));
return out;
} catch (KernelException e) {
throw e;
} catch (Exception e) {
throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, e, "Failed to compile function defined in `%s`: %s", fcnDefinition.getSimpleName(), e.getMessage());
}
}
use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.
the class ProcedureCompiler method compileAggregationFunction.
List<CallableUserAggregationFunction> compileAggregationFunction(Class<?> fcnDefinition) throws KernelException {
try {
List<Method> methods = Arrays.stream(fcnDefinition.getDeclaredMethods()).filter(m -> m.isAnnotationPresent(UserAggregationFunction.class)).collect(Collectors.toList());
if (methods.isEmpty()) {
return emptyList();
}
assertValidConstructor(fcnDefinition);
List<CallableUserAggregationFunction> out = new ArrayList<>(methods.size());
for (Method method : methods) {
String valueName = method.getAnnotation(UserAggregationFunction.class).value();
String definedName = method.getAnnotation(UserAggregationFunction.class).name();
QualifiedName funcName = extractName(fcnDefinition, method, valueName, definedName);
if (config.isWhitelisted(funcName.toString())) {
out.add(compileAggregationFunction(fcnDefinition, method, funcName));
} else {
log.warn(String.format("The function '%s' is not on the allowlist and won't be loaded.", funcName.toString()));
}
}
out.sort(Comparator.comparing(a -> a.signature().name().toString()));
return out;
} catch (KernelException e) {
throw e;
} catch (Exception e) {
throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, e, "Failed to compile function defined in `%s`: %s", fcnDefinition.getSimpleName(), e.getMessage());
}
}
Aggregations