use of com.datastax.driver.core.Metadata in project javaee7-samples by javaee-samples.
the class PersonSessionBean method initDB.
@PostConstruct
private void initDB() {
cluster = Cluster.builder().addContactPoint("localhost").build();
Metadata metadata = cluster.getMetadata();
System.out.printf("Connected to cluster: %s\n", metadata.getClusterName());
for (Host host : metadata.getAllHosts()) {
System.out.printf("Datacenter: %s; Host: %s; Rack: %s\n", host.getDatacenter(), host.getAddress(), host.getRack());
}
session = cluster.connect();
session.execute("CREATE KEYSPACE IF NOT EXISTS test WITH replication " + "= {'class':'SimpleStrategy', 'replication_factor':1};");
session.execute("CREATE TABLE IF NOT EXISTS test.person (" + "name text PRIMARY KEY," + "age int" + ");");
selectAllPersons = session.prepare("SELECT * FROM test.person");
insertPerson = session.prepare("INSERT INTO test.person (name, age) VALUES (?, ?);");
}
use of com.datastax.driver.core.Metadata in project GNS by MobilityFirst.
the class CassandraRecords method connect.
private void connect(String node) {
cluster = Cluster.builder().addContactPoint(node).build();
Metadata metadata = cluster.getMetadata();
DatabaseConfig.getLogger().log(Level.INFO, "Connected to cluster: {0}", metadata.getClusterName());
for (Host host : metadata.getAllHosts()) {
DatabaseConfig.getLogger().log(Level.INFO, "Datacenter: {0} Host: {1} Rack: {2}", new Object[] { host.getDatacenter(), host.getAddress(), host.getRack() });
}
session = cluster.connect();
}
use of com.datastax.driver.core.Metadata in project smscgateway by RestComm.
the class DBOperations method stop.
public void stop() throws Exception {
if (!this.started)
return;
if (cluster != null && !cluster.isClosed()) {
Metadata metadata = cluster.getMetadata();
cluster.close();
logger.info(String.format("Disconnected from cluster: %s\n", metadata.getClusterName()));
}
this.started = false;
}
use of com.datastax.driver.core.Metadata in project smscgateway by RestComm.
the class PersistenceProxy method testCassandraAccess.
// public void setKeyspace(Keyspace val) {
// this.keyspace = val;
// }
//
// public Keyspace getKeyspace() {
// return this.keyspace;
// }
public boolean testCassandraAccess() {
String ip = "127.0.0.1";
String keyspace = "RestCommSMSC";
try {
// dbOperations = DBOperations.getInstance();
Cluster cluster = Cluster.builder().addContactPoint(ip).build();
Metadata metadata = cluster.getMetadata();
for (Host host : metadata.getAllHosts()) {
logger.info(String.format("Datacenter: %s; Host: %s; Rack: %s\n", host.getDatacenter(), host.getAddress(), host.getRack()));
}
Session session = cluster.connect();
session.execute("USE \"" + keyspace + "\"");
PreparedStatement ps = session.prepare("select * from \"" + Schema.FAMILY_SMPP_SMS_ROUTING_RULE + "\" limit 1;");
BoundStatement boundStatement = new BoundStatement(ps);
boundStatement.bind();
session.execute(boundStatement);
return true;
} catch (Exception e) {
return false;
}
}
use of com.datastax.driver.core.Metadata in project smscgateway by RestComm.
the class NN_DBOper method stop.
public void stop() throws Exception {
if (!this.started)
return;
cluster.close();
// cluster.shutdown();
Metadata metadata = cluster.getMetadata();
logger.info(String.format("Disconnected from cluster: %s\n", metadata.getClusterName()));
this.started = false;
}
Aggregations