Checking if Astyanax Keyspace is null or not

Is there a way to check if the Astyanax keyspace exists in the current context? Now my code does the following:

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(); } 

Is this the only way to check if a keyspace exists?

+4
source share
1 answer

I do it like this ...

 try { keyspace.getKeyspaceProperties(); LOG.debug("keyspace exist"); } catch (Exception e) { LOG.debug("keyspace does NOT exist"); } 

This code throws an exception, so be sure to put a comment. If people check the magazine, they will understand what is happening.

UPDATE There is a person who made a function request on github Problem number 382 . Hope this helps ...

0
source

Source: https://habr.com/ru/post/1496795/


All Articles