use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by serge-rider.
the class ExasolTableColumnManager method addObjectModifyActions.
// -----
// Alter
// -----
@Override
protected void addObjectModifyActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actionList, ObjectChangeCommand command, Map<String, Object> options) {
ExasolTableColumn exasolColumn = command.getObject();
Map<Object, Object> props = command.getProperties();
if (props.containsKey("defaultValue") || props.containsKey("dataType") || props.containsKey("scale") || props.containsKey("maxLength") || props.containsKey("autoGenerated") || props.containsKey("identityValue") || props.containsKey("required")) {
// build nullability string
String nullability = "";
if (exasolColumn.isOriRequired() != null && exasolColumn.isOriRequired() != exasolColumn.isRequired())
nullability = exasolColumn.isRequired() ? "NOT NULL" : "NULL";
final String deltaSQL = DBUtils.getQuotedIdentifier(exasolColumn) + " " + exasolColumn.getFormatType() + " " + (exasolColumn.getDefaultValue() == null ? "" : " DEFAULT " + exasolColumn.getDefaultValue()) + " " + formatIdentiy(exasolColumn.isAutoGenerated(), exasolColumn.getIdentityValue()) + " " + nullability;
if (!deltaSQL.isEmpty()) {
String sqlAlterColumn = String.format(SQL_ALTER, exasolColumn.getTable().getFullyQualifiedName(DBPEvaluationContext.DDL), deltaSQL);
actionList.add(new SQLDatabasePersistAction(CMD_ALTER, sqlAlterColumn));
}
}
// Comment
DBEPersistAction commentAction = buildCommentAction(exasolColumn);
if (commentAction != null) {
actionList.add(commentAction);
}
if (command.getProperties().containsKey("distKey")) {
try {
actionList.addAll(modifyDistKey(monitor, exasolColumn));
} catch (DBException e) {
log.error("Failed to modify distkey settings", e);
}
}
}
use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by serge-rider.
the class ExasolTableManager method addObjectModifyActions.
// ------
// Alter
// ------
@Override
public void addObjectModifyActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actionList, ObjectChangeCommand command, Map<String, Object> options) {
ExasolTable exasolTable = command.getObject();
if (command.getProperties().size() > 0) {
if (command.getProperties().containsKey("hasPartitionKey") && ((command.getProperties().get("hasPartitionKey").toString()).equals("false"))) {
actionList.add(new SQLDatabasePersistAction("ALTER TABLE " + exasolTable.getFullyQualifiedName(DBPEvaluationContext.DDL) + " DROP PARTITION KEYS"));
} else if (command.getProperties().size() > 1) {
StringBuilder sb = new StringBuilder(128);
sb.append(SQL_ALTER);
sb.append(exasolTable.getFullyQualifiedName(DBPEvaluationContext.DDL));
sb.append(" ");
appendTableModifiers(monitor, command.getObject(), command, sb, true);
actionList.add(new SQLDatabasePersistAction(CMD_ALTER, sb.toString()));
}
}
DBEPersistAction commentAction = buildCommentAction(exasolTable);
if (commentAction != null) {
actionList.add(commentAction);
}
}
use of org.jkiss.dbeaver.model.edit.DBEPersistAction in project dbeaver by serge-rider.
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 serge-rider.
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 serge-rider.
the class DB2SchemaManager method addObjectDeleteActions.
@Override
protected void addObjectDeleteActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, ObjectDeleteCommand command, Map<String, Object> options) {
String schemaName = command.getObject().getName();
DBEPersistAction action = new SQLDatabasePersistAction("Drop schema (SQL)", String.format(SQL_DROP_SCHEMA, DBUtils.getQuotedIdentifier(command.getObject())));
actions.add(action);
}
Aggregations