Skip to content

Commit

Permalink
Revert "dbeaver/pro#2676 use fully qualified names checkbox (#33848)"
Browse files Browse the repository at this point in the history
This reverts commit bd558e2.
  • Loading branch information
serge-rider committed Jun 5, 2024
1 parent 786cf80 commit 089f310
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<? extends DBSTableIndex> getIndexes(DBRProgressMonitor monitor) throws DBException {
public Collection<? extends DBSTableIndex> 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<String, Object> 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<String, Object> 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<DBEPersistAction> actions = new ArrayList<>();
Expand Down Expand Up @@ -141,28 +155,18 @@ public String getObjectDefinitionText(DBRProgressMonitor monitor, Map<String, Ob
return ddl.toString();
}

private void fetchViewQueryResult(JDBCSession session) throws SQLException, DBException {
if (viewQueryResult == null) {
// Do not use view id as a parameter. For some reason it doesn't work for Redshift
viewQueryResult = JDBCUtils.queryString(session, "SELECT pg_get_viewdef(" + getObjectId() + ", true)");
}
if (viewQueryResult == null) {
throw new DBException("View '" + getName() + "' doesn't exist");
}
}

protected String readExtraDefinition(JDBCSession session, Map<String, Object> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,7 @@ public static String getTableDDL(@NotNull DBRProgressMonitor monitor, @NotNull D
return generateTableDDL(monitor, table, options, addComments);
}

public static <T extends DBSEntity> void generateTableListDDL(
@NotNull DBRProgressMonitor monitor,
@NotNull StringBuilder sql,
@NotNull Collection<T> tablesOrViews,
Map<String, Object> options,
boolean addComments
) throws DBException {
public static <T extends DBSEntity> void generateTableListDDL(@NotNull DBRProgressMonitor monitor, @NotNull StringBuilder sql, @NotNull Collection<T> tablesOrViews, Map<String, Object> options, boolean addComments) throws DBException {
List<T> goodTableList = new ArrayList<>();
List<T> cycleTableList = new ArrayList<>();
List<T> viewList = new ArrayList<>();
Expand Down

0 comments on commit 089f310

Please sign in to comment.