use of com.datastax.oss.driver.internal.core.metadata.schema.ScriptBuilder in project java-driver by datastax.
the class TableMetadata method describeWithChildren.
/**
* {@inheritDoc}
*
* <p>This describes the table and all of its indices. Contrary to previous driver versions, views
* are <b>not</b> included.
*/
@NonNull
@Override
default String describeWithChildren(boolean pretty) {
String createTable = describe(pretty);
ScriptBuilder builder = new ScriptBuilder(pretty).append(createTable);
for (IndexMetadata indexMetadata : getIndexes().values()) {
builder.forceNewLine(2).append(indexMetadata.describeWithChildren(pretty));
}
return builder.build();
}
use of com.datastax.oss.driver.internal.core.metadata.schema.ScriptBuilder in project java-driver by datastax.
the class IndexMetadata method describe.
@NonNull
@Override
default String describe(boolean pretty) {
ScriptBuilder builder = new ScriptBuilder(pretty);
if (getClassName().isPresent()) {
builder.append("CREATE CUSTOM INDEX ").append(getName()).append(" ON ").append(getKeyspace()).append(".").append(getTable()).append(String.format(" (%s)", getTarget())).newLine().append(String.format("USING '%s'", getClassName().get()));
// Some options already appear in the CREATE statement, ignore them
Map<String, String> describedOptions = Maps.filterKeys(getOptions(), k -> !"target".equals(k) && !"class_name".equals(k));
if (!describedOptions.isEmpty()) {
builder.newLine().append("WITH OPTIONS = {").newLine().increaseIndent();
boolean first = true;
for (Map.Entry<String, String> option : describedOptions.entrySet()) {
if (first) {
first = false;
} else {
builder.append(",").newLine();
}
builder.append(String.format("'%s' : '%s'", option.getKey(), option.getValue()));
}
builder.decreaseIndent().append("}");
}
} else {
builder.append("CREATE INDEX ").append(getName()).append(" ON ").append(getKeyspace()).append(".").append(getTable()).append(String.format(" (%s);", getTarget()));
}
return builder.build();
}
use of com.datastax.oss.driver.internal.core.metadata.schema.ScriptBuilder in project java-driver by datastax.
the class UserDefinedType method describe.
@NonNull
@Override
default String describe(boolean pretty) {
ScriptBuilder builder = new ScriptBuilder(pretty);
builder.append("CREATE TYPE ").append(getKeyspace()).append(".").append(getName()).append(" (").newLine().increaseIndent();
List<CqlIdentifier> fieldNames = getFieldNames();
List<DataType> fieldTypes = getFieldTypes();
int fieldCount = fieldNames.size();
for (int i = 0; i < fieldCount; i++) {
builder.append(fieldNames.get(i)).append(" ").append(fieldTypes.get(i).asCql(true, pretty));
if (i < fieldCount - 1) {
builder.append(",");
}
builder.newLine();
}
builder.decreaseIndent().append(");");
return builder.build();
}
Aggregations