From 089f3100da06d4c639c43efc107ae7c3ca5643c1 Mon Sep 17 00:00:00 2001 From: serge-rider Date: Wed, 5 Jun 2024 18:10:01 +0200 Subject: [PATCH] Revert "dbeaver/pro#2676 use fully qualified names checkbox (#33848)" This reverts commit bd558e25b768638e9a32db1a6151236f44619b54. --- .../dbeaver/ext/postgresql/PostgreUtils.java | 9 +-- .../ext/postgresql/model/PostgreViewBase.java | 76 ++++++++++--------- .../dbeaver/model/struct/DBStructUtils.java | 8 +- 3 files changed, 43 insertions(+), 50 deletions(-) diff --git a/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/PostgreUtils.java b/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/PostgreUtils.java index d2e7ec17e4dc..028fdb784b18 100644 --- a/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/PostgreUtils.java +++ b/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/PostgreUtils.java @@ -616,18 +616,13 @@ public static void setArrayParameter(JDBCPreparedStatement dbStat, int index, Li } } - public static String getViewDDL( - @NotNull DBRProgressMonitor monitor, - @NotNull PostgreViewBase view, - @NotNull String definition, - @NotNull Map options - ) throws DBException { + public static String getViewDDL(DBRProgressMonitor monitor, PostgreViewBase view, String definition) throws DBException { // In some cases view definition already has view header (e.g. Redshift + with no schema binding) if (definition.toLowerCase(Locale.ENGLISH).startsWith("create ")) { return definition; } StringBuilder sql = new StringBuilder(view instanceof PostgreView ? "CREATE OR REPLACE " : "CREATE "); - sql.append(view.getTableTypeName()).append(" ").append(DBUtils.getEntityScriptName(view, options)); + sql.append(view.getTableTypeName()).append(" ").append(view.getFullyQualifiedName(DBPEvaluationContext.DDL)); final DBERegistry editorsRegistry = DBWorkbench.getPlatform().getEditorsRegistry(); final PostgreViewManager entityEditor = editorsRegistry.getObjectManager(view.getClass(), PostgreViewManager.class); diff --git a/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreViewBase.java b/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreViewBase.java index 146018b1a9c6..d6ebb5806572 100644 --- a/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreViewBase.java +++ b/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreViewBase.java @@ -48,58 +48,72 @@ /** * PostgreViewBase */ -public abstract class PostgreViewBase extends PostgreTableReal implements DBSView { - private String viewQueryResult; +public abstract class PostgreViewBase extends PostgreTableReal implements DBSView +{ + private String source; - public PostgreViewBase(PostgreSchema catalog) { + public PostgreViewBase(PostgreSchema catalog) + { super(catalog); } public PostgreViewBase( PostgreSchema catalog, - ResultSet dbResult - ) { + ResultSet dbResult) + { super(catalog, dbResult); } @NotNull @Property(viewable = true, editable = true, valueTransformer = DBObjectNameCaseTransformer.class, order = 1) @Override - public String getName() { + public String getName() + { return super.getName(); } @Override - public boolean isView() { + public boolean isView() + { return true; } @Override - public Collection getIndexes(DBRProgressMonitor monitor) throws DBException { + public Collection getIndexes(DBRProgressMonitor monitor) throws DBException + { return null; } + public String getSource() { + return source; + } + @Override @Property(hidden = true, editable = true, updatable = true, order = -1) - public String getObjectDefinitionText(DBRProgressMonitor monitor, Map options) throws DBException { - String source; - if (isPersisted()) { - source = getDataSource().getServerType().readViewDDL(monitor, this); - if (source == null) { - try (JDBCSession session = DBUtils.openMetaSession(monitor, this, "Read view definition")) { - - fetchViewQueryResult(session); - source = PostgreUtils.getViewDDL(monitor, this, viewQueryResult, options); - String extDefinition = readExtraDefinition(session, options); - if (extDefinition != null) { - source += "\n" + extDefinition; + public String getObjectDefinitionText(DBRProgressMonitor monitor, Map options) throws DBException + { + if (source == null) { + if (isPersisted()) { + source = getDataSource().getServerType().readViewDDL(monitor, this); + if (source == null) { + try (JDBCSession session = DBUtils.openMetaSession(monitor, this, "Read view definition")) { + // Do not use view id as a parameter. For some reason it doesn't work for Redshift + String definition = JDBCUtils.queryString(session, "SELECT pg_get_viewdef(" + getObjectId() + ", true)"); + if (definition == null) { + throw new DBException("View '" + getName() + "' doesn't exist"); + } + this.source = PostgreUtils.getViewDDL(monitor, this, definition); + String extDefinition = readExtraDefinition(session, options); + if (extDefinition != null) { + this.source += "\n" + extDefinition; + } + } catch (SQLException e) { + throw new DBException("Error reading view definition: " + e.getMessage(), e); } - } catch (SQLException e) { - throw new DBException("Error reading view definition: " + e.getMessage(), e); } + } else { + source = ""; } - } else { - source = ""; } List actions = new ArrayList<>(); @@ -141,28 +155,18 @@ public String getObjectDefinitionText(DBRProgressMonitor monitor, Map options) throws DBException { return null; } @Override public void setObjectDefinitionText(String sourceText) { - viewQueryResult = sourceText; + this.source = sourceText; } @Override public DBSObject refreshObject(@NotNull DBRProgressMonitor monitor) throws DBException { - this.viewQueryResult = null; + this.source = null; return super.refreshObject(monitor); } } diff --git a/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/struct/DBStructUtils.java b/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/struct/DBStructUtils.java index 3bc80c2e8d70..653279493465 100644 --- a/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/struct/DBStructUtils.java +++ b/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/struct/DBStructUtils.java @@ -130,13 +130,7 @@ public static String getTableDDL(@NotNull DBRProgressMonitor monitor, @NotNull D return generateTableDDL(monitor, table, options, addComments); } - public static void generateTableListDDL( - @NotNull DBRProgressMonitor monitor, - @NotNull StringBuilder sql, - @NotNull Collection tablesOrViews, - Map options, - boolean addComments - ) throws DBException { + public static void generateTableListDDL(@NotNull DBRProgressMonitor monitor, @NotNull StringBuilder sql, @NotNull Collection tablesOrViews, Map options, boolean addComments) throws DBException { List goodTableList = new ArrayList<>(); List cycleTableList = new ArrayList<>(); List viewList = new ArrayList<>();