Search in sources :

Example 1 with GeneratedXmlFile

use of org.mybatis.generator.api.GeneratedXmlFile in project generator by mybatis.

the class IntrospectedTableMyBatis3Impl method getGeneratedXmlFiles.

/* (non-Javadoc)
     * @see org.mybatis.generator.api.IntrospectedTable#getGeneratedXmlFiles()
     */
@Override
public List<GeneratedXmlFile> getGeneratedXmlFiles() {
    List<GeneratedXmlFile> answer = new ArrayList<GeneratedXmlFile>();
    if (xmlMapperGenerator != null) {
        Document document = xmlMapperGenerator.getDocument();
        GeneratedXmlFile gxf = new GeneratedXmlFile(document, getMyBatis3XmlMapperFileName(), getMyBatis3XmlMapperPackage(), context.getSqlMapGeneratorConfiguration().getTargetProject(), true, context.getXmlFormatter());
        if (context.getPlugins().sqlMapGenerated(gxf, this)) {
            answer.add(gxf);
        }
    }
    return answer;
}
Also used : ArrayList(java.util.ArrayList) Document(org.mybatis.generator.api.dom.xml.Document) GeneratedXmlFile(org.mybatis.generator.api.GeneratedXmlFile)

Example 2 with GeneratedXmlFile

use of org.mybatis.generator.api.GeneratedXmlFile in project generator by mybatis.

the class XmlFileMergerTest method testThatFilesAreTheSameAfterMerge.

@Test
public void testThatFilesAreTheSameAfterMerge() throws Exception {
    DefaultXmlFormatter xmlFormatter = new DefaultXmlFormatter();
    Properties p = new Properties();
    p.setProperty(PropertyRegistry.COMMENT_GENERATOR_SUPPRESS_DATE, "true");
    CommentGenerator commentGenerator = new DefaultCommentGenerator();
    commentGenerator.addConfigurationProperties(p);
    Document document = new Document(XmlConstants.MYBATIS3_MAPPER_PUBLIC_ID, XmlConstants.MYBATIS3_MAPPER_SYSTEM_ID);
    document.setRootElement(getSqlMapElement(commentGenerator));
    GeneratedXmlFile generatedFile1 = new GeneratedXmlFile(document, "TestMapper.xml", "org.mybatis.test", "src", true, xmlFormatter);
    InputSource is1 = new InputSource(new StringReader(generatedFile1.getFormattedContent()));
    GeneratedXmlFile generatedFile2 = new GeneratedXmlFile(document, "TestMapper.xml", "org.mybatis.test", "src", true, xmlFormatter);
    InputSource is2 = new InputSource(new StringReader(generatedFile2.getFormattedContent()));
    String mergedSource = XmlFileMergerJaxp.getMergedSource(is1, is2, "TestMapper.xml");
    assertEquals(generatedFile1.getFormattedContent(), mergedSource);
}
Also used : DefaultXmlFormatter(org.mybatis.generator.api.dom.DefaultXmlFormatter) InputSource(org.xml.sax.InputSource) CommentGenerator(org.mybatis.generator.api.CommentGenerator) StringReader(java.io.StringReader) Properties(java.util.Properties) Document(org.mybatis.generator.api.dom.xml.Document) GeneratedXmlFile(org.mybatis.generator.api.GeneratedXmlFile) Test(org.junit.Test)

Example 3 with GeneratedXmlFile

use of org.mybatis.generator.api.GeneratedXmlFile in project generator by mybatis.

the class IntrospectedTableIbatis2Java2Impl method getGeneratedXmlFiles.

@Override
public List<GeneratedXmlFile> getGeneratedXmlFiles() {
    List<GeneratedXmlFile> answer = new ArrayList<GeneratedXmlFile>();
    Document document = sqlMapGenerator.getDocument();
    GeneratedXmlFile gxf = new GeneratedXmlFile(document, getIbatis2SqlMapFileName(), getIbatis2SqlMapPackage(), context.getSqlMapGeneratorConfiguration().getTargetProject(), true, context.getXmlFormatter());
    if (context.getPlugins().sqlMapGenerated(gxf, this)) {
        answer.add(gxf);
    }
    return answer;
}
Also used : ArrayList(java.util.ArrayList) Document(org.mybatis.generator.api.dom.xml.Document) GeneratedXmlFile(org.mybatis.generator.api.GeneratedXmlFile)

Example 4 with GeneratedXmlFile

use of org.mybatis.generator.api.GeneratedXmlFile in project generator by mybatis.

the class MapperConfigPlugin method contextGenerateAdditionalXmlFiles.

@Override
public List<GeneratedXmlFile> contextGenerateAdditionalXmlFiles() {
    Document document = new Document(XmlConstants.MYBATIS3_MAPPER_CONFIG_PUBLIC_ID, XmlConstants.MYBATIS3_MAPPER_CONFIG_SYSTEM_ID);
    //$NON-NLS-1$
    XmlElement root = new XmlElement("configuration");
    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 a Mapper Config file - in many cases you will need to add"));
    root.addElement(new TextElement(//$NON-NLS-1$
    "    to this file before it is usable by MyBatis."));
    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 mappers = new XmlElement("mappers");
    root.addElement(mappers);
    XmlElement mapper;
    for (String mapperFile : mapperFiles) {
        //$NON-NLS-1$
        mapper = new XmlElement("mapper");
        //$NON-NLS-1$
        mapper.addAttribute(new Attribute("resource", mapperFile));
        mappers.addElement(mapper);
    }
    GeneratedXmlFile gxf = new GeneratedXmlFile(document, properties.getProperty("fileName", //$NON-NLS-1$ //$NON-NLS-2$
    "MapperConfig.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 5 with GeneratedXmlFile

use of org.mybatis.generator.api.GeneratedXmlFile 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)

Aggregations

GeneratedXmlFile (org.mybatis.generator.api.GeneratedXmlFile)5 Document (org.mybatis.generator.api.dom.xml.Document)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)2 Attribute (org.mybatis.generator.api.dom.xml.Attribute)2 TextElement (org.mybatis.generator.api.dom.xml.TextElement)2 XmlElement (org.mybatis.generator.api.dom.xml.XmlElement)2 Messages.getString (org.mybatis.generator.internal.util.messages.Messages.getString)2 StringReader (java.io.StringReader)1 Properties (java.util.Properties)1 Test (org.junit.Test)1 CommentGenerator (org.mybatis.generator.api.CommentGenerator)1 DefaultXmlFormatter (org.mybatis.generator.api.dom.DefaultXmlFormatter)1 InputSource (org.xml.sax.InputSource)1