Search in sources :

Example 16 with Rdb$fields

use of org.jooq.util.firebird.rdb.tables.Rdb$fields in project jOOQ by jOOQ.

the class FirebirdTableValuedFunction method getElements0.

@Override
protected List<ColumnDefinition> getElements0() throws SQLException {
    List<ColumnDefinition> result = new ArrayList<>();
    Rdb$procedureParameters p = RDB$PROCEDURE_PARAMETERS.as("p");
    Rdb$fields f = RDB$FIELDS.as("f");
    // DatabaseMetaData implementation
    for (Record record : create().select(p.RDB$PARAMETER_NUMBER, p.RDB$PARAMETER_NAME.trim(), p.RDB$DESCRIPTION, p.RDB$DEFAULT_VALUE, DSL.bitOr(p.RDB$NULL_FLAG.nvl((short) 0), f.RDB$NULL_FLAG.nvl((short) 0)).as(p.RDB$NULL_FLAG), p.RDB$DEFAULT_SOURCE, // [#3342] FIELD_LENGTH should be ignored for LOBs
    CHARACTER_LENGTH(f).as("CHAR_LEN"), f.RDB$FIELD_PRECISION, FIELD_SCALE(f).as("FIELD_SCALE"), FIELD_TYPE(f).as("FIELD_TYPE"), f.RDB$FIELD_SUB_TYPE).from(p).leftOuterJoin(f).on(p.RDB$FIELD_SOURCE.eq(f.RDB$FIELD_NAME)).where(p.RDB$PROCEDURE_NAME.eq(getName())).and(p.RDB$PARAMETER_TYPE.eq((short) 1)).orderBy(p.RDB$PARAMETER_NUMBER)) {
        DefaultDataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), record.get("FIELD_TYPE", String.class), record.get("CHAR_LEN", short.class), record.get(f.RDB$FIELD_PRECISION), record.get("FIELD_SCALE", Integer.class), record.get(p.RDB$NULL_FLAG) == 0, record.get(p.RDB$DEFAULT_SOURCE));
        result.add(new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), record.get(p.RDB$PARAMETER_NAME.trim()), result.size() + 1, type, false, null));
    }
    return result;
}
Also used : DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) DefaultColumnDefinition(org.jooq.meta.DefaultColumnDefinition) Rdb$fields(org.jooq.meta.firebird.rdb.tables.Rdb$fields) ArrayList(java.util.ArrayList) Record(org.jooq.Record) Rdb$procedureParameters(org.jooq.meta.firebird.rdb.tables.Rdb$procedureParameters) DefaultColumnDefinition(org.jooq.meta.DefaultColumnDefinition) ColumnDefinition(org.jooq.meta.ColumnDefinition)

Example 17 with Rdb$fields

use of org.jooq.util.firebird.rdb.tables.Rdb$fields in project atlasmap by atlasmap.

the class SchemaInspector method doInspect.

private void doInspect(InputStream is) throws Exception {
    xmlDocument = AtlasXmlModelFactory.createXmlDocument();
    Fields fields = new Fields();
    xmlDocument.setFields(fields);
    namespaceContext = new AtlasXmlNamespaceContext();
    rootNamespace = null;
    XSOMParser parser = new XSOMParser(SAXParserFactory.newInstance());
    parser.setAnnotationParser(new DomAnnotationParserFactory());
    parser.setErrorHandler(new XSOMErrorHandler());
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    Document doc = dbf.newDocumentBuilder().parse(is);
    Element root = doc.getDocumentElement();
    if (root == null) {
        throw new XmlInspectionException("XML schema document is empty");
    } else if ("SchemaSet".equals(root.getLocalName())) {
        XPath xpath = XPathFactory.newInstance().newXPath();
        xpath.setNamespaceContext(namespaceContext);
        NodeList subSchemas = (NodeList) xpath.evaluate(String.format("/%s:SchemaSet/%s:AdditionalSchemas/%s:schema", NS_PREFIX_SCHEMASET, NS_PREFIX_SCHEMASET, NS_PREFIX_XMLSCHEMA), doc, XPathConstants.NODESET);
        for (int i = 0; i < subSchemas.getLength(); i++) {
            Element e = (Element) subSchemas.item(i);
            inheritNamespaces(e, false);
            parser.parse(toInputStream(transformer, e));
        }
        Element rootSchema = (Element) xpath.evaluate(String.format("/%s:SchemaSet/%s:schema", NS_PREFIX_SCHEMASET, NS_PREFIX_XMLSCHEMA), doc, XPathConstants.NODE);
        if (rootSchema == null) {
            throw new XmlInspectionException("The root schema '/SchemaSet/schema' must be specified once and only once");
        }
        rootNamespace = getTargetNamespace(rootSchema);
        if (rootNamespace != null && !rootNamespace.isEmpty()) {
            namespaceContext.add("tns", rootNamespace);
        }
        inheritNamespaces(rootSchema, true);
        parser.parse(toInputStream(transformer, rootSchema));
    } else if ("schema".equals(root.getLocalName())) {
        parser.parse(toInputStream(transformer, root));
        rootNamespace = getTargetNamespace(root);
        if (rootNamespace != null && !rootNamespace.isEmpty()) {
            namespaceContext.add("tns", rootNamespace);
        }
    } else {
        throw new XmlInspectionException(String.format("Unsupported document element '%s': root element must be 'schema' or 'SchemaSet'", root.getLocalName()));
    }
    XSSchemaSet schemaSet = parser.getResult();
    printSchemaSet(schemaSet);
    populateNamespaces();
}
Also used : XPath(javax.xml.xpath.XPath) XSOMParser(com.sun.xml.xsom.parser.XSOMParser) Transformer(javax.xml.transform.Transformer) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) XSSchemaSet(com.sun.xml.xsom.XSSchemaSet) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) XmlDocument(io.atlasmap.xml.v2.XmlDocument) XmlFields(io.atlasmap.xml.v2.XmlFields) Fields(io.atlasmap.v2.Fields) DomAnnotationParserFactory(com.sun.xml.xsom.util.DomAnnotationParserFactory)

Example 18 with Rdb$fields

use of org.jooq.util.firebird.rdb.tables.Rdb$fields in project atlasmap by atlasmap.

the class CsvFieldReader method readSchema.

/**
 * Reads only the first row of the document.
 *
 * If firstRecordAsHeader is set to true it uses column names for field names, otherwise it uses an index
 * starting from 0.
 *
 * @return {@link Document} built from CSV
 * @throws AtlasException if it fails
 */
public Document readSchema() throws AtlasException {
    CSVFormat csvFormat = csvConfig.newCsvFormat();
    CSVParser parser;
    try {
        document.mark(Integer.MAX_VALUE);
        parser = csvFormat.parse(new InputStreamReader(document));
    } catch (IOException e) {
        throw new AtlasException(e);
    }
    List<CsvField> fields = new ArrayList<>();
    if (csvConfig.isFirstRecordAsHeader()) {
        for (String headerName : parser.getHeaderNames()) {
            CsvField field = new CsvField();
            field.setName(headerName);
            field.setPath("/<>/" + headerName);
            field.setFieldType(FieldType.STRING);
            fields.add(field);
        }
    } else {
        CSVRecord record = parser.iterator().next();
        for (int i = 0; i < record.size(); i++) {
            CsvField field = new CsvField();
            if (parser.getHeaderNames() != null && parser.getHeaderNames().size() > i) {
                field.setName(parser.getHeaderNames().get(i));
            } else {
                field.setColumn(i);
                field.setName(String.valueOf(i));
            }
            field.setPath("/<>/" + field.getName());
            field.setFieldType(FieldType.STRING);
            fields.add(field);
        }
    }
    try {
        document.reset();
    } catch (IOException e) {
        throw new AtlasException(e);
    }
    CsvFields csvFields = new CsvFields();
    csvFields.getCsvField().addAll(fields);
    CsvComplexType csvComplexType = new CsvComplexType();
    csvComplexType.setFieldType(FieldType.COMPLEX);
    csvComplexType.setCollectionType(CollectionType.LIST);
    csvComplexType.setPath("/<>");
    csvComplexType.setName("");
    csvComplexType.setCsvFields(csvFields);
    Fields documentFields = new Fields();
    documentFields.getField().add(csvComplexType);
    Document document = new Document();
    document.setFields(documentFields);
    return document;
}
Also used : InputStreamReader(java.io.InputStreamReader) CsvComplexType(io.atlasmap.csv.v2.CsvComplexType) CsvFields(io.atlasmap.csv.v2.CsvFields) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AtlasException(io.atlasmap.api.AtlasException) Document(io.atlasmap.v2.Document) CsvFields(io.atlasmap.csv.v2.CsvFields) Fields(io.atlasmap.v2.Fields) CsvField(io.atlasmap.csv.v2.CsvField) CSVParser(org.apache.commons.csv.CSVParser) CSVFormat(org.apache.commons.csv.CSVFormat) CSVRecord(org.apache.commons.csv.CSVRecord)

Example 19 with Rdb$fields

use of org.jooq.util.firebird.rdb.tables.Rdb$fields in project atlasmap by atlasmap.

the class XmlInstanceInspector method inspect.

/**
 * Inspects the XML instance.
 * @param document XML instance
 */
public void inspect(Document document) {
    xmlDocument.setFields(new Fields());
    parseDocument(document.getDocumentElement());
}
Also used : XmlFields(io.atlasmap.xml.v2.XmlFields) Fields(io.atlasmap.v2.Fields)

Example 20 with Rdb$fields

use of org.jooq.util.firebird.rdb.tables.Rdb$fields in project atlasmap by atlasmap.

the class XmlSchemaInspector method doInspect.

private void doInspect(InputStream is) throws Exception {
    xmlDocument = AtlasXmlModelFactory.createXmlDocument();
    Fields fields = new Fields();
    xmlDocument.setFields(fields);
    AtlasXmlSchemaSetParser parser = new AtlasXmlSchemaSetParser(this.classLoader);
    XSSchemaSet schemaSet = parser.parse(is);
    this.namespaceContext = parser.getNamespaceContext();
    this.rootNamespace = parser.getRootNamespace();
    printSchemaSet(schemaSet);
    populateNamespaces();
}
Also used : XmlFields(io.atlasmap.xml.v2.XmlFields) XmlEnumFields(io.atlasmap.xml.v2.XmlEnumFields) Fields(io.atlasmap.v2.Fields) XSSchemaSet(com.sun.xml.xsom.XSSchemaSet) AtlasXmlSchemaSetParser(io.atlasmap.xml.core.schema.AtlasXmlSchemaSetParser)

Aggregations

Fields (io.atlasmap.v2.Fields)15 Record (org.jooq.Record)9 Document (io.atlasmap.v2.Document)8 ArrayList (java.util.ArrayList)7 Test (org.junit.jupiter.api.Test)7 DefaultDataTypeDefinition (org.jooq.meta.DefaultDataTypeDefinition)5 Rdb$fields (org.jooq.meta.firebird.rdb.tables.Rdb$fields)5 XmlFields (io.atlasmap.xml.v2.XmlFields)4 DataTypeDefinition (org.jooq.meta.DataTypeDefinition)3 ColumnDefinition (org.jooq.util.ColumnDefinition)3 DefaultDataTypeDefinition (org.jooq.util.DefaultDataTypeDefinition)3 Rdb$fields (org.jooq.util.firebird.rdb.tables.Rdb$fields)3 XSSchemaSet (com.sun.xml.xsom.XSSchemaSet)2 Rdb$functionArguments (org.jooq.meta.firebird.rdb.tables.Rdb$functionArguments)2 Rdb$procedureParameters (org.jooq.meta.firebird.rdb.tables.Rdb$procedureParameters)2 DefaultColumnDefinition (org.jooq.util.DefaultColumnDefinition)2 Rdb$procedureParameters (org.jooq.util.firebird.rdb.tables.Rdb$procedureParameters)2 XSOMParser (com.sun.xml.xsom.parser.XSOMParser)1 DomAnnotationParserFactory (com.sun.xml.xsom.util.DomAnnotationParserFactory)1 AtlasException (io.atlasmap.api.AtlasException)1