use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by dbeaver.
the class OracleSequenceManager method addObjectDeleteActions.
@Override
protected void addObjectDeleteActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, ObjectDeleteCommand command, Map<String, Object> options) {
String sql = "DROP SEQUENCE " + command.getObject().getFullyQualifiedName(DBPEvaluationContext.DDL);
DBEPersistAction action = new SQLDatabasePersistAction("Drop Sequence", sql);
actions.add(action);
}
use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by dbeaver.
the class PostgreViewBase method getObjectDefinitionText.
@Override
@Property(hidden = true, editable = true, updatable = true, order = -1)
public String getObjectDefinitionText(DBRProgressMonitor monitor, Map<String, Object> options) throws DBException {
if (source == null) {
if (isPersisted()) {
try (JDBCSession session = DBUtils.openMetaSession(monitor, this, "Read view definition")) {
// Do not use view id as a parameter. For some reason it doesn't work for Redshift
String definition = JDBCUtils.queryString(session, "SELECT pg_get_viewdef(" + getObjectId() + ", true)");
if (definition == null) {
throw new DBException("View '" + getName() + "' doesn't exist");
}
this.source = PostgreUtils.getViewDDL(monitor, this, definition);
String extDefinition = readExtraDefinition(session, options);
if (extDefinition != null) {
this.source += "\n" + extDefinition;
}
} catch (SQLException e) {
throw new DBException("Error reading view definition: " + e.getMessage(), e);
}
} else {
source = "";
}
}
List<DBEPersistAction> actions = new ArrayList<>();
if (CommonUtils.getOption(options, DBPScriptObject.OPTION_INCLUDE_COMMENTS)) {
if (getDescription() != null) {
actions.add(new SQLDatabasePersistAction("Comment", "COMMENT ON " + getViewType() + " " + getFullyQualifiedName(DBPEvaluationContext.DDL) + " IS " + SQLUtils.quoteString(this, getDescription())));
}
for (PostgreTableColumn column : CommonUtils.safeCollection(getAttributes(monitor))) {
if (!CommonUtils.isEmpty(column.getDescription())) {
PostgreTableColumnManager.addColumnCommentAction(actions, column);
}
}
}
if (isPersisted() && CommonUtils.getOption(options, DBPScriptObject.OPTION_INCLUDE_PERMISSIONS)) {
PostgreUtils.getObjectGrantPermissionActions(monitor, this, actions, options);
}
StringBuilder ddl = new StringBuilder(source);
if (!actions.isEmpty()) {
ddl.append("\n\n").append(SQLUtils.generateScript(getDataSource(), actions.toArray(new DBEPersistAction[0]), false));
}
return ddl.toString();
}
use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by dbeaver.
the class DBStructUtils method generateObjectDDL.
public static String generateObjectDDL(@NotNull DBRProgressMonitor monitor, @NotNull DBSObject object, Map<String, Object> options, boolean addComments) throws DBException {
final DBERegistry editorsRegistry = object.getDataSource().getContainer().getPlatform().getEditorsRegistry();
final SQLObjectEditor entityEditor = editorsRegistry.getObjectManager(object.getClass(), SQLObjectEditor.class);
if (entityEditor != null) {
SQLObjectEditor.ObjectCreateCommand createCommand = entityEditor.makeCreateCommand(object, options);
DBEPersistAction[] ddlActions = createCommand.getPersistActions(monitor, DBUtils.getDefaultContext(object, true), options);
return SQLUtils.generateScript(object.getDataSource(), ddlActions, addComments);
}
log.debug("Object editor not found for " + object.getClass().getName());
return SQLUtils.generateCommentLine(object.getDataSource(), "Can't generate DDL: object editor not found for " + object.getClass().getName());
}
use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by dbeaver.
the class NavigatorHandlerObjectBase method showScript.
protected static boolean showScript(IWorkbenchWindow workbenchWindow, DBECommandContext commandContext, Map<String, Object> options, String dialogTitle) {
Collection<? extends DBECommand> commands = commandContext.getFinalCommands();
StringBuilder script = new StringBuilder();
try {
UIUtils.runInProgressService(monitor -> {
try {
for (DBECommand command : commands) {
DBEPersistAction[] persistActions = command.getPersistActions(monitor, commandContext.getExecutionContext(), options);
script.append(SQLUtils.generateScript(commandContext.getExecutionContext().getDataSource(), persistActions, false));
if (script.length() == 0) {
script.append(SQLUtils.generateComments(commandContext.getExecutionContext().getDataSource(), persistActions, false));
}
}
} catch (DBException e) {
throw new InvocationTargetException(e);
}
});
} catch (InvocationTargetException e) {
DBWorkbench.getPlatformUI().showError("Script generation error", "Error generating alter script", e.getTargetException());
} catch (InterruptedException e) {
return false;
}
if (script.length() > 0) {
UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class);
if (serviceSQL != null) {
return serviceSQL.openSQLViewer(commandContext.getExecutionContext(), dialogTitle, UIIcon.SQL_PREVIEW, script.toString(), true, false) == IDialogConstants.PROCEED_ID;
}
} else {
return UIUtils.confirmAction(workbenchWindow.getShell(), dialogTitle, "No SQL script available.\nAre you sure you want to proceed?");
}
return false;
}
Aggregations