提交 dd15372b 编写于 作者: S serge-rider

Refactoring: model.sql bundle extraction

Former-commit-id: 427266a3
上级 72197d27
...@@ -44,7 +44,6 @@ import org.jkiss.dbeaver.model.qm.QMUtils; ...@@ -44,7 +44,6 @@ import org.jkiss.dbeaver.model.qm.QMUtils;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.OSDescriptor; import org.jkiss.dbeaver.model.runtime.OSDescriptor;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor; import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
import org.jkiss.dbeaver.model.sql.format.SQLFormatterRegistry;
import org.jkiss.dbeaver.registry.*; import org.jkiss.dbeaver.registry.*;
import org.jkiss.dbeaver.registry.datatype.DataTypeProviderRegistry; import org.jkiss.dbeaver.registry.datatype.DataTypeProviderRegistry;
import org.jkiss.dbeaver.registry.driver.DriverDescriptor; import org.jkiss.dbeaver.registry.driver.DriverDescriptor;
...@@ -56,7 +55,6 @@ import org.jkiss.dbeaver.runtime.jobs.KeepAliveJob; ...@@ -56,7 +55,6 @@ import org.jkiss.dbeaver.runtime.jobs.KeepAliveJob;
import org.jkiss.dbeaver.runtime.net.GlobalProxySelector; import org.jkiss.dbeaver.runtime.net.GlobalProxySelector;
import org.jkiss.dbeaver.runtime.qm.QMControllerImpl; import org.jkiss.dbeaver.runtime.qm.QMControllerImpl;
import org.jkiss.dbeaver.runtime.qm.QMLogFileWriter; import org.jkiss.dbeaver.runtime.qm.QMLogFileWriter;
import org.jkiss.dbeaver.ui.editors.sql.registry.SQLFormatterConfigurationRegistry;
import org.jkiss.dbeaver.ui.resources.DefaultResourceHandlerImpl; import org.jkiss.dbeaver.ui.resources.DefaultResourceHandlerImpl;
import org.jkiss.dbeaver.utils.ContentUtils; import org.jkiss.dbeaver.utils.ContentUtils;
import org.jkiss.dbeaver.utils.GeneralUtils; import org.jkiss.dbeaver.utils.GeneralUtils;
...@@ -484,12 +482,6 @@ public class DBeaverCore implements DBPPlatform { ...@@ -484,12 +482,6 @@ public class DBeaverCore implements DBPPlatform {
return DataFormatterRegistry.getInstance(); return DataFormatterRegistry.getInstance();
} }
@NotNull
@Override
public SQLFormatterRegistry getSQLFormatterRegistry() {
return SQLFormatterConfigurationRegistry.getInstance();
}
@NotNull @NotNull
@Override @Override
public DBPPreferenceStore getPreferenceStore() { public DBPPreferenceStore getPreferenceStore() {
......
...@@ -70,8 +70,10 @@ public class DataSourceToolbarUtils ...@@ -70,8 +70,10 @@ public class DataSourceToolbarUtils
public static void updateCommandsUI() { public static void updateCommandsUI() {
ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class); ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
commandService.refreshElements("org.jkiss.dbeaver.ui.tools.select.connection", null); if (commandService != null) {
commandService.refreshElements("org.jkiss.dbeaver.ui.tools.select.schema", null); commandService.refreshElements("org.jkiss.dbeaver.ui.tools.select.connection", null);
commandService.refreshElements("org.jkiss.dbeaver.ui.editors.sql.sync.connection", null); commandService.refreshElements("org.jkiss.dbeaver.ui.tools.select.schema", null);
commandService.refreshElements("org.jkiss.dbeaver.ui.editors.sql.sync.connection", null);
}
} }
} }
\ No newline at end of file
...@@ -44,6 +44,11 @@ public class HTTPTunnelConfiguratorUI implements IObjectPropertyConfigurator<DBW ...@@ -44,6 +44,11 @@ public class HTTPTunnelConfiguratorUI implements IObjectPropertyConfigurator<DBW
properties.clear(); properties.clear();
} }
@Override
public void resetSettings(DBWHandlerConfiguration configuration) {
}
@Override @Override
public boolean isComplete() public boolean isComplete()
{ {
......
...@@ -24,6 +24,11 @@ import org.jkiss.dbeaver.ui.IObjectPropertyConfigurator; ...@@ -24,6 +24,11 @@ import org.jkiss.dbeaver.ui.IObjectPropertyConfigurator;
*/ */
public abstract class SSLConfiguratorAbstractUI implements IObjectPropertyConfigurator<DBWHandlerConfiguration> { public abstract class SSLConfiguratorAbstractUI implements IObjectPropertyConfigurator<DBWHandlerConfiguration> {
@Override
public void resetSettings(DBWHandlerConfiguration configuration) {
}
@Override @Override
public boolean isComplete() public boolean isComplete()
{ {
......
...@@ -87,6 +87,11 @@ public class SocksProxyConfiguratorUI implements IObjectPropertyConfigurator<DBW ...@@ -87,6 +87,11 @@ public class SocksProxyConfiguratorUI implements IObjectPropertyConfigurator<DBW
configuration.setSavePassword(savePasswordCheckbox.getSelection()); configuration.setSavePassword(savePasswordCheckbox.getSelection());
} }
@Override
public void resetSettings(DBWHandlerConfiguration configuration) {
}
@Override @Override
public boolean isComplete() public boolean isComplete()
{ {
......
...@@ -49,7 +49,7 @@ import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession; ...@@ -49,7 +49,7 @@ import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils; import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor; import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
import org.jkiss.dbeaver.model.sql.SQLUtils; import org.jkiss.dbeaver.model.sql.format.SQLFormatUtils;
import org.jkiss.utils.CommonUtils; import org.jkiss.utils.CommonUtils;
import java.sql.Clob; import java.sql.Clob;
...@@ -572,7 +572,7 @@ public class DB2Utils { ...@@ -572,7 +572,7 @@ public class DB2Utils {
{ {
// First let the defaut SQL formater operate // First let the defaut SQL formater operate
String result = SQLUtils.formatSQL(db2DataSource, rawText); String result = SQLFormatUtils.formatSQL(db2DataSource, rawText);
// Put some kwywords on the same line // Put some kwywords on the same line
result = result.replace("CREATE\r\n PROCEDURE", "CREATE PROCEDURE"); result = result.replace("CREATE\r\n PROCEDURE", "CREATE PROCEDURE");
......
...@@ -30,7 +30,7 @@ import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils; ...@@ -30,7 +30,7 @@ import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.impl.jdbc.struct.JDBCTableConstraint; import org.jkiss.dbeaver.model.impl.jdbc.struct.JDBCTableConstraint;
import org.jkiss.dbeaver.model.meta.Property; import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.sql.SQLUtils; import org.jkiss.dbeaver.model.sql.format.SQLFormatUtils;
import org.jkiss.dbeaver.model.struct.DBSEntityAttributeRef; import org.jkiss.dbeaver.model.struct.DBSEntityAttributeRef;
import org.jkiss.dbeaver.model.struct.DBSEntityConstraintType; import org.jkiss.dbeaver.model.struct.DBSEntityConstraintType;
import org.jkiss.dbeaver.model.struct.DBSObjectState; import org.jkiss.dbeaver.model.struct.DBSObjectState;
...@@ -145,7 +145,7 @@ public class DB2TableCheckConstraint extends JDBCTableConstraint<DB2Table> imple ...@@ -145,7 +145,7 @@ public class DB2TableCheckConstraint extends JDBCTableConstraint<DB2Table> imple
@Override @Override
public String getObjectDefinitionText(DBRProgressMonitor monitor, Map<String, Object> options) throws DBException public String getObjectDefinitionText(DBRProgressMonitor monitor, Map<String, Object> options) throws DBException
{ {
return SQLUtils.formatSQL(getDataSource(), text); return SQLFormatUtils.formatSQL(getDataSource(), text);
} }
// ----------------- // -----------------
......
...@@ -35,7 +35,7 @@ import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils; ...@@ -35,7 +35,7 @@ import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.meta.Association; import org.jkiss.dbeaver.model.meta.Association;
import org.jkiss.dbeaver.model.meta.Property; import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.sql.SQLUtils; import org.jkiss.dbeaver.model.sql.format.SQLFormatUtils;
import org.jkiss.dbeaver.model.struct.DBSObject; import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.model.struct.DBSObjectState; import org.jkiss.dbeaver.model.struct.DBSObjectState;
import org.jkiss.dbeaver.model.struct.rdb.DBSTrigger; import org.jkiss.dbeaver.model.struct.rdb.DBSTrigger;
...@@ -160,7 +160,7 @@ public class DB2Trigger extends DB2SchemaObject implements DBSTrigger, DB2Source ...@@ -160,7 +160,7 @@ public class DB2Trigger extends DB2SchemaObject implements DBSTrigger, DB2Source
@Override @Override
public String getObjectDefinitionText(DBRProgressMonitor monitor, Map<String, Object> options) throws DBException public String getObjectDefinitionText(DBRProgressMonitor monitor, Map<String, Object> options) throws DBException
{ {
return SQLUtils.formatSQL(getDataSource(), text); return SQLFormatUtils.formatSQL(getDataSource(), text);
} }
// ----------------- // -----------------
......
...@@ -34,7 +34,7 @@ import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils; ...@@ -34,7 +34,7 @@ import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.meta.Association; import org.jkiss.dbeaver.model.meta.Association;
import org.jkiss.dbeaver.model.meta.Property; import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.sql.SQLUtils; import org.jkiss.dbeaver.model.sql.format.SQLFormatUtils;
import org.jkiss.dbeaver.model.struct.DBSObject; import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.model.struct.DBSObjectState; import org.jkiss.dbeaver.model.struct.DBSObjectState;
import org.jkiss.dbeaver.model.struct.rdb.DBSView; import org.jkiss.dbeaver.model.struct.rdb.DBSView;
...@@ -117,7 +117,7 @@ public abstract class DB2ViewBase extends DB2TableBase implements DB2SourceObjec ...@@ -117,7 +117,7 @@ public abstract class DB2ViewBase extends DB2TableBase implements DB2SourceObjec
@Property(hidden = true, editable = true, updatable = true, order = -1) @Property(hidden = true, editable = true, updatable = true, order = -1)
public String getObjectDefinitionText(DBRProgressMonitor monitor, Map<String, Object> options) throws DBException public String getObjectDefinitionText(DBRProgressMonitor monitor, Map<String, Object> options) throws DBException
{ {
return SQLUtils.formatSQL(getDataSource(), text); return SQLFormatUtils.formatSQL(getDataSource(), text);
} }
// ----------------- // -----------------
......
...@@ -32,7 +32,7 @@ import org.jkiss.dbeaver.model.impl.jdbc.cache.JDBCStructCache; ...@@ -32,7 +32,7 @@ import org.jkiss.dbeaver.model.impl.jdbc.cache.JDBCStructCache;
import org.jkiss.dbeaver.model.meta.Property; import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor; import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
import org.jkiss.dbeaver.model.sql.SQLUtils; import org.jkiss.dbeaver.model.sql.format.SQLFormatUtils;
import org.jkiss.dbeaver.model.struct.DBSEntityAssociation; import org.jkiss.dbeaver.model.struct.DBSEntityAssociation;
import org.jkiss.dbeaver.model.struct.DBSObject; import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.model.struct.DBSObjectState; import org.jkiss.dbeaver.model.struct.DBSObjectState;
...@@ -178,7 +178,7 @@ public class ExasolView extends ExasolTableBase implements ExasolSourceObject, D ...@@ -178,7 +178,7 @@ public class ExasolView extends ExasolTableBase implements ExasolSourceObject, D
@Property(hidden = true, editable = true, updatable = true, order = -1) @Property(hidden = true, editable = true, updatable = true, order = -1)
public String getObjectDefinitionText(DBRProgressMonitor monitor, Map<String, Object> options) throws DBException { public String getObjectDefinitionText(DBRProgressMonitor monitor, Map<String, Object> options) throws DBException {
read(); read();
return SQLUtils.formatSQL(getDataSource(), this.text); return SQLFormatUtils.formatSQL(getDataSource(), this.text);
} }
......
...@@ -8,8 +8,11 @@ Require-Bundle: org.eclipse.ui, ...@@ -8,8 +8,11 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime, org.eclipse.core.runtime,
org.jkiss.dbeaver.core, org.jkiss.dbeaver.core,
org.jkiss.dbeaver.model, org.jkiss.dbeaver.model,
org.jkiss.dbeaver.model.sql,
org.jkiss.dbeaver.ui, org.jkiss.dbeaver.ui,
org.jkiss.dbeaver.ui.editors.sql,
org.eclipse.core.resources org.eclipse.core.resources
Export-Package: org.jkiss.dbeaver.ext.format.sqlworkbenchj
Bundle-ActivationPolicy: lazy Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-Vendor: JKISS Bundle-Vendor: JKISS
...@@ -6,9 +6,14 @@ ...@@ -6,9 +6,14 @@
<formatter <formatter
id="sqlworkbenchj" id="sqlworkbenchj"
class="org.jkiss.dbeaver.ext.format.sqlworkbenchj.SQLWorkbenchJFormatter" class="org.jkiss.dbeaver.ext.format.sqlworkbenchj.SQLWorkbenchJFormatter"
configurerClass="org.jkiss.dbeaver.ext.format.sqlworkbenchj.SQLWorkbenchJFormatterSettingsPage"
label="SQL Workbench/J formatter" label="SQL Workbench/J formatter"
description="Formatter from SQL Workbench/J"/> description="Formatter from SQL Workbench/J"/>
</extension> </extension>
<extension point="org.eclipse.core.runtime.adapters">
<factory adaptableType="org.jkiss.dbeaver.ext.format.sqlworkbenchj.SQLWorkbenchJFormatter" class="org.jkiss.dbeaver.ext.format.sqlworkbenchj.SQLWorkbenchJAdapterFactory">
<adapter type="org.jkiss.dbeaver.ui.editors.sql.preferences.format.SQLFormatterConfigurator"/>
</factory>
</extension>
</plugin> </plugin>
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 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.format.sqlworkbenchj;
import org.eclipse.core.runtime.IAdapterFactory;
import org.jkiss.dbeaver.ui.editors.sql.preferences.format.SQLFormatterConfigurator;
/**
* Adapts objects to their UI configurators
*/
public class SQLWorkbenchJAdapterFactory implements IAdapterFactory
{
private static final Class<?>[] ADAPTER_LIST = {
SQLFormatterConfigurator.class
};
@Override
public <T> T getAdapter(Object adaptableObject, Class<T> adapterType)
{
if (adapterType == SQLFormatterConfigurator.class && adaptableObject instanceof SQLWorkbenchJFormatter) {
return adapterType.cast(new SQLWorkbenchJFormatterSettingsPage());
}
return null;
}
@Override
public Class[] getAdapterList()
{
return ADAPTER_LIST;
}
}
...@@ -23,7 +23,7 @@ import org.eclipse.swt.widgets.Group; ...@@ -23,7 +23,7 @@ import org.eclipse.swt.widgets.Group;
import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore; import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore;
import org.jkiss.dbeaver.ui.UIUtils; import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.controls.TextWithOpenFolder; import org.jkiss.dbeaver.ui.controls.TextWithOpenFolder;
import org.jkiss.dbeaver.ui.editors.sql.format.BaseFormatterConfigurationPage; import org.jkiss.dbeaver.ui.editors.sql.preferences.format.BaseFormatterConfigurationPage;
import org.jkiss.utils.CommonUtils; import org.jkiss.utils.CommonUtils;
/** /**
......
...@@ -5,7 +5,8 @@ Bundle-SymbolicName: org.jkiss.dbeaver.ext.generic;singleton:=true ...@@ -5,7 +5,8 @@ Bundle-SymbolicName: org.jkiss.dbeaver.ext.generic;singleton:=true
Bundle-Version: 2.3.96.qualifier Bundle-Version: 2.3.96.qualifier
Bundle-Release-Date: 20190611 Bundle-Release-Date: 20190611
Require-Bundle: org.eclipse.core.runtime, Require-Bundle: org.eclipse.core.runtime,
org.jkiss.dbeaver.model org.jkiss.dbeaver.model;visibility:=reexport,
org.jkiss.dbeaver.model.sql;visibility:=reexport
Bundle-ActivationPolicy: lazy Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-Vendor: JKISS Bundle-Vendor: JKISS
......
...@@ -29,7 +29,7 @@ import org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement; ...@@ -29,7 +29,7 @@ import org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet; import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession; import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.sql.SQLUtils; import org.jkiss.dbeaver.model.sql.format.SQLFormatUtils;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Map; import java.util.Map;
...@@ -113,7 +113,7 @@ public class HANAMetaModel extends GenericMetaModel ...@@ -113,7 +113,7 @@ public class HANAMetaModel extends GenericMetaModel
} }
if (ddl.length() > 0) { if (ddl.length() > 0) {
// Format DDL // Format DDL
return SQLUtils.formatSQL(sourceObject.getDataSource(), ddl.toString()); return SQLFormatUtils.formatSQL(sourceObject.getDataSource(), ddl.toString());
} }
} }
} }
......
...@@ -18,7 +18,6 @@ package org.jkiss.dbeaver.ext.hive.model; ...@@ -18,7 +18,6 @@ package org.jkiss.dbeaver.ext.hive.model;
import org.jkiss.dbeaver.DBException; import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.generic.model.GenericDataSource; import org.jkiss.dbeaver.ext.generic.model.GenericDataSource;
import org.jkiss.dbeaver.ext.generic.model.GenericProcedure;
import org.jkiss.dbeaver.ext.generic.model.GenericTable; import org.jkiss.dbeaver.ext.generic.model.GenericTable;
import org.jkiss.dbeaver.ext.generic.model.meta.GenericMetaModel; import org.jkiss.dbeaver.ext.generic.model.meta.GenericMetaModel;
import org.jkiss.dbeaver.model.DBPDataSourceContainer; import org.jkiss.dbeaver.model.DBPDataSourceContainer;
...@@ -28,7 +27,7 @@ import org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement; ...@@ -28,7 +27,7 @@ import org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet; import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession; import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.sql.SQLUtils; import org.jkiss.dbeaver.model.sql.format.SQLFormatUtils;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Map; import java.util.Map;
...@@ -65,7 +64,7 @@ public class HiveMetaModel extends GenericMetaModel ...@@ -65,7 +64,7 @@ public class HiveMetaModel extends GenericMetaModel
} }
String ddl = sql.toString(); String ddl = sql.toString();
if (sourceObject.isView()) { if (sourceObject.isView()) {
return SQLUtils.formatSQL(sourceObject.getDataSource(), ddl); return SQLFormatUtils.formatSQL(sourceObject.getDataSource(), ddl);
} }
return ddl; return ddl;
} }
......
...@@ -29,7 +29,7 @@ import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet; ...@@ -29,7 +29,7 @@ import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession; import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils; import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.sql.SQLUtils; import org.jkiss.dbeaver.model.sql.format.SQLFormatUtils;
import org.jkiss.dbeaver.model.struct.rdb.DBSProcedureType; import org.jkiss.dbeaver.model.struct.rdb.DBSProcedureType;
import java.sql.SQLException; import java.sql.SQLException;
...@@ -121,7 +121,7 @@ public class HSQLMetaModel extends GenericMetaModel ...@@ -121,7 +121,7 @@ public class HSQLMetaModel extends GenericMetaModel
if (dbResult.nextRow()) { if (dbResult.nextRow()) {
String definition = dbResult.getString(1); String definition = dbResult.getString(1);
if (definition != null) { if (definition != null) {
definition = SQLUtils.formatSQL(dataSource, definition); definition = SQLFormatUtils.formatSQL(dataSource, definition);
} }
return definition; return definition;
} }
......
...@@ -22,7 +22,7 @@ import org.jkiss.dbeaver.ext.generic.model.GenericTrigger; ...@@ -22,7 +22,7 @@ import org.jkiss.dbeaver.ext.generic.model.GenericTrigger;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet; import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils; import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.meta.Property; import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.sql.SQLUtils; import org.jkiss.dbeaver.model.sql.format.SQLFormatUtils;
/** /**
* HSQLTrigger * HSQLTrigger
...@@ -42,7 +42,7 @@ public class HSQLTrigger extends GenericTrigger { ...@@ -42,7 +42,7 @@ public class HSQLTrigger extends GenericTrigger {
timing = JDBCUtils.safeGetString(dbResult, "ACTION_TIMING"); timing = JDBCUtils.safeGetString(dbResult, "ACTION_TIMING");
statement = JDBCUtils.safeGetString(dbResult, "ACTION_STATEMENT"); statement = JDBCUtils.safeGetString(dbResult, "ACTION_STATEMENT");
if (statement != null) { if (statement != null) {
statement = SQLUtils.formatSQL(getDataSource(), statement); statement = SQLFormatUtils.formatSQL(getDataSource(), statement);
} }
} }
......
...@@ -6,6 +6,7 @@ Bundle-Version: 2.1.95.qualifier ...@@ -6,6 +6,7 @@ Bundle-Version: 2.1.95.qualifier
Bundle-Release-Date: 20190611 Bundle-Release-Date: 20190611
Require-Bundle: org.eclipse.core.runtime, Require-Bundle: org.eclipse.core.runtime,
org.jkiss.dbeaver.model, org.jkiss.dbeaver.model,
org.jkiss.dbeaver.model.sql,
org.jkiss.dbeaver.data.gis, org.jkiss.dbeaver.data.gis,
com.google.gson com.google.gson
Bundle-ActivationPolicy: lazy Bundle-ActivationPolicy: lazy
......
...@@ -34,7 +34,7 @@ import org.jkiss.dbeaver.model.meta.LazyProperty; ...@@ -34,7 +34,7 @@ import org.jkiss.dbeaver.model.meta.LazyProperty;
import org.jkiss.dbeaver.model.meta.Property; import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.meta.PropertyGroup; import org.jkiss.dbeaver.model.meta.PropertyGroup;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.sql.SQLUtils; import org.jkiss.dbeaver.model.sql.format.SQLFormatUtils;
import org.jkiss.dbeaver.model.struct.rdb.DBSTableConstraint; import org.jkiss.dbeaver.model.struct.rdb.DBSTableConstraint;
import org.jkiss.dbeaver.model.struct.rdb.DBSTableForeignKey; import org.jkiss.dbeaver.model.struct.rdb.DBSTableForeignKey;
import org.jkiss.dbeaver.model.struct.rdb.DBSTableIndex; import org.jkiss.dbeaver.model.struct.rdb.DBSTableIndex;
...@@ -220,7 +220,7 @@ public class MySQLView extends MySQLTableBase implements DBSView ...@@ -220,7 +220,7 @@ public class MySQLView extends MySQLTableBase implements DBSView
} }
} }
additionalInfo.setDefinition( additionalInfo.setDefinition(
SQLUtils.formatSQL(getDataSource(), definition)); SQLFormatUtils.formatSQL(getDataSource(), definition));
} }
} }
......
...@@ -5,6 +5,7 @@ Bundle-SymbolicName: org.jkiss.dbeaver.ext.postgresql;singleton:=true ...@@ -5,6 +5,7 @@ Bundle-SymbolicName: org.jkiss.dbeaver.ext.postgresql;singleton:=true
Bundle-Version: 2.1.83.qualifier Bundle-Version: 2.1.83.qualifier
Bundle-Release-Date: 20190611 Bundle-Release-Date: 20190611
Require-Bundle: org.jkiss.dbeaver.model, Require-Bundle: org.jkiss.dbeaver.model,
org.jkiss.dbeaver.model.sql,
org.jkiss.dbeaver.ext.generic, org.jkiss.dbeaver.ext.generic,
org.jkiss.dbeaver.data.gis;visibility:=reexport, org.jkiss.dbeaver.data.gis;visibility:=reexport,
org.jkiss.bundle.gis;visibility:=reexport, org.jkiss.bundle.gis;visibility:=reexport,
......
...@@ -33,6 +33,7 @@ import org.jkiss.dbeaver.model.meta.IPropertyValueTransformer; ...@@ -33,6 +33,7 @@ import org.jkiss.dbeaver.model.meta.IPropertyValueTransformer;
import org.jkiss.dbeaver.model.meta.Property; import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.sql.SQLUtils; import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.model.sql.format.SQLFormatUtils;
import org.jkiss.dbeaver.model.struct.DBSActionTiming; import org.jkiss.dbeaver.model.struct.DBSActionTiming;
import org.jkiss.dbeaver.model.struct.DBSObjectState; import org.jkiss.dbeaver.model.struct.DBSObjectState;
import org.jkiss.dbeaver.model.struct.rdb.DBSManipulationType; import org.jkiss.dbeaver.model.struct.rdb.DBSManipulationType;
...@@ -271,7 +272,7 @@ public class PostgreTrigger implements DBSTrigger, DBPQualifiedObject, PostgreOb ...@@ -271,7 +272,7 @@ public class PostgreTrigger implements DBSTrigger, DBPQualifiedObject, PostgreOb
try (JDBCSession session = DBUtils.openMetaSession(monitor, this, "Read trigger definition")) { try (JDBCSession session = DBUtils.openMetaSession(monitor, this, "Read trigger definition")) {
String triggerSource = JDBCUtils.queryString(session, "SELECT pg_catalog.pg_get_triggerdef(?)", objectId); String triggerSource = JDBCUtils.queryString(session, "SELECT pg_catalog.pg_get_triggerdef(?)", objectId);
if (triggerSource != null) { if (triggerSource != null) {
triggerSource = SQLUtils.formatSQL(getDataSource(), triggerSource); triggerSource = SQLFormatUtils.formatSQL(getDataSource(), triggerSource);
ddl.append(triggerSource).append(";"); ddl.append(triggerSource).append(";");
} }
} catch (SQLException e) { } catch (SQLException e) {
......
...@@ -26,8 +26,9 @@ import org.jkiss.dbeaver.model.meta.Property; ...@@ -26,8 +26,9 @@ import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor; import org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor;
import org.jkiss.dbeaver.model.preferences.DBPPropertySource; import org.jkiss.dbeaver.model.preferences.DBPPropertySource;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.sql.SQLUtils; import org.jkiss.dbeaver.model.sql.format.SQLFormatUtils;
import org.jkiss.utils.CommonUtils; import org.jkiss.utils.CommonUtils;
import java.util.*; import java.util.*;
/** /**
...@@ -159,7 +160,7 @@ public abstract class PostgrePlanNodeBase<NODE extends PostgrePlanNodeBase<?>> e ...@@ -159,7 +160,7 @@ public abstract class PostgrePlanNodeBase<NODE extends PostgrePlanNodeBase<?>> e
cond = attributes.get(ATTR_FILTER); cond = attributes.get(ATTR_FILTER);
} }
if (!CommonUtils.isEmpty(cond)) { if (!CommonUtils.isEmpty(cond)) {
cond = SQLUtils.formatSQL(dataSource, cond); cond = SQLFormatUtils.formatSQL(dataSource, cond);
} }
return cond; return cond;
} }
......
...@@ -7,7 +7,11 @@ Bundle-Version: 1.0.0.qualifier ...@@ -7,7 +7,11 @@ Bundle-Version: 1.0.0.qualifier
Bundle-Release-Date: 20190611 Bundle-Release-Date: 20190611
Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy Bundle-ActivationPolicy: lazy
Export-Package: org.jkiss.dbeaver.model.sql Export-Package: org.jkiss.dbeaver.model.sql,
org.jkiss.dbeaver.model.sql.format,
org.jkiss.dbeaver.model.sql.format.external,
org.jkiss.dbeaver.model.sql.format.tokenized,
org.jkiss.dbeaver.model.sql.registry
Bundle-ClassPath: . Bundle-ClassPath: .
Require-Bundle: org.eclipse.equinox.security, Require-Bundle: org.eclipse.equinox.security,
org.eclipse.core.runtime, org.eclipse.core.runtime,
......
Bundle-Vendor = JKISS Bundle-Vendor = JKISS
Bundle-Name = DBeaver SQL Model Bundle-Name = DBeaver SQL Model
extension-point.org.jkiss.dbeaver.sqlFormatter.name = SQL formatters
sql.formatter.default.name = Default formatter
sql.formatter.default.tip = Default SQL formatter
sql.formatter.compact.name = Compact formatter
sql.formatter.compact.tip = Compact SQL formatter. Similar to default formatter but with more compact output
sql.formatter.external.name = External formatter
sql.formatter.external.tip = External formatter. Uses configurable command-line executable to format SQL queries
extension-point.org.jkiss.dbeaver.sqlCommand.name = SQL-Skriptbefehle
extension-point.org.jkiss.dbeaver.sqlFormatter.name = SQL-Formatierer
extension-point.org.jkiss.dbeaver.sqlCommand.name = Commandes de scripts SQL
extension-point.org.jkiss.dbeaver.sqlFormatter.name = Formateurs SQL
extension-point.org.jkiss.dbeaver.sqlCommand.name =SQL\u30B9\u30AF\u30EA\u30D7\u30C8\u30B3\u30DE\u30F3\u30C9
extension-point.org.jkiss.dbeaver.sqlFormatter.name =SQL\u30D5\u30A9\u30FC\u30DE\u30C3\u30BF
extension-point.org.jkiss.dbeaver.sqlCommand.name = SQL \uC2A4\uD06C\uB9BD\uD2B8 \uBA85\uB839\uC5B4
extension-point.org.jkiss.dbeaver.sqlFormatter.name = SQL \uD3EC\uB9F7\uD130
sql.formatter.default.name = \uC11C\uC2DD \uAE30\uBCF8\uAC12
sql.formatter.default.tip = SQL \uC11C\uC2DD \uAE30\uBCF8\uAC12
sql.formatter.compact.name = Compact \uC11C\uC2DD
sql.formatter.compact.tip = Compact SQL \uC11C\uC2DD. \uAE30\uBCF8 \uC11C\uC2DD\uACFC \uC720\uC0AC\uD558\uC9C0\uB9CC \uB354 compact\uD558\uAC8C
sql.formatter.external.name = External formatter
sql.formatter.external.tip = External formatter. Uses configurable command-line executable to format SQL queries
sql.formatter.default.name = \u0421\u0442\u0430\u043D\u0434\u0430\u0440\u0442\u043D\u044B\u0439
sql.formatter.default.tip = SQL \u0444\u043E\u0440\u043C\u0430\u0442\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435 \u043F\u043E \u0443\u043C\u043E\u043B\u0447\u0430\u043D\u0438\u044E.
sql.formatter.compact.name = \u041A\u043E\u043C\u043F\u0430\u043A\u0442\u043D\u044B\u0439
sql.formatter.compact.tip = \u041A\u043E\u043C\u043F\u0430\u043A\u0442\u043D\u043E\u0435 \u0444\u043E\u0440\u043C\u0430\u0442\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435. \u0410\u043D\u0430\u043B\u043E\u0433\u0438\u0447\u043D\u043E \u0441\u0442\u0430\u043D\u0434\u0430\u0440\u0442\u043D\u043E\u043C\u0443, \u043D\u043E \u0441 \u0431\u043E\u043B\u0435\u0435 \u043A\u043E\u043C\u043F\u0430\u043A\u0442\u043D\u044B\u043C \u0432\u044B\u0445\u043E\u0434\u043E\u043C.
sql.formatter.external.name = \u0412\u043D\u0435\u0448\u043D\u0438\u0439
sql.formatter.external.tip = \u0412\u043D\u0435\u0448\u043D\u044F\u044F \u043F\u0440\u043E\u0433\u0440\u0430\u043C\u043C\u0430. \u0418\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0435\u0442 \u043D\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043C\u044B\u0439 \u0438\u0441\u043F\u043E\u043B\u043D\u044F\u0435\u043C\u044B\u0439 \u0444\u0430\u0439\u043B \u043A\u043E\u043C\u0430\u043D\u0434\u043D\u043E\u0439 \u0441\u0442\u0440\u043E\u043A\u0438 \u0434\u043B\u044F \u0444\u043E\u0440\u043C\u0430\u0442\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u044F \u0437\u0430\u043F\u0440\u043E\u0441\u043E\u0432 SQL.
extension-point.org.jkiss.dbeaver.sqlCommand.name = SQL \u811A\u672C\u547D\u4EE4
extension-point.org.jkiss.dbeaver.sqlFormatter.name = SQL \u683C\u5F0F\u5316
...@@ -2,5 +2,16 @@ ...@@ -2,5 +2,16 @@
<?eclipse version="3.2"?> <?eclipse version="3.2"?>
<plugin> <plugin>
<extension-point id="org.jkiss.dbeaver.sqlFormatter" name="%extension-point.org.jkiss.dbeaver.sqlFormatter.name" schema="schema/org.jkiss.dbeaver.sqlFormatter.exsd"/>
<extension point="org.eclipse.core.runtime.preferences">
<initializer class="org.jkiss.dbeaver.model.sql.internal.SQLModelPreferencesInitializer"/>
</extension>
<extension point="org.jkiss.dbeaver.sqlFormatter">
<formatter id="default" class="org.jkiss.dbeaver.model.sql.format.tokenized.SQLFormatterTokenized" label="%sql.formatter.default.name" description="%sql.formatter.default.tip"/>
<formatter id="compact" class="org.jkiss.dbeaver.model.sql.format.tokenized.SQLFormatterCompact" label="%sql.formatter.compact.name" description="%sql.formatter.compact.tip"/>
<formatter id="external" class="org.jkiss.dbeaver.model.sql.format.external.SQLFormatterExternal" label="%sql.formatter.external.name" description="%sql.formatter.external.tip"/>
</extension>
</plugin> </plugin>
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 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.model.sql;
/**
* Preferences constants
*/
public final class SQLModelPreferences {
public final static String SQL_FORMAT_FORMATTER = "sql.format.formatter";
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 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.model.sql.format;
import org.jkiss.dbeaver.model.sql.SQLDataSource;
import org.jkiss.dbeaver.model.sql.SQLSyntaxManager;
import org.jkiss.dbeaver.model.sql.registry.SQLFormatterConfigurationRegistry;
/**
* SQL Formatter
*/
public class SQLFormatUtils {
public static String formatSQL(SQLDataSource dataSource, String query)
{
SQLSyntaxManager syntaxManager = new SQLSyntaxManager();
syntaxManager.init(dataSource.getSQLDialect(), dataSource.getContainer().getPreferenceStore());
SQLFormatterConfiguration configuration = new SQLFormatterConfiguration(dataSource, syntaxManager);
SQLFormatter formatter = SQLFormatterConfigurationRegistry.getInstance().createFormatter(configuration);
if (formatter == null) {
return query;
}
return formatter.format(query, configuration);
}
}
/* /*
* DBeaver - Universal Database Manager * DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org) * Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.jkiss.dbeaver.model.sql.format; package org.jkiss.dbeaver.model.sql.format;
import org.jkiss.code.NotNull; import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.ModelPreferences; import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBPDataSource; import org.jkiss.dbeaver.model.DBPIdentifierCase;
import org.jkiss.dbeaver.model.DBPIdentifierCase; import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore;
import org.jkiss.dbeaver.model.DBPKeywordType; import org.jkiss.dbeaver.model.sql.SQLModelPreferences;
import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore; import org.jkiss.dbeaver.model.sql.SQLSyntaxManager;
import org.jkiss.dbeaver.model.sql.SQLSyntaxManager; import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.dbeaver.utils.GeneralUtils; import org.jkiss.utils.CommonUtils;
import org.jkiss.utils.CommonUtils;
import java.util.HashMap;
import java.util.HashMap; import java.util.Locale;
import java.util.Locale; import java.util.Map;
import java.util.Map;
/**
/** * SQLFormatterConfiguration
* SQLFormatterConfiguration */
*/ public class SQLFormatterConfiguration {
public class SQLFormatterConfiguration {
private String formatterId;
private String formatterId;
private DBPDataSource dataSource;
private DBPDataSource dataSource; @NotNull
@NotNull private DBPIdentifierCase keywordCase;
private DBPIdentifierCase keywordCase; private String indentString = " ";
private String indentString = " "; private SQLSyntaxManager syntaxManager;
private SQLSyntaxManager syntaxManager; @NotNull
@NotNull private String sourceEncoding = GeneralUtils.DEFAULT_ENCODING;
private String sourceEncoding = GeneralUtils.DEFAULT_ENCODING;
private Map<String, Object> properties = new HashMap<>();
private Map<String, Object> properties = new HashMap<>();
/**
/** * Create formatter config with default (set in properties) formatter
* Create formatter config with default (set in properties) formatter */
*/ public SQLFormatterConfiguration(DBPDataSource dataSource, SQLSyntaxManager syntaxManager) {
public SQLFormatterConfiguration(DBPDataSource dataSource, SQLSyntaxManager syntaxManager) { this(dataSource, syntaxManager, CommonUtils.notEmpty(syntaxManager.getPreferenceStore().getString(SQLModelPreferences.SQL_FORMAT_FORMATTER)).toUpperCase(Locale.ENGLISH));
this(dataSource, syntaxManager, CommonUtils.notEmpty(syntaxManager.getPreferenceStore().getString(ModelPreferences.SQL_FORMAT_FORMATTER)).toUpperCase(Locale.ENGLISH)); }
}
public SQLFormatterConfiguration(DBPDataSource dataSource, SQLSyntaxManager syntaxManager, String formatterId) {
public SQLFormatterConfiguration(DBPDataSource dataSource, SQLSyntaxManager syntaxManager, String formatterId) { this.dataSource = dataSource;
this.dataSource = dataSource; this.syntaxManager = syntaxManager;
this.syntaxManager = syntaxManager; this.keywordCase = syntaxManager.getKeywordCase();
this.keywordCase = syntaxManager.getKeywordCase();
this.formatterId = formatterId;
this.formatterId = formatterId; }
}
public DBPDataSource getDataSource() {
public DBPDataSource getDataSource() { return dataSource;
return dataSource; }
}
public SQLSyntaxManager getSyntaxManager() {
public SQLSyntaxManager getSyntaxManager() { return syntaxManager;
return syntaxManager; }
}
public String getFormatterId() {
public String getFormatterId() { return formatterId;
return formatterId; }
}
public void setFormatterId(String formatterId) {
public void setFormatterId(String formatterId) { this.formatterId = formatterId;
this.formatterId = formatterId; syntaxManager.getPreferenceStore().setValue(
syntaxManager.getPreferenceStore().setValue( SQLModelPreferences.SQL_FORMAT_FORMATTER, formatterId.toUpperCase(Locale.ENGLISH));
ModelPreferences.SQL_FORMAT_FORMATTER, formatterId.toUpperCase(Locale.ENGLISH)); }
}
public String getIndentString() {
public String getIndentString() { return indentString;
return indentString; }
}
public void setIndentString(String indentString) {
public void setIndentString(String indentString) { this.indentString = indentString;
this.indentString = indentString; }
}
@NotNull
@NotNull public DBPIdentifierCase getKeywordCase() {
public DBPIdentifierCase getKeywordCase() { return keywordCase;
return keywordCase; }
}
public void setKeywordCase(@NotNull DBPIdentifierCase keyword) {
public void setKeywordCase(@NotNull DBPIdentifierCase keyword) { this.keywordCase = keyword;
this.keywordCase = keyword; }
}
@NotNull
@NotNull public String getSourceEncoding() {
public String getSourceEncoding() { return sourceEncoding;
return sourceEncoding; }
}
public void setSourceEncoding(@NotNull String sourceEncoding) {
public void setSourceEncoding(@NotNull String sourceEncoding) { this.sourceEncoding = sourceEncoding;
this.sourceEncoding = sourceEncoding; }
}
public boolean isFunction(String name) {
public boolean isFunction(String name) { return syntaxManager.getDialect().getFunctions(dataSource).contains(name.toUpperCase(Locale.ENGLISH));
return syntaxManager.getDialect().getFunctions(dataSource).contains(name.toUpperCase(Locale.ENGLISH)); }
}
public Object getProperty(String name) {
public Object getProperty(String name) { return properties.get(name);
return properties.get(name); }
}
public void setProperty(String name, Object value) {
public void setProperty(String name, Object value) { properties.put(name, value);
properties.put(name, value); }
}
public void setProperties(Map<String, Object> properties) {
public void setProperties(Map<String, Object> properties) { this.properties = properties;
this.properties = properties; }
}
public DBPPreferenceStore getPreferenceStore() {
public DBPPreferenceStore getPreferenceStore() { return syntaxManager.getPreferenceStore();
return syntaxManager.getPreferenceStore(); }
}
public void loadSettings() {
public void loadSettings() {
}
}
public void saveSettings() {
public void saveSettings() {
}
}
}
}
/* /*
* DBeaver - Universal Database Manager * DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org) * Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* /*
* FormatterToken * FormatterToken
*/ */
package org.jkiss.dbeaver.model.sql.format.tokenized; package org.jkiss.dbeaver.model.sql.format.tokenized;
class FormatterToken { class FormatterToken {
private TokenType fType; private TokenType fType;
private String fString; private String fString;
private int fPos = -1; private int fPos = -1;
public FormatterToken(final TokenType argType, final String argString, final int argPos) public FormatterToken(final TokenType argType, final String argString, final int argPos)
{ {
fType = argType; fType = argType;
fString = argString; fString = argString;
fPos = argPos; fPos = argPos;
} }
public FormatterToken(final TokenType argType, final String argString) public FormatterToken(final TokenType argType, final String argString)
{ {
this(argType, argString, -1); this(argType, argString, -1);
} }
public void setType(final TokenType argType) public void setType(final TokenType argType)
{ {
fType = argType; fType = argType;
} }
public TokenType getType() public TokenType getType()
{ {
return fType; return fType;
} }
public void setString(final String argString) public void setString(final String argString)
{ {
fString = argString; fString = argString;
} }
public String getString() public String getString()
{ {
return fString; return fString;
} }
public void setPos(final int argPos) public void setPos(final int argPos)
{ {
fPos = argPos; fPos = argPos;
} }
public int getPos() public int getPos()
{ {
return fPos; return fPos;
} }
public String toString() { public String toString() {
return fString + " [" + fType + "]"; return fString + " [" + fType + "]";
} }
} }
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 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.model.sql.internal;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.jkiss.dbeaver.ModelPreferences;
import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore;
import org.jkiss.dbeaver.model.sql.SQLModelPreferences;
import org.jkiss.dbeaver.model.sql.format.tokenized.SQLFormatterTokenized;
import org.jkiss.dbeaver.utils.PrefUtils;
public class SQLModelPreferencesInitializer extends AbstractPreferenceInitializer {
public SQLModelPreferencesInitializer() {
}
@Override
public void initializeDefaultPreferences() {
// Init default preferences
DBPPreferenceStore store = ModelPreferences.getPreferences();
// Common
PrefUtils.setDefaultPreferenceValue(store, SQLModelPreferences.SQL_FORMAT_FORMATTER, SQLFormatterTokenized.FORMATTER_ID);
}
}
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.jkiss.dbeaver.ui.editors.sql.registry; package org.jkiss.dbeaver.model.sql.registry;
import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.core.runtime.IExtensionRegistry;
...@@ -99,20 +99,4 @@ public class SQLFormatterConfigurationRegistry implements SQLFormatterRegistry ...@@ -99,20 +99,4 @@ public class SQLFormatterConfigurationRegistry implements SQLFormatterRegistry
} }
} }
@Nullable
public SQLFormatterConfigurator createConfigurator(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.createConfigurer();
} catch (DBException e) {
log.error("Error creating and configuring formatter", e);
return null;
}
}
} }
...@@ -15,16 +15,14 @@ ...@@ -15,16 +15,14 @@
* limitations under the License. * limitations under the License.
*/ */
package org.jkiss.dbeaver.ui.editors.sql.registry; package org.jkiss.dbeaver.model.sql.registry;
import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IConfigurationElement;
import org.jkiss.code.Nullable;
import org.jkiss.code.NotNull; import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException; import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.impl.AbstractContextDescriptor;
import org.jkiss.dbeaver.model.impl.AbstractDescriptor; import org.jkiss.dbeaver.model.impl.AbstractDescriptor;
import org.jkiss.dbeaver.model.sql.format.SQLFormatter; import org.jkiss.dbeaver.model.sql.format.SQLFormatter;
import org.jkiss.dbeaver.model.impl.AbstractContextDescriptor;
import org.jkiss.utils.CommonUtils;
/** /**
* SQLFormatterDescriptor * SQLFormatterDescriptor
...@@ -37,8 +35,6 @@ public class SQLFormatterDescriptor extends AbstractContextDescriptor { ...@@ -37,8 +35,6 @@ public class SQLFormatterDescriptor extends AbstractContextDescriptor {
private final String label; private final String label;
private final String description; private final String description;
private final AbstractDescriptor.ObjectType formatterImplClass; private final AbstractDescriptor.ObjectType formatterImplClass;
private final AbstractDescriptor.ObjectType configurerImplClass;
public SQLFormatterDescriptor(IConfigurationElement config) { public SQLFormatterDescriptor(IConfigurationElement config) {
super(config); super(config);
...@@ -46,11 +42,6 @@ public class SQLFormatterDescriptor extends AbstractContextDescriptor { ...@@ -46,11 +42,6 @@ public class SQLFormatterDescriptor extends AbstractContextDescriptor {
this.label = config.getAttribute("label"); this.label = config.getAttribute("label");
this.description = config.getAttribute("description"); this.description = config.getAttribute("description");
this.formatterImplClass = new AbstractDescriptor.ObjectType(config.getAttribute("class")); 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() { public String getId() {
...@@ -71,13 +62,4 @@ public class SQLFormatterDescriptor extends AbstractContextDescriptor { ...@@ -71,13 +62,4 @@ public class SQLFormatterDescriptor extends AbstractContextDescriptor {
return formatterImplClass.createInstance(SQLFormatter.class); return formatterImplClass.createInstance(SQLFormatter.class);
} }
@Nullable
public SQLFormatterConfigurator createConfigurer()
throws DBException {
if (configurerImplClass == null) {
return null;
}
return configurerImplClass.createInstance(SQLFormatterConfigurator.class);
}
} }
...@@ -59,9 +59,6 @@ Export-Package: org.jkiss.dbeaver, ...@@ -59,9 +59,6 @@ Export-Package: org.jkiss.dbeaver,
org.jkiss.dbeaver.model.runtime.load, org.jkiss.dbeaver.model.runtime.load,
org.jkiss.dbeaver.model.sql, org.jkiss.dbeaver.model.sql,
org.jkiss.dbeaver.model.sql.eval, org.jkiss.dbeaver.model.sql.eval,
org.jkiss.dbeaver.model.sql.format,
org.jkiss.dbeaver.model.sql.format.external,
org.jkiss.dbeaver.model.sql.format.tokenized,
org.jkiss.dbeaver.model.sql.parser, org.jkiss.dbeaver.model.sql.parser,
org.jkiss.dbeaver.model.struct, org.jkiss.dbeaver.model.struct,
org.jkiss.dbeaver.model.struct.rdb, org.jkiss.dbeaver.model.struct.rdb,
......
...@@ -25,7 +25,6 @@ import org.jkiss.dbeaver.model.impl.preferences.BundlePreferenceStore; ...@@ -25,7 +25,6 @@ import org.jkiss.dbeaver.model.impl.preferences.BundlePreferenceStore;
import org.jkiss.dbeaver.model.qm.QMConstants; import org.jkiss.dbeaver.model.qm.QMConstants;
import org.jkiss.dbeaver.model.qm.QMObjectType; import org.jkiss.dbeaver.model.qm.QMObjectType;
import org.jkiss.dbeaver.model.sql.SQLConstants; import org.jkiss.dbeaver.model.sql.SQLConstants;
import org.jkiss.dbeaver.model.sql.format.tokenized.SQLFormatterTokenized;
import org.jkiss.dbeaver.utils.GeneralUtils; import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.dbeaver.utils.PrefUtils; import org.jkiss.dbeaver.utils.PrefUtils;
import org.osgi.framework.Bundle; import org.osgi.framework.Bundle;
...@@ -96,7 +95,6 @@ public final class ModelPreferences ...@@ -96,7 +95,6 @@ public final class ModelPreferences
public static final String SQL_VARIABLES_ENABLED = "sql.variables.enabled"; //$NON-NLS-1$ public static final String SQL_VARIABLES_ENABLED = "sql.variables.enabled"; //$NON-NLS-1$
public static final String SQL_FILTER_FORCE_SUBSELECT = "sql.query.filter.force.subselect"; //$NON-NLS-1$ public static final String SQL_FILTER_FORCE_SUBSELECT = "sql.query.filter.force.subselect"; //$NON-NLS-1$
public final static String SQL_FORMAT_FORMATTER = "sql.format.formatter";
public final static String SQL_FORMAT_KEYWORD_CASE = "sql.format.keywordCase"; public final static String SQL_FORMAT_KEYWORD_CASE = "sql.format.keywordCase";
public final static String SQL_FORMAT_EXTERNAL_CMD = "sql.format.external.cmd"; public final static String SQL_FORMAT_EXTERNAL_CMD = "sql.format.external.cmd";
public final static String SQL_FORMAT_EXTERNAL_FILE = "sql.format.external.file"; public final static String SQL_FORMAT_EXTERNAL_FILE = "sql.format.external.file";
...@@ -212,7 +210,6 @@ public final class ModelPreferences ...@@ -212,7 +210,6 @@ public final class ModelPreferences
PrefUtils.setDefaultPreferenceValue(store, SQL_VARIABLES_ENABLED, true); PrefUtils.setDefaultPreferenceValue(store, SQL_VARIABLES_ENABLED, true);
PrefUtils.setDefaultPreferenceValue(store, SQL_FILTER_FORCE_SUBSELECT, false); PrefUtils.setDefaultPreferenceValue(store, SQL_FILTER_FORCE_SUBSELECT, false);
PrefUtils.setDefaultPreferenceValue(store, SQL_FORMAT_FORMATTER, SQLFormatterTokenized.FORMATTER_ID);
PrefUtils.setDefaultPreferenceValue(store, SQL_FORMAT_KEYWORD_CASE, ""); PrefUtils.setDefaultPreferenceValue(store, SQL_FORMAT_KEYWORD_CASE, "");
PrefUtils.setDefaultPreferenceValue(store, SQL_FORMAT_LF_BEFORE_COMMA, false); PrefUtils.setDefaultPreferenceValue(store, SQL_FORMAT_LF_BEFORE_COMMA, false);
PrefUtils.setDefaultPreferenceValue(store, SQL_FORMAT_EXTERNAL_CMD, ""); PrefUtils.setDefaultPreferenceValue(store, SQL_FORMAT_EXTERNAL_CMD, "");
......
...@@ -28,7 +28,6 @@ import org.jkiss.dbeaver.model.navigator.DBNModel; ...@@ -28,7 +28,6 @@ import org.jkiss.dbeaver.model.navigator.DBNModel;
import org.jkiss.dbeaver.model.qm.QMController; import org.jkiss.dbeaver.model.qm.QMController;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.OSDescriptor; import org.jkiss.dbeaver.model.runtime.OSDescriptor;
import org.jkiss.dbeaver.model.sql.format.SQLFormatterRegistry;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
...@@ -78,9 +77,6 @@ public interface DBPPlatform ...@@ -78,9 +77,6 @@ public interface DBPPlatform
@NotNull @NotNull
DBPDataFormatterRegistry getDataFormatterRegistry(); DBPDataFormatterRegistry getDataFormatterRegistry();
@NotNull
SQLFormatterRegistry getSQLFormatterRegistry();
@NotNull @NotNull
DBPPreferenceStore getPreferenceStore(); DBPPreferenceStore getPreferenceStore();
......
...@@ -30,8 +30,6 @@ import org.jkiss.dbeaver.model.exec.DBCSession; ...@@ -30,8 +30,6 @@ import org.jkiss.dbeaver.model.exec.DBCSession;
import org.jkiss.dbeaver.model.impl.sql.BasicSQLDialect; import org.jkiss.dbeaver.model.impl.sql.BasicSQLDialect;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor; 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.*; import org.jkiss.dbeaver.model.struct.*;
import org.jkiss.dbeaver.model.struct.rdb.DBSTableForeignKey; import org.jkiss.dbeaver.model.struct.rdb.DBSTableForeignKey;
import org.jkiss.dbeaver.model.struct.rdb.DBSTableForeignKeyColumn; import org.jkiss.dbeaver.model.struct.rdb.DBSTableForeignKeyColumn;
...@@ -295,18 +293,6 @@ public final class SQLUtils { ...@@ -295,18 +293,6 @@ public final class SQLUtils {
return result.toString(); return result.toString();
} }
public static String formatSQL(SQLDataSource dataSource, String query)
{
SQLSyntaxManager syntaxManager = new SQLSyntaxManager();
syntaxManager.init(dataSource.getSQLDialect(), dataSource.getContainer().getPreferenceStore());
SQLFormatterConfiguration configuration = new SQLFormatterConfiguration(dataSource, syntaxManager);
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) public static void appendLikeCondition(StringBuilder sql, String value, boolean not)
{ {
value = makeSQLLike(value); value = makeSQLLike(value);
......
...@@ -269,6 +269,11 @@ public class SSHTunnelConfiguratorUI implements IObjectPropertyConfigurator<DBWH ...@@ -269,6 +269,11 @@ public class SSHTunnelConfiguratorUI implements IObjectPropertyConfigurator<DBWH
properties.put(SSHConstants.PROP_CONNECT_TIMEOUT, tunnelTimeout.getText()); properties.put(SSHConstants.PROP_CONNECT_TIMEOUT, tunnelTimeout.getText());
} }
@Override
public void resetSettings(DBWHandlerConfiguration configuration) {
}
private void updatePrivateKeyVisibility() private void updatePrivateKeyVisibility()
{ {
boolean isPassword = authMethodCombo.getSelectionIndex() == 0; boolean isPassword = authMethodCombo.getSelectionIndex() == 0;
......
...@@ -31,13 +31,13 @@ Export-Package: org.jkiss.dbeaver.runtime.sql, ...@@ -31,13 +31,13 @@ Export-Package: org.jkiss.dbeaver.runtime.sql,
org.jkiss.dbeaver.ui.editors.sql, org.jkiss.dbeaver.ui.editors.sql,
org.jkiss.dbeaver.ui.editors.sql.convert, org.jkiss.dbeaver.ui.editors.sql.convert,
org.jkiss.dbeaver.ui.editors.sql.dialogs, org.jkiss.dbeaver.ui.editors.sql.dialogs,
org.jkiss.dbeaver.ui.editors.sql.format,
org.jkiss.dbeaver.ui.editors.sql.generator, org.jkiss.dbeaver.ui.editors.sql.generator,
org.jkiss.dbeaver.ui.editors.sql.handlers, org.jkiss.dbeaver.ui.editors.sql.handlers,
org.jkiss.dbeaver.ui.editors.sql.indent, org.jkiss.dbeaver.ui.editors.sql.indent,
org.jkiss.dbeaver.ui.editors.sql.internal, org.jkiss.dbeaver.ui.editors.sql.internal,
org.jkiss.dbeaver.ui.editors.sql.log, org.jkiss.dbeaver.ui.editors.sql.log,
org.jkiss.dbeaver.ui.editors.sql.preferences, org.jkiss.dbeaver.ui.editors.sql.preferences,
org.jkiss.dbeaver.ui.editors.sql.preferences.format,
org.jkiss.dbeaver.ui.editors.sql.registry, org.jkiss.dbeaver.ui.editors.sql.registry,
org.jkiss.dbeaver.ui.editors.sql.scripts, org.jkiss.dbeaver.ui.editors.sql.scripts,
org.jkiss.dbeaver.ui.editors.sql.syntax, org.jkiss.dbeaver.ui.editors.sql.syntax,
......
...@@ -2,7 +2,6 @@ Bundle-Vendor = DBeaver Corp ...@@ -2,7 +2,6 @@ Bundle-Vendor = DBeaver Corp
Bundle-Name = DBeaver UI Editors - SQL Bundle-Name = DBeaver UI Editors - SQL
extension-point.org.jkiss.dbeaver.sqlCommand.name = SQL script commands extension-point.org.jkiss.dbeaver.sqlCommand.name = SQL script commands
extension-point.org.jkiss.dbeaver.sqlFormatter.name = SQL formatters
extension-point.org.jkiss.dbeaver.sql.covertname = SQL text conversions extension-point.org.jkiss.dbeaver.sql.covertname = SQL text conversions
content-type.org.jkiss.dbeaver.sql.name = SQL Script content-type.org.jkiss.dbeaver.sql.name = SQL Script
...@@ -30,12 +29,6 @@ sql.convert.label.keep.formatting.discription = Keeps original formatting (white ...@@ -30,12 +29,6 @@ sql.convert.label.keep.formatting.discription = Keeps original formatting (white
sql.convert.label.line.delimiter.name = Line delimiter sql.convert.label.line.delimiter.name = Line delimiter
sql.convert.label.line.delimiter.discription = Delimiter for source code lines. Usually \\n or space sql.convert.label.line.delimiter.discription = Delimiter for source code lines. Usually \\n or space
sql.convert.label.line.delimiter.delphi.discription = Delimiter for source code lines. Usually #13#10 or space sql.convert.label.line.delimiter.delphi.discription = Delimiter for source code lines. Usually #13#10 or space
sql.formatter.default.name = Default formatter
sql.formatter.default.tip = Default SQL formatter
sql.formatter.compact.name = Compact formatter
sql.formatter.compact.tip = Compact SQL formatter. Similar to default formatter but with more compact output
sql.formatter.external.name = External formatter
sql.formatter.external.tip = External formatter. Uses configurable command-line executable to format SQL queries
sql.plan.view.simple.name=Simple sql.plan.view.simple.name=Simple
sql.plan.view.simple.tip=Simple execution plan presentation sql.plan.view.simple.tip=Simple execution plan presentation
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
<extension-point id="org.jkiss.dbeaver.sql.covert" name="%extension-point.org.jkiss.dbeaver.sql.covertname" schema="schema/org.jkiss.dbeaver.sql.convert.exsd"/> <extension-point id="org.jkiss.dbeaver.sql.covert" name="%extension-point.org.jkiss.dbeaver.sql.covertname" schema="schema/org.jkiss.dbeaver.sql.convert.exsd"/>
<extension-point id="org.jkiss.dbeaver.sqlCommand" name="%extension-point.org.jkiss.dbeaver.sqlCommand.name" schema="schema/org.jkiss.dbeaver.sqlCommand.exsd"/> <extension-point id="org.jkiss.dbeaver.sqlCommand" name="%extension-point.org.jkiss.dbeaver.sqlCommand.name" schema="schema/org.jkiss.dbeaver.sqlCommand.exsd"/>
<extension-point id="org.jkiss.dbeaver.sqlPresentation" name="%extension-point.org.jkiss.dbeaver.sqlCommand.name" schema="schema/org.jkiss.dbeaver.sqlPresentation.exsd"/> <extension-point id="org.jkiss.dbeaver.sqlPresentation" name="%extension-point.org.jkiss.dbeaver.sqlCommand.name" schema="schema/org.jkiss.dbeaver.sqlPresentation.exsd"/>
<extension-point id="org.jkiss.dbeaver.sqlFormatter" name="%extension-point.org.jkiss.dbeaver.sqlFormatter.name" schema="schema/org.jkiss.dbeaver.sqlFormatter.exsd"/>
<extension-point id="org.jkiss.dbeaver.sql.plan.view" name="%extension-point.org.jkiss.dbeaver.sqlPlanView.name" schema="schema/org.jkiss.dbeaver.sqlPlanView.exsd"/> <extension-point id="org.jkiss.dbeaver.sql.plan.view" name="%extension-point.org.jkiss.dbeaver.sqlPlanView.name" schema="schema/org.jkiss.dbeaver.sqlPlanView.exsd"/>
<extension point="org.eclipse.core.runtime.preferences"> <extension point="org.eclipse.core.runtime.preferences">
...@@ -39,12 +38,6 @@ ...@@ -39,12 +38,6 @@
--> -->
</extension> </extension>
<extension point="org.jkiss.dbeaver.sqlFormatter">
<formatter id="default" class="org.jkiss.dbeaver.model.sql.format.tokenized.SQLFormatterTokenized" configurerClass="org.jkiss.dbeaver.ui.editors.sql.format.tokenized.SQLTokenizedFormatterConfigurationPage" label="%sql.formatter.default.name" description="%sql.formatter.default.tip"/>
<formatter id="compact" class="org.jkiss.dbeaver.model.sql.format.tokenized.SQLFormatterCompact" configurerClass="org.jkiss.dbeaver.ui.editors.sql.format.tokenized.SQLTokenizedFormatterConfigurationPage" label="%sql.formatter.compact.name" description="%sql.formatter.compact.tip"/>
<formatter id="external" class="org.jkiss.dbeaver.model.sql.format.external.SQLFormatterExternal" configurerClass="org.jkiss.dbeaver.ui.editors.sql.format.SQLExternalFormatterConfigurationPage" label="%sql.formatter.external.name" description="%sql.formatter.external.tip"/>
</extension>
<extension point="org.jkiss.dbeaver.sqlCommand"> <extension point="org.jkiss.dbeaver.sqlCommand">
<command id="set" class="org.jkiss.dbeaver.runtime.sql.commands.SQLCommandSet" label="Set" description="Sets variable/parameter value"/> <command id="set" class="org.jkiss.dbeaver.runtime.sql.commands.SQLCommandSet" label="Set" description="Sets variable/parameter value"/>
<command id="echo" class="org.jkiss.dbeaver.runtime.sql.commands.SQLCommandEcho" label="Echo" description="Prints string to Output log"/> <command id="echo" class="org.jkiss.dbeaver.runtime.sql.commands.SQLCommandEcho" label="Echo" description="Prints string to Output log"/>
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
*/ */
package org.jkiss.dbeaver.ui.editors.sql.preferences; package org.jkiss.dbeaver.ui.editors.sql.preferences;
import org.eclipse.jface.dialogs.IDialogPage;
import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.custom.StyledText;
...@@ -31,21 +32,26 @@ import org.eclipse.swt.widgets.Control; ...@@ -31,21 +32,26 @@ import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IEditorSite; import org.eclipse.ui.IEditorSite;
import org.jkiss.dbeaver.DBException; import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log; import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.ModelPreferences;
import org.jkiss.dbeaver.model.DBPDataSource; import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBPDataSourceContainer; import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.DBPIdentifierCase; import org.jkiss.dbeaver.model.DBPIdentifierCase;
import org.jkiss.dbeaver.model.exec.DBCExecutionContext; import org.jkiss.dbeaver.model.exec.DBCExecutionContext;
import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore; import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore;
import org.jkiss.dbeaver.model.sql.SQLModelPreferences;
import org.jkiss.dbeaver.model.sql.format.SQLFormatter;
import org.jkiss.dbeaver.model.sql.format.external.SQLFormatterExternal;
import org.jkiss.dbeaver.model.sql.format.tokenized.SQLFormatterTokenized;
import org.jkiss.dbeaver.model.sql.registry.SQLFormatterConfigurationRegistry;
import org.jkiss.dbeaver.model.sql.registry.SQLFormatterDescriptor;
import org.jkiss.dbeaver.ui.UIUtils; import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.editors.StringEditorInput; import org.jkiss.dbeaver.ui.editors.StringEditorInput;
import org.jkiss.dbeaver.ui.editors.SubEditorSite; import org.jkiss.dbeaver.ui.editors.SubEditorSite;
import org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase; import org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase;
import org.jkiss.dbeaver.ui.editors.sql.SQLPreferenceConstants; import org.jkiss.dbeaver.ui.editors.sql.SQLPreferenceConstants;
import org.jkiss.dbeaver.ui.editors.sql.preferences.format.SQLExternalFormatterConfigurationPage;
import org.jkiss.dbeaver.ui.editors.sql.preferences.format.SQLFormatterConfigurator;
import org.jkiss.dbeaver.ui.editors.sql.preferences.format.tokenized.SQLTokenizedFormatterConfigurationPage;
import org.jkiss.dbeaver.ui.editors.sql.internal.SQLEditorMessages; import org.jkiss.dbeaver.ui.editors.sql.internal.SQLEditorMessages;
import org.jkiss.dbeaver.ui.editors.sql.registry.SQLFormatterConfigurationRegistry;
import org.jkiss.dbeaver.ui.editors.sql.registry.SQLFormatterConfigurator;
import org.jkiss.dbeaver.ui.editors.sql.registry.SQLFormatterDescriptor;
import org.jkiss.dbeaver.ui.preferences.TargetPrefPage; import org.jkiss.dbeaver.ui.preferences.TargetPrefPage;
import org.jkiss.dbeaver.utils.ContentUtils; import org.jkiss.dbeaver.utils.ContentUtils;
import org.jkiss.dbeaver.utils.GeneralUtils; import org.jkiss.dbeaver.utils.GeneralUtils;
...@@ -91,7 +97,7 @@ public class PrefPageSQLFormat extends TargetPrefPage ...@@ -91,7 +97,7 @@ public class PrefPageSQLFormat extends TargetPrefPage
return return
store.contains(SQLPreferenceConstants.SQL_FORMAT_BOLD_KEYWORDS) || store.contains(SQLPreferenceConstants.SQL_FORMAT_BOLD_KEYWORDS) ||
store.contains(ModelPreferences.SQL_FORMAT_FORMATTER); store.contains(SQLModelPreferences.SQL_FORMAT_FORMATTER);
} }
@Override @Override
...@@ -221,7 +227,7 @@ public class PrefPageSQLFormat extends TargetPrefPage ...@@ -221,7 +227,7 @@ public class PrefPageSQLFormat extends TargetPrefPage
{ {
styleBoldKeywords.setSelection(store.getBoolean(SQLPreferenceConstants.SQL_FORMAT_BOLD_KEYWORDS)); styleBoldKeywords.setSelection(store.getBoolean(SQLPreferenceConstants.SQL_FORMAT_BOLD_KEYWORDS));
String formatterId = store.getString(ModelPreferences.SQL_FORMAT_FORMATTER); String formatterId = store.getString(SQLModelPreferences.SQL_FORMAT_FORMATTER);
for (int i = 0; i < formatters.size(); i++) { for (int i = 0; i < formatters.size(); i++) {
if (formatters.get(i).getId().equalsIgnoreCase(formatterId)) { if (formatters.get(i).getId().equalsIgnoreCase(formatterId)) {
formatterSelector.select(i); formatterSelector.select(i);
...@@ -242,7 +248,7 @@ public class PrefPageSQLFormat extends TargetPrefPage ...@@ -242,7 +248,7 @@ public class PrefPageSQLFormat extends TargetPrefPage
} }
store.setValue(SQLPreferenceConstants.SQL_FORMAT_BOLD_KEYWORDS, styleBoldKeywords.getSelection()); store.setValue(SQLPreferenceConstants.SQL_FORMAT_BOLD_KEYWORDS, styleBoldKeywords.getSelection());
store.setValue(ModelPreferences.SQL_FORMAT_FORMATTER, store.setValue(SQLModelPreferences.SQL_FORMAT_FORMATTER,
formatters.get(formatterSelector.getSelectionIndex()).getId().toUpperCase(Locale.ENGLISH)); formatters.get(formatterSelector.getSelectionIndex()).getId().toUpperCase(Locale.ENGLISH));
PrefUtils.savePreferenceStore(store); PrefUtils.savePreferenceStore(store);
...@@ -253,7 +259,7 @@ public class PrefPageSQLFormat extends TargetPrefPage ...@@ -253,7 +259,7 @@ public class PrefPageSQLFormat extends TargetPrefPage
{ {
store.setToDefault(SQLPreferenceConstants.SQL_FORMAT_BOLD_KEYWORDS); store.setToDefault(SQLPreferenceConstants.SQL_FORMAT_BOLD_KEYWORDS);
store.setToDefault(ModelPreferences.SQL_FORMAT_FORMATTER); store.setToDefault(SQLModelPreferences.SQL_FORMAT_FORMATTER);
if (curConfigurator != null) { if (curConfigurator != null) {
curConfigurator.resetSettings(store); curConfigurator.resetSettings(store);
} }
...@@ -280,11 +286,19 @@ public class PrefPageSQLFormat extends TargetPrefPage ...@@ -280,11 +286,19 @@ public class PrefPageSQLFormat extends TargetPrefPage
SQLFormatterDescriptor selFormatter = formatters.get(formatterSelector.getSelectionIndex()); SQLFormatterDescriptor selFormatter = formatters.get(formatterSelector.getSelectionIndex());
try { try {
curConfigurator = selFormatter.createConfigurer(); SQLFormatter sqlFormatter = selFormatter.createFormatter();
if (curConfigurator != null) { // FIXME: this is a dirty hack because I'm too lazy to make proper registry/adapter for formatter UI configurators
// FIXME: for now we support only predefined list of formatters
if (sqlFormatter instanceof SQLFormatterTokenized) {
curConfigurator = new SQLTokenizedFormatterConfigurationPage();
} else if (sqlFormatter instanceof SQLFormatterExternal) {
curConfigurator = new SQLExternalFormatterConfigurationPage();
} else {
curConfigurator = GeneralUtils.adapt(sqlFormatter, SQLFormatterConfigurator.class);
}
if (curConfigurator instanceof IDialogPage) {
curConfigurator.configure(selFormatter); curConfigurator.configure(selFormatter);
((IDialogPage)curConfigurator).createControl(formatterConfigPlaceholder);
curConfigurator.createControl(formatterConfigPlaceholder);
curConfigurator.loadSettings(getTargetPreferenceStore()); curConfigurator.loadSettings(getTargetPreferenceStore());
} }
} catch (DBException e) { } catch (DBException e) {
...@@ -312,4 +326,4 @@ public class PrefPageSQLFormat extends TargetPrefPage ...@@ -312,4 +326,4 @@ public class PrefPageSQLFormat extends TargetPrefPage
sqlViewer.reloadSyntaxRules(); sqlViewer.reloadSyntaxRules();
} }
} }
\ No newline at end of file
...@@ -14,14 +14,13 @@ ...@@ -14,14 +14,13 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.jkiss.dbeaver.ui.editors.sql.format; package org.jkiss.dbeaver.ui.editors.sql.preferences.format;
import org.eclipse.jface.dialogs.DialogPage; import org.eclipse.jface.dialogs.DialogPage;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore; import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore;
import org.jkiss.dbeaver.model.sql.format.SQLFormatterConfiguration; import org.jkiss.dbeaver.model.sql.format.SQLFormatterConfiguration;
import org.jkiss.dbeaver.ui.editors.sql.registry.SQLFormatterConfigurator; import org.jkiss.dbeaver.model.sql.registry.SQLFormatterDescriptor;
import org.jkiss.dbeaver.ui.editors.sql.registry.SQLFormatterDescriptor;
public abstract class BaseFormatterConfigurationPage extends DialogPage implements SQLFormatterConfigurator { public abstract class BaseFormatterConfigurationPage extends DialogPage implements SQLFormatterConfigurator {
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.jkiss.dbeaver.ui.editors.sql.format; package org.jkiss.dbeaver.ui.editors.sql.preferences.format;
import org.eclipse.jface.fieldassist.SimpleContentProposalProvider; import org.eclipse.jface.fieldassist.SimpleContentProposalProvider;
import org.eclipse.jface.fieldassist.TextContentAdapter; import org.eclipse.jface.fieldassist.TextContentAdapter;
......
...@@ -14,15 +14,15 @@ ...@@ -14,15 +14,15 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.jkiss.dbeaver.ui.editors.sql.registry; package org.jkiss.dbeaver.ui.editors.sql.preferences.format;
import org.eclipse.jface.dialogs.IDialogPage;
import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore; import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore;
import org.jkiss.dbeaver.model.sql.registry.SQLFormatterDescriptor;
/** /**
* SQL Formatter configurer * SQL Formatter configurator
*/ */
public interface SQLFormatterConfigurator extends IDialogPage { public interface SQLFormatterConfigurator {
/** /**
* Sets configuration parameters * Sets configuration parameters
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.jkiss.dbeaver.ui.editors.sql.format.tokenized; package org.jkiss.dbeaver.ui.editors.sql.preferences.format.tokenized;
import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
...@@ -26,7 +26,7 @@ import org.jkiss.dbeaver.ModelPreferences; ...@@ -26,7 +26,7 @@ import org.jkiss.dbeaver.ModelPreferences;
import org.jkiss.dbeaver.model.DBPIdentifierCase; import org.jkiss.dbeaver.model.DBPIdentifierCase;
import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore; import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore;
import org.jkiss.dbeaver.ui.UIUtils; import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.editors.sql.format.BaseFormatterConfigurationPage; import org.jkiss.dbeaver.ui.editors.sql.preferences.format.BaseFormatterConfigurationPage;
import org.jkiss.dbeaver.ui.editors.sql.internal.SQLEditorMessages; import org.jkiss.dbeaver.ui.editors.sql.internal.SQLEditorMessages;
import org.jkiss.utils.CommonUtils; import org.jkiss.utils.CommonUtils;
......
...@@ -22,7 +22,7 @@ import org.eclipse.jface.text.source.ISourceViewer; ...@@ -22,7 +22,7 @@ import org.eclipse.jface.text.source.ISourceViewer;
import org.jkiss.dbeaver.model.sql.SQLSyntaxManager; import org.jkiss.dbeaver.model.sql.SQLSyntaxManager;
import org.jkiss.dbeaver.model.sql.format.SQLFormatter; import org.jkiss.dbeaver.model.sql.format.SQLFormatter;
import org.jkiss.dbeaver.model.sql.format.SQLFormatterConfiguration; import org.jkiss.dbeaver.model.sql.format.SQLFormatterConfiguration;
import org.jkiss.dbeaver.ui.editors.sql.registry.SQLFormatterConfigurationRegistry; import org.jkiss.dbeaver.model.sql.registry.SQLFormatterConfigurationRegistry;
import org.jkiss.dbeaver.ui.editors.sql.SQLEditorSourceViewerConfiguration; import org.jkiss.dbeaver.ui.editors.sql.SQLEditorSourceViewerConfiguration;
/** /**
......
...@@ -19,7 +19,7 @@ package org.jkiss.dbeaver.ui; ...@@ -19,7 +19,7 @@ package org.jkiss.dbeaver.ui;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
/** /**
* IDataSourceConnectionEditor * IObjectPropertyConfigurator
*/ */
public interface IObjectPropertyConfigurator<T> public interface IObjectPropertyConfigurator<T>
{ {
...@@ -29,6 +29,8 @@ public interface IObjectPropertyConfigurator<T> ...@@ -29,6 +29,8 @@ public interface IObjectPropertyConfigurator<T>
void saveSettings(T configuration); void saveSettings(T configuration);
void resetSettings(T configuration);
boolean isComplete(); boolean isComplete();
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册