• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ListUtilities类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.mybatis.generator.codegen.mybatis3.ListUtilities的典型用法代码示例。如果您正苦于以下问题:Java ListUtilities类的具体用法?Java ListUtilities怎么用?Java ListUtilities使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ListUtilities类属于org.mybatis.generator.codegen.mybatis3包,在下文中一共展示了ListUtilities类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: generateUpdateByPrimaryKeyWithoutBLOBs

import org.mybatis.generator.codegen.mybatis3.ListUtilities; //导入依赖的package包/类
/**
 * Implements the rule for generating the update by primary key without
 * BLOBs SQL Map element and DAO method. If the table has a primary key as
 * well as other non-BLOB fields, and the updateByPrimaryKey statement is
 * allowed, then generate the element and method.
 * 
 * @return true if the element and method should be generated
 */
public boolean generateUpdateByPrimaryKeyWithoutBLOBs() {
    if (isModelOnly) {
        return false;
    }
    
    if (ListUtilities.removeGeneratedAlwaysColumns(introspectedTable.getBaseColumns()).isEmpty()) {
        return false;
    }
    
    boolean rc = tableConfiguration.isUpdateByPrimaryKeyStatementEnabled()
            && introspectedTable.hasPrimaryKeyColumns()
            && introspectedTable.hasBaseColumns();

    return rc;
}
 
开发者ID:bandaotixi,项目名称:generator_mybatis,代码行数:24,代码来源:BaseRules.java


示例2: generateUpdateByPrimaryKeySelective

import org.mybatis.generator.codegen.mybatis3.ListUtilities; //导入依赖的package包/类
/**
 * Implements the rule for generating the update by primary key selective
 * SQL Map element and DAO method. If the table has a primary key as well as
 * other fields, and the updateByPrimaryKey statement is allowed, then
 * generate the element and method.
 * 
 * @return true if the element and method should be generated
 */
public boolean generateUpdateByPrimaryKeySelective() {
    if (isModelOnly) {
        return false;
    }
    
    if (ListUtilities.removeGeneratedAlwaysColumns(introspectedTable.getNonPrimaryKeyColumns()).isEmpty()) {
        return false;
    }
    
    boolean rc = tableConfiguration.isUpdateByPrimaryKeyStatementEnabled()
            && introspectedTable.hasPrimaryKeyColumns()
            && (introspectedTable.hasBLOBColumns() || introspectedTable
                    .hasBaseColumns());

    return rc;
}
 
开发者ID:bandaotixi,项目名称:generator_mybatis,代码行数:25,代码来源:BaseRules.java


示例3: generateUpdateByPrimaryKeyWithoutBLOBs

import org.mybatis.generator.codegen.mybatis3.ListUtilities; //导入依赖的package包/类
/**
 * Implements the rule for generating the update by primary key without
 * BLOBs SQL Map element and DAO method. If the table has a primary key as
 * well as other non-BLOB fields, and the updateByPrimaryKey statement is
 * allowed, then generate the element and method.
 * 
 * @return true if the element and method should be generated
 */
@Override
public boolean generateUpdateByPrimaryKeyWithoutBLOBs() {
    if (isModelOnly) {
        return false;
    }
    
    if (ListUtilities.removeGeneratedAlwaysColumns(introspectedTable.getBaseColumns()).isEmpty()) {
        return false;
    }
    
    boolean rc = tableConfiguration.isUpdateByPrimaryKeyStatementEnabled()
            && introspectedTable.hasPrimaryKeyColumns()
            && introspectedTable.hasBaseColumns();

    return rc;
}
 
开发者ID:nextyu,项目名称:summer-mybatis-generator,代码行数:25,代码来源:BaseRules.java


示例4: generateUpdateByPrimaryKeyWithBLOBs

import org.mybatis.generator.codegen.mybatis3.ListUtilities; //导入依赖的package包/类
/**
 * Implements the rule for generating the update by primary key with BLOBs
 * SQL Map element and DAO method. If the table has a primary key as well as
 * other BLOB fields, and the updateByPrimaryKey statement is allowed, then
 * generate the element and method.
 * 
 * @return true if the element and method should be generated
 */
@Override
public boolean generateUpdateByPrimaryKeyWithBLOBs() {
    if (isModelOnly) {
        return false;
    }
    
    if (ListUtilities.removeGeneratedAlwaysColumns(introspectedTable.getNonPrimaryKeyColumns()).isEmpty()) {
        return false;
    }
    boolean rc = tableConfiguration.isUpdateByPrimaryKeyStatementEnabled()
            && introspectedTable.hasPrimaryKeyColumns()
            && introspectedTable.hasBLOBColumns();

    return rc;
}
 
开发者ID:nextyu,项目名称:summer-mybatis-generator,代码行数:24,代码来源:BaseRules.java


示例5: generateUpdateByPrimaryKeySelective

import org.mybatis.generator.codegen.mybatis3.ListUtilities; //导入依赖的package包/类
/**
 * Implements the rule for generating the update by primary key selective
 * SQL Map element and DAO method. If the table has a primary key as well as
 * other fields, and the updateByPrimaryKey statement is allowed, then
 * generate the element and method.
 * 
 * @return true if the element and method should be generated
 */
@Override
public boolean generateUpdateByPrimaryKeySelective() {
    if (isModelOnly) {
        return false;
    }
    
    if (ListUtilities.removeGeneratedAlwaysColumns(introspectedTable.getNonPrimaryKeyColumns()).isEmpty()) {
        return false;
    }
    
    boolean rc = tableConfiguration.isUpdateByPrimaryKeyStatementEnabled()
            && introspectedTable.hasPrimaryKeyColumns()
            && (introspectedTable.hasBLOBColumns() || introspectedTable
                    .hasBaseColumns());

    return rc;
}
 
开发者ID:nextyu,项目名称:summer-mybatis-generator,代码行数:26,代码来源:BaseRules.java


示例6: generateUpdateByPrimaryKeyWithBLOBs

import org.mybatis.generator.codegen.mybatis3.ListUtilities; //导入依赖的package包/类
/**
 * Implements the rule for generating the update by primary key with BLOBs
 * SQL Map element and DAO method. If the table has a primary key as well as
 * other BLOB fields, and the updateByPrimaryKey statement is allowed, then
 * generate the element and method.
 * 
 * @return true if the element and method should be generated
 */
public boolean generateUpdateByPrimaryKeyWithBLOBs() {
    if (isModelOnly) {
        return false;
    }
    
    if (ListUtilities.removeGeneratedAlwaysColumns(introspectedTable.getNonPrimaryKeyColumns()).isEmpty()) {
        return false;
    }
    boolean rc = tableConfiguration.isUpdateByPrimaryKeyStatementEnabled()
            && introspectedTable.hasPrimaryKeyColumns()
            && introspectedTable.hasBLOBColumns();

    return rc;
}
 
开发者ID:bandaotixi,项目名称:generator_mybatis,代码行数:23,代码来源:BaseRules.java


示例7: addClassElements

import org.mybatis.generator.codegen.mybatis3.ListUtilities; //导入依赖的package包/类
@Override
public void addClassElements(TopLevelClass topLevelClass) {
    Set<String> staticImports = new TreeSet<String>();
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();

    if (useLegacyBuilder) {
    	staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.BEGIN"); //$NON-NLS-1$
    	staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.UPDATE"); //$NON-NLS-1$
    	staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SET"); //$NON-NLS-1$
    	staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SQL"); //$NON-NLS-1$
    } else {
    	importedTypes.add(NEW_BUILDER_IMPORT);
    }

    importedTypes.add(new FullyQualifiedJavaType("java.util.Map")); //$NON-NLS-1$
    
    Method method = new Method(getMethodName());
    method.setReturnType(FullyQualifiedJavaType.getStringInstance());
    method.setVisibility(JavaVisibility.PUBLIC);
    method.addParameter(new Parameter(new FullyQualifiedJavaType("java.util.Map<java.lang.String, java.lang.Object>"), //$NON-NLS-1$
            "parameter")); //$NON-NLS-1$
    
    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    if (useLegacyBuilder) {
    	method.addBodyLine("BEGIN();"); //$NON-NLS-1$
    } else {
    	method.addBodyLine("SQL sql = new SQL();"); //$NON-NLS-1$
    }
    
    method.addBodyLine(String.format("%sUPDATE(\"%s\");", //$NON-NLS-1$
            builderPrefix,
    		escapeStringForJava(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime())));
    method.addBodyLine(""); //$NON-NLS-1$
    
    for (IntrospectedColumn introspectedColumn : ListUtilities.removeGeneratedAlwaysColumns(getColumns())) {
        StringBuilder sb = new StringBuilder();
        sb.append(getParameterClause(introspectedColumn));
        sb.insert(2, "record."); //$NON-NLS-1$
        
        method.addBodyLine(String.format("%sSET(\"%s = %s\");", //$NON-NLS-1$
                builderPrefix,
        		escapeStringForJava(getAliasedEscapedColumnName(introspectedColumn)),
                sb.toString()));
    }
    
    method.addBodyLine(""); //$NON-NLS-1$
    
    FullyQualifiedJavaType example =
        new FullyQualifiedJavaType(introspectedTable.getExampleType());
    importedTypes.add(example);
    method.addBodyLine(String.format("%s example = (%s) parameter.get(\"example\");", //$NON-NLS-1$
            example.getShortName(), example.getShortName()));
    
    if (useLegacyBuilder) {
    	method.addBodyLine("applyWhere(example, true);"); //$NON-NLS-1$
    	method.addBodyLine("return SQL();"); //$NON-NLS-1$
    } else {
    	method.addBodyLine("applyWhere(sql, example, true);"); //$NON-NLS-1$
    	method.addBodyLine("return sql.toString();"); //$NON-NLS-1$
    }
    
    if (callPlugins(method, topLevelClass)) {
        topLevelClass.addStaticImports(staticImports);
        topLevelClass.addImportedTypes(importedTypes);
        topLevelClass.addMethod(method);
    }
}
 
开发者ID:bandaotixi,项目名称:generator_mybatis,代码行数:70,代码来源:ProviderUpdateByExampleWithoutBLOBsMethodGenerator.java


示例8: addClassElements

import org.mybatis.generator.codegen.mybatis3.ListUtilities; //导入依赖的package包/类
@Override
public void addClassElements(TopLevelClass topLevelClass) {
    Set<String> staticImports = new TreeSet<String>();
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    
    if (useLegacyBuilder) {
    	staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.BEGIN"); //$NON-NLS-1$
    	staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.INSERT_INTO"); //$NON-NLS-1$
    	staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SQL"); //$NON-NLS-1$
    	staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.VALUES"); //$NON-NLS-1$
    } else {
    	importedTypes.add(NEW_BUILDER_IMPORT);
    }

    FullyQualifiedJavaType fqjt = introspectedTable.getRules()
        .calculateAllFieldsClass();
    importedTypes.add(fqjt);

    Method method = new Method(
            introspectedTable.getInsertSelectiveStatementId());
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType.getStringInstance());
    method.addParameter(new Parameter(fqjt, "record")); //$NON-NLS-1$
    
    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    if (useLegacyBuilder) {
    	method.addBodyLine("BEGIN();"); //$NON-NLS-1$
    } else {
    	method.addBodyLine("SQL sql = new SQL();"); //$NON-NLS-1$
    }

	method.addBodyLine(String.format("%sINSERT_INTO(\"%s\");", //$NON-NLS-1$
            builderPrefix,
			escapeStringForJava(introspectedTable.getFullyQualifiedTableNameAtRuntime())));
	
    for (IntrospectedColumn introspectedColumn : ListUtilities.removeIdentityAndGeneratedAlwaysColumns(introspectedTable.getAllColumns())) {
        
        method.addBodyLine(""); //$NON-NLS-1$
        if (!introspectedColumn.getFullyQualifiedJavaType().isPrimitive()
                && !introspectedColumn.isSequenceColumn()) {
            method.addBodyLine(String.format("if (record.%s() != null) {", //$NON-NLS-1$
                getGetterMethodName(introspectedColumn.getJavaProperty(),
                        introspectedColumn.getFullyQualifiedJavaType())));
        }
      	method.addBodyLine(String.format("%sVALUES(\"%s\", \"%s\");", //$NON-NLS-1$
      			builderPrefix,
      			escapeStringForJava(getEscapedColumnName(introspectedColumn)),
                getParameterClause(introspectedColumn)));

      	if (!introspectedColumn.getFullyQualifiedJavaType().isPrimitive()
                && !introspectedColumn.isSequenceColumn()) {
            method.addBodyLine("}"); //$NON-NLS-1$
        }
    }
    
    method.addBodyLine(""); //$NON-NLS-1$
    if (useLegacyBuilder) {
    	method.addBodyLine("return SQL();"); //$NON-NLS-1$
    } else {
    	method.addBodyLine("return sql.toString();"); //$NON-NLS-1$
    }
    
    if (context.getPlugins().providerInsertSelectiveMethodGenerated(method, topLevelClass,
            introspectedTable)) {
        topLevelClass.addStaticImports(staticImports);
        topLevelClass.addImportedTypes(importedTypes);
        topLevelClass.addMethod(method);
    }
}
 
开发者ID:bandaotixi,项目名称:generator_mybatis,代码行数:72,代码来源:ProviderInsertSelectiveMethodGenerator.java


示例9: addMapperAnnotations

import org.mybatis.generator.codegen.mybatis3.ListUtilities; //导入依赖的package包/类
@Override
public void addMapperAnnotations(Method method) {
    
    GeneratedKey gk = introspectedTable.getGeneratedKey();
    
    method.addAnnotation("@Insert({"); //$NON-NLS-1$
    StringBuilder insertClause = new StringBuilder();
    StringBuilder valuesClause = new StringBuilder();
    
    javaIndent(insertClause, 1);
    javaIndent(valuesClause, 1);

    insertClause.append("\"insert into "); //$NON-NLS-1$
    insertClause.append(escapeStringForJava(introspectedTable
            .getFullyQualifiedTableNameAtRuntime()));
    insertClause.append(" ("); //$NON-NLS-1$

    valuesClause.append("\"values ("); //$NON-NLS-1$

    List<String> valuesClauses = new ArrayList<String>();
    Iterator<IntrospectedColumn> iter = ListUtilities.removeIdentityAndGeneratedAlwaysColumns(introspectedTable.getAllColumns())
            .iterator();
    boolean hasFields = false;
    while (iter.hasNext()) {
        IntrospectedColumn introspectedColumn = iter.next();

        insertClause.append(escapeStringForJava(getEscapedColumnName(introspectedColumn)));
        valuesClause.append(getParameterClause(introspectedColumn));
        hasFields = true;
        if (iter.hasNext()) {
            insertClause.append(", "); //$NON-NLS-1$
            valuesClause.append(", "); //$NON-NLS-1$
        }

        if (valuesClause.length() > 60) {
            if (!iter.hasNext()) {
                insertClause.append(')');
                valuesClause.append(')');
            }
            insertClause.append("\","); //$NON-NLS-1$
            valuesClause.append('\"');
            if (iter.hasNext()) {
                valuesClause.append(',');
            }
            
            method.addAnnotation(insertClause.toString());
            insertClause.setLength(0);
            javaIndent(insertClause, 1);
            insertClause.append('\"');
            
            valuesClauses.add(valuesClause.toString());
            valuesClause.setLength(0);
            javaIndent(valuesClause, 1);
            valuesClause.append('\"');
            hasFields = false;
        }
    }
    
    if (hasFields) {
        insertClause.append(")\","); //$NON-NLS-1$
        method.addAnnotation(insertClause.toString());

        valuesClause.append(")\""); //$NON-NLS-1$
        valuesClauses.add(valuesClause.toString());
    }

    for (String clause : valuesClauses) {
        method.addAnnotation(clause);
    }
    
    method.addAnnotation("})"); //$NON-NLS-1$

    if (gk != null) {
        addGeneratedKeyAnnotation(method, gk);
    }
}
 
开发者ID:bandaotixi,项目名称:generator_mybatis,代码行数:77,代码来源:AnnotatedInsertMethodGenerator.java


示例10: addElements

import org.mybatis.generator.codegen.mybatis3.ListUtilities; //导入依赖的package包/类
@Override
public void addElements(XmlElement parentElement) {
    XmlElement answer = new XmlElement("update"); //$NON-NLS-1$

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

    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()));

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

    for (IntrospectedColumn introspectedColumn : ListUtilities.removeGeneratedAlwaysColumns(introspectedTable
            .getAllColumns())) {
        XmlElement isNotNullElement = new XmlElement("if"); //$NON-NLS-1$
        sb.setLength(0);
        sb.append(introspectedColumn.getJavaProperty("record.")); //$NON-NLS-1$
        sb.append(" != null"); //$NON-NLS-1$
        isNotNullElement.addAttribute(new Attribute("test", sb.toString())); //$NON-NLS-1$
        dynamicElement.addElement(isNotNullElement);

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

        isNotNullElement.addElement(new TextElement(sb.toString()));
    }

    answer.addElement(getUpdateByExampleIncludeElement());

    if (context.getPlugins()
            .sqlMapUpdateByExampleSelectiveElementGenerated(answer,
                    introspectedTable)) {
        parentElement.addElement(answer);
    }
}
 
开发者ID:bandaotixi,项目名称:generator_mybatis,代码行数:50,代码来源:UpdateByExampleSelectiveElementGenerator.java


示例11: addElements

import org.mybatis.generator.codegen.mybatis3.ListUtilities; //导入依赖的package包/类
@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 = ListUtilities.removeGeneratedAlwaysColumns(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);
    }
}
 
开发者ID:bandaotixi,项目名称:generator_mybatis,代码行数:53,代码来源:UpdateByExampleWithBLOBsElementGenerator.java


示例12: addElements

import org.mybatis.generator.codegen.mybatis3.ListUtilities; //导入依赖的package包/类
@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 = ListUtilities.removeGeneratedAlwaysColumns(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);
    }
}
 
开发者ID:bandaotixi,项目名称:generator_mybatis,代码行数:54,代码来源:UpdateByExampleWithoutBLOBsElementGenerator.java


示例13: generateXmlElementWithSelective

import org.mybatis.generator.codegen.mybatis3.ListUtilities; //导入依赖的package包/类
/**
 * 当Selective情况
 * @param document
 * @param introspectedTable
 */
private void generateXmlElementWithSelective(Document document, IntrospectedTable introspectedTable) {
    List<IntrospectedColumn> columns = ListUtilities.removeGeneratedAlwaysColumns(introspectedTable.getAllColumns());
    // ====================================== upsertSelective ======================================
    XmlElement eleUpsertSelective = new XmlElement("insert");
    eleUpsertSelective.addAttribute(new Attribute("id", METHOD_UPSERT_SELECTIVE));
    // 添加注释(!!!必须添加注释,overwrite覆盖生成时,@see XmlFileMergerJaxp.isGeneratedNode会去判断注释中是否存在OLD_ELEMENT_TAGS中的一点,例子:@mbg.generated)
    commentGenerator.addComment(eleUpsertSelective);

    // 参数类型
    eleUpsertSelective.addAttribute(new Attribute("parameterType", introspectedTable.getRules().calculateAllFieldsClass().getFullyQualifiedName()));

    // 使用JDBC的getGenereatedKeys方法获取主键并赋值到keyProperty设置的领域模型属性中。所以只支持MYSQL和SQLServer
    XmlElementGeneratorTools.useGeneratedKeys(eleUpsertSelective, introspectedTable);

    // insert
    eleUpsertSelective.addElement(new TextElement("insert into " + introspectedTable.getFullyQualifiedTableNameAtRuntime()));
    eleUpsertSelective.addElement(XmlElementGeneratorTools.generateKeysSelective(columns));
    eleUpsertSelective.addElement(new TextElement("values"));
    eleUpsertSelective.addElement(XmlElementGeneratorTools.generateValuesSelective(columns));
    eleUpsertSelective.addElement(new TextElement("on duplicate key update "));
    // set 操作增加增量插件支持
    this.incrementsSelectiveSupport(eleUpsertSelective, XmlElementGeneratorTools.generateSetsSelective(columns, null, false), introspectedTable, false);

    document.getRootElement().addElement(eleUpsertSelective);
    logger.debug("itfsw(存在即更新插件):" + introspectedTable.getMyBatis3XmlMapperFileName() + "增加upsertSelective实现方法。");
    if (this.allowMultiQueries) {
        // ====================================== upsertByExampleSelective ======================================
        XmlElement eleUpsertByExampleSelective = new XmlElement("insert");
        eleUpsertByExampleSelective.addAttribute(new Attribute("id", METHOD_UPSERT_BY_EXAMPLE_SELECTIVE));
        // 参数类型
        eleUpsertByExampleSelective.addAttribute(new Attribute("parameterType", "map"));
        // 添加注释(!!!必须添加注释,overwrite覆盖生成时,@see XmlFileMergerJaxp.isGeneratedNode会去判断注释中是否存在OLD_ELEMENT_TAGS中的一点,例子:@mbg.generated)
        commentGenerator.addComment(eleUpsertByExampleSelective);

        // 使用JDBC的getGenereatedKeys方法获取主键并赋值到keyProperty设置的领域模型属性中。所以只支持MYSQL和SQLServer
        XmlElementGeneratorTools.useGeneratedKeys(eleUpsertByExampleSelective, introspectedTable, "record.");

        // insert
        eleUpsertByExampleSelective.addElement(new TextElement("insert into " + introspectedTable.getFullyQualifiedTableNameAtRuntime()));
        eleUpsertByExampleSelective.addElement(XmlElementGeneratorTools.generateKeysSelective(columns, "record."));
        this.generateExistsClause(introspectedTable, eleUpsertByExampleSelective, true, columns);

        // multiQueries
        eleUpsertByExampleSelective.addElement(new TextElement(";"));

        // update
        eleUpsertByExampleSelective.addElement(new TextElement("update " + introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()));
        eleUpsertByExampleSelective.addElement(new TextElement("set"));
        // set 操作增加增量插件支持
        this.incrementsSelectiveSupport(eleUpsertByExampleSelective, XmlElementGeneratorTools.generateSetsSelective(ListUtilities.removeIdentityAndGeneratedAlwaysColumns(columns), "record."), introspectedTable, true);

        // update where
        eleUpsertByExampleSelective.addElement(XmlElementGeneratorTools.getUpdateByExampleIncludeElement(introspectedTable));

        document.getRootElement().addElement(eleUpsertByExampleSelective);
        logger.debug("itfsw(存在即更新插件):" + introspectedTable.getMyBatis3XmlMapperFileName() + "增加upsertSelective实现方法。");
    }
}
 
开发者ID:itfsw,项目名称:mybatis-generator-plugin,代码行数:64,代码来源:UpsertPlugin.java


示例14: addMapperAnnotations

import org.mybatis.generator.codegen.mybatis3.ListUtilities; //导入依赖的package包/类
@Override
public void addMapperAnnotations(Interface interfaze, Method method) {
    interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.Insert")); //$NON-NLS-1$
    
    GeneratedKey gk = introspectedTable.getGeneratedKey();
    
    method.addAnnotation("@Insert({"); //$NON-NLS-1$
    StringBuilder insertClause = new StringBuilder();
    StringBuilder valuesClause = new StringBuilder();
    
    javaIndent(insertClause, 1);
    javaIndent(valuesClause, 1);

    insertClause.append("\"insert into "); //$NON-NLS-1$
    insertClause.append(escapeStringForJava(introspectedTable
            .getFullyQualifiedTableNameAtRuntime()));
    insertClause.append(" ("); //$NON-NLS-1$

    valuesClause.append("\"values ("); //$NON-NLS-1$

    List<String> valuesClauses = new ArrayList<String>();
    Iterator<IntrospectedColumn> iter = ListUtilities.removeIdentityAndGeneratedAlwaysColumns(introspectedTable.getAllColumns())
            .iterator();
    boolean hasFields = false;
    while (iter.hasNext()) {
        IntrospectedColumn introspectedColumn = iter.next();

        insertClause.append(escapeStringForJava(getEscapedColumnName(introspectedColumn)));
        valuesClause.append(getParameterClause(introspectedColumn));
        hasFields = true;
        if (iter.hasNext()) {
            insertClause.append(", "); //$NON-NLS-1$
            valuesClause.append(", "); //$NON-NLS-1$
        }

        if (valuesClause.length() > 60) {
            if (!iter.hasNext()) {
                insertClause.append(')');
                valuesClause.append(')');
            }
            insertClause.append("\","); //$NON-NLS-1$
            valuesClause.append('\"');
            if (iter.hasNext()) {
                valuesClause.append(',');
            }
            
            method.addAnnotation(insertClause.toString());
            insertClause.setLength(0);
            javaIndent(insertClause, 1);
            insertClause.append('\"');
            
            valuesClauses.add(valuesClause.toString());
            valuesClause.setLength(0);
            javaIndent(valuesClause, 1);
            valuesClause.append('\"');
            hasFields = false;
        }
    }
    
    if (hasFields) {
        insertClause.append(")\","); //$NON-NLS-1$
        method.addAnnotation(insertClause.toString());

        valuesClause.append(")\""); //$NON-NLS-1$
        valuesClauses.add(valuesClause.toString());
    }

    for (String clause : valuesClauses) {
        method.addAnnotation(clause);
    }
    
    method.addAnnotation("})"); //$NON-NLS-1$

    if (gk != null) {
        addGeneratedKeyAnnotation(interfaze, method, gk);
    }
}
 
开发者ID:xiachengwei5,项目名称:org.mybatis.generator.core-1.3.5,代码行数:78,代码来源:AnnotatedInsertMethodGenerator.java


示例15: addClassElements

import org.mybatis.generator.codegen.mybatis3.ListUtilities; //导入依赖的package包/类
@Override
public void addClassElements(TopLevelClass topLevelClass) {
    Set<String> staticImports = new TreeSet<String>();
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();

    if (useLegacyBuilder) {
        staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.BEGIN"); //$NON-NLS-1$
        staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.UPDATE"); //$NON-NLS-1$
        staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SET"); //$NON-NLS-1$
        staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SQL"); //$NON-NLS-1$
    } else {
        importedTypes.add(NEW_BUILDER_IMPORT);
    }

    importedTypes.add(new FullyQualifiedJavaType("java.util.Map")); //$NON-NLS-1$
    
    Method method = new Method(getMethodName());
    method.setReturnType(FullyQualifiedJavaType.getStringInstance());
    method.setVisibility(JavaVisibility.PUBLIC);
    method.addParameter(new Parameter(new FullyQualifiedJavaType("java.util.Map<java.lang.String, java.lang.Object>"), //$NON-NLS-1$
            "parameter")); //$NON-NLS-1$
    
    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    if (useLegacyBuilder) {
        method.addBodyLine("BEGIN();"); //$NON-NLS-1$
    } else {
        method.addBodyLine("SQL sql = new SQL();"); //$NON-NLS-1$
    }
    
    method.addBodyLine(String.format("%sUPDATE(\"%s\");", //$NON-NLS-1$
            builderPrefix,
            escapeStringForJava(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime())));
    method.addBodyLine(""); //$NON-NLS-1$
    
    for (IntrospectedColumn introspectedColumn : ListUtilities.removeGeneratedAlwaysColumns(getColumns())) {
        StringBuilder sb = new StringBuilder();
        sb.append(getParameterClause(introspectedColumn));
        sb.insert(2, "record."); //$NON-NLS-1$
        
        method.addBodyLine(String.format("%sSET(\"%s = %s\");", //$NON-NLS-1$
                builderPrefix,
                escapeStringForJava(getAliasedEscapedColumnName(introspectedColumn)),
                sb.toString()));
    }
    
    method.addBodyLine(""); //$NON-NLS-1$
    
    FullyQualifiedJavaType example =
            new FullyQualifiedJavaType(introspectedTable.getExampleType());
    importedTypes.add(example);
    method.addBodyLine(String.format("%s example = (%s) parameter.get(\"example\");", //$NON-NLS-1$
            example.getShortName(), example.getShortName()));
    
    if (useLegacyBuilder) {
        method.addBodyLine("applyWhere(example, true);"); //$NON-NLS-1$
        method.addBodyLine("return SQL();"); //$NON-NLS-1$
    } else {
        method.addBodyLine("applyWhere(sql, example, true);"); //$NON-NLS-1$
        method.addBodyLine("return sql.toString();"); //$NON-NLS-1$
    }
    
    if (callPlugins(method, topLevelClass)) {
        topLevelClass.addStaticImports(staticImports);
        topLevelClass.addImportedTypes(importedTypes);
        topLevelClass.addMethod(method);
    }
}
 
开发者ID:nextyu,项目名称:summer-mybatis-generator,代码行数:70,代码来源:ProviderUpdateByExampleWithoutBLOBsMethodGenerator.java


示例16: addClassElements

import org.mybatis.generator.codegen.mybatis3.ListUtilities; //导入依赖的package包/类
@Override
public void addClassElements(TopLevelClass topLevelClass) {
    Set<String> staticImports = new TreeSet<String>();
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    
    if (useLegacyBuilder) {
        staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.BEGIN"); //$NON-NLS-1$
        staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.INSERT_INTO"); //$NON-NLS-1$
        staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.SQL"); //$NON-NLS-1$
        staticImports.add("org.apache.ibatis.jdbc.SqlBuilder.VALUES"); //$NON-NLS-1$
    } else {
        importedTypes.add(NEW_BUILDER_IMPORT);
    }

    FullyQualifiedJavaType fqjt = introspectedTable.getRules()
            .calculateAllFieldsClass();
    importedTypes.add(fqjt);

    Method method = new Method(
            introspectedTable.getInsertSelectiveStatementId());
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType.getStringInstance());
    method.addParameter(new Parameter(fqjt, "record")); //$NON-NLS-1$
    
    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    if (useLegacyBuilder) {
        method.addBodyLine("BEGIN();"); //$NON-NLS-1$
    } else {
        method.addBodyLine("SQL sql = new SQL();"); //$NON-NLS-1$
    }

    method.addBodyLine(String.format("%sINSERT_INTO(\"%s\");", //$NON-NLS-1$
            builderPrefix,
            escapeStringForJava(introspectedTable.getFullyQualifiedTableNameAtRuntime())));

    for (IntrospectedColumn introspectedColumn : ListUtilities.removeIdentityAndGeneratedAlwaysColumns(introspectedTable.getAllColumns())) {
        
        method.addBodyLine(""); //$NON-NLS-1$
        if (!introspectedColumn.getFullyQualifiedJavaType().isPrimitive()
                && !introspectedColumn.isSequenceColumn()) {
            method.addBodyLine(String.format("if (record.%s() != null) {", //$NON-NLS-1$
                    getGetterMethodName(introspectedColumn.getJavaProperty(),
                            introspectedColumn.getFullyQualifiedJavaType())));
        }
        method.addBodyLine(String.format("%sVALUES(\"%s\", \"%s\");", //$NON-NLS-1$
                builderPrefix,
                escapeStringForJava(getEscapedColumnName(introspectedColumn)),
                getParameterClause(introspectedColumn)));

        if (!introspectedColumn.getFullyQualifiedJavaType().isPrimitive()
                && !introspectedColumn.isSequenceColumn()) {
            method.addBodyLine("}"); //$NON-NLS-1$
        }
    }
    
    method.addBodyLine(""); //$NON-NLS-1$
    if (useLegacyBuilder) {
        method.addBodyLine("return SQL();"); //$NON-NLS-1$
    } else {
        method.addBodyLine("return sql.toString();"); //$NON-NLS-1$
    }
    
    if (context.getPlugins().providerInsertSelectiveMethodGenerated(method, topLevelClass,
            introspectedTable)) {
        topLevelClass.addStaticImports(staticImports);
        topLevelClass.addImportedTypes(importedTypes);
        topLevelClass.addMethod(method);
    }
}
 
开发者ID:nextyu,项目名称:summer-mybatis-generator,代码行数:72,代码来源:ProviderInsertSelectiveMethodGenerator.java



注:本文中的org.mybatis.generator.codegen.mybatis3.ListUtilities类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DatabaseURL类代码示例发布时间:2022-05-23
下一篇:
Java UniqueOrKey类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap