use of com.datastax.oss.driver.internal.core.metadata.schema.ScriptBuilder in project java-driver by datastax.
the class DseGraphTableMetadata method describe.
@NonNull
@Override
default String describe(boolean pretty) {
ScriptBuilder builder = new ScriptBuilder(pretty);
if (isVirtual()) {
builder.append("/* VIRTUAL ");
} else {
builder.append("CREATE ");
}
builder.append("TABLE ").append(getKeyspace()).append(".").append(getName()).append(" (").newLine().increaseIndent();
for (ColumnMetadata column : getColumns().values()) {
builder.append(column.getName()).append(" ").append(column.getType().asCql(true, pretty));
if (column.isStatic()) {
builder.append(" static");
}
builder.append(",").newLine();
}
// PK
builder.append("PRIMARY KEY (");
if (getPartitionKey().size() == 1) {
// PRIMARY KEY (k
builder.append(getPartitionKey().get(0).getName());
} else {
// PRIMARY KEY ((k1, k2)
builder.append("(");
boolean first = true;
for (ColumnMetadata pkColumn : getPartitionKey()) {
if (first) {
first = false;
} else {
builder.append(", ");
}
builder.append(pkColumn.getName());
}
builder.append(")");
}
// PRIMARY KEY (<pk portion>, cc1, cc2, cc3)
for (ColumnMetadata clusteringColumn : getClusteringColumns().keySet()) {
builder.append(", ").append(clusteringColumn.getName());
}
builder.append(")");
builder.newLine().decreaseIndent().append(")");
builder.increaseIndent();
if (isCompactStorage()) {
builder.andWith().append("COMPACT STORAGE");
}
if (getClusteringColumns().containsValue(ClusteringOrder.DESC)) {
builder.andWith().append("CLUSTERING ORDER BY (");
boolean first = true;
for (Map.Entry<? extends ColumnMetadata, ClusteringOrder> entry : getClusteringColumns().entrySet()) {
if (first) {
first = false;
} else {
builder.append(", ");
}
builder.append(entry.getKey().getName()).append(" ").append(entry.getValue().name());
}
builder.append(")");
}
getVertex().ifPresent(vertex -> {
builder.andWith().append("VERTEX LABEL").append(" ").append(vertex.getLabelName());
});
getEdge().ifPresent(edge -> {
builder.andWith().append("EDGE LABEL").append(" ").append(edge.getLabelName());
ScriptHelper.appendEdgeSide(builder, edge.getFromTable(), edge.getFromLabel(), edge.getFromPartitionKeyColumns(), edge.getFromClusteringColumns(), "FROM");
ScriptHelper.appendEdgeSide(builder, edge.getToTable(), edge.getToLabel(), edge.getToPartitionKeyColumns(), edge.getToClusteringColumns(), "TO");
});
Map<CqlIdentifier, Object> options = getOptions();
RelationParser.appendOptions(options, builder);
builder.append(";");
if (isVirtual()) {
builder.append(" */");
}
return builder.build();
}
use of com.datastax.oss.driver.internal.core.metadata.schema.ScriptBuilder in project java-driver by datastax.
the class AggregateMetadata method describe.
@NonNull
@Override
default String describe(boolean pretty) {
ScriptBuilder builder = new ScriptBuilder(pretty);
builder.append("CREATE AGGREGATE ").append(getKeyspace()).append(".").append(getSignature().getName()).append("(");
boolean first = true;
for (int i = 0; i < getSignature().getParameterTypes().size(); i++) {
if (first) {
first = false;
} else {
builder.append(",");
}
DataType type = getSignature().getParameterTypes().get(i);
builder.append(type.asCql(false, pretty));
}
builder.increaseIndent().append(")").newLine().append("SFUNC ").append(getStateFuncSignature().getName()).newLine().append("STYPE ").append(getStateType().asCql(false, pretty));
if (getFinalFuncSignature().isPresent()) {
builder.newLine().append("FINALFUNC ").append(getFinalFuncSignature().get().getName());
}
if (getInitCond().isPresent()) {
Optional<String> formatInitCond = formatInitCond();
assert formatInitCond.isPresent();
builder.newLine().append("INITCOND ").append(formatInitCond.get());
}
return builder.append(";").build();
}
use of com.datastax.oss.driver.internal.core.metadata.schema.ScriptBuilder in project java-driver by datastax.
the class FunctionMetadata method describe.
@NonNull
@Override
default String describe(boolean pretty) {
ScriptBuilder builder = new ScriptBuilder(pretty);
builder.append("CREATE FUNCTION ").append(getKeyspace()).append(".").append(getSignature().getName()).append("(");
boolean first = true;
for (int i = 0; i < getSignature().getParameterTypes().size(); i++) {
if (first) {
first = false;
} else {
builder.append(",");
}
DataType type = getSignature().getParameterTypes().get(i);
CqlIdentifier name = getParameterNames().get(i);
builder.append(name).append(" ").append(type.asCql(false, pretty));
}
return builder.append(")").increaseIndent().newLine().append(isCalledOnNullInput() ? "CALLED ON NULL INPUT" : "RETURNS NULL ON NULL INPUT").newLine().append("RETURNS ").append(getReturnType().asCql(false, true)).newLine().append("LANGUAGE ").append(getLanguage()).newLine().append("AS '").append(getBody()).append("';").build();
}
use of com.datastax.oss.driver.internal.core.metadata.schema.ScriptBuilder in project java-driver by datastax.
the class KeyspaceMetadata method describe.
@NonNull
@Override
default String describe(boolean pretty) {
ScriptBuilder builder = new ScriptBuilder(pretty);
if (isVirtual()) {
builder.append("/* VIRTUAL ");
} else {
builder.append("CREATE ");
}
builder.append("KEYSPACE ").append(getName()).append(" WITH replication = { 'class' : '").append(getReplication().get("class")).append("'");
for (Map.Entry<String, String> entry : getReplication().entrySet()) {
if (!entry.getKey().equals("class")) {
builder.append(", '").append(entry.getKey()).append("': '").append(entry.getValue()).append("'");
}
}
builder.append(" } AND durable_writes = ").append(Boolean.toString(isDurableWrites())).append(";");
if (isVirtual()) {
builder.append(" */");
}
return builder.build();
}
use of com.datastax.oss.driver.internal.core.metadata.schema.ScriptBuilder in project java-driver by datastax.
the class KeyspaceMetadata method describeWithChildren.
@NonNull
@Override
default String describeWithChildren(boolean pretty) {
String createKeyspace = describe(pretty);
ScriptBuilder builder = new ScriptBuilder(pretty).append(createKeyspace);
for (Describable element : Iterables.concat(getUserDefinedTypes().values(), getTables().values(), getViews().values(), getFunctions().values(), getAggregates().values())) {
builder.forceNewLine(2).append(element.describeWithChildren(pretty));
}
return builder.build();
}
Aggregations