use of org.neo4j.kernel.api.proc.CallableProcedure in project neo4j by neo4j.
the class ReflectiveProcedureTest method shouldAllowVoidOutput.
@Test
public void shouldAllowVoidOutput() throws Throwable {
// When
CallableProcedure proc = compile(ProcedureWithVoidOutput.class).get(0);
// Then
assertEquals(0, proc.signature().outputSignature().size());
assertFalse(proc.apply(null, new Object[0]).hasNext());
}
use of org.neo4j.kernel.api.proc.CallableProcedure in project neo4j by neo4j.
the class ReflectiveProcedureTest method shouldRunClassWithMultipleProceduresDeclared.
@Test
public void shouldRunClassWithMultipleProceduresDeclared() throws Throwable {
// Given
List<CallableProcedure> compiled = compile(MultiProcedureProcedure.class);
CallableProcedure bananaPeople = compiled.get(0);
CallableProcedure coolPeople = compiled.get(1);
// When
RawIterator<Object[], ProcedureException> coolOut = coolPeople.apply(new BasicContext(), new Object[0]);
RawIterator<Object[], ProcedureException> bananaOut = bananaPeople.apply(new BasicContext(), new Object[0]);
// Then
assertThat(asList(coolOut), contains(new Object[] { "Bonnie" }, new Object[] { "Clyde" }));
assertThat(asList(bananaOut), contains(new Object[] { "Jake", 18L }, new Object[] { "Pontus", 2L }));
}
use of org.neo4j.kernel.api.proc.CallableProcedure in project neo4j by neo4j.
the class ReflectiveProcedureTest method shouldRunSimpleReadOnlyProcedure.
@Test
public void shouldRunSimpleReadOnlyProcedure() throws Throwable {
// Given
CallableProcedure proc = compile(SingleReadOnlyProcedure.class).get(0);
// When
RawIterator<Object[], ProcedureException> out = proc.apply(new BasicContext(), new Object[0]);
// Then
assertThat(asList(out), contains(new Object[] { "Bonnie" }, new Object[] { "Clyde" }));
}
use of org.neo4j.kernel.api.proc.CallableProcedure 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);
} else {
if (overrideCurrentImplementation) {
procedures.put(name, proc);
} else {
throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, "Unable to register procedure, because the name `%s` is already in use.", name);
}
}
}
use of org.neo4j.kernel.api.proc.CallableProcedure in project neo4j by neo4j.
the class ReflectiveProcedureCompiler method compileProcedure.
private CallableProcedure compileProcedure(Class<?> procDefinition, MethodHandle constructor, Method method, Optional<String> warning, boolean fullAccess, QualifiedName procName) throws ProcedureException, IllegalAccessException {
MethodHandle procedureMethod = lookup.unreflect(method);
List<FieldSignature> inputSignature = inputSignatureDeterminer.signatureFor(method);
OutputMapper outputMapper = outputMappers.mapper(method);
Optional<String> description = description(method);
Procedure procedure = method.getAnnotation(Procedure.class);
Mode mode = procedure.mode();
if (method.isAnnotationPresent(PerformsWrites.class)) {
if (!procedure.mode().equals(org.neo4j.procedure.Mode.DEFAULT)) {
throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, "Conflicting procedure annotation, cannot use PerformsWrites and mode");
} else {
mode = Mode.WRITE;
}
}
Optional<String> deprecated = deprecated(method, procedure::deprecatedBy, "Use of @Procedure(deprecatedBy) without @Deprecated in " + procName);
List<FieldInjections.FieldSetter> setters = allFieldInjections.setters(procDefinition);
if (!fullAccess && !config.fullAccessFor(procName.toString())) {
try {
setters = safeFieldInjections.setters(procDefinition);
} catch (ComponentInjectionException e) {
description = Optional.of(procName.toString() + " is not available due to having restricted access rights, check configuration.");
log.warn(description.get());
ProcedureSignature signature = new ProcedureSignature(procName, inputSignature, outputMapper.signature(), Mode.DEFAULT, Optional.empty(), new String[0], description, warning);
return new FailedLoadProcedure(signature);
}
}
ProcedureSignature signature = new ProcedureSignature(procName, inputSignature, outputMapper.signature(), mode, deprecated, config.rolesFor(procName.toString()), description, warning);
return new ReflectiveProcedure(signature, constructor, procedureMethod, outputMapper, setters);
}
Aggregations