|
35 | 35 | import java.lang.reflect.InvocationTargetException; |
36 | 36 | import java.lang.reflect.ParameterizedType; |
37 | 37 | import java.lang.reflect.Type; |
38 | | -import java.sql.SQLException; |
39 | 38 | import java.util.HashSet; |
40 | 39 | import java.util.Optional; |
41 | 40 | import java.util.Set; |
|
44 | 43 | import static java.lang.System.identityHashCode; |
45 | 44 | import static java.lang.reflect.Proxy.newProxyInstance; |
46 | 45 | import static java.util.Optional.empty; |
47 | | -import static st.orm.template.SqlInterceptor.consume; |
| 46 | +import static st.orm.template.SqlInterceptor.observeThrowing; |
48 | 47 |
|
49 | 48 | public final class KORMTemplateImpl extends KQueryTemplateImpl implements KORMTemplate { |
50 | 49 | private final static ORMReflection REFLECTION = Providers.getORMReflection(); |
@@ -183,18 +182,20 @@ private static void getAllInterfaces(Class<?> clazz, Set<Class<?>> interfacesFou |
183 | 182 | private <T extends KRepository> T wrapRepository(@Nonnull T repository) { |
184 | 183 | return (T) newProxyInstance(repository.getClass().getClassLoader(), getAllInterfaces(repository.getClass()).toArray(new Class[0]), (_, method, args) -> { |
185 | 184 | var lastSql = new AtomicReference<Sql>(); |
186 | | - try (var _ = consume(lastSql::setPlain)) { |
187 | | - try { |
188 | | - return method.invoke(repository, args); |
189 | | - } catch (Exception | Error e) { |
190 | | - throw e; |
191 | | - } catch (Throwable e) { |
192 | | - throw new PersistenceException(e); |
193 | | - } |
| 185 | + try { |
| 186 | + return observeThrowing(lastSql::setPlain, () -> { |
| 187 | + try { |
| 188 | + return method.invoke(repository, args); |
| 189 | + } catch (Exception | Error e) { |
| 190 | + throw e; |
| 191 | + } catch (Throwable e) { |
| 192 | + throw new PersistenceException(e); |
| 193 | + } |
| 194 | + }); |
194 | 195 | } catch (InvocationTargetException e) { |
195 | 196 | try { |
196 | 197 | throw e.getTargetException(); |
197 | | - } catch (SQLException | PersistenceException ex) { |
| 198 | + } catch (Exception ex) { |
198 | 199 | Sql sql = lastSql.getPlain(); |
199 | 200 | if (sql != null && ex.getSuppressed().length == 0) { |
200 | 201 | ex.addSuppressed(new SqlTemplateException(STR.""" |
|
0 commit comments