use of org.neo4j.internal.kernel.api.procs.QualifiedName 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.internal.kernel.api.procs.QualifiedName 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());
}
}
use of org.neo4j.internal.kernel.api.procs.QualifiedName in project neo4j by neo4j.
the class ProcedureHolder method name2Id.
private Integer name2Id(QualifiedName name) {
Integer id = nameToId.get(name);
if (id == null) {
// Did not find it in the case sensitive lookup - let's check for case insensitive objects
QualifiedName lowerCaseName = toLowerCaseName(name);
id = caseInsensitiveName2Id.get(lowerCaseName);
}
return id;
}
use of org.neo4j.internal.kernel.api.procs.QualifiedName in project neo4j by neo4j.
the class ProcedureRegistry method register.
/**
* Register a new function.
*
* @param function the function.
*/
public void register(CallableUserAggregationFunction function, boolean overrideCurrentImplementation, boolean builtIn) throws ProcedureException {
UserFunctionSignature signature = function.signature();
QualifiedName name = signature.name();
if (functions.get(name) != null) {
throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, "Unable to register aggregation function, because the name `%s` is already in use as a function.", name);
}
CallableUserAggregationFunction oldImplementation = aggregationFunctions.get(name);
if (oldImplementation == null) {
aggregationFunctions.put(name, function, signature.caseInsensitive());
} else {
if (overrideCurrentImplementation) {
aggregationFunctions.put(name, function, signature.caseInsensitive());
} else {
throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, "Unable to register aggregation function, because the name `%s` is already in use.", name);
}
}
if (builtIn) {
builtInAggregatingFunctionIds.add(aggregationFunctions.idOf(name));
}
}
use of org.neo4j.internal.kernel.api.procs.QualifiedName in project neo4j by neo4j.
the class ProcedureRegistry method register.
/**
* Register a new procedure.
*
* @param proc the procedure.
*/
public void register(CallableProcedure proc, boolean overrideCurrentImplementation) throws ProcedureException {
ProcedureSignature signature = proc.signature();
QualifiedName name = signature.name();
String descriptiveName = signature.toString();
validateSignature(descriptiveName, signature.inputSignature(), "input");
validateSignature(descriptiveName, signature.outputSignature(), "output");
if (!signature.isVoid() && signature.outputSignature().isEmpty()) {
throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, "Procedures with zero output fields must be declared as VOID");
}
CallableProcedure oldImplementation = procedures.get(name);
if (oldImplementation == null) {
procedures.put(name, proc, signature.caseInsensitive());
} else {
if (overrideCurrentImplementation) {
procedures.put(name, proc, signature.caseInsensitive());
} else {
throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, "Unable to register procedure, because the name `%s` is already in use.", name);
}
}
}
Aggregations