Plugin for setting parameters of custom types (eg. Joda time, etc..)
8 | *
9 | * Note: Support for java.time is implemented by Fluent-Jdbc by default
10 | */
11 | @FunctionalInterface
12 | public interface ParamSetter {
13 | void set(T param, PreparedStatement statement, Integer index) throws SQLException;
14 | }
15 |
--------------------------------------------------------------------------------
/fluent-jdbc/src/main/java/org/codejargon/fluentjdbc/api/integration/ConnectionProvider.java:
--------------------------------------------------------------------------------
1 | package org.codejargon.fluentjdbc.api.integration;
2 |
3 | import java.sql.SQLException;
4 |
5 | /**
6 | *
7 | * Provides Connections to FluentJdbc Queries. It allows both acquiring and releasing a Connection.
8 | * This makes it possible to integrate FluentJdbc to most pooling / transaction management solutions.
9 | *
10 | *
11 | * Implementation pattern
12 | *
13 | * query -> {
14 | * Connection connection = ... // acquire a connection
15 | * query.receive(connection) // make the connection available to FluentJdbc queries
16 | * connection.close() // release connection - may not be needed if connection is already managed
17 | * }
18 | *
19 | *
20 | *
21 | * Example implementations:
22 | *
23 | *
24 | *
25 | * Getting connection from a datasource (provided in the library as DataSourceConnectionProvider):
26 | *
27 | *
28 | *
29 | * query -> {
30 | * try(Connection connection = dataSource.getConnection()) {
31 | * query.receive(connection);
32 | * }
33 | * }
34 | *
35 | *
36 | *
37 | * Getting connection from a callback mechanism (eg Spring JdbcOperations/JdbcTemplate):
38 | *
39 | *
40 | *
41 | * query -> {
42 | * jdbcTemplate.execute(connection -> {
43 | * query.receive(connection);
44 | * });
45 | * }
46 | *
47 | *
48 | */
49 | @FunctionalInterface
50 | public interface ConnectionProvider {
51 | void provide(QueryConnectionReceiver query) throws SQLException;
52 | }
53 |
--------------------------------------------------------------------------------
/fluent-jdbc/src/main/java/org/codejargon/fluentjdbc/api/integration/QueryConnectionReceiver.java:
--------------------------------------------------------------------------------
1 | package org.codejargon.fluentjdbc.api.integration;
2 |
3 | import java.sql.Connection;
4 | import java.sql.SQLException;
5 |
6 | /**
7 | * Fluent-Jdbc queries receive the connections from this interface. Should be called in ConnectionProvider implementations,
8 | * no need to implement it for integrations.
9 | */
10 | @FunctionalInterface
11 | public interface QueryConnectionReceiver {
12 | void receive(Connection connection) throws SQLException;
13 | }
14 |
--------------------------------------------------------------------------------
/fluent-jdbc/src/main/java/org/codejargon/fluentjdbc/api/integration/providers/DataSourceConnectionProvider.java:
--------------------------------------------------------------------------------
1 | package org.codejargon.fluentjdbc.api.integration.providers;
2 |
3 | import org.codejargon.fluentjdbc.api.integration.QueryConnectionReceiver;
4 | import org.codejargon.fluentjdbc.api.integration.ConnectionProvider;
5 |
6 | import javax.sql.DataSource;
7 | import java.sql.Connection;
8 | import java.sql.SQLException;
9 |
10 | /**
11 | * ConnectionProvider based on a DataSource.
12 | */
13 | public class DataSourceConnectionProvider implements ConnectionProvider {
14 | private final DataSource dataSource;
15 |
16 | public DataSourceConnectionProvider(DataSource dataSource) {
17 | this.dataSource = dataSource;
18 | }
19 |
20 | @Override
21 | public void provide(QueryConnectionReceiver query) throws SQLException {
22 | try(Connection connection = dataSource.getConnection()) {
23 | query.receive(connection);
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/fluent-jdbc/src/main/java/org/codejargon/fluentjdbc/api/mapper/Mappers.java:
--------------------------------------------------------------------------------
1 | package org.codejargon.fluentjdbc.api.mapper;
2 |
3 | import org.codejargon.fluentjdbc.api.query.Mapper;
4 |
5 | import java.math.BigDecimal;
6 | import java.sql.Blob;
7 | import java.sql.ResultSetMetaData;
8 | import java.util.Collections;
9 | import java.util.LinkedHashMap;
10 | import java.util.Map;
11 |
12 | /**
13 | * A set of common mappers for convenience.
14 | * @see org.codejargon.fluentjdbc.api.mapper.ObjectMappers
15 | */
16 | public abstract class Mappers {
17 | private static final Mapper singleInteger = (rs) -> rs.getInt(1);
18 | private static final Mapper singleLong = (rs) -> rs.getLong(1);
19 | private static final Mapper singleString = (rs) -> rs.getString(1);
20 | private static final Mapper singleBigDecimal = (rs) -> rs.getBigDecimal(1);
21 | private static final Mapper singleBoolean = (rs) -> rs.getBoolean(1);
22 | private static final Mapper