Skip to content
This repository was archived by the owner on May 3, 2022. It is now read-only.

ClusterInformation examples

Otávio Santana edited this page Mar 31, 2014 · 4 revisions

Simple Example

     ClusterInformation clusterInformation = ClusterInformation.create()
            .addHost(Constants.HOST)
            .withKeySpace(Constants.KEY_SPACE);
    EasyCassandraManager easyCassandraManager = new EasyCassandraManager(clusterInformation);

change the port

     ClusterInformation clusterInformation = ClusterInformation.create()
            .addHost(Constants.HOST)
            .withKeySpace(Constants.KEY_SPACE).withPort(9021);
    EasyCassandraManager easyCassandraManager = new EasyCassandraManager(clusterInformation);

with authorization

    ClusterInformation clusterInformation = ClusterInformation.create()
            .addHost(Constants.HOST)
            .withKeySpace(Constants.KEY_SPACE).withUser("user").withPassword("passWord");
    EasyCassandraManager easyCassandraManager = new EasyCassandraManager(clusterInformation);

if not exist create a keyspace with a custom query

    ClusterInformation clusterInformation = ClusterInformation.create()
            .addHost(Constants.HOST)
          .withKeySpace(Constants.KEY_SPACE).withReplicaStrategy(ReplicaStrategy.CUSTOM_STRATEGY).withCustomQuery(My_CUSTOM_QUERY);
    EasyCassandraManager easyCassandraManager = new EasyCassandraManager(clusterInformation);

if not exist create a keyspace with a SimpleStrategy with replica fator 3

   ClusterInformation clusterInformation = ClusterInformation.create()
            .addHost(Constants.HOST)
            .withKeySpace(Constants.KEY_SPACE).withReplicaStrategy(ReplicaStrategy.SIMPLES_TRATEGY).withReplicaFactor(3);
    EasyCassandraManager easyCassandraManager = new EasyCassandraManager(clusterInformation);

Or

    ClusterInformation clusterInformation = ClusterInformation.create()
            .addHost(Constants.HOST)
            .withKeySpace(Constants.KEY_SPACE).withReplicaFactor(3);
    EasyCassandraManager easyCassandraManager = new EasyCassandraManager(clusterInformation);

Will Create keyspace with a query:

     CREATE KEYSPACE IF NOT EXISTS javabahia WITH replication = {'class': 'SimpleStrategy' , 'replication_factor': 3};

if not exist create a keyspace with a NetworkTopologyStrategy with DC1 with replica factor 2 and DC2 replica factor 3.

     ClusterInformation clusterInformation = ClusterInformation.create()
            .addHost(Constants.HOST).withKeySpace(Constants.KEY_SPACE)
            .withReplicaStrategy(ReplicaStrategy.NETWORK_TOPOLOGY_STRATEGY)
            .addDataCenter("DC1", 2).addDataCenter("DC2", 3);
    EasyCassandraManager easyCassandraManager = new EasyCassandraManager(clusterInformation);

Will Create keyspace with a query:

     CREATE KEYSPACE IF NOT EXISTS javabahia WITH replication = {'class': 'NetworkTopologyStrategy'  , 'DC1' : 2,'DC2' : 3 };

Clone this wiki locally