diff --git a/plugins/org.jkiss.dbeaver.core/OSGI-INF/l10n/bundle.properties b/plugins/org.jkiss.dbeaver.core/OSGI-INF/l10n/bundle.properties
index a57f2327c6a7345da6a034078d3e345f1e46a34d..b6f925af3ec698cb0a478ce662f3170ebfeba71d 100644
--- a/plugins/org.jkiss.dbeaver.core/OSGI-INF/l10n/bundle.properties
+++ b/plugins/org.jkiss.dbeaver.core/OSGI-INF/l10n/bundle.properties
@@ -12,6 +12,7 @@ extension-point.org.jkiss.dbeaver.dataTransfer.name = Data Transfer Provider
extension-point.org.jkiss.dbeaver.dataFormatter.name = Data Formatters
extension-point.org.jkiss.dbeaver.aggregateFunction.name = Aggregate Functions
extension-point.org.jkiss.dbeaver.sqlCommand.name = SQL script commands
+extension-point.org.jkiss.dbeaver.sqlFormatter.name = SQL formatters
extension-point.org.jkiss.dbeaver.resourceHandler.name = Resource Handlers
extension-point.org.jkiss.dbeaver.networkHandler.name = Network Handlers
extension-point.org.jkiss.dbeaver.resources.name = Resources
diff --git a/plugins/org.jkiss.dbeaver.core/plugin.xml b/plugins/org.jkiss.dbeaver.core/plugin.xml
index 41fa93b02ada685b63f717bd8c4cde3bcc8cf43d..0315853c12948fed80498bb7ce3ea30db40c530e 100644
--- a/plugins/org.jkiss.dbeaver.core/plugin.xml
+++ b/plugins/org.jkiss.dbeaver.core/plugin.xml
@@ -28,13 +28,14 @@
-
+
+
@@ -3300,6 +3301,11 @@
+
+
+
+
+
+
+
+
+
+
+
+ [Enter description of this extension point.]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ [Enter the first release in which this extension point appears.]
+
+
+
+
+
+
+
+
+ [Enter extension point usage example here.]
+
+
+
+
+
+
+
+
+ [Enter API information here.]
+
+
+
+
+
+
+
+
+ [Enter information about supplied implementation of this extension point.]
+
+
+
+
+
diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/core/DBeaverCore.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/core/DBeaverCore.java
index 95b793d149f207b02055756b5ba35100cbf6cce4..7906034ad20078bb3f7bdc6b4a734b8bd54027df 100644
--- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/core/DBeaverCore.java
+++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/core/DBeaverCore.java
@@ -40,11 +40,13 @@ import org.jkiss.dbeaver.model.qm.QMController;
import org.jkiss.dbeaver.model.qm.QMUtils;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.OSDescriptor;
+import org.jkiss.dbeaver.model.sql.format.SQLFormatterRegistry;
import org.jkiss.dbeaver.registry.DataSourceProviderRegistry;
import org.jkiss.dbeaver.registry.PluginServiceRegistry;
import org.jkiss.dbeaver.registry.ProjectRegistry;
import org.jkiss.dbeaver.registry.datatype.DataTypeProviderRegistry;
import org.jkiss.dbeaver.registry.editor.EntityEditorsRegistry;
+import org.jkiss.dbeaver.registry.sql.SQLFormatterConfigurationRegistry;
import org.jkiss.dbeaver.runtime.IPluginService;
import org.jkiss.dbeaver.runtime.jobs.KeepAliveJob;
import org.jkiss.dbeaver.runtime.net.GlobalProxySelector;
@@ -349,6 +351,11 @@ public class DBeaverCore implements DBPPlatform {
return EntityEditorsRegistry.getInstance();
}
+ @Override
+ public SQLFormatterRegistry getSQLFormatterRegistry() {
+ return SQLFormatterConfigurationRegistry.getInstance();
+ }
+
@NotNull
@Override
public DBPPreferenceStore getPreferenceStore() {
diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/sql/SQLFormatterConfigurationRegistry.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/sql/SQLFormatterConfigurationRegistry.java
new file mode 100644
index 0000000000000000000000000000000000000000..d023f4bd7abde96bfa70f2f510f76e999daab031
--- /dev/null
+++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/sql/SQLFormatterConfigurationRegistry.java
@@ -0,0 +1,125 @@
+/*
+ * 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.registry.sql;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
+import org.jkiss.code.Nullable;
+import org.jkiss.dbeaver.DBException;
+import org.jkiss.dbeaver.Log;
+import org.jkiss.dbeaver.model.sql.SQLUtils;
+import org.jkiss.dbeaver.model.sql.format.SQLFormatter;
+import org.jkiss.dbeaver.model.sql.format.SQLFormatterConfiguration;
+import org.jkiss.dbeaver.model.sql.format.SQLFormatterRegistry;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class SQLFormatterConfigurationRegistry implements SQLFormatterRegistry
+{
+ private static final Log log = Log.getLog(SQLFormatterConfigurationRegistry.class);
+
+ private static final String TAG_FORMATTER = "formatter"; //$NON-NLS-1$
+
+ private static SQLFormatterConfigurationRegistry instance = null;
+
+ public synchronized static SQLFormatterConfigurationRegistry getInstance()
+ {
+ if (instance == null) {
+ instance = new SQLFormatterConfigurationRegistry();
+ instance.loadExtensions(Platform.getExtensionRegistry());
+ }
+ return instance;
+ }
+
+ private final List formatters = new ArrayList<>();
+
+ private SQLFormatterConfigurationRegistry()
+ {
+ }
+
+ private void loadExtensions(IExtensionRegistry registry)
+ {
+ IConfigurationElement[] extConfigs = registry.getConfigurationElementsFor(SQLFormatterDescriptor.EXTENSION_ID);
+ for (IConfigurationElement ext : extConfigs) {
+ // Load formatters
+ if (TAG_FORMATTER.equals(ext.getName())) {
+ this.formatters.add(
+ new SQLFormatterDescriptor(ext));
+ }
+ }
+ }
+
+ public void dispose()
+ {
+ formatters.clear();
+ }
+
+ public List getFormatters() {
+ return formatters;
+ }
+
+ public SQLFormatterDescriptor getFormatter(String id) {
+ for (SQLFormatterDescriptor formatter : formatters) {
+ if (formatter.getId().equalsIgnoreCase(id)) {
+ return formatter;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ @Nullable
+ public SQLFormatter createFormatter(SQLFormatterConfiguration configuration) {
+ final String formatterId = configuration.getFormatterId();
+ SQLFormatterDescriptor formatterDesc = getFormatter(formatterId);
+ if (formatterDesc == null) {
+ log.error("Formatter '" + formatterId + "' not found");
+ return null;
+ }
+ try {
+ return formatterDesc.createFormatter();
+ } catch (DBException e) {
+ log.error("Error creating formatter", e);
+ return null;
+ }
+ }
+
+ @Override
+ @Nullable
+ public SQLFormatter createAndConfigureFormatter(SQLFormatterConfiguration configuration) {
+ final String formatterId = configuration.getFormatterId();
+ SQLFormatterDescriptor formatterDesc = getFormatter(formatterId);
+ if (formatterDesc == null) {
+ log.error("Formatter '" + formatterId + "' not found");
+ return null;
+ }
+ try {
+ SQLFormatter formatter = formatterDesc.createFormatter();
+ SQLFormatterConfigurer configurer = formatterDesc.createConfigurer();
+ if (configurer != null) {
+ configurer.configure(formatter, configuration);
+ }
+ return formatter;
+ } catch (DBException e) {
+ log.error("Error creating and configuring formatter", e);
+ return null;
+ }
+ }
+
+}
diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/sql/SQLFormatterConfigurer.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/sql/SQLFormatterConfigurer.java
new file mode 100644
index 0000000000000000000000000000000000000000..8b414b09638b16dd1057b74163681313105f344a
--- /dev/null
+++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/sql/SQLFormatterConfigurer.java
@@ -0,0 +1,29 @@
+/*
+ * 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.registry.sql;
+
+import org.jkiss.dbeaver.model.sql.format.SQLFormatter;
+import org.jkiss.dbeaver.model.sql.format.SQLFormatterConfiguration;
+
+/**
+ * SQL Formatter configurer
+ */
+public interface SQLFormatterConfigurer {
+
+ void configure(SQLFormatter formatter, SQLFormatterConfiguration configuration);
+
+}
diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/sql/SQLFormatterDescriptor.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/sql/SQLFormatterDescriptor.java
new file mode 100644
index 0000000000000000000000000000000000000000..74773ad7692ec11d20de320a73c23fc1d5f55a7d
--- /dev/null
+++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/sql/SQLFormatterDescriptor.java
@@ -0,0 +1,87 @@
+/*
+ * 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.registry.sql;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.jgit.annotations.Nullable;
+import org.jkiss.code.NotNull;
+import org.jkiss.dbeaver.DBException;
+import org.jkiss.dbeaver.model.impl.AbstractDescriptor;
+import org.jkiss.dbeaver.model.sql.format.SQLFormatter;
+import org.jkiss.dbeaver.registry.AbstractContextDescriptor;
+import org.jkiss.dbeaver.registry.RegistryConstants;
+import org.jkiss.utils.CommonUtils;
+
+/**
+ * SQLFormatterDescriptor
+ */
+public class SQLFormatterDescriptor extends AbstractContextDescriptor {
+
+ public static final String EXTENSION_ID = "org.jkiss.dbeaver.sqlFormatter"; //$NON-NLS-1$
+
+ private final String id;
+ private final String label;
+ private final String description;
+ private final AbstractDescriptor.ObjectType formatterImplClass;
+ private final AbstractDescriptor.ObjectType configurerImplClass;
+
+
+ public SQLFormatterDescriptor(IConfigurationElement config)
+ {
+ super(config);
+ this.id = config.getAttribute("id");
+ this.label = config.getAttribute("label");
+ this.description = config.getAttribute("description");
+ this.formatterImplClass = new AbstractDescriptor.ObjectType(config.getAttribute("class"));
+ if (!CommonUtils.isEmpty(config.getAttribute("configurerClass"))) {
+ this.configurerImplClass = new AbstractDescriptor.ObjectType(config.getAttribute("configurerClass"));
+ } else {
+ this.configurerImplClass = null;
+ }
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ @NotNull
+ public SQLFormatter createFormatter()
+ throws DBException
+ {
+ return formatterImplClass.createInstance(SQLFormatter.class);
+ }
+
+ @Nullable
+ public SQLFormatterConfigurer createConfigurer()
+ throws DBException
+ {
+ if (configurerImplClass == null) {
+ return null;
+ }
+ return configurerImplClass.createInstance(SQLFormatterConfigurer.class);
+ }
+
+}
diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/syntax/SQLFormattingStrategy.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/syntax/SQLFormattingStrategy.java
index da28b0110a0011b88c7c37dc64a7300e7e4df7c1..640a3dfd9158acf692169b6e6afaafc8cfa49c7f 100644
--- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/syntax/SQLFormattingStrategy.java
+++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/editors/sql/syntax/SQLFormattingStrategy.java
@@ -19,9 +19,11 @@ package org.jkiss.dbeaver.ui.editors.sql.syntax;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.formatter.ContextBasedFormattingStrategy;
import org.eclipse.jface.text.source.ISourceViewer;
+import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.model.sql.SQLSyntaxManager;
import org.jkiss.dbeaver.model.sql.format.SQLFormatter;
import org.jkiss.dbeaver.model.sql.format.SQLFormatterConfiguration;
+import org.jkiss.dbeaver.registry.sql.SQLFormatterConfigurationRegistry;
import org.jkiss.dbeaver.ui.editors.sql.SQLEditorSourceViewerConfiguration;
/**
@@ -55,7 +57,11 @@ public class SQLFormattingStrategy extends ContextBasedFormattingStrategy
SQLFormatterConfiguration configuration = new SQLFormatterConfiguration(sqlSyntax);
configuration.setIndentString(indentPrefixes[0]);
- SQLFormatter formatter = configuration.createFormatter();
+ SQLFormatter formatter = SQLFormatterConfigurationRegistry.getInstance().createAndConfigureFormatter(configuration);
+ if (formatter == null) {
+ DBeaverUI.getInstance().showError("SQL Format", "Can't create SQL formatter. See error log.");
+ return content;
+ }
return formatter.format(content, configuration);
}
diff --git a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/preferences/PrefPageSQLFormat.java b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/preferences/PrefPageSQLFormat.java
index 3fd55cdbd9c56efa8a36266f8fefa458ba52741d..bed6008794e4a069d41b9ea4bd0e8851a660e008 100644
--- a/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/preferences/PrefPageSQLFormat.java
+++ b/plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/ui/preferences/PrefPageSQLFormat.java
@@ -31,6 +31,7 @@ import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.IEditorSite;
import org.jkiss.dbeaver.ModelPreferences;
+import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
@@ -38,7 +39,8 @@ import org.jkiss.dbeaver.model.DBPIdentifierCase;
import org.jkiss.dbeaver.model.exec.DBCExecutionContext;
import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore;
import org.jkiss.dbeaver.model.sql.format.external.SQLExternalFormatter;
-import org.jkiss.dbeaver.model.sql.format.tokenized.SQLTokenizedFormatter;
+import org.jkiss.dbeaver.registry.sql.SQLFormatterConfigurationRegistry;
+import org.jkiss.dbeaver.registry.sql.SQLFormatterDescriptor;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.editors.StringEditorInput;
import org.jkiss.dbeaver.ui.editors.SubEditorSite;
@@ -48,9 +50,9 @@ import org.jkiss.dbeaver.utils.ContentUtils;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.dbeaver.utils.PrefUtils;
import org.jkiss.utils.CommonUtils;
-import org.jkiss.dbeaver.core.CoreMessages;
import java.io.InputStream;
+import java.util.List;
import java.util.Locale;
/**
@@ -81,6 +83,7 @@ public class PrefPageSQLFormat extends TargetPrefPage
private SQLEditorBase sqlViewer;
private Composite defaultGroup;
private Composite externalGroup;
+ private List formatters;
public PrefPageSQLFormat()
{
@@ -148,8 +151,10 @@ public class PrefPageSQLFormat extends TargetPrefPage
formatterPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
formatterSelector = UIUtils.createLabelCombo(formatterPanel, CoreMessages.pref_page_sql_format_label_formatter, SWT.DROP_DOWN | SWT.READ_ONLY);
- formatterSelector.add(capitalizeCaseName(SQLTokenizedFormatter.FORMATTER_ID));
- formatterSelector.add(capitalizeCaseName(SQLExternalFormatter.FORMATTER_ID));
+ formatters = SQLFormatterConfigurationRegistry.getInstance().getFormatters();
+ for (SQLFormatterDescriptor formatterDesc : formatters) {
+ formatterSelector.add(capitalizeCaseName(formatterDesc.getLabel()));
+ }
formatterSelector.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
@@ -259,8 +264,15 @@ public class PrefPageSQLFormat extends TargetPrefPage
afKeywordCase.setSelection(store.getBoolean(SQLPreferenceConstants.SQL_FORMAT_KEYWORD_CASE_AUTO));
afExtractFromSource.setSelection(store.getBoolean(SQLPreferenceConstants.SQL_FORMAT_EXTRACT_FROM_SOURCE));
+ String formatterId = store.getString(ModelPreferences.SQL_FORMAT_FORMATTER);
+ for (int i = 0; i < formatters.size(); i++) {
+ if (formatters.get(i).getId().equalsIgnoreCase(formatterId)) {
+ formatterSelector.select(i);
+ break;
+ }
+ }
+ if (formatterSelector.getSelectionIndex() < 0) formatterSelector.select(0);
- UIUtils.setComboSelection(formatterSelector, capitalizeCaseName(store.getString(ModelPreferences.SQL_FORMAT_FORMATTER)));
final String caseName = store.getString(ModelPreferences.SQL_FORMAT_KEYWORD_CASE);
if (CommonUtils.isEmpty(caseName)) {
keywordCaseCombo.select(0);
@@ -286,7 +298,8 @@ public class PrefPageSQLFormat extends TargetPrefPage
store.setValue(SQLPreferenceConstants.SQL_FORMAT_KEYWORD_CASE_AUTO, afKeywordCase.getSelection());
store.setValue(SQLPreferenceConstants.SQL_FORMAT_EXTRACT_FROM_SOURCE, afExtractFromSource.getSelection());
- store.setValue(ModelPreferences.SQL_FORMAT_FORMATTER, formatterSelector.getText().toUpperCase(Locale.ENGLISH));
+ store.setValue(ModelPreferences.SQL_FORMAT_FORMATTER,
+ formatters.get(formatterSelector.getSelectionIndex()).getId().toUpperCase(Locale.ENGLISH));
final String caseName;
if (keywordCaseCombo.getSelectionIndex() == 0) {
@@ -330,11 +343,12 @@ public class PrefPageSQLFormat extends TargetPrefPage
}
private void showFormatterSettings() {
- final boolean isDefFormatter = formatterSelector.getSelectionIndex() == 0;
- defaultGroup.setVisible(isDefFormatter);
- externalGroup.setVisible(!isDefFormatter);
- ((GridData)defaultGroup.getLayoutData()).exclude = !isDefFormatter;
- ((GridData)externalGroup.getLayoutData()).exclude = isDefFormatter;
+ SQLFormatterDescriptor selFormatter = formatters.get(formatterSelector.getSelectionIndex());
+ boolean isExternal = selFormatter.getId().equalsIgnoreCase(SQLExternalFormatter.FORMATTER_ID);
+ defaultGroup.setVisible(!isExternal);
+ externalGroup.setVisible(isExternal);
+ ((GridData)defaultGroup.getLayoutData()).exclude = isExternal;
+ ((GridData)externalGroup.getLayoutData()).exclude = !isExternal;
defaultGroup.getParent().layout();
}
diff --git a/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/SQLUtils.java b/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/SQLUtils.java
index abdfd406b1f1241943951bba9ac97e4aa2f53278..1a80151a1353a4bef881172977991b62eadbc40d 100644
--- a/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/SQLUtils.java
+++ b/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/SQLUtils.java
@@ -29,6 +29,7 @@ import org.jkiss.dbeaver.model.exec.DBCSession;
import org.jkiss.dbeaver.model.impl.sql.BasicSQLDialect;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
+import org.jkiss.dbeaver.model.sql.format.SQLFormatter;
import org.jkiss.dbeaver.model.sql.format.SQLFormatterConfiguration;
import org.jkiss.dbeaver.model.struct.DBSAttributeBase;
import org.jkiss.dbeaver.model.struct.DBSObject;
@@ -280,7 +281,11 @@ public final class SQLUtils {
SQLSyntaxManager syntaxManager = new SQLSyntaxManager();
syntaxManager.init(dataSource.getSQLDialect(), dataSource.getContainer().getPreferenceStore());
SQLFormatterConfiguration configuration = new SQLFormatterConfiguration(syntaxManager);
- return configuration.createFormatter().format(query, configuration);
+ SQLFormatter formatter = dataSource.getDataSource().getContainer().getPlatform().getSQLFormatterRegistry().createFormatter(configuration);
+ if (formatter == null) {
+ return query;
+ }
+ return formatter.format(query, configuration);
}
public static void appendLikeCondition(StringBuilder sql, String value, boolean not)
diff --git a/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/format/SQLFormatterConfiguration.java b/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/format/SQLFormatterConfiguration.java
index 8549647072de6d0068d1051d2523d40fff8e97eb..071d462a1fce3e3bec149b70b5354a1139515369 100644
--- a/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/format/SQLFormatterConfiguration.java
+++ b/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/format/SQLFormatterConfiguration.java
@@ -23,8 +23,6 @@ import org.jkiss.dbeaver.model.DBPIdentifierCase;
import org.jkiss.dbeaver.model.DBPKeywordType;
import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore;
import org.jkiss.dbeaver.model.sql.SQLSyntaxManager;
-import org.jkiss.dbeaver.model.sql.format.external.SQLExternalFormatter;
-import org.jkiss.dbeaver.model.sql.format.tokenized.SQLTokenizedFormatter;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.utils.CommonUtils;
@@ -112,14 +110,6 @@ public class SQLFormatterConfiguration {
this.properties = properties;
}
- public SQLFormatter createFormatter() {
- if (SQLExternalFormatter.FORMATTER_ID.equals(formatterId)) {
- return new SQLExternalFormatter();
- } else {
- return new SQLTokenizedFormatter();
- }
- }
-
public DBPPreferenceStore getPreferenceStore() {
return syntaxManager.getPreferenceStore();
}
diff --git a/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/format/SQLFormatterRegistry.java b/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/format/SQLFormatterRegistry.java
index 1c4e68fe95cd6d108c7f7cc07d2eb4cedc1c8ea6..d348701c9f78f8ed39bacaf644828458afba2f2d 100644
--- a/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/format/SQLFormatterRegistry.java
+++ b/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/format/SQLFormatterRegistry.java
@@ -16,13 +16,24 @@
*/
package org.jkiss.dbeaver.model.sql.format;
-import org.jkiss.dbeaver.DBException;
+import org.jkiss.code.NotNull;
+import org.jkiss.code.Nullable;
/**
* SQL Formatter registry
*/
public interface SQLFormatterRegistry {
- SQLFormatter createAndConfigureFormatter(SQLFormatterConfiguration configuration) throws DBException;
+ /**
+ * Creates new formatter. Uses default config and doesn't interact with user for any configuration.
+ */
+ @Nullable
+ SQLFormatter createFormatter(@NotNull SQLFormatterConfiguration configuration);
+
+ /**
+ * Creates and configures new formatter. Interacts with user in needed.
+ */
+ @Nullable
+ SQLFormatter createAndConfigureFormatter(@NotNull SQLFormatterConfiguration configuration);
}