Search in sources :

Example 1 with DatabaseIntrospector

use of org.mybatis.generator.internal.db.DatabaseIntrospector in project generator by mybatis.

the class Context method introspectTables.

/**
     * Introspect tables based on the configuration specified in the
     * constructor. This method is long running.
     * 
     * @param callback
     *            a progress callback if progress information is desired, or
     *            <code>null</code>
     * @param warnings
     *            any warning generated from this method will be added to the
     *            List. Warnings are always Strings.
     * @param fullyQualifiedTableNames
     *            a set of table names to generate. The elements of the set must
     *            be Strings that exactly match what's specified in the
     *            configuration. For example, if table name = "foo" and schema =
     *            "bar", then the fully qualified table name is "foo.bar". If
     *            the Set is null or empty, then all tables in the configuration
     *            will be used for code generation.
     * 
     * @throws SQLException
     *             if some error arises while introspecting the specified
     *             database tables.
     * @throws InterruptedException
     *             if the progress callback reports a cancel
     */
public void introspectTables(ProgressCallback callback, List<String> warnings, Set<String> fullyQualifiedTableNames) throws SQLException, InterruptedException {
    introspectedTables = new ArrayList<IntrospectedTable>();
    JavaTypeResolver javaTypeResolver = ObjectFactory.createJavaTypeResolver(this, warnings);
    Connection connection = null;
    try {
        //$NON-NLS-1$
        callback.startTask(getString("Progress.0"));
        connection = getConnection();
        DatabaseIntrospector databaseIntrospector = new DatabaseIntrospector(this, connection.getMetaData(), javaTypeResolver, warnings);
        for (TableConfiguration tc : tableConfigurations) {
            String tableName = composeFullyQualifiedTableName(tc.getCatalog(), tc.getSchema(), tc.getTableName(), '.');
            if (fullyQualifiedTableNames != null && fullyQualifiedTableNames.size() > 0 && !fullyQualifiedTableNames.contains(tableName)) {
                continue;
            }
            if (!tc.areAnyStatementsEnabled()) {
                //$NON-NLS-1$
                warnings.add(getString("Warning.0", tableName));
                continue;
            }
            //$NON-NLS-1$
            callback.startTask(getString("Progress.1", tableName));
            List<IntrospectedTable> tables = databaseIntrospector.introspectTables(tc);
            if (tables != null) {
                introspectedTables.addAll(tables);
            }
            callback.checkCancel();
        }
    } finally {
        closeConnection(connection);
    }
}
Also used : JavaTypeResolver(org.mybatis.generator.api.JavaTypeResolver) DatabaseIntrospector(org.mybatis.generator.internal.db.DatabaseIntrospector) Connection(java.sql.Connection) IntrospectedTable(org.mybatis.generator.api.IntrospectedTable) Messages.getString(org.mybatis.generator.internal.util.messages.Messages.getString)

Aggregations

Connection (java.sql.Connection)1 IntrospectedTable (org.mybatis.generator.api.IntrospectedTable)1 JavaTypeResolver (org.mybatis.generator.api.JavaTypeResolver)1 DatabaseIntrospector (org.mybatis.generator.internal.db.DatabaseIntrospector)1 Messages.getString (org.mybatis.generator.internal.util.messages.Messages.getString)1