diff --git a/plugins/org.jkiss.dbeaver.ext.postgresql/OSGI-INF/l10n/bundle.properties b/plugins/org.jkiss.dbeaver.ext.postgresql/OSGI-INF/l10n/bundle.properties index b236c7853dfe76201453e358bf205173be684e45..bbc0932b052c48c1935076135264adfec1cf67d7 100644 --- a/plugins/org.jkiss.dbeaver.ext.postgresql/OSGI-INF/l10n/bundle.properties +++ b/plugins/org.jkiss.dbeaver.ext.postgresql/OSGI-INF/l10n/bundle.properties @@ -584,3 +584,5 @@ tools.vacuum.name=Vacuum tools.vacuum.description=Vacuum table(s) tools.truncate.name=Truncate tools.truncate.description=Truncate table(s) +tools.refesh.mview.name=Refresh Materialized View +tools.refesh.mview.description=Refresh materialized view(s) diff --git a/plugins/org.jkiss.dbeaver.ext.postgresql/plugin.xml b/plugins/org.jkiss.dbeaver.ext.postgresql/plugin.xml index 026c006d471f19d9aa4ce3cfb685b1a6fa1c2710..55ed9daa8ba1e831247363131748e1b9481b2fd2 100644 --- a/plugins/org.jkiss.dbeaver.ext.postgresql/plugin.xml +++ b/plugins/org.jkiss.dbeaver.ext.postgresql/plugin.xml @@ -493,6 +493,15 @@ singleton="false"> + + + diff --git a/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/PostgreMessages.java b/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/PostgreMessages.java index d2441a7b68b230cdfe158818bafedd8df95c65fa..d04feedd671ae4c59a0210b4ea77e7db9f7027b5 100644 --- a/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/PostgreMessages.java +++ b/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/PostgreMessages.java @@ -75,6 +75,9 @@ public class PostgreMessages extends NLS { /* tool analyze */ public static String tool_analyze_title_table; public static String tool_analyze_title_database; + + /* tool refresh mat view */ + public static String tool_refresh_mview_title_table; /* tool vacuum */ public static String tool_vacuum_analyze_check_tooltip; @@ -94,7 +97,12 @@ public class PostgreMessages extends NLS { public static String tool_truncate_checkbox_restart_tooltip; public static String tool_truncate_group_option; public static String tool_truncate_title_table; - + + /* tool refresh mat view */ + public static String tool_refresh_mview_group_option; + public static String tool_refresh_mview_with_data; + public static String tool_refresh_mview_with_data_tooltip; + /* dialog create db */ public static String dialog_create_db_group_definition; public static String dialog_create_db_group_general; diff --git a/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/PostgresResources.properties b/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/PostgresResources.properties index f333efb6a8d8b76a4607d3141709aa12ef8fd5ba..5d694db7116e140e94f6710b7df84c930ee8b57f 100644 --- a/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/PostgresResources.properties +++ b/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/PostgresResources.properties @@ -57,6 +57,9 @@ tool_script_title_import=Import configuration tool_analyze_title_database=Analyze database tool_analyze_title_table=Analyze table(s) +# tool refresh mat view +tool_refresh_mview_title_table = Refresh materialized view + # tool vacuum # tool_vacuum_analyze_check_tooltip=Updates statistics used by the planner to determine the most efficient way to execute a query. tool_vacuum_dps_check_tooltip=Normally, VACUUM will skip pages based on the visibility map.\nPages where all tuples are known to be frozen can always be skipped, and those where all tuples are known to be visible to all transactions may be skipped except when performing an aggressive vacuum.\nFurthermore, except when performing an aggressive vacuum, some pages may be skipped in order to avoid waiting for other sessions to finish using them.\nThis option disables all page-skipping behavior, and is intended to be used only the contents of the visibility map are thought to be suspect, which should happen only if there is a hardware or software issue causing database corruption. @@ -76,6 +79,11 @@ tool_truncate_checkbox_restart_tooltip=Automatically restart sequences owned by tool_truncate_group_option=Options tool_truncate_title_table=Truncate table(s) +# tool refresh mat view +tool_refresh_mview_group_option = Options +tool_refresh_mview_with_data = With data +tool_refresh_mview_with_data_tooltip = If WITH DATA is specified (or defaults) the backing query is executed to provide the new data, and the materialized view is left in a scannable state.\nIf WITH NO DATA is specified no new data is generated and the materialized view is left in an unscannable state. + # dialog create db # dialog_create_db_group_definition=Definition dialog_create_db_group_general=General diff --git a/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/tools/maintenance/PostgreToolRefreshMView.java b/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/tools/maintenance/PostgreToolRefreshMView.java new file mode 100644 index 0000000000000000000000000000000000000000..8295f4986b1c92ac31bff2485c3db5d1213836d4 --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/tools/maintenance/PostgreToolRefreshMView.java @@ -0,0 +1,88 @@ +/* + * DBeaver - Universal Database Manager + * Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jkiss.dbeaver.ext.postgresql.tools.maintenance; + +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchPartSite; +import org.eclipse.ui.IWorkbenchWindow; +import org.jkiss.dbeaver.DBException; +import org.jkiss.dbeaver.ext.postgresql.PostgreMessages; +import org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase; +import org.jkiss.dbeaver.ext.postgresql.model.PostgreMaterializedView; +import org.jkiss.dbeaver.ext.postgresql.model.PostgreObject; +import org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase; +import org.jkiss.dbeaver.model.DBPEvaluationContext; +import org.jkiss.dbeaver.model.struct.DBSObject; +import org.jkiss.dbeaver.tools.IExternalTool; +import org.jkiss.dbeaver.ui.UIUtils; +import org.jkiss.utils.CommonUtils; + +import java.util.Collection; +import java.util.List; + +/** + * Table analyze + */ +public class PostgreToolRefreshMView implements IExternalTool +{ + @Override + public void execute(IWorkbenchWindow window, IWorkbenchPart activePart, Collection objects) throws DBException + { + List tables = CommonUtils.filterCollection(objects, PostgreMaterializedView.class); + if (!tables.isEmpty()) { + SQLDialog dialog = new SQLDialog(activePart.getSite(), tables); + dialog.open(); + } + } + + static class SQLDialog extends TableToolDialog { + + private Button withDataCheck; + + public SQLDialog(IWorkbenchPartSite partSite, List selectedTables) + { + super(partSite, PostgreMessages.tool_refresh_mview_title_table, selectedTables); + } + + @Override + protected void generateObjectCommand(List lines, PostgreObject object) { + String sql = "REFRESH MATERIALIZED VIEW " + ((PostgreMaterializedView) object).getFullyQualifiedName(DBPEvaluationContext.DDL) + " "; + if (withDataCheck.getSelection()) { + sql += "WITH DATA"; + } else { + sql += "WITH NO DATA"; + } + lines.add(sql); + } + + @Override + protected void createControls(Composite parent) { + + Group optionsGroup = UIUtils.createControlGroup(parent, PostgreMessages.tool_refresh_mview_group_option, 1, 0, 0); + optionsGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + withDataCheck = UIUtils.createCheckbox(optionsGroup, PostgreMessages.tool_refresh_mview_with_data, PostgreMessages.tool_refresh_mview_with_data_tooltip, true, 0); + withDataCheck.addSelectionListener(SQL_CHANGE_LISTENER); + + createObjectsSelector(parent); + } + } + +} diff --git a/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/tools/maintenance/TableToolDialog.java b/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/tools/maintenance/TableToolDialog.java index 44c76ec0d93d2b53378a9ae426a9b72fb221e657..c5c96de9e1dc2bbe7b838c9e77cf23fec471694a 100644 --- a/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/tools/maintenance/TableToolDialog.java +++ b/plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/tools/maintenance/TableToolDialog.java @@ -47,7 +47,7 @@ import java.util.List; public abstract class TableToolDialog extends GenerateMultiSQLDialog { - public TableToolDialog(IWorkbenchPartSite partSite, String title, Collection tables) { + public TableToolDialog(IWorkbenchPartSite partSite, String title, Collection tables) { super(partSite, title, toObjects(tables), true); } @@ -55,7 +55,7 @@ public abstract class TableToolDialog extends GenerateMultiSQLDialogsingletonList(database), true); } - private static Collection toObjects(Collection tables) { + private static Collection toObjects(Collection tables) { List objectList = new ArrayList<>(); objectList.addAll(tables); return objectList;