Search in sources :

Example 1 with Metadata

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 (?, ?);");
}
Also used : Metadata(com.datastax.driver.core.Metadata) Host(com.datastax.driver.core.Host) PostConstruct(javax.annotation.PostConstruct)

Example 2 with Metadata

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();
}
Also used : Metadata(com.datastax.driver.core.Metadata) Host(com.datastax.driver.core.Host)

Example 3 with Metadata

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;
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) Metadata(com.datastax.driver.core.Metadata) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata)

Example 4 with Metadata

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;
    }
}
Also used : Metadata(com.datastax.driver.core.Metadata) Cluster(com.datastax.driver.core.Cluster) Host(com.datastax.driver.core.Host) PreparedStatement(com.datastax.driver.core.PreparedStatement) BoundStatement(com.datastax.driver.core.BoundStatement) Session(com.datastax.driver.core.Session)

Example 5 with Metadata

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;
}
Also used : Metadata(com.datastax.driver.core.Metadata)

Aggregations

Metadata (com.datastax.driver.core.Metadata)20 Host (com.datastax.driver.core.Host)13 Cluster (com.datastax.driver.core.Cluster)9 Session (com.datastax.driver.core.Session)6 Builder (com.datastax.driver.core.Cluster.Builder)4 KeyspaceMetadata (com.datastax.driver.core.KeyspaceMetadata)4 BoundStatement (com.datastax.driver.core.BoundStatement)3 PreparedStatement (com.datastax.driver.core.PreparedStatement)3 TableMetadata (com.datastax.driver.core.TableMetadata)3 InvalidQueryException (com.datastax.driver.core.exceptions.InvalidQueryException)3 ProtocolVersion (com.datastax.driver.core.ProtocolVersion)2 IOException (java.io.IOException)2 InetSocketAddress (java.net.InetSocketAddress)2 Date (java.util.Date)2 SSLContext (javax.net.ssl.SSLContext)2 XMLStreamException (javolution.xml.stream.XMLStreamException)2 PersistenceException (org.mobicents.smsc.cassandra.PersistenceException)2 PoolingOptions (com.datastax.driver.core.PoolingOptions)1 QueryOptions (com.datastax.driver.core.QueryOptions)1 SSLOptions (com.datastax.driver.core.SSLOptions)1