use of org.neo4j.kernel.api.exceptions.KernelException in project neo4j by neo4j.
the class ReflectiveProcedureCompiler method compileProcedure.
List<CallableProcedure> compileProcedure(Class<?> procDefinition, Optional<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();
}
MethodHandle constructor = constructor(procDefinition);
ArrayList<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, constructor, method, warning, fullAccess, procName));
} else {
log.warn(String.format("The procedure '%s' is not on the whitelist 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.kernel.api.exceptions.KernelException in project neo4j by neo4j.
the class ReflectiveProcedureCompiler method compileFunction.
List<CallableUserFunction> compileFunction(Class<?> fcnDefinition) throws KernelException {
try {
List<Method> procedureMethods = Arrays.stream(fcnDefinition.getDeclaredMethods()).filter(m -> m.isAnnotationPresent(UserFunction.class)).collect(Collectors.toList());
if (procedureMethods.isEmpty()) {
return emptyList();
}
MethodHandle constructor = constructor(fcnDefinition);
ArrayList<CallableUserFunction> out = new ArrayList<>(procedureMethods.size());
for (Method method : procedureMethods) {
String valueName = method.getAnnotation(UserFunction.class).value();
String definedName = method.getAnnotation(UserFunction.class).name();
QualifiedName procName = extractName(fcnDefinition, method, valueName, definedName);
if (config.isWhitelisted(procName.toString())) {
out.add(compileFunction(fcnDefinition, constructor, method, procName));
} else {
log.warn(String.format("The function '%s' is not on the whitelist 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 function defined in `%s`: %s", fcnDefinition.getSimpleName(), e.getMessage());
}
}
use of org.neo4j.kernel.api.exceptions.KernelException in project neo4j by neo4j.
the class TransactionStateMachineSPI method executeQuery.
@Override
public BoltResultHandle executeQuery(BoltQuerySource querySource, SecurityContext securityContext, String statement, Map<String, Object> params, ThrowingAction<KernelException> onFail) throws QueryExecutionKernelException {
InternalTransaction internalTransaction = queryService.beginTransaction(implicit, securityContext);
ClientConnectionInfo sourceDetails = new BoltConnectionInfo(querySource.principalName, querySource.clientName, querySource.connectionDescriptor.clientAddress, querySource.connectionDescriptor.serverAddress);
TransactionalContext transactionalContext = contextFactory.newContext(sourceDetails, internalTransaction, statement, params);
return new BoltResultHandle() {
@Override
public BoltResult start() throws KernelException {
try {
Result run = queryExecutionEngine.executeQuery(statement, params, transactionalContext);
return new CypherAdapterStream(run, clock);
} catch (KernelException e) {
onFail.apply();
throw new QueryExecutionKernelException(e);
} catch (Throwable e) {
onFail.apply();
throw e;
}
}
@Override
public void terminate() {
transactionalContext.terminate();
}
};
}
Aggregations