Search in sources :

Example 6 with Schema

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()));
}
Also used : Schema(org.jooq.Schema)

Example 7 with Schema

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);
}
Also used : DSL.currentSchema(org.jooq.impl.DSL.currentSchema) Schema(org.jooq.Schema)

Example 8 with Schema

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);
    }
}
Also used : Schema(org.jooq.Schema) TableRecord(org.jooq.TableRecord) UpdatableRecord(org.jooq.UpdatableRecord) Record(org.jooq.Record) IOException(org.jooq.exception.IOException) TableField(org.jooq.TableField)

Example 9 with Schema

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 "";
}
Also used : Configuration(org.jooq.Configuration) Schema(org.jooq.Schema) TableField(org.jooq.TableField) AttachableInternal(org.jooq.AttachableInternal)

Example 10 with Schema

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);
                        }
                    }
                }
            }
        }
    }
}
Also used : SchemaDefinition(org.jooq.util.SchemaDefinition) Schema(org.jooq.Schema) TableDefinition(org.jooq.util.TableDefinition) ColumnDefinition(org.jooq.util.ColumnDefinition)

Aggregations

Schema (org.jooq.Schema)22 TableField (org.jooq.TableField)6 Record (org.jooq.Record)5 TableRecord (org.jooq.TableRecord)4 UpdatableRecord (org.jooq.UpdatableRecord)4 DSL.currentSchema (org.jooq.impl.DSL.currentSchema)4 Table (org.jooq.Table)3 InformationSchema (org.jooq.util.xml.jaxb.InformationSchema)3 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 Name (org.jooq.Name)2 Sequence (org.jooq.Sequence)2 Support (org.jooq.Support)2 IOException (org.jooq.exception.IOException)2 SchemaDefinition (org.jooq.util.SchemaDefinition)2 Collections.unmodifiableList (java.util.Collections.unmodifiableList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1