use of org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement 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;
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement 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));
}
}
}
}
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement 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));
}
}
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement in project dbeaver by serge-rider.
the class SQLiteMetaModel method loadSequences.
@Override
public List<GenericSequence> loadSequences(@NotNull DBRProgressMonitor monitor, @NotNull GenericStructContainer container) throws DBException {
try (JDBCSession session = DBUtils.openMetaSession(monitor, container.getDataSource(), "Read sequences")) {
try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT * FROM sqlite_sequence")) {
List<GenericSequence> result = new ArrayList<>();
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
while (dbResult.next()) {
String name = JDBCUtils.safeGetString(dbResult, 1);
long value = JDBCUtils.safeGetLong(dbResult, 2);
result.add(new GenericSequence(container, name, null, value, 0, Long.MAX_VALUE, 1));
}
}
return result;
}
} catch (SQLException e) {
throw new DBException(e, container.getDataSource());
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement in project dbeaver by serge-rider.
the class PostgreMetaModel 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 sequence_name FROM information_schema.sequences WHERE sequence_schema=?")) {
dbStat.setString(1, container.getName());
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
List<GenericSequence> result = new ArrayList<>();
while (dbResult.next()) {
String name = JDBCUtils.safeGetString(dbResult, 1);
try (JDBCPreparedStatement dbSeqStat = session.prepareStatement("SELECT last_value,min_value,max_value,increment_by from " + container.getName() + "." + name)) {
try (JDBCResultSet seqResults = dbSeqStat.executeQuery()) {
seqResults.next();
GenericSequence sequence = new GenericSequence(container, name, PostgreUtils.getObjectComment(monitor, container.getDataSource(), container.getName(), name), JDBCUtils.safeGetLong(seqResults, 1), JDBCUtils.safeGetLong(seqResults, 2), JDBCUtils.safeGetLong(seqResults, 3), JDBCUtils.safeGetLong(seqResults, 4));
result.add(sequence);
}
}
}
return result;
}
}
} catch (SQLException e) {
throw new DBException(e, container.getDataSource());
}
}
Aggregations