private AnyValue callFunction( int id, AnyValue[] input, final AccessMode mode ) throws ProcedureException { ktx.assertOpen(); SecurityContext securityContext = ktx.securityContext().withMode( mode ); try ( KernelTransaction.Revertable ignore = ktx.overrideWith( securityContext ) ) { return procedures.callFunction( prepareContext( securityContext ), id, input ); } }
private AnyValue callFunction( QualifiedName name, AnyValue[] input, final AccessMode mode ) throws ProcedureException { ktx.assertOpen(); SecurityContext securityContext = ktx.securityContext().withMode( mode ); try ( KernelTransaction.Revertable ignore = ktx.overrideWith( securityContext ) ) { return procedures.callFunction( prepareContext( securityContext ), name, input ); } }
@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 shouldNotAllowCallingNonExistingFunction() throws Throwable { // Expect exception.expect( ProcedureException.class ); exception.expectMessage( "There is no function with the name `org.myproc` registered for this " + "database instance. Please ensure you've spelled the " + "function name correctly and that the function is properly deployed." ); // When procs.callFunction( new BasicContext(), signature.name(), new AnyValue[] {numberValue( 1337 )} ); }
@Test public void shouldMakeContextAvailable() throws Throwable { // Given Key<String> someKey = key("someKey", String.class); procs.register( new CallableUserFunction.BasicUserFunction( signature ) { @Override public AnyValue apply( Context ctx, AnyValue[] input ) throws ProcedureException { return Values.stringValue( ctx.get( someKey ) ); } } ); BasicContext ctx = new BasicContext(); ctx.put( someKey, "hello, world" ); // When Object result = procs.callFunction( ctx, signature.name(), new AnyValue[0] ); // Then assertThat( result, equalTo(Values.of("hello, world") ) ); }
private AnyValue callFunction( int id, AnyValue[] input, final AccessMode mode ) throws ProcedureException { ktx.assertOpen(); SecurityContext securityContext = ktx.securityContext().withMode( mode ); try ( KernelTransaction.Revertable ignore = ktx.overrideWith( securityContext ) ) { return procedures.callFunction( prepareContext( securityContext ), id, input ); } }
private AnyValue callFunction( QualifiedName name, AnyValue[] input, final AccessMode mode ) throws ProcedureException { ktx.assertOpen(); SecurityContext securityContext = ktx.securityContext().withMode( mode ); try ( KernelTransaction.Revertable ignore = ktx.overrideWith( securityContext ) ) { return procedures.callFunction( prepareContext( securityContext ), name, input ); } }