Created
October 14, 2015 23:01
-
-
Save zznate/e3db151242ce1d4c20bf to your computer and use it in GitHub Desktop.
Example of a "Component" or "Resource" controlling Cassandra access
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyClusterManager { | |
private Session session; | |
private Cluster cluster; | |
@javax.annotation.PostConstruct | |
public void init() throws IOException | |
{ | |
cluster = createCluster(); // private method that builds a cluster | |
session = createSession(); // private method that builds a session | |
} | |
@javax.annotation.PreDestroy | |
public void shutdown() throws IOException | |
{ | |
session.close(); | |
cluster.close(); | |
} | |
// Expose block-and-tackle operations thusly: | |
@Override | |
public ResultSet execute(final Statement boundStatement) | |
{ | |
return session.execute(boundStatement); | |
} | |
@Override | |
public ResultSetFuture executeAsync(final Statement boundStatement) | |
{ | |
return session.executeAsync(boundStatement); | |
} | |
@Override | |
public PreparedStatement prepare(final String statement) | |
{ | |
return session.prepare(statement); | |
} | |
@Override | |
public ResultSet execute(final String statement) | |
{ | |
return session.execute(statement); | |
} | |
@Override | |
public Metadata getMetadata() | |
{ | |
return cluster.getMetadata(); | |
} | |
//... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment