use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by serge-rider.
the class PostgreFDWConfigWizard method installFDW.
private void installFDW(DBRProgressMonitor monitor) throws DBException {
monitor.beginTask("Generate FDW script", 2);
monitor.subTask("Read actions");
List<DBEPersistAction> actions = generateScript(monitor);
monitor.subTask("Execute script");
DBCExecutionContext context = DBUtils.getDefaultContext(getDatabase(), false);
DBExecUtils.executeScript(monitor, context, "Install FDW", actions);
}
use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by serge-rider.
the class PostgreFDWConfigWizardPageFinal method generateScript.
private void generateScript() {
StringBuilder script = new StringBuilder();
try {
PostgreDataSource dataSource = getWizard().getDatabase().getDataSource();
getWizard().getRunnableContext().run(true, true, monitor -> {
try {
DBExecUtils.tryExecuteRecover(monitor, dataSource, param -> {
try {
monitor.beginTask("Generate FDW script", 2);
monitor.subTask("Read actions");
List<DBEPersistAction> actions = getWizard().generateScript(monitor);
monitor.subTask("Generate script");
script.append(SQLUtils.generateScript(dataSource, actions.toArray(new DBEPersistAction[0]), false));
monitor.done();
} catch (DBException e) {
throw new InvocationTargetException(e);
}
});
} catch (DBException e) {
throw new InvocationTargetException(e);
}
});
} catch (InvocationTargetException e) {
log.debug(e.getTargetException());
setErrorMessage(e.getTargetException().getMessage());
return;
} catch (InterruptedException e) {
return;
}
setErrorMessage(null);
scriptText = script.toString();
UIServiceSQL service = DBWorkbench.getService(UIServiceSQL.class);
if (service != null) {
service.setSQLPanelText(sqlPanel, scriptText);
}
}
use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by serge-rider.
the class DBStructUtils method generateTableDDL.
public static String generateTableDDL(@NotNull DBRProgressMonitor monitor, @NotNull DBSEntity table, Map<String, Object> options, boolean addComments) throws DBException {
final DBERegistry editorsRegistry = table.getDataSource().getContainer().getPlatform().getEditorsRegistry();
final SQLObjectEditor entityEditor = editorsRegistry.getObjectManager(table.getClass(), SQLObjectEditor.class);
if (entityEditor instanceof SQLTableManager) {
DBEPersistAction[] ddlActions = ((SQLTableManager) entityEditor).getTableDDL(monitor, table, options);
return SQLUtils.generateScript(table.getDataSource(), ddlActions, addComments);
}
log.debug("Table editor not found for " + table.getClass().getName());
return SQLUtils.generateCommentLine(table.getDataSource(), "Can't generate DDL: table editor not found for " + table.getClass().getName());
}
use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by serge-rider.
the class MySQLCommandChangeUser method getPersistActions.
@Override
public DBEPersistAction[] getPersistActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, Map<String, Object> options) {
List<DBEPersistAction> actions = new ArrayList<>();
boolean newUser = !getObject().isPersisted();
if (newUser) {
actions.add(new // $NON-NLS-2$
SQLDatabasePersistAction(// $NON-NLS-2$
MySQLUIMessages.edit_command_change_user_action_create_new_user, // $NON-NLS-2$
"CREATE USER " + getObject().getFullName()) {
@Override
public void afterExecute(DBCSession session, Throwable error) {
if (error == null) {
getObject().setPersisted(true);
}
}
});
}
boolean hasSet;
final MySQLDataSource dataSource = getObject().getDataSource();
if (MySQLUtils.isAlterUSerSupported(dataSource)) {
StringBuilder script = new StringBuilder();
if (generateAlterScript(script)) {
actions.add(new SQLDatabasePersistAction(MySQLUIMessages.edit_command_change_user_action_update_user_record, script.toString()));
}
} else {
String updateSQL = generateUpdateScript();
if (updateSQL != null) {
actions.add(new SQLDatabasePersistAction(MySQLUIMessages.edit_command_change_user_action_update_user_record, updateSQL));
}
updateSQL = generatePasswordSet();
if (updateSQL != null) {
actions.add(new SQLDatabasePersistAction(MySQLUIMessages.edit_command_change_user_action_update_user_record, updateSQL));
}
}
return actions.toArray(new DBEPersistAction[0]);
}
use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by serge-rider.
the class ACLCommandChangePrivilege method getPersistActions.
@Override
public DBEPersistAction[] getPersistActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, Map<String, Object> options) {
DBAPrivilegeOwner object = getObject();
String grantScript = aclManager.generatePermissionChangeScript(monitor, object, grant, privilege, privilegeTypes, options);
return new DBEPersistAction[] { new SQLDatabasePersistAction(ACLMessages.edit_command_grant_privilege_action_grant_privilege, grantScript) };
}
Aggregations