Skip to content

Poolable statement hint #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/org/tarantool/jdbc/SQLPreparedStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public SQLPreparedStatement(SQLConnection connection, String sql) throws SQLExce
super(connection);
this.sql = sql;
this.parameters = new HashMap<>();
setPoolable(true);
}

public SQLPreparedStatement(SQLConnection connection,
Expand All @@ -51,6 +52,7 @@ public SQLPreparedStatement(SQLConnection connection,
super(connection, resultSetType, resultSetConcurrency, resultSetHoldability);
this.sql = sql;
this.parameters = new HashMap<>();
setPoolable(true);
}

@Override
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/org/tarantool/jdbc/SQLStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ public class SQLStatement implements TarantoolStatement {
*/
private long timeout;

/**
* Hint to the statement pool implementation indicating
* whether the application wants the statement to be pooled.
*
* Ignored.
*/
private boolean poolable;

private final AtomicBoolean isClosed = new AtomicBoolean(false);

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

@Override
public void setPoolable(boolean poolable) throws SQLException {
throw new SQLFeatureNotSupportedException();
checkNotClosed();
this.poolable = poolable;
}

@Override
public boolean isPoolable() throws SQLException {
throw new SQLFeatureNotSupportedException();
checkNotClosed();
return poolable;
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/org/tarantool/jdbc/JdbcPreparedStatementIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,14 @@ public void testExecuteStringBatchQuery() throws Exception {
assertThrows(SQLException.class, () -> prep.addBatch("INSERT INTO test(id, val) VALUES (1, 'one')"));
}

@Test
void testPoolableStatus() throws SQLException {
prep = conn.prepareStatement("SELECT val FROM test WHERE id = ?");
assertTrue(prep.isPoolable());
prep.setPoolable(false);
assertFalse(prep.isPoolable());
}

private List<?> consoleSelect(Object key) {
List<?> list = testHelper.evaluate(TestUtils.toLuaSelect("TEST", key));
return list == null ? Collections.emptyList() : (List<?>) list.get(0);
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/org/tarantool/jdbc/JdbcStatementIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,13 @@ public void testExecuteResultSetBatchQuery() throws Exception {
assertEquals("six", consoleSelect(6).get(1));
}

@Test
void testPoolableStatus() throws SQLException {
assertFalse(stmt.isPoolable());
stmt.setPoolable(true);
assertTrue(stmt.isPoolable());
}

private List<?> consoleSelect(Object key) {
List<?> list = testHelper.evaluate(TestUtils.toLuaSelect("TEST", key));
return list == null ? Collections.emptyList() : (List<?>) list.get(0);
Expand Down