use of org.jkiss.dbeaver.model.exec.DBCException in project dbeaver by serge-rider.
the class DB2BaseTableToolDialog method getScriptListener.
@Override
protected SQLScriptProgressListener<DB2Table> getScriptListener() {
final int nbExtraColumns = getNumberExtraResultingColumns();
return new SQLScriptStatusDialog<DB2Table>(getShell(), getTitle() + " " + DB2Messages.dialog_table_tools_progress, null) {
@Override
protected void createStatusColumns(Tree objectTree) {
TreeColumn msgColumn = new TreeColumn(objectTree, SWT.NONE);
msgColumn.setText(DB2Messages.dialog_table_tools_result);
for (int i = 0; i < nbExtraColumns; i++) {
new TreeColumn(objectTree, SWT.NONE);
}
}
@Override
public void endObjectProcessing(@NotNull DB2Table db2Table, Exception exception) {
TreeItem treeItem = getTreeItem(db2Table);
if (exception == null) {
treeItem.setText(1, DB2Messages.dialog_table_tools_success_title);
} else {
treeItem.setText(1, exception.getMessage());
}
UIUtils.packColumns(treeItem.getParent(), false, null);
}
// DF: This method is for tools that return resultsets
@Override
public void processObjectResults(@NotNull DB2Table db2Table, @Nullable DBCStatement statement, @Nullable DBCResultSet resultSet) throws DBCException {
if (resultSet == null) {
return;
}
// Retrive column names
JDBCResultSetMetaDataImpl rsMetaData = (JDBCResultSetMetaDataImpl) resultSet.getMeta();
try {
TreeItem treeItem = getTreeItem(db2Table);
Font f = UIUtils.makeBoldFont(treeItem.getFont());
if (treeItem != null) {
// Display the column names
TreeItem subItem = null;
subItem = new TreeItem(treeItem, SWT.NONE);
subItem.setFont(f);
for (int i = 0; i < rsMetaData.getColumnCount(); i++) {
subItem.setText(i, rsMetaData.getColumnName(i + 1));
subItem.setGrayed(true);
}
// Display the data for each row
while (resultSet.nextRow()) {
subItem = new TreeItem(treeItem, SWT.NONE);
for (int i = 0; i < rsMetaData.getColumnCount(); i++) {
subItem.setText(i, CommonUtils.toString(resultSet.getAttributeValue(i)));
}
}
treeItem.setExpanded(true);
}
} catch (SQLException e) {
throw new DBCException(e.getMessage());
}
}
};
}
use of org.jkiss.dbeaver.model.exec.DBCException in project dbeaver by serge-rider.
the class CompileHandler method compileUnit.
public static boolean compileUnit(DBRProgressMonitor monitor, DBCCompileLog compileLog, OracleSourceObject unit) throws DBCException {
final DBEPersistAction[] compileActions = unit.getCompileActions();
if (ArrayUtils.isEmpty(compileActions)) {
return true;
}
try (JDBCSession session = DBUtils.openUtilSession(monitor, unit.getDataSource(), "Compile '" + unit.getName() + "'")) {
boolean success = true;
for (DBEPersistAction action : compileActions) {
final String script = action.getScript();
compileLog.trace(script);
if (monitor.isCanceled()) {
break;
}
try {
try (DBCStatement dbStat = session.prepareStatement(DBCStatementType.QUERY, script, false, false, false)) {
dbStat.executeStatement();
}
action.handleExecute(session, null);
} catch (DBCException e) {
action.handleExecute(session, e);
throw e;
}
if (action instanceof OracleObjectPersistAction) {
if (!logObjectErrors(session, compileLog, unit, ((OracleObjectPersistAction) action).getObjectType())) {
success = false;
}
}
}
final DBSObjectState oldState = unit.getObjectState();
unit.refreshObjectState(monitor);
if (unit.getObjectState() != oldState) {
unit.getDataSource().getContainer().fireEvent(new DBPEvent(DBPEvent.Action.OBJECT_UPDATE, unit));
}
return success;
}
}
use of org.jkiss.dbeaver.model.exec.DBCException 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.exec.DBCException in project dbeaver by serge-rider.
the class OracleDataType method getComponentType.
@Property(viewable = true, order = 8)
public OracleDataType getComponentType(@NotNull DBRProgressMonitor monitor) throws DBCException {
if (componentType != null) {
return componentType;
}
OracleSchema schema = getSchema();
if (schema == null || !TYPE_CODE_COLLECTION.equals(typeCode) || !getDataSource().isAtLeastV10()) {
return null;
}
try (JDBCSession session = DBUtils.openMetaSession(monitor, getDataSource(), "Load collection types")) {
try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT ELEM_TYPE_OWNER,ELEM_TYPE_NAME,ELEM_TYPE_MOD FROM SYS.ALL_COLL_TYPES WHERE OWNER=? AND TYPE_NAME=?")) {
dbStat.setString(1, schema.getName());
dbStat.setString(2, getName());
try (JDBCResultSet dbResults = dbStat.executeQuery()) {
if (dbResults.next()) {
String compTypeSchema = JDBCUtils.safeGetString(dbResults, "ELEM_TYPE_OWNER");
String compTypeName = JDBCUtils.safeGetString(dbResults, "ELEM_TYPE_NAME");
//String compTypeMod = JDBCUtils.safeGetString(dbResults, "ELEM_TYPE_MOD");
componentType = OracleDataType.resolveDataType(monitor, getDataSource(), compTypeSchema, compTypeName);
} else {
log.warn("Can't resolve collection type [" + getName() + "]");
}
}
}
} catch (Exception e) {
log.warn("Error reading collection types", e);
}
return componentType;
}
use of org.jkiss.dbeaver.model.exec.DBCException in project dbeaver by serge-rider.
the class MySQLTable method loadAdditionalInfo.
private void loadAdditionalInfo(DBRProgressMonitor monitor) throws DBCException {
if (!isPersisted()) {
additionalInfo.loaded = true;
return;
}
MySQLDataSource dataSource = getDataSource();
try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Load table status")) {
try (JDBCPreparedStatement dbStat = session.prepareStatement("SHOW TABLE STATUS FROM " + DBUtils.getQuotedIdentifier(getContainer()) + " LIKE '" + getName() + "'")) {
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
if (dbResult.next()) {
// filer table description (for INNODB it contains some system information)
String desc = JDBCUtils.safeGetString(dbResult, MySQLConstants.COL_TABLE_COMMENT);
if (desc != null) {
if (desc.startsWith(INNODB_COMMENT)) {
desc = "";
} else if (!CommonUtils.isEmpty(desc)) {
int divPos = desc.indexOf("; " + INNODB_COMMENT);
if (divPos != -1) {
desc = desc.substring(0, divPos);
}
}
additionalInfo.description = desc;
}
additionalInfo.engine = dataSource.getEngine(JDBCUtils.safeGetString(dbResult, MySQLConstants.COL_ENGINE));
additionalInfo.rowCount = JDBCUtils.safeGetLong(dbResult, MySQLConstants.COL_TABLE_ROWS);
additionalInfo.autoIncrement = JDBCUtils.safeGetLong(dbResult, MySQLConstants.COL_AUTO_INCREMENT);
additionalInfo.createTime = JDBCUtils.safeGetTimestamp(dbResult, MySQLConstants.COL_CREATE_TIME);
additionalInfo.updateTime = JDBCUtils.safeGetTimestamp(dbResult, "Update_time");
additionalInfo.checkTime = JDBCUtils.safeGetTimestamp(dbResult, "Check_time");
additionalInfo.collation = dataSource.getCollation(JDBCUtils.safeGetString(dbResult, MySQLConstants.COL_COLLATION));
if (additionalInfo.collation != null) {
additionalInfo.charset = additionalInfo.collation.getCharset();
}
additionalInfo.avgRowLength = JDBCUtils.safeGetLong(dbResult, MySQLConstants.COL_AVG_ROW_LENGTH);
additionalInfo.dataLength = JDBCUtils.safeGetLong(dbResult, MySQLConstants.COL_DATA_LENGTH);
additionalInfo.maxDataLength = JDBCUtils.safeGetLong(dbResult, "Max_data_length");
additionalInfo.dataFree = JDBCUtils.safeGetLong(dbResult, "Data_free");
additionalInfo.indexLength = JDBCUtils.safeGetLong(dbResult, "Index_length");
additionalInfo.rowFormat = JDBCUtils.safeGetString(dbResult, "Row_format");
}
additionalInfo.loaded = true;
}
}
} catch (SQLException e) {
throw new DBCException(e, dataSource);
}
}
Aggregations