提交 068a62eb 编写于 作者: S serge-rider

PG: table DDL fix

上级 78bdd684
......@@ -62,13 +62,13 @@ public class SQLSourceViewer<T extends DBPScriptObject & DBSObject> extends SQLE
protected Map<String, Object> getSourceOptions() {
IDatabaseEditorInput editorInput = getEditorInput();
Collection<String> attributeNames = editorInput.getAttributeNames();
if (attributeNames.isEmpty()) {
return DBPScriptObject.EMPTY_OPTIONS;
}
Map<String, Object> options = new HashMap<String, Object>();
for (String name : attributeNames) {
Object attribute = editorInput.getAttribute(name);
options.put(name, attribute);
Map<String, Object> options = new HashMap<>();
options.put(DBPScriptObject.OPTION_DDL_SOURCE, true);
if (!attributeNames.isEmpty()) {
for (String name : attributeNames) {
Object attribute = editorInput.getAttribute(name);
options.put(name, attribute);
}
}
return options;
}
......
......@@ -27,7 +27,6 @@ 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.messages.ModelMessages;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
......@@ -39,7 +38,7 @@ import java.util.Map;
/**
* Postgre table manager
*/
public class PostgreTableManager extends SQLTableManager<PostgreTableBase, PostgreSchema> implements DBEObjectRenamer<PostgreTableBase> {
public class PostgreTableManager extends PostgreTableManagerBase implements DBEObjectRenamer<PostgreTableBase> {
private static final Class<?>[] CHILD_TYPES = {
PostgreTableColumn.class,
......@@ -82,11 +81,6 @@ public class PostgreTableManager extends SQLTableManager<PostgreTableBase, Postg
}
}
@Override
protected void addObjectExtraActions(List<DBEPersistAction> actions, NestedObjectCommand<PostgreTableBase, PropertyHandler> command, Map<String, Object> options) {
PostgreDDLUtils.addObjectExtraActions(actions, command.getObject(), options);
}
@Override
protected void appendTableModifiers(PostgreTableBase tableBase, NestedObjectCommand tableProps, StringBuilder ddl)
{
......
......@@ -17,14 +17,16 @@
package org.jkiss.dbeaver.ext.postgresql.edit;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.ext.postgresql.PostgreConstants;
import org.jkiss.dbeaver.ext.postgresql.model.*;
import org.jkiss.dbeaver.model.DBConstants;
import org.jkiss.dbeaver.model.DBPEvaluationContext;
import org.jkiss.dbeaver.model.DBPScriptObject;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.edit.DBEPersistAction;
import org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction;
import org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistActionComment;
import org.jkiss.dbeaver.model.impl.sql.edit.struct.SQLTableManager;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
import org.jkiss.dbeaver.model.sql.SQLUtils;
......@@ -38,13 +40,13 @@ import java.util.Map;
/**
* Postgre table manager
*/
public class PostgreDDLUtils {
public abstract class PostgreTableManagerBase extends SQLTableManager<PostgreTableBase, PostgreSchema> {
protected static final Log log = Log.getLog(PostgreDDLUtils.class);
static void addObjectExtraActions(List<DBEPersistAction> actions, PostgreTableBase table, Map<String, Object> options) {
protected void addObjectExtraActions(List<DBEPersistAction> actions, NestedObjectCommand<PostgreTableBase, PropertyHandler> command, Map<String, Object> options) {
boolean isDDL = CommonUtils.getOption(options, DBPScriptObject.OPTION_DDL_SOURCE);
PostgreTableBase table = command.getObject();
// Add comments
if (!CommonUtils.isEmpty(table.getDescription())) {
if ((!table.isPersisted() || command.getProperty(DBConstants.PROP_ID_DESCRIPTION) != null) && table.getDescription() != null) {
actions.add(new SQLDatabasePersistAction(
"Comment table",
"COMMENT ON " + (table.isView() ? "VIEW": "TABLE") + " " + table.getFullyQualifiedName(DBPEvaluationContext.DDL) +
......@@ -52,7 +54,7 @@ public class PostgreDDLUtils {
}
DBRProgressMonitor monitor = new VoidProgressMonitor();
try {
{
if (isDDL) {
// Column comments
boolean hasComments = false;
for (PostgreTableColumn column : table.getAttributes(monitor)) {
......@@ -69,7 +71,7 @@ public class PostgreDDLUtils {
}
// Triggers
if (table instanceof PostgreTableReal) {
if (isDDL && table instanceof PostgreTableReal) {
Collection<PostgreTrigger> triggers = ((PostgreTableReal) table).getTriggers(monitor);
if (!CommonUtils.isEmpty(triggers)) {
actions.add(new SQLDatabasePersistActionComment(table.getDataSource(), "Table Triggers"));
......@@ -80,8 +82,7 @@ public class PostgreDDLUtils {
}
}
if (CommonUtils.getOption(options, PostgreConstants.OPTION_DDL_SHOW_PERMISSIONS)) {
if (isDDL && CommonUtils.getOption(options, PostgreConstants.OPTION_DDL_SHOW_PERMISSIONS)) {
// Permissions
Collection<PostgrePermission> permissions = table.getPermissions(monitor);
if (!CommonUtils.isEmpty(permissions)) {
......@@ -102,5 +103,4 @@ public class PostgreDDLUtils {
log.error(e);
}
}
}
......@@ -25,7 +25,6 @@ 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.struct.SQLTableManager;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.utils.CommonUtils;
......@@ -36,7 +35,7 @@ import java.util.Map;
/**
* PostgreViewManager
*/
public class PostgreViewManager extends SQLTableManager<PostgreTableBase, PostgreSchema> {
public class PostgreViewManager extends PostgreTableManagerBase {
private static final Class<?>[] CHILD_TYPES = {
PostgreTableColumn.class,
......@@ -102,11 +101,6 @@ public class PostgreViewManager extends SQLTableManager<PostgreTableBase, Postgr
);
}
@Override
protected void addObjectExtraActions(List<DBEPersistAction> actions, NestedObjectCommand<PostgreTableBase, PropertyHandler> command, Map<String, Object> options) {
PostgreDDLUtils.addObjectExtraActions(actions, command.getObject(), options);
}
protected void createOrReplaceViewQuery(List<DBEPersistAction> actions, PostgreViewBase view)
{
String sql = view.getSource().trim();
......
......@@ -125,11 +125,10 @@ public class PostgreSourceViewEditor extends SQLSourceViewer<PostgreScriptObject
@Override
protected Map<String, Object> getSourceOptions() {
Map<String, Object> options = new HashMap<>();
Map<String, Object> options = super.getSourceOptions();
options.put(DBPScriptObject.OPTION_DEBUGGER_SOURCE, omitHeader);
options.put(PostgreConstants.OPTION_DDL_SHOW_PERMISSIONS, showPermissions);
options.put(PostgreConstants.OPTION_DDL_SHOW_COLUMN_COMMENTS, showColumnComments);
options.putAll(super.getSourceOptions());
return options;
}
}
......
......@@ -36,6 +36,8 @@ public interface DBPScriptObject extends DBPObject {
String OPTION_SCRIPT_FORMAT = "script.format";
String OPTION_SCRIPT_FORMAT_COMPACT = "script.format.compact";
String OPTION_DDL_SOURCE = "ddl.source";
// Extracts object source for debugger
// By defautl the same as regular source but in some cases source should be transormed (e.g. for PG)
String OPTION_DEBUGGER_SOURCE = "debugger.source";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册