createColumnFamily(ctx, ks, cf, comparator, keyValidator, defValidator, false);
}
public static void createColumnFamily(AstyanaxContext<Cluster> ctx,String ks, String cf, String comparator,
String keyValidator, String defValidator, boolean dropFirst) throws ConnectionException{
Cluster cluster = ctx.getEntity();
KeyspaceDefinition keyspace = cluster.describeKeyspace(ks);
if(keyspace != null){
LOG.warn("Keyspace {} already exists.", ks);
} else{
LOG.warn("Creating keyspace '{}'", ks);
KeyspaceDefinition ksDef = cluster.makeKeyspaceDefinition();
Map<String, String> stratOptions = new HashMap<String, String>();
stratOptions.put("replication_factor", "1");
ksDef.setName(ks)
.setStrategyClass("SimpleStrategy")
.setStrategyOptions(stratOptions);
cluster.addKeyspace(ksDef);
}
if (dropFirst){
LOG.warn("Dropping {} column family.", cf);
try{
cluster.dropColumnFamily(ks,cf);
} catch (BadRequestException bre){
LOG.warn("Could not drop column family, likely doesn't exist. [" + bre.getMessage() + "]");
}
}
LOG.warn("Adding column family: '{}'", cf);
try {
cluster.addColumnFamily(cluster.makeColumnFamilyDefinition().setKeyspace(ks).setName(cf).setComparatorType(comparator)
.setKeyValidationClass(keyValidator).setDefaultValidationClass(defValidator));
} catch (BadRequestException bre){
LOG.warn("Could not create column family [" + bre.getMessage() + "]");
}
}