src/main/java/de/uapcore/lightpit/dao/Functions.java

changeset 62
833e0385572a
parent 47
57cfb94ab99f
child 138
e2aa673dd473
     1.1 --- a/src/main/java/de/uapcore/lightpit/dao/Functions.java	Sun May 17 16:38:04 2020 +0200
     1.2 +++ b/src/main/java/de/uapcore/lightpit/dao/Functions.java	Mon May 18 21:05:57 2020 +0200
     1.3 @@ -28,6 +28,7 @@
     1.4   */
     1.5  package de.uapcore.lightpit.dao;
     1.6  
     1.7 +import java.sql.Date;
     1.8  import java.sql.PreparedStatement;
     1.9  import java.sql.SQLException;
    1.10  import java.sql.Types;
    1.11 @@ -47,6 +48,14 @@
    1.12          }
    1.13      }
    1.14  
    1.15 +    public static void setDateOrNull(PreparedStatement stmt, int index, Date date) throws SQLException {
    1.16 +        if (date == null) {
    1.17 +            stmt.setNull(index, Types.DATE);
    1.18 +        } else {
    1.19 +            stmt.setDate(index, date);
    1.20 +        }
    1.21 +    }
    1.22 +
    1.23      public static <T> void setForeignKeyOrNull(PreparedStatement stmt, int index, T instance, Function<? super T, Integer> keyGetter) throws SQLException {
    1.24          Integer key = Optional.ofNullable(instance).map(keyGetter).orElse(null);
    1.25          if (key == null) {

mercurial