diff --git a/features/org.jkiss.dbeaver.ui.feature/feature.xml b/features/org.jkiss.dbeaver.ui.feature/feature.xml
index 79b15e452d65aab0ea0e82050be22c9e98f65504..ddaa0d3f2dda296091e67263c06c93d136129115 100644
--- a/features/org.jkiss.dbeaver.ui.feature/feature.xml
+++ b/features/org.jkiss.dbeaver.ui.feature/feature.xml
@@ -55,6 +55,7 @@
+
diff --git a/plugins/org.jkiss.dbeaver.ext.mysql/plugin.xml b/plugins/org.jkiss.dbeaver.ext.mysql/plugin.xml
index 9f8ae9b37530618e4c1a50668949f140a7457e1c..e80a39a298820b85d2f05e0c3801e31dcc532dfa 100644
--- a/plugins/org.jkiss.dbeaver.ext.mysql/plugin.xml
+++ b/plugins/org.jkiss.dbeaver.ext.mysql/plugin.xml
@@ -370,6 +370,7 @@
+
@@ -383,11 +384,9 @@
-
diff --git a/plugins/org.jkiss.dbeaver.ext.mysql/src/org/jkiss/dbeaver/ext/mysql/tasks/MySQLToolTableCheck.java b/plugins/org.jkiss.dbeaver.ext.mysql/src/org/jkiss/dbeaver/ext/mysql/tasks/MySQLToolTableCheck.java
new file mode 100644
index 0000000000000000000000000000000000000000..9979850c0616e9a1f2a40835f52c0dc3b806295b
--- /dev/null
+++ b/plugins/org.jkiss.dbeaver.ext.mysql/src/org/jkiss/dbeaver/ext/mysql/tasks/MySQLToolTableCheck.java
@@ -0,0 +1,47 @@
+/*
+ * DBeaver - Universal Database Manager
+ * Copyright (C) 2010-2020 DBeaver Corp and others
+ * Copyright (C) 2011-2012 Eugene Fradkin (eugene.fradkin@gmail.com)
+ *
+ * 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.mysql.tasks;
+
+import org.jkiss.code.NotNull;
+import org.jkiss.dbeaver.ext.mysql.model.MySQLTableBase;
+import org.jkiss.dbeaver.model.DBPEvaluationContext;
+import org.jkiss.dbeaver.model.exec.DBCSession;
+import org.jkiss.dbeaver.model.sql.task.SQLToolExecuteHandler;
+import org.jkiss.utils.CommonUtils;
+
+import java.util.List;
+
+/**
+ * Table check
+ */
+public class MySQLToolTableCheck extends SQLToolExecuteHandler {
+
+ @NotNull
+ @Override
+ protected MySQLToolTableCheckSettings createToolSettings() {
+ return new MySQLToolTableCheckSettings();
+ }
+
+ public void generateObjectQueries(DBCSession session, MySQLToolTableCheckSettings settings, List queries, MySQLTableBase object) {
+ String sql = "CHECK TABLE " + object.getFullyQualifiedName(DBPEvaluationContext.DDL);
+ String option = settings.getOption();
+ if (!CommonUtils.isEmpty(option)) sql += " " + option;
+ queries.add(sql);
+ }
+
+}
diff --git a/plugins/org.jkiss.dbeaver.ext.mysql/src/org/jkiss/dbeaver/ext/mysql/tasks/MySQLToolTableCheckSettings.java b/plugins/org.jkiss.dbeaver.ext.mysql/src/org/jkiss/dbeaver/ext/mysql/tasks/MySQLToolTableCheckSettings.java
new file mode 100644
index 0000000000000000000000000000000000000000..1ad5be9ee44e9c8e4d85b37f7630d9011682d855
--- /dev/null
+++ b/plugins/org.jkiss.dbeaver.ext.mysql/src/org/jkiss/dbeaver/ext/mysql/tasks/MySQLToolTableCheckSettings.java
@@ -0,0 +1,61 @@
+/*
+ * DBeaver - Universal Database Manager
+ * Copyright (C) 2010-2020 DBeaver Corp and others
+ * Copyright (C) 2011-2012 Eugene Fradkin (eugene.fradkin@gmail.com)
+ *
+ * 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.mysql.tasks;
+
+import org.jkiss.dbeaver.ext.mysql.model.MySQLTableBase;
+import org.jkiss.dbeaver.model.meta.IPropertyValueListProvider;
+import org.jkiss.dbeaver.model.meta.Property;
+import org.jkiss.dbeaver.model.sql.task.SQLToolExecuteSettings;
+
+/**
+ * Table check settings
+ */
+public class MySQLToolTableCheckSettings extends SQLToolExecuteSettings {
+ private String option;
+
+ @Property(listProvider = CheckOptionListProvider.class)
+ public String getOption() {
+ return option;
+ }
+
+ public void setOption(String option) {
+ this.option = option;
+ }
+
+ private static class CheckOptionListProvider implements IPropertyValueListProvider {
+
+ @Override
+ public boolean allowCustomValue() {
+ return false;
+ }
+
+ @Override
+ public Object[] getPossibleValues(String object) {
+ return new String[] {
+ "",
+ "FOR UPGRADE",
+ "QUICK",
+ "FAST",
+ "MEDIUM",
+ "EXTENDED",
+ "CHANGED"
+ };
+ }
+ }
+
+}
diff --git a/plugins/org.jkiss.dbeaver.model.sql/META-INF/MANIFEST.MF b/plugins/org.jkiss.dbeaver.model.sql/META-INF/MANIFEST.MF
index 5f8441ef6b006ba785db671ba155f3c9e26be3b4..ebd384e7bfa3f45ebdd3d1febb22cae5f5fd12db 100644
--- a/plugins/org.jkiss.dbeaver.model.sql/META-INF/MANIFEST.MF
+++ b/plugins/org.jkiss.dbeaver.model.sql/META-INF/MANIFEST.MF
@@ -22,6 +22,7 @@ Export-Package: org.jkiss.dbeaver.model.sql,
org.jkiss.dbeaver.model.sql.parser.rules,
org.jkiss.dbeaver.model.sql.parser.tokens,
org.jkiss.dbeaver.model.sql.registry,
+ org.jkiss.dbeaver.model.sql.task,
org.jkiss.dbeaver.model.text,
org.jkiss.dbeaver.model.text.parser,
org.jkiss.dbeaver.model.text.parser.rules
diff --git a/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/sql/task/SQLToolExecuteHandler.java b/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/sql/task/SQLToolExecuteHandler.java
index 7974ef306eac60e53083636f8cafe9baf888aced..179c39ed1838f790479cfda9092ac3ee10da4265 100644
--- a/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/sql/task/SQLToolExecuteHandler.java
+++ b/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/sql/task/SQLToolExecuteHandler.java
@@ -19,24 +19,29 @@ package org.jkiss.dbeaver.model.sql.task;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
+import org.jkiss.dbeaver.model.DBUtils;
+import org.jkiss.dbeaver.model.exec.DBCException;
+import org.jkiss.dbeaver.model.exec.DBCSession;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.DBRRunnableContext;
+import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.model.task.DBTTask;
import org.jkiss.dbeaver.model.task.DBTTaskExecutionListener;
import org.jkiss.dbeaver.model.task.DBTTaskHandler;
import java.io.Writer;
import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
/**
* SQLToolExecuteHandler
*/
-public abstract class SQLToolExecuteHandler implements DBTTaskHandler {
+public abstract class SQLToolExecuteHandler> implements DBTTaskHandler {
@Override
- public void executeTask(
+ public final void executeTask(
@NotNull DBRRunnableContext runnableContext,
@NotNull DBTTask task,
@NotNull Locale locale,
@@ -44,12 +49,12 @@ public abstract class SQLToolExecuteHandler implements DBTTaskHandler {
@NotNull Writer logStream,
@NotNull DBTTaskExecutionListener listener) throws DBException
{
- SQLToolExecuteSettings settings = new SQLToolExecuteSettings();
+ SETTINGS settings = createToolSettings();
settings.loadConfiguration(runnableContext, task.getProperties());
executeWithSettings(runnableContext, task, locale, log, logStream, listener, settings);
}
- private void executeWithSettings(@NotNull DBRRunnableContext runnableContext, DBTTask task, @NotNull Locale locale, @NotNull Log log, Writer logStream, @NotNull DBTTaskExecutionListener listener, SQLToolExecuteSettings settings) throws DBException {
+ private void executeWithSettings(@NotNull DBRRunnableContext runnableContext, DBTTask task, @NotNull Locale locale, @NotNull Log log, Writer logStream, @NotNull DBTTaskExecutionListener listener, SETTINGS settings) throws DBException {
// Start consumers
listener.taskStarted(settings);
@@ -73,9 +78,20 @@ public abstract class SQLToolExecuteHandler implements DBTTaskHandler {
listener.taskFinished(settings, error);
}
- private void executeTool(DBRProgressMonitor monitor, DBTTask task, SQLToolExecuteSettings settings, Log log, Writer logStream) throws DBException {
- List objectList = settings.getObjectList();
+ private void executeTool(DBRProgressMonitor monitor, DBTTask task, SETTINGS settings, Log log, Writer logStream) throws DBException {
+ List queries = new ArrayList<>();
+ List objectList = settings.getObjectList();
+ for (OBJECT_TYPE object : objectList) {
+ try (DBCSession session = DBUtils.openMetaSession(monitor, object, "Generate tool queries")) {
+ generateObjectQueries(session, settings, queries, object);
+ }
+ }
}
+ @NotNull
+ protected abstract SETTINGS createToolSettings();
+
+ protected abstract void generateObjectQueries(DBCSession session, SETTINGS settings, List queries, OBJECT_TYPE object) throws DBCException;
+
}
diff --git a/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/task/DBTTaskType.java b/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/task/DBTTaskType.java
index b77447ffff4b866bec7f87dd2de414ab1dfba8b2..9bff384ff6f3ad4b8080ef181336da460cb8d562 100644
--- a/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/task/DBTTaskType.java
+++ b/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/task/DBTTaskType.java
@@ -53,4 +53,6 @@ public interface DBTTaskType {
@NotNull
DBTTaskHandler createHandler() throws DBException;
+ Class extends DBTTaskHandler> getHandlerClass();
+
}
diff --git a/plugins/org.jkiss.dbeaver.registry/src/org/jkiss/dbeaver/registry/task/TaskTypeDescriptor.java b/plugins/org.jkiss.dbeaver.registry/src/org/jkiss/dbeaver/registry/task/TaskTypeDescriptor.java
index 9682973a7a1267191292e0b4b7c69584a727da4c..f97cc62bfbf75c9074881564441af7d872e015e4 100644
--- a/plugins/org.jkiss.dbeaver.registry/src/org/jkiss/dbeaver/registry/task/TaskTypeDescriptor.java
+++ b/plugins/org.jkiss.dbeaver.registry/src/org/jkiss/dbeaver/registry/task/TaskTypeDescriptor.java
@@ -122,6 +122,11 @@ public class TaskTypeDescriptor extends AbstractContextDescriptor implements DBT
return handlerImplType.createInstance(DBTTaskHandler.class);
}
+ @Override
+ public Class extends DBTTaskHandler> getHandlerClass() {
+ return handlerImplType.getObjectClass(DBTTaskHandler.class);
+ }
+
@Override
public String toString() {
return getId();
diff --git a/plugins/org.jkiss.dbeaver.tasks.sql.ui/META-INF/MANIFEST.MF b/plugins/org.jkiss.dbeaver.tasks.sql.ui/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000000000000000000000000000000000..ec97841cb98d0e50c735b97492bee7ce56c28ce5
--- /dev/null
+++ b/plugins/org.jkiss.dbeaver.tasks.sql.ui/META-INF/MANIFEST.MF
@@ -0,0 +1,26 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Vendor: DBeaver Corp
+Bundle-Name: DBeaver Tasks - SQL Tools UI
+Bundle-SymbolicName: org.jkiss.dbeaver.tasks.sql.ui;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-Release-Date: 20200601
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
+Bundle-ActivationPolicy: lazy
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.swt,
+ org.eclipse.core.resources,
+ org.eclipse.jface,
+ org.eclipse.jface.text,
+ org.eclipse.ui,
+ org.eclipse.ui.editors,
+ org.eclipse.ui.views,
+ org.eclipse.ui.workbench,
+ org.eclipse.ui.workbench.texteditor,
+ org.jkiss.dbeaver.model,
+ org.jkiss.dbeaver.model.sql,
+ org.jkiss.dbeaver.registry,
+ org.jkiss.dbeaver.tasks.ui,
+ org.jkiss.dbeaver.ui
+Bundle-ClassPath: .
+Automatic-Module-Name: org.jkiss.dbeaver.tasks.sql.ui
diff --git a/plugins/org.jkiss.dbeaver.tasks.sql.ui/OSGI-INF/l10n/bundle.properties b/plugins/org.jkiss.dbeaver.tasks.sql.ui/OSGI-INF/l10n/bundle.properties
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/plugins/org.jkiss.dbeaver.tasks.sql.ui/build.properties b/plugins/org.jkiss.dbeaver.tasks.sql.ui/build.properties
new file mode 100644
index 0000000000000000000000000000000000000000..3c833df018f8d70ced93e47092c72a9f05b1bc58
--- /dev/null
+++ b/plugins/org.jkiss.dbeaver.tasks.sql.ui/build.properties
@@ -0,0 +1,6 @@
+source.. = src/
+output.. = target/classes/
+bin.includes = .,\
+ META-INF/,\
+ OSGI-INF/,\
+ plugin.xml
diff --git a/plugins/org.jkiss.dbeaver.tasks.sql.ui/plugin.xml b/plugins/org.jkiss.dbeaver.tasks.sql.ui/plugin.xml
new file mode 100644
index 0000000000000000000000000000000000000000..a29e0b7dd1b40d5dbcea84de10031a684b10a3cd
--- /dev/null
+++ b/plugins/org.jkiss.dbeaver.tasks.sql.ui/plugin.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
diff --git a/plugins/org.jkiss.dbeaver.tasks.sql.ui/pom.xml b/plugins/org.jkiss.dbeaver.tasks.sql.ui/pom.xml
new file mode 100644
index 0000000000000000000000000000000000000000..789e6966ddf344213e9662529b8f2f95806efcdd
--- /dev/null
+++ b/plugins/org.jkiss.dbeaver.tasks.sql.ui/pom.xml
@@ -0,0 +1,16 @@
+
+
+ 4.0.0
+
+ org.jkiss.dbeaver
+ plugins
+ 1.0.0-SNAPSHOT
+ ../
+
+ org.jkiss.dbeaver.tasks.sql.ui
+ 1.0.0-SNAPSHOT
+ eclipse-plugin
+
+
diff --git a/plugins/org.jkiss.dbeaver.tasks.sql.ui/src/org/jkiss/dbeaver/tasks/ui/sql/SQLToolTaskConfigurationWizard.java b/plugins/org.jkiss.dbeaver.tasks.sql.ui/src/org/jkiss/dbeaver/tasks/ui/sql/SQLToolTaskConfigurationWizard.java
new file mode 100644
index 0000000000000000000000000000000000000000..7d0d08edb9907c8d2de8beb0b765e7b67fc0dad3
--- /dev/null
+++ b/plugins/org.jkiss.dbeaver.tasks.sql.ui/src/org/jkiss/dbeaver/tasks/ui/sql/SQLToolTaskConfigurationWizard.java
@@ -0,0 +1,67 @@
+/*
+ * DBeaver - Universal Database Manager
+ * Copyright (C) 2010-2020 DBeaver Corp and others
+ *
+ * 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.tasks.ui.sql;
+
+import org.jkiss.code.NotNull;
+import org.jkiss.dbeaver.model.runtime.DBRRunnableContext;
+import org.jkiss.dbeaver.model.sql.task.SQLToolExecuteSettings;
+import org.jkiss.dbeaver.model.task.DBTTask;
+import org.jkiss.dbeaver.tasks.ui.wizard.TaskConfigurationWizard;
+import org.jkiss.dbeaver.ui.UIUtils;
+
+import java.util.Map;
+
+class SQLToolTaskConfigurationWizard extends TaskConfigurationWizard {
+ private SQLToolExecuteSettings settings = new SQLToolExecuteSettings();
+ private SQLToolTaskPageSettings pageSettings;
+
+ public SQLToolTaskConfigurationWizard() {
+ }
+
+ public SQLToolTaskConfigurationWizard(@NotNull DBTTask task) {
+ super(task);
+ settings.loadConfiguration(UIUtils.getDefaultRunnableContext(), task.getProperties());
+ }
+
+ @Override
+ protected String getDefaultWindowTitle() {
+ return "Script Execute";
+ }
+
+ @Override
+ public String getTaskTypeId() {
+ return getCurrentTask().getType().getId();
+ }
+
+ @Override
+ public void addPages() {
+ super.addPages();
+ pageSettings = new SQLToolTaskPageSettings(this);
+ addPage(pageSettings);
+ }
+
+ @Override
+ public void saveTaskState(DBRRunnableContext runnableContext, DBTTask task, Map state) {
+ //pageSettings.saveSettings();
+
+ settings.saveConfiguration(state);
+ }
+
+ public SQLToolExecuteSettings getSettings() {
+ return settings;
+ }
+}
diff --git a/plugins/org.jkiss.dbeaver.tasks.sql.ui/src/org/jkiss/dbeaver/tasks/ui/sql/SQLToolTaskConfigurator.java b/plugins/org.jkiss.dbeaver.tasks.sql.ui/src/org/jkiss/dbeaver/tasks/ui/sql/SQLToolTaskConfigurator.java
new file mode 100644
index 0000000000000000000000000000000000000000..e855ddb9a0ce99aae3d220f48e1476a220f9c7ca
--- /dev/null
+++ b/plugins/org.jkiss.dbeaver.tasks.sql.ui/src/org/jkiss/dbeaver/tasks/ui/sql/SQLToolTaskConfigurator.java
@@ -0,0 +1,90 @@
+/*
+ * DBeaver - Universal Database Manager
+ * Copyright (C) 2010-2020 DBeaver Corp and others
+ *
+ * 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.tasks.ui.sql;
+
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Table;
+import org.jkiss.code.NotNull;
+import org.jkiss.dbeaver.Log;
+import org.jkiss.dbeaver.model.app.DBPProject;
+import org.jkiss.dbeaver.model.runtime.DBRRunnableContext;
+import org.jkiss.dbeaver.model.task.DBTTask;
+import org.jkiss.dbeaver.model.task.DBTTaskType;
+import org.jkiss.dbeaver.tasks.ui.DBTTaskConfigPanel;
+import org.jkiss.dbeaver.tasks.ui.DBTTaskConfigurator;
+import org.jkiss.dbeaver.tasks.ui.wizard.TaskConfigurationWizard;
+
+/**
+ * SQL tool task configurator
+ */
+public class SQLToolTaskConfigurator implements DBTTaskConfigurator {
+
+ private static final Log log = Log.getLog(SQLToolTaskConfigurator.class);
+
+ @Override
+ public ConfigPanel createInputConfigurator(DBRRunnableContext runnableContext, @NotNull DBTTaskType taskType) {
+ return new ConfigPanel(runnableContext, taskType);
+ }
+
+ @Override
+ public TaskConfigurationWizard createTaskConfigWizard(@NotNull DBTTask taskConfiguration) {
+ return new SQLToolTaskConfigurationWizard(taskConfiguration);
+ }
+
+ private static class ConfigPanel implements DBTTaskConfigPanel {
+
+ private DBRRunnableContext runnableContext;
+ private DBTTaskType taskType;
+ private Table objectsTable;
+ private DBPProject currentProject;
+ private SQLToolTaskConfigurationWizard dtWizard;
+
+ ConfigPanel(DBRRunnableContext runnableContext, DBTTaskType taskType) {
+ this.runnableContext = runnableContext;
+ this.taskType = taskType;
+ //this.currentProject = NavigatorUtils.getSelectedProject();
+ }
+
+ @Override
+ public void createControl(Composite parent, TaskConfigurationWizard wizard, Runnable propertyChangeListener) {
+ dtWizard = (SQLToolTaskConfigurationWizard) wizard;
+ }
+
+ @Override
+ public void loadSettings() {
+ }
+
+ @Override
+ public void saveSettings() {
+ }
+
+ @Override
+ public boolean isComplete() {
+ return objectsTable.getItemCount() > 0;
+ }
+
+ @Override
+ public String getErrorMessage() {
+ if (objectsTable.getItemCount() == 0) {
+ return "No objects selected";
+ }
+ return null;
+ }
+ }
+
+}
diff --git a/plugins/org.jkiss.dbeaver.tasks.sql.ui/src/org/jkiss/dbeaver/tasks/ui/sql/SQLToolTaskPageSettings.java b/plugins/org.jkiss.dbeaver.tasks.sql.ui/src/org/jkiss/dbeaver/tasks/ui/sql/SQLToolTaskPageSettings.java
new file mode 100644
index 0000000000000000000000000000000000000000..9956b2097b77479063d9c12b26a0094c11503e86
--- /dev/null
+++ b/plugins/org.jkiss.dbeaver.tasks.sql.ui/src/org/jkiss/dbeaver/tasks/ui/sql/SQLToolTaskPageSettings.java
@@ -0,0 +1,401 @@
+/*
+ * DBeaver - Universal Database Manager
+ * Copyright (C) 2010-2020 DBeaver Corp and others
+ *
+ * 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.tasks.ui.sql;
+
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.jkiss.dbeaver.Log;
+import org.jkiss.dbeaver.model.DBPDataSourceContainer;
+import org.jkiss.dbeaver.model.navigator.DBNDataSource;
+import org.jkiss.dbeaver.model.navigator.DBNProject;
+import org.jkiss.dbeaver.model.navigator.DBNResource;
+import org.jkiss.dbeaver.runtime.DBWorkbench;
+import org.jkiss.dbeaver.ui.UIUtils;
+import org.jkiss.dbeaver.ui.dialogs.ActiveWizardPage;
+import org.jkiss.utils.CommonUtils;
+
+import java.util.*;
+
+/**
+ * SQL task settings page
+ */
+class SQLToolTaskPageSettings extends ActiveWizardPage {
+
+ private static final Log log = Log.getLog(SQLToolTaskPageSettings.class);
+
+ private SQLToolTaskConfigurationWizard sqlWizard;
+ private Button ignoreErrorsCheck;
+ private Button dumpQueryCheck;
+ private Button autoCommitCheck;
+ private TableViewer scriptsViewer;
+ private TableViewer dataSourceViewer;
+
+ private List selectedScripts = new ArrayList<>();
+ private List selectedDataSources = new ArrayList<>();
+
+ SQLToolTaskPageSettings(SQLToolTaskConfigurationWizard wizard) {
+ super("Tool parameters");
+ setTitle("Tool parameters");
+ setDescription("Parameters for database tool");
+ this.sqlWizard = wizard;
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ initializeDialogUnits(parent);
+
+ Composite composite = UIUtils.createComposite(parent, 1);
+ composite.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+/*
+ SQLScriptExecuteSettings dtSettings = getWizard().getSettings();
+
+ SashForm mainGroup = new SashForm(composite, SWT.NONE);
+ mainGroup.setSashWidth(5);
+ mainGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ DBNProject projectNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(sqlWizard.getProject());
+
+ {
+ Composite filesGroup = UIUtils.createControlGroup(mainGroup, DTMessages.sql_script_task_page_settings_group_files, 2, GridData.FILL_BOTH, 0);
+
+ scriptsViewer = new TableViewer(filesGroup, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
+ scriptsViewer.setContentProvider(new ListContentProvider());
+ scriptsViewer.getTable().setHeaderVisible(true);
+ scriptsViewer.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ return ((DBNResource) element).getResource().getProjectRelativePath().toString();
+ }
+ @Override
+ public Image getImage(Object element) {
+ return DBeaverIcons.getImage(((DBNResource)element).getNodeIconDefault());
+ }
+
+ });
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ gd.heightHint = 300;
+ gd.widthHint = 400;
+ scriptsViewer.getTable().setLayoutData(gd);
+ SQLTaskScriptSelectorDialog.createScriptColumns(scriptsViewer);
+
+ final Table scriptTable = scriptsViewer.getTable();
+ scriptTable.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ ToolBar buttonsToolbar = new ToolBar(filesGroup, SWT.VERTICAL);
+ buttonsToolbar.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
+ UIUtils.createToolItem(buttonsToolbar, "Add script", UIIcon.ROW_ADD, new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ SQLTaskScriptSelectorDialog dialog = new SQLTaskScriptSelectorDialog(getShell(), projectNode);
+ if (dialog.open() == IDialogConstants.OK_ID) {
+ for (DBNResource script : dialog.getSelectedScripts()) {
+ if (!selectedScripts.contains(script)) {
+ selectedScripts.add(script);
+ }
+ }
+ refreshScripts();
+ }
+ }
+ });
+ ToolItem deleteItem = UIUtils.createToolItem(buttonsToolbar, "Remove script", UIIcon.ROW_DELETE, new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ ISelection selection = scriptsViewer.getSelection();
+ if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
+ for (Object element : ((IStructuredSelection) selection).toArray()) {
+ if (element instanceof DBNResource) {
+ selectedScripts.remove(element);
+ }
+ }
+ refreshScripts();
+ }
+ }
+ });
+ UIUtils.createToolBarSeparator(buttonsToolbar, SWT.HORIZONTAL);
+ ToolItem moveUpItem = UIUtils.createToolItem(buttonsToolbar, "Move script up", UIIcon.ARROW_UP, new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ int selectionIndex = scriptTable.getSelectionIndex();
+ if (selectionIndex > 0) {
+ DBNResource prevScript = selectedScripts.get(selectionIndex - 1);
+ selectedScripts.set(selectionIndex - 1, selectedScripts.get(selectionIndex));
+ selectedScripts.set(selectionIndex, prevScript);
+ refreshScripts();
+ }
+ }
+ });
+ ToolItem moveDownItem = UIUtils.createToolItem(buttonsToolbar, "Move script down", UIIcon.ARROW_DOWN, new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ int selectionIndex = scriptTable.getSelectionIndex();
+ if (selectionIndex < scriptTable.getItemCount() - 1) {
+ DBNResource nextScript = selectedScripts.get(selectionIndex + 1);
+ selectedScripts.set(selectionIndex + 1, selectedScripts.get(selectionIndex));
+ selectedScripts.set(selectionIndex, nextScript);
+ refreshScripts();
+ }
+ }
+ });
+ scriptsViewer.addSelectionChangedListener(event -> {
+ int selectionIndex = scriptTable.getSelectionIndex();
+ deleteItem.setEnabled(selectionIndex >= 0);
+ moveUpItem.setEnabled(selectionIndex > 0);
+ moveDownItem.setEnabled(selectionIndex < scriptTable.getItemCount() - 1);
+ });
+ deleteItem.setEnabled(false);
+ }
+
+ {
+ Composite connectionsGroup = UIUtils.createControlGroup(mainGroup, DTMessages.sql_script_task_page_settings_group_connections, 2, GridData.FILL_BOTH, 0);
+
+ dataSourceViewer = new TableViewer(connectionsGroup, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
+ dataSourceViewer.setContentProvider(new ListContentProvider());
+ //dataSourceViewer.getTable().setHeaderVisible(true);
+ dataSourceViewer.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
+ return ((DBNDataSource) element).getNodeName();
+ }
+ @Override
+ public Image getImage(Object element) {
+ return DBeaverIcons.getImage(((DBNDataSource)element).getNodeIcon());
+ }
+ });
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ gd.heightHint = 300;
+ gd.widthHint = 400;
+ dataSourceViewer.getTable().setLayoutData(gd);
+
+ final Table dsTable = dataSourceViewer.getTable();
+ dsTable.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ ToolBar buttonsToolbar = new ToolBar(connectionsGroup, SWT.VERTICAL);
+ buttonsToolbar.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
+ UIUtils.createToolItem(buttonsToolbar, "Add datasource", UIIcon.ROW_ADD, new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ SQLTaskDataSourceSelectorDialog dialog = new SQLTaskDataSourceSelectorDialog(getShell(), projectNode);
+ if (dialog.open() == IDialogConstants.OK_ID) {
+ for (DBNDataSource ds : dialog.getSelectedDataSources()) {
+ if (!selectedDataSources.contains(ds)) {
+ selectedDataSources.add(ds);
+ }
+ }
+ refreshDataSources();
+ }
+ }
+ });
+ ToolItem deleteItem = UIUtils.createToolItem(buttonsToolbar, "Remove datasource", UIIcon.ROW_DELETE, new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ ISelection selection = dataSourceViewer.getSelection();
+ if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
+ for (Object element : ((IStructuredSelection) selection).toArray()) {
+ if (element instanceof DBNDataSource) {
+ selectedDataSources.remove(element);
+ }
+ }
+ refreshDataSources();
+ }
+ }
+ });
+ UIUtils.createToolBarSeparator(buttonsToolbar, SWT.HORIZONTAL);
+ ToolItem moveUpItem = UIUtils.createToolItem(buttonsToolbar, "Move datasource up", UIIcon.ARROW_UP, new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ int selectionIndex = dsTable.getSelectionIndex();
+ if (selectionIndex > 0) {
+ DBNDataSource prevScript = selectedDataSources.get(selectionIndex - 1);
+ selectedDataSources.set(selectionIndex - 1, selectedDataSources.get(selectionIndex));
+ selectedDataSources.set(selectionIndex, prevScript);
+ refreshDataSources();
+ }
+ }
+ });
+ ToolItem moveDownItem = UIUtils.createToolItem(buttonsToolbar, "Move datasource down", UIIcon.ARROW_DOWN, new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ int selectionIndex = dsTable.getSelectionIndex();
+ if (selectionIndex < dsTable.getItemCount() - 1) {
+ DBNDataSource nextScript = selectedDataSources.get(selectionIndex + 1);
+ selectedDataSources.set(selectionIndex + 1, selectedDataSources.get(selectionIndex));
+ selectedDataSources.set(selectionIndex, nextScript);
+ refreshScripts();
+ }
+ }
+ });
+ dataSourceViewer.addSelectionChangedListener(event -> {
+ int selectionIndex = dsTable.getSelectionIndex();
+ deleteItem.setEnabled(selectionIndex >= 0);
+ moveUpItem.setEnabled(selectionIndex > 0);
+ moveDownItem.setEnabled(selectionIndex < dsTable.getItemCount() - 1);
+ });
+ deleteItem.setEnabled(false);
+ }
+
+ {
+ Composite settingsGroup = UIUtils.createControlGroup(composite, DTMessages.sql_script_task_page_settings_group_script, 3, GridData.HORIZONTAL_ALIGN_BEGINNING, 0);
+
+ ignoreErrorsCheck = UIUtils.createCheckbox(settingsGroup, DTMessages.sql_script_task_page_settings_option_ignore_errors, "", dtSettings.isIgnoreErrors(), 1);
+ dumpQueryCheck = UIUtils.createCheckbox(settingsGroup, DTMessages.sql_script_task_page_settings_option_dump_results, "", dtSettings.isDumpQueryResultsToLog(), 1);
+ dumpQueryCheck.setEnabled(false);
+ autoCommitCheck = UIUtils.createCheckbox(settingsGroup, DTMessages.sql_script_task_page_settings_option_auto_commit, "", dtSettings.isAutoCommit(), 1);
+ }
+
+ getWizard().createTaskSaveButtons(composite, true, 1);
+
+ loadSettings();
+*/
+
+ setControl(composite);
+ }
+
+ private void refreshScripts() {
+ scriptsViewer.refresh(true, true);
+ updateSelectedScripts();
+ }
+
+ private void refreshDataSources() {
+ dataSourceViewer.refresh(true, true);
+ }
+
+ private void updateSelectedScripts() {
+ DBNProject projectNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(sqlWizard.getProject());
+
+ Set dataSources = new LinkedHashSet<>();
+ for (DBNResource element : selectedScripts) {
+ Collection resDS = element.getAssociatedDataSources();
+ if (!CommonUtils.isEmpty(resDS)) {
+ dataSources.addAll(resDS);
+ }
+ }
+
+ if (!dataSources.isEmpty()) {
+ List checkedDataSources = new ArrayList<>();
+ for (DBPDataSourceContainer ds : dataSources) {
+ DBNDataSource dsNode = projectNode.getDatabases().getDataSource(ds);
+ if (dsNode != null) {
+ checkedDataSources.add(dsNode);
+ }
+ }
+ if (!checkedDataSources.isEmpty()) {
+ refreshDataSources();
+ for (DBNDataSource dsNode : checkedDataSources) {
+ if (!selectedDataSources.contains(dsNode)) {
+ selectedDataSources.add(dsNode);
+ }
+ }
+ }
+ }
+ refreshDataSources();
+ updatePageCompletion();
+ }
+
+ @Override
+ public void activatePage() {
+ updatePageCompletion();
+ }
+
+ @Override
+ public void deactivatePage() {
+ }
+
+ @Override
+ protected boolean determinePageCompletion() {
+ if (selectedScripts.isEmpty()) {
+ setErrorMessage("You must select script(s) to execute");
+ return false;
+ }
+ if (selectedDataSources.isEmpty()) {
+ setErrorMessage("You must select connection(s)");
+ return false;
+ }
+ setErrorMessage(null);
+ return true;
+ }
+
+/*
+ public void loadSettings() {
+ SQLScriptExecuteSettings settings = sqlWizard.getSettings();
+
+ List scriptFiles = settings.getScriptFiles();
+ for (String filePath : scriptFiles) {
+ IFile file = SQLScriptExecuteSettings.getWorkspaceFile(filePath);
+ if (file == null) {
+ log.debug("Script file '" + filePath + "' not found");
+ continue;
+ }
+ DBPProject currentProject = DBWorkbench.getPlatform().getWorkspace().getProject(file.getProject());
+ if (currentProject == null) {
+ log.debug("Project '" + file.getProject().getName() + "' not found");
+ continue;
+ }
+ DBNProject projectNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(currentProject);
+ if (projectNode != null) {
+ DBNResource resource = projectNode.findResource(file);
+ if (resource != null) {
+ selectedScripts.add(resource);
+ }
+ }
+ }
+ scriptsViewer.setInput(selectedScripts);
+
+ for (DBPDataSourceContainer dataSource : settings.getDataSources()) {
+ DBNProject projectNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(dataSource.getProject());
+ DBNDataSource dsNode = projectNode.getDatabases().getDataSource(dataSource);
+ if (dsNode != null) {
+ selectedDataSources.add(dsNode);
+ }
+ }
+
+ dataSourceViewer.setInput(selectedDataSources);
+// if (!selectedDataSources.isEmpty()) {
+// dataSourceTree.getCheckboxViewer().setCheckedElements(selectedDataSources.toArray());
+// dataSourceTree.getCheckboxViewer().reveal(selectedDataSources.get(0));
+// }
+ }
+
+ public void saveSettings() {
+ if (sqlWizard == null) {
+ return;
+ }
+ SQLScriptExecuteSettings settings = sqlWizard.getSettings();
+
+ List scriptPaths = new ArrayList<>();
+ for (DBNResource resource : selectedScripts) {
+ IResource res = resource.getResource();
+ if (res instanceof IFile) {
+ scriptPaths.add(res.getFullPath().toString());
+ }
+ }
+ settings.setScriptFiles(scriptPaths);
+ List dsList = new ArrayList<>();
+ for (DBNDataSource dsNode : selectedDataSources) {
+ dsList.add(dsNode.getDataSourceContainer());
+ }
+ settings.setDataSources(dsList);
+
+ settings.setIgnoreErrors(ignoreErrorsCheck.getSelection());
+ settings.setDumpQueryResultsToLog(dumpQueryCheck.getSelection());
+ settings.setAutoCommit(autoCommitCheck.getSelection());
+ }
+*/
+
+}
\ No newline at end of file
diff --git a/plugins/org.jkiss.dbeaver.tasks.ui/src/org/jkiss/dbeaver/tasks/ui/registry/TaskConfiguratorDescriptor.java b/plugins/org.jkiss.dbeaver.tasks.ui/src/org/jkiss/dbeaver/tasks/ui/registry/TaskConfiguratorDescriptor.java
index 2e8c6cdd71045c4bb759b7821fe271d5941cdac2..6d3280bae2e7fab5836d9ad12e2edadbdc208d72 100644
--- a/plugins/org.jkiss.dbeaver.tasks.ui/src/org/jkiss/dbeaver/tasks/ui/registry/TaskConfiguratorDescriptor.java
+++ b/plugins/org.jkiss.dbeaver.tasks.ui/src/org/jkiss/dbeaver/tasks/ui/registry/TaskConfiguratorDescriptor.java
@@ -31,14 +31,25 @@ import org.jkiss.utils.CommonUtils;
public class TaskConfiguratorDescriptor extends AbstractContextDescriptor {
private final TaskTypeDescriptor type;
+ private final ObjectType taskHandlerType;
private final IConfigurationElement config;
private final ObjectType implType;
private final boolean supportsPanel;
+ TaskConfiguratorDescriptor(IConfigurationElement config) {
+ super(config);
+ this.type = null;
+ this.config = config;
+ this.taskHandlerType = new ObjectType(config, "handler");
+ this.implType = new ObjectType(config, "class");
+ this.supportsPanel = CommonUtils.getBoolean(config.getAttribute("supportsPanel"), true);
+ }
+
TaskConfiguratorDescriptor(TaskTypeDescriptor type, IConfigurationElement config) {
super(config);
this.type = type;
this.config = config;
+ this.taskHandlerType = null;
this.implType = new ObjectType(config, "class");
this.supportsPanel = CommonUtils.getBoolean(config.getAttribute("supportsPanel"), true);
}
@@ -58,6 +69,10 @@ public class TaskConfiguratorDescriptor extends AbstractContextDescriptor {
return type;
}
+ public ObjectType getTaskHandlerType() {
+ return taskHandlerType;
+ }
+
@NotNull
public DBTTaskConfigurator createConfigurator() throws DBException {
return implType.createInstance(DBTTaskConfigurator.class);
diff --git a/plugins/org.jkiss.dbeaver.tasks.ui/src/org/jkiss/dbeaver/tasks/ui/registry/TaskUIRegistry.java b/plugins/org.jkiss.dbeaver.tasks.ui/src/org/jkiss/dbeaver/tasks/ui/registry/TaskUIRegistry.java
index a8683f340dd7b4f821b315c4c57c82a0db12b6e7..5abefe239492fe9c8fc17bc929fc049b345e00b7 100644
--- a/plugins/org.jkiss.dbeaver.tasks.ui/src/org/jkiss/dbeaver/tasks/ui/registry/TaskUIRegistry.java
+++ b/plugins/org.jkiss.dbeaver.tasks.ui/src/org/jkiss/dbeaver/tasks/ui/registry/TaskUIRegistry.java
@@ -22,12 +22,16 @@ import org.eclipse.core.runtime.Platform;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.exec.DBCException;
+import org.jkiss.dbeaver.model.task.DBTTaskHandler;
import org.jkiss.dbeaver.model.task.DBTTaskType;
import org.jkiss.dbeaver.registry.task.TaskRegistry;
import org.jkiss.dbeaver.registry.task.TaskTypeDescriptor;
import org.jkiss.dbeaver.tasks.ui.DBTTaskConfigurator;
+import org.jkiss.utils.CommonUtils;
+import java.util.ArrayList;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
public class TaskUIRegistry {
@@ -45,6 +49,7 @@ public class TaskUIRegistry {
}
private final Map taskConfigurators = new LinkedHashMap<>();
+ private final List taskHandlerConfigurators = new ArrayList<>();
private TaskUIRegistry(IExtensionRegistry registry) {
IConfigurationElement[] extElements = registry.getConfigurationElementsFor(TASK_EXTENSION_ID);
@@ -54,7 +59,12 @@ public class TaskUIRegistry {
String typeId = ext.getAttribute("type");
TaskTypeDescriptor taskType = TaskRegistry.getInstance().getTaskType(typeId);
if (taskType == null) {
- log.debug("Task type '" + typeId + "' not found. Skip configurator.");
+ if (!CommonUtils.isEmpty(ext.getAttribute("handler"))) {
+ TaskConfiguratorDescriptor configDescriptor = new TaskConfiguratorDescriptor(ext);
+ taskHandlerConfigurators.add(configDescriptor);
+ } else {
+ log.debug("Task type '" + typeId + "' not found. Skip configurator.");
+ }
} else {
TaskConfiguratorDescriptor configDescriptor = new TaskConfiguratorDescriptor(taskType, ext);
taskConfigurators.put(taskType, configDescriptor);
@@ -78,7 +88,18 @@ public class TaskUIRegistry {
public DBTTaskConfigurator createConfigurator(DBTTaskType taskType) throws DBCException {
TaskConfiguratorDescriptor configuratorDescriptor = taskConfigurators.get(taskType);
if (configuratorDescriptor == null) {
- throw new DBCException("Task configurator not supported for " + taskType.getName());
+ Class extends DBTTaskHandler> handlerClass = taskType.getHandlerClass();
+ if (handlerClass != null) {
+ for (TaskConfiguratorDescriptor tcd : taskHandlerConfigurators) {
+ if (tcd.getTaskHandlerType().getObjectClass().isAssignableFrom(handlerClass)) {
+ configuratorDescriptor = tcd;
+ break;
+ }
+ }
+ }
+ if (configuratorDescriptor == null) {
+ throw new DBCException("Task configurator not supported for " + taskType.getName());
+ }
}
try {
return configuratorDescriptor.createConfigurator();
diff --git a/plugins/pom.xml b/plugins/pom.xml
index 5f945dfd440ea73478efc7a467be1c2d2d23f3c9..82462aa65f4d155070ef31ff2ed8cf28ccabf91e 100644
--- a/plugins/pom.xml
+++ b/plugins/pom.xml
@@ -117,6 +117,7 @@
org.jkiss.dbeaver.ext.erd
org.jkiss.dbeaver.tasks.native.ui
org.jkiss.dbeaver.tasks.ui
+ org.jkiss.dbeaver.tasks.sql.ui
org.jkiss.dbeaver.data.office.ui
org.jkiss.dbeaver.ext.sample.database