Search in sources :

Example 1 with DB2TableType

use of org.jkiss.dbeaver.ext.db2.model.dict.DB2TableType in project dbeaver by serge-rider.

the class DB2StructureAssistant method searchTables.

// --------------
// Helper Classes
// --------------
private void searchTables(JDBCSession session, DB2Schema schema, String searchObjectNameMask, List<DB2ObjectType> db2ObjectTypes, int maxResults, List<DBSObjectReference> objects, int nbResults) throws SQLException, DBException {
    String baseSQL;
    if (schema != null) {
        baseSQL = "SELECT TABSCHEMA,TABNAME,TYPE FROM SYSCAT.TABLES\n" + "WHERE TABSCHEMA =? AND TABNAME LIKE ? AND TYPE IN (%s)\n" + "WITH UR";
    } else {
        baseSQL = "SELECT TABSCHEMA,TABNAME,TYPE FROM SYSCAT.TABLES\n" + "WHERE TABNAME LIKE ? AND TYPE IN (%s)\n" + "WITH UR";
    }
    String sql = buildTableSQL(baseSQL, db2ObjectTypes);
    int n = 1;
    try (JDBCPreparedStatement dbStat = session.prepareStatement(sql)) {
        if (schema != null) {
            dbStat.setString(n++, schema.getName());
        //dbStat.setString(n++, DB2Constants.SYSTEM_CATALOG_SCHEMA);
        }
        dbStat.setString(n++, searchObjectNameMask);
        dbStat.setFetchSize(DBConstants.METADATA_FETCH_SIZE);
        String schemaName;
        String objectName;
        DB2Schema db2Schema;
        DB2TableType tableType;
        DB2ObjectType objectType;
        try (JDBCResultSet dbResult = dbStat.executeQuery()) {
            while (dbResult.next()) {
                if (session.getProgressMonitor().isCanceled()) {
                    break;
                }
                if (nbResults++ >= maxResults) {
                    break;
                }
                schemaName = JDBCUtils.safeGetStringTrimmed(dbResult, "TABSCHEMA");
                objectName = JDBCUtils.safeGetString(dbResult, "TABNAME");
                tableType = CommonUtils.valueOf(DB2TableType.class, JDBCUtils.safeGetString(dbResult, "TYPE"));
                db2Schema = dataSource.getSchema(session.getProgressMonitor(), schemaName);
                if (db2Schema == null) {
                    LOG.debug("Schema '" + schemaName + "' not found. Probably was filtered");
                    continue;
                }
                objectType = tableType.getDb2ObjectType();
                objects.add(new DB2ObjectReference(objectName, db2Schema, objectType));
            }
        }
    }
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) DB2Schema(org.jkiss.dbeaver.ext.db2.model.DB2Schema) DB2TableType(org.jkiss.dbeaver.ext.db2.model.dict.DB2TableType)

Aggregations

DB2Schema (org.jkiss.dbeaver.ext.db2.model.DB2Schema)1 DB2TableType (org.jkiss.dbeaver.ext.db2.model.dict.DB2TableType)1 JDBCPreparedStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)1 JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)1