Cassandra 检查Astyanax键空间是否为空或不';不存在
是否有方法检查当前上下文中是否存在Astyanax键空间?现在,我的代码执行以下操作:Cassandra 检查Astyanax键空间是否为空或不';不存在,cassandra,astyanax,Cassandra,Astyanax,是否有方法检查当前上下文中是否存在Astyanax键空间?现在,我的代码执行以下操作: keyspace = context.getClient(); try{ keyspace.describeKeyspace(); }catch (BadRequestException e){ keyspace.createKeyspace(ImmutableMap.<String, Object>builder() .put("strategy_o
keyspace = context.getClient();
try{
keyspace.describeKeyspace();
}catch (BadRequestException e){
keyspace.createKeyspace(ImmutableMap.<String, Object>builder()
.put("strategy_options", ImmutableMap.<String, Object>builder()
.put("replication_factor", "1")
.build())
.put("strategy_class", "SimpleStrategy")
.build();
}
keyspace=context.getClient();
试一试{
descripbekeyspace();
}捕获(BADE异常){
createKeyspace(ImmutableMap.builder()
.put(“策略选项”,ImmutableMap.builder()
.put(“复制系数”、“1”)
.build())
.put(“策略类”、“简单策略”)
.build();
}
这是检查键空间是否存在的唯一方法吗?我就是这样做的
try {
keyspace.getKeyspaceProperties();
LOG.debug("keyspace exist");
} catch (Exception e) {
LOG.debug("keyspace does NOT exist");
}
此代码将生成一个异常,因此请务必添加一些注释。如果人们查看日志,他们将了解发生了什么
更新
有人在github上提出了功能请求
.
希望对您有所帮助…我认为这基本上就是我在上面所做的,但是使用getKeyspaceProperties方法而不是describeKeyspace方法。我一直在寻找if(keyspace.getKeyspaceProperties()==null){…}