Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ab82458eb | ||
|
|
515570f057 | ||
|
|
8dba178348 | ||
|
|
4574c841d8 | ||
|
|
c4d459c461 |
@@ -5,7 +5,7 @@ plugins {
|
||||
}
|
||||
|
||||
group 'ru.di9'
|
||||
version '1.9.1'
|
||||
version '1.9.2'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
||||
@@ -15,10 +15,10 @@ public interface JdbcTemplate {
|
||||
<T> T query(@Language("GenericSQL") String sql, ResultSetExtractor<T> rse) throws DataAccessException;
|
||||
|
||||
<T> T query(@Language("GenericSQL") String sql, PreparedStatementProcessor psp, ResultSetExtractor<T> rse)
|
||||
throws DataAccessException;
|
||||
throws DataAccessException;
|
||||
|
||||
<T> Optional<T> queryOne(@Language("GenericSQL") String sql, ResultSetExtractor<T> rse)
|
||||
throws DataAccessException;
|
||||
throws DataAccessException;
|
||||
|
||||
<T> Optional<T> queryOne(@Language("GenericSQL") String sql, PreparedStatementProcessor psp,
|
||||
ResultSetExtractor<T> rse) throws DataAccessException;
|
||||
@@ -34,5 +34,5 @@ public interface JdbcTemplate {
|
||||
|
||||
void transaction(Consumer<JdbcTemplate> consumer);
|
||||
|
||||
void update(@Language("GenericSQL") String sql, PreparedStatementProcessor psp);
|
||||
void update(@Language("GenericSQL") String sql, PreparedStatementProcessor psp) throws DataAccessException;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package ru.di9.jdbc;
|
||||
|
||||
import org.intellij.lang.annotations.Language;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.*;
|
||||
@@ -50,13 +51,14 @@ public class JdbcTemplateImpl implements JdbcTemplate {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public <T> T query(@Language("GenericSQL") String sql, PreparedStatementProcessor psp,
|
||||
ResultSetExtractor<T> rse) throws DataAccessException {
|
||||
try (Connection connection = dataSource.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||
psp.process(preparedStatement);
|
||||
try (ResultSet resultSet = preparedStatement.executeQuery()) {
|
||||
return resultSet.next() ? rse.extractData(resultSet) : null;
|
||||
return rse.extractData(resultSet);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw throwDataAccessException(sql, e);
|
||||
@@ -146,7 +148,7 @@ public class JdbcTemplateImpl implements JdbcTemplate {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(String sql, PreparedStatementProcessor psp) {
|
||||
public void update(String sql, PreparedStatementProcessor psp) throws DataAccessException {
|
||||
try (PreparedStatement statement = dataSource.getConnection().prepareStatement(sql)){
|
||||
psp.process(statement);
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ public class JdbcTemplateTransactional implements JdbcTemplate, AutoCloseable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(String sql, PreparedStatementProcessor psp) {
|
||||
public void update(String sql, PreparedStatementProcessor psp) throws DataAccessException {
|
||||
try (PreparedStatement statement = connection.prepareStatement(sql)) {
|
||||
psp.process(statement);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user