0

I am using Spring boot 2 with Reactive repository for executing stored proc which will return the count. I have 30 stored proc and all of them will just return a number and takes no arguments.

So created a model for stored proc StroedProcDomain.java and one sample repository as below.

@Repository
public interface JobRepository extends ReactiveCrudRepository<StroedProcDomain, Long> {

    @Query("CALL JOB_LOAD()")
    Mono<Integer> executeProc();

}

Need to create 30 such repositories and would like to enforce all the repositories to use the same method

Mono<Integer> executeProc()

But the stored proc name will be different. So @Query will be different for each repository.

What is the best way to achieve this?

Currently, I have 30 repositories. Would like to have a base repository so as to force the method name.

user1578872
  • 7,808
  • 29
  • 108
  • 206
  • I don't think this is possible to force the method name on an interface. To have a base repository, you can define an interface and use @NoRepositoryBean on it then extend it, however this mean the Query annotation has to be put on the base interface method. https://stackoverflow.com/questions/11576831/understanding-the-spring-data-jpa-norepositorybean-interface – Cyril G. Sep 12 '21 at 15:13
  • Is it possible to pass the query thru param and have only one method in the base class? – user1578872 Sep 12 '21 at 15:19

1 Answers1

1

In theory you could put a two methods on a common interface: your actual query method, which would be implemented by a custom method calling the stored procedure, plus a method that provides just the name of the stored procedure.

But this would be considerable more code and more complex code than just an annotated query method on each repository.

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348