Skip to content

Commit fa0bc3f

Browse files
committed
Poolable statement hint
Implement corresponding API related to poolable statements. This hint is ignored and used to be compatible with the API. Closes: #181
1 parent cdc0505 commit fa0bc3f

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

src/main/java/org/tarantool/jdbc/SQLPreparedStatement.java

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public SQLPreparedStatement(SQLConnection connection, String sql) throws SQLExce
4141
super(connection);
4242
this.sql = sql;
4343
this.parameters = new HashMap<>();
44+
setPoolable(true);
4445
}
4546

4647
public SQLPreparedStatement(SQLConnection connection,
@@ -51,6 +52,7 @@ public SQLPreparedStatement(SQLConnection connection,
5152
super(connection, resultSetType, resultSetConcurrency, resultSetHoldability);
5253
this.sql = sql;
5354
this.parameters = new HashMap<>();
55+
setPoolable(true);
5456
}
5557

5658
@Override

src/main/java/org/tarantool/jdbc/SQLStatement.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ public class SQLStatement implements TarantoolStatement {
5050
*/
5151
private long timeout;
5252

53+
/**
54+
* Hint to the statement pool implementation indicating
55+
* whether the application wants the statement to be pooled.
56+
*
57+
* Ignored.
58+
*/
59+
private boolean poolable;
60+
5361
private final AtomicBoolean isClosed = new AtomicBoolean(false);
5462

5563
protected SQLStatement(SQLConnection sqlConnection) throws SQLException {
@@ -329,12 +337,14 @@ public boolean isClosed() throws SQLException {
329337

330338
@Override
331339
public void setPoolable(boolean poolable) throws SQLException {
332-
throw new SQLFeatureNotSupportedException();
340+
checkNotClosed();
341+
this.poolable = poolable;
333342
}
334343

335344
@Override
336345
public boolean isPoolable() throws SQLException {
337-
throw new SQLFeatureNotSupportedException();
346+
checkNotClosed();
347+
return poolable;
338348
}
339349

340350
/**

src/test/java/org/tarantool/jdbc/JdbcPreparedStatementIT.java

+8
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,14 @@ public void testExecuteStringBatchQuery() throws Exception {
477477
assertThrows(SQLException.class, () -> prep.addBatch("INSERT INTO test(id, val) VALUES (1, 'one')"));
478478
}
479479

480+
@Test
481+
void testPoolableStatus() throws SQLException {
482+
prep = conn.prepareStatement("SELECT val FROM test WHERE id = ?");
483+
assertTrue(prep.isPoolable());
484+
prep.setPoolable(false);
485+
assertFalse(prep.isPoolable());
486+
}
487+
480488
private List<?> consoleSelect(Object key) {
481489
List<?> list = testHelper.evaluate(TestUtils.toLuaSelect("TEST", key));
482490
return list == null ? Collections.emptyList() : (List<?>) list.get(0);

src/test/java/org/tarantool/jdbc/JdbcStatementIT.java

+7
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,13 @@ public void testExecuteResultSetBatchQuery() throws Exception {
527527
assertEquals("six", consoleSelect(6).get(1));
528528
}
529529

530+
@Test
531+
void testPoolableStatus() throws SQLException {
532+
assertFalse(stmt.isPoolable());
533+
stmt.setPoolable(true);
534+
assertTrue(stmt.isPoolable());
535+
}
536+
530537
private List<?> consoleSelect(Object key) {
531538
List<?> list = testHelper.evaluate(TestUtils.toLuaSelect("TEST", key));
532539
return list == null ? Collections.emptyList() : (List<?>) list.get(0);

0 commit comments

Comments
 (0)