use of org.jkiss.dbeaver.model.exec.jdbc.JDBCSession in project dbeaver by serge-rider.
the class PostgreSequence method loadAdditionalInfo.
private void loadAdditionalInfo(DBRProgressMonitor monitor) {
try (JDBCSession session = DBUtils.openMetaSession(monitor, getDataSource(), "Load sequence additional info")) {
try (JDBCPreparedStatement dbSeqStat = session.prepareStatement("SELECT last_value,min_value,max_value,increment_by from " + getFullyQualifiedName(DBPEvaluationContext.DML))) {
try (JDBCResultSet seqResults = dbSeqStat.executeQuery()) {
if (seqResults.next()) {
additionalInfo.lastValue = JDBCUtils.safeGetLong(seqResults, 1);
additionalInfo.minValue = JDBCUtils.safeGetLong(seqResults, 2);
additionalInfo.maxValue = JDBCUtils.safeGetLong(seqResults, 3);
additionalInfo.incrementBy = JDBCUtils.safeGetLong(seqResults, 4);
}
}
}
additionalInfo.loaded = true;
} catch (Exception e) {
log.warn("Error reading sequence values", e);
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCSession in project dbeaver by serge-rider.
the class PostgreTable method getSubInheritance.
@NotNull
public List<PostgreTableInheritance> getSubInheritance(@NotNull DBRProgressMonitor monitor) throws DBException {
if (subTables == null) {
try (JDBCSession session = DBUtils.openMetaSession(monitor, getDataSource(), "Load table inheritance info")) {
try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT i.*,c.relnamespace " + "FROM pg_catalog.pg_inherits i,pg_catalog.pg_class c " + "WHERE i.inhparent=? AND c.oid=i.inhrelid")) {
dbStat.setLong(1, getObjectId());
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
while (dbResult.next()) {
final long subSchemaId = JDBCUtils.safeGetLong(dbResult, "relnamespace");
final long subTableId = JDBCUtils.safeGetLong(dbResult, "inhrelid");
PostgreSchema schema = getDatabase().getSchema(monitor, subSchemaId);
if (schema == null) {
log.warn("Can't find sub-table's schema '" + subSchemaId + "'");
continue;
}
PostgreTableBase subTable = schema.getTable(monitor, subTableId);
if (subTable == null) {
log.warn("Can't find sub-table '" + subTableId + "' in '" + schema.getName() + "'");
continue;
}
if (subTables == null) {
subTables = new ArrayList<>();
}
subTables.add(new PostgreTableInheritance(subTable, this, JDBCUtils.safeGetInt(dbResult, "inhseqno"), true));
}
}
}
} catch (SQLException e) {
throw new DBCException(e, getDataSource());
}
if (subTables == null) {
subTables = Collections.emptyList();
}
}
return subTables;
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCSession in project dbeaver by serge-rider.
the class PostgreTableForeign method readForeignInfo.
private void readForeignInfo(DBRProgressMonitor monitor) throws DBException {
if (foreignServerId > 0) {
return;
}
try (JDBCSession session = DBUtils.openMetaSession(monitor, getDataSource(), "Read foreign table info")) {
try (JDBCPreparedStatement stat = session.prepareStatement("SELECT * FROM pg_catalog.pg_foreign_table WHERE ftrelid=?")) {
stat.setLong(1, getObjectId());
try (JDBCResultSet result = stat.executeQuery()) {
if (result.next()) {
foreignServerId = JDBCUtils.safeGetLong(result, "ftserver");
foreignOptions = JDBCUtils.safeGetArray(result, "ftoptions");
}
}
}
} catch (SQLException e) {
throw new DBCException(e, getDataSource());
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCSession in project dbeaver by serge-rider.
the class PostgreViewBase method getObjectDefinitionText.
@Override
@Property(hidden = true, editable = true, updatable = true, order = -1)
public String getObjectDefinitionText(DBRProgressMonitor monitor) throws DBException {
if (source == null) {
if (isPersisted()) {
try (JDBCSession session = DBUtils.openMetaSession(monitor, getDataSource(), "Read view definition")) {
String definition = JDBCUtils.queryString(session, "SELECT pg_get_viewdef(?, true)", getObjectId());
this.source = PostgreUtils.getViewDDL(this, definition);
} catch (SQLException e) {
throw new DBException("Error reading view definition", e);
}
} else {
source = "";
}
}
return source;
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCSession in project dbeaver by serge-rider.
the class MySQLDataSource method loadPrivileges.
private List<MySQLPrivilege> loadPrivileges(DBRProgressMonitor monitor) throws DBException {
try (JDBCSession session = DBUtils.openMetaSession(monitor, this, "Load privileges")) {
try (JDBCPreparedStatement dbStat = session.prepareStatement("SHOW PRIVILEGES")) {
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
List<MySQLPrivilege> privileges = new ArrayList<>();
while (dbResult.next()) {
MySQLPrivilege user = new MySQLPrivilege(this, dbResult);
privileges.add(user);
}
return privileges;
}
}
} catch (SQLException ex) {
throw new DBException(ex, this);
}
}
Aggregations