org.mybatis.generator.config.MergeConstants Java Examples

The following examples show how to use org.mybatis.generator.config.MergeConstants. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmlFileMergerJaxp.java    From mapper-generator-javafx with Apache License 2.0 6 votes vote down vote up
private static boolean isNewFormatNode(Node node) {
    // check for new node format - if the first non-whitespace node
    // is an XML comment, and the comment includes
    // one of the old element tags,
    // then it is a generated node
    NodeList children = node.getChildNodes();
    int length = children.getLength();
    for (int i = 0; i < length; i++) {
        Node childNode = children.item(i);
        if (childNode != null && childNode.getNodeType() == Node.COMMENT_NODE) {
            String commentData = ((Comment) childNode).getData();
            return MergeConstants.comentContainsTag(commentData);
        }
    }
    
    return false;
}
 
Example #2
Source File: DefaultCommentGenerator.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
/**
 * This method adds the custom javadoc tag for. You may do nothing if you do
 * not wish to include the Javadoc tag - however, if you do not include the
 * Javadoc tag then the Java merge capability of the eclipse plugin will
 * break.
 * 
 * @param javaElement
 *            the java element
 */
protected void addJavadocTag(JavaElement javaElement,
        boolean markAsDoNotDelete) {
    javaElement.addJavaDocLine(" *"); //$NON-NLS-1$
    StringBuilder sb = new StringBuilder();
    sb.append(" * "); //$NON-NLS-1$
    sb.append(MergeConstants.NEW_ELEMENT_TAG);
    if (markAsDoNotDelete) {
        sb.append(" do_not_delete_during_merge"); //$NON-NLS-1$
    }
    String s = getDateString();
    if (s != null) {
        sb.append(' ');
        sb.append(s);
    }
    javaElement.addJavaDocLine(sb.toString());
}
 
Example #3
Source File: DG2CommentGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
@Override
    public void addComment(XmlElement xmlElement) {
        xmlElement.addElement(new TextElement("<!--")); //$NON-NLS-1$

        StringBuilder sb = new StringBuilder();
        sb.append(MergeConstants.NEW_ELEMENT_TAG);
        xmlElement.addElement(new TextElement(sb.toString()));
//        xmlElement
//                .addElement(new TextElement(
//                        "  This element is automatically generated by MyBatis Generator, do not modify.")); //$NON-NLS-1$

//        String s = getDateString();
//        if (s != null) {
//            sb.setLength(0);
//            sb.append("  This element was generated on "); //$NON-NLS-1$
//            sb.append(s);
//            sb.append('.');
//            xmlElement.addElement(new TextElement(sb.toString()));
//        }

        xmlElement.addElement(new TextElement("-->")); //$NON-NLS-1$
    }
 
Example #4
Source File: DefaultCommentGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
/**
 * This method adds the custom javadoc tag for. You may do nothing if you do not wish to include the Javadoc tag -
 * however, if you do not include the Javadoc tag then the Java merge capability of the eclipse plugin will break.
 *
 * @param javaElement       the java element
 * @param markAsDoNotDelete the mark as do not delete
 */
protected void addJavadocTag(JavaElement javaElement,
                             boolean markAsDoNotDelete) {
    javaElement.addJavaDocLine(" *"); //$NON-NLS-1$
    StringBuilder sb = new StringBuilder();
    sb.append(" * "); //$NON-NLS-1$
    sb.append(MergeConstants.NEW_ELEMENT_TAG);
    if (markAsDoNotDelete) {
        sb.append(" do_not_delete_during_merge"); //$NON-NLS-1$
    }
    String s = getDateString();
    if (s != null) {
        sb.append(' ');
        sb.append(s);
    }
    javaElement.addJavaDocLine(sb.toString());
}
 
Example #5
Source File: DGCommentGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
@Override
    public void addComment(XmlElement xmlElement) {
        xmlElement.addElement(new TextElement("<!--")); //$NON-NLS-1$

        StringBuilder sb = new StringBuilder();
        sb.append(MergeConstants.NEW_ELEMENT_TAG);
        xmlElement.addElement(new TextElement(sb.toString()));
//        xmlElement
//                .addElement(new TextElement(
//                        "  This element is automatically generated by MyBatis Generator, do not modify.")); //$NON-NLS-1$

//        String s = getDateString();
//        if (s != null) {
//            sb.setLength(0);
//            sb.append("  This element was generated on "); //$NON-NLS-1$
//            sb.append(s);
//            sb.append('.');
//            xmlElement.addElement(new TextElement(sb.toString()));
//        }

        xmlElement.addElement(new TextElement("-->")); //$NON-NLS-1$
    }
 
Example #6
Source File: DefaultCommentGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a suitable comment to warn users that the element was generated, and when it was generated.
 *
 * @param xmlElement the xml element
 */
//xml注释
public void addComment(XmlElement xmlElement) {
    if (suppressAllComments) {
        return;
    }

    xmlElement.addElement(new TextElement("<!--")); //$NON-NLS-1$

    StringBuilder sb = new StringBuilder();
    sb.append("  WARNING - "); //$NON-NLS-1$
    sb.append(MergeConstants.NEW_ELEMENT_TAG);
    xmlElement.addElement(new TextElement(sb.toString()));
    xmlElement
            .addElement(new TextElement(
                    "  This element is automatically generated by MyBatis Generator, do not modify.")); //$NON-NLS-1$

    String s = getDateString();
    if (s != null) {
        sb.setLength(0);
        sb.append("  This element was generated on "); //$NON-NLS-1$
        sb.append(s);
        sb.append('.');
        xmlElement.addElement(new TextElement(sb.toString()));
    }

    xmlElement.addElement(new TextElement("-->")); //$NON-NLS-1$
}
 
Example #7
Source File: MyBatisGenerator.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
private void writeGeneratedJavaFile(GeneratedJavaFile gjf, ProgressCallback callback)
        throws InterruptedException, IOException {
    File targetFile;
    String source;
    try {
        File directory = shellCallback.getDirectory(gjf.getTargetProject(), gjf.getTargetPackage());
        targetFile = new File(directory, gjf.getFileName());
        if (targetFile.exists()) {
            if (shellCallback.isMergeSupported()) {
                source = shellCallback.mergeJavaFile(
                        gjf.getFormattedContent(),
                        targetFile,
                        MergeConstants.getOldElementTags(),
                        gjf.getFileEncoding());
            } else {
                source = checkInner(targetFile, directory, gjf);
            }
        } else {
            source = gjf.getFormattedContent();
        }

        callback.checkCancel();
        callback.startTask(getString("Progress.15", targetFile.getName()));
        writeFile(targetFile, source, gjf.getFileEncoding());
    } catch (ShellException e) {
        warnings.add(e.getMessage());
    }
}
 
Example #8
Source File: CommentPluginTest.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * 测试配置了模板参数转换
 */
@Test
public void testGenerateWithTemplate() throws Exception {
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/CommentPlugin/mybatis-generator.xml");
    MyBatisGenerator myBatisGenerator = tool.generate();

    // java中的注释
    for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()) {
        if (file.getFileName().equals("Tb.java")) {
            TopLevelClass topLevelClass = (TopLevelClass) file.getCompilationUnit();
            // addJavaFileComment
            Assert.assertEquals(topLevelClass.getFileCommentLines().get(0), "TestAddJavaFileComment:Tb:" + new SimpleDateFormat("yyyy-MM").format(new Date()));
            // addFieldComment 同时测试 if 判断和 mbg
            Field id = topLevelClass.getFields().get(0);
            Assert.assertEquals(id.getJavaDocLines().get(0), "注释1");
            Assert.assertEquals(id.getJavaDocLines().get(1), MergeConstants.NEW_ELEMENT_TAG);
            // addGeneralMethodComment
            Method cons = topLevelClass.getMethods().get(0);
            Assert.assertEquals(cons.getJavaDocLines().get(0), "addGeneralMethodComment:Tb:tb");
            // addSetterComment
            Method setter = topLevelClass.getMethods().get(5);
            Assert.assertEquals(setter.getJavaDocLines().get(0), "addSetterComment:field1:field1");
        }
    }

    // xml注释
    ObjectUtil xml = new ObjectUtil(myBatisGenerator.getGeneratedXmlFiles().get(0));
    Document doc = (Document) xml.get("document");
    List<Element> els = ((XmlElement) (doc.getRootElement().getElements().get(0))).getElements();
    String comment = ((TextElement) els.get(0)).getContent();
    Assert.assertEquals(comment, "addComment:BaseResultMap");
}
 
Example #9
Source File: BugFixedTest.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * 测试批量batchUpsert存在主键的情况
 * https://github.com/itfsw/mybatis-generator-plugin/issues/77
 * @throws Exception
 */
@Test
public void issues81() throws Exception {
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/BugFixedTest/issues-81.xml");
    MyBatisGenerator myBatisGenerator = tool.generate(() -> DBHelper.createDB("scripts/BugFixedTest/issues-81.sql"));

    // 是否在使用系统默认模板
    int count = 0;
    for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()) {
        if (file.getFormattedContent().indexOf(MergeConstants.NEW_ELEMENT_TAG) != -1) {
            count++;
        }
    }
    Assert.assertTrue(count == 0);
}
 
Example #10
Source File: MapperCommentGenerator.java    From azeroth with Apache License 2.0 5 votes vote down vote up
/**
 * xml中的注释
 *
 * @param xmlElement
 */
public void addComment(XmlElement xmlElement) {
    xmlElement.addElement(new TextElement("<!--"));
    StringBuilder sb = new StringBuilder();
    sb.append("  WARNING - ");
    sb.append(MergeConstants.NEW_ELEMENT_TAG);
    xmlElement.addElement(new TextElement(sb.toString()));
    xmlElement.addElement(new TextElement("-->"));
}
 
Example #11
Source File: MapperCommentGenerator.java    From azeroth with Apache License 2.0 5 votes vote down vote up
/**
 * 删除标记
 *
 * @param javaElement
 * @param markAsDoNotDelete
 */
protected void addJavadocTag(JavaElement javaElement, boolean markAsDoNotDelete) {
    StringBuilder sb = new StringBuilder();
    sb.append(" * ");
    sb.append(MergeConstants.NEW_ELEMENT_TAG);
    if (markAsDoNotDelete) {
        sb.append(" do_not_delete_during_merge");
    }
    javaElement.addJavaDocLine(sb.toString());
}
 
Example #12
Source File: MapperCommentGenerator.java    From jeesuite-libs with Apache License 2.0 5 votes vote down vote up
/**
 * xml中的注释
 *
 * @param xmlElement
 */
public void addComment(XmlElement xmlElement) {
    xmlElement.addElement(new TextElement("<!--"));
    StringBuilder sb = new StringBuilder();
    sb.append("  WARNING - ");
    sb.append(MergeConstants.NEW_ELEMENT_TAG);
    xmlElement.addElement(new TextElement(sb.toString()));
    xmlElement.addElement(new TextElement("-->"));
}
 
Example #13
Source File: MapperCommentGenerator.java    From jeesuite-libs with Apache License 2.0 5 votes vote down vote up
/**
 * 删除标记
 *
 * @param javaElement
 * @param markAsDoNotDelete
 */
protected void addJavadocTag(JavaElement javaElement, boolean markAsDoNotDelete) {
    StringBuilder sb = new StringBuilder();
    sb.append(" * ");
    sb.append(MergeConstants.NEW_ELEMENT_TAG);
    if (markAsDoNotDelete) {
        sb.append(" do_not_delete_during_merge");
    }
    javaElement.addJavaDocLine(sb.toString());
}
 
Example #14
Source File: TemplateCommentGenerator.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * This method is called to add a comment as the first child of the root element. This method could be used to add a
 * general file comment (such as a copyright notice). However, note that the XML file merge function does not deal
 * with this comment. If you run the generator repeatedly, you will only retain the comment from the initial run.
 * <p>
 *
 * The default implementation does nothing.
 * @param rootElement the root element
 */
@Override
public void addRootComment(XmlElement rootElement) {
    Map<String, Object> map = new HashMap<>();
    map.put("mgb", MergeConstants.NEW_ELEMENT_TAG);
    map.put("rootElement", rootElement);

    // 添加评论
    addXmlElementComment(rootElement, map, EnumNode.ADD_ROOT_COMMENT);
}
 
Example #15
Source File: DefaultCommentGenerator.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a suitable comment to warn users that the element was generated, and
 * when it was generated.
 */
public void addComment(XmlElement xmlElement) {
    if (suppressAllComments) {
        return;
    }

    xmlElement.addElement(new TextElement("<!--")); //$NON-NLS-1$

    StringBuilder sb = new StringBuilder();
    sb.append("  WARNING - "); //$NON-NLS-1$
    sb.append(MergeConstants.NEW_ELEMENT_TAG);
    xmlElement.addElement(new TextElement(sb.toString()));
    xmlElement
            .addElement(new TextElement(
                    "  This element is automatically generated by MyBatis Generator, do not modify.")); //$NON-NLS-1$

    String s = getDateString();
    if (s != null) {
        sb.setLength(0);
        sb.append("  This element was generated on "); //$NON-NLS-1$
        sb.append(s);
        sb.append('.');
        xmlElement.addElement(new TextElement(sb.toString()));
    }

    xmlElement.addElement(new TextElement("-->")); //$NON-NLS-1$
}
 
Example #16
Source File: MapperCommentGenerator.java    From Mapper with MIT License 5 votes vote down vote up
/**
 * xml中的注释
 *
 * @param xmlElement
 */
@Override
public void addComment(XmlElement xmlElement) {
    xmlElement.addElement(new TextElement("<!--"));
    StringBuilder sb = new StringBuilder();
    sb.append("  WARNING - ");
    sb.append(MergeConstants.NEW_ELEMENT_TAG);
    xmlElement.addElement(new TextElement(sb.toString()));
    xmlElement.addElement(new TextElement("-->"));
}
 
Example #17
Source File: MapperCommentGenerator.java    From Mapper with MIT License 5 votes vote down vote up
/**
 * 删除标记
 *
 * @param javaElement
 * @param markAsDoNotDelete
 */
protected void addJavadocTag(JavaElement javaElement, boolean markAsDoNotDelete) {
    StringBuilder sb = new StringBuilder();
    sb.append(" * ");
    sb.append(MergeConstants.NEW_ELEMENT_TAG);
    if (markAsDoNotDelete) {
        sb.append(" do_not_delete_during_merge");
    }
    javaElement.addJavaDocLine(sb.toString());
}
 
Example #18
Source File: TemplateCommentGenerator.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Adds the field comment.
 * @param field             the field
 * @param introspectedTable the introspected table
 */
@Override
public void addFieldComment(Field field, IntrospectedTable introspectedTable) {
    Map<String, Object> map = new HashMap<>();
    map.put("mgb", MergeConstants.NEW_ELEMENT_TAG);
    map.put("field", field);
    map.put("introspectedTable", introspectedTable);

    // 添加评论
    addJavaElementComment(field, map, EnumNode.ADD_FIELD_COMMENT);
}
 
Example #19
Source File: XmlFileMergerJaxp.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
private static boolean isOldFormatNode(Node node) {
    Element element = (Element) node;
    String id = element.getAttribute("id");
    if (id != null) {
        return MergeConstants.idStartsWithPrefix(id);
    }
    
    return false;
}
 
Example #20
Source File: MyMapperCommentGenerator.java    From jvue-admin with MIT License 5 votes vote down vote up
/**
 * xml中的注释
 *
 * @param xmlElement
 */
@Override
public void addComment(XmlElement xmlElement) {
    xmlElement.addElement(new TextElement("<!--"));
    StringBuilder sb = new StringBuilder();
    sb.append("  WARNING - ");
    sb.append(MergeConstants.NEW_ELEMENT_TAG);
    xmlElement.addElement(new TextElement(sb.toString()));
    xmlElement.addElement(new TextElement("-->"));
}
 
Example #21
Source File: MyMapperCommentGenerator.java    From jvue-admin with MIT License 5 votes vote down vote up
/**
 * 删除标记
 *
 * @param javaElement
 * @param markAsDoNotDelete
 */
protected void addJavadocTag(JavaElement javaElement, boolean markAsDoNotDelete) {
    StringBuilder sb = new StringBuilder();
    sb.append(" * ");
    sb.append(MergeConstants.NEW_ELEMENT_TAG);
    if (markAsDoNotDelete) {
        sb.append(" do_not_delete_during_merge");
    }
    javaElement.addJavaDocLine(sb.toString());
}
 
Example #22
Source File: MapperCommentGenerator.java    From tk-mybatis with MIT License 5 votes vote down vote up
/**
 * xml中的注释
 *
 * @param xmlElement
 */
public void addComment(XmlElement xmlElement) {
    xmlElement.addElement(new TextElement("<!--"));
    StringBuilder sb = new StringBuilder();
    sb.append("  WARNING - ");
    sb.append(MergeConstants.NEW_ELEMENT_TAG);
    xmlElement.addElement(new TextElement(sb.toString()));
    xmlElement.addElement(new TextElement("-->"));
}
 
Example #23
Source File: MapperCommentGenerator.java    From tk-mybatis with MIT License 5 votes vote down vote up
/**
 * 删除标记
 *
 * @param javaElement
 * @param markAsDoNotDelete
 */
protected void addJavadocTag(JavaElement javaElement, boolean markAsDoNotDelete) {
    StringBuilder sb = new StringBuilder();
    sb.append(" * ");
    sb.append(MergeConstants.NEW_ELEMENT_TAG);
    if (markAsDoNotDelete) {
        sb.append(" do_not_delete_during_merge");
    }
    javaElement.addJavaDocLine(sb.toString());
}
 
Example #24
Source File: TemplateCommentGenerator.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * This method should add a Javadoc comment to the specified field. The field is related to the specified table and
 * is used to hold the value of the specified column.
 * <p>
 *
 * <b>Important:</b> This method should add a the nonstandard JavaDoc tag "@mbg.generated" to the comment. Without
 * this tag, the Eclipse based Java merge feature will fail.
 * @param field              the field
 * @param introspectedTable  the introspected table
 * @param introspectedColumn the introspected column
 */
@Override
public void addFieldComment(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
    Map<String, Object> map = new HashMap<>();
    map.put("mgb", MergeConstants.NEW_ELEMENT_TAG);
    map.put("field", field);
    map.put("introspectedTable", introspectedTable);
    map.put("introspectedColumn", introspectedColumn);

    // 添加评论
    addJavaElementComment(field, map, EnumNode.ADD_FIELD_COMMENT);
}
 
Example #25
Source File: TemplateCommentGenerator.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * This method should add a suitable comment as a child element of the specified xmlElement to warn users that the
 * element was generated and is subject to regeneration.
 * @param xmlElement the xml element
 */
@Override
public void addComment(XmlElement xmlElement) {
    Map<String, Object> map = new HashMap<>();
    map.put("mgb", MergeConstants.NEW_ELEMENT_TAG);
    map.put("xmlElement", xmlElement);

    // 添加评论
    addXmlElementComment(xmlElement, map, EnumNode.ADD_COMMENT);
}
 
Example #26
Source File: TemplateCommentGenerator.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Adds the inner class comment.
 * @param innerClass        the inner class
 * @param introspectedTable the introspected table
 * @param markAsDoNotDelete the mark as do not delete
 */
@Override
public void addClassComment(InnerClass innerClass, IntrospectedTable introspectedTable, boolean markAsDoNotDelete) {
    Map<String, Object> map = new HashMap<>();
    map.put("mgb", MergeConstants.NEW_ELEMENT_TAG);
    map.put("innerClass", innerClass);
    map.put("introspectedTable", introspectedTable);
    map.put("markAsDoNotDelete", markAsDoNotDelete);

    // 添加评论
    addJavaElementComment(innerClass, map, EnumNode.ADD_CLASS_COMMENT);
}
 
Example #27
Source File: TemplateCommentGenerator.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Adds the enum comment.
 * @param innerEnum         the inner enum
 * @param introspectedTable the introspected table
 */
@Override
public void addEnumComment(InnerEnum innerEnum, IntrospectedTable introspectedTable) {
    Map<String, Object> map = new HashMap<>();
    map.put("mgb", MergeConstants.NEW_ELEMENT_TAG);
    map.put("innerEnum", innerEnum);
    map.put("introspectedTable", introspectedTable);

    // 添加评论
    addJavaElementComment(innerEnum, map, EnumNode.ADD_ENUM_COMMENT);
}
 
Example #28
Source File: TemplateCommentGenerator.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Adds the getter comment.
 * @param method             the method
 * @param introspectedTable  the introspected table
 * @param introspectedColumn the introspected column
 */
@Override
public void addGetterComment(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
    Map<String, Object> map = new HashMap<>();
    map.put("mgb", MergeConstants.NEW_ELEMENT_TAG);
    map.put("method", method);
    map.put("introspectedTable", introspectedTable);
    map.put("introspectedColumn", introspectedColumn);

    // 添加评论
    addJavaElementComment(method, map, EnumNode.ADD_GETTER_COMMENT);
}
 
Example #29
Source File: TemplateCommentGenerator.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Adds the setter comment.
 * @param method             the method
 * @param introspectedTable  the introspected table
 * @param introspectedColumn the introspected column
 */
@Override
public void addSetterComment(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
    Map<String, Object> map = new HashMap<>();
    map.put("mgb", MergeConstants.NEW_ELEMENT_TAG);
    map.put("method", method);
    map.put("introspectedTable", introspectedTable);
    map.put("introspectedColumn", introspectedColumn);

    // 添加评论
    addJavaElementComment(method, map, EnumNode.ADD_SETTER_COMMENT);
}
 
Example #30
Source File: TemplateCommentGenerator.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Adds the general method comment.
 * @param method            the method
 * @param introspectedTable the introspected table
 */
@Override
public void addGeneralMethodComment(Method method, IntrospectedTable introspectedTable) {
    Map<String, Object> map = new HashMap<>();
    map.put("mgb", MergeConstants.NEW_ELEMENT_TAG);
    map.put("method", method);
    map.put("introspectedTable", introspectedTable);

    // 添加评论
    addJavaElementComment(method, map, EnumNode.ADD_GENERAL_METHOD_COMMENT);
}