提交 70d85741 编写于 作者: S Serge Rider

Object manager model refactoring (create/alter command)


Former-commit-id: 0a228919
上级 814999eb
......@@ -70,9 +70,8 @@ public abstract class DB2AbstractDropOnlyManager<OBJECT_TYPE extends DBSObject &
}
@Override
protected DBEPersistAction[] makeObjectCreateActions(ObjectCreateCommand command)
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand command)
{
return null;
}
}
......@@ -125,7 +125,7 @@ public class DB2ForeignKeyManager extends SQLForeignKeyManager<DB2TableForeignKe
// ------
@Override
protected DBEPersistAction[] makeObjectModifyActions(ObjectChangeCommand command)
protected void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand command)
{
// DF: Throw exception for now
// Will have to implement it for alter FK query optimisation + TRUST
......
......@@ -81,11 +81,11 @@ public class DB2SchemaManager extends SQLObjectEditor<DB2Schema, DB2DataSource>
}
@Override
protected DBEPersistAction[] makeObjectCreateActions(ObjectCreateCommand command)
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand command)
{
SQLDatabasePersistAction action = new SQLDatabasePersistAction("Create schema", String.format(SQL_CREATE_SCHEMA,
DBUtils.getQuotedIdentifier(command.getObject())));
return new DBEPersistAction[] { action };
actions.add(action);
}
@Override
......
......@@ -22,11 +22,11 @@ import org.eclipse.jface.dialogs.IDialogConstants;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.model.edit.DBEPersistAction;
import org.jkiss.dbeaver.ext.db2.DB2Messages;
import org.jkiss.dbeaver.ext.db2.model.DB2Schema;
import org.jkiss.dbeaver.ext.db2.model.DB2Sequence;
import org.jkiss.dbeaver.model.edit.DBECommandContext;
import org.jkiss.dbeaver.model.edit.DBEPersistAction;
import org.jkiss.dbeaver.model.impl.DBSObjectCache;
import org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction;
import org.jkiss.dbeaver.model.impl.sql.edit.SQLObjectEditor;
......@@ -34,7 +34,6 @@ import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.ui.dialogs.struct.CreateEntityDialog;
import org.jkiss.utils.CommonUtils;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -88,35 +87,27 @@ public class DB2SequenceManager extends SQLObjectEditor<DB2Sequence, DB2Schema>
}
@Override
protected DBEPersistAction[] makeObjectCreateActions(ObjectCreateCommand command)
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand command)
{
List<DBEPersistAction> listeCommands = new ArrayList<>(2);
String sql = buildStatement(command.getObject(), false);
listeCommands.add(new SQLDatabasePersistAction("Create Sequence", sql));
actions.add(new SQLDatabasePersistAction("Create Sequence", sql));
String comment = buildComment(command.getObject());
if (comment != null) {
listeCommands.add(new SQLDatabasePersistAction("Comment on Sequence", comment));
actions.add(new SQLDatabasePersistAction("Comment on Sequence", comment));
}
return listeCommands.toArray(new DBEPersistAction[listeCommands.size()]);
}
@Override
protected DBEPersistAction[] makeObjectModifyActions(ObjectChangeCommand command)
protected void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand command)
{
List<DBEPersistAction> listeActions = new ArrayList<>(2);
String sql = buildStatement(command.getObject(), true);
listeActions.add(new SQLDatabasePersistAction("Alter Sequence", sql));
actionList.add(new SQLDatabasePersistAction("Alter Sequence", sql));
String comment = buildComment(command.getObject());
if (comment != null) {
listeActions.add(new SQLDatabasePersistAction("Comment on Sequence", comment));
actionList.add(new SQLDatabasePersistAction("Comment on Sequence", comment));
}
return listeActions.toArray(new DBEPersistAction[listeActions.size()]);
}
@Override
......
......@@ -20,13 +20,13 @@ package org.jkiss.dbeaver.ext.db2.manager;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.edit.DBEObjectRenamer;
import org.jkiss.dbeaver.model.edit.DBEPersistAction;
import org.jkiss.dbeaver.ext.db2.model.DB2Table;
import org.jkiss.dbeaver.ext.db2.model.DB2TableBase;
import org.jkiss.dbeaver.ext.db2.model.DB2TableColumn;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.edit.DBECommandContext;
import org.jkiss.dbeaver.model.edit.DBEObjectRenamer;
import org.jkiss.dbeaver.model.edit.DBEPersistAction;
import org.jkiss.dbeaver.model.impl.DBSObjectCache;
import org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction;
import org.jkiss.dbeaver.model.impl.sql.edit.struct.SQLTableColumnManager;
......@@ -34,7 +34,6 @@ import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.utils.CommonUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
......@@ -98,34 +97,30 @@ public class DB2TableColumnManager extends SQLTableColumnManager<DB2TableColumn,
// Alter
// -----
@Override
protected DBEPersistAction[] makeObjectModifyActions(ObjectChangeCommand command)
protected void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand command)
{
DB2TableColumn db2Column = command.getObject();
List<DBEPersistAction> actions = new ArrayList<>(3);
boolean hasColumnChanges = false;
if (!command.getProperties().isEmpty()) {
final String deltaSQL = computeDeltaSQL(command);
if (!deltaSQL.isEmpty()) {
hasColumnChanges = true;
String sqlAlterColumn = String.format(SQL_ALTER, db2Column.getTable().getFullQualifiedName(), deltaSQL);
actions.add(new SQLDatabasePersistAction(CMD_ALTER, sqlAlterColumn));
actionList.add(new SQLDatabasePersistAction(CMD_ALTER, sqlAlterColumn));
}
}
// Comment
DBEPersistAction commentAction = buildCommentAction(db2Column);
if (commentAction != null) {
actions.add(commentAction);
actionList.add(commentAction);
}
if (hasColumnChanges) {
// Be Safe, Add a reorg action
actions.add(buildReorgAction(db2Column));
actionList.add(buildReorgAction(db2Column));
}
return actions.toArray(new DBEPersistAction[actions.size()]);
}
// -------
......
......@@ -20,16 +20,10 @@ package org.jkiss.dbeaver.ext.db2.manager;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.edit.DBEPersistAction;
import org.jkiss.dbeaver.ext.db2.model.DB2Index;
import org.jkiss.dbeaver.ext.db2.model.DB2Schema;
import org.jkiss.dbeaver.ext.db2.model.DB2Table;
import org.jkiss.dbeaver.ext.db2.model.DB2TableColumn;
import org.jkiss.dbeaver.ext.db2.model.DB2TableForeignKey;
import org.jkiss.dbeaver.ext.db2.model.DB2TableUniqueKey;
import org.jkiss.dbeaver.ext.db2.model.DB2Tablespace;
import org.jkiss.dbeaver.ext.db2.model.*;
import org.jkiss.dbeaver.model.edit.DBECommandContext;
import org.jkiss.dbeaver.model.edit.DBEObjectRenamer;
import org.jkiss.dbeaver.model.edit.DBEPersistAction;
import org.jkiss.dbeaver.model.impl.DBSObjectCache;
import org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction;
import org.jkiss.dbeaver.model.impl.sql.edit.struct.SQLTableManager;
......@@ -37,8 +31,6 @@ import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.utils.CommonUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
......@@ -142,17 +134,13 @@ public class DB2TableManager extends SQLTableManager<DB2Table, DB2Schema> implem
}
@Override
public DBEPersistAction[] makeStructObjectCreateActions(StructCreateCommand command)
public void addStructObjectCreateActions(List<DBEPersistAction> actions, StructCreateCommand command)
{
super.addStructObjectCreateActions(actions, command);
// Eventually add Comment
DBEPersistAction commentAction = buildCommentAction(command.getObject());
if (commentAction == null) {
return super.makeStructObjectCreateActions(command);
} else {
List<DBEPersistAction> actionList = new ArrayList<>(Arrays.asList(super
.makeStructObjectCreateActions(command)));
actionList.add(commentAction);
return actionList.toArray(new DBEPersistAction[actionList.size()]);
if (commentAction != null) {
actions.add(commentAction);
}
}
......@@ -161,12 +149,10 @@ public class DB2TableManager extends SQLTableManager<DB2Table, DB2Schema> implem
// ------
@Override
public DBEPersistAction[] makeObjectModifyActions(ObjectChangeCommand command)
public void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand command)
{
DB2Table db2Table = command.getObject();
List<DBEPersistAction> actions = new ArrayList<>(2);
if (command.getProperties().size() > 1) {
StringBuilder sb = new StringBuilder(128);
sb.append(SQL_ALTER);
......@@ -175,15 +161,13 @@ public class DB2TableManager extends SQLTableManager<DB2Table, DB2Schema> implem
appendTableModifiers(command.getObject(), command, sb);
actions.add(new SQLDatabasePersistAction(CMD_ALTER, sb.toString()));
actionList.add(new SQLDatabasePersistAction(CMD_ALTER, sb.toString()));
}
DBEPersistAction commentAction = buildCommentAction(db2Table);
if (commentAction != null) {
actions.add(commentAction);
actionList.add(commentAction);
}
return actions.toArray(new DBEPersistAction[actions.size()]);
}
// ------
......
......@@ -68,7 +68,7 @@ public class MySQLCatalogManager extends SQLObjectEditor<MySQLCatalog, MySQLData
}
@Override
protected DBEPersistAction[] makeObjectCreateActions(ObjectCreateCommand command)
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand command)
{
final MySQLCatalog catalog = command.getObject();
final StringBuilder script = new StringBuilder("CREATE SCHEMA `" + catalog.getName() + "`");
......@@ -78,9 +78,9 @@ public class MySQLCatalogManager extends SQLObjectEditor<MySQLCatalog, MySQLData
if (catalog.getDefaultCollation() != null) {
script.append("\nDEFAULT COLLATE ").append(catalog.getDefaultCollation().getName());
}
return new DBEPersistAction[] {
actions.add(
new SQLDatabasePersistAction("Create schema", script.toString()) //$NON-NLS-2$
};
);
}
@Override
......
......@@ -78,15 +78,15 @@ public class MySQLProcedureManager extends SQLObjectEditor<MySQLProcedure, MySQL
}
@Override
protected DBEPersistAction[] makeObjectCreateActions(ObjectCreateCommand command)
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand command)
{
return createOrReplaceProcedureQuery(command.getObject());
createOrReplaceProcedureQuery(actions, command.getObject());
}
@Override
protected DBEPersistAction[] makeObjectModifyActions(ObjectChangeCommand command)
protected void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand command)
{
return createOrReplaceProcedureQuery(command.getObject());
createOrReplaceProcedureQuery(actionList, command.getObject());
}
@Override
......@@ -97,12 +97,12 @@ public class MySQLProcedureManager extends SQLObjectEditor<MySQLProcedure, MySQL
);
}
private DBEPersistAction[] createOrReplaceProcedureQuery(MySQLProcedure procedure)
private void createOrReplaceProcedureQuery(List<DBEPersistAction> actions, MySQLProcedure procedure)
{
return new DBEPersistAction[] {
new SQLDatabasePersistAction("Drop procedure", "DROP " + procedure.getProcedureType() + " IF EXISTS " + procedure.getFullQualifiedName()), //$NON-NLS-2$ //$NON-NLS-3$
new SQLDatabasePersistAction("Create procedure", procedure.getDeclaration()) //$NON-NLS-2$
};
actions.add(
new SQLDatabasePersistAction("Drop procedure", "DROP " + procedure.getProcedureType() + " IF EXISTS " + procedure.getFullQualifiedName())); //$NON-NLS-2$ //$NON-NLS-3$
actions.add(
new SQLDatabasePersistAction("Create procedure", procedure.getDeclaration()));
}
}
......
......@@ -105,14 +105,14 @@ public class MySQLTableColumnManager extends SQLTableColumnManager<MySQLTableCol
}
@Override
protected DBEPersistAction[] makeObjectModifyActions(ObjectChangeCommand command)
protected void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand command)
{
final MySQLTableColumn column = command.getObject();
return new DBEPersistAction[] {
actionList.add(
new SQLDatabasePersistAction(
"Modify column",
"ALTER TABLE " + column.getTable().getFullQualifiedName() + " MODIFY COLUMN " + getNestedDeclaration(column.getTable(), command))}; //$NON-NLS-1$ //$NON-NLS-2$
"ALTER TABLE " + column.getTable().getFullQualifiedName() + " MODIFY COLUMN " + getNestedDeclaration(column.getTable(), command))); //$NON-NLS-1$ //$NON-NLS-2$
}
@Override
......
......@@ -73,15 +73,15 @@ public class MySQLTableManager extends SQLTableManager<MySQLTableBase, MySQLCata
}
@Override
protected DBEPersistAction[] makeObjectModifyActions(ObjectChangeCommand command)
protected void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand command)
{
StringBuilder query = new StringBuilder("ALTER TABLE "); //$NON-NLS-1$
query.append(command.getObject().getFullQualifiedName()).append(" "); //$NON-NLS-1$
appendTableModifiers(command.getObject(), command, query);
return new DBEPersistAction[] {
actionList.add(
new SQLDatabasePersistAction(query.toString())
};
);
}
@Override
......
......@@ -73,15 +73,15 @@ public class MySQLViewManager extends SQLObjectEditor<MySQLTableBase, MySQLCatal
}
@Override
protected DBEPersistAction[] makeObjectCreateActions(ObjectCreateCommand command)
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand command)
{
return createOrReplaceViewQuery((MySQLView) command.getObject());
createOrReplaceViewQuery(actions, (MySQLView) command.getObject());
}
@Override
protected DBEPersistAction[] makeObjectModifyActions(ObjectChangeCommand command)
protected void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand command)
{
return createOrReplaceViewQuery((MySQLView) command.getObject());
createOrReplaceViewQuery(actionList, (MySQLView) command.getObject());
}
@Override
......@@ -92,7 +92,7 @@ public class MySQLViewManager extends SQLObjectEditor<MySQLTableBase, MySQLCatal
);
}
private DBEPersistAction[] createOrReplaceViewQuery(MySQLView view)
private void createOrReplaceViewQuery(List<DBEPersistAction> actions, MySQLView view)
{
StringBuilder decl = new StringBuilder(200);
final String lineSeparator = GeneralUtils.getDefaultLineSeparator();
......@@ -102,9 +102,7 @@ public class MySQLViewManager extends SQLObjectEditor<MySQLTableBase, MySQLCatal
if (checkOption != null && checkOption != MySQLView.CheckOption.NONE) {
decl.append(lineSeparator).append("WITH ").append(checkOption.getDefinitionName()).append(" CHECK OPTION"); //$NON-NLS-1$ //$NON-NLS-2$
}
return new DBEPersistAction[] {
new SQLDatabasePersistAction("Create view", decl.toString())
};
actions.add(new SQLDatabasePersistAction("Create view", decl.toString()));
}
/*
......
......@@ -21,12 +21,12 @@ package org.jkiss.dbeaver.ext.oracle.edit;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.model.edit.DBEPersistAction;
import org.jkiss.dbeaver.ext.oracle.OracleMessages;
import org.jkiss.dbeaver.ext.oracle.model.OracleDataType;
import org.jkiss.dbeaver.ext.oracle.model.OracleSchema;
import org.jkiss.dbeaver.ext.oracle.model.OracleUtils;
import org.jkiss.dbeaver.model.edit.DBECommandContext;
import org.jkiss.dbeaver.model.edit.DBEPersistAction;
import org.jkiss.dbeaver.model.impl.DBSObjectCache;
import org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction;
import org.jkiss.dbeaver.model.impl.sql.edit.SQLObjectEditor;
......@@ -34,7 +34,6 @@ import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.ui.dialogs.struct.CreateEntityDialog;
import org.jkiss.utils.CommonUtils;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -67,9 +66,9 @@ public class OracleDataTypeManager extends SQLObjectEditor<OracleDataType, Oracl
}
@Override
protected DBEPersistAction[] makeObjectCreateActions(ObjectCreateCommand objectCreateCommand)
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand objectCreateCommand)
{
return createOrReplaceProcedureQuery(objectCreateCommand.getObject());
createOrReplaceProcedureQuery(actions, objectCreateCommand.getObject());
}
@Override
......@@ -83,9 +82,9 @@ public class OracleDataTypeManager extends SQLObjectEditor<OracleDataType, Oracl
}
@Override
protected DBEPersistAction[] makeObjectModifyActions(ObjectChangeCommand objectChangeCommand)
protected void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand objectChangeCommand)
{
return createOrReplaceProcedureQuery(objectChangeCommand.getObject());
createOrReplaceProcedureQuery(actionList, objectChangeCommand.getObject());
}
@Override
......@@ -94,25 +93,23 @@ public class OracleDataTypeManager extends SQLObjectEditor<OracleDataType, Oracl
return FEATURE_EDITOR_ON_CREATE;
}
private DBEPersistAction[] createOrReplaceProcedureQuery(OracleDataType dataType)
private void createOrReplaceProcedureQuery(List<DBEPersistAction> actionList, OracleDataType dataType)
{
List<DBEPersistAction> actions = new ArrayList<>();
String header = OracleUtils.normalizeSourceName(dataType, false);
if (!CommonUtils.isEmpty(header)) {
actions.add(
actionList.add(
new SQLDatabasePersistAction(
"Create type header",
"CREATE OR REPLACE " + header)); //$NON-NLS-1$
}
String body = OracleUtils.normalizeSourceName(dataType, true);
if (!CommonUtils.isEmpty(body)) {
actions.add(
actionList.add(
new SQLDatabasePersistAction(
"Create type body",
"CREATE OR REPLACE " + body)); //$NON-NLS-1$
}
OracleUtils.addSchemaChangeActions(actions, dataType);
return actions.toArray(new DBEPersistAction[actions.size()]);
OracleUtils.addSchemaChangeActions(actionList, dataType);
}
}
......
......@@ -71,15 +71,15 @@ public class OracleMaterializedViewManager extends SQLObjectEditor<OracleMateria
}
@Override
protected DBEPersistAction[] makeObjectCreateActions(ObjectCreateCommand command)
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand command)
{
return createOrReplaceViewQuery(command.getObject());
createOrReplaceViewQuery(actions, command.getObject());
}
@Override
protected DBEPersistAction[] makeObjectModifyActions(ObjectChangeCommand command)
protected void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand command)
{
return createOrReplaceViewQuery(command.getObject());
createOrReplaceViewQuery(actionList, command.getObject());
}
@Override
......@@ -90,16 +90,16 @@ public class OracleMaterializedViewManager extends SQLObjectEditor<OracleMateria
);
}
private DBEPersistAction[] createOrReplaceViewQuery(OracleMaterializedView view)
private void createOrReplaceViewQuery(List<DBEPersistAction> actions, OracleMaterializedView view)
{
StringBuilder decl = new StringBuilder(200);
final String lineSeparator = GeneralUtils.getDefaultLineSeparator();
decl.append("CREATE MATERIALIZED VIEW ").append(view.getFullQualifiedName()).append(lineSeparator) //$NON-NLS-1$
.append("AS ").append(view.getObjectDefinitionText(null)); //$NON-NLS-1$
return new DBEPersistAction[] {
new SQLDatabasePersistAction("Drop view", "DROP MATERIALIZED VIEW " + view.getFullQualifiedName()), //$NON-NLS-2$
new SQLDatabasePersistAction("Create view", decl.toString())
};
actions.add(
new SQLDatabasePersistAction("Drop view", "DROP MATERIALIZED VIEW " + view.getFullQualifiedName())); //$NON-NLS-2$
actions.add(
new SQLDatabasePersistAction("Create view", decl.toString()));
}
}
......
......@@ -22,12 +22,12 @@ import org.eclipse.jface.dialogs.IDialogConstants;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.model.edit.DBEPersistAction;
import org.jkiss.dbeaver.ext.oracle.OracleMessages;
import org.jkiss.dbeaver.ext.oracle.model.OraclePackage;
import org.jkiss.dbeaver.ext.oracle.model.OracleSchema;
import org.jkiss.dbeaver.ext.oracle.model.OracleUtils;
import org.jkiss.dbeaver.model.edit.DBECommandContext;
import org.jkiss.dbeaver.model.edit.DBEPersistAction;
import org.jkiss.dbeaver.model.impl.DBSObjectCache;
import org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction;
import org.jkiss.dbeaver.model.impl.sql.edit.SQLObjectEditor;
......@@ -36,7 +36,6 @@ import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.ui.dialogs.struct.CreateEntityDialog;
import org.jkiss.utils.CommonUtils;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -64,9 +63,9 @@ public class OraclePackageManager extends SQLObjectEditor<OraclePackage, OracleS
}
@Override
protected DBEPersistAction[] makeObjectCreateActions(ObjectCreateCommand objectCreateCommand)
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand objectCreateCommand)
{
return createOrReplaceProcedureQuery(objectCreateCommand.getObject());
createOrReplaceProcedureQuery(actions, objectCreateCommand.getObject());
}
@Override
......@@ -80,9 +79,9 @@ public class OraclePackageManager extends SQLObjectEditor<OraclePackage, OracleS
}
@Override
protected DBEPersistAction[] makeObjectModifyActions(ObjectChangeCommand objectChangeCommand)
protected void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand objectChangeCommand)
{
return createOrReplaceProcedureQuery(objectChangeCommand.getObject());
createOrReplaceProcedureQuery(actionList, objectChangeCommand.getObject());
}
@Override
......@@ -91,25 +90,24 @@ public class OraclePackageManager extends SQLObjectEditor<OraclePackage, OracleS
return FEATURE_EDITOR_ON_CREATE;
}
private DBEPersistAction[] createOrReplaceProcedureQuery(OraclePackage pack)
private void createOrReplaceProcedureQuery(List<DBEPersistAction> actionList, OraclePackage pack)
{
List<DBEPersistAction> actions = new ArrayList<>();
try {
String header = pack.getObjectDefinitionText(VoidProgressMonitor.INSTANCE);
if (!CommonUtils.isEmpty(header)) {
actions.add(
actionList.add(
new SQLDatabasePersistAction(
"Create package header",
header)); //$NON-NLS-1$
}
String body = pack.getObjectBodyDefinitionText(VoidProgressMonitor.INSTANCE);
if (!CommonUtils.isEmpty(body)) {
actions.add(
actionList.add(
new SQLDatabasePersistAction(
"Create package body",
body)); //$NON-NLS-1$
} else {
actions.add(
actionList.add(
new SQLDatabasePersistAction(
"Drop package header",
"DROP PACKAGE BODY " + pack.getFullQualifiedName(), DBEPersistAction.ActionType.OPTIONAL) //$NON-NLS-1$
......@@ -118,8 +116,7 @@ public class OraclePackageManager extends SQLObjectEditor<OraclePackage, OracleS
} catch (DBException e) {
log.warn(e);
}
OracleUtils.addSchemaChangeActions(actions, pack);
return actions.toArray(new DBEPersistAction[actions.size()]);
OracleUtils.addSchemaChangeActions(actionList, pack);
}
}
......
......@@ -21,18 +21,17 @@ package org.jkiss.dbeaver.ext.oracle.edit;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.model.edit.DBEPersistAction;
import org.jkiss.dbeaver.ext.oracle.model.OracleProcedureStandalone;
import org.jkiss.dbeaver.ext.oracle.model.OracleSchema;
import org.jkiss.dbeaver.ext.oracle.model.OracleUtils;
import org.jkiss.dbeaver.model.edit.DBECommandContext;
import org.jkiss.dbeaver.model.edit.DBEPersistAction;
import org.jkiss.dbeaver.model.impl.DBSObjectCache;
import org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction;
import org.jkiss.dbeaver.model.impl.sql.edit.SQLObjectEditor;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.ui.dialogs.struct.CreateProcedureDialog;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -61,9 +60,9 @@ public class OracleProcedureManager extends SQLObjectEditor<OracleProcedureStand
}
@Override
protected DBEPersistAction[] makeObjectCreateActions(ObjectCreateCommand objectCreateCommand)
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand objectCreateCommand)
{
return createOrReplaceProcedureQuery(objectCreateCommand.getObject());
createOrReplaceProcedureQuery(actions, objectCreateCommand.getObject());
}
@Override
......@@ -77,9 +76,9 @@ public class OracleProcedureManager extends SQLObjectEditor<OracleProcedureStand
}
@Override
protected DBEPersistAction[] makeObjectModifyActions(ObjectChangeCommand objectChangeCommand)
protected void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand objectChangeCommand)
{
return createOrReplaceProcedureQuery(objectChangeCommand.getObject());
createOrReplaceProcedureQuery(actionList, objectChangeCommand.getObject());
}
@Override
......@@ -88,16 +87,14 @@ public class OracleProcedureManager extends SQLObjectEditor<OracleProcedureStand
return FEATURE_EDITOR_ON_CREATE;
}
private DBEPersistAction[] createOrReplaceProcedureQuery(OracleProcedureStandalone procedure)
private void createOrReplaceProcedureQuery(List<DBEPersistAction> actionList, OracleProcedureStandalone procedure)
{
String source = OracleUtils.normalizeSourceName(procedure, false);
if (source == null) {
return null;
return;
}
List<DBEPersistAction> actions = new ArrayList<>();
actions.add(new SQLDatabasePersistAction("Create procedure", source)); //$NON-NLS-2$
OracleUtils.addSchemaChangeActions(actions, procedure);
return actions.toArray(new DBEPersistAction[actions.size()]);
actionList.add(new SQLDatabasePersistAction("Create procedure", source)); //$NON-NLS-2$
OracleUtils.addSchemaChangeActions(actionList, procedure);
}
}
......@@ -77,13 +77,13 @@ public class OracleSchemaManager extends SQLObjectEditor<OracleSchema, OracleDat
}
@Override
protected DBEPersistAction[] makeObjectCreateActions(ObjectCreateCommand command)
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand command)
{
OracleUser user = command.getObject().getUser();
return new DBEPersistAction[] {
actions.add(
new SQLDatabasePersistAction("Create schema",
"CREATE USER " + DBUtils.getQuotedIdentifier(user) + " IDENTIFIED BY \"" + user.getPassword() + "\"")
};
);
}
@Override
......
......@@ -36,7 +36,6 @@ import org.jkiss.dbeaver.model.struct.DBSDataType;
import org.jkiss.dbeaver.model.struct.DBSObject;
import java.sql.Types;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -72,24 +71,22 @@ public class OracleTableColumnManager extends SQLTableColumnManager<OracleTableC
}
@Override
protected DBEPersistAction[] makeObjectModifyActions(ObjectChangeCommand command)
protected void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand command)
{
final OracleTableColumn column = command.getObject();
List<DBEPersistAction> actions = new ArrayList<>(2);
boolean hasComment = command.getProperty("comment") != null;
if (!hasComment || command.getProperties().size() > 1) {
actions.add(new SQLDatabasePersistAction(
actionList.add(new SQLDatabasePersistAction(
"Modify column",
"ALTER TABLE " + column.getTable().getFullQualifiedName() + //$NON-NLS-1$
" MODIFY " + getNestedDeclaration(column.getTable(), command))); //$NON-NLS-1$
}
if (hasComment) {
actions.add(new SQLDatabasePersistAction(
actionList.add(new SQLDatabasePersistAction(
"Comment column",
"COMMENT ON COLUMN " + column.getTable().getFullQualifiedName() + "." + DBUtils.getQuotedIdentifier(column) +
" IS '" + column.getComment(VoidProgressMonitor.INSTANCE) + "'"));
}
return actions.toArray(new DBEPersistAction[actions.size()]);
}
@Override
......
......@@ -20,18 +20,17 @@ package org.jkiss.dbeaver.ext.oracle.edit;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.edit.DBEPersistAction;
import org.jkiss.dbeaver.ext.oracle.model.*;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.edit.DBECommandContext;
import org.jkiss.dbeaver.model.edit.DBEObjectRenamer;
import org.jkiss.dbeaver.model.edit.DBEPersistAction;
import org.jkiss.dbeaver.model.impl.DBSObjectCache;
import org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction;
import org.jkiss.dbeaver.model.impl.sql.edit.struct.SQLTableManager;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.model.struct.DBSObject;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -66,18 +65,15 @@ public class OracleTableManager extends SQLTableManager<OracleTable, OracleSchem
}
@Override
protected DBEPersistAction[] makeObjectModifyActions(ObjectChangeCommand command)
protected void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand command)
{
List<DBEPersistAction> actions = new ArrayList<>(2);
if (command.getProperties().size() > 1 || command.getProperty("comment") == null) {
StringBuilder query = new StringBuilder("ALTER TABLE "); //$NON-NLS-1$
query.append(command.getObject().getFullQualifiedName()).append(" "); //$NON-NLS-1$
appendTableModifiers(command.getObject(), command, query);
actions.add(new SQLDatabasePersistAction(query.toString()));
actionList.add(new SQLDatabasePersistAction(query.toString()));
}
addObjectExtraActions(actions, command);
return actions.toArray(new DBEPersistAction[actions.size()]);
addObjectExtraActions(actionList, command);
}
@Override
......
......@@ -22,12 +22,12 @@ import org.eclipse.jface.dialogs.IDialogConstants;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.model.edit.DBEPersistAction;
import org.jkiss.dbeaver.ext.oracle.OracleMessages;
import org.jkiss.dbeaver.ext.oracle.model.OracleTableBase;
import org.jkiss.dbeaver.ext.oracle.model.OracleTrigger;
import org.jkiss.dbeaver.ext.oracle.model.OracleUtils;
import org.jkiss.dbeaver.model.edit.DBECommandContext;
import org.jkiss.dbeaver.model.edit.DBEPersistAction;
import org.jkiss.dbeaver.model.impl.DBSObjectCache;
import org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction;
import org.jkiss.dbeaver.model.impl.sql.edit.SQLObjectEditor;
......@@ -35,7 +35,6 @@ import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.ui.dialogs.struct.CreateEntityDialog;
import org.jkiss.utils.CommonUtils;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -80,15 +79,15 @@ public class OracleTriggerManager extends SQLObjectEditor<OracleTrigger, OracleT
}
@Override
protected DBEPersistAction[] makeObjectCreateActions(ObjectCreateCommand command)
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand command)
{
return createOrReplaceViewQuery(command.getObject());
createOrReplaceViewQuery(actions, command.getObject());
}
@Override
protected DBEPersistAction[] makeObjectModifyActions(ObjectChangeCommand command)
protected void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand command)
{
return createOrReplaceViewQuery(command.getObject());
createOrReplaceViewQuery(actionList, command.getObject());
}
@Override
......@@ -99,16 +98,14 @@ public class OracleTriggerManager extends SQLObjectEditor<OracleTrigger, OracleT
);
}
private DBEPersistAction[] createOrReplaceViewQuery(OracleTrigger trigger)
private void createOrReplaceViewQuery(List<DBEPersistAction> actions, OracleTrigger trigger)
{
String source = OracleUtils.normalizeSourceName(trigger, false);
if (source == null) {
return null;
return;
}
List<DBEPersistAction> actions = new ArrayList<>();
actions.add(new SQLDatabasePersistAction("Create trigger", "CREATE OR REPLACE " + source)); //$NON-NLS-2$
OracleUtils.addSchemaChangeActions(actions, trigger);
return actions.toArray(new DBEPersistAction[actions.size()]);
}
}
......
......@@ -73,15 +73,15 @@ public class OracleViewManager extends SQLObjectEditor<OracleView, OracleSchema>
}
@Override
protected DBEPersistAction[] makeObjectCreateActions(ObjectCreateCommand command)
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand command)
{
return createOrReplaceViewQuery(command);
createOrReplaceViewQuery(actions, command);
}
@Override
protected DBEPersistAction[] makeObjectModifyActions(ObjectChangeCommand command)
protected void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand command)
{
return createOrReplaceViewQuery(command);
createOrReplaceViewQuery(actionList, command);
}
@Override
......@@ -92,11 +92,10 @@ public class OracleViewManager extends SQLObjectEditor<OracleView, OracleSchema>
);
}
private DBEPersistAction[] createOrReplaceViewQuery(DBECommandComposite<OracleView, PropertyHandler> command)
private void createOrReplaceViewQuery(List<DBEPersistAction> actions, DBECommandComposite<OracleView, PropertyHandler> command)
{
final OracleView view = command.getObject();
boolean hasComment = command.getProperty("comment") != null;
List<DBEPersistAction> actions = new ArrayList<>(2);
if (!hasComment || command.getProperties().size() > 1) {
StringBuilder decl = new StringBuilder(200);
final String lineSeparator = GeneralUtils.getDefaultLineSeparator();
......@@ -110,7 +109,6 @@ public class OracleViewManager extends SQLObjectEditor<OracleView, OracleSchema>
"COMMENT ON TABLE " + view.getFullQualifiedName() +
" IS '" + view.getComment() + "'"));
}
return actions.toArray(new DBEPersistAction[actions.size()]);
}
}
......
......@@ -63,20 +63,19 @@ public class PostgreDatabaseManager extends SQLObjectEditor<PostgreDatabase, Pos
}
@Override
protected DBEPersistAction[] makeObjectCreateActions(ObjectCreateCommand command)
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand command)
{
final PostgreDatabase database = command.getObject();
final StringBuilder script = new StringBuilder("CREATE DATABASE " + DBUtils.getQuotedIdentifier(database));
return new DBEPersistAction[] {
new SQLDatabasePersistAction("Create database", script.toString()) //$NON-NLS-2$
};
actions.add(
new SQLDatabasePersistAction("Create database", "CREATE DATABASE " + DBUtils.getQuotedIdentifier(database)) //$NON-NLS-2$
);
}
@Override
protected void addObjectDeleteActions(List<DBEPersistAction> actions, ObjectDeleteCommand command)
{
actions.add(
new SQLDatabasePersistAction("Drop database", "DROP SCHEMA " + DBUtils.getQuotedIdentifier(command.getObject())) //$NON-NLS-2$
new SQLDatabasePersistAction("Drop database", "DROP DATABASE " + DBUtils.getQuotedIdentifier(command.getObject())) //$NON-NLS-2$
);
}
......
......@@ -76,15 +76,15 @@ public class PostgreProcedureManager extends SQLObjectEditor<PostgreProcedure, P
}
@Override
protected DBEPersistAction[] makeObjectCreateActions(ObjectCreateCommand command)
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand command)
{
return createOrReplaceProcedureQuery(command.getObject());
createOrReplaceProcedureQuery(actions, command.getObject());
}
@Override
protected DBEPersistAction[] makeObjectModifyActions(ObjectChangeCommand command)
protected void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand command)
{
return createOrReplaceProcedureQuery(command.getObject());
createOrReplaceProcedureQuery(actionList, command.getObject());
}
@Override
......@@ -96,13 +96,13 @@ public class PostgreProcedureManager extends SQLObjectEditor<PostgreProcedure, P
);
}
private DBEPersistAction[] createOrReplaceProcedureQuery(PostgreProcedure procedure)
private void createOrReplaceProcedureQuery(List<DBEPersistAction> actions, PostgreProcedure procedure)
{
String objectType = procedure.isAggregate() ? "AGGREGATE" : "FUNCTION";
return new DBEPersistAction[] {
new SQLDatabasePersistAction("Drop procedure", "DROP " + objectType + " IF EXISTS " + procedure.getFullQualifiedSignature()), //$NON-NLS-2$ //$NON-NLS-3$
new SQLDatabasePersistAction("Create procedure", procedure.getBody()) //$NON-NLS-2$
};
actions.add(
new SQLDatabasePersistAction("Drop procedure", "DROP " + objectType + " IF EXISTS " + procedure.getFullQualifiedSignature()));
actions.add(
new SQLDatabasePersistAction("Create procedure", procedure.getBody()));
}
}
......
......@@ -65,7 +65,7 @@ public class PostgreSchemaManager extends SQLObjectEditor<PostgreSchema, Postgre
}
@Override
protected DBEPersistAction[] makeObjectCreateActions(ObjectCreateCommand command)
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand command)
{
final PostgreSchema schema = command.getObject();
final StringBuilder script = new StringBuilder("CREATE SCHEMA " + DBUtils.getQuotedIdentifier(schema));
......@@ -78,9 +78,9 @@ public class PostgreSchemaManager extends SQLObjectEditor<PostgreSchema, Postgre
log.error(e);
}
return new DBEPersistAction[] {
actions.add(
new SQLDatabasePersistAction("Create schema", script.toString()) //$NON-NLS-2$
};
);
}
@Override
......
......@@ -34,7 +34,6 @@ import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.utils.CommonUtils;
import java.sql.Types;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -125,7 +124,7 @@ public class PostgreTableColumnManager extends SQLTableColumnManager<PostgreTabl
}
@Override
protected DBEPersistAction[] makeObjectModifyActions(ObjectChangeCommand command)
protected void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand command)
{
final PostgreAttribute column = command.getObject();
// PostgreSQL can't perform all changes by one query
......@@ -138,15 +137,13 @@ public class PostgreTableColumnManager extends SQLTableColumnManager<PostgreTabl
// ALTER [ COLUMN ] column RESET ( attribute_option [, ... ] )
// ALTER [ COLUMN ] column SET STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN }
String prefix = "ALTER TABLE " + DBUtils.getObjectFullName(column.getTable()) + " ALTER COLUMN " + DBUtils.getQuotedIdentifier(column) + " ";
List<SQLDatabasePersistAction> actions = new ArrayList<>();
actions.add(new SQLDatabasePersistAction("Set column type", prefix + "TYPE " + column.getFullQualifiedTypeName()));
actions.add(new SQLDatabasePersistAction("Set column nullability", prefix + (column.isRequired() ? "SET" : "DROP") + " NOT NULL"));
actionList.add(new SQLDatabasePersistAction("Set column type", prefix + "TYPE " + column.getFullQualifiedTypeName()));
actionList.add(new SQLDatabasePersistAction("Set column nullability", prefix + (column.isRequired() ? "SET" : "DROP") + " NOT NULL"));
if (CommonUtils.isEmpty(column.getDefaultValue())) {
actions.add(new SQLDatabasePersistAction("Drop column default", prefix + "DROP DEFAULT"));
actionList.add(new SQLDatabasePersistAction("Drop column default", prefix + "DROP DEFAULT"));
} else {
actions.add(new SQLDatabasePersistAction("Set column default", prefix + "SET DEFAULT " + column.getDefaultValue()));
actionList.add(new SQLDatabasePersistAction("Set column default", prefix + "SET DEFAULT " + column.getDefaultValue()));
}
return actions.toArray(new DBEPersistAction[actions.size()]);
}
@Override
......
......@@ -32,7 +32,6 @@ import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.utils.CommonUtils;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -69,20 +68,17 @@ public class PostgreTableManager extends SQLTableManager<PostgreTableBase, Postg
}
@Override
protected DBEPersistAction[] makeObjectModifyActions(ObjectChangeCommand command)
protected void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand command)
{
final PostgreTableBase table = command.getObject();
List<DBEPersistAction> actions = new ArrayList<>(2);
if (command.getProperties().size() > 1 || command.getProperty("description") == null) {
StringBuilder query = new StringBuilder("ALTER TABLE "); //$NON-NLS-1$
query.append(table.getFullQualifiedName()).append(" "); //$NON-NLS-1$
appendTableModifiers(table, command, query);
actions.add(new SQLDatabasePersistAction(query.toString()));
actionList.add(new SQLDatabasePersistAction(query.toString()));
}
addObjectExtraActions(actions, command);
return actions.toArray(new DBEPersistAction[actions.size()]);
addObjectExtraActions(actionList, command);
}
@Override
......
......@@ -72,15 +72,15 @@ public class PostgreViewManager extends SQLObjectEditor<PostgreTableBase, Postgr
}
@Override
protected DBEPersistAction[] makeObjectCreateActions(ObjectCreateCommand command)
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand command)
{
return createOrReplaceViewQuery((PostgreView) command.getObject());
createOrReplaceViewQuery(actions, (PostgreView) command.getObject());
}
@Override
protected DBEPersistAction[] makeObjectModifyActions(ObjectChangeCommand command)
protected void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand command)
{
return createOrReplaceViewQuery((PostgreView) command.getObject());
createOrReplaceViewQuery(actionList, (PostgreView) command.getObject());
}
@Override
......@@ -91,21 +91,16 @@ public class PostgreViewManager extends SQLObjectEditor<PostgreTableBase, Postgr
);
}
private DBEPersistAction[] createOrReplaceViewQuery(PostgreView view)
private void createOrReplaceViewQuery(List<DBEPersistAction> actions, PostgreView view)
{
StringBuilder decl = new StringBuilder(200);
final String lineSeparator = GeneralUtils.getDefaultLineSeparator();
decl.append("CREATE OR REPLACE VIEW ").append(view.getFullQualifiedName()).append(lineSeparator) //$NON-NLS-1$
.append("AS ").append(view.getSource()); //$NON-NLS-1$
/*
final PostgreView.CheckOption checkOption = view.getAdditionalInfo().getCheckOption();
if (checkOption != null && checkOption != PostgreView.CheckOption.NONE) {
decl.append(lineSeparator).append("WITH ").append(checkOption.getDefinitionName()).append(" CHECK OPTION"); //$NON-NLS-1$ //$NON-NLS-2$
}
*/
return new DBEPersistAction[] {
actions.add(
new SQLDatabasePersistAction("Create view", decl.toString())
};
);
}
}
......
......@@ -119,9 +119,9 @@ public abstract class SQLObjectEditor<OBJECT_TYPE extends DBSObject, CONTAINER_T
//////////////////////////////////////////////////
// Actions
protected abstract DBEPersistAction[] makeObjectCreateActions(ObjectCreateCommand command);
protected abstract void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand command);
protected DBEPersistAction[] makeObjectModifyActions(ObjectChangeCommand command)
protected void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand command)
{
// Base SQL syntax do not support object properties change
throw new IllegalStateException("Object modification is not supported in " + getClass().getSimpleName()); //$NON-NLS-1$
......@@ -238,7 +238,9 @@ public abstract class SQLObjectEditor<OBJECT_TYPE extends DBSObject, CONTAINER_T
@Override
public DBEPersistAction[] getPersistActions()
{
return makeObjectModifyActions(this);
List<DBEPersistAction> actions = new ArrayList<>();
addObjectModifyActions(actions, this);
return actions.toArray(new DBEPersistAction[actions.size()]);
}
@Override
......@@ -268,7 +270,9 @@ public abstract class SQLObjectEditor<OBJECT_TYPE extends DBSObject, CONTAINER_T
@Override
public DBEPersistAction[] getPersistActions()
{
return makeObjectCreateActions(this);
List<DBEPersistAction> actions = new ArrayList<>();
addObjectCreateActions(actions, this);
return actions.toArray(new DBEPersistAction[actions.size()]);
}
@Override
......
......@@ -37,7 +37,7 @@ public abstract class SQLStructEditor<OBJECT_TYPE extends DBSEntity & DBPSaveabl
implements DBEStructEditor<OBJECT_TYPE>
{
protected abstract DBEPersistAction[] makeStructObjectCreateActions(StructCreateCommand command);
protected abstract void addStructObjectCreateActions(List<DBEPersistAction> actions, StructCreateCommand command);
@Override
public StructCreateCommand makeCreateCommand(OBJECT_TYPE object)
......@@ -115,7 +115,9 @@ public abstract class SQLStructEditor<OBJECT_TYPE extends DBSEntity & DBPSaveabl
@Override
public DBEPersistAction[] getPersistActions()
{
return makeStructObjectCreateActions(this);
List<DBEPersistAction> actions = new ArrayList<>();
addStructObjectCreateActions(actions, this);
return actions.toArray(new DBEPersistAction[actions.size()]);
}
}
......
......@@ -48,14 +48,14 @@ public abstract class SQLConstraintManager<OBJECT_TYPE extends JDBCTableConstrai
}
@Override
protected DBEPersistAction[] makeObjectCreateActions(ObjectCreateCommand command)
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand command)
{
final TABLE_TYPE table = command.getObject().getTable();
return new DBEPersistAction[] {
actions.add(
new SQLDatabasePersistAction(
ModelMessages.model_jdbc_create_new_constraint,
"ALTER TABLE " + table.getFullQualifiedName() + " ADD " + getNestedDeclaration(table, command))}; //$NON-NLS-1$ //$NON-NLS-2$
"ALTER TABLE " + table.getFullQualifiedName() + " ADD " + getNestedDeclaration(table, command)));
}
@Override
......
......@@ -52,14 +52,14 @@ public abstract class SQLForeignKeyManager<OBJECT_TYPE extends JDBCTableConstrai
}
@Override
protected DBEPersistAction[] makeObjectCreateActions(ObjectCreateCommand command)
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand command)
{
final TABLE_TYPE table = command.getObject().getTable();
return new DBEPersistAction[] {
actions.add(
new SQLDatabasePersistAction(
ModelMessages.model_jdbc_create_new_foreign_key,
"ALTER TABLE " + table.getFullQualifiedName() + " ADD " + getNestedDeclaration(table, command)) //$NON-NLS-1$ //$NON-NLS-2$
};
);
}
@Override
......
......@@ -46,7 +46,7 @@ public abstract class SQLIndexManager<OBJECT_TYPE extends JDBCTableIndex<? exten
}
@Override
protected DBEPersistAction[] makeObjectCreateActions(ObjectCreateCommand command)
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand command)
{
final TABLE_TYPE table = command.getObject().getTable();
final OBJECT_TYPE index = command.getObject();
......@@ -79,9 +79,9 @@ public abstract class SQLIndexManager<OBJECT_TYPE extends JDBCTableIndex<? exten
}
decl.append(")"); //$NON-NLS-1$
return new DBEPersistAction[] {
actions.add(
new SQLDatabasePersistAction(ModelMessages.model_jdbc_create_new_index, decl.toString())
};
);
}
@Override
......
......@@ -165,13 +165,13 @@ public abstract class SQLTableColumnManager<OBJECT_TYPE extends JDBCTableColumn<
}
@Override
protected DBEPersistAction[] makeObjectCreateActions(ObjectCreateCommand command)
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand command)
{
final TABLE_TYPE table = command.getObject().getTable();
return new DBEPersistAction[] {
actions.add(
new SQLDatabasePersistAction(
ModelMessages.model_jdbc_create_new_table_column,
"ALTER TABLE " + table.getFullQualifiedName() + " ADD " + getNestedDeclaration(table, command)) }; //$NON-NLS-1$ //$NON-NLS-2$
"ALTER TABLE " + table.getFullQualifiedName() + " ADD " + getNestedDeclaration(table, command)) );
}
@Override
......
......@@ -39,7 +39,6 @@ import org.jkiss.dbeaver.model.struct.rdb.DBSTableIndex;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.utils.CommonUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
......@@ -59,21 +58,20 @@ public abstract class SQLTableManager<OBJECT_TYPE extends JDBCTable, CONTAINER_T
}
@Override
protected final DBEPersistAction[] makeObjectCreateActions(ObjectCreateCommand objectChangeCommand)
protected final void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand objectChangeCommand)
{
throw new IllegalStateException("makeObjectCreateActions should never be called in struct editor");
throw new IllegalStateException("addObjectCreateActions should never be called in struct editor");
}
@Override
protected DBEPersistAction[] makeStructObjectCreateActions(StructCreateCommand command)
protected void addStructObjectCreateActions(List<DBEPersistAction> actions, StructCreateCommand command)
{
final OBJECT_TYPE table = command.getObject();
final NestedObjectCommand tableProps = command.getObjectCommands().get(table);
if (tableProps == null) {
log.warn("Object change command not found"); //$NON-NLS-1$
return null;
return;
}
List<DBEPersistAction> actions = new ArrayList<>();
final String tableName = table.getFullQualifiedName();
final String lineSeparator = GeneralUtils.getDefaultLineSeparator();
......@@ -106,8 +104,6 @@ public abstract class SQLTableManager<OBJECT_TYPE extends JDBCTable, CONTAINER_T
actions.add( 0, new SQLDatabasePersistAction(ModelMessages.model_jdbc_create_new_table, createQuery.toString()) );
addObjectExtraActions(actions, command);
return actions.toArray(new DBEPersistAction[actions.size()]);
}
@Override
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册