Ejemplo n.º 1
0
 /**
  * Deserialize only Keyspace attributes without nested ColumnFamilies
  *
  * @param row Keyspace attributes in serialized form
  * @return deserialized keyspace without cf_defs
  * @throws IOException if deserialization failed
  */
 public static KSMetaData fromSchema(Row row, Iterable<CFMetaData> cfms) throws IOException {
   UntypedResultSet.Row result =
       QueryProcessor.resultify("SELECT * FROM system.schema_keyspaces", row).one();
   try {
     return new KSMetaData(
         result.getString("name"),
         AbstractReplicationStrategy.getClass(result.getString("strategy_class")),
         fromJsonMap(result.getString("strategy_options")),
         result.getBoolean("durable_writes"),
         cfms);
   } catch (ConfigurationException e) {
     throw new RuntimeException(e);
   }
 }
Ejemplo n.º 2
0
  /**
   * Deserialize ColumnFamilies from low-level schema representation, all of them belong to the same
   * keyspace
   *
   * @param row
   * @return map containing name of the ColumnFamily and it's metadata for faster lookup
   */
  public static Map<String, CFMetaData> deserializeColumnFamilies(Row row) {
    if (row.cf == null) return Collections.emptyMap();

    Map<String, CFMetaData> cfms = new HashMap<String, CFMetaData>();
    UntypedResultSet results =
        QueryProcessor.resultify("SELECT * FROM system.schema_columnfamilies", row);
    for (UntypedResultSet.Row result : results) {
      CFMetaData cfm = CFMetaData.fromSchema(result);
      cfms.put(cfm.cfName, cfm);
    }

    for (CFMetaData cfm : cfms.values()) {
      Row columnRow = ColumnDefinition.readSchema(cfm.ksName, cfm.cfName);
      for (ColumnDefinition cd : ColumnDefinition.fromSchema(columnRow, cfm))
        cfm.column_metadata.put(cd.name, cd);
    }

    return cfms;
  }