use of org.jooq.Schema in project jOOQ by jOOQ.
the class UDTImpl method accept.
@Override
public final void accept(Context<?> ctx) {
Schema mappedSchema = Tools.getMappedSchema(ctx.configuration(), getSchema());
if (mappedSchema != null) {
ctx.visit(mappedSchema);
ctx.sql('.');
}
if (getPackage() != null) {
ctx.visit(getPackage());
ctx.sql('.');
}
ctx.visit(DSL.name(getName()));
}
use of org.jooq.Schema in project jOOQ by jOOQ.
the class ParserImpl method parseCreateSchema.
private static final DDLQuery parseCreateSchema(ParserContext ctx) {
boolean ifNotExists = parseKeywordIf(ctx, "IF NOT EXISTS");
Schema schemaName = parseSchemaName(ctx);
return ifNotExists ? ctx.dsl.createSchemaIfNotExists(schemaName) : ctx.dsl.createSchema(schemaName);
}
use of org.jooq.Schema in project jOOQ by jOOQ.
the class ResultImpl method formatJSON.
@Override
public final void formatJSON(Writer writer, JSONFormat format) {
try {
String separator;
int recordLevel = format.header() ? 2 : 1;
if (format.header()) {
if (format.format())
writer.append('{').append(format.newline()).append(format.indentString(1)).append("\"fields\": [");
else
writer.append("{\"fields\":[");
separator = "";
for (Field<?> field : fields.fields) {
writer.append(separator);
if (format.format())
writer.append(format.newline()).append(format.indentString(2));
writer.append('{');
if (format.format())
writer.append(format.newline()).append(format.indentString(3));
if (field instanceof TableField) {
Table<?> table = ((TableField<?, ?>) field).getTable();
if (table != null) {
Schema schema = table.getSchema();
if (schema != null) {
writer.append("\"schema\":");
if (format.format())
writer.append(' ');
JSONValue.writeJSONString(schema.getName(), writer);
writer.append(',');
if (format.format())
writer.append(format.newline()).append(format.indentString(3));
}
writer.append("\"table\":");
if (format.format())
writer.append(' ');
JSONValue.writeJSONString(table.getName(), writer);
writer.append(',');
if (format.format())
writer.append(format.newline()).append(format.indentString(3));
}
}
writer.append("\"name\":");
if (format.format())
writer.append(' ');
JSONValue.writeJSONString(field.getName(), writer);
writer.append(',');
if (format.format())
writer.append(format.newline()).append(format.indentString(3));
writer.append("\"type\":");
if (format.format())
writer.append(' ');
JSONValue.writeJSONString(field.getDataType().getTypeName().toUpperCase(), writer);
if (format.format())
writer.append(format.newline()).append(format.indentString(2));
writer.append('}');
separator = ",";
}
if (format.format())
writer.append(format.newline()).append(format.indentString(1)).append("],").append(format.newline()).append(format.indentString(1)).append("\"records\": ");
else
writer.append("],\"records\":");
}
writer.append('[');
separator = "";
switch(format.recordFormat()) {
case ARRAY:
for (Record record : this) {
writer.append(separator);
if (format.format())
writer.append(format.newline());
formatJSONArray0(record, fields, format, recordLevel, writer);
separator = ",";
}
break;
case OBJECT:
for (Record record : this) {
writer.append(separator);
if (format.format())
writer.append(format.newline());
formatJSONMap0(record, fields, format, recordLevel, writer);
separator = ",";
}
break;
default:
throw new IllegalArgumentException("Format not supported: " + format);
}
if (format.format()) {
writer.append(format.newline());
if (format.header())
writer.append(format.indentString(1));
}
writer.append(']');
if (format.header())
writer.append(format.newline()).append('}');
writer.flush();
} catch (java.io.IOException e) {
throw new IOException("Exception while writing JSON", e);
}
}
use of org.jooq.Schema in project jOOQ by jOOQ.
the class MockResultSetMetaData method getSchemaName.
@Override
public String getSchemaName(int column) throws SQLException {
rs.checkNotClosed();
Field<?> field = rs.result.field(column - 1);
if (field instanceof TableField) {
Table<?> table = ((TableField<?, ?>) field).getTable();
if (table != null) {
Schema schema = table.getSchema();
if (schema != null) {
Configuration configuration = ((AttachableInternal) rs.result).configuration();
Schema mapped = null;
if (configuration != null) {
mapped = DSL.using(configuration).map(schema);
}
if (mapped != null) {
return mapped.getName();
} else {
return schema.getName();
}
}
}
}
// By default, no schema is available
return "";
}
use of org.jooq.Schema in project jOOQ by jOOQ.
the class JDBCDatabase method loadUniqueKeys.
@Override
protected void loadUniqueKeys(DefaultRelations relations) throws SQLException {
for (Schema schema : getSchemasFromMeta()) {
SchemaDefinition s = getSchema(schema.getName());
if (s != null) {
for (Table<?> table : schema.getTables()) {
TableDefinition t = getTable(s, table.getName());
if (t != null) {
UniqueKey<?> key = table.getPrimaryKey();
if (key != null) {
for (Field<?> field : key.getFields()) {
ColumnDefinition c = t.getColumn(field.getName());
relations.addPrimaryKey("PK_" + key.getTable().getName(), c);
}
}
}
}
}
}
}
Aggregations