cassandra_client.set_keyspace(ksDef.getName());
for (TableInfo tableInfo : tableInfos)
{
if (isCql3Enabled(tableInfo) && !tableInfo.getType().equals(Type.SUPER_COLUMN_FAMILY.name()))
{
CqlMetadata metadata = new CqlMetadata();
Map<ByteBuffer, String> name_types = new HashMap<ByteBuffer, String>();
Map<ByteBuffer, String> value_types = new HashMap<ByteBuffer, String>();
List<ColumnInfo> columnInfos = tableInfo.getColumnMetadatas();
List<EmbeddedColumnInfo> compositeColumns = tableInfo.getEmbeddedColumnMetadatas();
if (compositeColumns != null && !compositeColumns.isEmpty())
{
EmbeddableType embeddableType = compositeColumns.get(0).getEmbeddable();
for (ColumnInfo columnInfo : compositeColumns.get(0).getColumns())
{
name_types
.put(ByteBufferUtil.bytes(columnInfo.getColumnName()), UTF8Type.class.getSimpleName());
value_types.put(ByteBufferUtil.bytes(columnInfo.getColumnName()),
CassandraValidationClassMapper.getValidationClassInstance(columnInfo.getType(), true)
.getName());
}
}
else
{
name_types.put(ByteBufferUtil.bytes(tableInfo.getIdColumnName()), UTF8Type.class.getSimpleName());
value_types.put(ByteBufferUtil.bytes(tableInfo.getIdColumnName()), CassandraValidationClassMapper
.getValidationClassInstance(tableInfo.getTableIdType(), true).getName());
}
for (ColumnInfo info : columnInfos)
{
name_types.put(ByteBufferUtil.bytes(info.getColumnName()), UTF8Type.class.getSimpleName());
value_types.put(ByteBufferUtil.bytes(info.getColumnName()), CassandraValidationClassMapper
.getValidationClassInstance(info.getType(), true).getName());
}
for (CollectionColumnInfo info : tableInfo.getCollectionColumnMetadatas())
{
name_types
.put(ByteBufferUtil.bytes(info.getCollectionColumnName()), UTF8Type.class.getSimpleName());
value_types.put(ByteBufferUtil.bytes(info.getCollectionColumnName()),
CassandraValidationClassMapper.getValueTypeName(info.getType(), info.getGenericClasses(),
true));
}
metadata.setDefault_name_type(UTF8Type.class.getSimpleName());
metadata.setDefault_value_type(UTF8Type.class.getSimpleName());
metadata.setName_types(name_types);
metadata.setValue_types(value_types);
CQLTranslator translator = new CQLTranslator();
final String describeTable = "select * from ";
StringBuilder builder = new StringBuilder(describeTable);
translator.ensureCase(builder, tableInfo.getTableName(), false);
builder.append("LIMIT 1");
cassandra_client.set_cql_version(CassandraConstants.CQL_VERSION_3_0);
CqlResult cqlResult = cassandra_client.execute_cql3_query(ByteBufferUtil.bytes(builder.toString()),
Compression.NONE, ConsistencyLevel.ONE);
KunderaCoreUtils.printQuery(builder.toString(), showQuery);
CqlMetadata originalMetadata = cqlResult.getSchema();
int compareResult = originalMetadata.compareTo(metadata);
if (compareResult > 0)
{
onLog(tableInfo, metadata, value_types, originalMetadata);
throw new SchemaGenerationException(
"Schema mismatch!, validation failed. see above table for mismatch");