org.mybatis.generator.api.dom.OutputUtilities Java Examples

The following examples show how to use org.mybatis.generator.api.dom.OutputUtilities. 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: Document.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
public String getFormattedContent() {
    StringBuilder sb = new StringBuilder();

    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); //$NON-NLS-1$

    if (publicId != null && systemId != null) {
        OutputUtilities.newLine(sb);
        sb.append("<!DOCTYPE "); //$NON-NLS-1$
        sb.append(rootElement.getName());
        sb.append(" PUBLIC \""); //$NON-NLS-1$
        sb.append(publicId);
        sb.append("\" \""); //$NON-NLS-1$
        sb.append(systemId);
        sb.append("\" >"); //$NON-NLS-1$
    }

    OutputUtilities.newLine(sb);
    sb.append(rootElement.getFormattedContent(0));

    return sb.toString();
}
 
Example #2
Source File: Document.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the formatted content.
 *
 * @return the formatted content
 */
public String getFormattedContent() {
    StringBuilder sb = new StringBuilder();

    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); //$NON-NLS-1$

    if (publicId != null && systemId != null) {
        OutputUtilities.newLine(sb);
        sb.append("<!DOCTYPE "); //$NON-NLS-1$
        sb.append(rootElement.getName());
        sb.append(" PUBLIC \""); //$NON-NLS-1$
        sb.append(publicId);
        sb.append("\" \""); //$NON-NLS-1$
        sb.append(systemId);
        sb.append("\">"); //$NON-NLS-1$
    }

    OutputUtilities.newLine(sb);
    sb.append(rootElement.getFormattedContent(0));

    return sb.toString();
}
 
Example #3
Source File: FullyQualifiedJavaTypeTest.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Test
public void testImportList() {
    Set<FullyQualifiedJavaType> types = new TreeSet<FullyQualifiedJavaType>();
    
    types.add(new FullyQualifiedJavaType("foo.bar.Example"));
    types.add(new FullyQualifiedJavaType("foo.bar.Example.Criteria"));
    types.add(new FullyQualifiedJavaType("foo.bar.Example.Criterion"));
    assertEquals(3, types.size());
    
    Set<String> imports = OutputUtilities.calculateImports(types);
    assertEquals(3, imports.size());
}
 
Example #4
Source File: ExtendedDocument.java    From dolphin with Apache License 2.0 5 votes vote down vote up
@Override
public String getFormattedContent() {
    StringBuilder sb = new StringBuilder();

    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); //$NON-NLS-1$

    if (getPublicId() != null && getSystemId() != null) {
        OutputUtilities.newLine(sb);
        sb.append("<!DOCTYPE "); //$NON-NLS-1$
        sb.append(getRootElement().getName());
        sb.append(" PUBLIC \""); //$NON-NLS-1$
        sb.append(getPublicId());
        sb.append("\" \""); //$NON-NLS-1$
        sb.append(getSystemId());
        sb.append("\" >"); //$NON-NLS-1$
    }

    // add file comments to the generated string
    if(StringUtils.isNotEmpty(fileComments)) {
        OutputUtilities.newLine(sb);
        sb.append(fileComments);
    }

    OutputUtilities.newLine(sb);
    sb.append(getRootElement().getFormattedContent(0));

    return sb.toString();
}
 
Example #5
Source File: CommentGenerator.java    From dolphin with Apache License 2.0 5 votes vote down vote up
public void addSqlMapFileComment(Document document){

        if(suppressAllComments) return;

        ExtendedDocument ed = null;
        if(document instanceof ExtendedDocument) {
            ed = (ExtendedDocument) document;
        } else return;

        // if user doesn't supplied the xml source copyright then use the default
        String copyright = copyrights.getFormatted("XmlSource", startYear, endYear);
        if(StringUtils.isEmpty(copyright)){
            copyright = defaultCopyrights.getFormatted("XmlSource",startYear,endYear);
        }
        if(StringUtils.isNotEmpty(copyright)) {
            String[] array = copyright.split("\\|");
            StringBuilder sb = new StringBuilder();
            for(String str : array){
                if(!str.startsWith("<!--") && !str.startsWith("-->")){
                    sb.append("    ");
                }
                sb.append(str);
                OutputUtilities.newLine(sb);
            }
            ed.setFileComments(sb.toString());
        }
    }
 
Example #6
Source File: PostgisGeoPlugin.java    From dolphin with Apache License 2.0 5 votes vote down vote up
protected String getContentWithoutOuterTags(XmlElement xe){
	int indentLevel = 0;
	StringBuilder sb = new StringBuilder();
	Iterator<Element> iter = xe.getElements().iterator();
	while(iter.hasNext()){
		sb.append(iter.next().getFormattedContent(indentLevel));
		if(iter.hasNext()){
            OutputUtilities.newLine(sb);				
		}
	}
       return sb.toString();
}
 
Example #7
Source File: XmlElement.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
@Override
public String getFormattedContent(int indentLevel) {
    StringBuilder sb = new StringBuilder();

    OutputUtilities.xmlIndent(sb, indentLevel);
    sb.append('<');
    sb.append(name);

    for (Attribute att : attributes) {
        sb.append(' ');
        sb.append(att.getFormattedContent());
    }

    if (elements.size() > 0) {
        sb.append(" >"); //$NON-NLS-1$
        for (Element element : elements) {
            OutputUtilities.newLine(sb);
            sb.append(element.getFormattedContent(indentLevel + 1));
        }
        OutputUtilities.newLine(sb);
        OutputUtilities.xmlIndent(sb, indentLevel);
        sb.append("</"); //$NON-NLS-1$
        sb.append(name);
        sb.append('>');

    } else {
        sb.append(" />"); //$NON-NLS-1$
    }

    return sb.toString();
}
 
Example #8
Source File: TextElement.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
@Override
public String getFormattedContent(int indentLevel) {
    StringBuilder sb = new StringBuilder();
    OutputUtilities.xmlIndent(sb, indentLevel);
    sb.append(content);
    return sb.toString();
}
 
Example #9
Source File: JavaElement.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
public void addFormattedAnnotations(StringBuilder sb, int indentLevel) {
    for (String annotation : annotations) {
        OutputUtilities.javaIndent(sb, indentLevel);
        sb.append(annotation);
        OutputUtilities.newLine(sb);
    }
}
 
Example #10
Source File: JavaElement.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
public void addFormattedJavadoc(StringBuilder sb, int indentLevel) {
    for (String javaDocLine : javaDocLines) {
        OutputUtilities.javaIndent(sb, indentLevel);
        sb.append(javaDocLine);
        OutputUtilities.newLine(sb);
    }
}
 
Example #11
Source File: MybatisGeneratorPlugin.java    From java-master with Apache License 2.0 5 votes vote down vote up
@Override
public boolean sqlMapDocumentGenerated(Document document, IntrospectedTable introspectedTable) {
    Element element = new Element() {
        @Override
        public String getFormattedContent(int indentLevel) {
            StringBuilder sb = new StringBuilder();
            OutputUtilities.xmlIndent(sb, indentLevel);
            sb.append("<!-- 此文件由 mybatis generator 生成,注意: 请勿手工改动此文件, 请使用 mybatis generator -->");
            return sb.toString();
        }
    };
    document.getRootElement().addElement(0, element);
    return super.sqlMapDocumentGenerated(document, introspectedTable);
}
 
Example #12
Source File: XmlElement.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
public String getFormattedContent(int indentLevel) {
    StringBuilder sb = new StringBuilder();

    OutputUtilities.xmlIndent(sb, indentLevel);
    sb.append('<');
    sb.append(name);

    Collections.sort(attributes);
    for (Attribute att : attributes) {
        sb.append(' ');
        sb.append(att.getFormattedContent());
    }

    if (elements.size() > 0) {
        sb.append(">"); //$NON-NLS-1$
        for (Element element : elements) {
            OutputUtilities.newLine(sb);
            sb.append(element.getFormattedContent(indentLevel + 1));
        }
        OutputUtilities.newLine(sb);
        OutputUtilities.xmlIndent(sb, indentLevel);
        sb.append("</"); //$NON-NLS-1$
        sb.append(name);
        sb.append('>');

    } else {
        sb.append(" />"); //$NON-NLS-1$
    }

    return sb.toString();
}
 
Example #13
Source File: BodyLineRenderer.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
public List<String> render(List<String> bodyLines) {
    List<String> lines = new ArrayList<>();
    int indentLevel = 1;
    StringBuilder sb = new StringBuilder();

    ListIterator<String> listIter = bodyLines.listIterator();
    while (listIter.hasNext()) {
        sb.setLength(0);
        String line = listIter.next();
        if (line.startsWith("}")) {
            indentLevel--;
        }

        OutputUtilities.javaIndent(sb, indentLevel);
        sb.append(line);
        lines.add(sb.toString());

        if (isCodeBlockStartExceptSwitchStatement(line) || line.endsWith(":")) {
            indentLevel++;
        }

        if (line.startsWith("break")) {
            // if the next line is '}', then don't outdent
            if (listIter.hasNext()) {
                String nextLine = listIter.next();
                if (nextLine.startsWith("}")) {
                    indentLevel++;
                }

                // set back to the previous element
                listIter.previous();
            }
            indentLevel--;
        }
    }

    return lines;
}
 
Example #14
Source File: Field.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
public String getFormattedContent(int indentLevel) {
    StringBuilder sb = new StringBuilder();

    addFormattedJavadoc(sb, indentLevel);
    addFormattedAnnotations(sb, indentLevel);

    OutputUtilities.javaIndent(sb, indentLevel);
    sb.append(getVisibility().getValue());

    if (isStatic()) {
        sb.append("static "); //$NON-NLS-1$
    }

    if (isFinal()) {
        sb.append("final "); //$NON-NLS-1$
    }

    if (isTransient()) {
        sb.append("transient "); //$NON-NLS-1$
    }
    
    if (isVolatile()) {
        sb.append("volatile "); //$NON-NLS-1$
    }
    
    sb.append(type.getShortName());

    sb.append(' ');
    sb.append(name);

    if (initializationString != null && initializationString.length() > 0) {
        sb.append(" = "); //$NON-NLS-1$
        sb.append(initializationString);
    }

    sb.append(';');

    return sb.toString();
}
 
Example #15
Source File: TextElement.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
public String getFormattedContent(int indentLevel) {
    StringBuilder sb = new StringBuilder();
    OutputUtilities.xmlIndent(sb, indentLevel);
    sb.append(content);
    return sb.toString();
}
 
Example #16
Source File: InitializationBlock.java    From mybatis-generator-core-fix with Apache License 2.0 4 votes vote down vote up
public String getFormattedContent(int indentLevel) {
    StringBuilder sb = new StringBuilder();

    for (String javaDocLine : javaDocLines) {
        OutputUtilities.javaIndent(sb, indentLevel);
        sb.append(javaDocLine);
        OutputUtilities.newLine(sb);
    }

    OutputUtilities.javaIndent(sb, indentLevel);

    if (isStatic) {
        sb.append("static "); //$NON-NLS-1$
    }

    sb.append('{');
    indentLevel++;

    ListIterator<String> listIter = bodyLines.listIterator();
    while (listIter.hasNext()) {
        String line = listIter.next();
        if (line.startsWith("}")) { //$NON-NLS-1$
            indentLevel--;
        }

        OutputUtilities.newLine(sb);
        OutputUtilities.javaIndent(sb, indentLevel);
        sb.append(line);

        if ((line.endsWith("{") && !line.startsWith("switch")) //$NON-NLS-1$ //$NON-NLS-2$
                || line.endsWith(":")) { //$NON-NLS-1$
            indentLevel++;
        }

        if (line.startsWith("break")) { //$NON-NLS-1$
            // if the next line is '}', then don't outdent
            if (listIter.hasNext()) {
                String nextLine = listIter.next();
                if (nextLine.startsWith("}")) { //$NON-NLS-1$
                    indentLevel++;
                }

                // set back to the previous element
                listIter.previous();
            }
            indentLevel--;
        }
    }

    indentLevel--;
    OutputUtilities.newLine(sb);
    OutputUtilities.javaIndent(sb, indentLevel);
    sb.append('}');

    return sb.toString();
}
 
Example #17
Source File: InsertBatchElementGenerator.java    From mapper-generator-javafx with Apache License 2.0 4 votes vote down vote up
@Override
public void addElements(XmlElement parentElement) {
    XmlElement answer = new XmlElement("insert");

    answer.addAttribute(new Attribute(
            "id", introspectedTable.getInsertBatchStatementId()));

    answer.addAttribute(new Attribute("parameterType",
            FullyQualifiedJavaType.getNewListInstance().getFullyQualifiedName()));

    context.getCommentGenerator().addComment(answer);

    this.generateKey(introspectedTable, answer);

    answer.addElement(new TextElement("insert into " + introspectedTable.getFullyQualifiedTableNameAtRuntime()));
    answer.addElement(new TextElement(" ("));

    StringBuilder insertClause = new StringBuilder();
    StringBuilder valuesClause = new StringBuilder();
    List<String> valuesClauses = new ArrayList<String>();
    List<IntrospectedColumn> columns = ListUtilities.removeIdentityAndGeneratedAlwaysColumns(introspectedTable.getAllColumns());
    for (int i = 0; i < columns.size(); i++) {
        IntrospectedColumn introspectedColumn = columns.get(i);

        insertClause.setLength(0);
        valuesClause.setLength(0);
        insertClause.append(MyBatis3FormattingUtilities.getEscapedColumnName(introspectedColumn));
        valuesClause.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, "item."));
        if (i + 1 < columns.size()) {
            insertClause.append(", ");
            valuesClause.append(", ");
        }

        answer.addElement(new TextElement(insertClause.toString()));
        OutputUtilities.xmlIndent(insertClause, 1);
        valuesClauses.add(valuesClause.toString());
        OutputUtilities.xmlIndent(valuesClause, 3);
    }

    answer.addElement(new TextElement(")"));
    OutputUtilities.xmlIndent(valuesClause, 1);
    answer.addElement(new TextElement("values"));
    OutputUtilities.xmlIndent(valuesClause, 1);
    answer.addElement(new TextElement("<foreach collection=\"list\" item=\"item\" separator=\",\">"));
    answer.addElement(new TextElement("("));

    for (String clause : valuesClauses) {
        answer.addElement(new TextElement(clause));
    }

    answer.addElement(new TextElement(")"));
    answer.addElement(new TextElement("</foreach>"));

    if (context.getPlugins().sqlMapInsertElementGenerated(answer, introspectedTable)) {
        parentElement.addElement(answer);
    }
}
 
Example #18
Source File: UpdateByExampleWithBLOBsElementGenerator.java    From mapper-generator-javafx with Apache License 2.0 4 votes vote down vote up
@Override
public void addElements(XmlElement parentElement) {
    XmlElement answer = new XmlElement("update");

    answer.addAttribute(new Attribute("id",
            introspectedTable.getUpdateByExampleWithBLOBsStatementId()));

    answer.addAttribute(new Attribute("parameterType", "map")); //$NON-NLS-2$
    context.getCommentGenerator().addComment(answer);

    StringBuilder sb = new StringBuilder();
    sb.append("update ");
    sb.append(introspectedTable
            .getAliasedFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));

    // set up for first column
    sb.setLength(0);
    sb.append("set ");

    Iterator<IntrospectedColumn> iter =
            ListUtilities.removeGeneratedAlwaysColumns(introspectedTable.getAllColumns()).iterator();
    while (iter.hasNext()) {
        IntrospectedColumn introspectedColumn = iter.next();
        
        sb.append(MyBatis3FormattingUtilities
                .getAliasedEscapedColumnName(introspectedColumn));
        sb.append(" = ");
        sb.append(MyBatis3FormattingUtilities.getParameterClause(
                introspectedColumn, "record."));

        if (iter.hasNext()) {
            sb.append(',');
        }

        answer.addElement(new TextElement(sb.toString()));

        // set up for the next column
        if (iter.hasNext()) {
            sb.setLength(0);
            OutputUtilities.xmlIndent(sb, 1);
        }
    }

    answer.addElement(getUpdateByExampleIncludeElement());

    if (context.getPlugins()
            .sqlMapUpdateByExampleWithBLOBsElementGenerated(answer,
                    introspectedTable)) {
        parentElement.addElement(answer);
    }
}
 
Example #19
Source File: EqualsHashCodePlugin.java    From mybatis-generator-plus with Apache License 2.0 4 votes vote down vote up
/**
 * Generates an <tt>equals</tt> method that does a comparison of all fields.
 * <p>
 * The generated <tt>equals</tt> method will be correct unless:
 * <ul>
 * <li>Other fields have been added to the generated classes</li>
 * <li>A <tt>rootClass</tt> is specified that holds state</li>
 * </ul>
 * 
 * @param topLevelClass
 *            the class to which the method will be added
 * @param introspectedColumns
 *            column definitions of this class and any superclass of this
 *            class
 * @param introspectedTable
 *            the table corresponding to this class
 */
protected void generateEquals(TopLevelClass topLevelClass,
        List<IntrospectedColumn> introspectedColumns,
        IntrospectedTable introspectedTable) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType
            .getBooleanPrimitiveInstance());
    method.setName("equals"); //$NON-NLS-1$
    method.addParameter(new Parameter(FullyQualifiedJavaType
            .getObjectInstance(), "that")); //$NON-NLS-1$
    if (introspectedTable.isJava5Targeted()) {
        method.addAnnotation("@Override"); //$NON-NLS-1$
    }

    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    method.addBodyLine("if (this == that) {"); //$NON-NLS-1$
    method.addBodyLine("return true;"); //$NON-NLS-1$
    method.addBodyLine("}"); //$NON-NLS-1$

    method.addBodyLine("if (that == null) {"); //$NON-NLS-1$
    method.addBodyLine("return false;"); //$NON-NLS-1$
    method.addBodyLine("}"); //$NON-NLS-1$

    method.addBodyLine("if (getClass() != that.getClass()) {"); //$NON-NLS-1$
    method.addBodyLine("return false;"); //$NON-NLS-1$
    method.addBodyLine("}"); //$NON-NLS-1$

    StringBuilder sb = new StringBuilder();
    sb.append(topLevelClass.getType().getShortName());
    sb.append(" other = ("); //$NON-NLS-1$
    sb.append(topLevelClass.getType().getShortName());
    sb.append(") that;"); //$NON-NLS-1$
    method.addBodyLine(sb.toString());

    boolean first = true;
    Iterator<IntrospectedColumn> iter = introspectedColumns.iterator();
    while (iter.hasNext()) {
        IntrospectedColumn introspectedColumn = iter.next();

        sb.setLength(0);

        if (first) {
            sb.append("return ("); //$NON-NLS-1$
            first = false;
        } else {
            OutputUtilities.javaIndent(sb, 1);
            sb.append("&& ("); //$NON-NLS-1$
        }

        String getterMethod = getGetterMethodName(
                introspectedColumn.getJavaProperty(), introspectedColumn
                        .getFullyQualifiedJavaType());

        if (introspectedColumn.getFullyQualifiedJavaType().isPrimitive()) {
            sb.append("this."); //$NON-NLS-1$
            sb.append(getterMethod);
            sb.append("() == "); //$NON-NLS-1$
            sb.append("other."); //$NON-NLS-1$
            sb.append(getterMethod);
            sb.append("())"); //$NON-NLS-1$
        } else {
            sb.append("this."); //$NON-NLS-1$
            sb.append(getterMethod);
            sb.append("() == null ? other."); //$NON-NLS-1$
            sb.append(getterMethod);
            sb.append("() == null : this."); //$NON-NLS-1$
            sb.append(getterMethod);
            sb.append("().equals(other."); //$NON-NLS-1$
            sb.append(getterMethod);
            sb.append("()))"); //$NON-NLS-1$
        }

        if (!iter.hasNext()) {
            sb.append(';');
        }

        method.addBodyLine(sb.toString());
    }

    topLevelClass.addMethod(method);
}
 
Example #20
Source File: UpdateByExampleWithoutBLOBsElementGenerator.java    From mybatis-generator-plus with Apache License 2.0 4 votes vote down vote up
@Override
public void addElements(XmlElement parentElement) {
    XmlElement answer = new XmlElement("update"); //$NON-NLS-1$

    answer.addAttribute(new Attribute("id", //$NON-NLS-1$
            introspectedTable.getUpdateByExampleStatementId()));

    answer.addAttribute(new Attribute("parameterType", "map")); //$NON-NLS-1$ //$NON-NLS-2$

    context.getCommentGenerator().addComment(answer);

    StringBuilder sb = new StringBuilder();
    sb.append("update "); //$NON-NLS-1$
    sb.append(introspectedTable
            .getAliasedFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));

    // set up for first column
    sb.setLength(0);
    sb.append("set "); //$NON-NLS-1$

    Iterator<IntrospectedColumn> iter = introspectedTable
            .getNonBLOBColumns().iterator();
    while (iter.hasNext()) {
        IntrospectedColumn introspectedColumn = iter.next();

        sb.append(MyBatis3FormattingUtilities
                .getAliasedEscapedColumnName(introspectedColumn));
        sb.append(" = "); //$NON-NLS-1$
        sb.append(MyBatis3FormattingUtilities.getParameterClause(
                introspectedColumn, "record.")); //$NON-NLS-1$

        if (iter.hasNext()) {
            sb.append(',');
        }

        answer.addElement(new TextElement(sb.toString()));

        // set up for the next column
        if (iter.hasNext()) {
            sb.setLength(0);
            OutputUtilities.xmlIndent(sb, 1);
        }
    }

    answer.addElement(getUpdateByExampleIncludeElement());

    if (context.getPlugins()
            .sqlMapUpdateByExampleWithoutBLOBsElementGenerated(answer,
                    introspectedTable)) {
        parentElement.addElement(answer);
    }
}
 
Example #21
Source File: UpdateByExampleWithBLOBsElementGenerator.java    From mybatis-generator-plus with Apache License 2.0 4 votes vote down vote up
@Override
public void addElements(XmlElement parentElement) {
    XmlElement answer = new XmlElement("update"); //$NON-NLS-1$

    answer.addAttribute(new Attribute("id", //$NON-NLS-1$
            introspectedTable.getUpdateByExampleWithBLOBsStatementId()));

    answer.addAttribute(new Attribute("parameterType", "map")); //$NON-NLS-1$ //$NON-NLS-2$
    context.getCommentGenerator().addComment(answer);

    StringBuilder sb = new StringBuilder();
    sb.append("update "); //$NON-NLS-1$
    sb.append(introspectedTable
            .getAliasedFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));

    // set up for first column
    sb.setLength(0);
    sb.append("set "); //$NON-NLS-1$

    Iterator<IntrospectedColumn> iter = introspectedTable.getAllColumns()
            .iterator();
    while (iter.hasNext()) {
        IntrospectedColumn introspectedColumn = iter.next();

        sb.append(MyBatis3FormattingUtilities
                .getAliasedEscapedColumnName(introspectedColumn));
        sb.append(" = "); //$NON-NLS-1$
        sb.append(MyBatis3FormattingUtilities.getParameterClause(
                introspectedColumn, "record.")); //$NON-NLS-1$

        if (iter.hasNext()) {
            sb.append(',');
        }

        answer.addElement(new TextElement(sb.toString()));

        // set up for the next column
        if (iter.hasNext()) {
            sb.setLength(0);
            OutputUtilities.xmlIndent(sb, 1);
        }
    }

    answer.addElement(getUpdateByExampleIncludeElement());

    if (context.getPlugins()
            .sqlMapUpdateByExampleWithBLOBsElementGenerated(answer,
                    introspectedTable)) {
        parentElement.addElement(answer);
    }
}
 
Example #22
Source File: UpdateByExampleWithoutBLOBsElementGenerator.java    From mybatis-generator-plus with Apache License 2.0 4 votes vote down vote up
@Override
public void addElements(XmlElement parentElement) {
    XmlElement answer = new XmlElement("update"); //$NON-NLS-1$

    answer.addAttribute(new Attribute(
            "id", introspectedTable.getUpdateByExampleStatementId())); //$NON-NLS-1$

    context.getCommentGenerator().addComment(answer);

    StringBuilder sb = new StringBuilder();
    sb.append("update "); //$NON-NLS-1$
    sb.append(introspectedTable
            .getAliasedFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));

    // set up for first column
    sb.setLength(0);
    sb.append("set "); //$NON-NLS-1$

    Iterator<IntrospectedColumn> iter = introspectedTable
            .getNonBLOBColumns().iterator();
    while (iter.hasNext()) {
        IntrospectedColumn introspectedColumn = iter.next();

        sb.append(Ibatis2FormattingUtilities
                .getAliasedEscapedColumnName(introspectedColumn));
        sb.append(" = "); //$NON-NLS-1$
        sb.append(Ibatis2FormattingUtilities.getParameterClause(
                introspectedColumn, "record.")); //$NON-NLS-1$

        if (iter.hasNext()) {
            sb.append(',');
        }

        answer.addElement(new TextElement(sb.toString()));

        // set up for the next column
        if (iter.hasNext()) {
            sb.setLength(0);
            OutputUtilities.xmlIndent(sb, 1);
        }
    }

    XmlElement isParameterPresentElement = new XmlElement(
            "isParameterPresent"); //$NON-NLS-1$
    answer.addElement(isParameterPresentElement);

    XmlElement includeElement = new XmlElement("include"); //$NON-NLS-1$
    includeElement.addAttribute(new Attribute("refid", //$NON-NLS-1$
            introspectedTable.getIbatis2SqlMapNamespace()
                    + "." + introspectedTable.getExampleWhereClauseId())); //$NON-NLS-1$
    isParameterPresentElement.addElement(includeElement);

    if (context.getPlugins()
            .sqlMapUpdateByExampleWithoutBLOBsElementGenerated(answer,
                    introspectedTable)) {
        parentElement.addElement(answer);
    }
}
 
Example #23
Source File: UpdateByExampleWithBLOBsElementGenerator.java    From mybatis-generator-plus with Apache License 2.0 4 votes vote down vote up
@Override
public void addElements(XmlElement parentElement) {
    XmlElement answer = new XmlElement("update"); //$NON-NLS-1$

    answer
            .addAttribute(new Attribute(
                    "id", introspectedTable.getUpdateByExampleWithBLOBsStatementId())); //$NON-NLS-1$

    context.getCommentGenerator().addComment(answer);

    StringBuilder sb = new StringBuilder();
    sb.append("update "); //$NON-NLS-1$
    sb.append(introspectedTable
            .getAliasedFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));

    // set up for first column
    sb.setLength(0);
    sb.append("set "); //$NON-NLS-1$

    Iterator<IntrospectedColumn> iter = introspectedTable.getAllColumns()
            .iterator();
    while (iter.hasNext()) {
        IntrospectedColumn introspectedColumn = iter.next();

        sb.append(Ibatis2FormattingUtilities
                .getAliasedEscapedColumnName(introspectedColumn));
        sb.append(" = "); //$NON-NLS-1$
        sb.append(Ibatis2FormattingUtilities.getParameterClause(
                introspectedColumn, "record.")); //$NON-NLS-1$

        if (iter.hasNext()) {
            sb.append(',');
        }

        answer.addElement(new TextElement(sb.toString()));

        // set up for the next column
        if (iter.hasNext()) {
            sb.setLength(0);
            OutputUtilities.xmlIndent(sb, 1);
        }
    }

    XmlElement isParameterPresentElement = new XmlElement(
            "isParameterPresent"); //$NON-NLS-1$
    answer.addElement(isParameterPresentElement);

    XmlElement includeElement = new XmlElement("include"); //$NON-NLS-1$
    includeElement.addAttribute(new Attribute("refid", //$NON-NLS-1$
            introspectedTable.getIbatis2SqlMapNamespace()
                    + "." + introspectedTable.getExampleWhereClauseId())); //$NON-NLS-1$
    isParameterPresentElement.addElement(includeElement);

    if (context.getPlugins()
            .sqlMapUpdateByExampleWithBLOBsElementGenerated(answer,
                    introspectedTable)) {
        parentElement.addElement(answer);
    }
}
 
Example #24
Source File: UpdateByExampleWithoutBLOBsElementGenerator.java    From mapper-generator-javafx with Apache License 2.0 4 votes vote down vote up
@Override
public void addElements(XmlElement parentElement) {
    XmlElement answer = new XmlElement("update");

    answer.addAttribute(new Attribute("id",
            introspectedTable.getUpdateByExampleStatementId()));

    answer.addAttribute(new Attribute("parameterType", "map")); //$NON-NLS-2$

    context.getCommentGenerator().addComment(answer);

    StringBuilder sb = new StringBuilder();
    sb.append("update ");
    sb.append(introspectedTable
            .getAliasedFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));

    // set up for first column
    sb.setLength(0);
    sb.append("set ");

    Iterator<IntrospectedColumn> iter =
            ListUtilities.removeGeneratedAlwaysColumns(introspectedTable.getNonBLOBColumns()).iterator();
    while (iter.hasNext()) {
        IntrospectedColumn introspectedColumn = iter.next();

        sb.append(MyBatis3FormattingUtilities
                .getAliasedEscapedColumnName(introspectedColumn));
        sb.append(" = ");
        sb.append(MyBatis3FormattingUtilities.getParameterClause(
                introspectedColumn, "record."));

        if (iter.hasNext()) {
            sb.append(',');
        }

        answer.addElement(new TextElement(sb.toString()));

        // set up for the next column
        if (iter.hasNext()) {
            sb.setLength(0);
            OutputUtilities.xmlIndent(sb, 1);
        }
    }

    answer.addElement(getUpdateByExampleIncludeElement());

    if (context.getPlugins()
            .sqlMapUpdateByExampleWithoutBLOBsElementGenerated(answer,
                    introspectedTable)) {
        parentElement.addElement(answer);
    }
}
 
Example #25
Source File: InnerInterface.java    From mybatis-generator-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * 格式化后内容,因为是内部接口,需要增加缩进
 *
 * @param indentLevel the indent level
 * @param compilationUnit the compilation unit
 * @return the formatted content
 */
@Override
public String getFormattedContent(int indentLevel, CompilationUnit compilationUnit) {
    StringBuilder sb = new StringBuilder();

    for (String commentLine : getFileCommentLines()) {
        sb.append(commentLine);
        newLine(sb);
    }

    if (stringHasValue(getType().getPackageName())) {
        sb.append("package "); 
        sb.append(getType().getPackageName());
        sb.append(';');
        newLine(sb);
        newLine(sb);
    }

    for (String staticImport : getStaticImports()) {
        sb.append("import static "); 
        sb.append(staticImport);
        sb.append(';');
        newLine(sb);
    }

    if (getStaticImports().size() > 0) {
        newLine(sb);
    }

    Set<String> importStrings = calculateImports(getImportedTypes());
    for (String importString : importStrings) {
        sb.append(importString);
        newLine(sb);
    }

    if (importStrings.size() > 0) {
        newLine(sb);
    }

    addFormattedJavadoc(sb, indentLevel);
    addFormattedAnnotations(sb, indentLevel);

    OutputUtilities.javaIndent(sb, indentLevel);

    sb.append(getVisibility().getValue());

    if (isFinal()) {
        sb.append("final "); 
    }

    sb.append("interface "); 
    sb.append(getType().getShortName());

    if (getSuperInterfaceTypes().size() > 0) {
        sb.append(" extends "); 

        boolean comma = false;
        for (FullyQualifiedJavaType fqjt : getSuperInterfaceTypes()) {
            if (comma) {
                sb.append(", "); 
            } else {
                comma = true;
            }

            sb.append(JavaDomUtils.calculateTypeName(this, fqjt));
        }
    }

    sb.append(" {"); 
    indentLevel++;

    Iterator<Method> mtdIter = getMethods().iterator();
    while (mtdIter.hasNext()) {
        newLine(sb);
        Method method = mtdIter.next();
        sb.append(method.getFormattedContent(indentLevel, true, this));
        if (mtdIter.hasNext()) {
            newLine(sb);
        }
    }

    indentLevel--;
    newLine(sb);
    javaIndent(sb, indentLevel);
    sb.append('}');

    return sb.toString();
}
 
Example #26
Source File: Field.java    From mybatis-generator-plus with Apache License 2.0 4 votes vote down vote up
public String getFormattedContent(int indentLevel) {
    StringBuilder sb = new StringBuilder();

    addFormattedJavadoc(sb, indentLevel);
    addFormattedAnnotations(sb, indentLevel);

    OutputUtilities.javaIndent(sb, indentLevel);
    sb.append(getVisibility().getValue());

    if (isStatic()) {
        sb.append("static "); //$NON-NLS-1$
    }

    if (isFinal()) {
        sb.append("final "); //$NON-NLS-1$
    }

    if (isTransient()) {
        sb.append("transient "); //$NON-NLS-1$
    }
    
    if (isVolatile()) {
        sb.append("volatile "); //$NON-NLS-1$
    }
    
    sb.append(type.getShortName());

    sb.append(' ');
    sb.append(name);

    if (initializationString != null && initializationString.length() > 0) {
        sb.append(" = "); //$NON-NLS-1$
        sb.append(initializationString);
    }

    sb.append(';');

    if(comments!=null){
        sb.append("//").append(comments);
    }

    return sb.toString();
}
 
Example #27
Source File: Interface.java    From mybatis-generator-plus with Apache License 2.0 4 votes vote down vote up
public String getFormattedContent() {
    StringBuilder sb = new StringBuilder();

    for (String commentLine : fileCommentLines) {
        sb.append(commentLine);
        newLine(sb);
    }

    if (stringHasValue(getType().getPackageName())) {
        sb.append("package "); //$NON-NLS-1$
        sb.append(getType().getPackageName());
        sb.append(';');
        newLine(sb);
        newLine(sb);
    }

    for (String staticImport : staticImports) {
        sb.append("import static "); //$NON-NLS-1$
        sb.append(staticImport);
        sb.append(';');
        newLine(sb);
    }
    
    if (staticImports.size() > 0) {
        newLine(sb);
    }
    
    Set<String> importStrings = calculateImports(importedTypes);
    for (String importString : importStrings) {
        sb.append(importString);
        newLine(sb);
    }

    if (importStrings.size() > 0) {
        newLine(sb);
    }

    int indentLevel = 0;

    addFormattedJavadoc(sb, indentLevel);
    addFormattedAnnotations(sb, indentLevel);

    sb.append(getVisibility().getValue());

    if (isStatic()) {
        sb.append("static "); //$NON-NLS-1$
    }

    if (isFinal()) {
        sb.append("final "); //$NON-NLS-1$
    }

    sb.append("interface "); //$NON-NLS-1$
    sb.append(getType().getShortName());

    if (getSuperInterfaceTypes().size() > 0) {
        sb.append(" extends "); //$NON-NLS-1$

        boolean comma = false;
        for (FullyQualifiedJavaType fqjt : getSuperInterfaceTypes()) {
            if (comma) {
                sb.append(", "); //$NON-NLS-1$
            } else {
                comma = true;
            }

            sb.append(fqjt.getShortName());
        }
    }

    sb.append(" {"); //$NON-NLS-1$
    indentLevel++;

    //add by wushuai start
    Iterator<Field> fldIter = fields.iterator();
    while (fldIter.hasNext()) {
        OutputUtilities.newLine(sb);
        Field field = fldIter.next();
        sb.append(field.getFormattedContent(indentLevel));
        OutputUtilities.newLine(sb);
    }
    //add by wushuai end
    
    Iterator<Method> mtdIter = getMethods().iterator();
    while (mtdIter.hasNext()) {
        newLine(sb);
        Method method = mtdIter.next();
        sb.append(method.getFormattedContent(indentLevel, true));
        if (mtdIter.hasNext()) {
            newLine(sb);
        }
    }

    indentLevel--;
    newLine(sb);
    javaIndent(sb, indentLevel);
    sb.append('}');

    return sb.toString();
}
 
Example #28
Source File: InitializationBlock.java    From mybatis-generator-plus with Apache License 2.0 4 votes vote down vote up
public String getFormattedContent(int indentLevel) {
    StringBuilder sb = new StringBuilder();

    for (String javaDocLine : javaDocLines) {
        OutputUtilities.javaIndent(sb, indentLevel);
        sb.append(javaDocLine);
        OutputUtilities.newLine(sb);
    }

    OutputUtilities.javaIndent(sb, indentLevel);

    if (isStatic) {
        sb.append("static "); //$NON-NLS-1$
    }

    sb.append('{');
    indentLevel++;

    ListIterator<String> listIter = bodyLines.listIterator();
    while (listIter.hasNext()) {
        String line = listIter.next();
        if (line.startsWith("}")) { //$NON-NLS-1$
            indentLevel--;
        }

        OutputUtilities.newLine(sb);
        OutputUtilities.javaIndent(sb, indentLevel);
        sb.append(line);

        if ((line.endsWith("{") && !line.startsWith("switch")) //$NON-NLS-1$ //$NON-NLS-2$
                || line.endsWith(":")) { //$NON-NLS-1$
            indentLevel++;
        }

        if (line.startsWith("break")) { //$NON-NLS-1$
            // if the next line is '}', then don't outdent
            if (listIter.hasNext()) {
                String nextLine = listIter.next();
                if (nextLine.startsWith("}")) { //$NON-NLS-1$
                    indentLevel++;
                }

                // set back to the previous element
                listIter.previous();
            }
            indentLevel--;
        }
    }

    indentLevel--;
    OutputUtilities.newLine(sb);
    OutputUtilities.javaIndent(sb, indentLevel);
    sb.append('}');

    return sb.toString();
}
 
Example #29
Source File: UpdateByExampleWithoutBLOBsElementGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 4 votes vote down vote up
@Override
public void addElements(XmlElement parentElement) {
    XmlElement answer = new XmlElement("update"); //$NON-NLS-1$

    answer.addAttribute(new Attribute("id", //$NON-NLS-1$
            introspectedTable.getUpdateByExampleStatementId()));

    answer.addAttribute(new Attribute("parameterType", "map")); //$NON-NLS-1$ //$NON-NLS-2$

    context.getCommentGenerator().addComment(answer);

    StringBuilder sb = new StringBuilder();
    sb.append("update "); //$NON-NLS-1$
    sb.append(introspectedTable
            .getAliasedFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));

    // set up for first column
    sb.setLength(0);
    sb.append("set "); //$NON-NLS-1$

    Iterator<IntrospectedColumn> iter = introspectedTable
            .getNonBLOBColumns().iterator();
    while (iter.hasNext()) {
        IntrospectedColumn introspectedColumn = iter.next();

        sb.append(MyBatis3FormattingUtilities
                .getAliasedEscapedColumnName(introspectedColumn));
        sb.append(" = "); //$NON-NLS-1$
        sb.append(MyBatis3FormattingUtilities.getParameterClause(
                introspectedColumn, "record.")); //$NON-NLS-1$

        if (iter.hasNext()) {
            sb.append(',');
        }

        answer.addElement(new TextElement(sb.toString()));

        // set up for the next column
        if (iter.hasNext()) {
            sb.setLength(0);
            OutputUtilities.xmlIndent(sb, 1);
        }
    }

    answer.addElement(getUpdateByExampleIncludeElement());

    if (context.getPlugins()
            .sqlMapUpdateByExampleWithoutBLOBsElementGenerated(answer,
                    introspectedTable)) {
        parentElement.addElement(answer);
    }
}
 
Example #30
Source File: UpdateByExampleWithBLOBsElementGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 4 votes vote down vote up
@Override
public void addElements(XmlElement parentElement) {
    XmlElement answer = new XmlElement("update"); //$NON-NLS-1$

    answer.addAttribute(new Attribute("id", //$NON-NLS-1$
            introspectedTable.getUpdateByExampleWithBLOBsStatementId()));

    answer.addAttribute(new Attribute("parameterType", "map")); //$NON-NLS-1$ //$NON-NLS-2$
    context.getCommentGenerator().addComment(answer);

    StringBuilder sb = new StringBuilder();
    sb.append("update "); //$NON-NLS-1$
    sb.append(introspectedTable
            .getAliasedFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));

    // set up for first column
    sb.setLength(0);
    sb.append("set "); //$NON-NLS-1$

    Iterator<IntrospectedColumn> iter = introspectedTable.getAllColumns()
            .iterator();
    while (iter.hasNext()) {
        IntrospectedColumn introspectedColumn = iter.next();

        sb.append(MyBatis3FormattingUtilities
                .getAliasedEscapedColumnName(introspectedColumn));
        sb.append(" = "); //$NON-NLS-1$
        sb.append(MyBatis3FormattingUtilities.getParameterClause(
                introspectedColumn, "record.")); //$NON-NLS-1$

        if (iter.hasNext()) {
            sb.append(',');
        }

        answer.addElement(new TextElement(sb.toString()));

        // set up for the next column
        if (iter.hasNext()) {
            sb.setLength(0);
            OutputUtilities.xmlIndent(sb, 1);
        }
    }

    answer.addElement(getUpdateByExampleIncludeElement());

    if (context.getPlugins()
            .sqlMapUpdateByExampleWithBLOBsElementGenerated(answer,
                    introspectedTable)) {
        parentElement.addElement(answer);
    }
}