Java Code Examples for org.mybatis.generator.codegen.mybatis3.MyBatis3FormattingUtilities#getParameterClause()

The following examples show how to use org.mybatis.generator.codegen.mybatis3.MyBatis3FormattingUtilities#getParameterClause() . 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: OptimisticLockerPlugin.java    From mybatis-generator-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * 生成版本号set节点
 * @param selective
 * @return
 */
private TextElement generateVersionSetEle(boolean selective) {
    if (this.customizedNextVersion) {
        return new TextElement(
                (selective ? "" : "set ")
                        + MyBatis3FormattingUtilities.getEscapedColumnName(this.versionColumn)
                        + " = "
                        + MyBatis3FormattingUtilities.getParameterClause(this.versionColumn, "record.")
                        + ","
        );
    } else {
        return new TextElement(
                (selective ? "" : "set ")
                        + MyBatis3FormattingUtilities.getEscapedColumnName(this.versionColumn)
                        + " = "
                        + MyBatis3FormattingUtilities.getEscapedColumnName(this.versionColumn)
                        + " + 1,"
        );
    }
}
 
Example 2
Source File: PostgisGeoPlugin.java    From dolphin with Apache License 2.0 6 votes vote down vote up
protected void checkAndReplaceInput(List<IntrospectedColumn> columns, TextElement te) {
  String sql = te.getContent();
  for(IntrospectedColumn column : columns){
  	if(column.getFullyQualifiedJavaType().getShortName().equals("Geometry")){
  		String paramStr = MyBatis3FormattingUtilities.getParameterClause(column);
  		sql = StringUtils.replace(sql, paramStr, "ST_GeomFromText(" + paramStr + ","+srid+")"); //replace no prefix geo relate column
  		paramStr = MyBatis3FormattingUtilities.getParameterClause(column, "record.");
  		sql = StringUtils.replace(sql, paramStr, "ST_GeomFromText(" + paramStr + ","+srid+")"); //replace mbg generate prefix geo relate column
  		paramStr = MyBatis3FormattingUtilities.getParameterClause(column, "item.");
  		sql = StringUtils.replace(sql, paramStr, "ST_GeomFromText(" + paramStr + ","+srid+")"); //replace mbg batch plugin generate prefix geo relate column				
//				System.out.println();
//				System.out.println(sql);
  	}
  }
  try {
    FieldUtils.writeDeclaredField(te, "content", sql, true);
  } catch (IllegalAccessException e) {
    e.printStackTrace();
  }
}
 
Example 3
Source File: BatchInsertPlugin.java    From hui-mybatis-generator-plugins with Apache License 2.0 4 votes vote down vote up
/**
 * batchInsert和batchInsertSelective的SQL生成
 *
 * @param document
 * @param introspectedTable
 */
private void addSqlMapper(Document document, IntrospectedTable introspectedTable) {
    //table名名字
    String tableName = introspectedTable.getFullyQualifiedTableNameAtRuntime();
    //column信息
    List<IntrospectedColumn> columnList = introspectedTable.getAllColumns();

    XmlElement baseElement = SqlMapperGeneratorTool.baseElementGenerator(SqlMapperGeneratorTool.INSERT,
            BATCH_INSERT,
            FullyQualifiedJavaType.getNewListInstance());

    XmlElement foreachElement = SqlMapperGeneratorTool.baseForeachElementGenerator(PARAMETER_NAME,
            "item",
            "index",
            ",");

    baseElement.addElement(new TextElement(String.format("insert into %s (", tableName)));

    foreachElement.addElement(new TextElement("("));

    for (int i = 0; i < columnList.size(); i++) {
        String columnInfo = "";
        String valueInfo = "";
        IntrospectedColumn introspectedColumn = columnList.get(i);
        if (introspectedColumn.isIdentity()) {
            continue;
        }
        columnInfo = introspectedColumn.getActualColumnName();
        valueInfo = MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, "item.");
        if (i != (columnList.size() - 1)) {
            columnInfo += (",");
            valueInfo += (",");
        }
        baseElement.addElement(new TextElement(columnInfo));
        foreachElement.addElement(new TextElement(valueInfo));

    }
    foreachElement.addElement(new TextElement(")"));

    baseElement.addElement(new TextElement(")"));

    baseElement.addElement(new TextElement("values"));

    baseElement.addElement(foreachElement);

    //3.parent Add
    document.getRootElement().addElement(baseElement);
}
 
Example 4
Source File: OracleBatchUpdatePlugin.java    From hui-mybatis-generator-plugins with Apache License 2.0 4 votes vote down vote up
public void addSqlMapper(Document document, IntrospectedTable introspectedTable) {
    String tableName = introspectedTable.getFullyQualifiedTableNameAtRuntime();
    List<IntrospectedColumn> columnList = introspectedTable.getAllColumns();
    //primaryKey的JDBC名字
    String primaryKeyName = introspectedTable.getPrimaryKeyColumns().get(0).getActualColumnName();
    //primaryKey的JAVA名字
    String primaryKeyJavaName = introspectedTable.getPrimaryKeyColumns().get(0).getJavaProperty();

    String keyParameterClause = MyBatis3FormattingUtilities.getParameterClause(introspectedTable.getPrimaryKeyColumns().get(0), "item.");
    XmlElement baseElement = SqlMapperGeneratorTool.baseElementGenerator(SqlMapperGeneratorTool.UPDATE,
            BATCH_UPDATE,
            FullyQualifiedJavaType.getNewListInstance());

    XmlElement foreachElement = SqlMapperGeneratorTool.baseForeachElementGenerator(PARAMETER_NAME,
            "item",
            "index",
            ";");

    foreachElement.addElement(new TextElement( String.format("update %s", tableName)));

    XmlElement setElement = new XmlElement("set");

    StringBuilder columnInfo = new StringBuilder();
    StringBuilder valuesInfo = new StringBuilder();

    for (int i = 0; i < columnList.size(); i++) {

        IntrospectedColumn introspectedColumn = columnList.get(i);
        if (introspectedColumn.isIdentity()) {
            continue;
        }
        columnInfo.append(introspectedColumn.getActualColumnName());
        valuesInfo.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, "item."));
        if (i != (columnList.size() - 1)) {
            valuesInfo.append(",");
        }
        String setSql = String.format(" %s = %s" ,columnInfo,valuesInfo);

        setElement.addElement(new TextElement(setSql));

        valuesInfo.delete(0, valuesInfo.length());
        columnInfo.delete(0, columnInfo.length());

    }

    foreachElement.addElement(setElement);

    String whereSql = String.format("where %s = %s",primaryKeyName,keyParameterClause);

    foreachElement.addElement(new TextElement(whereSql));

    baseElement.addElement(new TextElement("begin"));

    baseElement.addElement(foreachElement);

    baseElement.addElement(new TextElement(";end;"));

    //3.parent Add
    document.getRootElement().addElement(baseElement);
}
 
Example 5
Source File: OracleBatchInsertPlugin.java    From hui-mybatis-generator-plugins with Apache License 2.0 4 votes vote down vote up
private void addSqlMapper(Document document, IntrospectedTable introspectedTable) {
    //1.Batchinsert
    XmlElement baseElement = SqlMapperGeneratorTool.baseElementGenerator(SqlMapperGeneratorTool.INSERT,
            BATCH_INSERT,
            FullyQualifiedJavaType.getNewListInstance());

    XmlElement foreachElement = SqlMapperGeneratorTool.baseForeachElementGenerator(PARAMETER_NAME,
            "item",
            "index",
            "union all");


    //tableName
    baseElement.addElement(new TextElement(String.format("insert into %s (", introspectedTable.getFullyQualifiedTableNameAtRuntime())));

    foreachElement.addElement(new TextElement("("));
    foreachElement.addElement(new TextElement("select"));

    for (int i = 0; i < introspectedTable.getAllColumns().size(); i++) {
        //column信息
        IntrospectedColumn introspectedColumn = introspectedTable.getAllColumns().get(i);

        String columnInfo = "";
        String valueInfo = "";

        columnInfo = introspectedColumn.getActualColumnName();
        valueInfo = MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, "item.");
        if (introspectedColumn.isIdentity()) {
            String nextval = introspectedTable.getFullyQualifiedTableNameAtRuntime()+"_SEQUENCE.nextval" ;
            valueInfo = nextval;
        }
        if (i != (introspectedTable.getAllColumns().size() - 1)) {
            columnInfo += (",");
            valueInfo += ",";
        }
        baseElement.addElement(new TextElement(columnInfo));
        foreachElement.addElement(new TextElement(valueInfo));
    }
    foreachElement.addElement(new TextElement("from dual"));
    foreachElement.addElement(new TextElement(")"));


    baseElement.addElement(new TextElement(")"));

    baseElement.addElement(new TextElement("("));
    baseElement.addElement(foreachElement);
    baseElement.addElement(new TextElement(")"));

    //3.parent Add
    document.getRootElement().addElement(baseElement);
}
 
Example 6
Source File: IncrementsPlugin.java    From mybatis-generator-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * 生成增量操作节点
 * @param introspectedColumn
 * @param prefix
 * @param hasComma
 * @return
 */
@Override
public List<Element> incrementSetElementGenerated(IntrospectedColumn introspectedColumn, String prefix, boolean hasComma) {
    List<Element> list = new ArrayList<>();

    if (this.supportIncrement(introspectedColumn)) {
        // 1. column = 节点
        list.add(new TextElement(MyBatis3FormattingUtilities.getEscapedColumnName(introspectedColumn) + " = "));

        // 2. 选择节点
        // 条件
        XmlElement choose = new XmlElement("choose");

        // 没有启用增量操作
        XmlElement when = new XmlElement("when");
        when.addAttribute(new Attribute(
                "test",
                (prefix != null ? prefix : "_parameter.") + IncrementsPlugin.METHOD_INC_CHECK
                        + "('" + MyBatis3FormattingUtilities.escapeStringForMyBatis3(introspectedColumn.getActualColumnName()) + "')"
        ));
        TextElement spec = new TextElement(
                MyBatis3FormattingUtilities.getEscapedColumnName(introspectedColumn)
                        + " ${" + (prefix != null ? prefix : "_parameter.")
                        + IncrementsPlugin.METHOD_GET_INC_MAP + "()." + MyBatis3FormattingUtilities.escapeStringForMyBatis3(introspectedColumn.getActualColumnName()) + ".value} "
                        + MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, prefix));
        when.addElement(spec);
        choose.addElement(when);

        // 启用了增量操作
        XmlElement otherwise = new XmlElement("otherwise");
        TextElement normal = new TextElement(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, prefix));
        otherwise.addElement(normal);
        choose.addElement(otherwise);

        list.add(choose);

        // 3. 结尾逗号
        if (hasComma) {
            list.add(new TextElement(","));
        }
    }

    return list;
}