use of org.jkiss.dbeaver.model.exec.jdbc.JDBCSession in project dbeaver by serge-rider.
the class OracleTableBase method loadColumnComments.
void loadColumnComments(DBRProgressMonitor monitor) {
try {
try (JDBCSession session = DBUtils.openMetaSession(monitor, getDataSource(), "Load table column comments")) {
try (JDBCPreparedStatement stat = session.prepareStatement("SELECT COLUMN_NAME,COMMENTS FROM SYS.ALL_COL_COMMENTS cc WHERE CC.OWNER=? AND cc.TABLE_NAME=?")) {
stat.setString(1, getSchema().getName());
stat.setString(2, getName());
try (JDBCResultSet resultSet = stat.executeQuery()) {
while (resultSet.next()) {
String colName = resultSet.getString(1);
String colComment = resultSet.getString(2);
OracleTableColumn col = getAttribute(monitor, colName);
if (col == null) {
log.warn("Column '" + colName + "' not found in table '" + getFullyQualifiedName(DBPEvaluationContext.DDL) + "'");
} else {
col.setComment(CommonUtils.notEmpty(colComment));
}
}
}
}
}
for (OracleTableColumn col : getAttributes(monitor)) {
col.cacheComment();
}
} catch (Exception e) {
log.warn("Error fetching table '" + getName() + "' column comments", e);
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCSession in project dbeaver by serge-rider.
the class OracleUtils method getDDL.
public static String getDDL(DBRProgressMonitor monitor, String objectType, DBSEntity object, OracleDDLFormat ddlFormat) throws DBException {
String objectFullName = DBUtils.getObjectFullName(object, DBPEvaluationContext.DDL);
OracleSchema schema = null;
if (object instanceof OracleSchemaObject) {
schema = ((OracleSchemaObject) object).getSchema();
} else if (object instanceof OracleTableBase) {
schema = ((OracleTableBase) object).getContainer();
}
final OracleDataSource dataSource = (OracleDataSource) object.getDataSource();
monitor.beginTask("Load sources for " + objectType + " '" + objectFullName + "'...", 1);
try (final JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Load source code for " + objectType + " '" + objectFullName + "'")) {
if (dataSource.isAtLeastV9()) {
JDBCUtils.executeProcedure(session, "begin DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'STORAGE'," + ddlFormat.isShowStorage() + "); end;");
JDBCUtils.executeProcedure(session, "begin DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'TABLESPACE'," + ddlFormat.isShowTablespace() + "); end;");
JDBCUtils.executeProcedure(session, "begin DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'SEGMENT_ATTRIBUTES'," + ddlFormat.isShowSegments() + "); end;");
}
try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT DBMS_METADATA.GET_DDL(?,?" + (schema == null ? "" : ",?") + ") TXT " + "FROM DUAL")) {
dbStat.setString(1, objectType);
dbStat.setString(2, object.getName());
if (schema != null) {
dbStat.setString(3, schema.getName());
}
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
if (dbResult.next()) {
return dbResult.getString(1);
} else {
log.warn("No DDL for " + objectType + " '" + objectFullName + "'");
return "-- EMPTY DDL";
}
}
} finally {
/*
if (curSchema != null) {
setCurrentSchema(session, curSchema);
}
*/
}
} catch (SQLException e) {
if (object instanceof OracleTableBase) {
log.error("Error generating Oracle DDL. Generate default.", e);
return JDBCUtils.generateTableDDL(monitor, (OracleTableBase) object, true);
} else {
throw new DBException(e, dataSource);
}
} finally {
monitor.done();
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCSession 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);
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCSession in project dbeaver by serge-rider.
the class OracleServerSessionManager method alterSession.
@Override
public void alterSession(DBCSession session, OracleServerSession sessionType, Map<String, Object> options) throws DBException {
final boolean toKill = Boolean.TRUE.equals(options.get(PROP_KILL_SESSION));
final boolean immediate = Boolean.TRUE.equals(options.get(PROP_IMMEDIATE));
try {
StringBuilder sql = new StringBuilder("ALTER SYSTEM ");
if (toKill) {
sql.append("KILL SESSION ");
} else {
sql.append("DISCONNECT SESSION ");
}
sql.append("'").append(sessionType.getSid()).append(',').append(sessionType.getSerial()).append("'");
if (immediate) {
sql.append(" IMMEDIATE");
} else if (!toKill) {
sql.append(" POST_TRANSACTION");
}
try (JDBCPreparedStatement dbStat = ((JDBCSession) session).prepareStatement(sql.toString())) {
dbStat.execute();
}
} catch (SQLException e) {
throw new DBException(e, session.getDataSource());
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCSession in project dbeaver by serge-rider.
the class DB2Utils method createExplainTables.
public static void createExplainTables(DBRProgressMonitor monitor, DB2DataSource dataSource, String explainTableSchemaName, String tablespaceName) throws DBCException {
LOG.debug("Create EXPLAIN tables in " + explainTableSchemaName);
monitor.beginTask("Create EXPLAIN Tables", 1);
try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Create EXPLAIN tables")) {
try (JDBCCallableStatement stmtSP = session.prepareCall(CALL_INST_OBJ)) {
// EXPLAIN
stmtSP.setString(1, "EXPLAIN");
// Create
stmtSP.setString(2, "C");
// Tablespace
stmtSP.setString(3, tablespaceName);
// Schema
stmtSP.setString(4, explainTableSchemaName);
stmtSP.executeUpdate();
LOG.debug("Creation EXPLAIN Tables : OK");
} catch (SQLException e) {
LOG.error("SQLException occured during EXPLAIN tables creation in schema " + explainTableSchemaName, e);
throw new DBCException(e, dataSource);
}
} finally {
monitor.done();
}
}
Aggregations