public static QualifiedName procedureName( String... namespaceAndName ) { return procedureSignature( namespaceAndName ).build().name(); } }
@Override public RawIterator<Object[],ProcedureException> apply( Context ctx, Object[] input, ResourceTracker resourceTracker ) throws ProcedureException { throw new ProcedureException( Status.Procedure.ProcedureRegistrationFailed, signature().description().orElse( "Failed to load " + signature().name() ) ); } }
@Description( "List all procedures in the DBMS." ) @Procedure( name = "dbms.procedures", mode = DBMS ) public Stream<ProcedureResult> listProcedures() { securityContext.assertCredentialsNotExpired(); return graph.getDependencyResolver().resolveDependency( Procedures.class ).getAllProcedures().stream() .sorted( Comparator.comparing( a -> a.name().toString() ) ) .map( ProcedureResult::new ); }
private ProcedureException newProcedureException( Throwable throwable ) { // Unwrap the wrapped exception we get from invocation by reflection if ( throwable instanceof InvocationTargetException ) { throwable = throwable.getCause(); } if ( throwable instanceof Status.HasStatus ) { return new ProcedureException( ((Status.HasStatus) throwable).status(), throwable, throwable.getMessage() ); } else { Throwable cause = ExceptionUtils.getRootCause( throwable ); return new ProcedureException( Status.Procedure.ProcedureCallFailed, throwable, "Failed to invoke procedure `%s`: %s", signature.name(), "Caused by: " + (cause != null ? cause : throwable) ); } } }
private ProcedureResult( ProcedureSignature signature ) { this.name = signature.name().toString(); this.signature = signature.toString(); this.description = signature.description().orElse( "" ); this.mode = signature.mode().toString(); } }
out.sort( Comparator.comparing( a -> a.signature().name().toString() ) ); return out;
signature.name(), inputSignature.size(), input.length );
@Test public void shouldGetRegisteredProcedure() throws Throwable { // When procs.register( procedure ); // Then assertThat( procs.procedure( signature.name() ).signature(), equalTo( signature ) ); }
@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 shouldAllowOverridingProcedureName() throws Throwable { // When CallableProcedure proc = compile( ProcedureWithOverriddenName.class ).get( 0 ); // Then assertEquals("org.mystuff.thisisActuallyTheName", proc.signature().name().toString() ); }
@Test public void shouldAllowOverridingProcedureNameWithoutNamespace() throws Throwable { // When CallableProcedure proc = compile( ProcedureWithSingleName.class ).get( 0 ); // Then assertEquals("singleName", proc.signature().name().toString() ); }
@Test public void shouldSignalNonExistingProcedure() throws Throwable { // Expect exception.expect( ProcedureException.class ); exception.expectMessage( "There is no procedure with the name `org.myproc` registered for this " + "database instance. Please ensure you've spelled the " + "procedure name correctly and that the procedure is properly deployed." ); // When procs.procedure( signature.name() ); }
@Test public void shouldNotAllowCallingNonExistingProcedure() throws Throwable { // Expect exception.expect( ProcedureException.class ); exception.expectMessage( "There is no procedure with the name `org.myproc` registered for this " + "database instance. Please ensure you've spelled the " + "procedure name correctly and that the procedure is properly deployed." ); // When procs.callProcedure( new BasicContext(), signature.name(), new Object[]{1337}, resourceTracker ); }
@Test public void shouldMakeContextAvailable() throws Throwable { // Given Key<String> someKey = key("someKey", String.class); procs.register( new CallableProcedure.BasicProcedure( signature ) { @Override public RawIterator<Object[], ProcedureException> apply( Context ctx, Object[] input, ResourceTracker resourceTracker ) throws ProcedureException { return RawIterator.<Object[], ProcedureException>of( new Object[]{ctx.get( someKey )} ); } } ); BasicContext ctx = new BasicContext(); ctx.put( someKey, "hello, world" ); // When RawIterator<Object[], ProcedureException> result = procs.callProcedure( ctx, signature.name(), new Object[0], resourceTracker ); // Then assertThat( asList( result ), contains( equalTo( new Object[]{ "hello, world" } ) ) ); }
QualifiedName name = signature.name();
for ( CallableProcedure proc : procs ) String name = proc.signature().name().name(); proc.apply( new BasicContext(), new Object[0], resourceTracker ); switch ( name )
@Test public void registeredProcedureShouldGetRead() throws Throwable { // Given internalKernel().registerProcedure( new CallableProcedure.BasicProcedure( signature ) { @Override public RawIterator<Object[],ProcedureException> apply( Context ctx, Object[] input, ResourceTracker resourceTracker ) throws ProcedureException { return RawIterator.<Object[],ProcedureException>of( new Object[]{ctx.get( Context.KERNEL_TRANSACTION ).dataRead()} ); } } ); // When RawIterator<Object[],ProcedureException> stream = procs().procedureCallRead( procs().procedureGet( signature.name() ).id(), new Object[]{""} ); // Then assertNotNull( asList( stream ).get( 0 )[0] ); commit(); }
@Override public RawIterator<Object[],ProcedureException> apply( Context ctx, Object[] input, ResourceTracker resourceTracker ) throws ProcedureException { throw new ProcedureException( Status.Procedure.ProcedureRegistrationFailed, signature().description().orElse( "Failed to load " + signature().name() ) ); } }
@Description( "List all procedures in the DBMS." ) @Procedure( name = "dbms.procedures", mode = DBMS ) public Stream<ProcedureResult> listProcedures() { securityContext.assertCredentialsNotExpired(); Procedures procedures = graph.getDependencyResolver().resolveDependency( Procedures.class ); return procedures.getAllProcedures().stream() .sorted( Comparator.comparing( a -> a.name().toString() ) ) .map( ProcedureResult::new ); }
private ProcedureResult( ProcedureSignature signature ) { this.name = signature.name().toString(); this.signature = signature.toString(); this.description = signature.description().orElse( "" ); this.mode = signature.mode().toString(); } }