Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public final class ConnectionManager {
- private Session session;
- private Cluster cluster;
- private String keySpace;
- private String contactPoint;
- private Integer replicationFactor;
- public ConnectionManager setContactPoint(String contactPoint) {
- this.contactPoint = contactPoint;
- this.replicationFactor = 1;
- return this;
- }
- public ConnectionManager setKeySpace(String keySpace) {
- this.keySpace = keySpace;
- return this;
- }
- public ConnectionManager setReplicationFactor(Integer replicationFactor) {
- this.replicationFactor = replicationFactor;
- return this;
- }
- public ConnectionManager buildConnection() {
- CodecRegistry codecRegistry = new CodecRegistry();
- cluster = Cluster.builder()
- .addContactPoint(this.contactPoint)
- .withCodecRegistry(codecRegistry)
- .withoutJMXReporting()
- .build();
- Session s = cluster.connect();
- SimpleStatement statement = SchemaBuilder
- .createKeyspace(this.keySpace)
- .ifNotExists()
- .withSimpleStrategy(this.replicationFactor)
- .build();
- s.execute(statement.getQuery());
- session = cluster.connect(this.keySpace);
- return this;
- }
- public Session getSession() {
- return this.session;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement