Search in sources :

Example 1 with QualifiedName

use of org.neo4j.kernel.api.proc.QualifiedName 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);
        }
    }
}
Also used : CallableUserFunction(org.neo4j.kernel.api.proc.CallableUserFunction) QualifiedName(org.neo4j.kernel.api.proc.QualifiedName) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) UserFunctionSignature(org.neo4j.kernel.api.proc.UserFunctionSignature)

Example 2 with QualifiedName

use of org.neo4j.kernel.api.proc.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) 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);
        }
    }
}
Also used : CallableUserFunction(org.neo4j.kernel.api.proc.CallableUserFunction) QualifiedName(org.neo4j.kernel.api.proc.QualifiedName) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) UserFunctionSignature(org.neo4j.kernel.api.proc.UserFunctionSignature)

Example 3 with QualifiedName

use of org.neo4j.kernel.api.proc.QualifiedName in project neo4j by neo4j.

the class ProceduresKernelIT method shouldCallReadOnlyProcedure.

@Test
public void shouldCallReadOnlyProcedure() throws Throwable {
    // Given
    kernel.registerProcedure(procedure);
    // When
    RawIterator<Object[], ProcedureException> found = procedureCallOpsInNewTx().procedureCallRead(new QualifiedName(new String[] { "example" }, "exampleProc"), new Object[] { 1337 });
    // Then
    assertThat(asList(found), contains(equalTo(new Object[] { 1337 })));
}
Also used : QualifiedName(org.neo4j.kernel.api.proc.QualifiedName) NTString(org.neo4j.kernel.api.proc.Neo4jTypes.NTString) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Test(org.junit.Test)

Example 4 with QualifiedName

use of org.neo4j.kernel.api.proc.QualifiedName in project neo4j by neo4j.

the class ConfiguredProceduresTestBase method shouldSetAllowedToConfigSetting.

@Test
public void shouldSetAllowedToConfigSetting() throws Throwable {
    configuredSetup(stringMap(SecuritySettings.default_allowed.name(), "nonEmpty"));
    Procedures procedures = neo.getLocalGraph().getDependencyResolver().resolveDependency(Procedures.class);
    ProcedureSignature numNodes = procedures.procedure(new QualifiedName(new String[] { "test" }, "numNodes"));
    assertThat(Arrays.asList(numNodes.allowed()), containsInAnyOrder("nonEmpty"));
}
Also used : ProcedureSignature(org.neo4j.kernel.api.proc.ProcedureSignature) QualifiedName(org.neo4j.kernel.api.proc.QualifiedName) Procedures(org.neo4j.kernel.impl.proc.Procedures) Test(org.junit.Test)

Example 5 with QualifiedName

use of org.neo4j.kernel.api.proc.QualifiedName in project neo4j by neo4j.

the class ConfiguredProceduresTestBase method shouldSetAllowedToConfigSettingForUDF.

@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
public void shouldSetAllowedToConfigSettingForUDF() throws Throwable {
    configuredSetup(stringMap(SecuritySettings.default_allowed.name(), "nonEmpty"));
    Procedures procedures = neo.getLocalGraph().getDependencyResolver().resolveDependency(Procedures.class);
    UserFunctionSignature funcSig = procedures.function(new QualifiedName(new String[] { "test" }, "nonAllowedFunc")).get();
    assertThat(Arrays.asList(funcSig.allowed()), containsInAnyOrder("nonEmpty"));
}
Also used : QualifiedName(org.neo4j.kernel.api.proc.QualifiedName) Procedures(org.neo4j.kernel.impl.proc.Procedures) UserFunctionSignature(org.neo4j.kernel.api.proc.UserFunctionSignature) Test(org.junit.Test)

Aggregations

QualifiedName (org.neo4j.kernel.api.proc.QualifiedName)13 ProcedureSignature (org.neo4j.kernel.api.proc.ProcedureSignature)8 Test (org.junit.Test)7 ProcedureException (org.neo4j.kernel.api.exceptions.ProcedureException)7 UserFunctionSignature (org.neo4j.kernel.api.proc.UserFunctionSignature)7 CallableUserFunction (org.neo4j.kernel.api.proc.CallableUserFunction)5 CallableProcedure (org.neo4j.kernel.api.proc.CallableProcedure)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 ArrayList (java.util.ArrayList)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 List (java.util.List)3 Optional (java.util.Optional)3 Supplier (java.util.function.Supplier)3