提交 9bdcfd85 编写于 作者: S Serge Rider

#1562 Auto-commit mode model


Former-commit-id: 274e1565
上级 8ec77bbb
...@@ -327,7 +327,7 @@ class ConnectionPageInitialization extends ConnectionWizardPage implements IData ...@@ -327,7 +327,7 @@ class ConnectionPageInitialization extends ConnectionWizardPage implements IData
return; return;
} }
try { try {
dataSource.setDefaultAutoCommit(autocommit.getSelection(), null, true, null); dataSource.setDefaultAutoCommit(autocommit.getSelection());
if (txnOptionsLoaded) { if (txnOptionsLoaded) {
int levelIndex = isolationLevel.getSelectionIndex(); int levelIndex = isolationLevel.getSelectionIndex();
if (levelIndex <= 0) { if (levelIndex <= 0) {
......
...@@ -30,7 +30,6 @@ import org.jkiss.dbeaver.model.connection.DBPDriver; ...@@ -30,7 +30,6 @@ import org.jkiss.dbeaver.model.connection.DBPDriver;
import org.jkiss.dbeaver.model.connection.DBPNativeClientLocation; import org.jkiss.dbeaver.model.connection.DBPNativeClientLocation;
import org.jkiss.dbeaver.model.data.DBDDataFormatterProfile; import org.jkiss.dbeaver.model.data.DBDDataFormatterProfile;
import org.jkiss.dbeaver.model.data.DBDValueHandler; import org.jkiss.dbeaver.model.data.DBDValueHandler;
import org.jkiss.dbeaver.model.exec.DBCExecutionContext;
import org.jkiss.dbeaver.model.impl.data.DefaultValueHandler; import org.jkiss.dbeaver.model.impl.data.DefaultValueHandler;
import org.jkiss.dbeaver.model.net.DBWNetworkHandler; import org.jkiss.dbeaver.model.net.DBWNetworkHandler;
import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore; import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore;
...@@ -158,7 +157,7 @@ class StreamDataSourceContainer implements DBPDataSourceContainer { ...@@ -158,7 +157,7 @@ class StreamDataSourceContainer implements DBPDataSourceContainer {
} }
@Override @Override
public void setDefaultAutoCommit(boolean autoCommit, @Nullable DBCExecutionContext updateContext, boolean updateConnection, @Nullable Runnable onFinish) throws DBException { public void setDefaultAutoCommit(boolean autoCommit) {
} }
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.model;
/**
* Auto-commit mode
*/
public enum DBPAutoCommitMode {
ON,
OFF,
SMART
}
...@@ -27,7 +27,6 @@ import org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration; ...@@ -27,7 +27,6 @@ import org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration;
import org.jkiss.dbeaver.model.connection.DBPDriver; import org.jkiss.dbeaver.model.connection.DBPDriver;
import org.jkiss.dbeaver.model.connection.DBPNativeClientLocation; import org.jkiss.dbeaver.model.connection.DBPNativeClientLocation;
import org.jkiss.dbeaver.model.data.DBDPreferences; import org.jkiss.dbeaver.model.data.DBDPreferences;
import org.jkiss.dbeaver.model.exec.DBCExecutionContext;
import org.jkiss.dbeaver.model.net.DBWNetworkHandler; import org.jkiss.dbeaver.model.net.DBWNetworkHandler;
import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore; import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
...@@ -102,8 +101,7 @@ public interface DBPDataSourceContainer extends DBSObject, DBDPreferences, DBPNa ...@@ -102,8 +101,7 @@ public interface DBPDataSourceContainer extends DBSObject, DBDPreferences, DBPNa
boolean isDefaultAutoCommit(); boolean isDefaultAutoCommit();
void setDefaultAutoCommit(boolean autoCommit, @Nullable DBCExecutionContext updateContext, boolean updateConnection, @Nullable Runnable onFinish) void setDefaultAutoCommit(boolean autoCommit);
throws DBException;
@Nullable @Nullable
DBPTransactionIsolation getActiveTransactionsIsolation(); DBPTransactionIsolation getActiveTransactionsIsolation();
......
...@@ -33,6 +33,7 @@ import org.jkiss.dbeaver.model.impl.struct.AbstractTable; ...@@ -33,6 +33,7 @@ import org.jkiss.dbeaver.model.impl.struct.AbstractTable;
import org.jkiss.dbeaver.model.messages.ModelMessages; import org.jkiss.dbeaver.model.messages.ModelMessages;
import org.jkiss.dbeaver.model.meta.Property; import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.sql.SQLConstants;
import org.jkiss.dbeaver.model.sql.SQLDataSource; import org.jkiss.dbeaver.model.sql.SQLDataSource;
import org.jkiss.dbeaver.model.sql.SQLDialect; import org.jkiss.dbeaver.model.sql.SQLDialect;
import org.jkiss.dbeaver.model.sql.SQLUtils; import org.jkiss.dbeaver.model.sql.SQLUtils;
...@@ -318,7 +319,7 @@ public abstract class JDBCTable<DATASOURCE extends DBPDataSource, CONTAINER exte ...@@ -318,7 +319,7 @@ public abstract class JDBCTable<DATASOURCE extends DBPDataSource, CONTAINER exte
String tableName = DBUtils.getEntityScriptName(JDBCTable.this, options); String tableName = DBUtils.getEntityScriptName(JDBCTable.this, options);
StringBuilder query = new StringBuilder(200); StringBuilder query = new StringBuilder(200);
query query
.append(useUpsert(session) ? "UPSERT" : "INSERT") .append(useUpsert(session) ? SQLConstants.KEYWORD_UPSERT : SQLConstants.KEYWORD_INSERT)
.append(" INTO ").append(tableName).append(" ("); //$NON-NLS-1$ //$NON-NLS-2$ .append(" INTO ").append(tableName).append(" ("); //$NON-NLS-1$ //$NON-NLS-2$
allNulls = true; allNulls = true;
......
...@@ -61,6 +61,13 @@ public class BasicSQLDialect implements SQLDialect { ...@@ -61,6 +61,13 @@ public class BasicSQLDialect implements SQLDialect {
private static final String[] CORE_NON_TRANSACTIONAL_KEYWORDS = new String[]{ private static final String[] CORE_NON_TRANSACTIONAL_KEYWORDS = new String[]{
SQLConstants.KEYWORD_SELECT, SQLConstants.KEYWORD_SELECT,
}; };
protected static final String[] TRANSACTIONAL_KEYWORDS = new String[]{
SQLConstants.KEYWORD_INSERT,
SQLConstants.KEYWORD_DELETE,
SQLConstants.KEYWORD_UPDATE,
SQLConstants.KEYWORD_MERGE,
SQLConstants.KEYWORD_UPSERT,
SQLConstants.KEYWORD_TRUNCATE};
public static final String[][] DEFAULT_IDENTIFIER_QUOTES = {{"\"", "\""}}; public static final String[][] DEFAULT_IDENTIFIER_QUOTES = {{"\"", "\""}};
public static final String[][] DEFAULT_STRING_QUOTES = {{"'", "'"}}; public static final String[][] DEFAULT_STRING_QUOTES = {{"'", "'"}};
...@@ -451,8 +458,12 @@ public class BasicSQLDialect implements SQLDialect { ...@@ -451,8 +458,12 @@ public class BasicSQLDialect implements SQLDialect {
// anyhow it shouldn't be transactional // anyhow it shouldn't be transactional
return false; return false;
} }
String[] ntk = getDDLKeywords(); for (String keyword : getDDLKeywords()) {
for (String keyword : ntk) { if (queryString.startsWith(keyword)) {
return !ArrayUtils.contains(getNonTransactionKeywords(), keyword);
}
}
for (String keyword : getTransactionKeywords()) {
if (queryString.startsWith(keyword)) { if (queryString.startsWith(keyword)) {
return true; return true;
} }
...@@ -460,6 +471,11 @@ public class BasicSQLDialect implements SQLDialect { ...@@ -460,6 +471,11 @@ public class BasicSQLDialect implements SQLDialect {
return false; return false;
} }
@NotNull
protected String[] getTransactionKeywords() {
return isStandardSQL() ? TRANSACTIONAL_KEYWORDS : new String[0];
}
@NotNull @NotNull
protected String[] getNonTransactionKeywords() { protected String[] getNonTransactionKeywords() {
return isStandardSQL() ? NON_TRANSACTIONAL_KEYWORDS : CORE_NON_TRANSACTIONAL_KEYWORDS; return isStandardSQL() ? NON_TRANSACTIONAL_KEYWORDS : CORE_NON_TRANSACTIONAL_KEYWORDS;
......
...@@ -31,8 +31,14 @@ public class SQLConstants { ...@@ -31,8 +31,14 @@ public class SQLConstants {
public static final String ML_COMMENT_END = "*/"; public static final String ML_COMMENT_END = "*/";
public static final String SL_COMMENT = "--"; public static final String SL_COMMENT = "--";
public static final String KEYWORD_UPDATE = "UPDATE";
public static final String KEYWORD_SELECT = "SELECT"; public static final String KEYWORD_SELECT = "SELECT";
public static final String KEYWORD_INSERT = "INSERT";
public static final String KEYWORD_UPDATE = "UPDATE";
public static final String KEYWORD_DELETE = "DELETE";
public static final String KEYWORD_MERGE = "MERGE";
public static final String KEYWORD_UPSERT = "UPSERT";
public static final String KEYWORD_TRUNCATE = "TRUNCATE";
public static final String KEYWORD_FROM = "FROM"; public static final String KEYWORD_FROM = "FROM";
public static final String KEYWORD_INTO = "INTO"; public static final String KEYWORD_INTO = "INTO";
public static final String KEYWORD_JOIN = "JOIN"; public static final String KEYWORD_JOIN = "JOIN";
...@@ -123,7 +129,7 @@ public class SQLConstants { ...@@ -123,7 +129,7 @@ public class SQLConstants {
"DEC", "DEC",
"DECLARE", "DECLARE",
"DEFAULT", "DEFAULT",
"DELETE", KEYWORD_DELETE,
"DENSE_RANK", "DENSE_RANK",
"DEREF", "DEREF",
"DESCRIBE", "DESCRIBE",
...@@ -172,7 +178,7 @@ public class SQLConstants { ...@@ -172,7 +178,7 @@ public class SQLConstants {
"INNER", "INNER",
"INOUT", "INOUT",
"INSENSITIVE", "INSENSITIVE",
"INSERT", KEYWORD_INSERT,
"INTERSECT", "INTERSECT",
"INTERSECTION", "INTERSECTION",
"INTERVAL", "INTERVAL",
...@@ -190,7 +196,7 @@ public class SQLConstants { ...@@ -190,7 +196,7 @@ public class SQLConstants {
"LOCALTIMESTAMP", "LOCALTIMESTAMP",
"MATCH", "MATCH",
"MEMBER", "MEMBER",
"MERGE", KEYWORD_MERGE,
"METHOD", "METHOD",
"MINUTE", "MINUTE",
"MOD", "MOD",
...@@ -291,7 +297,7 @@ public class SQLConstants { ...@@ -291,7 +297,7 @@ public class SQLConstants {
"UNIQUE", "UNIQUE",
"UNKNOWN", "UNKNOWN",
"UNNEST", "UNNEST",
"UPDATE", KEYWORD_UPDATE,
"USER", "USER",
"USING", "USING",
//"VALUE", // too common for column names //"VALUE", // too common for column names
......
...@@ -381,25 +381,7 @@ public class DataSourceDescriptor ...@@ -381,25 +381,7 @@ public class DataSourceDescriptor
} }
@Override @Override
public void setDefaultAutoCommit(final boolean autoCommit, @Nullable DBCExecutionContext updateContext, boolean updateConnection, @Nullable final Runnable onFinish) throws DBException { public void setDefaultAutoCommit(final boolean autoCommit) {
if (updateContext != null) {
final DBCTransactionManager txnManager = DBUtils.getTransactionManager(updateContext);
if (updateConnection && txnManager != null) {
TasksJob.runTask("Set auto-commit mode", monitor -> {
try {
// Change auto-commit mode
txnManager.setAutoCommit(monitor, autoCommit);
} catch (DBCException e) {
throw new InvocationTargetException(e);
} finally {
monitor.done();
if (onFinish != null) {
onFinish.run();
}
}
});
}
}
// Save in preferences // Save in preferences
if (autoCommit == getConnectionConfiguration().getConnectionType().isAutocommit()) { if (autoCommit == getConnectionConfiguration().getConnectionType().isAutocommit()) {
connectionInfo.getBootstrap().setDefaultAutoCommit(null); connectionInfo.getBootstrap().setDefaultAutoCommit(null);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册