Search in sources :

Example 71 with Attribute

use of org.mybatis.generator.api.dom.xml.Attribute in project generator by mybatis.

the class RowBoundsPlugin method copyAndSaveElement.

/**
     * Use the method copy constructor to create a new element
     * 
     * @param fullyQualifiedTable
     * @param method
     */
private void copyAndSaveElement(XmlElement element, FullyQualifiedTable fqt) {
    XmlElement newElement = new XmlElement(element);
    // remove old id attribute and add a new one with the new name
    for (Iterator<Attribute> iterator = newElement.getAttributes().iterator(); iterator.hasNext(); ) {
        Attribute attribute = iterator.next();
        if ("id".equals(attribute.getName())) {
            //$NON-NLS-1$
            iterator.remove();
            //$NON-NLS-1$ //$NON-NLS-2$
            Attribute newAttribute = new Attribute("id", attribute.getValue() + "WithRowbounds");
            newElement.addAttribute(newAttribute);
            break;
        }
    }
    // save the new element locally.   We'll add it to the document
    // later
    List<XmlElement> elements = elementsToAdd.get(fqt);
    if (elements == null) {
        elements = new ArrayList<XmlElement>();
        elementsToAdd.put(fqt, elements);
    }
    elements.add(newElement);
}
Also used : Attribute(org.mybatis.generator.api.dom.xml.Attribute) XmlElement(org.mybatis.generator.api.dom.xml.XmlElement)

Example 72 with Attribute

use of org.mybatis.generator.api.dom.xml.Attribute in project generator by mybatis.

the class SqlMapConfigPlugin method contextGenerateAdditionalXmlFiles.

@Override
public List<GeneratedXmlFile> contextGenerateAdditionalXmlFiles() {
    Document document = new Document(XmlConstants.IBATIS2_SQL_MAP_CONFIG_PUBLIC_ID, XmlConstants.IBATIS2_SQL_MAP_CONFIG_SYSTEM_ID);
    //$NON-NLS-1$
    XmlElement root = new XmlElement("sqlMapConfig");
    document.setRootElement(root);
    //$NON-NLS-1$
    root.addElement(new TextElement("<!--"));
    root.addElement(new TextElement(//$NON-NLS-1$
    "  This file is generated by MyBatis Generator."));
    root.addElement(new TextElement(//$NON-NLS-1$
    "  This file is the shell of an SqlMapConfig file - in many cases you will need to add"));
    root.addElement(new TextElement(//$NON-NLS-1$
    "    to this file before it is usable by iBATIS."));
    StringBuilder sb = new StringBuilder();
    //$NON-NLS-1$
    sb.append("  This file was generated on ");
    sb.append(new Date());
    sb.append('.');
    root.addElement(new TextElement(sb.toString()));
    //$NON-NLS-1$
    root.addElement(new TextElement("-->"));
    //$NON-NLS-1$
    XmlElement settings = new XmlElement("settings");
    //$NON-NLS-1$ //$NON-NLS-2$
    settings.addAttribute(new Attribute("useStatementNamespaces", "true"));
    root.addElement(settings);
    XmlElement sqlMap;
    for (String sqlMapFile : sqlMapFiles) {
        //$NON-NLS-1$
        sqlMap = new XmlElement("sqlMap");
        //$NON-NLS-1$
        sqlMap.addAttribute(new Attribute("resource", sqlMapFile));
        root.addElement(sqlMap);
    }
    GeneratedXmlFile gxf = new GeneratedXmlFile(document, properties.getProperty("fileName", //$NON-NLS-1$ //$NON-NLS-2$
    "SqlMapConfig.xml"), //$NON-NLS-1$
    properties.getProperty("targetPackage"), //$NON-NLS-1$
    properties.getProperty("targetProject"), false, context.getXmlFormatter());
    List<GeneratedXmlFile> answer = new ArrayList<GeneratedXmlFile>(1);
    answer.add(gxf);
    return answer;
}
Also used : TextElement(org.mybatis.generator.api.dom.xml.TextElement) Attribute(org.mybatis.generator.api.dom.xml.Attribute) ArrayList(java.util.ArrayList) XmlElement(org.mybatis.generator.api.dom.xml.XmlElement) Messages.getString(org.mybatis.generator.internal.util.messages.Messages.getString) Document(org.mybatis.generator.api.dom.xml.Document) Date(java.util.Date) GeneratedXmlFile(org.mybatis.generator.api.GeneratedXmlFile)

Example 73 with Attribute

use of org.mybatis.generator.api.dom.xml.Attribute in project generator by mybatis.

the class XmlFileMergerTest method addInsertElement.

private void addInsertElement(CommentGenerator commentGenerator, XmlElement parentElement) {
    XmlElement answer = new XmlElement("insert");
    answer.addAttribute(new Attribute("id", "insert"));
    FullyQualifiedJavaType parameterType;
    parameterType = new FullyQualifiedJavaType("org.mybatis.test.TestRecord");
    answer.addAttribute(new Attribute("parameterType", parameterType.getFullyQualifiedName()));
    commentGenerator.addComment(answer);
    StringBuilder insertClause = new StringBuilder();
    StringBuilder valuesClause = new StringBuilder();
    insertClause.append("insert into ");
    insertClause.append("myschema.mytable");
    insertClause.append(" (id, description)");
    valuesClause.append("values (#{id}, #{description})");
    answer.addElement(new TextElement(insertClause.toString()));
    answer.addElement(new TextElement(valuesClause.toString()));
    parentElement.addElement(answer);
}
Also used : TextElement(org.mybatis.generator.api.dom.xml.TextElement) Attribute(org.mybatis.generator.api.dom.xml.Attribute) FullyQualifiedJavaType(org.mybatis.generator.api.dom.java.FullyQualifiedJavaType) XmlElement(org.mybatis.generator.api.dom.xml.XmlElement)

Aggregations

Attribute (org.mybatis.generator.api.dom.xml.Attribute)73 XmlElement (org.mybatis.generator.api.dom.xml.XmlElement)73 TextElement (org.mybatis.generator.api.dom.xml.TextElement)39 IntrospectedColumn (org.mybatis.generator.api.IntrospectedColumn)30 FullyQualifiedJavaType (org.mybatis.generator.api.dom.java.FullyQualifiedJavaType)5 ArrayList (java.util.ArrayList)4 Document (org.mybatis.generator.api.dom.xml.Document)4 GeneratedKey (org.mybatis.generator.config.GeneratedKey)4 Messages.getString (org.mybatis.generator.internal.util.messages.Messages.getString)3 Date (java.util.Date)2 GeneratedXmlFile (org.mybatis.generator.api.GeneratedXmlFile)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1