提交 3ba7aab7 编写于 作者: S Serge Rider

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

......@@ -993,6 +993,11 @@ public class UIUtils {
}
public static void putSectionValueWithType(IDialogSettings dialogSettings, @NotNull String key, Object value) {
if (value == null) {
dialogSettings.put(key, ((String) null));
return;
}
if (value instanceof Double) {
dialogSettings.put(key, (Double) value);
} else
......
......@@ -30,6 +30,8 @@ public class AutoRefreshJob extends AbstractJob {
AutoRefreshJob(AutoRefreshControl refreshControl) {
super("Auto-refresh job (" + refreshControl.getControlId() + ")");
setSystem(true);
setUser(false);
this.refreshControl = refreshControl;
}
......
......@@ -2617,6 +2617,11 @@ public class ResultSetViewer extends Viewer
UIUtils.showMessageBox(viewerPanel.getShell(), "Data read", "Data read is in progress - can't run another", SWT.ICON_WARNING);
return false;
}
DBCExecutionContext executionContext = getExecutionContext();
if (executionContext == null) {
UIUtils.showMessageBox(viewerPanel.getShell(), "Data read", "Can't read data - no active connection", SWT.ICON_WARNING);
return false;
}
// Cancel any refresh jobs
autoRefreshControl.cancelRefresh();
......@@ -2633,7 +2638,7 @@ public class ResultSetViewer extends Viewer
dataContainer,
useDataFilter,
this,
getExecutionContext(),
executionContext,
progressControl);
dataPumpJob.addJobChangeListener(new JobChangeAdapter() {
@Override
......
......@@ -54,10 +54,22 @@ public class ExecutionQueueErrorJob extends AbstractUIJob {
queue);
int result = dialog.open();
switch (result) {
case IDialogConstants.STOP_ID: response = ExecutionQueueErrorResponse.STOP; break;
case IDialogConstants.SKIP_ID: response = ExecutionQueueErrorResponse.IGNORE; break;
case IDialogConstants.RETRY_ID: response = ExecutionQueueErrorResponse.RETRY; break;
default: response = ExecutionQueueErrorResponse.IGNORE_ALL; break;
case IDialogConstants.CANCEL_ID:
case IDialogConstants.STOP_ID:
response = ExecutionQueueErrorResponse.STOP;
break;
case IDialogConstants.SKIP_ID:
response = ExecutionQueueErrorResponse.IGNORE;
break;
case IDialogConstants.RETRY_ID:
response = ExecutionQueueErrorResponse.RETRY;
break;
case IDialogConstants.IGNORE_ID:
response = ExecutionQueueErrorResponse.IGNORE_ALL;
break;
default:
response = ExecutionQueueErrorResponse.STOP;
break;
}
return Status.OK_STATUS;
......
......@@ -252,6 +252,12 @@ public class TabbedFolderPageEditor extends TabbedFolderPage implements IDatabas
public TabbedFolderPageEditorSite(MultiPageEditorPart multiPageEditor, IEditorPart editor) {
super(multiPageEditor, editor);
}
@Override
public String getId() {
String id = editorDescriptor.getId();
return id;
}
@NotNull
@Override
......
......@@ -144,6 +144,9 @@ public class SessionManagerViewer
protected void onSessionSelect(DBAServerSession session)
{
if (curSession == session) {
return;
}
curSession = session;
updateSQL();
if (session == null) {
......@@ -183,15 +186,11 @@ public class SessionManagerViewer
}
protected void updateSQL() {
try {
String text = curSession == null ? "" : CommonUtils.notEmpty(curSession.getActiveQuery());
StringEditorInput sqlInput = new StringEditorInput(sessionTable.getShell().getText(), text, true, GeneralUtils.getDefaultFileEncoding());
sqlViewer.init(subSite, sqlInput);
if (sqlViewer.getTextViewer() != null) {
sqlViewer.reloadSyntaxRules();
}
} catch (PartInitException e) {
DBUserInterface.getInstance().showError(sessionTable.getShell().getText(), null, e);
String text = curSession == null ? "" : CommonUtils.notEmpty(curSession.getActiveQuery());
StringEditorInput sqlInput = new StringEditorInput(sessionTable.getShell().getText(), text, true, GeneralUtils.getDefaultFileEncoding());
sqlViewer.setInput(sqlInput);
if (sqlViewer.getTextViewer() != null) {
sqlViewer.reloadSyntaxRules();
}
}
......
......@@ -14,4 +14,6 @@ Require-Bundle: org.eclipse.core.runtime,
org.jkiss.dbeaver.core,
org.jkiss.dbeaver.ui,
org.jkiss.dbeaver.debug.core
Export-Package: org.jkiss.dbeaver.debug.ui
Export-Package: org.jkiss.dbeaver.debug.ui,
org.jkiss.dbeaver.debug.ui.actions,
org.jkiss.dbeaver.debug.ui.details
......@@ -23,21 +23,21 @@
point="org.eclipse.core.runtime.adapters">
<factory
adaptableType="org.jkiss.dbeaver.ui.editors.entity.EntityEditor"
class="org.jkiss.dbeaver.debug.internal.ui.actions.DebugActionAdapterFactory">
class="org.jkiss.dbeaver.debug.ui.actions.DebugActionAdapterFactory">
<adapter
type="org.eclipse.debug.ui.actions.IToggleBreakpointsTarget">
</adapter>
</factory>
<factory
adaptableType="org.jkiss.dbeaver.ui.editors.entity.EntityEditorInput"
class="org.jkiss.dbeaver.debug.internal.ui.actions.DebugActionAdapterFactory">
class="org.jkiss.dbeaver.debug.ui.actions.DebugActionAdapterFactory">
<adapter
type="org.eclipse.debug.ui.actions.ILaunchable">
</adapter>
</factory>
<factory
adaptableType="org.jkiss.dbeaver.model.navigator.DBNDatabaseObject"
class="org.jkiss.dbeaver.debug.internal.ui.actions.DebugActionAdapterFactory">
class="org.jkiss.dbeaver.debug.ui.actions.DebugActionAdapterFactory">
<adapter
type="org.eclipse.debug.ui.actions.ILaunchable">
</adapter>
......
package org.jkiss.dbeaver.debug.internal.ui.actions;
package org.jkiss.dbeaver.debug.ui.actions;
import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.debug.ui.actions.ILaunchable;
import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget;
import org.jkiss.dbeaver.debug.ui.actions.ToggleProcedureBreakpointTarget;
public class DebugActionAdapterFactory implements IAdapterFactory {
......
......@@ -254,7 +254,7 @@ public class MockDataExecuteWizard extends AbstractToolWizard<DBSDataManipulato
} catch (DBException e) {
String message = " Error inserting Mock Data: " + e.getMessage() + ".";
log.error(message, e);
logPage.appendLog(message, true);
logPage.appendLog(message + "\n", true);
}
} finally {
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org)
* Copyright (C) 2010-2017 Eugene Fradkin (eugene.fradkin@gmail.com)
*
* 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.mockdata;
import org.jkiss.code.NotNull;
import org.jkiss.utils.IntKeyMap;
import java.math.BigDecimal;
import java.util.Random;
public class MockDataUtils {
public static int LONG_PRECISION = String.valueOf(Long.MAX_VALUE).length(); // 19
public static int INTEGER_PRECISION = String.valueOf(Integer.MAX_VALUE).length(); // 11
public static int SHORT_PRECISION = String.valueOf(Short.MAX_VALUE).length(); // 5
public static int BYTE_PRECISION = String.valueOf(Byte.MAX_VALUE).length(); // 3
private static final Random random = new Random();
private static IntKeyMap<Integer> degrees = new IntKeyMap<Integer>();
public static Object generateNumeric(Integer precision, Integer scale, Double min, Double max) {
// Integers
if ((scale == null || scale == 0) && (precision != null && precision != 0)) {
if (precision <= BYTE_PRECISION) {
return new Byte((byte) randomInteger(degree(precision), min, max));
}
if (precision <= SHORT_PRECISION) {
return new Short((short) randomInteger(degree(precision), min, max));
}
if (precision <= INTEGER_PRECISION) {
return randomInteger(degree(precision), min, max);
}
if (precision <= LONG_PRECISION) {
return new Long(getRandomLong(min, max, random));
}
// Default integer number
return null; // TODO new BigInteger();
}
// Non-integers
else {
if (precision != null && precision > 0) {
int scl = scale != null ? scale : 0;
StringBuilder sb = new StringBuilder();
if (precision <= scl) {
sb.append('0');
} else {
sb.append(randomInteger(degree(precision - scl), 0d, null));
}
if (scl > 0) {
sb.append('.');
sb.append(randomInteger(degree(scl), 0d, null));
}
return new BigDecimal(sb.toString());
} else {
return new BigDecimal(getRandomLong(min, max, random));
}
}
}
public static int getRandomInt(int min, int max, @NotNull Random random) {
if (min == Integer.MIN_VALUE && max == Integer.MAX_VALUE) {
return random.nextInt();
}
long dif = (long) max - (long) min;
float number = random.nextFloat(); // 0 <= number < 1
return ((int) ((long) min + number * dif));
}
public static double getRandomDouble(double min, double max, @NotNull Random random) {
double dif = max - min;
double number = random.nextDouble(); // 0 <= number < 1
return min + number * dif;
}
private static long getRandomLong(Double min, Double max, Random random) {
long minimum = Long.MIN_VALUE;
if (min != null && min > minimum) {
minimum = Math.round(min);
}
long maximum = Long.MAX_VALUE;
if (max != null && max < maximum) {
maximum = Math.round(max);
}
return getRandomLong(minimum, maximum, random);
}
public static long getRandomLong(long min, long max, @NotNull Random random) {
if (min == Long.MIN_VALUE && max == Long.MAX_VALUE) {
return random.nextLong();
}
double dif = (double)max - (double)min;
double number = random.nextDouble(); // 0 <= number < 1
return Math.round(min + number * dif);
}
private static int degree(int d) {
Integer value = degrees.get(d);
if (value == null) {
int result = 10;
for (int i = 0; i < d - 1; i++) {
result *= 10;
}
degrees.put(d, value = result);
}
return value;
}
private static int randomInteger(int bound, Double min, Double max) {
int minimum = Integer.MIN_VALUE;
int maximum = Integer.MAX_VALUE;
if (min != null && min > minimum && min < Integer.MAX_VALUE) {
minimum = (int) Math.round(min);
}
if (max == null || max > bound) {
max = (double)bound;
}
if (max < maximum) {
maximum = (int) Math.round(max);
}
return getRandomInt(minimum, maximum, random);
}
}
......@@ -16,11 +16,6 @@ public abstract class AbstractMockValueGenerator implements MockValueGenerator {
public static final int UNIQUE_VALUES_SET_SIZE = 1000000;
protected static int LONG_PRECISION = String.valueOf(Long.MAX_VALUE).length(); // 19
protected static int INTEGER_PRECISION = String.valueOf(Integer.MAX_VALUE).length(); // 10
protected static int SHORT_PRECISION = String.valueOf(Short.MAX_VALUE).length(); // 5
protected static int BYTE_PRECISION = String.valueOf(Byte.MAX_VALUE).length(); // 3
protected DBSEntity dbsEntity;
protected DBSAttributeBase attribute;
......
......@@ -18,10 +18,10 @@
package org.jkiss.dbeaver.ext.mockdata.generator;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.mockdata.MockDataUtils;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import java.io.IOException;
import java.math.BigDecimal;
public class NumericRandomGenerator extends AbstractMockValueGenerator {
......@@ -33,52 +33,8 @@ public class NumericRandomGenerator extends AbstractMockValueGenerator {
long maxLength = attribute.getMaxLength();
Integer scale = attribute.getScale();
Integer precision = attribute.getPrecision();
// Integers
if ((scale == null || scale == 0) && (precision != null && precision != 0)) {
if (precision < BYTE_PRECISION) {
return new Byte((byte) random.nextInt(degree(r(precision))));
}
if (precision < SHORT_PRECISION) {
return new Short((short) random.nextInt(degree(r(precision))));
}
if (precision < INTEGER_PRECISION) {
return new Integer(random.nextInt(degree(r(precision))));
}
if (precision < LONG_PRECISION) {
return new Long(random.nextLong());
}
// Default integer number
return null; // TODO new BigInteger();
}
// Non-integers
else {
if (precision != null && precision > 0) {
int scl = scale != null ? scale : 0;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < precision; i++) {
sb.append(random.nextInt(10));
if (i == scale) {
sb.append('.');
}
}
return new BigDecimal(sb.reverse().toString());
} else {
return new BigDecimal(random.nextLong()); // TODO
}
}
return MockDataUtils.generateNumeric(precision, scale, null, null);
}
}
private static int degree(int d) {
int result = 10;
for (int i = 0; i < d - 1; i++) {
result *= 10;
}
return result;
}
private int r(int i) {
return random.nextInt(i);
}
}
......@@ -18,6 +18,7 @@
package org.jkiss.dbeaver.ext.mockdata.generator;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.mockdata.MockDataUtils;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSAttributeBase;
import org.jkiss.dbeaver.model.struct.DBSDataManipulator;
......@@ -63,16 +64,16 @@ public class NumericSequenceGenerator extends AbstractMockValueGenerator {
start += step;
}
Integer precision = attribute.getPrecision();
if (precision == null || precision < INTEGER_PRECISION) { // TODO ???
if (precision == null || precision < MockDataUtils.INTEGER_PRECISION) { // TODO ???
return (int)(value);
}
if (precision < BYTE_PRECISION) {
if (precision < MockDataUtils.BYTE_PRECISION) {
return (byte)(value);
}
if (precision < SHORT_PRECISION) {
if (precision < MockDataUtils.SHORT_PRECISION) {
return (short)(value);
}
if (precision < LONG_PRECISION) {
if (precision < MockDataUtils.LONG_PRECISION) {
return new Long(value);
}
......
......@@ -77,4 +77,31 @@
</shortcut>
</extension>
<extension
point="org.eclipse.core.runtime.adapters">
<factory
adaptableType="org.jkiss.dbeaver.ext.postgresql.ui.editors.PostgreSourceViewEditor"
class="org.jkiss.dbeaver.debug.ui.actions.DebugActionAdapterFactory">
<adapter
type="org.eclipse.debug.ui.actions.IToggleBreakpointsTarget">
</adapter>
</factory>
</extension>
<extension
point="org.eclipse.ui.editorActions">
<editorContribution
id="org.jkiss.dbeaver.debug.ui.editorContribution"
targetID="postgresql.source.view">
<action
actionID="RulerDoubleClick"
class="org.eclipse.debug.ui.actions.RulerToggleBreakpointActionDelegate"
icon="platform:/plugin/org.eclipse.debug.ui/$nl$/icons/full/obj16/brkp_obj.png"
id="org.jkiss.dbeaver.debug.ui.actions.ManageBreakpointRulerAction"
label="Toggle &amp;Breakpoint"
style="push">
</action>
</editorContribution>
</extension>
</plugin>
......@@ -71,19 +71,23 @@ public class PostgreGeometryValueHandler extends JDBCAbstractValueHandler {
} else if (object instanceof Geometry) {
return object;
} else if (object instanceof String) {
if (CommonUtils.isEmpty((String) object)) {
return null;
}
try {
Class<?> jtsGeometry = DBUtils.getDriverClass(session.getDataSource(), "org.postgis.jts.JtsGeometry");
return BeanUtils.invokeStaticMethod(
jtsGeometry, "geomFromString", new Class[] { String.class }, new Object[] { object }
);
} catch (Throwable e) {
throw new DBCException(e, session.getDataSource());
}
return makeGeometryFromString(session, (String) object);
} else {
throw new DBCException("Unsupported geometry value: " + object);
return makeGeometryFromString(session, object.toString());
}
}
private Object makeGeometryFromString(DBCSession session, String object) throws DBCException {
if (CommonUtils.isEmpty(object)) {
return null;
}
try {
Class<?> jtsGeometry = DBUtils.getDriverClass(session.getDataSource(), "org.postgis.jts.JtsGeometry");
return BeanUtils.invokeStaticMethod(
jtsGeometry, "geomFromString", new Class[] { String.class }, new Object[] { object }
);
} catch (Throwable e) {
throw new DBCException(e, session.getDataSource());
}
}
......
......@@ -40,6 +40,9 @@ public final class ModelPreferences
{
public static final String QUERY_ROLLBACK_ON_ERROR = "query.rollback-on-error"; //$NON-NLS-1$
public static final String EXECUTE_RECOVER_ENABLED = "execute.recover.enabled"; //$NON-NLS-1$
public static final String EXECUTE_RECOVER_RETRY_COUNT = "execute.recover.retryCount"; //$NON-NLS-1$
public static final String SCRIPT_STATEMENT_DELIMITER = "script.sql.delimiter"; //$NON-NLS-1$
public static final String SCRIPT_IGNORE_NATIVE_DELIMITER = "script.sql.ignoreNativeDelimiter"; //$NON-NLS-1$
public static final String SCRIPT_STATEMENT_DELIMITER_BLANK = "script.sql.delimiter.blank"; //$NON-NLS-1$
......@@ -110,6 +113,8 @@ public final class ModelPreferences
private static void initializeDefaultPreferences(DBPPreferenceStore store) {
// Common
PrefUtils.setDefaultPreferenceValue(store, QUERY_ROLLBACK_ON_ERROR, false);
PrefUtils.setDefaultPreferenceValue(store, EXECUTE_RECOVER_ENABLED, true);
PrefUtils.setDefaultPreferenceValue(store, EXECUTE_RECOVER_RETRY_COUNT, 1);
// SQL execution
PrefUtils.setDefaultPreferenceValue(store, SCRIPT_STATEMENT_DELIMITER, SQLConstants.DEFAULT_STATEMENT_DELIMITER);
......
......@@ -29,6 +29,7 @@ import org.jkiss.dbeaver.model.exec.*;
import org.jkiss.dbeaver.model.impl.data.DefaultValueHandler;
import org.jkiss.dbeaver.model.impl.sql.BasicSQLDialect;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress;
import org.jkiss.dbeaver.model.sql.*;
import org.jkiss.dbeaver.model.struct.*;
import org.jkiss.dbeaver.model.struct.rdb.*;
......@@ -37,6 +38,7 @@ import org.jkiss.dbeaver.utils.RuntimeUtils;
import org.jkiss.utils.ArrayUtils;
import org.jkiss.utils.CommonUtils;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
/**
......@@ -1464,4 +1466,29 @@ public final class DBUtils {
return list;
}
public static boolean tryExecuteRecover(@NotNull DBRProgressMonitor monitor, @NotNull DBPDataSource dataSource, @NotNull DBRRunnableWithProgress runnable) throws DBException {
int tryCount = 1;
if (dataSource.getContainer().getPreferenceStore().getBoolean(ModelPreferences.EXECUTE_RECOVER_ENABLED)) {
tryCount += dataSource.getContainer().getPreferenceStore().getInt(ModelPreferences.EXECUTE_RECOVER_RETRY_COUNT);
}
Throwable lastError = null;
for (int i = 0; i < tryCount; i++) {
try {
runnable.run(monitor);
lastError = null;
break;
} catch (InvocationTargetException e) {
lastError = e.getTargetException();
log.error("Operation filed. Retry cont = " + (tryCount - i), e.getTargetException());
} catch (InterruptedException e) {
log.error("Operation interrupted");
return false;
}
}
if (lastError != null) {
throw new DBException(lastError, dataSource);
}
return true;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册