Search in sources :

Example 1 with JavaTypeResolver

use of org.mybatis.generator.api.JavaTypeResolver 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)

Example 2 with JavaTypeResolver

use of org.mybatis.generator.api.JavaTypeResolver in project generator by mybatis.

the class ObjectFactory method createJavaTypeResolver.

/**
     * Creates a new Object object.
     *
     * @param context
     *            the context
     * @param warnings
     *            the warnings
     * @return the java type resolver
     */
public static JavaTypeResolver createJavaTypeResolver(Context context, List<String> warnings) {
    JavaTypeResolverConfiguration config = context.getJavaTypeResolverConfiguration();
    String type;
    if (config != null && config.getConfigurationType() != null) {
        type = config.getConfigurationType();
        if ("DEFAULT".equalsIgnoreCase(type)) {
            //$NON-NLS-1$
            type = JavaTypeResolverDefaultImpl.class.getName();
        }
    } else {
        type = JavaTypeResolverDefaultImpl.class.getName();
    }
    JavaTypeResolver answer = (JavaTypeResolver) createInternalObject(type);
    answer.setWarnings(warnings);
    if (config != null) {
        answer.addConfigurationProperties(config.getProperties());
    }
    answer.setContext(context);
    return answer;
}
Also used : JavaTypeResolver(org.mybatis.generator.api.JavaTypeResolver) JavaTypeResolverConfiguration(org.mybatis.generator.config.JavaTypeResolverConfiguration) Messages.getString(org.mybatis.generator.internal.util.messages.Messages.getString) JavaTypeResolverDefaultImpl(org.mybatis.generator.internal.types.JavaTypeResolverDefaultImpl)

Aggregations

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