提交 aa0957f6 编写于 作者: J jurgen

Model refactoring

上级 8be9b259
...@@ -25,6 +25,7 @@ import org.jkiss.dbeaver.DBException; ...@@ -25,6 +25,7 @@ import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBPApplication; import org.jkiss.dbeaver.model.DBPApplication;
import org.jkiss.dbeaver.model.DBPPreferenceStore; import org.jkiss.dbeaver.model.DBPPreferenceStore;
import org.jkiss.dbeaver.model.DBPProjectManager; import org.jkiss.dbeaver.model.DBPProjectManager;
import org.jkiss.dbeaver.model.qm.QMUtils;
import org.jkiss.dbeaver.registry.PluginServiceRegistry; import org.jkiss.dbeaver.registry.PluginServiceRegistry;
import org.jkiss.dbeaver.runtime.IPluginService; import org.jkiss.dbeaver.runtime.IPluginService;
import org.jkiss.dbeaver.runtime.net.GlobalProxyAuthenticator; import org.jkiss.dbeaver.runtime.net.GlobalProxyAuthenticator;
...@@ -161,7 +162,9 @@ public class DBeaverCore implements DBPApplication { ...@@ -161,7 +162,9 @@ public class DBeaverCore implements DBPApplication {
this.localSystem = new OSDescriptor(Platform.getOS(), Platform.getOSArch()); this.localSystem = new OSDescriptor(Platform.getOS(), Platform.getOSArch());
QMUtils.initApplication(this);
this.queryManager = new QMControllerImpl(); this.queryManager = new QMControllerImpl();
this.qmLogWriter = new QMLogFileWriter(); this.qmLogWriter = new QMLogFileWriter();
this.queryManager.registerMetaListener(qmLogWriter); this.queryManager.registerMetaListener(qmLogWriter);
...@@ -333,6 +336,11 @@ public class DBeaverCore implements DBPApplication { ...@@ -333,6 +336,11 @@ public class DBeaverCore implements DBPApplication {
return queryManager; return queryManager;
} }
@Override
public DBPPreferenceStore getPreferenceStore() {
return getGlobalPreferenceStore();
}
public ProjectRegistry getProjectRegistry() public ProjectRegistry getProjectRegistry()
{ {
return projectRegistry; return projectRegistry;
......
...@@ -22,6 +22,7 @@ import org.eclipse.core.resources.IProject; ...@@ -22,6 +22,7 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspace;
import org.jkiss.code.NotNull; import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.navigator.DBNModel; import org.jkiss.dbeaver.model.navigator.DBNModel;
import org.jkiss.dbeaver.model.qm.QMController;
import java.util.Collection; import java.util.Collection;
...@@ -35,7 +36,14 @@ public interface DBPApplication ...@@ -35,7 +36,14 @@ public interface DBPApplication
IWorkspace getWorkspace(); IWorkspace getWorkspace();
@NotNull
DBPProjectManager getProjectManager(); DBPProjectManager getProjectManager();
@NotNull
Collection<IProject> getLiveProjects(); Collection<IProject> getLiveProjects();
@NotNull
QMController getQueryManager();
@NotNull
DBPPreferenceStore getPreferenceStore();
} }
...@@ -28,6 +28,8 @@ import org.jkiss.dbeaver.model.project.DBPResourceHandler; ...@@ -28,6 +28,8 @@ import org.jkiss.dbeaver.model.project.DBPResourceHandler;
*/ */
public interface DBPProjectManager public interface DBPProjectManager
{ {
DBPApplication geApplication();
DBPResourceHandler getResourceHandler(IResource resource); DBPResourceHandler getResourceHandler(IResource resource);
IProject getActiveProject(); IProject getActiveProject();
......
...@@ -17,9 +17,9 @@ ...@@ -17,9 +17,9 @@
*/ */
package org.jkiss.dbeaver.model.impl.jdbc.data; package org.jkiss.dbeaver.model.impl.jdbc.data;
import org.jkiss.dbeaver.core.Log;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.jkiss.dbeaver.core.DBeaverCore; import org.jkiss.dbeaver.DBeaverPreferences;
import org.jkiss.dbeaver.core.Log;
import org.jkiss.dbeaver.model.DBPDataSource; import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.data.DBDContentStorage; import org.jkiss.dbeaver.model.data.DBDContentStorage;
import org.jkiss.dbeaver.model.data.DBDDisplayFormat; import org.jkiss.dbeaver.model.data.DBDDisplayFormat;
...@@ -30,7 +30,6 @@ import org.jkiss.dbeaver.model.impl.BytesContentStorage; ...@@ -30,7 +30,6 @@ import org.jkiss.dbeaver.model.impl.BytesContentStorage;
import org.jkiss.dbeaver.model.impl.TemporaryContentStorage; import org.jkiss.dbeaver.model.impl.TemporaryContentStorage;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSTypedObject; import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import org.jkiss.dbeaver.DBeaverPreferences;
import org.jkiss.dbeaver.utils.ContentUtils; import org.jkiss.dbeaver.utils.ContentUtils;
import org.jkiss.dbeaver.utils.MimeTypes; import org.jkiss.dbeaver.utils.MimeTypes;
...@@ -80,12 +79,12 @@ public class JDBCContentBLOB extends JDBCContentLOB { ...@@ -80,12 +79,12 @@ public class JDBCContentBLOB extends JDBCContentLOB {
{ {
if (storage == null && blob != null) { if (storage == null && blob != null) {
long contentLength = getContentLength(); long contentLength = getContentLength();
if (contentLength < DBeaverCore.getGlobalPreferenceStore().getInt(DBeaverPreferences.MEMORY_CONTENT_MAX_SIZE)) { if (contentLength < dataSource.getContainer().getApplication().getPreferenceStore().getInt(DBeaverPreferences.MEMORY_CONTENT_MAX_SIZE)) {
try { try {
storage = BytesContentStorage.createFromStream( storage = BytesContentStorage.createFromStream(
blob.getBinaryStream(), blob.getBinaryStream(),
contentLength, contentLength,
DBeaverCore.getGlobalPreferenceStore().getString(DBeaverPreferences.CONTENT_HEX_ENCODING)); dataSource.getContainer().getApplication().getPreferenceStore().getString(DBeaverPreferences.CONTENT_HEX_ENCODING));
} }
catch (SQLException e) { catch (SQLException e) {
throw new DBCException(e, dataSource); throw new DBCException(e, dataSource);
......
...@@ -17,10 +17,9 @@ ...@@ -17,10 +17,9 @@
*/ */
package org.jkiss.dbeaver.model.impl.jdbc.data; package org.jkiss.dbeaver.model.impl.jdbc.data;
import org.jkiss.dbeaver.core.Log;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.jkiss.dbeaver.DBeaverPreferences; import org.jkiss.dbeaver.DBeaverPreferences;
import org.jkiss.dbeaver.core.DBeaverCore; import org.jkiss.dbeaver.core.Log;
import org.jkiss.dbeaver.model.DBPDataSource; import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.data.DBDContent; import org.jkiss.dbeaver.model.data.DBDContent;
import org.jkiss.dbeaver.model.data.DBDContentStorage; import org.jkiss.dbeaver.model.data.DBDContentStorage;
...@@ -82,7 +81,7 @@ public class JDBCContentCLOB extends JDBCContentLOB implements DBDContent { ...@@ -82,7 +81,7 @@ public class JDBCContentCLOB extends JDBCContentLOB implements DBDContent {
{ {
if (storage == null && clob != null) { if (storage == null && clob != null) {
long contentLength = getContentLength(); long contentLength = getContentLength();
if (contentLength < DBeaverCore.getGlobalPreferenceStore().getInt(DBeaverPreferences.MEMORY_CONTENT_MAX_SIZE)) { if (contentLength < dataSource.getContainer().getApplication().getPreferenceStore().getInt(DBeaverPreferences.MEMORY_CONTENT_MAX_SIZE)) {
try { try {
storage = StringContentStorage.createFromReader(clob.getCharacterStream(), contentLength); storage = StringContentStorage.createFromReader(clob.getCharacterStream(), contentLength);
} }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
package org.jkiss.dbeaver.model.impl.net; package org.jkiss.dbeaver.model.impl.net;
import org.jkiss.dbeaver.DBException; import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBPApplication;
import org.jkiss.dbeaver.model.DBPConnectionConfiguration; import org.jkiss.dbeaver.model.DBPConnectionConfiguration;
import org.jkiss.dbeaver.model.net.DBWHandlerConfiguration; import org.jkiss.dbeaver.model.net.DBWHandlerConfiguration;
import org.jkiss.dbeaver.model.net.DBWTunnel; import org.jkiss.dbeaver.model.net.DBWTunnel;
...@@ -31,7 +32,7 @@ import java.io.IOException; ...@@ -31,7 +32,7 @@ import java.io.IOException;
public class HTTPTunnelImpl implements DBWTunnel { public class HTTPTunnelImpl implements DBWTunnel {
@Override @Override
public DBPConnectionConfiguration initializeTunnel(DBRProgressMonitor monitor, DBWHandlerConfiguration configuration, DBPConnectionConfiguration connectionInfo) public DBPConnectionConfiguration initializeTunnel(DBRProgressMonitor monitor, DBPApplication application, DBWHandlerConfiguration configuration, DBPConnectionConfiguration connectionInfo)
throws DBException, IOException throws DBException, IOException
{ {
return connectionInfo; return connectionInfo;
......
...@@ -20,8 +20,8 @@ package org.jkiss.dbeaver.model.impl.net; ...@@ -20,8 +20,8 @@ package org.jkiss.dbeaver.model.impl.net;
import com.jcraft.jsch.*; import com.jcraft.jsch.*;
import org.jkiss.dbeaver.DBException; import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.DBeaverPreferences; import org.jkiss.dbeaver.DBeaverPreferences;
import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.core.Log; import org.jkiss.dbeaver.core.Log;
import org.jkiss.dbeaver.model.DBPApplication;
import org.jkiss.dbeaver.model.DBPConnectionConfiguration; import org.jkiss.dbeaver.model.DBPConnectionConfiguration;
import org.jkiss.dbeaver.model.DBPPreferenceStore; import org.jkiss.dbeaver.model.DBPPreferenceStore;
import org.jkiss.dbeaver.model.net.DBWHandlerConfiguration; import org.jkiss.dbeaver.model.net.DBWHandlerConfiguration;
...@@ -48,7 +48,7 @@ public class SSHTunnelImpl implements DBWTunnel { ...@@ -48,7 +48,7 @@ public class SSHTunnelImpl implements DBWTunnel {
private transient Session session; private transient Session session;
@Override @Override
public DBPConnectionConfiguration initializeTunnel(DBRProgressMonitor monitor, DBWHandlerConfiguration configuration, DBPConnectionConfiguration connectionInfo) public DBPConnectionConfiguration initializeTunnel(DBRProgressMonitor monitor, DBPApplication application, DBWHandlerConfiguration configuration, DBPConnectionConfiguration connectionInfo)
throws DBException, IOException throws DBException, IOException
{ {
String dbPortString = connectionInfo.getHostPort(); String dbPortString = connectionInfo.getHostPort();
...@@ -107,7 +107,7 @@ public class SSHTunnelImpl implements DBWTunnel { ...@@ -107,7 +107,7 @@ public class SSHTunnelImpl implements DBWTunnel {
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw new DBException("Bad database port number: " + dbPortString); throw new DBException("Bad database port number: " + dbPortString);
} }
int localPort = findFreePort(); int localPort = findFreePort(application);
try { try {
if (jsch == null) { if (jsch == null) {
jsch = new JSch(); jsch = new JSch();
...@@ -155,9 +155,9 @@ public class SSHTunnelImpl implements DBWTunnel { ...@@ -155,9 +155,9 @@ public class SSHTunnelImpl implements DBWTunnel {
return connectionInfo; return connectionInfo;
} }
private int findFreePort() private int findFreePort(DBPApplication application)
{ {
DBPPreferenceStore store = DBeaverCore.getGlobalPreferenceStore(); DBPPreferenceStore store = application.getPreferenceStore();
int minPort = store.getInt(DBeaverPreferences.NET_TUNNEL_PORT_MIN); int minPort = store.getInt(DBeaverPreferences.NET_TUNNEL_PORT_MIN);
int maxPort = store.getInt(DBeaverPreferences.NET_TUNNEL_PORT_MAX); int maxPort = store.getInt(DBeaverPreferences.NET_TUNNEL_PORT_MAX);
int portRange = Math.abs(maxPort - minPort); int portRange = Math.abs(maxPort - minPort);
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
package org.jkiss.dbeaver.model.net; package org.jkiss.dbeaver.model.net;
import org.jkiss.dbeaver.DBException; import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBPApplication;
import org.jkiss.dbeaver.model.DBPConnectionConfiguration; import org.jkiss.dbeaver.model.DBPConnectionConfiguration;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
...@@ -28,7 +29,7 @@ import java.io.IOException; ...@@ -28,7 +29,7 @@ import java.io.IOException;
*/ */
public interface DBWTunnel extends DBWNetworkHandler { public interface DBWTunnel extends DBWNetworkHandler {
DBPConnectionConfiguration initializeTunnel(DBRProgressMonitor monitor, DBWHandlerConfiguration configuration, DBPConnectionConfiguration connectionInfo) DBPConnectionConfiguration initializeTunnel(DBRProgressMonitor monitor, DBPApplication application, DBWHandlerConfiguration configuration, DBPConnectionConfiguration connectionInfo)
throws DBException, IOException; throws DBException, IOException;
void closeTunnel(DBRProgressMonitor monitor, DBPConnectionConfiguration connectionInfo) void closeTunnel(DBRProgressMonitor monitor, DBPConnectionConfiguration connectionInfo)
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
package org.jkiss.dbeaver.model.qm; package org.jkiss.dbeaver.model.qm;
import org.jkiss.dbeaver.core.DBeaverCore; import org.jkiss.dbeaver.model.DBPApplication;
import java.util.List; import java.util.List;
...@@ -27,38 +27,43 @@ import java.util.List; ...@@ -27,38 +27,43 @@ import java.util.List;
*/ */
public class QMUtils { public class QMUtils {
private static DBPApplication application;
private static QMExecutionHandler defaultHandler; private static QMExecutionHandler defaultHandler;
public static void initApplication(DBPApplication application) {
QMUtils.application = application;
}
public static QMExecutionHandler getDefaultHandler() public static QMExecutionHandler getDefaultHandler()
{ {
if (defaultHandler == null) { if (defaultHandler == null) {
defaultHandler = DBeaverCore.getInstance().getQueryManager().getDefaultHandler(); defaultHandler = application.getQueryManager().getDefaultHandler();
} }
return defaultHandler; return defaultHandler;
} }
public static void registerHandler(QMExecutionHandler handler) public static void registerHandler(QMExecutionHandler handler)
{ {
DBeaverCore.getInstance().getQueryManager().registerHandler(handler); application.getQueryManager().registerHandler(handler);
} }
public static void unregisterHandler(QMExecutionHandler handler) public static void unregisterHandler(QMExecutionHandler handler)
{ {
DBeaverCore.getInstance().getQueryManager().unregisterHandler(handler); application.getQueryManager().unregisterHandler(handler);
} }
public static void registerMetaListener(QMMetaListener metaListener) public static void registerMetaListener(QMMetaListener metaListener)
{ {
DBeaverCore.getInstance().getQueryManager().registerMetaListener(metaListener); application.getQueryManager().registerMetaListener(metaListener);
} }
public static void unregisterMetaListener(QMMetaListener metaListener) public static void unregisterMetaListener(QMMetaListener metaListener)
{ {
DBeaverCore.getInstance().getQueryManager().unregisterMetaListener(metaListener); application.getQueryManager().unregisterMetaListener(metaListener);
} }
public static List<QMMetaEvent> getPastMetaEvents() public static List<QMMetaEvent> getPastMetaEvents()
{ {
return DBeaverCore.getInstance().getQueryManager().getPastMetaEvents(); return application.getQueryManager().getPastMetaEvents();
} }
} }
...@@ -48,6 +48,9 @@ public interface DBSDataSourceContainer extends DBSObject, DBDPreferences, DBPNa ...@@ -48,6 +48,9 @@ public interface DBSDataSourceContainer extends DBSObject, DBDPreferences, DBPNa
@NotNull @NotNull
DBPDriver getDriver(); DBPDriver getDriver();
@NotNull
DBPApplication getApplication();
/** /**
* Connection configuration. * Connection configuration.
* @return connection details * @return connection details
......
...@@ -202,6 +202,11 @@ public class DataSourceDescriptor ...@@ -202,6 +202,11 @@ public class DataSourceDescriptor
return driver; return driver;
} }
@Override
public DBPApplication getApplication() {
return registry.getApplication();
}
public void setDriver(@NotNull DriverDescriptor driver) public void setDriver(@NotNull DriverDescriptor driver)
{ {
if (driver == this.driver) { if (driver == this.driver) {
...@@ -591,7 +596,7 @@ public class DataSourceDescriptor ...@@ -591,7 +596,7 @@ public class DataSourceDescriptor
monitor.subTask("Initialize tunnel"); monitor.subTask("Initialize tunnel");
tunnel = tunnelConfiguration.createHandler(DBWTunnel.class); tunnel = tunnelConfiguration.createHandler(DBWTunnel.class);
try { try {
tunnelConnectionInfo = tunnel.initializeTunnel(monitor, tunnelConfiguration, connectionInfo); tunnelConnectionInfo = tunnel.initializeTunnel(monitor, registry.getApplication(), tunnelConfiguration, connectionInfo);
} catch (Exception e) { } catch (Exception e) {
throw new DBCException("Can't initialize tunnel", e); throw new DBCException("Can't initialize tunnel", e);
} }
......
...@@ -66,13 +66,15 @@ public class DataSourceRegistry implements DBPDataSourceRegistry ...@@ -66,13 +66,15 @@ public class DataSourceRegistry implements DBPDataSourceRegistry
public static final String CONFIG_FILE_NAME = ".dbeaver-data-sources.xml"; //$NON-NLS-1$ public static final String CONFIG_FILE_NAME = ".dbeaver-data-sources.xml"; //$NON-NLS-1$
public static final String OLD_CONFIG_FILE_NAME = "data-sources.xml"; //$NON-NLS-1$ public static final String OLD_CONFIG_FILE_NAME = "data-sources.xml"; //$NON-NLS-1$
private final DBPApplication application;
private final IProject project; private final IProject project;
private final List<DataSourceDescriptor> dataSources = new ArrayList<DataSourceDescriptor>(); private final List<DataSourceDescriptor> dataSources = new ArrayList<DataSourceDescriptor>();
private final List<DBPEventListener> dataSourceListeners = new ArrayList<DBPEventListener>(); private final List<DBPEventListener> dataSourceListeners = new ArrayList<DBPEventListener>();
public DataSourceRegistry(IProject project) public DataSourceRegistry(DBPApplication application, IProject project)
{ {
this.application = application;
this.project = project; this.project = project;
IFile configFile = project.getFile(CONFIG_FILE_NAME); IFile configFile = project.getFile(CONFIG_FILE_NAME);
if (!configFile.exists()) { if (!configFile.exists()) {
...@@ -133,6 +135,10 @@ public class DataSourceRegistry implements DBPDataSourceRegistry ...@@ -133,6 +135,10 @@ public class DataSourceRegistry implements DBPDataSourceRegistry
} }
} }
public DBPApplication getApplication() {
return application;
}
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
// Data sources // Data sources
......
...@@ -23,6 +23,7 @@ import org.eclipse.core.runtime.*; ...@@ -23,6 +23,7 @@ import org.eclipse.core.runtime.*;
import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Display;
import org.jkiss.dbeaver.DBException; import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.core.DBeaverCore; import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.model.DBPApplication;
import org.jkiss.dbeaver.model.DBPProjectManager; import org.jkiss.dbeaver.model.DBPProjectManager;
import org.jkiss.dbeaver.ui.resources.DefaultResourceHandlerImpl; import org.jkiss.dbeaver.ui.resources.DefaultResourceHandlerImpl;
import org.jkiss.dbeaver.model.project.DBPProjectListener; import org.jkiss.dbeaver.model.project.DBPProjectListener;
...@@ -170,6 +171,11 @@ public class ProjectRegistry implements DBPProjectManager { ...@@ -170,6 +171,11 @@ public class ProjectRegistry implements DBPProjectManager {
} }
} }
@Override
public DBPApplication geApplication() {
return DBeaverCore.getInstance();
}
@Override @Override
public DBPResourceHandler getResourceHandler(IResource resource) public DBPResourceHandler getResourceHandler(IResource resource)
{ {
...@@ -335,7 +341,7 @@ public class ProjectRegistry implements DBPProjectManager { ...@@ -335,7 +341,7 @@ public class ProjectRegistry implements DBPProjectManager {
log.warn("Project [" + project + "] already added"); log.warn("Project [" + project + "] already added");
return; return;
} }
projectDatabases.put(project, new DataSourceRegistry(project)); projectDatabases.put(project, new DataSourceRegistry(DBeaverCore.getInstance(), project));
} }
@Override @Override
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册