Elffuss BraidHub

kikocis/java-driver public

Add logged keyspace getter in Session

JAVA-249 #fixes
Changeset6ec239cc86dc43436b68736285d02e0b8ec18c72e86ed3a69e69e1cf68cf5fb4
AuthorSylvain Lebresne <sylvain@datastax.com> · 2014-02-18 16:32 +01:00
CommitterSylvain Lebresne <sylvain@datastax.com> · 2014-02-18 16:32 +01:00
Parentsc628d3c56e18

Browse the files at this changeset

3 files changed

modified driver-core/CHANGELOG.rst +2 −1
@@ -4,9 +4,10 @@
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)
modified driver-core/src/main/java/com/datastax/driver/core/Session.java +11 −0
@@ -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 *
modified driver-core/src/main/java/com/datastax/driver/core/SessionManager.java +5 −1
@@ -67,6 +67,10 @@
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 @@
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));