From 1643632413189cff4dd3323ad866f71476dd17b5 Mon Sep 17 00:00:00 2001 From: serge-rider Date: Sun, 3 Dec 2017 21:47:15 +0300 Subject: [PATCH] #2130 SQL formatters model/registry Former-commit-id: b57bc9e53ab13c9e020510fbd3d350208defc049 --- .../OSGI-INF/l10n/bundle.properties | 1 + plugins/org.jkiss.dbeaver.core/plugin.xml | 8 +- .../org.jkiss.dbeaver.sqlFormatter.exsd | 223 ++++++++++++++++++ .../org/jkiss/dbeaver/core/DBeaverCore.java | 7 + .../SQLFormatterConfigurationRegistry.java | 125 ++++++++++ .../registry/sql/SQLFormatterConfigurer.java | 29 +++ .../registry/sql/SQLFormatterDescriptor.java | 87 +++++++ .../sql/syntax/SQLFormattingStrategy.java | 8 +- .../ui/preferences/PrefPageSQLFormat.java | 36 ++- .../org/jkiss/dbeaver/model/sql/SQLUtils.java | 7 +- .../sql/format/SQLFormatterConfiguration.java | 10 - .../sql/format/SQLFormatterRegistry.java | 15 +- 12 files changed, 530 insertions(+), 26 deletions(-) create mode 100644 plugins/org.jkiss.dbeaver.core/schema/org.jkiss.dbeaver.sqlFormatter.exsd create mode 100644 plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/sql/SQLFormatterConfigurationRegistry.java create mode 100644 plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/sql/SQLFormatterConfigurer.java create mode 100644 plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/sql/SQLFormatterDescriptor.java 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 a57f2327c6..b6f925af3e 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 41fa93b02a..0315853c12 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 95b793d149..7906034ad2 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 0000000000..d023f4bd7a --- /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 0000000000..8b414b0963 --- /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 0000000000..74773ad769 --- /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 da28b0110a..640a3dfd91 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 3fd55cdbd9..bed6008794 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 abdfd406b1..1a80151a13 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 8549647072..071d462a1f 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 1c4e68fe95..d348701c9f 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); } -- GitLab