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

Merge remote-tracking branch 'origin/devel' into devel

......@@ -18,8 +18,13 @@
package org.jkiss.dbeaver.core;
import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.*;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
......@@ -44,6 +49,7 @@ import org.jkiss.dbeaver.runtime.net.GlobalProxyAuthenticator;
import org.jkiss.dbeaver.runtime.net.GlobalProxySelector;
import org.jkiss.dbeaver.runtime.qm.QMControllerImpl;
import org.jkiss.dbeaver.runtime.qm.QMLogFileWriter;
import org.jkiss.utils.CommonUtils;
import org.osgi.framework.Bundle;
import org.osgi.framework.Version;
......@@ -51,7 +57,7 @@ import java.io.File;
import java.io.IOException;
import java.net.Authenticator;
import java.net.ProxySelector;
import java.text.MessageFormat;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
......@@ -71,8 +77,8 @@ public class DBeaverCore implements DBPApplication {
private static boolean standalone = false;
private static volatile boolean isClosing = false;
private File tempFolder;
private IWorkspace workspace;
private IProject tempProject;
private OSDescriptor localSystem;
private DBNModel navigatorModel;
......@@ -170,6 +176,33 @@ public class DBeaverCore implements DBPApplication {
{
long startTime = System.currentTimeMillis();
log.debug("Initialize Core...");
// Temp folder
{
try {
final java.nio.file.Path tempDirectory = Files.createTempDirectory(TEMP_PROJECT_NAME);
tempFolder = tempDirectory.toFile();
} catch (IOException e) {
final String sysTempFolder = System.getProperty("java.io.tmpdir");
if (!CommonUtils.isEmpty(sysTempFolder)) {
tempFolder = new File(sysTempFolder, TEMP_PROJECT_NAME);
if (!tempFolder.mkdirs()){
final String sysUserFolder = System.getProperty("user.home");
if (!CommonUtils.isEmpty(sysUserFolder)) {
tempFolder = new File(sysUserFolder, TEMP_PROJECT_NAME);
if (!tempFolder.mkdirs()){
tempFolder = new File(TEMP_PROJECT_NAME);
if (!tempFolder.mkdirs()){
log.error("Can't create temp directory!");
}
}
}
}
}
}
}
// Register properties adapter
this.workspace = ResourcesPlugin.getWorkspace();
......@@ -215,30 +248,6 @@ public class DBeaverCore implements DBPApplication {
} catch (DBException e) {
log.error("Error loading projects", e);
}
try {
// Temp project
tempProject = workspace.getRoot().getProject(TEMP_PROJECT_NAME);
if (tempProject.exists()) {
try {
tempProject.delete(true, true, monitor);
} catch (CoreException e) {
log.error("Can't delete temp project", e);
}
}
IProjectDescription description = workspace.newProjectDescription(TEMP_PROJECT_NAME);
description.setName(TEMP_PROJECT_NAME);
description.setComment("Project for DBeaver temporary content");
try {
tempProject.create(description, IProject.HIDDEN, monitor);
} catch (CoreException e) {
log.error("Can't create temp project", e);
}
tempProject.open(monitor);
} catch (Throwable e) {
log.error("Cannot open temp project", e); //$NON-NLS-1$
}
}
public synchronized void dispose()
......@@ -272,18 +281,6 @@ public class DBeaverCore implements DBPApplication {
this.projectRegistry = null;
}
// Cleanup temp project
IProgressMonitor monitor = new NullProgressMonitor();
if (workspace != null) {
if (tempProject != null && tempProject.exists()) {
try {
tempProject.delete(true, true, monitor);
} catch (CoreException e) {
log.warn("Can't cleanup temp project", e);
}
}
}
if (this.qmLogWriter != null) {
this.queryManager.unregisterMetaListener(qmLogWriter);
this.qmLogWriter.dispose();
......@@ -297,6 +294,7 @@ public class DBeaverCore implements DBPApplication {
if (isStandalone() && workspace != null) {
try {
IProgressMonitor monitor = new NullProgressMonitor();
workspace.save(true, monitor);
} catch (CoreException ex) {
log.error("Can't save workspace", ex); //$NON-NLS-1$
......@@ -375,27 +373,8 @@ public class DBeaverCore implements DBPApplication {
return projectRegistry;
}
public IProject getTempProject() {
return tempProject;
}
@NotNull
public IFolder getTempFolder(DBRProgressMonitor monitor, String name)
throws IOException
{
if (tempProject == null) {
throw new IOException("Temp project wasn't initialized properly");
}
IPath tempPath = tempProject.getProjectRelativePath().append(name);
IFolder tempFolder = tempProject.getFolder(tempPath);
if (!tempFolder.exists()) {
try {
tempFolder.create(true, true, monitor.getNestedMonitor());
tempFolder.setHidden(true);
} catch (CoreException ex) {
throw new IOException(MessageFormat.format(CoreMessages.DBeaverCore_error_can_create_temp_dir, tempFolder.toString()), ex);
}
}
public File getTempFolder(DBRProgressMonitor monitor, String name) {
return tempFolder;
}
......
......@@ -565,7 +565,6 @@ public class DataSourceDescriptor
log.debug("Connect with '" + getName() + "' (" + getId() + ")");
connecting = true;
DBPConnectionConfiguration savedConnectionInfo = null;
tunnelConnectionInfo = null;
try {
// Handle tunnel
......@@ -590,10 +589,6 @@ public class DataSourceDescriptor
}
monitor.worked(1);
}
if (tunnelConnectionInfo != null) {
savedConnectionInfo = connectionInfo;
connectionInfo = tunnelConnectionInfo;
}
monitor.subTask("Connect to data source");
dataSource = getDriver().getDataSourceProvider().openDataSource(monitor, this);
monitor.worked(1);
......@@ -638,9 +633,6 @@ public class DataSourceDescriptor
}
} finally {
monitor.done();
if (savedConnectionInfo != null) {
connectionInfo = savedConnectionInfo;
}
connecting = false;
}
}
......
......@@ -20,6 +20,7 @@ package org.jkiss.dbeaver.registry;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.jface.text.templates.TemplateContextType;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.core.CoreMessages;
......@@ -154,6 +155,7 @@ public class DataSourceProviderDescriptor extends AbstractDescriptor
return icon;
}
@NotNull
public DBPDataSourceProvider getInstance(DriverDescriptor driver)
throws DBException
{
......
......@@ -20,6 +20,7 @@ package org.jkiss.dbeaver.registry.driver;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.DBeaverPreferences;
import org.jkiss.dbeaver.Log;
......@@ -316,6 +317,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
this.iconError = new DBIconComposite(this.iconPlain, false, null, null, isCustom() ? DBIcon.OVER_LAMP : null, DBIcon.OVER_ERROR);
}
@Nullable
@Override
public DriverClassLoader getClassLoader()
{
......@@ -338,6 +340,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
return providerDescriptor;
}
@NotNull
@Override
public DBPDataSourceProvider getDataSourceProvider()
throws DBException
......@@ -345,6 +348,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
return providerDescriptor.getInstance(this);
}
@Nullable
@Override
public DBPClientManager getClientManager()
{
......@@ -361,6 +365,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
}
}
@NotNull
@Override
public String getId()
{
......@@ -378,6 +383,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
this.category = category;
}
@NotNull
@Override
@Property(viewable = true, order = 1)
public String getName()
......@@ -402,11 +408,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
this.description = description;
}
public String getNote()
{
return note;
}
@NotNull
public String getFullName()
{
if (CommonUtils.isEmpty(category)) {
......@@ -429,6 +431,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
* Driver icon, includes overlays for driver conditions (custom, invalid, etc)..
* @return icon
*/
@NotNull
@Override
public DBPImage getIcon()
{
......@@ -464,6 +467,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
this.disabled = disabled;
}
@Nullable
@Override
@Property(viewable = true, order = 2)
public String getDriverClassName()
......@@ -479,8 +483,9 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
}
}
@NotNull
@Override
public Object getDriverInstance(DBRRunnableContext runnableContext)
public Object getDriverInstance(@NotNull DBRRunnableContext runnableContext)
throws DBException
{
if (driverInstance == null) {
......@@ -516,6 +521,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
}
}
@Nullable
@Override
public String getDefaultPort()
{
......@@ -527,6 +533,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
this.driverDefaultPort = driverDefaultPort;
}
@Nullable
@Override
@Property(viewable = true, order = 3)
public String getSampleURL()
......@@ -539,6 +546,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
this.sampleURL = sampleURL;
}
@Nullable
@Override
public String getWebURL()
{
......@@ -578,6 +586,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
return customDriverLoader;
}
@Nullable
@Override
public DBXTreeNode getNavigatorRoot() {
return providerDescriptor.getTreeDescriptor();
......@@ -600,6 +609,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
driverClassName.contains("sun.jdbc"); //$NON-NLS-1$
}
@NotNull
@Override
public Collection<String> getClientHomeIds()
{
......@@ -691,18 +701,21 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
return fileSources;
}
@NotNull
@Override
public List<DBPPropertyDescriptor> getConnectionPropertyDescriptors()
{
return connectionPropertyDescriptors;
}
@NotNull
@Override
public Map<Object, Object> getDefaultConnectionProperties()
{
return defaultConnectionProperties;
}
@NotNull
@Override
public Map<Object, Object> getConnectionProperties()
{
......@@ -725,12 +738,14 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
return defaultParameters;
}
@NotNull
@Override
public Map<Object, Object> getDriverParameters()
{
return customParameters;
}
@Nullable
@Override
public Object getDriverParameter(String name)
{
......@@ -1141,6 +1156,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver
}
}
@Nullable
@Override
public DBPClientHome getClientHome(String homeId)
{
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2015 Serge Rieder (serge@jkiss.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.jkiss.dbeaver.runtime;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.jkiss.dbeaver.ui.editors.IPersistentStorage;
import org.jkiss.dbeaver.utils.ContentUtils;
import org.jkiss.dbeaver.utils.GeneralUtils;
import java.io.*;
/**
* LocalFileStorage
*/
public class LocalFileStorage implements IStorage, IPersistentStorage {
private final File file;
public LocalFileStorage(File file) {
this.file = file;
}
@Override
public InputStream getContents() throws CoreException {
try {
return new FileInputStream(file);
} catch (FileNotFoundException e) {
throw new CoreException(GeneralUtils.makeExceptionStatus(e));
}
}
@Override
public IPath getFullPath() {
return new Path(file.getAbsolutePath());
}
@Override
public String getName() {
return file.getName();
}
@Override
public boolean isReadOnly() {
return !file.canWrite();
}
@Override
public void setContents(IProgressMonitor monitor, InputStream stream) throws CoreException {
try (OutputStream os = new FileOutputStream(file)) {
ContentUtils.copyStreams(stream, 0, os, new DefaultProgressMonitor(monitor));
} catch (IOException e) {
throw new CoreException(GeneralUtils.makeExceptionStatus(e));
}
}
@Override
public <T> T getAdapter(Class<T> adapter) {
return null;
}
}
\ No newline at end of file
......@@ -309,7 +309,7 @@ public class ContentEditor extends MultiPageAbstractEditor implements IValueEdit
} catch (Exception e) {
log.warn("Can't determine value content length", e);
// Get file length
contentLength = getEditorInput().getFile().getFullPath().toFile().length();
contentLength = getEditorInput().getContentFile().length();
}
MimeType mimeType = ContentUtils.getMimeType(contentType);
IEditorPart defaultPage = null, preferredPage = null;
......
......@@ -17,7 +17,6 @@
*/
package org.jkiss.dbeaver.ui.editors.content;
import org.jkiss.dbeaver.Log;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.*;
......@@ -31,11 +30,13 @@ import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.*;
import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.DBIcon;
import org.jkiss.dbeaver.ui.DBeaverIcons;
import org.jkiss.dbeaver.ui.UIIcon;
import org.jkiss.dbeaver.ui.dialogs.DialogUtils;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.dialogs.DialogUtils;
import org.jkiss.dbeaver.utils.ContentUtils;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
......@@ -118,17 +119,13 @@ public class ContentEditorContributor extends MultiPageEditorActionBarContributo
if (this.activeEditor != null) {
if (encodingCombo != null && !encodingCombo.isDisposed()) {
try {
String curCharset = this.activeEditor.getEditorInput().getFile().getCharset();
int charsetCount = encodingCombo.getItemCount();
for (int i = 0; i < charsetCount; i++) {
if (encodingCombo.getItem(i).equals(curCharset)) {
encodingCombo.select(i);
break;
}
String curCharset = ContentUtils.DEFAULT_CHARSET;
int charsetCount = encodingCombo.getItemCount();
for (int i = 0; i < charsetCount; i++) {
if (encodingCombo.getItem(i).equals(curCharset)) {
encodingCombo.select(i);
break;
}
} catch (CoreException e) {
log.error(e);
}
}
applyAction.setEnabled(activeEditor.isDirty());
......@@ -189,11 +186,7 @@ public class ContentEditorContributor extends MultiPageEditorActionBarContributo
{
String curCharset = null;
if (getEditor() != null) {
try {
curCharset = getEditor().getEditorInput().getFile().getCharset();
} catch (CoreException e) {
log.error(e);
}
curCharset = getEditor().getEditorInput().getFileCharset();
}
encodingCombo = UIUtils.createEncodingCombo(parent, curCharset);
encodingCombo.setToolTipText("Content Encoding");
......@@ -205,22 +198,7 @@ public class ContentEditorContributor extends MultiPageEditorActionBarContributo
final ContentEditorInput contentEditorInput = contentEditor.getEditorInput();
Combo combo = (Combo) e.widget;
final String charset = combo.getItem(combo.getSelectionIndex());
try {
contentEditor.getSite().getWorkbenchWindow().run(false, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
contentEditorInput.getFile().setCharset(charset, monitor);
} catch (CoreException e1) {
throw new InvocationTargetException(e1);
}
}
});
} catch (InvocationTargetException e1) {
log.error(e1.getTargetException());
} catch (InterruptedException e1) {
// do nothing
}
contentEditorInput.setFileCharset(charset);
}
}
......
......@@ -17,12 +17,11 @@
*/
package org.jkiss.dbeaver.ui.editors.content;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.resources.ResourceAttributes;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IPathEditorInput;
import org.eclipse.ui.IPersistableElement;
......@@ -30,14 +29,17 @@ import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.model.DBIcon;
import org.jkiss.dbeaver.model.DBPContextProvider;
import org.jkiss.dbeaver.model.data.*;
import org.jkiss.dbeaver.model.data.DBDContent;
import org.jkiss.dbeaver.model.data.DBDContentStorage;
import org.jkiss.dbeaver.model.data.DBDContentStorageLocal;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.DBCExecutionContext;
import org.jkiss.dbeaver.model.impl.TemporaryContentStorage;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.runtime.LocalFileStorage;
import org.jkiss.dbeaver.runtime.RuntimeUtils;
import org.jkiss.dbeaver.model.DBIcon;
import org.jkiss.dbeaver.ui.DBeaverIcons;
import org.jkiss.dbeaver.ui.data.IAttributeController;
import org.jkiss.dbeaver.ui.data.IValueController;
......@@ -55,8 +57,9 @@ public class ContentEditorInput implements IPathEditorInput, DBPContextProvider
private IValueController valueController;
private ContentEditorPart[] editorParts;
private IFile contentFile;
private File contentFile;
private boolean contentDetached = false;
private String fileCharset = ContentUtils.DEFAULT_CHARSET;
public ContentEditorInput(
IValueController valueController,
......@@ -69,6 +72,10 @@ public class ContentEditorInput implements IPathEditorInput, DBPContextProvider
this.prepareContent(monitor);
}
public File getContentFile() {
return contentFile;
}
public IValueController getValueController()
{
return valueController;
......@@ -129,6 +136,9 @@ public class ContentEditorInput implements IPathEditorInput, DBPContextProvider
@Override
public Object getAdapter(Class adapter)
{
if (adapter == IStorage.class) {
return new LocalFileStorage(contentFile);
}
return null;
}
......@@ -178,11 +188,8 @@ public class ContentEditorInput implements IPathEditorInput, DBPContextProvider
catch (IOException e) {
// Delete temp file
if (contentFile != null && contentFile.exists()) {
try {
contentFile.delete(true, false, monitor.getNestedMonitor());
}
catch (CoreException e1) {
log.warn("Can't delete temporary content file", e);
if (!contentFile.delete()) {
log.warn("Can't delete temporary content file '" + contentFile.getAbsolutePath() + "'");
}
}
throw new DBException("Can't delete content file", e);
......@@ -197,41 +204,26 @@ public class ContentEditorInput implements IPathEditorInput, DBPContextProvider
private void markReadOnly(boolean readOnly) throws DBException
{
ResourceAttributes attributes = contentFile.getResourceAttributes();
if (attributes != null && attributes.isReadOnly() != readOnly) {
attributes.setReadOnly(readOnly);
try {
contentFile.setResourceAttributes(attributes);
}
catch (CoreException e) {
throw new DBException("Can't set content read-only", e);
}
if (!contentFile.setWritable(!readOnly)) {
throw new DBException("Can't set content read-only");
}
}
public void release(DBRProgressMonitor monitor)
{
if (contentFile != null && !contentDetached) {
ContentUtils.deleteTempFile(monitor, contentFile);
if (!contentFile.delete()) {
log.warn("Can't delete temp file '" + contentFile.getAbsolutePath() + "'");
}
contentDetached = true;
}
}
public IFile getFile() {
return contentFile;
}
public IStorage getStorage()
throws CoreException
{
return contentFile;
}
@Nullable
@Override
public IPath getPath()
{
return contentFile == null ? null : contentFile.getLocation();
return contentFile == null ? null : new Path(contentFile.getAbsolutePath());
}
public boolean isReadOnly() {
......@@ -241,9 +233,9 @@ public class ContentEditorInput implements IPathEditorInput, DBPContextProvider
void saveToExternalFile(File file, IProgressMonitor monitor)
throws CoreException
{
try {
try (InputStream is = new FileInputStream(contentFile)) {
ContentUtils.saveContentToFile(
contentFile.getContents(true),
is,
file,
RuntimeUtils.makeMonitor(monitor));
}
......@@ -257,23 +249,9 @@ public class ContentEditorInput implements IPathEditorInput, DBPContextProvider
{
try {
try (InputStream inputStream = new FileInputStream(extFile)) {
/*
ResourceAttributes atts = contentFile.getResourceAttributes();
atts.setReadOnly(false);
contentFile.setResourceAttributes(atts);
*/
File intFile = contentFile.getLocation().toFile();
try (OutputStream outputStream = new FileOutputStream(intFile)) {
try (OutputStream outputStream = new FileOutputStream(contentFile)) {
ContentUtils.copyStreams(inputStream, extFile.length(), outputStream, RuntimeUtils.makeMonitor(monitor));
}
// Append zero empty content to trigger content refresh
contentFile.appendContents(
new ByteArrayInputStream(new byte[0]),
true,
false,
monitor);
}
}
catch (Throwable e) {
......@@ -288,17 +266,15 @@ public class ContentEditorInput implements IPathEditorInput, DBPContextProvider
markReadOnly(false);
if (contents.isNull()) {
ContentUtils.copyStreamToFile(monitor, new ByteArrayInputStream(new byte[0]), 0, contentFile);
} else {
if (storage == null) {
log.warn("Can't get data from null storage");
return;
}
if (ContentUtils.isTextContent(contents)) {
ContentUtils.copyReaderToFile(monitor, storage.getContentReader(), storage.getContentLength(), storage.getCharset(), contentFile);
try (OutputStream os = new FileOutputStream(contentFile)) {
if (contents.isNull()) {
ContentUtils.copyStreams(new ByteArrayInputStream(new byte[0]), 0, os, monitor);
} else {
ContentUtils.copyStreamToFile(monitor, storage.getContentStream(), storage.getContentLength(), contentFile);
if (storage == null) {
log.warn("Can't get data from null storage");
return;
}
ContentUtils.copyStreams(storage.getContentStream(), storage.getContentLength(), os, monitor);
}
}
......@@ -330,4 +306,12 @@ public class ContentEditorInput implements IPathEditorInput, DBPContextProvider
public DBCExecutionContext getExecutionContext() {
return valueController.getExecutionContext();
}
public String getFileCharset() {
return fileCharset;
}
public void setFileCharset(String fileCharset) {
this.fileCharset = fileCharset;
}
}
\ No newline at end of file
......@@ -95,10 +95,10 @@ public class SQLEditorInput extends ProjectFileEditorInput implements IPersistab
return super.getName();
}
return
"Script: " + getFile().getName() + " \n" +
"Connection: " + dataSourceContainer.getName() + " \n" +
"Type: " + (dataSourceContainer.getDriver() == null ? "Unknown" : dataSourceContainer.getDriver().getFullName()) + " \n" +
"URL: " + dataSourceContainer.getConnectionConfiguration().getUrl();
"Script: " + getFile().getName() +
" \nConnection: " + dataSourceContainer.getName() +
" \nType: " + (dataSourceContainer.getDriver().getFullName()) +
" \nURL: " + dataSourceContainer.getConnectionConfiguration().getUrl();
}
@Override
......
......@@ -18,7 +18,6 @@
package org.jkiss.dbeaver.model;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.jkiss.code.NotNull;
......@@ -29,6 +28,7 @@ import org.jkiss.dbeaver.model.qm.QMController;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.DBRRunnableContext;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
......@@ -60,7 +60,7 @@ public interface DBPApplication
DBPPreferenceStore getPreferenceStore();
@NotNull
IFolder getTempFolder(DBRProgressMonitor monitor, String name) throws IOException;
File getTempFolder(DBRProgressMonitor monitor, String name) throws IOException;
@NotNull
DBRRunnableContext getRunnableContext();
......
......@@ -140,6 +140,9 @@ public interface DBPDataSourceContainer extends DBSObject, DBDPreferences, DBPNa
*/
boolean reconnect(DBRProgressMonitor monitor) throws DBException;
@Nullable
DBPDataSource getDataSource();
String getFolderPath();
void setFolderPath(String folderPath);
......
......@@ -19,11 +19,9 @@
package org.jkiss.dbeaver.model.connection;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBPDataSourceProvider;
import org.jkiss.dbeaver.model.DBPImage;
import org.jkiss.dbeaver.model.DBPObject;
import org.jkiss.dbeaver.model.DBPPropertyDescriptor;
import org.jkiss.dbeaver.model.*;
import org.jkiss.dbeaver.model.navigator.meta.DBXTreeNode;
import org.jkiss.dbeaver.model.runtime.DBRRunnableContext;
......@@ -33,31 +31,43 @@ import java.util.Map;
/**
* DBPDriver
*/
public interface DBPDriver extends DBPObject
public interface DBPDriver extends DBPNamedObject
{
/**
* Driver contributor
*/
@NotNull
DBPDataSourceProvider getDataSourceProvider()
throws DBException;
/**
* Client manager or null
*/
@Nullable
DBPClientManager getClientManager();
@NotNull
String getId();
String getName();
@NotNull
String getFullName();
@Nullable
String getDescription();
String getNote();
@NotNull
DBPImage getIcon();
@Nullable
String getDriverClassName();
@Nullable
String getDefaultPort();
@Nullable
String getSampleURL();
@Nullable
String getWebURL();
boolean isClientRequired();
......@@ -69,30 +79,40 @@ public interface DBPDriver extends DBPObject
boolean isCustomDriverLoader();
@Nullable
DBXTreeNode getNavigatorRoot();
@NotNull
Collection<DBPPropertyDescriptor> getConnectionPropertyDescriptors();
@NotNull
Map<Object, Object> getDefaultConnectionProperties();
@NotNull
Map<Object, Object> getConnectionProperties();
@NotNull
Map<Object, Object> getDriverParameters();
@Nullable
Object getDriverParameter(String name);
boolean isSupportedByLocalSystem();
@NotNull
Collection<String> getClientHomeIds();
@Nullable
DBPClientHome getClientHome(String homeId);
@Nullable
ClassLoader getClassLoader();
@NotNull
Collection<? extends DBPDriverLibrary> getDriverLibraries();
Object getDriverInstance(DBRRunnableContext runnableContext) throws DBException;
@NotNull
Object getDriverInstance(@NotNull DBRRunnableContext runnableContext) throws DBException;
void loadDriver(DBRRunnableContext runnableContext) throws DBException;
......
......@@ -18,7 +18,7 @@
package org.jkiss.dbeaver.model.data;
import org.eclipse.core.resources.IFile;
import java.io.File;
/**
* Local content storage.
......@@ -28,6 +28,6 @@ import org.eclipse.core.resources.IFile;
*/
public interface DBDContentStorageLocal extends DBDContentStorage {
IFile getDataFile();
File getDataFile();
}
\ No newline at end of file
......@@ -17,9 +17,6 @@
*/
package org.jkiss.dbeaver.model.impl;
import org.jkiss.dbeaver.Log;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.jkiss.dbeaver.model.DBPApplication;
import org.jkiss.dbeaver.model.data.DBDContentStorage;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
......@@ -32,8 +29,6 @@ import java.io.*;
*/
public class ExternalContentStorage implements DBDContentStorage {
static final Log log = Log.getLog(ExternalContentStorage.class);
private final DBPApplication application;
private File file;
private String charset;
......@@ -81,17 +76,15 @@ public class ExternalContentStorage implements DBDContentStorage {
throws IOException
{
// Create new local storage
IFile tempFile = ContentUtils.createTempContentFile(monitor, application, "copy" + this.hashCode());
File tempFile = ContentUtils.createTempContentFile(monitor, application, "copy" + this.hashCode());
try {
InputStream is = new FileInputStream(file);
try {
tempFile.setContents(is, true, false, monitor.getNestedMonitor());
}
finally {
ContentUtils.close(is);
try (InputStream is = new FileInputStream(file)) {
try (OutputStream os = new FileOutputStream(tempFile)) {
ContentUtils.copyStreams(is, file.length(), os, monitor);
}
}
} catch (CoreException e) {
ContentUtils.deleteTempFile(monitor, tempFile);
} catch (IOException e) {
ContentUtils.deleteTempFile(tempFile);
throw new IOException(e);
}
return new TemporaryContentStorage(application, tempFile);
......
......@@ -17,32 +17,23 @@
*/
package org.jkiss.dbeaver.model.impl;
import org.jkiss.dbeaver.Log;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.jkiss.dbeaver.model.DBPApplication;
import org.jkiss.dbeaver.model.data.DBDContentStorage;
import org.jkiss.dbeaver.model.data.DBDContentStorageLocal;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.utils.ContentUtils;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.*;
/**
* File content storage
*/
public class TemporaryContentStorage implements DBDContentStorageLocal {
static final Log log = Log.getLog(TemporaryContentStorage.class);
private final DBPApplication application;
private IFile file;
private File file;
public TemporaryContentStorage(DBPApplication application, IFile file)
public TemporaryContentStorage(DBPApplication application, File file)
{
this.application = application;
this.file = file;
......@@ -52,44 +43,26 @@ public class TemporaryContentStorage implements DBDContentStorageLocal {
public InputStream getContentStream()
throws IOException
{
try {
return file.getContents();
}
catch (CoreException e) {
throw new IOException(e);
}
return new FileInputStream(file);
}
@Override
public Reader getContentReader()
throws IOException
{
try {
return new InputStreamReader(
file.getContents(),
file.getCharset());
}
catch (CoreException e) {
throw new IOException(e);
}
return new FileReader(file);
}
@Override
public long getContentLength()
{
return file.getLocation().toFile().length();
return file.length();
}
@Override
public String getCharset()
{
try {
return file.getCharset();
}
catch (CoreException e) {
log.warn(e);
return null;
}
return ContentUtils.DEFAULT_CHARSET;
}
@Override
......@@ -97,17 +70,15 @@ public class TemporaryContentStorage implements DBDContentStorageLocal {
throws IOException
{
// Create new local storage
IFile tempFile = ContentUtils.createTempContentFile(monitor, application, "copy" + this.hashCode());
File tempFile = ContentUtils.createTempContentFile(monitor, application, "copy" + this.hashCode());
try {
InputStream is = file.getContents(true);
try {
tempFile.setContents(is, true, false, monitor.getNestedMonitor());
try (InputStream is = new FileInputStream(file)) {
try (OutputStream os = new FileOutputStream(tempFile)) {
ContentUtils.copyStreams(is, file.length(), os, monitor);
}
}
finally {
ContentUtils.close(is);
}
} catch (CoreException e) {
ContentUtils.deleteTempFile(monitor, tempFile);
} catch (IOException e) {
ContentUtils.deleteTempFile(tempFile);
throw new IOException(e);
}
return new TemporaryContentStorage(application, tempFile);
......@@ -116,16 +87,11 @@ public class TemporaryContentStorage implements DBDContentStorageLocal {
@Override
public void release()
{
try {
file.delete(true, false, new NullProgressMonitor());
}
catch (CoreException e) {
log.warn(e);
}
ContentUtils.deleteTempFile(file);
}
@Override
public IFile getDataFile()
public File getDataFile()
{
return file;
}
......
......@@ -119,18 +119,14 @@ public abstract class JDBCDataSource
{
// Use driver properties
final Map<Object, Object> driverProperties = container.getDriver().getConnectionProperties();
if (driverProperties != null) {
for (Map.Entry<Object,Object> prop : driverProperties.entrySet()) {
connectProps.setProperty(CommonUtils.toString(prop.getKey()), CommonUtils.toString(prop.getValue()));
}
for (Map.Entry<Object,Object> prop : driverProperties.entrySet()) {
connectProps.setProperty(CommonUtils.toString(prop.getKey()), CommonUtils.toString(prop.getValue()));
}
}
DBPConnectionConfiguration connectionInfo = container.getActualConnectionConfiguration();
if (connectionInfo.getProperties() != null) {
for (Map.Entry<Object,Object> prop : connectionInfo.getProperties().entrySet()) {
connectProps.setProperty(CommonUtils.toString(prop.getKey()), CommonUtils.toString(prop.getValue()));
}
for (Map.Entry<Object,Object> prop : connectionInfo.getProperties().entrySet()) {
connectProps.setProperty(CommonUtils.toString(prop.getKey()), CommonUtils.toString(prop.getValue()));
}
if (!CommonUtils.isEmpty(connectionInfo.getUserName())) {
connectProps.put(DBConstants.DATA_SOURCE_PROPERTY_USER, getConnectionUserName(connectionInfo));
......
......@@ -17,10 +17,9 @@
*/
package org.jkiss.dbeaver.model.impl.jdbc.data;
import org.eclipse.core.resources.IFile;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.ModelPreferences;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.ModelPreferences;
import org.jkiss.dbeaver.model.DBPApplication;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.data.DBDContentStorage;
......@@ -34,11 +33,8 @@ import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import org.jkiss.dbeaver.utils.ContentUtils;
import org.jkiss.dbeaver.utils.MimeTypes;
import org.jkiss.utils.IOUtils;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.sql.Blob;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
......@@ -100,20 +96,20 @@ public class JDBCContentBLOB extends JDBCContentLOB {
}
} else {
// Create new local storage
IFile tempFile;
File tempFile;
try {
tempFile = ContentUtils.createTempContentFile(monitor, application, "blob" + blob.hashCode());
}
catch (IOException e) {
throw new DBCException("Can't create temporary file", e);
}
try {
ContentUtils.copyStreamToFile(monitor, blob.getBinaryStream(), contentLength, tempFile);
try (OutputStream os = new FileOutputStream(tempFile)) {
ContentUtils.copyStreams(blob.getBinaryStream(), contentLength, os, monitor);
} catch (IOException e) {
ContentUtils.deleteTempFile(monitor, tempFile);
throw new DBCException("IO error whle copying stream", e);
ContentUtils.deleteTempFile(tempFile);
throw new DBCException("IO error while copying stream", e);
} catch (SQLException e) {
ContentUtils.deleteTempFile(monitor, tempFile);
ContentUtils.deleteTempFile(tempFile);
throw new DBCException(e, dataSource);
}
this.storage = new TemporaryContentStorage(application, tempFile);
......
......@@ -17,13 +17,15 @@
*/
package org.jkiss.dbeaver.model.impl.jdbc.data;
import org.eclipse.core.resources.IFile;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.ModelPreferences;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.ModelPreferences;
import org.jkiss.dbeaver.model.DBPApplication;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.data.*;
import org.jkiss.dbeaver.model.data.DBDContent;
import org.jkiss.dbeaver.model.data.DBDContentCached;
import org.jkiss.dbeaver.model.data.DBDContentStorage;
import org.jkiss.dbeaver.model.data.DBDDisplayFormat;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
......@@ -32,12 +34,10 @@ import org.jkiss.dbeaver.model.impl.TemporaryContentStorage;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import org.jkiss.dbeaver.utils.ContentUtils;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.dbeaver.utils.MimeTypes;
import org.jkiss.utils.CommonUtils;
import java.io.IOException;
import java.io.Reader;
import java.io.*;
import java.sql.Clob;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
......@@ -96,20 +96,20 @@ public class JDBCContentCLOB extends JDBCContentLOB implements DBDContent {
}
} else {
// Create new local storage
IFile tempFile;
File tempFile;
try {
tempFile = ContentUtils.createTempContentFile(monitor, application, "clob" + clob.hashCode());
}
catch (IOException e) {
throw new DBCException("Can't create temp file", e);
}
try {
ContentUtils.copyReaderToFile(monitor, clob.getCharacterStream(), contentLength, GeneralUtils.DEFAULT_FILE_CHARSET_NAME, tempFile);
try (Writer os = new FileWriter(tempFile)) {
ContentUtils.copyStreams(clob.getCharacterStream(), contentLength, os, monitor);
} catch (IOException e) {
ContentUtils.deleteTempFile(monitor, tempFile);
ContentUtils.deleteTempFile(tempFile);
throw new DBCException("IO error while copying content", e);
} catch (SQLException e) {
ContentUtils.deleteTempFile(monitor, tempFile);
ContentUtils.deleteTempFile(tempFile);
throw new DBCException(e, dataSource);
}
this.storage = new TemporaryContentStorage(application, tempFile);
......
......@@ -60,20 +60,21 @@ public class ContentUtils {
}
public static IFolder getLobFolder(DBRProgressMonitor monitor, DBPApplication application)
public static File getLobFolder(DBRProgressMonitor monitor, DBPApplication application)
throws IOException
{
return application.getTempFolder(monitor, LOB_DIR);
}
public static IFile createTempContentFile(DBRProgressMonitor monitor, DBPApplication application, String fileName)
public static File createTempContentFile(DBRProgressMonitor monitor, DBPApplication application, String fileName)
throws IOException
{
IFile file = makeTempFile(
return makeTempFile(
monitor,
getLobFolder(monitor, application),
fileName,
"data");
/*
try {
String charset = application.getPreferenceStore().getString(ModelPreferences.CONTENT_HEX_ENCODING);
file.setCharset(charset, monitor.getNestedMonitor());
......@@ -81,17 +82,15 @@ public class ContentUtils {
log.error("Can't set file charset", e);
}
return file;
*/
}
public static IFile makeTempFile(DBRProgressMonitor monitor, IFolder folder, String name, String extension)
public static File makeTempFile(DBRProgressMonitor monitor, File folder, String name, String extension)
throws IOException
{
IFile tempFile = folder.getFile(name + "-" + System.currentTimeMillis() + "." + extension); //$NON-NLS-1$ //$NON-NLS-2$
try {
InputStream contents = new ByteArrayInputStream(new byte[0]);
tempFile.create(contents, true, monitor.getNestedMonitor());
} catch (CoreException ex) {
throw new IOException(MessageFormat.format(ModelMessages.DBeaverCore_error_can_create_temp_file, tempFile.toString(), folder.toString()), ex);
File tempFile = new File(folder, name + "-" + System.currentTimeMillis() + "." + extension); //$NON-NLS-1$ //$NON-NLS-2$
if (!tempFile.createNewFile()){
throw new IOException(MessageFormat.format(ModelMessages.DBeaverCore_error_can_create_temp_file, tempFile.getAbsolutePath(), folder.getAbsoluteFile()));
}
return tempFile;
}
......@@ -430,4 +429,10 @@ public class ContentUtils {
return MimeTypes.TEXT_XML.equalsIgnoreCase(content.getContentType());
}
public static void deleteTempFile(File tempFile) {
if (!tempFile.delete()) {
log.warn("Can't delete temp file '" + tempFile.getAbsolutePath() + "'");
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册