Skip to content

Commit 1873f25

Browse files
add JdbcTemplate
1 parent 29dce74 commit 1873f25

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/DefaultJdbcClient.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,25 @@ public DefaultJdbcClient(NamedParameterJdbcOperations jdbcTemplate) {
8383
this.namedParamOps = jdbcTemplate;
8484
}
8585

86+
/**
87+
* Expose the classic Spring JdbcTemplate to allow invocation of
88+
* classic JDBC operations.
89+
*/
90+
@Override
91+
public JdbcOperations getJdbcOperations() {
92+
return this.classicOps;
93+
}
94+
95+
/**
96+
* Expose the classic Spring {@link JdbcTemplate} itself, if available,
97+
* in particular for passing it on to other {@code JdbcTemplate} consumers.
98+
* <p>If sufficient for the purposes at hand, {@link #getJdbcOperations()}
99+
* is recommended over this variant.
100+
*/
101+
public JdbcTemplate getJdbcTemplate() {
102+
Assert.state(this.classicOps instanceof JdbcTemplate, "No JdbcTemplate available");
103+
return (JdbcTemplate) this.classicOps;
104+
}
86105

87106
@Override
88107
public StatementSpec sql(String sql) {

spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/JdbcClient.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import org.springframework.dao.support.DataAccessUtils;
3030
import org.springframework.jdbc.core.JdbcOperations;
31+
import org.springframework.jdbc.core.JdbcTemplate;
3132
import org.springframework.jdbc.core.ResultSetExtractor;
3233
import org.springframework.jdbc.core.RowCallbackHandler;
3334
import org.springframework.jdbc.core.RowMapper;
@@ -76,6 +77,19 @@ public interface JdbcClient {
7677
*/
7778
StatementSpec sql(String sql);
7879

80+
/**
81+
* Expose the classic Spring JdbcTemplate to allow invocation of
82+
* classic JDBC operations.
83+
*/
84+
JdbcOperations getJdbcOperations();
85+
86+
/**
87+
* Expose the classic Spring {@link JdbcTemplate} itself, if available,
88+
* in particular for passing it on to other {@code JdbcTemplate} consumers.
89+
* <p>If sufficient for the purposes at hand, {@link #getJdbcOperations()}
90+
* is recommended over this variant.
91+
*/
92+
JdbcTemplate getJdbcTemplate();
7993

8094
// Static factory methods
8195

0 commit comments

Comments
 (0)