Skip to content

Commit 11d5349

Browse files
author
Sylvain Lebresne
committed
Add logged keyspace getter in Session
JAVA-249 #fixes
1 parent 342de12 commit 11d5349

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

driver-core/CHANGELOG.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ CHANGELOG
44
1.0.6:
55
------
66

7+
- [new] Added Session#prepareAsync calls (JAVA-224)
8+
- [new] Added Cluster#getLoggedKeyspace (JAVA-249)
79
- [improvement] Make most main objects interface to facilitate testing/mocking (JAVA-195)
810
- [improvement] Avoid preparing a statement multiple time per host with multiple sessions
9-
- [improvement] Adds Session#prepareAsync calls (JAVA-224)
1011
- [bug] Fix potential thread leaks when shutting down Metrics (JAVA-232)
1112
- [bug] Fix potential NPE in HostConnectionPool (JAVA-231)
1213
- [bug] Make sure connections are returned to the right pools (JAVA-255)

driver-core/src/main/java/com/datastax/driver/core/Session.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@
3636
*/
3737
public interface Session {
3838

39+
/**
40+
* The keyspace to which this Session is currently logged in, if any.
41+
* <p>
42+
* This correspond to the name passed to {@link Cluster#connect(String)}, or to the
43+
* last keyspace logged into through a "USE" CQL query if one was used.
44+
*
45+
* @return the name of the keyspace to which this Session is currently
46+
* logged in, or {@code null} if the session is logged to no keyspace.
47+
*/
48+
public String getLoggedKeyspace();
49+
3950
/**
4051
* Executes the provided query.
4152
*

driver-core/src/main/java/com/datastax/driver/core/SessionManager.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ class SessionManager implements Session {
6767
}
6868
}
6969

70+
public String getLoggedKeyspace() {
71+
return poolsState.keyspace;
72+
}
73+
7074
public ResultSet execute(String query) {
7175
return execute(new SimpleStatement(query));
7276
}
@@ -299,7 +303,7 @@ void setKeyspace(String keyspace) {
299303
long timeout = configuration().getSocketOptions().getConnectTimeoutMillis();
300304
try {
301305
Future<?> future = executeQuery(new QueryMessage("use " + keyspace, ConsistencyLevel.DEFAULT_CASSANDRA_CL), Query.DEFAULT);
302-
// Note: using the connection timeout is perfectly correct, we should probably change that someday
306+
// Note: using the connection timeout isn't perfectly correct, we should probably change that someday
303307
Uninterruptibles.getUninterruptibly(future, timeout, TimeUnit.MILLISECONDS);
304308
} catch (TimeoutException e) {
305309
throw new DriverInternalError(String.format("No responses after %d milliseconds while setting current keyspace. This should not happen, unless you have setup a very low connection timeout.", timeout));

0 commit comments

Comments
 (0)