コード例 #1
0
  @Override
  public void clearStorage() throws StorageException {
    try {
      Cluster cluster = clusterContext.getEntity();

      Keyspace ks = cluster.getKeyspace(keySpaceName);

      // Not a big deal if Keyspace doesn't not exist (dropped manually by user or tests).
      // This is called on per test setup basis to make sure that previous test cleaned
      // everything up, so first invocation would always fail as Keyspace doesn't yet exist.
      if (ks == null) return;

      for (ColumnFamilyDefinition cf :
          cluster.describeKeyspace(keySpaceName).getColumnFamilyList()) {
        ks.truncateColumnFamily(new ColumnFamily<Object, Object>(cf.getName(), null, null));
      }
    } catch (ConnectionException e) {
      throw new PermanentStorageException(e);
    } finally {
      close();
    }
  }
コード例 #2
0
 private void ensureColumnFamilyExists(String name, String comparator) throws StorageException {
   Cluster cl = clusterContext.getEntity();
   try {
     KeyspaceDefinition ksDef = cl.describeKeyspace(keySpaceName);
     boolean found = false;
     if (null != ksDef) {
       for (ColumnFamilyDefinition cfDef : ksDef.getColumnFamilyList()) {
         found |= cfDef.getName().equals(name);
       }
     }
     if (!found) {
       ColumnFamilyDefinition cfDef =
           cl.makeColumnFamilyDefinition()
               .setName(name)
               .setKeyspace(keySpaceName)
               .setComparatorType(comparator);
       cl.addColumnFamily(cfDef);
     }
   } catch (ConnectionException e) {
     throw new TemporaryStorageException(e);
   }
 }
コード例 #3
0
 @Override
 public OperationResult<SchemaChangeResult> addColumnFamily(final ColumnFamilyDefinition def)
     throws ConnectionException {
   return executeSchemaChangeOperation(
       new AbstractKeyspaceOperationImpl<SchemaChangeResult>(
           tracerFactory.newTracer(CassandraOperationType.ADD_COLUMN_FAMILY), def.getKeyspace()) {
         @Override
         public SchemaChangeResult internalExecute(Client client, ConnectionContext context)
             throws Exception {
           return new SchemaChangeResponseImpl()
               .setSchemaId(
                   client.system_add_column_family(
                       ((ThriftColumnFamilyDefinitionImpl) def)
                           .getThriftColumnFamilyDefinition()));
         }
       });
 }