Search in sources :

Example 16 with Schema

use of org.jooq.Schema in project jOOQ by jOOQ.

the class ParserImpl method parseAlterSchema.

private static final DDLQuery parseAlterSchema(ParserContext ctx) {
    boolean ifExists = parseKeywordIf(ctx, "IF EXISTS");
    Schema schemaName = parseSchemaName(ctx);
    parseKeyword(ctx, "RENAME TO");
    Schema newName = parseSchemaName(ctx);
    AlterSchemaStep s1 = ifExists ? ctx.dsl.alterSchemaIfExists(schemaName) : ctx.dsl.alterSchema(schemaName);
    AlterSchemaFinalStep s2 = s1.renameTo(newName);
    return s2;
}
Also used : AlterSchemaFinalStep(org.jooq.AlterSchemaFinalStep) DSL.currentSchema(org.jooq.impl.DSL.currentSchema) Schema(org.jooq.Schema) AlterSchemaStep(org.jooq.AlterSchemaStep)

Example 17 with Schema

use of org.jooq.Schema in project jOOQ by jOOQ.

the class ResultImpl method intoXML.

@Override
public final <H extends ContentHandler> H intoXML(H handler, XMLFormat format) throws SAXException {
    Attributes empty = new AttributesImpl();
    handler.startDocument();
    if (format.xmlns())
        handler.startPrefixMapping("", Constants.NS_EXPORT);
    handler.startElement("", "", "result", empty);
    if (format.header()) {
        handler.startElement("", "", "fields", empty);
        for (Field<?> field : fields.fields) {
            AttributesImpl attrs = new AttributesImpl();
            if (field instanceof TableField<?, ?>) {
                Table<?> table = ((TableField) field).getTable();
                if (table != null) {
                    Schema schema = table.getSchema();
                    if (schema != null) {
                        attrs.addAttribute("", "", "schema", "CDATA", schema.getName());
                    }
                    attrs.addAttribute("", "", "table", "CDATA", table.getName());
                }
            }
            attrs.addAttribute("", "", "name", "CDATA", field.getName());
            attrs.addAttribute("", "", "type", "CDATA", field.getDataType().getTypeName().toUpperCase());
            handler.startElement("", "", "field", attrs);
            handler.endElement("", "", "field");
        }
        handler.endElement("", "", "fields");
        handler.startElement("", "", "records", empty);
    }
    for (Record record : this) {
        handler.startElement("", "", "record", empty);
        for (int index = 0; index < fields.fields.length; index++) {
            Field<?> field = fields.fields[index];
            Object value = record.get(index);
            String tag = format.recordFormat() == COLUMN_NAME_ELEMENTS ? escapeXML(fields.fields[index].getName()) : "value";
            AttributesImpl attrs = new AttributesImpl();
            if (format.recordFormat() == VALUE_ELEMENTS_WITH_FIELD_ATTRIBUTE)
                attrs.addAttribute("", "", "field", "CDATA", field.getName());
            handler.startElement("", "", tag, attrs);
            if (value != null) {
                char[] chars = format0(value, false, false).toCharArray();
                handler.characters(chars, 0, chars.length);
            }
            handler.endElement("", "", tag);
        }
        handler.endElement("", "", "record");
    }
    if (format.header())
        handler.endElement("", "", "records");
    if (format.xmlns())
        handler.endPrefixMapping("");
    handler.endDocument();
    return handler;
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) Schema(org.jooq.Schema) Attributes(org.xml.sax.Attributes) TableRecord(org.jooq.TableRecord) UpdatableRecord(org.jooq.UpdatableRecord) Record(org.jooq.Record) TableField(org.jooq.TableField)

Example 18 with Schema

use of org.jooq.Schema in project jOOQ by jOOQ.

the class ResultImpl method intoXML.

@Override
public final Document intoXML(XMLFormat format) {
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document document = builder.newDocument();
        Element eResult = document.createElement("result");
        if (format.xmlns())
            eResult.setAttribute("xmlns", Constants.NS_EXPORT);
        document.appendChild(eResult);
        Element eRecordParent = eResult;
        if (format.header()) {
            Element eFields = document.createElement("fields");
            eResult.appendChild(eFields);
            for (Field<?> field : fields.fields) {
                Element eField = document.createElement("field");
                if (field instanceof TableField<?, ?>) {
                    Table<?> table = ((TableField) field).getTable();
                    if (table != null) {
                        Schema schema = table.getSchema();
                        if (schema != null) {
                            eField.setAttribute("schema", schema.getName());
                        }
                        eField.setAttribute("table", table.getName());
                    }
                }
                eField.setAttribute("name", field.getName());
                eField.setAttribute("type", field.getDataType().getTypeName().toUpperCase());
                eFields.appendChild(eField);
            }
            Element eRecords = document.createElement("records");
            eResult.appendChild(eRecords);
            eRecordParent = eRecords;
        }
        for (Record record : this) {
            Element eRecord = document.createElement("record");
            eRecordParent.appendChild(eRecord);
            for (int index = 0; index < fields.fields.length; index++) {
                Field<?> field = fields.fields[index];
                Object value = record.get(index);
                String tag = format.recordFormat() == COLUMN_NAME_ELEMENTS ? escapeXML(fields.fields[index].getName()) : "value";
                Element eValue = document.createElement(tag);
                if (format.recordFormat() == VALUE_ELEMENTS_WITH_FIELD_ATTRIBUTE)
                    eValue.setAttribute("field", field.getName());
                eRecord.appendChild(eValue);
                if (value != null) {
                    eValue.setTextContent(format0(value, false, false));
                }
            }
        }
        return document;
    } catch (ParserConfigurationException ignore) {
        throw new RuntimeException(ignore);
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Element(org.w3c.dom.Element) Schema(org.jooq.Schema) Document(org.w3c.dom.Document) TableField(org.jooq.TableField) DocumentBuilder(javax.xml.parsers.DocumentBuilder) TableRecord(org.jooq.TableRecord) UpdatableRecord(org.jooq.UpdatableRecord) Record(org.jooq.Record) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 19 with Schema

use of org.jooq.Schema in project jOOQ by jOOQ.

the class ResultImpl method formatXML.

@Override
public final void formatXML(Writer writer, XMLFormat format) {
    String newline = format.newline();
    int recordLevel = format.header() ? 2 : 1;
    try {
        writer.append("<result");
        if (format.xmlns())
            writer.append(" xmlns=\"" + Constants.NS_EXPORT + "\"");
        writer.append(">");
        if (format.header()) {
            writer.append(newline).append(format.indentString(1)).append("<fields>");
            for (Field<?> field : fields.fields) {
                writer.append(newline).append(format.indentString(2)).append("<field");
                if (field instanceof TableField) {
                    Table<?> table = ((TableField<?, ?>) field).getTable();
                    if (table != null) {
                        Schema schema = table.getSchema();
                        if (schema != null) {
                            writer.append(" schema=\"");
                            writer.append(escapeXML(schema.getName()));
                            writer.append("\"");
                        }
                        writer.append(" table=\"");
                        writer.append(escapeXML(table.getName()));
                        writer.append("\"");
                    }
                }
                writer.append(" name=\"");
                writer.append(escapeXML(field.getName()));
                writer.append("\"");
                writer.append(" type=\"");
                writer.append(field.getDataType().getTypeName().toUpperCase());
                writer.append("\"/>");
            }
            writer.append(newline).append(format.indentString(1)).append("</fields>");
            writer.append(newline).append(format.indentString(1)).append("<records>");
        }
        for (Record record : this) {
            writer.append(newline).append(format.indentString(recordLevel));
            formatXMLRecord(writer, format, recordLevel, record, fields);
        }
        if (format.header())
            writer.append(newline).append(format.indentString(1)).append("</records>");
        writer.append(newline).append("</result>");
        writer.flush();
    } catch (java.io.IOException e) {
        throw new IOException("Exception while writing XML", 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 20 with Schema

use of org.jooq.Schema in project jOOQ by jOOQ.

the class SequenceImpl method accept0.

private final void accept0(Context<?> ctx, boolean asStringLiterals) {
    Schema mappedSchema = Tools.getMappedSchema(ctx.configuration(), schema);
    if (mappedSchema != null && ctx.family() != CUBRID) {
        if (asStringLiterals) {
            ctx.visit(inline(mappedSchema.getName())).sql(", ");
        } else {
            ctx.visit(mappedSchema).sql('.');
        }
    }
    if (asStringLiterals)
        ctx.visit(inline(name));
    else if (nameIsPlainSQL)
        ctx.sql(name);
    else
        ctx.literal(name);
}
Also used : Schema(org.jooq.Schema)

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