summaryrefslogtreecommitdiff
path: root/sql-persistence/src
diff options
context:
space:
mode:
Diffstat (limited to 'sql-persistence/src')
-rw-r--r--sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlDao.java15
-rw-r--r--sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlSession.java1
2 files changed, 15 insertions, 1 deletions
diff --git a/sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlDao.java b/sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlDao.java
index c253229..361fd95 100644
--- a/sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlDao.java
+++ b/sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlDao.java
@@ -36,10 +36,19 @@ public abstract class SqlDao<Id, T, S extends SqlSession, Row> {
protected abstract T newEntity(Row row) throws SQLException;
protected List<T> runQuery(final String sql) throws SQLException {
+ return runQuery(new Preparator() {
+ @Override
+ public void prepare(PreparedStatement stmt) throws SQLException {
+ }
+ }, sql);
+ }
+
+ protected List<T> runQuery(final Preparator preparator, final String sql) throws SQLException {
return session.query(new SqlExecutor.QueryCommand<T>() {
@Override
public List<T> run(Connection c) throws SQLException {
try (PreparedStatement stmt = c.prepareStatement(sql)) {
+ preparator.prepare(stmt);
ResultSet rs = stmt.executeQuery();
List<Row> rows = new ArrayList<>();
@@ -47,7 +56,7 @@ public abstract class SqlDao<Id, T, S extends SqlSession, Row> {
rows.add(newRow(rs));
}
- List<T> entities = new ArrayList<T>(rows.size());
+ List<T> entities = new ArrayList<>(rows.size());
for (Row row : rows) {
entities.add(newEntity(row));
}
@@ -57,4 +66,8 @@ public abstract class SqlDao<Id, T, S extends SqlSession, Row> {
}
});
}
+
+ protected static interface Preparator {
+ void prepare(PreparedStatement stmt) throws SQLException;
+ }
}
diff --git a/sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlSession.java b/sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlSession.java
index b5e58eb..43f1206 100644
--- a/sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlSession.java
+++ b/sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlSession.java
@@ -6,6 +6,7 @@ import java.sql.Statement;
import java.util.List;
public class SqlSession {
+ // TODO: Make private
public final Connection c;
public SqlSession(Connection c) {