-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d8f2f7
commit 1ce68ad
Showing
16 changed files
with
179 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
/.classpath | ||
/bin/ | ||
/.settings/org.eclipse.buildship.core.prefs | ||
/.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/org/itsallcode/jdbc/dialect/ColumnValueSetter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.itsallcode.jdbc.dialect; | ||
|
||
import java.sql.PreparedStatement; | ||
import java.sql.SQLException; | ||
|
||
public interface ColumnValueSetter<T> { | ||
|
||
void setObject(PreparedStatement stmt, int parameterIndex, T object) throws SQLException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.itsallcode.jdbc.dialect; | ||
|
||
import java.sql.PreparedStatement; | ||
import java.time.*; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
public final class Setters { | ||
private Setters() { | ||
} | ||
|
||
public static <T> ColumnValueSetter<T> generic() { | ||
return PreparedStatement::setObject; | ||
} | ||
|
||
static ColumnValueSetter<LocalDate> localDateToString() { | ||
return (final PreparedStatement stmt, final int parameterIndex, final LocalDate date) -> stmt | ||
.setString(parameterIndex, date.toString()); | ||
} | ||
|
||
public static ColumnValueSetter<Instant> instantToString(final DateTimeFormatter dateTimeFormatter, | ||
final ZoneId timeZone) { | ||
return (final PreparedStatement stmt, final int parameterIndex, final Instant instant) -> stmt | ||
.setString(parameterIndex, dateTimeFormatter.format(LocalDateTime.ofInstant(instant, timeZone))); | ||
} | ||
|
||
public static ColumnValueSetter<LocalDateTime> localDateTimeToString(final DateTimeFormatter dateTimeFormatter) { | ||
return (final PreparedStatement stmt, final int parameterIndex, final LocalDateTime localDateTime) -> stmt | ||
.setString(parameterIndex, dateTimeFormatter.format(localDateTime)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/org/itsallcode/jdbc/statement/ParamSetterProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.itsallcode.jdbc.statement; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.itsallcode.jdbc.dialect.*; | ||
|
||
public class ParamSetterProvider { | ||
private static final ColumnValueSetter<Object> GENERIC_SETTER = Setters.generic(); | ||
private final DbDialect dialect; | ||
private final Map<Class<?>, ColumnValueSetter<Object>> setters = new HashMap<>(); | ||
|
||
public ParamSetterProvider(final DbDialect dialect) { | ||
this.dialect = dialect; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
ColumnValueSetter<Object> findSetter(final Object object) { | ||
if (object == null) { | ||
return GENERIC_SETTER; | ||
} | ||
return setters.computeIfAbsent(object.getClass(), | ||
type -> (ColumnValueSetter<Object>) dialect.createSetter(type)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 0 additions & 32 deletions
32
src/test/java/org/itsallcode/jdbc/ParameterMapperTest.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.