提交 89a22ede 编写于 作者: S ShadelessFox

Merge branch 'devel' of https://github.com/dbeaver/dbeaver into redshift-string-escape#10348

 Conflicts:
	plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreServerExtension.java
	plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/impls/PostgreServerExtensionBase.java
......@@ -22,6 +22,7 @@ public class DBGConstants {
public static final String BUNDLE_SYMBOLIC_NAME = "org.jkiss.dbeaver.debug.core"; //$NON-NLS-1$
public static final String ATTR_PROJECT_NAME = BUNDLE_SYMBOLIC_NAME + ".ATTR_PROJECT_NAME"; //$NON-NLS-1$
public static final String ATTR_DATASOURCE_ID = BUNDLE_SYMBOLIC_NAME + ".ATTR_DATASOURCE_ID"; //$NON-NLS-1$
public static final String ATTR_DEBUG_TYPE = BUNDLE_SYMBOLIC_NAME + ".ATTR_DEBUG_TYPE"; //$NON-NLS-1$
......
......@@ -30,7 +30,6 @@ import org.jkiss.dbeaver.debug.DBGException;
import org.jkiss.dbeaver.debug.core.model.DatabaseDebugTarget;
import org.jkiss.dbeaver.debug.core.model.DatabaseProcess;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.utils.GeneralUtils;
import java.util.Map;
......@@ -40,12 +39,7 @@ public class DatabaseLaunchDelegate extends LaunchConfigurationDelegate {
@Override
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
throws CoreException {
String datasourceId = configuration.getAttribute(DBGConstants.ATTR_DATASOURCE_ID, (String)null);
DBPDataSourceContainer datasourceDescriptor = DBUtils.findDataSource(datasourceId);
if (datasourceDescriptor == null) {
String message = NLS.bind("Unable to find data source with id {0}", datasourceId);
throw new CoreException(DebugUtils.newErrorStatus(message));
}
DBPDataSourceContainer datasourceDescriptor = DebugUtils.getDataSourceContainer(configuration);
DBGController controller = createController(datasourceDescriptor, configuration.getAttributes());
if (controller == null) {
String message = NLS.bind("Unable to find debug controller for datasource {0}", datasourceDescriptor);
......
......@@ -26,6 +26,7 @@ import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.osgi.util.NLS;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.debug.DBGConstants;
......@@ -35,6 +36,7 @@ import org.jkiss.dbeaver.debug.core.model.DatabaseStackFrame;
import org.jkiss.dbeaver.debug.internal.core.DebugCoreMessages;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.navigator.DBNDatabaseNode;
import org.jkiss.dbeaver.model.navigator.DBNModel;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
......@@ -197,4 +199,16 @@ public class DebugUtils {
public static void fireTerminate(Object source) {
fireEvent(new DebugEvent(source, DebugEvent.TERMINATE));
}
@NotNull
public static DBPDataSourceContainer getDataSourceContainer(ILaunchConfiguration configuration) throws CoreException {
String projectName = configuration.getAttribute(DBGConstants.ATTR_PROJECT_NAME, (String)null);
String datasourceId = configuration.getAttribute(DBGConstants.ATTR_DATASOURCE_ID, (String)null);
DBPDataSourceContainer datasourceDescriptor = DBUtils.findDataSource(projectName, datasourceId);
if (datasourceDescriptor == null) {
String message = NLS.bind("Unable to find data source with id {0}", datasourceId);
throw new CoreException(newErrorStatus(message));
}
return datasourceDescriptor;
}
}
......@@ -23,21 +23,15 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
import org.eclipse.debug.core.sourcelookup.ISourcePathComputerDelegate;
import org.jkiss.dbeaver.debug.DBGConstants;
import org.jkiss.dbeaver.debug.core.DebugUtils;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.DBUtils;
public class DBGSourcePathComputer implements ISourcePathComputerDelegate {
@Override
public ISourceContainer[] computeSourceContainers(ILaunchConfiguration configuration, IProgressMonitor monitor)
throws CoreException {
String datasourceId = configuration.getAttribute(DBGConstants.ATTR_DATASOURCE_ID, "");
DBPDataSourceContainer dataSource = DBUtils.findDataSource(datasourceId);
if (dataSource == null) {
throw new CoreException(DebugUtils.newErrorStatus("Can't find datasource " + datasourceId));
}
DBPDataSourceContainer dataSource = DebugUtils.getDataSourceContainer(configuration);
DatabaseNavigatorSourceContainer container = new DatabaseNavigatorSourceContainer(dataSource);
return new ISourceContainer[] { container };
}
......
......@@ -31,6 +31,7 @@ import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.PlatformUI;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.debug.DBGConstants;
import org.jkiss.dbeaver.debug.core.DebugUtils;
import org.jkiss.dbeaver.debug.ui.internal.DebugConfigurationPanelDescriptor;
......@@ -38,7 +39,6 @@ import org.jkiss.dbeaver.debug.ui.internal.DebugConfigurationPanelRegistry;
import org.jkiss.dbeaver.debug.ui.internal.DebugUIMessages;
import org.jkiss.dbeaver.model.DBIcon;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.runtime.DBRRunnableContext;
import org.jkiss.dbeaver.registry.DataSourceRegistry;
import org.jkiss.dbeaver.runtime.DBWorkbench;
......@@ -54,6 +54,8 @@ import java.util.Map;
public class DatabaseDebugConfigurationTab extends AbstractLaunchConfigurationTab implements DBGConfigurationPanelContainer {
static protected final Log log = Log.getLog(DatabaseDebugConfigurationTab.class);
private DebugConfigurationPanelDescriptor selectedDebugType;
private DBGConfigurationPanel selectedDebugPanel;
private ILaunchConfiguration currentConfiguration;
......@@ -198,8 +200,12 @@ public class DatabaseDebugConfigurationTab extends AbstractLaunchConfigurationTa
public void initializeFrom(ILaunchConfiguration configuration) {
this.currentConfiguration = configuration;
try {
String dsId = configuration.getAttribute(DBGConstants.ATTR_DATASOURCE_ID, (String) null);
DBPDataSourceContainer dataSource = DBUtils.findDataSource(dsId);
DBPDataSourceContainer dataSource = null;
try {
dataSource = DebugUtils.getDataSourceContainer(configuration);
} catch (CoreException e) {
log.debug(e);
}
connectionCombo.select(dataSource);
if (dataSource != null) {
driverText.setText(dataSource.getDriver().getFullName());
......
......@@ -43,6 +43,8 @@ import org.jkiss.dbeaver.ui.navigator.NavigatorPreferences;
import org.jkiss.dbeaver.utils.RuntimeUtils;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ResourceBundle;
......@@ -175,19 +177,21 @@ public class ERDEditorStandalone extends ERDEditorPart implements IResourceChang
private EntityDiagram loadContentFromFile(DBRProgressMonitor progressMonitor)
throws DBException
{
final IFile file = getEditorFile();
IFile resFile = getEditorFile();
IProject project = resFile == null ? DBWorkbench.getPlatform().getWorkspace().getActiveProject().getEclipseProject() : resFile.getProject();
final File localFile = EditorUtils.getLocalFileFromInput(getEditorInput());
final DiagramPart diagramPart = getDiagramPart();
EntityDiagram entityDiagram = new EntityDiagram(null, file.getName(), getContentProvider(), getDecorator());
EntityDiagram entityDiagram = new EntityDiagram(null, localFile.getName(), getContentProvider(), getDecorator());
entityDiagram.clear();
entityDiagram.setLayoutManualAllowed(true);
entityDiagram.setLayoutManualDesired(true);
diagramPart.setModel(entityDiagram);
try (final InputStream fileContent = file.getContents()) {
DiagramLoader.load(progressMonitor, file.getProject(), diagramPart, fileContent);
try (final InputStream fileContent = new FileInputStream(localFile)) {
DiagramLoader.load(progressMonitor, project, diagramPart, fileContent);
} catch (Exception e) {
log.error("Error loading ER diagram from '" + file.getName() + "'", e);
log.error("Error loading ER diagram from '" + localFile.getName() + "'", e);
}
return entityDiagram;
......
......@@ -41,6 +41,7 @@ public class PostgreSqlDebugCore {
String databaseName = procedure.getDatabase().getName();
String schemaName = procedure.getSchema().getName();
configuration.put(DBGConstants.ATTR_PROJECT_NAME, dataSourceContainer.getProject().getName());
configuration.put(DBGConstants.ATTR_DATASOURCE_ID, dataSourceContainer.getId());
configuration.put(DBGConstants.ATTR_DEBUG_TYPE, PostgreDebugConstants.DEBUG_TYPE_FUNCTION);
configuration.put(PostgreDebugConstants.ATTR_DATABASE_NAME, databaseName);
......
......@@ -84,6 +84,7 @@ public class PostgreConstants {
"oid", "oid", "Row identifier", false);
public static final String TYPE_UUID = "uuid";
public static final String TYPE_BPCHAR = "bpchar";
public static final String TYPE_VARCHAR = "varchar";
public static final String TYPE_HSTORE = "hstore";
public static final String TYPE_JSON = "json";
......
......@@ -94,8 +94,11 @@ public class PostgreDataTypeCache extends JDBCObjectCache<PostgreSchema, Postgre
private void mapAliases(PostgreSchema schema) {
// Cache aliases
if (schema.isCatalogSchema()) {
mapDataTypeAliases(schema.getDataSource().getServerType().getDataTypeAliases(), false);
mapDataTypeAliases(PostgreConstants.SERIAL_TYPES, true);
PostgreServerExtension serverType = schema.getDataSource().getServerType();
mapDataTypeAliases(serverType.getDataTypeAliases(), false);
if (serverType.supportSerialTypes()) {
mapDataTypeAliases(PostgreConstants.SERIAL_TYPES, true);
}
}
}
......
......@@ -138,5 +138,7 @@ public interface PostgreServerExtension
boolean supportsRolesWithCreateDBAbility();
boolean supportSerialTypes();
boolean supportsBackslashStringEscape();
}
......@@ -454,6 +454,11 @@ public abstract class PostgreServerExtensionBase implements PostgreServerExtensi
return supportsRoles();
}
@Override
public boolean supportSerialTypes() {
return true;
}
@Override
public boolean supportsBackslashStringEscape() {
return false;
......
......@@ -19,6 +19,7 @@ package org.jkiss.dbeaver.ext.postgresql.model.impls.redshift;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.ext.postgresql.PostgreConstants;
import org.jkiss.dbeaver.ext.postgresql.model.*;
import org.jkiss.dbeaver.ext.postgresql.model.impls.PostgreServerExtensionBase;
import org.jkiss.dbeaver.model.DBUtils;
......@@ -33,6 +34,7 @@ import org.osgi.framework.Version;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -237,6 +239,19 @@ public class PostgreServerRedshift extends PostgreServerExtensionBase {
return true;
}
@Override
public boolean supportSerialTypes() {
return false;
}
@Override
public Map<String, String> getDataTypeAliases() {
Map<String, String> aliasMap = new LinkedHashMap<>(super.getDataTypeAliases());
aliasMap.put("character", PostgreConstants.TYPE_BPCHAR);
aliasMap.put("character varying", PostgreConstants.TYPE_VARCHAR);
return aliasMap;
}
@Override
public PostgreDatabase.SchemaCache createSchemaCache(PostgreDatabase database) {
return new RedshiftSchemaCache();
......
......@@ -100,6 +100,7 @@ public class RedshiftView extends PostgreView
PostgreTableColumn viewColumn = new PostgreTableColumn(this);
viewColumn.setName(colName);
viewColumn.setPersisted(true);
String colTypeName;
int colPrecision = -1, colScale = -1;
......
......@@ -2014,6 +2014,19 @@ public final class DBUtils {
return null;
}
public static DBPDataSourceContainer findDataSource(String projectName, String dataSourceId) {
DBPProject project = null;
if (!CommonUtils.isEmpty(projectName)) {
project = DBWorkbench.getPlatform().getWorkspace().getProject(projectName);
}
if (project != null) {
return project.getDataSourceRegistry().getDataSource(dataSourceId);
} else {
return DBUtils.findDataSource(dataSourceId);
}
}
/**
* Compares two values read from database.
* Main difference with regular compare is that all numbers are compared as doubles (i.e. data type oesn't matter).
......
......@@ -20,7 +20,7 @@ import org.jkiss.dbeaver.model.meta.IPropertyValueTransformer;
import org.jkiss.dbeaver.model.struct.DBSObject;
/**
* Shows numeric value if it is not zero and not MAX_VALUE
* Shows numeric value if it is greater than zero and not MAX_VALUE
*/
public class DBDummyNumberTransformer implements IPropertyValueTransformer<DBSObject, Number> {
......@@ -30,11 +30,11 @@ public class DBDummyNumberTransformer implements IPropertyValueTransformer<DBSOb
if (value == null) {
return null;
}
if (value instanceof Double && (value.doubleValue() == 0.0 || value.doubleValue() == Double.MAX_VALUE)) {
if (value instanceof Double && (value.doubleValue() <= 0.0 || value.doubleValue() == Double.MAX_VALUE)) {
return null;
} else if (value instanceof Float && (value.floatValue() == 0.0 || value.floatValue() == Float.MAX_VALUE)) {
} else if (value instanceof Float && (value.floatValue() <= 0.0 || value.floatValue() == Float.MAX_VALUE)) {
return null;
} else if ((value.longValue() == 0 || value.longValue() == Long.MAX_VALUE || value.longValue() == Integer.MAX_VALUE)) {
} else if ((value.longValue() <= 0 || value.longValue() == Long.MAX_VALUE || value.longValue() == Integer.MAX_VALUE)) {
return null;
}
......
......@@ -50,6 +50,7 @@ public class DBRProcessDescriptor
String commandLine = variablesResolver == null ?
command.getCommand() :
GeneralUtils.replaceVariables(command.getCommand(), variablesResolver);
commandLine = CommonUtils.notEmpty(commandLine);
processBuilder = new ProcessBuilder(GeneralUtils.parseCommandLine(commandLine));
// Set working directory
......
......@@ -25,6 +25,7 @@ import org.eclipse.jface.dialogs.MessageDialogWithToggle;
import org.eclipse.jface.preference.IPreferenceNode;
import org.eclipse.jface.preference.PreferenceManager;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.*;
import org.eclipse.ui.application.IWorkbenchConfigurer;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
......@@ -32,6 +33,7 @@ import org.eclipse.ui.application.WorkbenchAdvisor;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
import org.eclipse.ui.internal.ide.application.DelayedEventsProcessor;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBeaverPreferences;
import org.jkiss.dbeaver.Log;
......@@ -101,6 +103,12 @@ public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {
"org.eclipse.debug.ui.DebugPreferencePage" // Debugger
};
//processor must be created before we start event loop
private final DelayedEventsProcessor processor;
protected ApplicationWorkbenchAdvisor() {
this.processor = new DelayedEventsProcessor(Display.getCurrent());
}
@Override
public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
......@@ -286,4 +294,10 @@ public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {
super.eventLoopException(exception);
log.error("Event loop exception", exception);
}
@Override
public void eventLoopIdle(Display display) {
processor.catchUp(display);
super.eventLoopIdle(display);
}
}
......@@ -32,7 +32,6 @@ import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.WorkbenchPlugin;
import org.eclipse.ui.internal.ide.ChooseWorkspaceData;
import org.eclipse.ui.internal.ide.ChooseWorkspaceDialog;
import org.eclipse.ui.internal.ide.application.DelayedEventsProcessor;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBeaverPreferences;
import org.jkiss.dbeaver.Log;
......@@ -408,7 +407,6 @@ public class DBeaverApplication extends BaseApplicationImpl implements DBPApplic
if (display == null) {
display = PlatformUI.createDisplay();
}
DelayedEventsProcessor processor = new DelayedEventsProcessor(display);
}
return display;
}
......@@ -679,5 +677,4 @@ public class DBeaverApplication extends BaseApplicationImpl implements DBPApplic
}
}
}
......@@ -21,7 +21,6 @@ import org.eclipse.ui.*;
import org.eclipse.ui.part.ViewPart;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.*;
import org.jkiss.dbeaver.model.app.DBPProject;
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.dbeaver.ui.UIExecutionQueue;
import org.jkiss.dbeaver.ui.UIUtils;
......@@ -83,16 +82,7 @@ public class DashboardView extends ViewPart implements IDataSourceContainerProvi
projectName = secondaryId.substring(0, divPos);
dsId = secondaryId.substring(divPos + 1);
}
DBPProject project = null;
if (!CommonUtils.isEmpty(projectName)) {
project = DBWorkbench.getPlatform().getWorkspace().getProject(projectName);
}
if (project != null) {
dataSourceContainer = project.getDataSourceRegistry().getDataSource(dsId);
} else {
dataSourceContainer = DBUtils.findDataSource(dsId);
}
dataSourceContainer = DBUtils.findDataSource(projectName, dsId);
if (dataSourceContainer == null) {
throw new IllegalStateException("Database connection '" + dsId + "' not found");
}
......
......@@ -218,9 +218,11 @@ public class ClientHomesPanel extends Composite {
public void loadHomes(DBPDriver driver) {
homesTable.removeAll();
this.driver = driver;
selectHome(null);
this.driver = driver;
DBPNativeClientLocationManager clientManager = this.driver.getNativeClientManager();
if (clientManager == null) {
log.debug("Client manager is not supported by driver '" + driver.getName() + "'"); //$NON-NLS-1$ //$NON-NLS-2$
......
......@@ -251,8 +251,13 @@ public class NavigatorHandlerObjectCreateNew extends NavigatorHandlerObjectCreat
if (metaChildren.size() == 1 && metaChildren.get(0) instanceof DBXTreeItem) {
nodeClass = node.getChildrenClass((DBXTreeItem)metaChildren.get(0));
}
// FIXME: folder.getChildrenClass may return more precise type than node.getChildrenClass
// FIXME: we probably should use it then (only if it is subclass)
{
Class<?> childrenClass = ((DBNDatabaseFolder) node).getChildrenClass();
if (nodeClass == null || (childrenClass != null && nodeClass.isAssignableFrom(childrenClass))) {
// folder.getChildrenClass may return more precise type than node.getChildrenClass
nodeClass = childrenClass;
}
}
if (nodeClass == null) {
nodeClass = ((DBNDatabaseFolder) node).getChildrenClass();
}
......
......@@ -119,7 +119,7 @@ public class TabFolderReorder
Point point = folder.toControl(folder.getDisplay().getCursorLocation());
CTabItem item = folder.getItem(new Point(point.x, point.y));
if (item != null && dragItem != null) {
swapTabs(dragItem, item);
moveTab(folder, folder.indexOf(dragItem), folder.indexOf(item));
}
}
}
......@@ -153,6 +153,29 @@ public class TabFolderReorder
});
}
public void moveTab(@NotNull CTabFolder folder, int from, int to) {
if (from == to) {
return;
}
CTabItem currTabItem = folder.getItem(from);
CTabItem nextTabItem;
if (from < to) {
for (int i = from + 1; i <= to; i++) {
nextTabItem = folder.getItem(i);
swapTabs(currTabItem, nextTabItem);
currTabItem = nextTabItem;
}
} else {
for (int i = from - 1; i >= to; i--) {
nextTabItem = folder.getItem(i);
swapTabs(currTabItem, nextTabItem);
currTabItem = nextTabItem;
}
}
}
public void swapTabs(@NotNull CTabItem src, @NotNull CTabItem dst) {
if (src == dst) {
return;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册