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;
}
}
}
}
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;
}
}
}
}
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());
}
}
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));
}
}
}
}
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());
}
}
Aggregations