Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dbeaver/pro#2676 use fully qualified names checkbox #33848

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -616,13 +616,18 @@
}
}

public static String getViewDDL(DBRProgressMonitor monitor, PostgreViewBase view, String definition) throws DBException {
public static String getViewDDL(

Check warning on line 619 in plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/PostgreUtils.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Report

plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/PostgreUtils.java#L619

Missing a Javadoc comment.
@NotNull DBRProgressMonitor monitor,
@NotNull PostgreViewBase view,
@NotNull String definition,
@NotNull Map<String, Object> options
) 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(view.getFullyQualifiedName(DBPEvaluationContext.DDL));
sql.append(view.getTableTypeName()).append(" ").append(DBUtils.getEntityScriptName(view, options));

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,72 +48,58 @@
/**
* PostgreViewBase
*/
public abstract class PostgreViewBase extends PostgreTableReal implements DBSView
{
private String source;
public abstract class PostgreViewBase extends PostgreTableReal implements DBSView {
private String viewQueryResult;

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
{
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);
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;
}
} 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 @@ -155,18 +141,28 @@ public String getObjectDefinitionText(DBRProgressMonitor monitor, Map<String, Ob
return ddl.toString();
}

private void fetchViewQueryResult(JDBCSession session) throws SQLException, DBException {
ShadelessFox marked this conversation as resolved.
Show resolved Hide resolved
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;
}

@Override
public DBSObject refreshObject(@NotNull DBRProgressMonitor monitor) throws DBException {
this.source = null;
this.viewQueryResult = null;
return super.refreshObject(monitor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,13 @@
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(

Check warning on line 133 in plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/struct/DBStructUtils.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Report

plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/struct/DBStructUtils.java#L133

Missing a Javadoc comment.
@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
Loading