use of org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction in project dbeaver by serge-rider.
the class MySQLTriggerManager method createOrReplaceTriggerQuery.
protected void createOrReplaceTriggerQuery(List<DBEPersistAction> actions, MySQLTrigger trigger) {
if (trigger.isPersisted()) {
actions.add(new SQLDatabasePersistAction("Drop trigger", "DROP TRIGGER IF EXISTS " + trigger.getFullyQualifiedName(DBPEvaluationContext.DDL)));
}
String ddl = "CREATE TRIGGER " + trigger.getFullyQualifiedName(DBPEvaluationContext.DDL) + "\n" + trigger.getActionTiming() + " " + trigger.getManipulationType() + "\n" + "ON " + trigger.getTable().getFullyQualifiedName(DBPEvaluationContext.DDL) + " FOR EACH ROW\n" + trigger.getBody();
//$NON-NLS-2$
actions.add(new SQLDatabasePersistAction("Create trigger", ddl, true));
}
use of org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction in project dbeaver by serge-rider.
the class ExasolTableColumnManager method addObjectRenameActions.
@Override
protected void addObjectRenameActions(List<DBEPersistAction> actions, ObjectRenameCommand command) {
final ExasolTableColumn column = command.getObject();
actions.add(new SQLDatabasePersistAction("Rename column", "ALTER TABLE " + column.getTable().getFullyQualifiedName(DBPEvaluationContext.DDL) + " RENAME COLUMN " + DBUtils.getQuotedIdentifier(column.getDataSource(), command.getOldName()) + " TO " + DBUtils.getQuotedIdentifier(column.getDataSource(), command.getNewName())));
}
use of org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction in project dbeaver by serge-rider.
the class ExasolTableManager method addObjectRenameActions.
// ------
// Rename
// ------
@Override
public void addObjectRenameActions(List<DBEPersistAction> actions, ObjectRenameCommand command) {
String sql = String.format(SQL_RENAME_TABLE, command.getObject().getFullyQualifiedName(DBPEvaluationContext.DDL), command.getNewName());
actions.add(new SQLDatabasePersistAction(CMD_RENAME, sql));
}
use of org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction in project dbeaver by serge-rider.
the class ExasolTableManager method addObjectModifyActions.
// ------
// Alter
// ------
@Override
public void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand command) {
ExasolTable exasolTable = command.getObject();
if (command.getProperties().size() > 1) {
StringBuilder sb = new StringBuilder(128);
sb.append(SQL_ALTER);
sb.append(exasolTable.getFullyQualifiedName(DBPEvaluationContext.DDL));
sb.append(" ");
appendTableModifiers(command.getObject(), command, sb);
actionList.add(new SQLDatabasePersistAction(CMD_ALTER, sb.toString()));
}
DBEPersistAction commentAction = buildCommentAction(exasolTable);
if (commentAction != null) {
actionList.add(commentAction);
}
}
use of org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction in project dbeaver by serge-rider.
the class SQLTableManager method addStructObjectCreateActions.
@Override
protected void addStructObjectCreateActions(List<DBEPersistAction> actions, StructCreateCommand command) {
final OBJECT_TYPE table = command.getObject();
final NestedObjectCommand tableProps = command.getObjectCommands().get(table);
if (tableProps == null) {
//$NON-NLS-1$
log.warn("Object change command not found");
return;
}
final String tableName = table.getFullyQualifiedName(DBPEvaluationContext.DDL);
final String lineSeparator = GeneralUtils.getDefaultLineSeparator();
StringBuilder createQuery = new StringBuilder(100);
//$NON-NLS-1$ //$NON-NLS-2$
createQuery.append("CREATE TABLE ").append(tableName).append(" (").append(lineSeparator);
boolean hasNestedDeclarations = false;
final Collection<NestedObjectCommand> orderedCommands = getNestedOrderedCommands(command);
for (NestedObjectCommand nestedCommand : orderedCommands) {
if (nestedCommand.getObject() == table) {
continue;
}
if (excludeFromDDL(nestedCommand, orderedCommands)) {
continue;
}
final String nestedDeclaration = nestedCommand.getNestedDeclaration(table);
if (!CommonUtils.isEmpty(nestedDeclaration)) {
// Insert nested declaration
if (hasNestedDeclarations) {
//$NON-NLS-1$
createQuery.append(",").append(lineSeparator);
}
//$NON-NLS-1$
createQuery.append("\t").append(nestedDeclaration);
hasNestedDeclarations = true;
} else {
// This command should be executed separately
final DBEPersistAction[] nestedActions = nestedCommand.getPersistActions();
if (nestedActions != null) {
Collections.addAll(actions, nestedActions);
}
}
}
//$NON-NLS-1$
createQuery.append(lineSeparator).append(")");
appendTableModifiers(table, tableProps, createQuery);
actions.add(0, new SQLDatabasePersistAction(ModelMessages.model_jdbc_create_new_table, createQuery.toString()));
}
Aggregations