Search in sources :

Example 1 with CreateKeyspace

use of com.datastax.driver.core.schemabuilder.CreateKeyspace in project hop by apache.

the class DriverConnection method createKeyspace.

@Override
public void createKeyspace(String keyspaceName, boolean ifNotExists, Map<String, Object> createOptions) throws Exception {
    CreateKeyspace create = SchemaBuilder.createKeyspace(keyspaceName).ifNotExists();
    create.with().replication(createOptions);
}
Also used : CreateKeyspace(com.datastax.driver.core.schemabuilder.CreateKeyspace)

Example 2 with CreateKeyspace

use of com.datastax.driver.core.schemabuilder.CreateKeyspace in project scalardb by scalar-labs.

the class CassandraAdmin method createNamespace.

@Override
public void createNamespace(String namespace, Map<String, String> options) throws ExecutionException {
    CreateKeyspace query = SchemaBuilder.createKeyspace(quoteIfNecessary(namespace));
    String replicationFactor = options.getOrDefault(REPLICATION_FACTOR, "1");
    ReplicationStrategy replicationStrategy = options.containsKey(REPLICATION_STRATEGY) ? ReplicationStrategy.fromString(options.get(REPLICATION_STRATEGY)) : ReplicationStrategy.SIMPLE_STRATEGY;
    Map<String, Object> replicationOptions = new LinkedHashMap<>();
    if (replicationStrategy == ReplicationStrategy.SIMPLE_STRATEGY) {
        replicationOptions.put("class", ReplicationStrategy.SIMPLE_STRATEGY.toString());
        replicationOptions.put("replication_factor", replicationFactor);
    } else if (replicationStrategy == ReplicationStrategy.NETWORK_TOPOLOGY_STRATEGY) {
        replicationOptions.put("class", ReplicationStrategy.NETWORK_TOPOLOGY_STRATEGY.toString());
        replicationOptions.put("dc1", replicationFactor);
    }
    try {
        clusterManager.getSession().execute(query.with().replication(replicationOptions).getQueryString());
    } catch (RuntimeException e) {
        throw new ExecutionException(String.format("creating the keyspace %s failed", namespace), e);
    }
}
Also used : CreateKeyspace(com.datastax.driver.core.schemabuilder.CreateKeyspace) ExecutionException(com.scalar.db.exception.storage.ExecutionException) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

CreateKeyspace (com.datastax.driver.core.schemabuilder.CreateKeyspace)2 ExecutionException (com.scalar.db.exception.storage.ExecutionException)1 LinkedHashMap (java.util.LinkedHashMap)1