Search in sources :

Example 6 with JDBCResultSet

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

the class GenericStructureAssistant method findProceduresByMask.

private void findProceduresByMask(JDBCSession session, GenericCatalog catalog, GenericSchema schema, String procNameMask, int maxResults, List<DBSObjectReference> objects) throws SQLException, DBException {
    final GenericMetaObject procObject = getDataSource().getMetaObject(GenericConstants.OBJECT_PROCEDURE);
    DBRProgressMonitor monitor = session.getProgressMonitor();
    try (JDBCResultSet dbResult = session.getMetaData().getProcedures(catalog == null ? null : catalog.getName(), schema == null ? null : schema.getName(), procNameMask)) {
        while (dbResult.next()) {
            if (monitor.isCanceled()) {
                break;
            }
            String catalogName = GenericUtils.safeGetStringTrimmed(procObject, dbResult, JDBCConstants.PROCEDURE_CAT);
            String schemaName = GenericUtils.safeGetStringTrimmed(procObject, dbResult, JDBCConstants.PROCEDURE_SCHEM);
            String procName = GenericUtils.safeGetStringTrimmed(procObject, dbResult, JDBCConstants.PROCEDURE_NAME);
            String uniqueName = GenericUtils.safeGetStringTrimmed(procObject, dbResult, JDBCConstants.SPECIFIC_NAME);
            if (CommonUtils.isEmpty(procName)) {
                continue;
            }
            if (CommonUtils.isEmpty(uniqueName)) {
                uniqueName = procName;
            }
            objects.add(new ProcedureReference(findContainer(session.getProgressMonitor(), catalog, schema, catalogName, schemaName), catalogName, procName, uniqueName));
            if (objects.size() >= maxResults) {
                break;
            }
        }
    }
}
Also used : GenericMetaObject(org.jkiss.dbeaver.ext.generic.model.meta.GenericMetaObject) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Example 7 with JDBCResultSet

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

the class GenericStructureAssistant method findTablesByMask.

private void findTablesByMask(JDBCSession session, GenericCatalog catalog, GenericSchema schema, String tableNameMask, int maxResults, List<DBSObjectReference> objects) throws SQLException, DBException {
    final GenericMetaObject tableObject = getDataSource().getMetaObject(GenericConstants.OBJECT_TABLE);
    final DBRProgressMonitor monitor = session.getProgressMonitor();
    try (JDBCResultSet dbResult = session.getMetaData().getTables(catalog == null ? null : catalog.getName(), schema == null ? null : schema.getName(), tableNameMask, null)) {
        while (dbResult.next()) {
            if (monitor.isCanceled()) {
                break;
            }
            String catalogName = GenericUtils.safeGetStringTrimmed(tableObject, dbResult, JDBCConstants.TABLE_CAT);
            String schemaName = GenericUtils.safeGetStringTrimmed(tableObject, dbResult, JDBCConstants.TABLE_SCHEM);
            String tableName = GenericUtils.safeGetStringTrimmed(tableObject, dbResult, JDBCConstants.TABLE_NAME);
            if (CommonUtils.isEmpty(tableName)) {
                continue;
            }
            objects.add(new TableReference(findContainer(session.getProgressMonitor(), catalog, schema, catalogName, schemaName), tableName, GenericUtils.safeGetString(tableObject, dbResult, JDBCConstants.REMARKS)));
            if (objects.size() >= maxResults) {
                break;
            }
        }
    }
}
Also used : GenericMetaObject(org.jkiss.dbeaver.ext.generic.model.meta.GenericMetaObject) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Example 8 with JDBCResultSet

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

the class DerbyMetaModel method loadSequences.

@Override
public List<GenericSequence> loadSequences(@NotNull DBRProgressMonitor monitor, @NotNull GenericStructContainer container) throws DBException {
    try (JDBCSession session = DBUtils.openMetaSession(monitor, container.getDataSource(), "Read procedure definition")) {
        try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT seq.SEQUENCENAME,seq.CURRENTVALUE,seq.MINIMUMVALUE,seq.MAXIMUMVALUE,seq.INCREMENT\n" + "FROM sys.SYSSEQUENCES seq,sys.SYSSCHEMAS s\n" + "WHERE seq.SCHEMAID=s.SCHEMAID AND s.SCHEMANAME=?")) {
            dbStat.setString(1, container.getName());
            try (JDBCResultSet dbResult = dbStat.executeQuery()) {
                List<GenericSequence> result = new ArrayList<GenericSequence>();
                while (dbResult.next()) {
                    GenericSequence sequence = new GenericSequence(container, JDBCUtils.safeGetString(dbResult, 1), "", JDBCUtils.safeGetLong(dbResult, 2), JDBCUtils.safeGetLong(dbResult, 3), JDBCUtils.safeGetLong(dbResult, 4), JDBCUtils.safeGetLong(dbResult, 5));
                    result.add(sequence);
                }
                return result;
            }
        }
    } catch (SQLException e) {
        throw new DBException(e, container.getDataSource());
    }
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement) JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession) DBException(org.jkiss.dbeaver.DBException) SQLException(java.sql.SQLException) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) ArrayList(java.util.ArrayList)

Example 9 with JDBCResultSet

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

the class DB2PlanStatement method loadChildren.

// -------------
// Load children
// -------------
private void loadChildren(JDBCSession session) throws SQLException {
    mapDataObjects = new HashMap<>(32);
    try (JDBCPreparedStatement sqlStmt = session.prepareStatement(String.format(SEL_BASE_SELECT, planTableSchema, "EXPLAIN_OBJECT", "OBJECT_SCHEMA,OBJECT_NAME"))) {
        setQueryParameters(sqlStmt);
        try (JDBCResultSet res = sqlStmt.executeQuery()) {
            DB2PlanObject db2PlanObject;
            while (res.next()) {
                db2PlanObject = new DB2PlanObject(res);
                mapDataObjects.put(db2PlanObject.getNodeName(), db2PlanObject);
            }
        }
    }
    mapOperators = new HashMap<>(64);
    try (JDBCPreparedStatement sqlStmt = session.prepareStatement(String.format(SEL_BASE_SELECT, planTableSchema, "EXPLAIN_OPERATOR", "OPERATOR_ID"))) {
        setQueryParameters(sqlStmt);
        try (JDBCResultSet res = sqlStmt.executeQuery()) {
            DB2PlanOperator db2PlanOperator;
            while (res.next()) {
                db2PlanOperator = new DB2PlanOperator(session, res, this, planTableSchema);
                mapOperators.put(db2PlanOperator.getNodeName(), db2PlanOperator);
                if (db2PlanOperator.getOperatorType() == DB2PlanOperatorType.RETURN) {
                    rootNode = db2PlanOperator;
                }
            }
        }
    }
    listStreams = new ArrayList<>();
    try (JDBCPreparedStatement sqlStmt = session.prepareStatement(String.format(SEL_BASE_SELECT, planTableSchema, "EXPLAIN_STREAM", "STREAM_ID DESC"))) {
        setQueryParameters(sqlStmt);
        try (JDBCResultSet res = sqlStmt.executeQuery()) {
            while (res.next()) {
                listStreams.add(new DB2PlanStream(res, this));
            }
        }
    }
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)

Example 10 with JDBCResultSet

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

the class DB2PlanAnalyser method explain.

// ----------------
// Business Methods
// ----------------
public void explain(JDBCSession session) throws DBCException {
    Integer stmtNo = STMT_NO_GEN.incrementAndGet();
    String explainStmt = String.format(PT_EXPLAIN, stmtNo, query);
    LOG.debug("Schema=" + planTableSchema + " : " + explainStmt);
    try {
        // Start by cleaning old rows for safety
        cleanExplainTables(session, stmtNo, planTableSchema);
        // Explain
        try (JDBCPreparedStatement dbStat = session.prepareStatement(String.format(PT_EXPLAIN, stmtNo, query))) {
            dbStat.execute();
        }
        // Build Node Structure
        try (JDBCPreparedStatement dbStat = session.prepareStatement(String.format(SEL_STMT, planTableSchema))) {
            dbStat.setInt(1, stmtNo);
            try (JDBCResultSet dbResult = dbStat.executeQuery()) {
                dbResult.next();
                db2PlanStatement = new DB2PlanStatement(session, dbResult, planTableSchema);
            }
        }
        listNodes = db2PlanStatement.buildNodes();
        // Clean afterward
        cleanExplainTables(session, stmtNo, planTableSchema);
    } catch (SQLException e) {
        throw new DBCException(e, session.getDataSource());
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement) SQLException(java.sql.SQLException) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) DBCException(org.jkiss.dbeaver.model.exec.DBCException)

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