use of org.neo4j.kernel.api.proc.CallableUserFunction in project neo4j by neo4j.
the class ProcedureRegistry method register.
/**
* Register a new function.
*
* @param function the function.
*/
public void register(CallableUserFunction function, boolean overrideCurrentImplementation) throws ProcedureException {
UserFunctionSignature signature = function.signature();
QualifiedName name = signature.name();
CallableUserFunction oldImplementation = functions.get(name);
if (oldImplementation == null) {
functions.put(name, function);
} else {
if (overrideCurrentImplementation) {
functions.put(name, function);
} else {
throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, "Unable to register function, because the name `%s` is already in use.", name);
}
}
}
use of org.neo4j.kernel.api.proc.CallableUserFunction 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) throws ProcedureException {
UserFunctionSignature signature = function.signature();
QualifiedName name = signature.name();
CallableUserFunction oldImplementation = functions.get(name);
if (oldImplementation == null) {
aggregationFunctions.put(name, function);
} else {
if (overrideCurrentImplementation) {
aggregationFunctions.put(name, function);
} else {
throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, "Unable to register aggregation function, because the name `%s` is already in use.", name);
}
}
}
use of org.neo4j.kernel.api.proc.CallableUserFunction in project neo4j by neo4j.
the class Procedures method start.
@Override
public void start() throws Throwable {
ProcedureJarLoader loader = new ProcedureJarLoader(compiler, log);
ProcedureJarLoader.Callables callables = loader.loadProceduresFromDir(pluginDir);
for (CallableProcedure procedure : callables.procedures()) {
register(procedure);
}
for (CallableUserFunction function : callables.functions()) {
register(function);
}
for (CallableUserAggregationFunction function : callables.aggregationFunctions()) {
register(function);
}
// And register built-in procedures
builtin.accept(this);
}
use of org.neo4j.kernel.api.proc.CallableUserFunction in project neo4j by neo4j.
the class ReflectiveUserFunctionTest method shouldInjectLogging.
@Test
public void shouldInjectLogging() throws KernelException {
// Given
Log log = spy(Log.class);
components.register(Log.class, (ctx) -> log);
CallableUserFunction function = procedureCompiler.compileFunction(LoggingFunction.class).get(0);
// When
function.apply(new BasicContext(), new Object[0]);
// Then
verify(log).debug("1");
verify(log).info("2");
verify(log).warn("3");
verify(log).error("4");
}
use of org.neo4j.kernel.api.proc.CallableUserFunction in project neo4j by neo4j.
the class ReflectiveUserFunctionTest method shouldSupportFunctionDeprecation.
@Test
public void shouldSupportFunctionDeprecation() throws Throwable {
// Given
Log log = mock(Log.class);
ReflectiveProcedureCompiler procedureCompiler = new ReflectiveProcedureCompiler(new TypeMappers(), components, new ComponentRegistry(), log, ProcedureConfig.DEFAULT);
// When
List<CallableUserFunction> funcs = procedureCompiler.compileFunction(FunctionWithDeprecation.class);
// Then
verify(log).warn("Use of @UserFunction(deprecatedBy) without @Deprecated in org.neo4j.kernel.impl.proc.badFunc");
verifyNoMoreInteractions(log);
for (CallableUserFunction func : funcs) {
String name = func.signature().name().name();
func.apply(new BasicContext(), new Object[0]);
switch(name) {
case "newFunc":
assertFalse("Should not be deprecated", func.signature().deprecated().isPresent());
break;
case "oldFunc":
case "badFunc":
assertTrue("Should be deprecated", func.signature().deprecated().isPresent());
assertThat(func.signature().deprecated().get(), equalTo("newFunc"));
break;
default:
fail("Unexpected function: " + name);
}
}
}
Aggregations