Skip to content

Commit

Permalink
dbeaver/pro#2676 Use fully qualified names checkbox for SQL DDL view …
Browse files Browse the repository at this point in the history
…generation
  • Loading branch information
HocKu7 committed May 22, 2024
1 parent a3637f3 commit bca3896
Showing 1 changed file with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
*/
public abstract class PostgreViewBase extends PostgreTableReal implements DBSView
{
private String source;
private String viewQueryResult;

public PostgreViewBase(PostgreSchema catalog)
{
Expand Down Expand Up @@ -84,28 +84,21 @@ public Collection<? extends DBSTableIndex> getIndexes(DBRProgressMonitor monitor
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
{
if (source == null) {
String source;

Check warning on line 91 in plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreViewBase.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Report

plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreViewBase.java#L91

method def child has incorrect indentation level 12, expected level should be 8.
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, options);

fetchViewQueryResult(session);

Check warning on line 97 in plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreViewBase.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Report

plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreViewBase.java#L97

try child has incorrect indentation level 24, expected level should be 20.
source = PostgreUtils.getViewDDL(monitor, this, viewQueryResult, options);

Check warning on line 98 in plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreViewBase.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Report

plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreViewBase.java#L98

try child has incorrect indentation level 24, expected level should be 20.
String extDefinition = readExtraDefinition(session, options);
if (extDefinition != null) {
this.source += "\n" + extDefinition;
source += "\n" + extDefinition;

Check warning on line 101 in plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreViewBase.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Report

plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreViewBase.java#L101

if child has incorrect indentation level 28, expected level should be 24.
}
} catch (SQLException e) {
throw new DBException("Error reading view definition: " + e.getMessage(), e);
Expand All @@ -114,7 +107,6 @@ public String getObjectDefinitionText(DBRProgressMonitor monitor, Map<String, Ob
} else {
source = "";
}
}

List<DBEPersistAction> actions = new ArrayList<>();
if (CommonUtils.getOption(options, DBPScriptObject.OPTION_INCLUDE_COMMENTS)) {
Expand Down Expand Up @@ -155,18 +147,28 @@ 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) {
this.source = sourceText;
viewQueryResult=sourceText;

Check warning on line 166 in plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreViewBase.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Report

plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreViewBase.java#L166

WhitespaceAround: = is not followed by whitespace. Empty blocks may only be represented as [] when not part of a multi-block statement (4.1.3)

Check warning on line 166 in plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreViewBase.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Report

plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreViewBase.java#L166

WhitespaceAround: = is not preceded with whitespace.
}

@Override
public DBSObject refreshObject(@NotNull DBRProgressMonitor monitor) throws DBException {
this.source = null;
this.viewQueryResult = null;
return super.refreshObject(monitor);
}
}

0 comments on commit bca3896

Please sign in to comment.