Search in sources :

Example 56 with JDBCResultSet

use of org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet in project dbeaver by serge-rider.

the class OracleView method loadAdditionalInfo.

private void loadAdditionalInfo(DBRProgressMonitor monitor) throws DBException {
    if (!isPersisted()) {
        additionalInfo.loaded = true;
        return;
    }
    String viewText = null;
    try (JDBCSession session = DBUtils.openMetaSession(monitor, getDataSource(), "Load table status")) {
        boolean isOracle9 = getDataSource().isAtLeastV9();
        try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT TEXT,TYPE_TEXT,OID_TEXT,VIEW_TYPE_OWNER,VIEW_TYPE" + (isOracle9 ? ",SUPERVIEW_NAME" : "") + "\n" + "FROM SYS.ALL_VIEWS WHERE OWNER=? AND VIEW_NAME=?")) {
            dbStat.setString(1, getContainer().getName());
            dbStat.setString(2, getName());
            try (JDBCResultSet dbResult = dbStat.executeQuery()) {
                if (dbResult.next()) {
                    viewText = JDBCUtils.safeGetString(dbResult, "TEXT");
                    additionalInfo.setText(viewText);
                    additionalInfo.setTypeText(JDBCUtils.safeGetStringTrimmed(dbResult, "TYPE_TEXT"));
                    additionalInfo.setOidText(JDBCUtils.safeGetStringTrimmed(dbResult, "OID_TEXT"));
                    additionalInfo.typeOwner = JDBCUtils.safeGetStringTrimmed(dbResult, "VIEW_TYPE_OWNER");
                    additionalInfo.typeName = JDBCUtils.safeGetStringTrimmed(dbResult, "VIEW_TYPE");
                    if (isOracle9) {
                        String superViewName = JDBCUtils.safeGetString(dbResult, "SUPERVIEW_NAME");
                        if (!CommonUtils.isEmpty(superViewName)) {
                            additionalInfo.setSuperView(getContainer().getView(monitor, superViewName));
                        }
                    }
                } else {
                    log.warn("Cannot find view '" + getFullyQualifiedName(DBPEvaluationContext.UI) + "' metadata");
                }
                additionalInfo.loaded = true;
            }
        }
    } catch (SQLException e) {
        throw new DBCException(e, getDataSource());
    }
    if (viewText != null) {
        viewText = "CREATE OR REPLACE VIEW " + getFullyQualifiedName(DBPEvaluationContext.DDL) + " AS\n" + viewText;
    }
    additionalInfo.setText(viewText);
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement) JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession) SQLException(java.sql.SQLException) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) DBCException(org.jkiss.dbeaver.model.exec.DBCException)

Example 57 with JDBCResultSet

use of org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet in project dbeaver by serge-rider.

the class DB2Utils method readApplications.

// ---------------------
// DBA Data and Actions
// ---------------------
public static List<DB2ServerApplication> readApplications(DBRProgressMonitor monitor, JDBCSession session) throws SQLException {
    LOG.debug("readApplications");
    List<DB2ServerApplication> listApplications = new ArrayList<>();
    try (JDBCPreparedStatement dbStat = session.prepareStatement(SEL_APP)) {
        try (JDBCResultSet dbResult = dbStat.executeQuery()) {
            while (dbResult.next()) {
                listApplications.add(new DB2ServerApplication(dbResult));
            }
        }
    }
    return listApplications;
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) ArrayList(java.util.ArrayList) DB2ServerApplication(org.jkiss.dbeaver.ext.db2.model.app.DB2ServerApplication)

Example 58 with JDBCResultSet

use of org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet in project dbeaver by serge-rider.

the class DB2Utils method readDBCfg.

public static List<DB2Parameter> readDBCfg(DBRProgressMonitor monitor, JDBCSession session) throws SQLException {
    LOG.debug("readDBCfg");
    List<DB2Parameter> listDBParameters = new ArrayList<>();
    try (JDBCPreparedStatement dbStat = session.prepareStatement(SEL_DBCFG)) {
        try (JDBCResultSet dbResult = dbStat.executeQuery()) {
            while (dbResult.next()) {
                listDBParameters.add(new DB2Parameter((DB2DataSource) session.getDataSource(), dbResult));
            }
        }
    }
    return listDBParameters;
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) DB2DataSource(org.jkiss.dbeaver.ext.db2.model.DB2DataSource) ArrayList(java.util.ArrayList) DB2Parameter(org.jkiss.dbeaver.ext.db2.info.DB2Parameter)

Example 59 with JDBCResultSet

use of org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet 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)

Example 60 with JDBCResultSet

use of org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet 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

JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)82 JDBCPreparedStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)66 SQLException (java.sql.SQLException)57 JDBCSession (org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)54 DBException (org.jkiss.dbeaver.DBException)53 ArrayList (java.util.ArrayList)20 DBCException (org.jkiss.dbeaver.model.exec.DBCException)15 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)12 JDBCStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement)10 AbstractObjectReference (org.jkiss.dbeaver.model.impl.struct.AbstractObjectReference)10 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)8 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)5 GenericMetaObject (org.jkiss.dbeaver.ext.generic.model.meta.GenericMetaObject)4 NotNull (org.jkiss.code.NotNull)3 DB2XMLString (org.jkiss.dbeaver.ext.db2.info.DB2XMLString)3 DB2DataSource (org.jkiss.dbeaver.ext.db2.model.DB2DataSource)3 GenericDataSource (org.jkiss.dbeaver.ext.generic.model.GenericDataSource)3 Matcher (java.util.regex.Matcher)2 DB2Parameter (org.jkiss.dbeaver.ext.db2.info.DB2Parameter)2 DB2Schema (org.jkiss.dbeaver.ext.db2.model.DB2Schema)2