Search in sources :

Example 11 with DB2Table

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

the class DB2StructureAssistant method searchColumns.

private void searchColumns(JDBCSession session, DB2Schema schema, String searchObjectNameMask, List<DB2ObjectType> objectTypes, int maxResults, List<DBSObjectReference> objects, int nbResults) throws SQLException, DBException {
    String sql;
    if (schema != null) {
        sql = SQL_COLS_SCHEMA;
    } else {
        sql = SQL_COLS_ALL;
    }
    int n = 1;
    try (JDBCPreparedStatement dbStat = session.prepareStatement(sql)) {
        if (schema != null) {
            dbStat.setString(n++, schema.getName());
        }
        dbStat.setString(n++, searchObjectNameMask);
        dbStat.setFetchSize(DBConstants.METADATA_FETCH_SIZE);
        String tableSchemaName;
        String tableOrViewName;
        String columnName;
        DB2Schema db2Schema;
        DB2Table db2Table;
        DB2View db2View;
        try (JDBCResultSet dbResult = dbStat.executeQuery()) {
            while (dbResult.next()) {
                if (session.getProgressMonitor().isCanceled()) {
                    break;
                }
                if (nbResults++ >= maxResults) {
                    return;
                }
                tableSchemaName = JDBCUtils.safeGetStringTrimmed(dbResult, "TABSCHEMA");
                tableOrViewName = JDBCUtils.safeGetString(dbResult, "TABNAME");
                columnName = JDBCUtils.safeGetString(dbResult, "COLNAME");
                db2Schema = dataSource.getSchema(session.getProgressMonitor(), tableSchemaName);
                if (db2Schema == null) {
                    LOG.debug("Schema '" + tableSchemaName + "' not found. Probably was filtered");
                    continue;
                }
                // Try with table, then view
                db2Table = db2Schema.getTable(session.getProgressMonitor(), tableOrViewName);
                if (db2Table != null) {
                    objects.add(new DB2ObjectReference(columnName, db2Table, DB2ObjectType.COLUMN));
                } else {
                    db2View = db2Schema.getView(session.getProgressMonitor(), tableOrViewName);
                    if (db2View != null) {
                        objects.add(new DB2ObjectReference(columnName, db2View, DB2ObjectType.COLUMN));
                    }
                }
            }
        }
    }
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement) DB2Table(org.jkiss.dbeaver.ext.db2.model.DB2Table) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) DB2View(org.jkiss.dbeaver.ext.db2.model.DB2View) DB2Schema(org.jkiss.dbeaver.ext.db2.model.DB2Schema)

Aggregations

Nullable (org.jkiss.code.Nullable)5 DB2Table (org.jkiss.dbeaver.ext.db2.model.DB2Table)4 DB2TableColumn (org.jkiss.dbeaver.ext.db2.model.DB2TableColumn)4 DB2Schema (org.jkiss.dbeaver.ext.db2.model.DB2Schema)3 DB2TableKeyColumn (org.jkiss.dbeaver.ext.db2.model.DB2TableKeyColumn)3 SQLException (java.sql.SQLException)2 JDBCPreparedStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)2 JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)2 Clob (java.sql.Clob)1 ArrayList (java.util.ArrayList)1 Font (org.eclipse.swt.graphics.Font)1 Tree (org.eclipse.swt.widgets.Tree)1 TreeColumn (org.eclipse.swt.widgets.TreeColumn)1 TreeItem (org.eclipse.swt.widgets.TreeItem)1 NotNull (org.jkiss.code.NotNull)1 DBException (org.jkiss.dbeaver.DBException)1 DB2XMLString (org.jkiss.dbeaver.ext.db2.info.DB2XMLString)1 DB2Index (org.jkiss.dbeaver.ext.db2.model.DB2Index)1 DB2TableBase (org.jkiss.dbeaver.ext.db2.model.DB2TableBase)1 DB2TableCheckConstraintColumn (org.jkiss.dbeaver.ext.db2.model.DB2TableCheckConstraintColumn)1