List<ColumnDef> columnMetadataList = columnFamilyDefToUpdate.getColumn_metadata();
List<String> indexList = new ArrayList<String>();
if (columnMetadataList != null) {
for (ColumnDef columnDef : columnMetadataList) {
indexList.add(new StringAccessor().fromBytes(String.class, columnDef.getName()));
}
// need to set them to null else it is giving problem on update
// column family and trying to add again existing indexes.
// columnFamilyDefToUpdate.column_metadata = null;
}
// Iterate over all columns for creating secondary index on them
for (Column column : columns) {
ColumnDef columnDef = new ColumnDef();
columnDef.setName(column.getName());
columnDef.setValidation_class(CassandraValidationClassMapper.getValidationClass(columnType, false));
columnDef.setIndex_type(IndexType.KEYS);
// Add secondary index only if it's not already created
// (if already created, it would be there in column family
// definition)
if (!indexList.contains(new StringAccessor().fromBytes(String.class, column.getName()))) {
isUpdatable = true;
columnFamilyDefToUpdate.addToColumn_metadata(columnDef);
}
}