fixes handler signatures and one compile error for AbstractDao.setForeignKeyOrNull()

Wed, 13 May 2020 18:31:52 +0200

author
Mike Becker <universe@uap-core.de>
date
Wed, 13 May 2020 18:31:52 +0200
changeset 40
276ef00a336d
parent 39
e722861558bb
child 41
4f1c026a8aab

fixes handler signatures and one compile error for AbstractDao.setForeignKeyOrNull()

src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java file | annotate | diff | comparison | revisions
src/main/java/de/uapcore/lightpit/dao/AbstractDao.java file | annotate | diff | comparison | revisions
src/main/java/de/uapcore/lightpit/modules/ErrorModule.java file | annotate | diff | comparison | revisions
src/main/java/de/uapcore/lightpit/modules/HomeModule.java file | annotate | diff | comparison | revisions
src/main/java/de/uapcore/lightpit/modules/LanguageModule.java file | annotate | diff | comparison | revisions
src/main/java/de/uapcore/lightpit/modules/VersionsModule.java file | annotate | diff | comparison | revisions
--- a/src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java	Tue May 12 22:03:00 2020 +0200
+++ b/src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java	Wed May 13 18:31:52 2020 +0200
@@ -168,7 +168,7 @@
                                 method.getName()
                         );
                     } else {
-                        LOG.warn("{} is annotated with {} but has the wrong parameters - (HttpServletRequest,HttpServletResponse) required",
+                        LOG.warn("{} is annotated with {} but has the wrong parameters - (HttpServletRequest,HttpServletResponse,DataAccessObjects) required",
                                 method.getName(), RequestMapping.class.getSimpleName()
                         );
                     }
--- a/src/main/java/de/uapcore/lightpit/dao/AbstractDao.java	Tue May 12 22:03:00 2020 +0200
+++ b/src/main/java/de/uapcore/lightpit/dao/AbstractDao.java	Wed May 13 18:31:52 2020 +0200
@@ -74,7 +74,7 @@
         }
     }
 
-    protected final void setForeignKeyOrNull(PreparedStatement stmt, int index, Object instance, Function<Object, Integer> keyGetter) throws SQLException {
+    protected final <T> void setForeignKeyOrNull(PreparedStatement stmt, int index, T instance, Function<? super T, Integer> keyGetter) throws SQLException {
         Integer key = Optional.ofNullable(instance).map(keyGetter).orElse(null);
         if (key == null) {
             stmt.setNull(index, Types.INTEGER);
--- a/src/main/java/de/uapcore/lightpit/modules/ErrorModule.java	Tue May 12 22:03:00 2020 +0200
+++ b/src/main/java/de/uapcore/lightpit/modules/ErrorModule.java	Wed May 13 18:31:52 2020 +0200
@@ -29,6 +29,7 @@
 package de.uapcore.lightpit.modules;
 
 import de.uapcore.lightpit.*;
+import de.uapcore.lightpit.dao.DataAccessObjects;
 
 import javax.servlet.annotation.WebServlet;
 import javax.servlet.http.HttpServletRequest;
@@ -51,7 +52,7 @@
 
     public static final String REQ_ATTR_ERROR_CODE = "errorCode";
 
-    private ResponseType handle(HttpServletRequest req, HttpServletResponse resp, int sc) {
+    private ResponseType handle(HttpServletRequest req, int sc) {
 
         req.setAttribute(REQ_ATTR_ERROR_CODE, sc);
         setStylesheet(req, "error");
@@ -61,17 +62,17 @@
     }
 
     @RequestMapping(requestPath = "404", method = HttpMethod.GET)
-    public ResponseType handle404(HttpServletRequest req, HttpServletResponse resp) {
-        return handle(req, resp, 404);
+    public ResponseType handle404(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) {
+        return handle(req, 404);
     }
 
     @RequestMapping(requestPath = "403", method = HttpMethod.GET)
-    public ResponseType handle403(HttpServletRequest req, HttpServletResponse resp) {
-        return handle(req, resp, 403);
+    public ResponseType handle403(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) {
+        return handle(req, 403);
     }
 
     @RequestMapping(requestPath = "500", method = HttpMethod.GET)
-    public ResponseType handle500(HttpServletRequest req, HttpServletResponse resp) {
-        return handle(req, resp, 500);
+    public ResponseType handle500(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) {
+        return handle(req, 500);
     }
 }
--- a/src/main/java/de/uapcore/lightpit/modules/HomeModule.java	Tue May 12 22:03:00 2020 +0200
+++ b/src/main/java/de/uapcore/lightpit/modules/HomeModule.java	Wed May 13 18:31:52 2020 +0200
@@ -29,6 +29,7 @@
 package de.uapcore.lightpit.modules;
 
 import de.uapcore.lightpit.*;
+import de.uapcore.lightpit.dao.DataAccessObjects;
 
 import javax.servlet.annotation.WebServlet;
 import javax.servlet.http.HttpServletRequest;
@@ -49,7 +50,7 @@
 public final class HomeModule extends AbstractLightPITServlet {
 
     @RequestMapping(method = HttpMethod.GET)
-    public ResponseType handle(HttpServletRequest req, HttpServletResponse resp) {
+    public ResponseType handle(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) {
 
         return ResponseType.HTML_FULL;
     }
--- a/src/main/java/de/uapcore/lightpit/modules/LanguageModule.java	Tue May 12 22:03:00 2020 +0200
+++ b/src/main/java/de/uapcore/lightpit/modules/LanguageModule.java	Wed May 13 18:31:52 2020 +0200
@@ -29,6 +29,7 @@
 package de.uapcore.lightpit.modules;
 
 import de.uapcore.lightpit.*;
+import de.uapcore.lightpit.dao.DataAccessObjects;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -85,7 +86,7 @@
     }
 
     @RequestMapping(method = HttpMethod.GET)
-    public ResponseType handle(HttpServletRequest req, HttpServletResponse resp) {
+    public ResponseType handle(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) {
 
         req.setAttribute("languages", languages);
         req.setAttribute("browserLanguage", req.getLocale());
@@ -96,7 +97,7 @@
     }
 
     @RequestMapping(method = HttpMethod.POST)
-    public ResponseType switchLanguage(HttpServletRequest req, HttpServletResponse resp) {
+    public ResponseType switchLanguage(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) {
 
         Optional<Locale> chosenLanguage = Optional.ofNullable(req.getParameter("language"))
                 .map(Locale::forLanguageTag)
@@ -105,6 +106,6 @@
         chosenLanguage.ifPresent((l) -> req.getSession().setAttribute(Constants.SESSION_ATTR_LANGUAGE, l));
         chosenLanguage.ifPresent(resp::setLocale);
 
-        return handle(req, resp);
+        return handle(req, resp, dao);
     }
 }
--- a/src/main/java/de/uapcore/lightpit/modules/VersionsModule.java	Tue May 12 22:03:00 2020 +0200
+++ b/src/main/java/de/uapcore/lightpit/modules/VersionsModule.java	Wed May 13 18:31:52 2020 +0200
@@ -29,6 +29,7 @@
 package de.uapcore.lightpit.modules;
 
 import de.uapcore.lightpit.*;
+import de.uapcore.lightpit.dao.DataAccessObjects;
 
 import javax.servlet.annotation.WebServlet;
 import javax.servlet.http.HttpServletRequest;
@@ -46,7 +47,7 @@
 )
 public final class VersionsModule extends AbstractLightPITServlet {
     @RequestMapping(method = HttpMethod.GET)
-    public ResponseType handle(HttpServletRequest req, HttpServletResponse resp) {
+    public ResponseType handle(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) {
 
         return ResponseType.HTML_FULL;
     }

mercurial