use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.
the class ContentPanelEditor method primeEditorValue.
@Override
public void primeEditorValue(@Nullable final Object value) throws DBException {
final DBDContent content = (DBDContent) valueController.getValue();
if (content == null) {
valueController.showMessage("NULL content value. Must be DBDContent.", DBPMessageType.ERROR);
return;
}
if (streamEditor == null) {
valueController.showMessage("NULL content editor.", DBPMessageType.ERROR);
return;
}
DBeaverUI.runInUI(valueController.getValueSite().getWorkbenchWindow(), new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
streamEditor.primeEditorValue(monitor, control, content);
} catch (Throwable e) {
log.debug(e);
valueController.showMessage(e.getMessage(), DBPMessageType.ERROR);
}
}
});
}
use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.
the class DB2GranteeAuthCache method fetchObject.
@Override
protected DB2AuthBase fetchObject(@NotNull JDBCSession session, @NotNull DB2Grantee db2Grantee, @NotNull JDBCResultSet resultSet) throws SQLException, DBException {
DB2DataSource db2DataSource = db2Grantee.getDataSource();
DBRProgressMonitor monitor = session.getProgressMonitor();
String objectSchemaName = JDBCUtils.safeGetStringTrimmed(resultSet, "OBJ_SCHEMA");
String objectName = JDBCUtils.safeGetStringTrimmed(resultSet, "OBJ_NAME");
DB2ObjectType objectType = CommonUtils.valueOf(DB2ObjectType.class, JDBCUtils.safeGetString(resultSet, "OBJ_TYPE"));
switch(objectType) {
case COLUMN:
String columnName = JDBCUtils.safeGetStringTrimmed(resultSet, "USAGEAUTH");
DB2TableColumn db2TableColumn = DB2Utils.findColumnBySchemaNameAndTableNameAndName(monitor, db2DataSource, objectSchemaName, objectName, columnName);
return new DB2AuthColumn(monitor, db2Grantee, db2TableColumn, resultSet);
case INDEX:
DB2Index db2Index = DB2Utils.findIndexBySchemaNameAndName(monitor, db2DataSource, objectSchemaName, objectName);
return new DB2AuthIndex(monitor, db2Grantee, db2Index, resultSet);
case MODULE:
DB2Module db2Module = DB2Utils.findModuleBySchemaNameAndName(monitor, db2DataSource, objectSchemaName, objectName);
return new DB2AuthModule(monitor, db2Grantee, db2Module, resultSet);
case PACKAGE:
DB2Package db2Package = DB2Utils.findPackageBySchemaNameAndName(monitor, db2DataSource, objectSchemaName, objectName);
return new DB2AuthPackage(monitor, db2Grantee, db2Package, resultSet);
case PROCEDURE:
// Can be a Function or a Procedure
DB2RoutineType routineType = CommonUtils.valueOf(DB2RoutineType.class, JDBCUtils.safeGetStringTrimmed(resultSet, "USAGEAUTH"));
switch(routineType) {
case F:
DB2Routine db2Udf = DB2Utils.findUDFBySchemaNameAndName(monitor, db2DataSource, objectSchemaName, objectName);
return new DB2AuthUDF(monitor, db2Grantee, db2Udf, resultSet);
case M:
DB2Routine db2Method = DB2Utils.findMethodBySchemaNameAndName(monitor, db2DataSource, objectSchemaName, objectName);
return new DB2AuthMethod(monitor, db2Grantee, db2Method, resultSet);
case P:
DB2Routine db2Procedure = DB2Utils.findProcedureBySchemaNameAndName(monitor, db2DataSource, objectSchemaName, objectName);
return new DB2AuthProcedure(monitor, db2Grantee, db2Procedure, resultSet);
default:
throw new DBException(routineType + " is not a valid DB2RoutineType");
}
case SCHEMA:
DB2Schema db2Schema = db2DataSource.getSchema(monitor, objectName);
return new DB2AuthSchema(monitor, db2Grantee, db2Schema, resultSet);
case SEQUENCE:
DB2Sequence db2Sequence = DB2Utils.findSequenceBySchemaNameAndName(monitor, db2DataSource, objectSchemaName, objectName);
return new DB2AuthSequence(monitor, db2Grantee, db2Sequence, resultSet);
case TABLE:
// Can be a Table, a View or an MQT..
DB2TableBase db2TableBase = DB2Utils.findTableBySchemaNameAndName(monitor, db2DataSource, objectSchemaName, objectName);
if (db2TableBase != null) {
return new DB2AuthTable(monitor, db2Grantee, db2TableBase, resultSet);
} else {
db2TableBase = DB2Utils.findViewBySchemaNameAndName(monitor, db2DataSource, objectSchemaName, objectName);
if (db2TableBase != null) {
return new DB2AuthView(monitor, db2Grantee, db2TableBase, resultSet);
} else {
db2TableBase = DB2Utils.findMQTBySchemaNameAndName(monitor, db2DataSource, objectSchemaName, objectName);
return new DB2AuthMaterializedQueryTable(monitor, db2Grantee, db2TableBase, resultSet);
}
}
case TABLESPACE:
DB2Tablespace db2Tablespace = db2DataSource.getTablespace(monitor, objectName);
return new DB2AuthTablespace(monitor, db2Grantee, db2Tablespace, resultSet);
case VARIABLE:
DB2Variable db2Variable = db2DataSource.getVariable(monitor, objectName);
return new DB2AuthVariable(monitor, db2Grantee, db2Variable, resultSet);
case XML_SCHEMA:
Long xmlSchemaId = Long.valueOf(objectName);
DB2XMLSchema db2XmlSchema = DB2Utils.findXMLSchemaByById(monitor, db2DataSource, xmlSchemaId);
return new DB2AuthXMLSchema(monitor, db2Grantee, db2XmlSchema, resultSet);
default:
throw new DBException("Programming error: " + objectType + " is not supported yet and the SELECT statement must exclude it");
}
}
use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.
the class CompileHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final List<OracleSourceObject> objects = getSelectedObjects(event);
if (!objects.isEmpty()) {
final Shell activeShell = HandlerUtil.getActiveShell(event);
if (objects.size() == 1) {
final OracleSourceObject unit = objects.get(0);
DBCSourceHost sourceHost = null;
final IWorkbenchPart activePart = HandlerUtil.getActiveEditor(event);
if (activePart != null) {
sourceHost = RuntimeUtils.getObjectAdapter(activePart, DBCSourceHost.class);
if (sourceHost == null) {
sourceHost = activePart.getAdapter(DBCSourceHost.class);
}
}
if (sourceHost != null && sourceHost.getSourceObject() != unit) {
sourceHost = null;
}
final DBCCompileLog compileLog = sourceHost == null ? new DBCCompileLogBase() : sourceHost.getCompileLog();
compileLog.clearLog();
Throwable error = null;
try {
DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
compileUnit(monitor, compileLog, unit);
} catch (DBCException e) {
throw new InvocationTargetException(e);
}
}
});
if (compileLog.getError() != null) {
error = compileLog.getError();
}
} catch (InvocationTargetException e) {
error = e.getTargetException();
} catch (InterruptedException e) {
return null;
}
if (error != null) {
UIUtils.showErrorDialog(activeShell, "Unexpected compilation error", null, error);
} else if (!CommonUtils.isEmpty(compileLog.getErrorStack())) {
// Show compile errors
int line = -1, position = -1;
StringBuilder fullMessage = new StringBuilder();
for (DBCCompileError oce : compileLog.getErrorStack()) {
fullMessage.append(oce.toString()).append(GeneralUtils.getDefaultLineSeparator());
if (line < 0) {
line = oce.getLine();
position = oce.getPosition();
}
}
// If compiled object is currently open in editor - try to position on error line
if (sourceHost != null && sourceHost.getSourceObject() == unit && line > 0 && position > 0) {
sourceHost.positionSource(line, position);
activePart.getSite().getPage().activate(activePart);
}
String errorTitle = unit.getName() + " compilation failed";
if (sourceHost != null) {
sourceHost.setCompileInfo(errorTitle, true);
sourceHost.showCompileLog();
}
UIUtils.showErrorDialog(activeShell, errorTitle, fullMessage.toString());
} else {
String message = unit.getName() + " compiled successfully";
if (sourceHost != null) {
sourceHost.setCompileInfo(message, true);
}
UIUtils.showMessageBox(activeShell, "Done", message, SWT.ICON_INFORMATION);
}
} else {
OracleCompilerDialog dialog = new OracleCompilerDialog(activeShell, objects);
dialog.open();
}
}
return null;
}
use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.
the class OracleStructureAssistant method searchAllObjects.
private void searchAllObjects(final JDBCSession session, final OracleSchema schema, String objectNameMask, DBSObjectType[] objectTypes, boolean caseSensitive, int maxResults, List<DBSObjectReference> objects) throws SQLException, DBException {
StringBuilder objectTypeClause = new StringBuilder(100);
final List<OracleObjectType> oracleObjectTypes = new ArrayList<>(objectTypes.length + 2);
for (DBSObjectType objectType : objectTypes) {
if (objectType instanceof OracleObjectType) {
oracleObjectTypes.add((OracleObjectType) objectType);
if (objectType == OracleObjectType.PROCEDURE) {
oracleObjectTypes.add(OracleObjectType.FUNCTION);
} else if (objectType == OracleObjectType.TABLE) {
oracleObjectTypes.add(OracleObjectType.VIEW);
oracleObjectTypes.add(OracleObjectType.MATERIALIZED_VIEW);
}
}
}
for (OracleObjectType objectType : oracleObjectTypes) {
if (objectTypeClause.length() > 0)
objectTypeClause.append(",");
objectTypeClause.append("'").append(objectType.getTypeName()).append("'");
}
if (objectTypeClause.length() == 0) {
return;
}
// Always search for synonyms
objectTypeClause.append(",'").append(OracleObjectType.SYNONYM.getTypeName()).append("'");
// Seek for objects (join with public synonyms)
try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT " + OracleUtils.getSysCatalogHint((OracleDataSource) session.getDataSource()) + " DISTINCT OWNER,OBJECT_NAME,OBJECT_TYPE FROM (SELECT OWNER,OBJECT_NAME,OBJECT_TYPE FROM ALL_OBJECTS WHERE " + "OBJECT_TYPE IN (" + objectTypeClause + ") AND OBJECT_NAME LIKE ? " + (schema == null ? "" : " AND OWNER=?") + "UNION ALL\n" + "SELECT " + OracleUtils.getSysCatalogHint((OracleDataSource) session.getDataSource()) + " O.OWNER,O.OBJECT_NAME,O.OBJECT_TYPE\n" + "FROM ALL_SYNONYMS S,ALL_OBJECTS O\n" + "WHERE O.OWNER=S.TABLE_OWNER AND O.OBJECT_NAME=S.TABLE_NAME AND S.OWNER='PUBLIC' AND S.SYNONYM_NAME LIKE ?)" + "\nORDER BY OBJECT_NAME")) {
if (!caseSensitive) {
objectNameMask = objectNameMask.toUpperCase();
}
dbStat.setString(1, objectNameMask);
if (schema != null) {
dbStat.setString(2, schema.getName());
}
dbStat.setString(schema != null ? 3 : 2, objectNameMask);
dbStat.setFetchSize(DBConstants.METADATA_FETCH_SIZE);
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
while (objects.size() < maxResults && dbResult.next()) {
if (session.getProgressMonitor().isCanceled()) {
break;
}
final String schemaName = JDBCUtils.safeGetString(dbResult, "OWNER");
final String objectName = JDBCUtils.safeGetString(dbResult, "OBJECT_NAME");
final String objectTypeName = JDBCUtils.safeGetString(dbResult, "OBJECT_TYPE");
final OracleObjectType objectType = OracleObjectType.getByType(objectTypeName);
if (objectType != null && objectType != OracleObjectType.SYNONYM && objectType.isBrowsable() && oracleObjectTypes.contains(objectType)) {
OracleSchema objectSchema = dataSource.getSchema(session.getProgressMonitor(), schemaName);
if (objectSchema == null) {
log.debug("Schema '" + schemaName + "' not found. Probably was filtered");
continue;
}
objects.add(new AbstractObjectReference(objectName, objectSchema, null, objectType.getTypeClass(), objectType) {
@Override
public DBSObject resolveObject(DBRProgressMonitor monitor) throws DBException {
OracleSchema tableSchema = (OracleSchema) getContainer();
DBSObject object = objectType.findObject(session.getProgressMonitor(), tableSchema, objectName);
if (object == null) {
throw new DBException(objectTypeName + " '" + objectName + "' not found in schema '" + tableSchema.getName() + "'");
}
return object;
}
});
}
}
}
}
}
use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.
the class OracleStructureAssistant method findConstraintsByMask.
private void findConstraintsByMask(JDBCSession session, final OracleSchema schema, String constrNameMask, DBSObjectType[] objectTypes, int maxResults, List<DBSObjectReference> objects) throws SQLException, DBException {
DBRProgressMonitor monitor = session.getProgressMonitor();
List<DBSObjectType> objectTypesList = Arrays.asList(objectTypes);
final boolean hasFK = objectTypesList.contains(OracleObjectType.FOREIGN_KEY);
final boolean hasConstraints = objectTypesList.contains(OracleObjectType.CONSTRAINT);
// Load tables
try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT " + OracleUtils.getSysCatalogHint((OracleDataSource) session.getDataSource()) + " OWNER, TABLE_NAME, CONSTRAINT_NAME, CONSTRAINT_TYPE\n" + "FROM SYS.ALL_CONSTRAINTS\n" + "WHERE CONSTRAINT_NAME like ?" + (!hasFK ? " AND CONSTRAINT_TYPE<>'R'" : "") + (schema != null ? " AND OWNER=?" : ""))) {
dbStat.setString(1, constrNameMask);
if (schema != null) {
dbStat.setString(2, schema.getName());
}
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
int tableNum = maxResults;
while (dbResult.next() && tableNum-- > 0) {
if (monitor.isCanceled()) {
break;
}
final String schemaName = JDBCUtils.safeGetString(dbResult, OracleConstants.COL_OWNER);
final String tableName = JDBCUtils.safeGetString(dbResult, OracleConstants.COL_TABLE_NAME);
final String constrName = JDBCUtils.safeGetString(dbResult, OracleConstants.COL_CONSTRAINT_NAME);
final String constrType = JDBCUtils.safeGetString(dbResult, OracleConstants.COL_CONSTRAINT_TYPE);
final DBSEntityConstraintType type = OracleTableConstraint.getConstraintType(constrType);
objects.add(new AbstractObjectReference(constrName, dataSource.getSchema(session.getProgressMonitor(), schemaName), null, type == DBSEntityConstraintType.FOREIGN_KEY ? OracleTableForeignKey.class : OracleTableConstraint.class, type == DBSEntityConstraintType.FOREIGN_KEY ? OracleObjectType.FOREIGN_KEY : OracleObjectType.CONSTRAINT) {
@Override
public DBSObject resolveObject(DBRProgressMonitor monitor) throws DBException {
OracleSchema tableSchema = schema != null ? schema : dataSource.getSchema(monitor, schemaName);
if (tableSchema == null) {
throw new DBException("Constraint schema '" + schemaName + "' not found");
}
OracleTable table = tableSchema.getTable(monitor, tableName);
if (table == null) {
throw new DBException("Constraint table '" + tableName + "' not found in catalog '" + tableSchema.getName() + "'");
}
DBSObject constraint = null;
if (hasFK && type == DBSEntityConstraintType.FOREIGN_KEY) {
constraint = table.getForeignKey(monitor, constrName);
}
if (hasConstraints && type != DBSEntityConstraintType.FOREIGN_KEY) {
constraint = table.getConstraint(monitor, constrName);
}
if (constraint == null) {
throw new DBException("Constraint '" + constrName + "' not found in table '" + table.getFullyQualifiedName(DBPEvaluationContext.DDL) + "'");
}
return constraint;
}
});
}
}
}
}
Aggregations