Java Code Examples for org.mybatis.generator.config.GeneratedKey#isJdbcStandard()

The following examples show how to use org.mybatis.generator.config.GeneratedKey#isJdbcStandard() . 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: DatabaseIntrospector.java    From mapper-generator-javafx with Apache License 2.0 6 votes vote down vote up
private void calculateIdentityColumns(TableConfiguration tc,
        Map<ActualTableName, List<IntrospectedColumn>> columns) {
    GeneratedKey gk = tc.getGeneratedKey();
    if (gk == null) {
        // no generated key, then no identity or sequence columns
        return;
    }

    for (Map.Entry<ActualTableName, List<IntrospectedColumn>> entry : columns
            .entrySet()) {
        for (IntrospectedColumn introspectedColumn : entry.getValue()) {
            if (isMatchedColumn(introspectedColumn, gk)) {
                if (gk.isIdentity() || gk.isJdbcStandard()) {
                    introspectedColumn.setIdentity(true);
                    introspectedColumn.setSequenceColumn(false);
                } else {
                    introspectedColumn.setIdentity(false);
                    introspectedColumn.setSequenceColumn(true);
                }
            }
        }
    }
}
 
Example 2
Source File: DatabaseIntrospector.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
private void calculateIdentityColumns(TableConfiguration tc,
        Map<ActualTableName, List<IntrospectedColumn>> columns) {
    GeneratedKey gk = tc.getGeneratedKey();
    if (gk == null) {
        // no generated key, then no identity or sequence columns
        return;
    }
    
    for (Map.Entry<ActualTableName, List<IntrospectedColumn>> entry : columns
            .entrySet()) {
        for (IntrospectedColumn introspectedColumn : entry.getValue()) {
            if (isMatchedColumn(introspectedColumn, gk)) {
                if (gk.isIdentity() || gk.isJdbcStandard()) {
                    introspectedColumn.setIdentity(true);
                    introspectedColumn.setSequenceColumn(false);
                } else {
                    introspectedColumn.setIdentity(false);
                    introspectedColumn.setSequenceColumn(true);
                }
            }
        }
    }
}
 
Example 3
Source File: SelectiveEnhancedPlugin.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * insertSelective
 * 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
 * @param element
 * @param introspectedTable
 * @return
 */
@Override
public boolean sqlMapInsertSelectiveElementGenerated(XmlElement element, IntrospectedTable introspectedTable) {
    // 清空
    XmlElement answer = new XmlElement("insert");
    answer.addAttribute(new Attribute("id", introspectedTable.getInsertSelectiveStatementId()));
    answer.addAttribute(new Attribute("parameterType", "map"));

    commentGenerator.addComment(answer);

    GeneratedKey gk = introspectedTable.getGeneratedKey();
    if (gk != null) {
        IntrospectedColumn introspectedColumn = introspectedTable.getColumn(gk.getColumn());
        // if the column is null, then it's a configuration error. The
        // warning has already been reported
        if (introspectedColumn != null) {
            if (gk.isJdbcStandard()) {
                XmlElementGeneratorTools.useGeneratedKeys(answer, introspectedTable, "record.");
            } else {
                answer.addElement(XmlElementGeneratorTools.getSelectKey(introspectedColumn, gk, "record."));
            }
        }
    }

    StringBuilder sb = new StringBuilder();

    sb.append("insert into ");
    sb.append(introspectedTable.getFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));

    // columns
    answer.addElement(this.generateInsertColumnSelective(ListUtilities.removeIdentityAndGeneratedAlwaysColumns(introspectedTable.getAllColumns())));
    // values
    answer.addElement(new TextElement("values"));
    answer.addElement(this.generateInsertValuesSelective(ListUtilities.removeIdentityAndGeneratedAlwaysColumns(introspectedTable.getAllColumns())));

    XmlElementTools.replaceXmlElement(element, answer);

    return super.sqlMapInsertSelectiveElementGenerated(element, introspectedTable);
}
 
Example 4
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 5
Source File: AbstractJavaMapperMethodGenerator.java    From mybatis-generator-plus 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());
        }
    }
}