use of org.jkiss.dbeaver.model.exec.jdbc.JDBCSession in project dbeaver by serge-rider.
the class OracleUtils method getSource.
public static String getSource(DBRProgressMonitor monitor, OracleSourceObject sourceObject, boolean body, boolean insertCreateReplace) throws DBCException {
if (sourceObject.getSourceType().isCustom()) {
log.warn("Can't read source for custom source objects");
return "-- ???? CUSTOM SOURCE";
}
final String sourceType = sourceObject.getSourceType().name();
final OracleSchema sourceOwner = sourceObject.getSchema();
if (sourceOwner == null) {
log.warn("No source owner for object '" + sourceObject.getName() + "'");
return null;
}
monitor.beginTask("Load sources for '" + sourceObject.getName() + "'...", 1);
String sysViewName = OracleConstants.VIEW_DBA_SOURCE;
if (!sourceObject.getDataSource().isViewAvailable(monitor, OracleConstants.SCHEMA_SYS, sysViewName)) {
sysViewName = OracleConstants.VIEW_ALL_SOURCE;
}
try (final JDBCSession session = DBUtils.openMetaSession(monitor, sourceOwner.getDataSource(), "Load source code for " + sourceType + " '" + sourceObject.getName() + "'")) {
try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT TEXT FROM " + OracleConstants.SCHEMA_SYS + "." + sysViewName + " " + "WHERE TYPE=? AND OWNER=? AND NAME=? " + "ORDER BY LINE")) {
dbStat.setString(1, body ? sourceType + " BODY" : sourceType);
dbStat.setString(2, sourceOwner.getName());
dbStat.setString(3, sourceObject.getName());
dbStat.setFetchSize(DBConstants.METADATA_FETCH_SIZE);
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
StringBuilder source = null;
int lineCount = 0;
while (dbResult.next()) {
if (monitor.isCanceled()) {
break;
}
final String line = dbResult.getString(1);
if (source == null) {
source = new StringBuilder(200);
}
source.append(line);
lineCount++;
monitor.subTask("Line " + lineCount);
}
if (source == null) {
return null;
}
if (insertCreateReplace) {
return insertCreateReplace(sourceObject, body, source.toString());
} else {
return source.toString();
}
}
}
} catch (SQLException e) {
throw new DBCException(e, sourceOwner.getDataSource());
} finally {
monitor.done();
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCSession in project dbeaver by serge-rider.
the class OracleUtils method getObjectStatus.
public static boolean getObjectStatus(DBRProgressMonitor monitor, OracleStatefulObject object, OracleObjectType objectType) throws DBCException {
try (JDBCSession session = DBUtils.openMetaSession(monitor, object.getDataSource(), "Refresh state of " + objectType.getTypeName() + " '" + object.getName() + "'")) {
try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT STATUS FROM SYS.ALL_OBJECTS WHERE OBJECT_TYPE=? AND OWNER=? AND OBJECT_NAME=?")) {
dbStat.setString(1, objectType.getTypeName());
dbStat.setString(2, object.getSchema().getName());
dbStat.setString(3, DBObjectNameCaseTransformer.transformObjectName(object, object.getName()));
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
if (dbResult.next()) {
return "VALID".equals(dbResult.getString("STATUS"));
} else {
log.warn(objectType.getTypeName() + " '" + object.getName() + "' not found in system dictionary");
return false;
}
}
}
} catch (SQLException e) {
throw new DBCException(e, object.getDataSource());
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCSession in project dbeaver by serge-rider.
the class OracleTablePhysical method getPartitionInfo.
@PropertyGroup
@LazyProperty(cacheValidator = PartitionInfoValidator.class)
public PartitionInfo getPartitionInfo(DBRProgressMonitor monitor) throws DBException {
if (partitionInfo == null && partitioned) {
try (final JDBCSession session = DBUtils.openMetaSession(monitor, getDataSource(), "Load partitioning info")) {
try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT * FROM ALL_PART_TABLES WHERE OWNER=? AND TABLE_NAME=?")) {
dbStat.setString(1, getContainer().getName());
dbStat.setString(2, getName());
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
if (dbResult.next()) {
partitionInfo = new PartitionInfo(monitor, this.getDataSource(), dbResult);
}
}
}
} catch (SQLException e) {
throw new DBException(e, getDataSource());
}
}
return partitionInfo;
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCSession in project dbeaver by serge-rider.
the class FireBirdUtils method getProcedureSource.
public static String getProcedureSource(DBRProgressMonitor monitor, GenericProcedure procedure) throws DBException {
try (JDBCSession session = DBUtils.openMetaSession(monitor, procedure.getDataSource(), "Load procedure source code")) {
DatabaseMetaData fbMetaData = session.getOriginal().getMetaData();
String source = (String) fbMetaData.getClass().getMethod("getProcedureSourceCode", String.class).invoke(fbMetaData, procedure.getName());
if (CommonUtils.isEmpty(source)) {
return null;
}
return getProcedureSourceWithHeader(monitor, procedure, source);
} catch (SQLException e) {
throw new DBException("Can't read source code of procedure '" + procedure.getName() + "'", e);
} catch (Exception e) {
log.debug(e);
return null;
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCSession in project dbeaver by serge-rider.
the class ExasolDataSource method initialize.
// -----------------------
// Initialization/Structure
// -----------------------
@Override
public void initialize(@NotNull DBRProgressMonitor monitor) throws DBException {
super.initialize(monitor);
try (JDBCSession session = DBUtils.openMetaSession(monitor, this, "Load data source meta info")) {
// First try to get active schema from special register 'CURRENT
// SCHEMA'
this.activeSchemaName = determineActiveSchema(session);
this.exasolCurrentUserPrivileges = new ExasolCurrentUserPrivileges(monitor, session, this);
this.driverMajorVersion = session.getMetaData().getDriverMajorVersion();
} catch (SQLException e) {
LOG.warn("Error reading active schema", e);
}
String schemaSQL = "select b.object_name,b.owner,b.created,b.object_comment from EXA_ALL_OBJECTS b " + "inner join EXA_SCHEMAS s on b.object_name = s.schema_name where b.object_type = 'SCHEMA' ";
if (exasolCurrentUserPrivileges.getatLeastV6()) {
//additional where clause to filter virtual schemas
schemaSQL += " and not schema_is_virtual ";
//build virtual schema cache for >V6 databases
virtualSchemaCache = new JDBCObjectSimpleCache<>(ExasolVirtualSchema.class, "select" + " SCHEMA_NAME as OBJECT_NAME," + " SCHEMA_OWNER AS OWNER," + " ADAPTER_SCRIPT," + " LAST_REFRESH," + " LAST_REFRESH_BY," + " ADAPTER_NOTES," + " OBJECT_COMMENT," + " CREATED" + " from" + " EXA_VIRTUAL_SCHEMAS s" + " INNER JOIN" + " EXA_ALL_OBJECTS o" + " ON" + " o.OBJECT_NAME = s.SCHEMA_NAME AND" + " o.OBJECT_TYPE = 'SCHEMA'");
}
schemaSQL += " union all select distinct SCHEMA_NAME as \"OBJECT_NAME\", 'SYS' as owner, cast(null as timestamp) as created, '' as \"OBJECT_COMMENT\" from SYS.EXA_SYSCAT " + "order by b.object_name";
schemaCache = new JDBCObjectSimpleCache<>(ExasolSchema.class, schemaSQL);
try {
this.dataTypeCache.getAllObjects(monitor, this);
} catch (DBException e) {
LOG.warn("Error reading types info", e);
this.dataTypeCache.setCache(Collections.<ExasolDataType>emptyList());
}
if (exasolCurrentUserPrivileges.getUserIsAuthorizedForUsers()) {
this.userCache = new JDBCObjectSimpleCache<>(ExasolUser.class, "select * from EXA_DBA_USERS ORDER BY USER_NAME");
}
if (exasolCurrentUserPrivileges.getUserIsAuthorizedForRoles()) {
this.roleCache = new JDBCObjectSimpleCache<>(ExasolRole.class, "SELECT * FROM EXA_DBA_ROLES ORDER BY ROLE_NAME");
}
if (exasolCurrentUserPrivileges.getUserIsAuthorizedForConnections()) {
this.connectionCache = new JDBCObjectSimpleCache<>(ExasolConnection.class, "SELECT * FROM EXA_DBA_CONNECTIONS ORDER BY CONNECTION_NAME");
}
if (exasolCurrentUserPrivileges.getUserIsAuthorizedForConnectionPrivs()) {
this.connectionGrantCache = new JDBCObjectSimpleCache<>(ExasolConnectionGrant.class, "SELECT c.*,P.ADMIN_OPTION,P.GRANTEE FROM SYS.EXA_DBA_CONNECTION_PRIVS P " + "INNER JOIN SYS.EXA_DBA_CONNECTIONS C on P.GRANTED_CONNECTION = C.CONNECTION_NAME ORDER BY P.GRANTEE,C.CONNECTION_NAME ");
}
if (exasolCurrentUserPrivileges.getUserIsAuthorizedForObjectPrivs()) {
this.baseTableGrantCache = new JDBCObjectSimpleCache<>(ExasolBaseObjectGrant.class, "SELECT " + " OBJECT_SCHEMA," + " OBJECT_TYPE," + " GRANTEE," + " OBJECT_NAME," + " GROUP_CONCAT(" + " DISTINCT PRIVILEGE" + " ORDER BY" + " OBJECT_SCHEMA," + " OBJECT_NAME" + " SEPARATOR '|'" + " ) as PRIVS " + " FROM" + " SYS.EXA_DBA_OBJ_PRIVS P" + " GROUP BY" + " OBJECT_SCHEMA," + " OBJECT_TYPE," + " GRANTEE," + " OBJECT_NAME ORDER BY GRANTEE,OBJECT_SCHEMA,OBJECT_TYPE,OBJECT_NAME");
}
if (exasolCurrentUserPrivileges.getUserIsAuthorizedForSystemPrivs()) {
this.systemGrantCache = new JDBCObjectSimpleCache<>(ExasolSystemGrant.class, "SELECT GRANTEE,PRIVILEGE,ADMIN_OPTION FROM SYS.EXA_DBA_SYS_PRIVS ORDER BY GRANTEE,PRIVILEGE");
}
if (exasolCurrentUserPrivileges.getUserIsAuthorizedForRolePrivs()) {
this.roleGrantCache = new JDBCObjectSimpleCache<>(ExasolRoleGrant.class, "select r.*,p.ADMIN_OPTION,p.GRANTEE from EXA_DBA_ROLES r " + "INNER JOIN EXA_DBA_ROLE_PRIVS p ON p.GRANTED_ROLE = r.ROLE_NAME ORDER BY P.GRANTEE,R.ROLE_NAME");
}
}
Aggregations