use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by dbeaver.
the class DB2SequenceManager method addObjectDeleteActions.
@Override
protected void addObjectDeleteActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, ObjectDeleteCommand command, Map<String, Object> options) {
String sql = String.format(SQL_DROP, 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 DB2AbstractDropOnlyManager method addObjectDeleteActions.
@Override
protected void addObjectDeleteActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, ObjectDeleteCommand command, Map<String, Object> options) {
DBEPersistAction action = new SQLDatabasePersistAction("Drop", buildDropStatement(command.getObject()));
actions.add(action);
}
use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by dbeaver.
the class SQLUtils method generateScript.
@NotNull
public static String generateScript(DBPDataSource dataSource, DBEPersistAction[] persistActions, boolean addComments) {
final SQLDialect sqlDialect = SQLUtils.getDialectFromDataSource(dataSource);
final String lineSeparator = GeneralUtils.getDefaultLineSeparator();
StringBuilder script = new StringBuilder(64);
if (addComments) {
script.append(DBEAVER_DDL_COMMENT).append(Platform.getProduct().getName()).append(lineSeparator).append(DBEAVER_DDL_WARNING).append(lineSeparator);
}
if (persistActions != null) {
String redefiner = sqlDialect.getScriptDelimiterRedefiner();
for (DBEPersistAction action : persistActions) {
String scriptLine = action.getScript();
if (CommonUtils.isEmpty(scriptLine)) {
continue;
}
String delimiter = getScriptLineDelimiter(sqlDialect);
if (action.isComplex() && redefiner != null) {
script.append(lineSeparator).append(redefiner).append(" ").append(DBEAVER_SCRIPT_DELIMITER).append(lineSeparator);
delimiter = DBEAVER_SCRIPT_DELIMITER;
script.append(delimiter).append(lineSeparator);
} else if (action.getType() == DBEPersistAction.ActionType.COMMENT) {
if (script.length() > 2) {
int lfCount = 0;
for (int i = script.length() - 1; i >= 0; i--) {
if (!Character.isWhitespace(script.charAt(i))) {
break;
}
if (script.charAt(i) == '\n')
lfCount++;
}
if (lfCount < 2) {
// Add line feed if we do not have empty line before
script.append(lineSeparator);
}
}
}
script.append(scriptLine);
if (action.getType() != DBEPersistAction.ActionType.COMMENT) {
String testLine = scriptLine.trim();
if (testLine.lastIndexOf(delimiter) != (testLine.length() - delimiter.length())) {
script.append(delimiter);
}
} else {
script.append(lineSeparator);
}
script.append(lineSeparator);
if (action.isComplex() && redefiner != null) {
script.append(redefiner).append(" ").append(getScriptLineDelimiter(sqlDialect)).append(lineSeparator);
}
}
}
return script.toString();
}
use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by dbeaver.
the class SQLUtils method generateComments.
@NotNull
public static String generateComments(DBPDataSource dataSource, DBEPersistAction[] persistActions, boolean addComments) {
final SQLDialect sqlDialect = SQLUtils.getDialectFromDataSource(dataSource);
final String lineSeparator = GeneralUtils.getDefaultLineSeparator();
StringBuilder script = new StringBuilder(64);
if (addComments) {
script.append(DBEAVER_DDL_COMMENT).append(Platform.getProduct().getName()).append(lineSeparator).append(DBEAVER_DDL_WARNING).append(lineSeparator);
}
if (persistActions != null) {
String slComment;
String[] slComments = sqlDialect.getSingleLineComments();
if (ArrayUtils.isEmpty(slComments)) {
slComment = "--";
} else {
slComment = slComments[0];
}
for (DBEPersistAction action : persistActions) {
if (action.getType() != DBEPersistAction.ActionType.COMMENT) {
String scriptLine = action.getTitle();
if (CommonUtils.isEmpty(scriptLine)) {
continue;
}
script.append(slComment).append(" ").append(scriptLine);
} else {
String scriptLine = action.getScript();
if (CommonUtils.isEmpty(scriptLine)) {
continue;
}
script.append(scriptLine);
}
script.append(lineSeparator);
}
}
return script.toString();
}
use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by dbeaver.
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());
}
Aggregations