use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by dbeaver.
the class EntityEditor method showChanges.
public int showChanges(boolean allowSave) {
DBECommandContext commandContext = getCommandContext();
if (commandContext == null) {
return IDialogConstants.CANCEL_ID;
}
Collection<? extends DBECommand> commands = commandContext.getFinalCommands();
if (CommonUtils.isEmpty(commands)) {
return IDialogConstants.IGNORE_ID;
}
StringBuilder script = new StringBuilder();
try {
saveInProgress = true;
UIUtils.runInProgressService(monitor -> {
monitor.beginTask("Generate SQL script", commands.size());
Map<String, Object> validateOptions = new HashMap<>();
for (DBECommand command : commands) {
monitor.subTask(command.getTitle());
try {
command.validateCommand(monitor, validateOptions);
} catch (final DBException e) {
throw new InvocationTargetException(e);
}
Map<String, Object> options = new HashMap<>();
options.put(DBPScriptObject.OPTION_OBJECT_SAVE, true);
DBPDataSource dataSource = getDatabaseObject().getDataSource();
try {
DBEPersistAction[] persistActions = command.getPersistActions(monitor, getExecutionContext(), options);
script.append(SQLUtils.generateScript(dataSource, persistActions, false));
} catch (DBException e) {
throw new InvocationTargetException(e);
}
monitor.worked(1);
}
monitor.done();
});
} catch (InterruptedException e) {
return IDialogConstants.CANCEL_ID;
} catch (InvocationTargetException e) {
log.error(e);
DBWorkbench.getPlatformUI().showError("Script generate error", "Couldn't generate alter script", e.getTargetException());
return IDialogConstants.CANCEL_ID;
} finally {
saveInProgress = false;
}
if (script.length() == 0) {
return IDialogConstants.PROCEED_ID;
}
ChangesPreviewer changesPreviewer = new ChangesPreviewer(script, allowSave);
UIUtils.syncExec(changesPreviewer);
return changesPreviewer.getResult();
}
use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by serge-rider.
the class DB2TableColumnManager method addObjectModifyActions.
// -----
// Alter
// -----
@Override
protected void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand command) {
DB2TableColumn db2Column = command.getObject();
boolean hasColumnChanges = false;
if (!command.getProperties().isEmpty()) {
final String deltaSQL = computeDeltaSQL(command);
if (!deltaSQL.isEmpty()) {
hasColumnChanges = true;
String sqlAlterColumn = String.format(SQL_ALTER, db2Column.getTable().getFullyQualifiedName(DBPEvaluationContext.DDL), deltaSQL);
actionList.add(new SQLDatabasePersistAction(CMD_ALTER, sqlAlterColumn));
}
}
// Comment
DBEPersistAction commentAction = buildCommentAction(db2Column);
if (commentAction != null) {
actionList.add(commentAction);
}
if (hasColumnChanges) {
// Be Safe, Add a reorg action
actionList.add(buildReorgAction(db2Column));
}
}
use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by serge-rider.
the class DB2TableManager method addObjectModifyActions.
// ------
// Alter
// ------
@Override
public void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand command) {
DB2Table db2Table = command.getObject();
if (command.getProperties().size() > 1) {
StringBuilder sb = new StringBuilder(128);
sb.append(SQL_ALTER);
sb.append(db2Table.getFullyQualifiedName(DBPEvaluationContext.DDL));
sb.append(" ");
appendTableModifiers(command.getObject(), command, sb);
actionList.add(new SQLDatabasePersistAction(CMD_ALTER, sb.toString()));
}
DBEPersistAction commentAction = buildCommentAction(db2Table);
if (commentAction != null) {
actionList.add(commentAction);
}
}
use of org.jkiss.dbeaver.model.edit.DBEPersistAction 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.edit.DBEPersistAction in project dbeaver by serge-rider.
the class OracleSequenceManager method addObjectDeleteActions.
@Override
protected void addObjectDeleteActions(List<DBEPersistAction> actions, ObjectDeleteCommand command) {
String sql = "DROP SEQUENCE " + command.getObject().getFullyQualifiedName(DBPEvaluationContext.DDL);
DBEPersistAction action = new SQLDatabasePersistAction("Drop Sequence", sql);
actions.add(action);
}
Aggregations