@Override public void registerUserFunction( CallableUserFunction function ) throws ProcedureException { procedures.register( function ); }
/** * Register a new function. This method must not be called concurrently with {@link #procedure(QualifiedName)}. * @param function the function. */ public void register( CallableUserAggregationFunction function ) throws ProcedureException { register( function, false ); }
@Override public void registerProcedure( CallableProcedure procedure ) throws ProcedureException { procedures.register( procedure ); }
@Override public void registerUserAggregationFunction( CallableUserAggregationFunction function ) throws ProcedureException { procedures.register( function ); }
/** * Register a new procedure. This method must not be called concurrently with {@link #procedure(QualifiedName)}. * @param proc the procedure. */ public void register( CallableProcedure proc ) throws ProcedureException { register( proc, false ); }
/** * Register a new function. This method must not be called concurrently with {@link #procedure(QualifiedName)}. * @param function the function. */ public void register( CallableUserFunction function ) throws ProcedureException { register( function, false ); }
private static void register( TemporalFunction<?> base, Procedures procedures ) throws ProcedureException { procedures.register( base ); procedures.register( new Now<>( base, "transaction" ) ); procedures.register( new Now<>( base, "statement" ) ); procedures.register( new Now<>( base, "realtime" ) ); procedures.register( new Truncate<>( base ) ); base.registerMore( procedures ); }
/** * Register a new function defined with annotations on a java class. * @param func the function class */ public void registerFunction( Class<?> func, boolean overrideCurrentImplementation ) throws KernelException { for ( CallableUserFunction function : compiler.compileFunction( func ) ) { register( function, overrideCurrentImplementation ); } }
static void register( Procedures procedures ) throws ProcedureException { procedures.register( new DurationFunction() ); procedures.register( new Between( "between" ) ); procedures.register( new Between( "inMonths" ) ); procedures.register( new Between( "inDays" ) ); procedures.register( new Between( "inSeconds" ) ); }
@Override public void accept( Procedures procs ) throws ProcedureException { procs.register( new ListComponentsProcedure( procedureName( "dbms", "components" ), neo4jVersion, neo4jEdition ) ); procs.register( new JmxQueryProcedure( procedureName( "dbms", "queryJmx" ), ManagementFactory.getPlatformMBeanServer() ) ); } }
/** * Register a new function defined with annotations on a java class. * @param func the function class */ public void registerBuiltInFunctions( Class<?> func ) throws KernelException { for ( CallableUserFunction function : compiler.withoutNamingRestrictions().compileFunction( func ) ) { register( function, false ); } }
@Test public void shouldNotAllowRegisteringConflictingName() throws Throwable { // Given procs.register( procedure ); // Expect exception.expect( ProcedureException.class ); exception.expectMessage( "Unable to register procedure, because the name `org.myproc` is already in use." ); // When procs.register( procedure ); }
@Test public void shouldNotAllowRegisteringConflictingName() throws Throwable { // Given procs.register( function ); // Expect exception.expect( ProcedureException.class ); exception.expectMessage( "Unable to register function, because the name `org.myproc` is already in use." ); // When procs.register( function ); }
@Test public void shouldCallRegisteredProcedure() throws Throwable { // Given procs.register( procedure ); // When RawIterator<Object[], ProcedureException> result = procs.callProcedure( new BasicContext(), signature.name(), new Object[]{1337}, resourceTracker ); // Then assertThat( asList( result ), contains( equalTo( new Object[]{1337} ) ) ); }
@Test public void shouldGetRegisteredProcedure() throws Throwable { // When procs.register( procedure ); // Then assertThat( procs.procedure( signature.name() ).signature(), equalTo( signature ) ); }
@Test public void shouldGetRegisteredFunction() throws Throwable { // When procs.register( function ); // Then assertThat( procs.function( signature.name() ).signature(), equalTo( signature ) ); }
@Test public void shouldCallRegisteredFunction() throws Throwable { // Given procs.register( function ); // When Object result = procs.callFunction( new BasicContext(), signature.name(), new AnyValue[] {numberValue( 1337 )} ); // Then assertThat( result , equalTo( Values.of(1337) ) ); }
@Test public void shouldNotAllowDuplicateFieldNamesInInput() throws Throwable { // Expect exception.expect( ProcedureException.class ); exception.expectMessage( "Procedure `asd(a :: ANY?, a :: ANY?) :: ()` cannot be " + "registered, because it contains a duplicated input field, 'a'. " + "You need to rename or remove one of the duplicate fields." ); // When procs.register( procedureWithSignature( procedureSignature( "asd" ).in( "a", NTAny ).in( "a", NTAny ).build() ) ); }
@Test public void shouldNotAllowDuplicateFieldNamesInOutput() throws Throwable { // Expect exception.expect( ProcedureException.class ); exception.expectMessage( "Procedure `asd() :: (a :: ANY?, a :: ANY?)` cannot be registered, " + "because it contains a duplicated output field, 'a'. " + "You need to rename or remove one of the duplicate fields." ); // When procs.register( procedureWithSignature( procedureSignature( "asd" ).out( "a", NTAny ).out( "a", NTAny ).build() ) ); }