1

I want to a create a functional interface or default method where I pass in a jpa repository method such as findById or findByNumber and have it return a generic type; this way I annotate it with @Retryable if the application fails to connect to db. Below are examples of methods I want passed through the functional interface:

Employee employee = repository.findById("2ed21");
Record record = repository.findbyNumber(311);
John Bollinger
  • 160,171
  • 8
  • 81
  • 157
Wes
  • 13
  • 3
  • 1
    There seems to be some duplicate text in your question, but more importantly, you haven't asked one. Where are you stuck? Please read [ask]. – tgdavies Aug 09 '23 at 22:16
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Aug 10 '23 at 14:26

1 Answers1

1

How about a simple method with a Supplier as a parameter where you can put literally anything?

@Retryable(...)
public <T> T retry(Supplier<T> supplier) {
    return supplier.get();
}

Usage:

Employee employee = retry(() -> repository.findById("2ed21"));
Record record = retry(() -> repository.findbyNumber(311));

Few notes:

Nikolas Charalambidis
  • 40,893
  • 16
  • 117
  • 183