Search in sources :

Example 11 with KernelException

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());
    }
}
Also used : FailedLoadProcedure(org.neo4j.kernel.api.proc.FailedLoadProcedure) Mode(org.neo4j.procedure.Mode) MethodHandle(java.lang.invoke.MethodHandle) Arrays(java.util.Arrays) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Log(org.neo4j.logging.Log) RawIterator(org.neo4j.collection.RawIterator) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure) UserAggregationResult(org.neo4j.procedure.UserAggregationResult) Status(org.neo4j.kernel.api.exceptions.Status) UserAggregationUpdate(org.neo4j.procedure.UserAggregationUpdate) FailedLoadFunction(org.neo4j.kernel.api.proc.FailedLoadFunction) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Iterators.asRawIterator(org.neo4j.helpers.collection.Iterators.asRawIterator) FailedLoadAggregatedFunction(org.neo4j.kernel.api.proc.FailedLoadAggregatedFunction) ProcedureSignature(org.neo4j.kernel.api.proc.ProcedureSignature) CallableUserAggregationFunction(org.neo4j.kernel.api.proc.CallableUserAggregationFunction) Procedure(org.neo4j.procedure.Procedure) Method(java.lang.reflect.Method) ComponentInjectionException(org.neo4j.kernel.api.exceptions.ComponentInjectionException) CallableUserFunction(org.neo4j.kernel.api.proc.CallableUserFunction) Iterator(java.util.Iterator) UserFunctionSignature(org.neo4j.kernel.api.proc.UserFunctionSignature) Collections.emptyList(java.util.Collections.emptyList) MethodHandles(java.lang.invoke.MethodHandles) Description(org.neo4j.procedure.Description) Collections.emptyIterator(java.util.Collections.emptyIterator) Collectors(java.util.stream.Collectors) KernelException(org.neo4j.kernel.api.exceptions.KernelException) FieldSignature(org.neo4j.kernel.api.proc.FieldSignature) UserFunction(org.neo4j.procedure.UserFunction) List(java.util.List) Stream(java.util.stream.Stream) UserAggregationFunction(org.neo4j.procedure.UserAggregationFunction) QualifiedName(org.neo4j.kernel.api.proc.QualifiedName) Modifier(java.lang.reflect.Modifier) Optional(java.util.Optional) PerformsWrites(org.neo4j.procedure.PerformsWrites) Comparator(java.util.Comparator) Context(org.neo4j.kernel.api.proc.Context) OutputMapper(org.neo4j.kernel.impl.proc.OutputMappers.OutputMapper) QualifiedName(org.neo4j.kernel.api.proc.QualifiedName) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) ComponentInjectionException(org.neo4j.kernel.api.exceptions.ComponentInjectionException) KernelException(org.neo4j.kernel.api.exceptions.KernelException) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure) FailedLoadProcedure(org.neo4j.kernel.api.proc.FailedLoadProcedure) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure) Procedure(org.neo4j.procedure.Procedure) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) KernelException(org.neo4j.kernel.api.exceptions.KernelException) MethodHandle(java.lang.invoke.MethodHandle)

Example 12 with KernelException

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());
    }
}
Also used : FailedLoadProcedure(org.neo4j.kernel.api.proc.FailedLoadProcedure) Mode(org.neo4j.procedure.Mode) MethodHandle(java.lang.invoke.MethodHandle) Arrays(java.util.Arrays) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Log(org.neo4j.logging.Log) RawIterator(org.neo4j.collection.RawIterator) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure) UserAggregationResult(org.neo4j.procedure.UserAggregationResult) Status(org.neo4j.kernel.api.exceptions.Status) UserAggregationUpdate(org.neo4j.procedure.UserAggregationUpdate) FailedLoadFunction(org.neo4j.kernel.api.proc.FailedLoadFunction) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Iterators.asRawIterator(org.neo4j.helpers.collection.Iterators.asRawIterator) FailedLoadAggregatedFunction(org.neo4j.kernel.api.proc.FailedLoadAggregatedFunction) ProcedureSignature(org.neo4j.kernel.api.proc.ProcedureSignature) CallableUserAggregationFunction(org.neo4j.kernel.api.proc.CallableUserAggregationFunction) Procedure(org.neo4j.procedure.Procedure) Method(java.lang.reflect.Method) ComponentInjectionException(org.neo4j.kernel.api.exceptions.ComponentInjectionException) CallableUserFunction(org.neo4j.kernel.api.proc.CallableUserFunction) Iterator(java.util.Iterator) UserFunctionSignature(org.neo4j.kernel.api.proc.UserFunctionSignature) Collections.emptyList(java.util.Collections.emptyList) MethodHandles(java.lang.invoke.MethodHandles) Description(org.neo4j.procedure.Description) Collections.emptyIterator(java.util.Collections.emptyIterator) Collectors(java.util.stream.Collectors) KernelException(org.neo4j.kernel.api.exceptions.KernelException) FieldSignature(org.neo4j.kernel.api.proc.FieldSignature) UserFunction(org.neo4j.procedure.UserFunction) List(java.util.List) Stream(java.util.stream.Stream) UserAggregationFunction(org.neo4j.procedure.UserAggregationFunction) QualifiedName(org.neo4j.kernel.api.proc.QualifiedName) Modifier(java.lang.reflect.Modifier) Optional(java.util.Optional) PerformsWrites(org.neo4j.procedure.PerformsWrites) Comparator(java.util.Comparator) Context(org.neo4j.kernel.api.proc.Context) OutputMapper(org.neo4j.kernel.impl.proc.OutputMappers.OutputMapper) CallableUserFunction(org.neo4j.kernel.api.proc.CallableUserFunction) QualifiedName(org.neo4j.kernel.api.proc.QualifiedName) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) ComponentInjectionException(org.neo4j.kernel.api.exceptions.ComponentInjectionException) KernelException(org.neo4j.kernel.api.exceptions.KernelException) CallableUserFunction(org.neo4j.kernel.api.proc.CallableUserFunction) UserFunction(org.neo4j.procedure.UserFunction) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) KernelException(org.neo4j.kernel.api.exceptions.KernelException) MethodHandle(java.lang.invoke.MethodHandle)

Example 13 with KernelException

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();
        }
    };
}
Also used : ClientConnectionInfo(org.neo4j.kernel.impl.query.clientconnection.ClientConnectionInfo) BoltConnectionInfo(org.neo4j.kernel.impl.query.clientconnection.BoltConnectionInfo) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) BoltResultHandle(org.neo4j.bolt.v1.runtime.TransactionStateMachine.BoltResultHandle) TransactionalContext(org.neo4j.kernel.impl.query.TransactionalContext) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) KernelException(org.neo4j.kernel.api.exceptions.KernelException) BoltResult(org.neo4j.bolt.v1.runtime.spi.BoltResult) Result(org.neo4j.graphdb.Result)

Aggregations

KernelException (org.neo4j.kernel.api.exceptions.KernelException)13 ArrayList (java.util.ArrayList)5 Log (org.neo4j.logging.Log)5 List (java.util.List)4 Optional (java.util.Optional)4 Stream (java.util.stream.Stream)4 RawIterator (org.neo4j.collection.RawIterator)4 Status (org.neo4j.kernel.api.exceptions.Status)4 CallableProcedure (org.neo4j.kernel.api.proc.CallableProcedure)4 CallableUserAggregationFunction (org.neo4j.kernel.api.proc.CallableUserAggregationFunction)4 CallableUserFunction (org.neo4j.kernel.api.proc.CallableUserFunction)4 MethodHandle (java.lang.invoke.MethodHandle)3 MethodHandles (java.lang.invoke.MethodHandles)3 Method (java.lang.reflect.Method)3 Modifier (java.lang.reflect.Modifier)3 Arrays (java.util.Arrays)3 Collections.emptyIterator (java.util.Collections.emptyIterator)3 Collections.emptyList (java.util.Collections.emptyList)3 Comparator (java.util.Comparator)3 Iterator (java.util.Iterator)3