Java Code Examples for org.mybatis.generator.api.IntrospectedTable#getColumn()

The following examples show how to use org.mybatis.generator.api.IntrospectedTable#getColumn() . 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: IntrospectedTableTools.java    From mybatis-generator-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * 安全获取column 通过正则获取的name可能包含beginningDelimiter&&endingDelimiter
 * @param introspectedTable
 * @param columnName
 * @return
 */
public static IntrospectedColumn safeGetColumn(IntrospectedTable introspectedTable, String columnName) {
    // columnName
    columnName = columnName.trim();
    // 过滤
    String beginningDelimiter = introspectedTable.getContext().getBeginningDelimiter();
    if (StringUtility.stringHasValue(beginningDelimiter)) {
        columnName = columnName.replaceFirst("^" + beginningDelimiter, "");
    }
    String endingDelimiter = introspectedTable.getContext().getEndingDelimiter();
    if (StringUtility.stringHasValue(endingDelimiter)) {
        columnName = columnName.replaceFirst(endingDelimiter + "$", "");
    }

    return introspectedTable.getColumn(columnName);
}
 
Example 2
Source File: OptimisticLockerPlugin.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void initialized(IntrospectedTable introspectedTable) {
    super.initialized(introspectedTable);
    sqlMaps.put(introspectedTable, new ArrayList<>());

    // 读取并验证版本列
    String versionColumn = introspectedTable.getTableConfigurationProperty(PRO_VERSION_COLUMN);
    if (versionColumn != null) {
        this.versionColumn = introspectedTable.getColumn(versionColumn);
        if (this.versionColumn == null) {
            warnings.add("itfsw(乐观锁插件):表" + introspectedTable.getFullyQualifiedTable() + "配置的版本列(" + introspectedTable.getTableConfigurationProperty(PRO_VERSION_COLUMN) + ")没有找到!");
        }
    } else {
        this.versionColumn = null;
    }

    // 自定义nextVersion
    // 首先获取全局配置
    Properties properties = getProperties();
    String customizedNextVersion = properties.getProperty(PRO_CUSTOMIZED_NEXT_VERSION);
    // 获取表单独配置,如果有则覆盖全局配置
    if (introspectedTable.getTableConfigurationProperty(PRO_CUSTOMIZED_NEXT_VERSION) != null) {
        customizedNextVersion = introspectedTable.getTableConfigurationProperty(PRO_CUSTOMIZED_NEXT_VERSION);
    }
    if (StringUtility.stringHasValue(customizedNextVersion) && StringUtility.isTrue(customizedNextVersion)) {
        this.customizedNextVersion = true;
    } else {
        this.customizedNextVersion = false;
    }

    super.initialized(introspectedTable);
}
 
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: DatabaseIntrospector.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
/**
 * Report introspection warnings.
 *
 * @param introspectedTable
 *            the introspected table
 * @param tableConfiguration
 *            the table configuration
 * @param table
 *            the table
 */
private void reportIntrospectionWarnings(
        IntrospectedTable introspectedTable,
        TableConfiguration tableConfiguration, FullyQualifiedTable table) {
    // make sure that every column listed in column overrides
    // actually exists in the table
    for (ColumnOverride columnOverride : tableConfiguration
            .getColumnOverrides()) {
        if (introspectedTable.getColumn(columnOverride.getColumnName()) == null) {
            warnings.add(getString("Warning.3", //$NON-NLS-1$
                    columnOverride.getColumnName(), table.toString()));
        }
    }

    // make sure that every column listed in ignored columns
    // actually exists in the table
    for (String string : tableConfiguration.getIgnoredColumnsInError()) {
        warnings.add(getString("Warning.4", //$NON-NLS-1$
                string, table.toString()));
    }

    GeneratedKey generatedKey = tableConfiguration.getGeneratedKey();
    if (generatedKey != null
            && introspectedTable.getColumn(generatedKey.getColumn()) == null) {
        if (generatedKey.isIdentity()) {
            warnings.add(getString("Warning.5", //$NON-NLS-1$
                    generatedKey.getColumn(), table.toString()));
        } else {
            warnings.add(getString("Warning.6", //$NON-NLS-1$
                    generatedKey.getColumn(), table.toString()));
        }
    }
    
    for (IntrospectedColumn ic : introspectedTable.getAllColumns()) {
        if (JavaReservedWords.containsWord(ic.getJavaProperty())) {
            warnings.add(getString("Warning.26", //$NON-NLS-1$
                    ic.getActualColumnName(), table.toString()));
        }
    }
}
 
Example 5
Source File: DatabaseIntrospector.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
private void reportIntrospectionWarnings(
        IntrospectedTable introspectedTable,
        TableConfiguration tableConfiguration, FullyQualifiedTable table) {
    // make sure that every column listed in column overrides
    // actually exists in the table
    for (ColumnOverride columnOverride : tableConfiguration
            .getColumnOverrides()) {
        if (introspectedTable.getColumn(columnOverride.getColumnName()) == null) {
            warnings.add(getString("Warning.3", //$NON-NLS-1$
                    columnOverride.getColumnName(), table.toString()));
        }
    }

    // make sure that every column listed in ignored columns
    // actually exists in the table
    for (String string : tableConfiguration.getIgnoredColumnsInError()) {
        warnings.add(getString("Warning.4", //$NON-NLS-1$
                string, table.toString()));
    }

    GeneratedKey generatedKey = tableConfiguration.getGeneratedKey();
    if (generatedKey != null
            && introspectedTable.getColumn(generatedKey.getColumn()) == null) {
        if (generatedKey.isIdentity()) {
            warnings.add(getString("Warning.5", //$NON-NLS-1$
                    generatedKey.getColumn(), table.toString()));
        } else {
            warnings.add(getString("Warning.6", //$NON-NLS-1$
                    generatedKey.getColumn(), table.toString()));
        }
    }
}