Java Code Examples for org.apache.cassandra.thrift.KsDef#getCf_defs()

The following examples show how to use org.apache.cassandra.thrift.KsDef#getCf_defs() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CassandraColumnMetaData.java    From learning-hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Static utility routine that returns a list of column families that exist in
 * the keyspace encapsulated in the supplied connection
 * 
 * @param conn the connection to use
 * @return a list of column families (tables)
 * @throws Exception if a problem occurs
 */
public static List<String> getColumnFamilyNames(CassandraConnection conn)
    throws Exception {

  KsDef keySpace = conn.describeKeyspace();
  List<CfDef> colFams = null;
  if (keySpace != null) {
    colFams = keySpace.getCf_defs();
  } else {
    throw new Exception(BaseMessages.getString(PKG,
        "CassandraColumnMetaData.Error.UnableToGetMetaDataForKeyspace",
        conn.m_keyspaceName));
  }

  List<String> colFamNames = new ArrayList<String>();
  for (CfDef fam : colFams) {
    colFamNames.add(fam.getName());
  }

  return colFamNames;
}
 
Example 2
Source File: CassandraSchemaMgr.java    From Doradus with Apache License 2.0 6 votes vote down vote up
/**
 * Return true if the given store name currently exists in the given keyspace. This
 * method can be used with a connection connected to any keyspace.
 * 
 * @param dbConn    Database connection to use.
 * @param cfName    Candidate ColumnFamily name.
 * @return          True if the CF exists in the database.
 */
public boolean columnFamilyExists(DBConn dbConn, String keyspace, String cfName) {
    KsDef ksDef = null;
    try {
        ksDef = dbConn.getClientSession().describe_keyspace(keyspace);
    } catch (Exception ex) {
        throw new RuntimeException("Failed to get keyspace definition for '" + keyspace + "'", ex);
    }
    
    List<CfDef> cfDefList = ksDef.getCf_defs();
    for (CfDef cfDef : cfDefList) {
        if (cfDef.getName().equals(cfName)) {
            return true;
        }
    }
    return false;
}
 
Example 3
Source File: CassandraColumnMetaData.java    From learning-hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Static utility routine for checking for the existence of a column family
 * (table)
 * 
 * @param conn the connection to use
 * @param columnFamily the column family to check for
 * @return true if the supplied column family name exists in the keyspace
 * @throws Exception if a problem occurs
 */
public static boolean columnFamilyExists(CassandraConnection conn,
    String columnFamily) throws Exception {

  boolean found = false;

  // column families
  KsDef keySpace = conn.describeKeyspace();
  List<CfDef> colFams = null;
  if (keySpace != null) {
    colFams = keySpace.getCf_defs();
  } else {
    throw new Exception(BaseMessages.getString(PKG,
        "CassandraColumnMetaData.Error.UnableToGetMetaDataForKeyspace",
        conn.m_keyspaceName));
  }

  // look for the requested column family
  for (CfDef fam : colFams) {
    String columnFamilyName = fam.getName(); // table name
    if (columnFamilyName.equals(columnFamily)) {
      found = true;
      break;
    }
  }

  return found;
}
 
Example 4
Source File: CliUtils.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
/**
 * Returns set of column family names in specified keySpace.
 * @param keySpace - keyspace definition to get column family names from.
 * @return Set - column family names
 */
public static Set<String> getCfNamesByKeySpace(KsDef keySpace)
{
    Set<String> names = new LinkedHashSet<String>();

    for (CfDef cfDef : keySpace.getCf_defs())
    {
        names.add(cfDef.getName());
    }

    return names;
}
 
Example 5
Source File: CassandraManager.java    From Hive-Cassandra with Apache License 2.0 5 votes vote down vote up
/**
 * Get Column family based on the configuration in the table. If nothing is found, return null.
 */
private CfDef getColumnFamily(KsDef ks) {
  for (CfDef cf : ks.getCf_defs()) {
    if (cf.getName().equalsIgnoreCase(columnFamilyName)) {
      return cf;
    }
  }

  return null;
}