Search in sources :

Example 11 with ScriptBuilder

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();
}
Also used : ScriptBuilder(com.datastax.oss.driver.internal.core.metadata.schema.ScriptBuilder) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 12 with ScriptBuilder

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();
}
Also used : ScriptBuilder(com.datastax.oss.driver.internal.core.metadata.schema.ScriptBuilder) Map(java.util.Map) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 13 with ScriptBuilder

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();
}
Also used : ScriptBuilder(com.datastax.oss.driver.internal.core.metadata.schema.ScriptBuilder) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) AttachmentPoint(com.datastax.oss.driver.api.core.detach.AttachmentPoint) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Aggregations

ScriptBuilder (com.datastax.oss.driver.internal.core.metadata.schema.ScriptBuilder)13 NonNull (edu.umd.cs.findbugs.annotations.NonNull)13 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)5 Map (java.util.Map)5 DataType (com.datastax.oss.driver.api.core.type.DataType)4 AttachmentPoint (com.datastax.oss.driver.api.core.detach.AttachmentPoint)1 ClusteringOrder (com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder)1 ColumnMetadata (com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata)1 ImmutableMap (com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap)1