Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4829deb

Browse files
committedJul 5, 2019
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 b53e0ba commit 4829deb

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed
 

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ public class SQLPreparedStatement extends SQLStatement implements PreparedStatem
3232
final String sql;
3333
final Map<Integer, Object> params;
3434

35-
3635
public SQLPreparedStatement(SQLConnection connection, String sql) throws SQLException {
3736
super(connection);
3837
this.sql = sql;
3938
this.params = new HashMap<>();
39+
setPoolable(true);
4040
}
4141

4242
public SQLPreparedStatement(SQLConnection connection,
@@ -47,6 +47,7 @@ public SQLPreparedStatement(SQLConnection connection,
4747
super(connection, resultSetType, resultSetConcurrency, resultSetHoldability);
4848
this.sql = sql;
4949
this.params = new HashMap<>();
50+
setPoolable(true);
5051
}
5152

5253
@Override

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ public class SQLStatement implements TarantoolStatement {
4444
*/
4545
private long timeout;
4646

47+
/**
48+
* Hint to the statement pool implementation indicating
49+
* whether the application wants the statement to be pooled.
50+
*
51+
* Ignored.
52+
*/
53+
private boolean poolable;
54+
4755
private final AtomicBoolean isClosed = new AtomicBoolean(false);
4856

4957
protected SQLStatement(SQLConnection sqlConnection) throws SQLException {
@@ -312,12 +320,14 @@ public boolean isClosed() throws SQLException {
312320

313321
@Override
314322
public void setPoolable(boolean poolable) throws SQLException {
315-
throw new SQLFeatureNotSupportedException();
323+
checkNotClosed();
324+
this.poolable = poolable;
316325
}
317326

318327
@Override
319328
public boolean isPoolable() throws SQLException {
320-
throw new SQLFeatureNotSupportedException();
329+
checkNotClosed();
330+
return poolable;
321331
}
322332

323333
/**

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,14 @@ public void testMoreResultsButKeepCurrent() throws SQLException {
322322
assertEquals(-1, prep.getUpdateCount());
323323
}
324324

325+
@Test
326+
void testPoolableStatus() throws SQLException {
327+
prep = conn.prepareStatement("SELECT val FROM test WHERE id = ?");
328+
assertTrue(prep.isPoolable());
329+
prep.setPoolable(false);
330+
assertFalse(prep.isPoolable());
331+
}
332+
325333
private List<?> consoleSelect(Object key) {
326334
List<?> list = testHelper.evaluate(TestUtils.toLuaSelect("TEST", key));
327335
return list == null ? Collections.emptyList() : (List<?>) list.get(0);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,13 @@ public void testMoreResultsButKeepCurrent() throws SQLException {
421421
assertEquals(-1, stmt.getUpdateCount());
422422
}
423423

424+
@Test
425+
void testPoolableStatus() throws SQLException {
426+
assertFalse(stmt.isPoolable());
427+
stmt.setPoolable(true);
428+
assertTrue(stmt.isPoolable());
429+
}
430+
424431
private List<?> consoleSelect(Object key) {
425432
List<?> list = testHelper.evaluate(TestUtils.toLuaSelect("TEST", key));
426433
return list == null ? Collections.emptyList() : (List<?>) list.get(0);

0 commit comments

Comments
 (0)
Please sign in to comment.