Java Code Examples for org.mybatis.generator.internal.ObjectFactory#createIntrospectedTable()

The following examples show how to use org.mybatis.generator.internal.ObjectFactory#createIntrospectedTable() . 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 4 votes vote down vote up
private List<IntrospectedTable> calculateIntrospectedTables(
        TableConfiguration tc,
        Map<ActualTableName, List<IntrospectedColumn>> columns) {
    boolean delimitIdentifiers = tc.isDelimitIdentifiers()
            || stringContainsSpace(tc.getCatalog())
            || stringContainsSpace(tc.getSchema())
            || stringContainsSpace(tc.getTableName());

    List<IntrospectedTable> answer = new ArrayList<>();

    for (Map.Entry<ActualTableName, List<IntrospectedColumn>> entry : columns
            .entrySet()) {
        ActualTableName atn = entry.getKey();

        // we only use the returned catalog and schema if something was
        // actually
        // specified on the table configuration. If something was returned
        // from the DB for these fields, but nothing was specified on the
        // table
        // configuration, then some sort of DB default is being returned
        // and we don't want that in our SQL
        FullyQualifiedTable table = new FullyQualifiedTable(
                stringHasValue(tc.getCatalog()) ? atn.getCatalog() : null,
                stringHasValue(tc.getSchema()) ? atn.getSchema() : null,
                atn.getTableName(),
                tc.getDomainObjectName(),
                tc.getAlias(),
                isTrue(tc.getProperty(PropertyRegistry.TABLE_IGNORE_QUALIFIERS_AT_RUNTIME)),
                tc.getProperty(PropertyRegistry.TABLE_RUNTIME_CATALOG),
                tc.getProperty(PropertyRegistry.TABLE_RUNTIME_SCHEMA),
                tc.getProperty(PropertyRegistry.TABLE_RUNTIME_TABLE_NAME),
                delimitIdentifiers,
                tc.getDomainObjectRenamingRule(),
                context);

        IntrospectedTable introspectedTable = ObjectFactory
                .createIntrospectedTable(tc, table, context);

        for (IntrospectedColumn introspectedColumn : entry.getValue()) {
            introspectedTable.addColumn(introspectedColumn);
        }

        calculatePrimaryKey(table, introspectedTable);

        enhanceIntrospectedTable(introspectedTable);

        answer.add(introspectedTable);
    }

    return answer;
}
 
Example 2
Source File: DatabaseIntrospector.java    From mybatis-generator-core-fix with Apache License 2.0 4 votes vote down vote up
/**
 * Calculate introspected tables.
 *
 * @param tc
 *            the tc
 * @param columns
 *            the columns
 * @return the list
 */
private List<IntrospectedTable> calculateIntrospectedTables(
        TableConfiguration tc,
        Map<ActualTableName, List<IntrospectedColumn>> columns) throws SQLException {
    boolean delimitIdentifiers = tc.isDelimitIdentifiers()
            || stringContainsSpace(tc.getCatalog())
            || stringContainsSpace(tc.getSchema())
            || stringContainsSpace(tc.getTableName());

    List<IntrospectedTable> answer = new ArrayList<IntrospectedTable>();

    for (Map.Entry<ActualTableName, List<IntrospectedColumn>> entry : columns
            .entrySet()) {
        ActualTableName atn = entry.getKey();

        // we only use the returned catalog and schema if something was
        // actually
        // specified on the table configuration. If something was returned
        // from the DB for these fields, but nothing was specified on the
        // table
        // configuration, then some sort of DB default is being returned
        // and we don't want that in our SQL
        FullyQualifiedTable table = new FullyQualifiedTable(
                stringHasValue(tc.getCatalog()) ? atn
                        .getCatalog() : null,
                stringHasValue(tc.getSchema()) ? atn
                        .getSchema() : null,
                atn.getTableName(),
                tc.getDomainObjectName(),
                tc.getAlias(),
                isTrue(tc.getProperty(PropertyRegistry.TABLE_IGNORE_QUALIFIERS_AT_RUNTIME)),
                tc.getProperty(PropertyRegistry.TABLE_RUNTIME_CATALOG),
                tc.getProperty(PropertyRegistry.TABLE_RUNTIME_SCHEMA),
                tc.getProperty(PropertyRegistry.TABLE_RUNTIME_TABLE_NAME),
                delimitIdentifiers, context);

        //设置数据库表的备注信息
        //start
        Statement stmt = this.databaseMetaData.getConnection().createStatement();
        ResultSet rs = stmt.executeQuery(new StringBuilder().append("SHOW TABLE STATUS LIKE '").append(atn.getTableName()).append("'").toString());
        while (rs.next())
            table.setRemark(rs.getString("COMMENT"));

        closeResultSet(rs);
        stmt.close();
        //end

        IntrospectedTable introspectedTable = ObjectFactory
                .createIntrospectedTable(tc, table, context);

        for (IntrospectedColumn introspectedColumn : entry.getValue()) {
            introspectedTable.addColumn(introspectedColumn);
        }

        calculatePrimaryKey(table, introspectedTable);
        
        enhanceIntrospectedTable(introspectedTable);

        answer.add(introspectedTable);
    }

    return answer;
}
 
Example 3
Source File: DatabaseIntrospector.java    From mybatis-generator-plus with Apache License 2.0 4 votes vote down vote up
private List<IntrospectedTable> calculateIntrospectedTables(
        TableConfiguration tc,
        Map<ActualTableName, List<IntrospectedColumn>> columns) {
    boolean delimitIdentifiers = tc.isDelimitIdentifiers()
            || stringContainsSpace(tc.getCatalog())
            || stringContainsSpace(tc.getSchema())
            || stringContainsSpace(tc.getTableName());

    List<IntrospectedTable> answer = new ArrayList<IntrospectedTable>();

    for (Map.Entry<ActualTableName, List<IntrospectedColumn>> entry : columns
            .entrySet()) {
        ActualTableName atn = entry.getKey();

        // we only use the returned catalog and schema if something was
        // actually
        // specified on the table configuration. If something was returned
        // from the DB for these fields, but nothing was specified on the
        // table
        // configuration, then some sort of DB default is being returned
        // and we don't want that in our SQL
        FullyQualifiedTable table = new FullyQualifiedTable(
                stringHasValue(tc.getCatalog()) ? atn
                        .getCatalog() : null,
                stringHasValue(tc.getSchema()) ? atn
                        .getSchema() : null,
                atn.getTableName(),
                tc.getDomainObjectName(),
                tc.getAlias(),
                isTrue(tc.getProperty(PropertyRegistry.TABLE_IGNORE_QUALIFIERS_AT_RUNTIME)),
                tc.getProperty(PropertyRegistry.TABLE_RUNTIME_CATALOG),
                tc.getProperty(PropertyRegistry.TABLE_RUNTIME_SCHEMA),
                tc.getProperty(PropertyRegistry.TABLE_RUNTIME_TABLE_NAME),
                delimitIdentifiers, context);

        IntrospectedTable introspectedTable = ObjectFactory
                .createIntrospectedTable(tc, table, context);

        for (IntrospectedColumn introspectedColumn : entry.getValue()) {
            introspectedTable.addColumn(introspectedColumn);
        }

        calculatePrimaryKey(table, introspectedTable);

        answer.add(introspectedTable);
    }

    return answer;
}