org.mybatis.generator.api.IntrospectedColumn Java Examples

The following examples show how to use org.mybatis.generator.api.IntrospectedColumn. 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: AbstractXmlElementGenerator.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
/**
 * This method should return an XmlElement for the select key used to
 * automatically generate keys.
 * 
 * @param introspectedColumn
 *            the column related to the select key statement
 * @param generatedKey
 *            the generated key for the current table
 * @return the selectKey element
 */
protected XmlElement getSelectKey(IntrospectedColumn introspectedColumn,
        GeneratedKey generatedKey) {
    String identityColumnType = introspectedColumn
            .getFullyQualifiedJavaType().getFullyQualifiedName();

    XmlElement answer = new XmlElement("selectKey"); //$NON-NLS-1$
    answer.addAttribute(new Attribute("resultType", identityColumnType)); //$NON-NLS-1$
    answer.addAttribute(new Attribute(
            "keyProperty", introspectedColumn.getJavaProperty())); //$NON-NLS-1$
    answer.addAttribute(new Attribute("order", //$NON-NLS-1$
            generatedKey.getMyBatis3Order())); 
    
    answer.addElement(new TextElement(generatedKey
                    .getRuntimeSqlStatement()));

    return answer;
}
 
Example #2
Source File: CommentGenerator.java    From mall-learning with Apache License 2.0 6 votes vote down vote up
/**
     * 给字段添加注释
     */
    @Override
    public void addFieldComment(Field field, IntrospectedTable introspectedTable,
                                IntrospectedColumn introspectedColumn) {
        String remarks = introspectedColumn.getRemarks();
        //根据参数和备注信息判断是否添加备注信息
        if(addRemarkComments&&StringUtility.stringHasValue(remarks)){
//            addFieldJavaDoc(field, remarks);
            //数据库中特殊字符需要转义
            if(remarks.contains("\"")){
                remarks = remarks.replace("\"","'");
            }
            //给model的字段添加swagger注解
            field.addJavaDocLine("@ApiModelProperty(value = \""+remarks+"\")");
        }
    }
 
Example #3
Source File: XmlElementGeneratorTools.java    From mybatis-generator-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * 生成
 * @param element
 * @param introspectedColumn
 * @param prefix
 * @param type               1:key,2:value,3:set
 */
private static void generateSelectiveCommColumnTo(XmlElement element, IntrospectedColumn introspectedColumn, String prefix, int type) {
    switch (type) {
        case 3:
            List<Element> incrementEles = PluginTools.getHook(IIncrementsPluginHook.class).incrementSetElementGenerated(introspectedColumn, prefix, true);
            if (!incrementEles.isEmpty()) {
                // 增量插件支持
                for (Element ele : incrementEles) {
                    element.addElement(ele);
                }
            } else {
                element.addElement(new TextElement(MyBatis3FormattingUtilities.getEscapedColumnName(introspectedColumn) + " = " + MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, prefix) + ","));
            }
            break;
        case 2:
            element.addElement(new TextElement(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, prefix) + ","));
            break;
        case 1:
            element.addElement(new TextElement(MyBatis3FormattingUtilities.getEscapedColumnName(introspectedColumn) + ","));
            break;
    }
}
 
Example #4
Source File: ExampleGenerator.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
private Method getNoValueMethod(IntrospectedColumn introspectedColumn,
        String nameFragment, String operator) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    StringBuilder sb = new StringBuilder();
    sb.append(introspectedColumn.getJavaProperty());
    sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
    sb.insert(0, "and"); //$NON-NLS-1$
    sb.append(nameFragment);
    method.setName(sb.toString());
    method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());
    sb.setLength(0);
    sb.append("addCriterion(\""); //$NON-NLS-1$
    sb.append(Ibatis2FormattingUtilities
            .getAliasedActualColumnName(introspectedColumn));
    sb.append(' ');
    sb.append(operator);
    sb.append("\");"); //$NON-NLS-1$
    method.addBodyLine(sb.toString());
    method.addBodyLine("return (Criteria) this;"); //$NON-NLS-1$

    return method;
}
 
Example #5
Source File: GenPlugin.java    From scaffold-cloud with MIT License 6 votes vote down vote up
/**
 * 保存
 *
 * @param id
 * @param pkColumn
 * @return
 */
private XmlElement createSave(String id, IntrospectedColumn pkColumn) {
    XmlElement save = new XmlElement("insert");
    save.addAttribute(new Attribute("id", id));
    if (null != pkColumn) {
        save.addAttribute(new Attribute("keyProperty", "item." + pkColumn.getJavaProperty()));
        save.addAttribute(new Attribute("useGeneratedKeys", "true"));
        save.addElement(new TextElement("<include refid=\"sql_insert_columns\" /><include " +
                "refid=\"sql_insert_values\" />"));
    } else {
        StringBuilder saveStr = new StringBuilder(
                "<foreach collection=\"list\" index=\"index\" item=\"item\" open=\"\" separator=\";\" " +
                        "close=\"\">\n\t  ")
                .append("<include refid=\"sql_insert_columns\" /><include refid=\"sql_insert_values\" " +
                        "/>\n\t</foreach>");
        save.addElement(new TextElement(saveStr.toString()));
    }
    return save;
}
 
Example #6
Source File: AbstractXmbgPlugin.java    From dolphin with Apache License 2.0 6 votes vote down vote up
protected void generateActualColumnNamesWithParenthesis(String fieldPrefix, String columnPrefix, boolean ifNullCheck, List<IntrospectedColumn> columns, XmlElement parent) {
  XmlElement trimElement = new XmlElement("trim");
  trimElement.addAttribute(new Attribute("suffixOverrides", ","));
  trimElement.addAttribute(new Attribute("prefix", "("));
  trimElement.addAttribute(new Attribute("suffix", ")"));

  StringBuilder sb = new StringBuilder();
  for (IntrospectedColumn introspectedColumn : columns) {
    sb.setLength(0);
    sb.append((columnPrefix == null ? "" : columnPrefix) + MyBatis3FormattingUtilities.getAliasedEscapedColumnName(introspectedColumn));
    sb.append(",");

    doIfNullCheck(fieldPrefix, ifNullCheck, trimElement, sb, introspectedColumn);
  }

  parent.addElement(trimElement);
}
 
Example #7
Source File: TableColumnBuilder.java    From Mapper with MIT License 6 votes vote down vote up
/**
 * 创建 ColumnField
 *
 * @param column
 * @return
 */
public static ColumnField build(IntrospectedColumn column) {
    ColumnField field = new ColumnField();
    field.setColumnName(column.getActualColumnName());
    field.setJdbcType(column.getJdbcTypeName());
    field.setFieldName(column.getJavaProperty());
    field.setRemarks(column.getRemarks());
    FullyQualifiedJavaType type = column.getFullyQualifiedJavaType();
    field.setType(type);
    field.setTypePackage(type.getPackageName());
    field.setShortTypeName(type.getShortName());
    field.setFullTypeName(type.getFullyQualifiedName());
    field.setIdentity(column.isIdentity());
    field.setNullable(column.isNullable());
    field.setSequenceColumn(column.isSequenceColumn());
    field.setBlobColumn(column.isBLOBColumn());
    field.setStringColumn(column.isStringColumn());
    field.setJdbcCharacterColumn(column.isJdbcCharacterColumn());
    field.setJdbcDateColumn(column.isJDBCDateColumn());
    field.setJdbcTimeColumn(column.isJDBCTimeColumn());
    field.setLength(column.getLength());
    field.setScale(column.getScale());
    return field;
}
 
Example #8
Source File: CommentGenerator.java    From mall-swarm with Apache License 2.0 6 votes vote down vote up
/**
     * 给字段添加注释
     */
    @Override
    public void addFieldComment(Field field, IntrospectedTable introspectedTable,
                                IntrospectedColumn introspectedColumn) {
        String remarks = introspectedColumn.getRemarks();
        //根据参数和备注信息判断是否添加备注信息
        if(addRemarkComments&&StringUtility.stringHasValue(remarks)){
//            addFieldJavaDoc(field, remarks);
            //数据库中特殊字符需要转义
            if(remarks.contains("\"")){
                remarks = remarks.replace("\"","'");
            }
            //给model的字段添加swagger注解
            field.addJavaDocLine("@ApiModelProperty(value = \""+remarks+"\")");
        }
    }
 
Example #9
Source File: Ibatis2FormattingUtilities.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
/**
 * The aliased column name for a select statement generated by the example clauses. This is not appropriate for
 * selects in SqlMaps because the column is not escaped for iBATIS. If there is a table alias, the value will be
 * alias.columnName.
 * 
 * This method is used in the Example classes and the returned value will be in a Java string. So we need to escape
 * double quotes if they are the delimiters.
 *
 * @param introspectedColumn
 *            the introspected column
 * @return the aliased column name
 */
public static String getAliasedActualColumnName(
        IntrospectedColumn introspectedColumn) {
    StringBuilder sb = new StringBuilder();
    if (stringHasValue(introspectedColumn.getTableAlias())) {
        sb.append(introspectedColumn.getTableAlias());
        sb.append('.');
    }

    if (introspectedColumn.isColumnNameDelimited()) {
        sb.append(escapeStringForJava(introspectedColumn
                .getContext().getBeginningDelimiter()));
    }

    sb.append(introspectedColumn.getActualColumnName());

    if (introspectedColumn.isColumnNameDelimited()) {
        sb.append(escapeStringForJava(introspectedColumn
                .getContext().getEndingDelimiter()));
    }

    return sb.toString();
}
 
Example #10
Source File: Ibatis2FormattingUtilities.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
/**
 * The phrase to use in a select list. If there is a table alias, the value
 * will be "alias.columnName as alias_columnName"
 * 
 * @return the proper phrase
 */
public static String getSelectListPhrase(
        IntrospectedColumn introspectedColumn) {
    if (stringHasValue(introspectedColumn.getTableAlias())) {
        StringBuilder sb = new StringBuilder();

        sb.append(getAliasedEscapedColumnName(introspectedColumn));
        sb.append(" as "); //$NON-NLS-1$
        if (introspectedColumn.isColumnNameDelimited()) {
            sb.append(introspectedColumn.getContext()
                    .getBeginningDelimiter());
        }
        sb.append(introspectedColumn.getTableAlias());
        sb.append('_');
        sb.append(escapeStringForIbatis2(introspectedColumn
                .getActualColumnName()));
        if (introspectedColumn.isColumnNameDelimited()) {
            sb.append(introspectedColumn.getContext().getEndingDelimiter());
        }
        return sb.toString();
    } else {
        return getEscapedColumnName(introspectedColumn);
    }
}
 
Example #11
Source File: MyBatis3FormattingUtilities.java    From mapper-generator-javafx with Apache License 2.0 6 votes vote down vote up
public static String getParameterClause(
        IntrospectedColumn introspectedColumn, String prefix) {
    StringBuilder sb = new StringBuilder();

    sb.append("#{");
    sb.append(introspectedColumn.getJavaProperty(prefix));
    sb.append(",jdbcType=");
    sb.append(introspectedColumn.getJdbcTypeName());

    if (stringHasValue(introspectedColumn.getTypeHandler())) {
        sb.append(",typeHandler=");
        sb.append(introspectedColumn.getTypeHandler());
    }

    sb.append('}');

    return sb.toString();
}
 
Example #12
Source File: CommentGenerator.java    From mall-learning with Apache License 2.0 6 votes vote down vote up
/**
     * 给字段添加注释
     */
    @Override
    public void addFieldComment(Field field, IntrospectedTable introspectedTable,
                                IntrospectedColumn introspectedColumn) {
        String remarks = introspectedColumn.getRemarks();
        //根据参数和备注信息判断是否添加备注信息
        if(addRemarkComments&&StringUtility.stringHasValue(remarks)){
//            addFieldJavaDoc(field, remarks);
            //数据库中特殊字符需要转义
            if(remarks.contains("\"")){
                remarks = remarks.replace("\"","'");
            }
            //给model的字段添加swagger注解
            field.addJavaDocLine("@ApiModelProperty(value = \""+remarks+"\")");
        }
    }
 
Example #13
Source File: DG2CommentGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
@Override
public void addFieldComment(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
    // 添加字段注释
    StringBuffer sb = new StringBuffer();
    field.addJavaDocLine("/**");
    //对应表中字段的备注(数据库中自己写的备注信息)
    if (introspectedColumn.getRemarks() != null)
        field.addJavaDocLine(" * " + introspectedColumn.getRemarks());
    sb.append(" * 表字段 : ");
    //对应表名称
    sb.append(introspectedTable.getFullyQualifiedTable());
    sb.append('.');
    //对应表中字段的名称
    sb.append(introspectedColumn.getActualColumnName());
    field.addJavaDocLine(sb.toString());
    // addJavadocTag(field, false);
    field.addJavaDocLine(" */");
}
 
Example #14
Source File: AbstractXmlElementGenerator.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
/**
 * This method should return an XmlElement for the select key used to
 * automatically generate keys.
 * 
 * @param introspectedColumn
 *            the column related to the select key statement
 * @param generatedKey
 *            the generated key for the current table
 * @return the selectKey element
 */
protected XmlElement getSelectKey(IntrospectedColumn introspectedColumn,
        GeneratedKey generatedKey) {
    String identityColumnType = introspectedColumn
            .getFullyQualifiedJavaType().getFullyQualifiedName();

    XmlElement answer = new XmlElement("selectKey"); //$NON-NLS-1$
    answer.addAttribute(new Attribute("resultClass", identityColumnType)); //$NON-NLS-1$
    answer.addAttribute(new Attribute(
            "keyProperty", introspectedColumn.getJavaProperty())); //$NON-NLS-1$
    if (stringHasValue(generatedKey.getType())) {
        answer.addAttribute(new Attribute("type", generatedKey.getType())); //$NON-NLS-1$  
    }
    answer
            .addElement(new TextElement(generatedKey
                    .getRuntimeSqlStatement()));

    return answer;
}
 
Example #15
Source File: MyMapperCommentGenerator.java    From jvue-admin with MIT License 6 votes vote down vote up
/**
 * getter方法注释
 *
 * @param method
 * @param introspectedTable
 * @param introspectedColumn
 */
@Override
public void addGetterComment(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
    StringBuilder sb = new StringBuilder();
    method.addJavaDocLine("/**");
    if (StringUtility.stringHasValue(introspectedColumn.getRemarks())) {
        sb.append(" * 获取");
        sb.append(introspectedColumn.getRemarks());
        method.addJavaDocLine(sb.toString());
        method.addJavaDocLine(" *");
    }
    sb.setLength(0);
    sb.append(" * @return ");
    sb.append(introspectedColumn.getActualColumnName());
    if (StringUtility.stringHasValue(introspectedColumn.getRemarks())) {
        sb.append(" - ");
        sb.append(introspectedColumn.getRemarks());
    }
    method.addJavaDocLine(sb.toString());
    method.addJavaDocLine(" */");
}
 
Example #16
Source File: IncrementsPlugin.java    From mybatis-generator-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * 有Selective代码生成
 * @param element
 */
private void generatedWithSelective(XmlElement element, IntrospectedTable introspectedTable, boolean hasPrefix) {
    if (this.support()) {
        // 查找 set->if->text
        List<XmlElement> sets = XmlElementTools.findXmlElements(element, "set");
        if (sets.size() > 0) {
            List<XmlElement> ifs = XmlElementTools.findXmlElements(sets.get(0), "if");
            if (ifs.size() > 0) {
                for (XmlElement xmlElement : ifs) {
                    // 下面为if的text节点
                    List<Element> textEles = xmlElement.getElements();
                    TextElement textEle = (TextElement) textEles.get(0);
                    String[] strs = textEle.getContent().split("=");
                    String columnName = strs[0].trim();
                    IntrospectedColumn introspectedColumn = IntrospectedTableTools.safeGetColumn(introspectedTable, columnName);
                    // 查找是否需要进行增量操作
                    List<Element> incrementEles = PluginTools.getHook(IIncrementsPluginHook.class).incrementSetElementGenerated(introspectedColumn, hasPrefix ? "record." : null, true);
                    if (!incrementEles.isEmpty()) {
                        xmlElement.getElements().clear();
                        xmlElement.getElements().addAll(incrementEles);
                    }
                }
            }
        }
    }
}
 
Example #17
Source File: CommentGenerator.java    From HIS with Apache License 2.0 6 votes vote down vote up
/**
     * 给字段添加注释
     */
    @Override
    public void addFieldComment(Field field, IntrospectedTable introspectedTable,
                                IntrospectedColumn introspectedColumn) {
        String remarks = introspectedColumn.getRemarks();
        //根据参数和备注信息判断是否添加备注信息
        if(addRemarkComments&&StringUtility.stringHasValue(remarks)){
//            addFieldJavaDoc(field, remarks);
            //数据库中特殊字符需要转义
            if(remarks.contains("\"")){
                remarks = remarks.replace("\"","'");
            }
            //给model的字段添加swagger注解
            field.addJavaDocLine("@ApiModelProperty(value = \""+remarks+"\")");
        }
    }
 
Example #18
Source File: CaseInsensitiveLikePlugin.java    From mapper-generator-javafx with Apache License 2.0 6 votes vote down vote up
private Method toMethod(IntrospectedColumn introspectedColumn) {
    StringBuilder sb = new StringBuilder();
    sb.append(introspectedColumn.getJavaProperty());
    sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
    sb.insert(0, "and");
    sb.append("LikeInsensitive");
    Method method = new Method(sb.toString());
    method.setVisibility(JavaVisibility.PUBLIC);
    method.addParameter(new Parameter(introspectedColumn
            .getFullyQualifiedJavaType(), "value"));

    method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());

    sb.setLength(0);
    sb.append("addCriterion(\"upper(");
    sb.append(MyBatis3FormattingUtilities
            .getAliasedActualColumnName(introspectedColumn));
    sb.append(") like\", value.toUpperCase(), \"");
    sb.append(introspectedColumn.getJavaProperty());
    sb.append("\");");
    method.addBodyLine(sb.toString());
    method.addBodyLine("return (Criteria) this;");
    return method;
}
 
Example #19
Source File: CommentGenerator.java    From mall-learning with Apache License 2.0 6 votes vote down vote up
/**
     * 给字段添加注释
     */
    @Override
    public void addFieldComment(Field field, IntrospectedTable introspectedTable,
                                IntrospectedColumn introspectedColumn) {
        String remarks = introspectedColumn.getRemarks();
        //根据参数和备注信息判断是否添加备注信息
        if(addRemarkComments&&StringUtility.stringHasValue(remarks)){
//            addFieldJavaDoc(field, remarks);
            //数据库中特殊字符需要转义
            if(remarks.contains("\"")){
                remarks = remarks.replace("\"","'");
            }
            //给model的字段添加swagger注解
            field.addJavaDocLine("@ApiModelProperty(value = \""+remarks+"\")");
        }
    }
 
Example #20
Source File: GenCommentGenerator.java    From scaffold-cloud with MIT License 6 votes vote down vote up
/**
 * setter方法注释
 * @param method
 * @param introspectedTable
 * @param introspectedColumn
 */
@Override
public void addSetterComment(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
	StringBuilder sb = new StringBuilder();
	method.addJavaDocLine("/**");
	if (StringUtility.stringHasValue(introspectedColumn.getRemarks())) {
		sb.append(" * 设置");
		sb.append(introspectedColumn.getRemarks());
		method.addJavaDocLine(sb.toString());
		method.addJavaDocLine(" *");
	}
	Parameter parm = method.getParameters().get(0);
	sb.setLength(0);
	sb.append(" * @param ");
	sb.append(parm.getName());
	if (StringUtility.stringHasValue(introspectedColumn.getRemarks())) {
		sb.append(" ");
		sb.append(introspectedColumn.getRemarks());
	}
	method.addJavaDocLine(sb.toString());
	method.addJavaDocLine(" */");
}
 
Example #21
Source File: CommentGenerator.java    From xmall with MIT License 6 votes vote down vote up
/**
 * 给字段添加注释
 */
@Override
public void addFieldComment(Field field, IntrospectedTable introspectedTable,
                            IntrospectedColumn introspectedColumn) {
    String remarks = introspectedColumn.getRemarks();
    //根据参数和备注信息判断是否添加备注信息
    if(addRemarkComments&&StringUtility.stringHasValue(remarks)){
        //文档注释开始
        field.addJavaDocLine("/**");
        //获取数据库字段的备注信息
        String[] remarkLines = remarks.split(System.getProperty("line.separator"));
        for(String remarkLine:remarkLines){
            field.addJavaDocLine(" * "+remarkLine);
        }
        addJavadocTag(field, false);
        field.addJavaDocLine(" */");
    }
}
 
Example #22
Source File: MyBatis3FormattingUtilities.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
public static String getEscapedColumnName(
        IntrospectedColumn introspectedColumn) {
    StringBuilder sb = new StringBuilder();
    sb.append(introspectedColumn.getActualColumnName());

    if (introspectedColumn.isColumnNameDelimited()) {
        sb.insert(0, introspectedColumn.getContext()
                .getBeginningDelimiter());
        sb.append(introspectedColumn.getContext().getEndingDelimiter());
    }

    return sb.toString();
}
 
Example #23
Source File: Ibatis2FormattingUtilities.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
/**
 * The renamed column name for a select statement. If there is a table
 * alias, the value will be alias_columnName. This is appropriate for use in
 * a result map.
 * 
 * @return the renamed column name
 */
public static String getRenamedColumnNameForResultMap(
        IntrospectedColumn introspectedColumn) {
    if (stringHasValue(introspectedColumn.getTableAlias())) {
        StringBuilder sb = new StringBuilder();

        sb.append(introspectedColumn.getTableAlias());
        sb.append('_');
        sb.append(introspectedColumn.getActualColumnName());
        return sb.toString();
    } else {
        return introspectedColumn.getActualColumnName();
    }
}
 
Example #24
Source File: BaseColumnListElementGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
public void addElements(XmlElement parentElement) {
    XmlElement answer = new XmlElement("sql"); //$NON-NLS-1$

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

    context.getCommentGenerator().addComment(answer);

    StringBuilder sb = new StringBuilder();
    Iterator<IntrospectedColumn> iter = introspectedTable
            .getNonBLOBColumns().iterator();
    while (iter.hasNext()) {
        sb.append(Ibatis2FormattingUtilities.getSelectListPhrase(iter
                .next()));

        if (iter.hasNext()) {
            sb.append(", "); //$NON-NLS-1$
        }

        if (sb.length() > 80) {
            answer.addElement(new TextElement(sb.toString()));
            sb.setLength(0);
        }
    }

    if (sb.length() > 0) {
        answer.addElement((new TextElement(sb.toString())));
    }

    if (context.getPlugins().sqlMapBaseColumnListElementGenerated(
            answer, introspectedTable)) {
        parentElement.addElement(answer);
    }
}
 
Example #25
Source File: AbstractJavaMapperMethodGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
protected void addGeneratedKeyAnnotation(Interface interfaze, Method method,
        GeneratedKey gk) {
    StringBuilder sb = new StringBuilder();
    IntrospectedColumn introspectedColumn = introspectedTable.getColumn(gk.getColumn());
    if (introspectedColumn != null) {
        if (gk.isJdbcStandard()) {
            interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.Options")); //$NON-NLS-1$
            sb.append("@Options(useGeneratedKeys=true,keyProperty=\""); //$NON-NLS-1$
            sb.append(introspectedColumn.getJavaProperty());
            sb.append("\")"); //$NON-NLS-1$
            method.addAnnotation(sb.toString());
        } else {
            interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.SelectKey")); //$NON-NLS-1$
            FullyQualifiedJavaType fqjt = introspectedColumn.getFullyQualifiedJavaType();
            interfaze.addImportedType(fqjt);
            sb.append("@SelectKey(statement=\""); //$NON-NLS-1$
            sb.append(gk.getRuntimeSqlStatement());
            sb.append("\", keyProperty=\""); //$NON-NLS-1$
            sb.append(introspectedColumn.getJavaProperty());
            sb.append("\", before="); //$NON-NLS-1$
            sb.append(gk.isIdentity() ? "false" : "true"); //$NON-NLS-1$ //$NON-NLS-2$
            sb.append(", resultType="); //$NON-NLS-1$
            sb.append(fqjt.getShortName());
            sb.append(".class)"); //$NON-NLS-1$
            method.addAnnotation(sb.toString());
        }
    }
}
 
Example #26
Source File: BaseColumnListElementGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
public void addElements(XmlElement parentElement) {
    XmlElement answer = new XmlElement("sql"); //$NON-NLS-1$

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

    context.getCommentGenerator().addComment(answer);

    StringBuilder sb = new StringBuilder();
    Iterator<IntrospectedColumn> iter = introspectedTable
            .getNonBLOBColumns().iterator();
    while (iter.hasNext()) {
        sb.append(MyBatis3FormattingUtilities.getSelectListPhrase(iter
                .next()));

        if (iter.hasNext()) {
            sb.append(", "); //$NON-NLS-1$
        }

        if (sb.length() > 80) {
            answer.addElement(new TextElement(sb.toString()));
            sb.setLength(0);
        }
    }

    if (sb.length() > 0) {
        answer.addElement((new TextElement(sb.toString())));
    }

    if (context.getPlugins().sqlMapBaseColumnListElementGenerated(
            answer, introspectedTable)) {
        parentElement.addElement(answer);
    }
}
 
Example #27
Source File: OptimisticLockingPlugin.java    From mybatis-generator-plugins with Apache License 2.0 5 votes vote down vote up
IntrospectedColumn getColumn(IntrospectedTable introspectedTable) {
	for (IntrospectedColumn column : introspectedTable.getAllColumns()) {
		if (lockColumn.equals(column.getActualColumnName())) {
			return column;
		}
	}

	return null;
}
 
Example #28
Source File: DB2UpsertPlugin.java    From dolphin with Apache License 2.0 5 votes vote down vote up
@Override protected XmlElement buildSqlClause(IntrospectedTable introspectedTable) {
  XmlElement sql = new XmlElement("sql");
  sql.addAttribute(new Attribute("id", IDENTIFIERS_ARRAY_CONDITIONS));

  XmlElement foreach = new XmlElement("foreach");
  foreach.addAttribute(new Attribute("collection", "array"));
  foreach.addAttribute(new Attribute("item", "item"));
  foreach.addAttribute(new Attribute("index", "index"));
  foreach.addAttribute(new Attribute("separator", " and "));

  StringBuilder sb = new StringBuilder();
  for (IntrospectedColumn introspectedColumn : introspectedTable.getAllColumns()) {
    XmlElement isEqualElement = new XmlElement("if");
    sb.setLength(0);
    sb.append("item == \'");
    sb.append(introspectedColumn.getJavaProperty());
    sb.append("\'");
    isEqualElement.addAttribute(new Attribute("test", sb.toString()));
    foreach.addElement(isEqualElement);

    sb.setLength(0);

    String columnName = MyBatis3FormattingUtilities.getAliasedEscapedColumnName(introspectedColumn);

    sb.append(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime() + "." + columnName);
    sb.append(" = ");
    sb.append("temp." + columnName);

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

  sql.addElement(foreach);

  return sql;
}
 
Example #29
Source File: BatchInsertPlugin.java    From dolphin with Apache License 2.0 5 votes vote down vote up
protected XmlElement getSelectKey(IntrospectedColumn introspectedColumn, GeneratedKey generatedKey) {
  String identityColumnType = introspectedColumn
      .getFullyQualifiedJavaType().getFullyQualifiedName();

  XmlElement answer = new XmlElement("selectKey"); //$NON-NLS-1$
  answer.addAttribute(new Attribute("resultType", identityColumnType)); //$NON-NLS-1$
  answer.addAttribute(new Attribute("keyProperty", introspectedColumn.getJavaProperty())); //$NON-NLS-1$
  answer.addAttribute(new Attribute("order", //$NON-NLS-1$
      generatedKey.getMyBatis3Order()));

  answer.addElement(new TextElement(generatedKey.getRuntimeSqlStatement()));

  return answer;
}
 
Example #30
Source File: BlobColumnListElementGenerator.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
@Override
public void addElements(XmlElement parentElement) {
    XmlElement answer = new XmlElement("sql");

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

    context.getCommentGenerator().addComment(answer);

    StringBuilder sb = new StringBuilder();

    Iterator<IntrospectedColumn> iter = introspectedTable.getBLOBColumns()
            .iterator();
    while (iter.hasNext()) {
        sb.append(MyBatis3FormattingUtilities.getSelectListPhrase(iter
                .next()));

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

        if (sb.length() > 80) {
            answer.addElement(new TextElement(sb.toString()));
            sb.setLength(0);
        }
    }

    if (sb.length() > 0) {
        answer.addElement(new TextElement(sb.toString()));
    }

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