1.1 --- a/src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java Sun Dec 20 11:06:25 2020 +0100 1.2 +++ b/src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java Mon Dec 21 18:29:34 2020 +0100 1.3 @@ -28,8 +28,8 @@ 1.4 */ 1.5 package de.uapcore.lightpit; 1.6 1.7 -import de.uapcore.lightpit.dao.DaoProvider; 1.8 -import de.uapcore.lightpit.dao.postgres.PGDaoProvider; 1.9 +import de.uapcore.lightpit.dao.DataAccessObject; 1.10 +import de.uapcore.lightpit.dao.PostgresDataAccessObject; 1.11 import org.slf4j.Logger; 1.12 import org.slf4j.LoggerFactory; 1.13 1.14 @@ -56,26 +56,6 @@ 1.15 1.16 private static final String SITE_JSP = jspPath("site"); 1.17 1.18 - 1.19 - @FunctionalInterface 1.20 - protected interface SQLFindFunction<K, T> { 1.21 - T apply(K key) throws SQLException; 1.22 - 1.23 - default <V> SQLFindFunction<V, T> compose(Function<? super V, ? extends K> before) throws SQLException { 1.24 - Objects.requireNonNull(before); 1.25 - return (v) -> this.apply(before.apply(v)); 1.26 - } 1.27 - 1.28 - default <V> SQLFindFunction<K, V> andThen(Function<? super T, ? extends V> after) throws SQLException { 1.29 - Objects.requireNonNull(after); 1.30 - return (t) -> after.apply(this.apply(t)); 1.31 - } 1.32 - 1.33 - static <K> Function<K, K> identity() { 1.34 - return (t) -> t; 1.35 - } 1.36 - } 1.37 - 1.38 /** 1.39 * Invocation mapping gathered from the {@link RequestMapping} annotations. 1.40 * <p> 1.41 @@ -101,15 +81,15 @@ 1.42 * @param connection the SQL connection 1.43 * @return a set of data access objects 1.44 */ 1.45 - private DaoProvider createDataAccessObjects(Connection connection) throws SQLException { 1.46 + private DataAccessObject createDataAccessObjects(Connection connection) { 1.47 final var df = (DataSourceProvider) getServletContext().getAttribute(DataSourceProvider.Companion.getSC_ATTR_NAME()); 1.48 if (df.getDialect() == DataSourceProvider.Dialect.Postgres) { 1.49 - return new PGDaoProvider(connection); 1.50 + return new PostgresDataAccessObject(connection); 1.51 } 1.52 throw new UnsupportedOperationException("Non-exhaustive if-else - this is a bug."); 1.53 } 1.54 1.55 - private void invokeMapping(Map.Entry<PathPattern, Method> mapping, HttpServletRequest req, HttpServletResponse resp, DaoProvider dao) throws IOException { 1.56 + private void invokeMapping(Map.Entry<PathPattern, Method> mapping, HttpServletRequest req, HttpServletResponse resp, DataAccessObject dao) throws IOException { 1.57 final var pathPattern = mapping.getKey(); 1.58 final var method = mapping.getValue(); 1.59 try { 1.60 @@ -122,7 +102,7 @@ 1.61 } else if (paramTypes[i].isAssignableFrom(HttpServletResponse.class)) { 1.62 paramValues[i] = resp; 1.63 } 1.64 - if (paramTypes[i].isAssignableFrom(DaoProvider.class)) { 1.65 + if (paramTypes[i].isAssignableFrom(DataAccessObject.class)) { 1.66 paramValues[i] = dao; 1.67 } 1.68 if (paramTypes[i].isAssignableFrom(PathParameters.class)) { 1.69 @@ -179,9 +159,9 @@ 1.70 boolean paramsInjectible = true; 1.71 for (var param : method.getParameterTypes()) { 1.72 paramsInjectible &= HttpServletRequest.class.isAssignableFrom(param) 1.73 - || HttpServletResponse.class.isAssignableFrom(param) 1.74 - || PathParameters.class.isAssignableFrom(param) 1.75 - || DaoProvider.class.isAssignableFrom(param); 1.76 + || HttpServletResponse.class.isAssignableFrom(param) 1.77 + || PathParameters.class.isAssignableFrom(param) 1.78 + || DataAccessObject.class.isAssignableFrom(param); 1.79 } 1.80 if (paramsInjectible) { 1.81 try { 1.82 @@ -360,7 +340,7 @@ 1.83 * @return the retrieved entity or an empty optional if there is no such entity or the request parameter was missing 1.84 * @throws SQLException if the find function throws an exception 1.85 */ 1.86 - protected <T, R> Optional<R> findByParameter(HttpServletRequest req, Class<T> clazz, String name, SQLFindFunction<? super T, ? extends R> find) throws SQLException { 1.87 + protected <T, R> Optional<R> findByParameter(HttpServletRequest req, Class<T> clazz, String name, Function<? super T, ? extends R> find) { 1.88 final var param = getParameter(req, clazz, name); 1.89 if (param.isPresent()) { 1.90 return Optional.ofNullable(find.apply(param.get()));