Example usage for java.sql DatabaseMetaData getTableTypes

List of usage examples for java.sql DatabaseMetaData getTableTypes

Introduction

In this page you can find the example usage for java.sql DatabaseMetaData getTableTypes.

Prototype

ResultSet getTableTypes() throws SQLException;

Source Link

Document

Retrieves the table types available in this database.

Usage

From source file:org.jumpmind.db.platform.AbstractJdbcDdlReader.java

public List<String> getTableTypes() {
    JdbcSqlTemplate sqlTemplate = (JdbcSqlTemplate) platform.getSqlTemplate();
    return sqlTemplate.execute(new IConnectionCallback<List<String>>() {
        public List<String> execute(Connection connection) throws SQLException {
            ArrayList<String> types = new ArrayList<String>();
            DatabaseMetaData meta = connection.getMetaData();
            ResultSet rs = null;//from   www .j  a  va  2 s  .c o m
            try {
                rs = meta.getTableTypes();
                while (rs.next()) {
                    types.add(rs.getString(1));
                }
                return types;
            } finally {
                JdbcSqlTemplate.close(rs);
            }
        }
    });
}

From source file:org.talend.core.model.metadata.builder.database.manager.dbs.ImpalaExtractManager.java

protected ResultSet getResultSetFromTableInfo(TableInfoParameters tableInfo, String namePattern,
        IMetadataConnection iMetadataConnection, String schema)
        throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
    String tableNamePattern = "".equals(namePattern) ? null : namePattern; //$NON-NLS-1$
    String[] types = new String[tableInfo.getTypes().size()];
    for (int i = 0; i < types.length; i++) {
        final String selectedTypeName = tableInfo.getTypes().get(i).getName();
        types[i] = selectedTypeName;/*  w w w . j av  a 2  s .co m*/
    }
    DatabaseMetaData dbMetaData = ImpalaConnectionManager.getInstance().createConnection(iMetadataConnection)
            .getMetaData();

    // rsTables = dbMetaData.getTables(null, ExtractMetaDataUtils.schema, tableNamePattern, types);
    ResultSet rsTableTypes = null;
    rsTableTypes = dbMetaData.getTableTypes();
    Set<String> availableTableTypes = new HashSet<String>();
    String[] neededTableTypes = { ETableTypes.TABLETYPE_TABLE.getName(), ETableTypes.TABLETYPE_VIEW.getName(),
            ETableTypes.TABLETYPE_SYNONYM.getName() };
    while (rsTableTypes.next()) {
        String currentTableType = StringUtils.trimToEmpty(rsTableTypes.getString(ExtractManager.TABLE_TYPE));
        if (ArrayUtils.contains(neededTableTypes, currentTableType)) {
            availableTableTypes.add(currentTableType);
        }
    }
    rsTableTypes.close();
    ResultSet rsTables = dbMetaData.getTables(null, schema, tableNamePattern, types);
    return rsTables;

}

From source file:org.talend.core.model.metadata.builder.database.manager.ExtractManager.java

/**
 * DOC ggu Comment method "getAvailableTableTypes".
 * //from   ww w  .j av  a 2  s. c o  m
 * 
 * make it's public,just for junit
 * 
 * @param dbMetaData
 * @return
 * @throws SQLException
 */
public Set<String> getAvailableTableTypes(DatabaseMetaData dbMetaData) throws SQLException {
    ResultSet rsTableTypes = dbMetaData.getTableTypes();
    Set<String> availableTableTypes = new HashSet<String>();
    String[] neededTableTypes = { ETableTypes.TABLETYPE_TABLE.getName(), ETableTypes.TABLETYPE_VIEW.getName(),
            ETableTypes.TABLETYPE_SYNONYM.getName() };

    try {
        while (rsTableTypes.next()) {
            // StringUtils.trimToEmpty(name) is because bug 4547
            String currentTableType = StringUtils
                    .trimToEmpty(rsTableTypes.getString(ExtractManager.TABLE_TYPE));
            // Because BASE TABLE which UniJDBCClientResultSet gets is not the support type of
            // UniJDBCDatabaseMetaData, do this so as to dispose bug 17281.
            if ("BASE TABLE".equalsIgnoreCase(currentTableType)) { //$NON-NLS-1$
                currentTableType = ETableTypes.TABLETYPE_TABLE.getName();
            }
            if (ArrayUtils.contains(neededTableTypes, currentTableType)) {
                availableTableTypes.add(currentTableType);
            }
        }
    } finally {
        rsTableTypes.close();// See bug 5029 Avoid "Invalid cursor exception"
    }
    return availableTableTypes;
}

From source file:org.talend.core.model.metadata.builder.database.manager.ExtractManager.java

/**
 * DOC qzhang Comment method "getResultSetFromTableInfo".
 * /*from ww w . ja v  a2  s .c o m*/
 * @param dbMetaData
 * @return
 * @throws SQLException
 * @throws IllegalAccessException
 * @throws InstantiationException
 * @throws ClassNotFoundException
 */
protected ResultSet getResultSetFromTableInfo(TableInfoParameters tableInfo, String namePattern,
        IMetadataConnection iMetadataConnection, String schema)
        throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
    ResultSet rsTables = null;
    ExtractMetaDataUtils extractMeta = ExtractMetaDataUtils.getInstance();
    String tableNamePattern = "".equals(namePattern) ? null : namePattern; //$NON-NLS-1$
    String[] types = new String[tableInfo.getTypes().size()];
    for (int i = 0; i < types.length; i++) {
        final String selectedTypeName = tableInfo.getTypes().get(i).getName();
        // bug 0017782 ,db2's SYNONYM need to convert to ALIAS;
        if ("SYNONYM".equals(selectedTypeName)
                && iMetadataConnection.getDbType().equals(EDatabaseTypeName.IBMDB2.getDisplayName())) {
            types[i] = "ALIAS";
        } else {
            types[i] = selectedTypeName;
        }
    }

    DatabaseMetaData dbMetaData = null;
    // Added by Marvin Wang on Mar. 13, 2013 for loading hive jars dynamically, refer to TDI-25072.
    if (EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(iMetadataConnection.getDbType())) {
        dbMetaData = HiveConnectionManager.getInstance().extractDatabaseMetaData(iMetadataConnection);
    } else {
        dbMetaData = extractMeta.getDatabaseMetaData(extractMeta.getConn(), iMetadataConnection.getDbType(),
                iMetadataConnection.isSqlMode(), iMetadataConnection.getDatabase());
    }
    // rsTables = dbMetaData.getTables(null, ExtractMetaDataUtils.schema, tableNamePattern, types);
    ResultSet rsTableTypes = null;
    rsTableTypes = dbMetaData.getTableTypes();
    Set<String> availableTableTypes = new HashSet<String>();
    String[] neededTableTypes = { ETableTypes.TABLETYPE_TABLE.getName(), ETableTypes.TABLETYPE_VIEW.getName(),
            ETableTypes.TABLETYPE_SYNONYM.getName() };
    while (rsTableTypes.next()) {
        String currentTableType = StringUtils.trimToEmpty(rsTableTypes.getString(ExtractManager.TABLE_TYPE));
        if (ArrayUtils.contains(neededTableTypes, currentTableType)) {
            availableTableTypes.add(currentTableType);
        }
    }
    rsTableTypes.close();
    rsTables = dbMetaData.getTables(null, schema, tableNamePattern, types);
    return rsTables;
}