Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
601d7c52
D
dbeaver
项目概览
suliangchun
/
dbeaver
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dbeaver
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
601d7c52
编写于
4月 17, 2015
作者:
J
jurgen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Txn close & disconnect in detached job to avoid UI freeze
Former-commit-id:
2a01f488
上级
533a5a44
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
157 addition
and
126 deletion
+157
-126
plugins/org.jkiss.dbeaver.core.application/src/org/jkiss/dbeaver/core/application/ApplicationWorkbenchAdvisor.java
...dbeaver/core/application/ApplicationWorkbenchAdvisor.java
+0
-26
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/DataSourceDescriptor.java
.../src/org/jkiss/dbeaver/registry/DataSourceDescriptor.java
+93
-53
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/DataSourceRegistry.java
...re/src/org/jkiss/dbeaver/registry/DataSourceRegistry.java
+2
-36
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/runtime/RuntimeUtils.java
...aver.core/src/org/jkiss/dbeaver/runtime/RuntimeUtils.java
+58
-4
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/runtime/jobs/DisconnectJob.java
...ore/src/org/jkiss/dbeaver/runtime/jobs/DisconnectJob.java
+2
-3
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/runtime/sql/SQLQueryJob.java
...r.core/src/org/jkiss/dbeaver/runtime/sql/SQLQueryJob.java
+2
-4
未找到文件。
plugins/org.jkiss.dbeaver.core.application/src/org/jkiss/dbeaver/core/application/ApplicationWorkbenchAdvisor.java
浏览文件 @
601d7c52
...
...
@@ -140,32 +140,6 @@ public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor
if
(!
closeActiveTransactions
())
{
return
false
;
}
/*
final IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
DBRProgressMonitor nullMonitor = VoidProgressMonitor.INSTANCE;
for (IWorkbenchPage workbenchPage : workbenchWindow.getPages()) {
for (IEditorReference editorRef : workbenchPage.getEditorReferences()) {
try {
if (editorRef.getEditor(false) == null) {
continue;
}
IEditorInput editorInput = editorRef.getEditorInput();
if (editorInput instanceof IAutoSaveEditorInput && ((IAutoSaveEditorInput) editorInput).isAutoSaveEnabled()) {
IEditorPart editor = editorRef.getEditor(false);
if (editor != null) {
if (!RuntimeUtils.validateAndSave(nullMonitor, editor)) {
return false;
}
}
}
} catch (CoreException ex) {
log.error("Can't obtain editor storage", ex); //$NON-NLS-1$
}
}
}
*/
return
true
;
}
...
...
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/DataSourceDescriptor.java
浏览文件 @
601d7c52
...
...
@@ -81,6 +81,8 @@ public class DataSourceDescriptor
{
static
final
Log
log
=
Log
.
getLog
(
DataSourceDescriptor
.
class
);
public
static
final
int
END_TRANSACTION_WAIT_TIME
=
3000
;
public
static
class
FilterMapping
{
public
final
Class
<?>
type
;
public
DBSObjectFilter
defaultFilter
;
...
...
@@ -864,62 +866,67 @@ public class DataSourceDescriptor
}
// First rollback active transaction
monitor
.
subTask
(
"Rollback active transaction"
);
DBCTransactionManager
txnManager
=
DBUtils
.
getTransactionManager
(
dataSource
);
try
{
if
(
txnManager
!=
null
&&
!
txnManager
.
isAutoCommit
())
{
// Check current transaction
// If there are some executions in last savepoint then ask user about commit/rollback
QMMCollector
qmm
=
DBeaverCore
.
getInstance
().
getQueryManager
().
getMetaCollector
();
if
(
qmm
!=
null
)
{
QMMSessionInfo
qmmSession
=
qmm
.
getSessionInfo
(
dataSource
);
QMMTransactionInfo
txn
=
qmmSession
==
null
?
null
:
qmmSession
.
getTransaction
(
);
QMMTransactionSavepointInfo
sp
=
txn
==
null
?
null
:
txn
.
getCurrentSavepoint
();
if
(
sp
!=
null
&&
(
sp
.
getPrevious
()
!=
null
||
sp
.
getLastExecute
()
!=
null
))
{
boolean
hasUserExec
=
false
;
if
(
true
)
{
// Do not check whether we have user queries, just ask for confirmation
hasUserExec
=
true
;
}
else
{
for
(
QMMTransactionSavepointInfo
psp
=
sp
;
psp
!=
null
;
psp
=
psp
.
getPrevious
())
{
if
(
psp
.
hasUserExecution
s
())
{
hasUserExec
=
true
;
break
;
}
if
(
txnManager
==
null
||
txnManager
.
isAutoCommit
())
{
return
true
;
}
// If there are some executions in last savepoint then ask user about commit/rollback
QMMCollector
qmm
=
DBeaverCore
.
getInstance
().
getQueryManager
().
getMetaCollector
();
if
(
qmm
!=
null
)
{
QMMSessionInfo
qmmSession
=
qmm
.
getSessionInfo
(
dataSource
);
QMMTransactionInfo
txn
=
qmmSession
==
null
?
null
:
qmmSession
.
getTransaction
();
QMMTransactionSavepointInfo
sp
=
txn
==
null
?
null
:
txn
.
getCurrentSavepoint
();
if
(
sp
!=
null
&&
(
sp
.
getPrevious
()
!=
null
||
sp
.
getLastExecute
()
!=
null
))
{
boolean
hasUserExec
=
false
;
if
(
true
)
{
// Do not check whether we have user queries, just ask for confirmation
hasUserExec
=
true
;
}
else
{
for
(
QMMTransactionSavepointInfo
psp
=
sp
;
psp
!=
null
;
psp
=
psp
.
getPreviou
s
())
{
if
(
psp
.
hasUserExecutions
())
{
hasUserExec
=
true
;
break
;
}
}
if
(
hasUserExec
)
{
// Ask for confirmation
TransactionCloseConfirmer
closeConfirmer
=
new
TransactionCloseConfirmer
();
UIUtils
.
runInUI
(
null
,
closeConfirmer
);
DBCSession
session
=
dataSource
.
openSession
(
monitor
,
DBCExecutionPurpose
.
UTIL
,
"End active transaction"
);
try
{
switch
(
closeConfirmer
.
result
)
{
case
IDialogConstants
.
YES_ID
:
txnManager
.
commit
(
session
);
break
;
case
IDialogConstants
.
NO_ID
:
txnManager
.
rollback
(
session
,
null
);
break
;
default
:
return
false
;
}
}
finally
{
session
.
close
();
}
if
(
hasUserExec
)
{
// Ask for confirmation
TransactionCloseConfirmer
closeConfirmer
=
new
TransactionCloseConfirmer
(
getName
());
UIUtils
.
runInUI
(
null
,
closeConfirmer
);
DBCSession
session
=
dataSource
.
openSession
(
monitor
,
DBCExecutionPurpose
.
UTIL
,
"End active transaction"
);
try
{
boolean
commit
;
switch
(
closeConfirmer
.
result
)
{
case
IDialogConstants
.
YES_ID
:
commit
=
true
;
break
;
case
IDialogConstants
.
NO_ID
:
commit
=
false
;
break
;
default
:
return
false
;
}
monitor
.
subTask
(
"End active transaction"
);
EndTransactionTask
task
=
new
EndTransactionTask
(
session
,
commit
);
RuntimeUtils
.
runTask
(
task
,
END_TRANSACTION_WAIT_TIME
);
}
finally
{
session
.
close
();
}
return
true
;
}
}
}
return
true
;
}
catch
(
Throwable
e
)
{
log
.
warn
(
"Could not rollback active transaction before disconnect"
,
e
);
return
true
;
}
finally
{
monitor
.
worked
(
1
);
}
return
true
;
}
@Override
...
...
@@ -1149,19 +1156,6 @@ public class DataSourceDescriptor
}
}
private
class
TransactionCloseConfirmer
implements
Runnable
{
int
result
=
IDialogConstants
.
NO_ID
;
@Override
public
void
run
()
{
result
=
ConfirmationDialog
.
showConfirmDialog
(
null
,
DBeaverPreferences
.
CONFIRM_TXN_DISCONNECT
,
ConfirmationDialog
.
QUESTION_WITH_CANCEL
,
getName
());
}
}
public
void
copyFrom
(
DataSourceDescriptor
descriptor
)
{
filterMap
.
clear
();
for
(
FilterMapping
mapping
:
descriptor
.
getObjectFilters
())
{
...
...
@@ -1180,4 +1174,50 @@ public class DataSourceDescriptor
public
String
toString
()
{
return
name
+
" ["
+
driver
+
"]"
;
}
private
static
class
EndTransactionTask
implements
DBRRunnableWithProgress
{
private
final
DBCSession
session
;
private
final
boolean
commit
;
private
EndTransactionTask
(
DBCSession
session
,
boolean
commit
)
{
this
.
session
=
session
;
this
.
commit
=
commit
;
}
@Override
public
void
run
(
DBRProgressMonitor
monitor
)
throws
InvocationTargetException
,
InterruptedException
{
DBCTransactionManager
txnManager
=
DBUtils
.
getTransactionManager
(
session
.
getDataSource
());
if
(
txnManager
!=
null
)
{
try
{
if
(
commit
)
{
txnManager
.
commit
(
session
);
}
else
{
txnManager
.
rollback
(
session
,
null
);
}
}
catch
(
DBCException
e
)
{
throw
new
InvocationTargetException
(
e
);
}
}
}
}
private
static
class
TransactionCloseConfirmer
implements
Runnable
{
final
String
name
;
int
result
=
IDialogConstants
.
NO_ID
;
private
TransactionCloseConfirmer
(
String
name
)
{
this
.
name
=
name
;
}
@Override
public
void
run
()
{
result
=
ConfirmationDialog
.
showConfirmDialog
(
null
,
DBeaverPreferences
.
CONFIRM_TXN_DISCONNECT
,
ConfirmationDialog
.
QUESTION_WITH_CANCEL
,
name
);
}
}
}
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/registry/DataSourceRegistry.java
浏览文件 @
601d7c52
...
...
@@ -18,19 +18,15 @@
*/
package
org.jkiss.dbeaver.registry
;
import
org.jkiss.dbeaver.core.Log
;
import
org.eclipse.core.resources.IFile
;
import
org.eclipse.core.resources.IProject
;
import
org.eclipse.core.runtime.CoreException
;
import
org.eclipse.core.runtime.IProgressMonitor
;
import
org.eclipse.core.runtime.IStatus
;
import
org.eclipse.core.runtime.Status
;
import
org.eclipse.core.runtime.jobs.Job
;
import
org.eclipse.jface.resource.StringConverter
;
import
org.jkiss.code.Nullable
;
import
org.jkiss.dbeaver.DBException
;
import
org.jkiss.dbeaver.core.DBeaverCore
;
import
org.jkiss.dbeaver.core.DBeaverUI
;
import
org.jkiss.dbeaver.core.Log
;
import
org.jkiss.dbeaver.model.*
;
import
org.jkiss.dbeaver.model.net.DBWHandlerConfiguration
;
import
org.jkiss.dbeaver.model.runtime.DBRProgressMonitor
;
...
...
@@ -43,7 +39,6 @@ import org.jkiss.dbeaver.model.struct.rdb.DBSSchema;
import
org.jkiss.dbeaver.registry.encode.EncryptionException
;
import
org.jkiss.dbeaver.registry.encode.PasswordEncrypter
;
import
org.jkiss.dbeaver.registry.encode.SimpleStringEncrypter
;
import
org.jkiss.dbeaver.runtime.AbstractJob
;
import
org.jkiss.dbeaver.runtime.RuntimeUtils
;
import
org.jkiss.dbeaver.runtime.VoidProgressMonitor
;
import
org.jkiss.dbeaver.utils.AbstractPreferenceStore
;
...
...
@@ -128,34 +123,7 @@ public class DataSourceRegistry implements DBPDataSourceRegistry
return
;
}
final
DisconnectTask
disconnectTask
=
new
DisconnectTask
();
Job
disconnectJob
=
new
AbstractJob
(
"Disconnect from data sources"
)
{
@Override
protected
IStatus
run
(
DBRProgressMonitor
monitor
)
{
try
{
disconnectTask
.
run
(
monitor
);
}
catch
(
InvocationTargetException
e
)
{
return
RuntimeUtils
.
makeExceptionStatus
(
e
.
getTargetException
());
}
catch
(
InterruptedException
e
)
{
// do nothing
}
return
Status
.
OK_STATUS
;
}
};
disconnectJob
.
schedule
();
// Wait for job to finish
long
startTime
=
System
.
currentTimeMillis
();
if
(
waitTime
>
0
)
{
while
(!
disconnectTask
.
finished
&&
System
.
currentTimeMillis
()
-
startTime
<
waitTime
)
{
try
{
Thread
.
sleep
(
50
);
}
catch
(
InterruptedException
e
)
{
break
;
}
}
}
if
(!
disconnectTask
.
finished
)
{
if
(!
RuntimeUtils
.
runTask
(
disconnectTask
,
waitTime
))
{
log
.
warn
(
"Some data source connections wasn't closed on shutdown in "
+
waitTime
+
"ms. Probably network timeout occurred."
);
}
}
...
...
@@ -810,7 +778,6 @@ public class DataSourceRegistry implements DBPDataSourceRegistry
private
class
DisconnectTask
implements
DBRRunnableWithProgress
{
boolean
disconnected
;
volatile
boolean
finished
;
@Override
public
void
run
(
DBRProgressMonitor
monitor
)
throws
InvocationTargetException
,
InterruptedException
{
List
<
DataSourceDescriptor
>
dsSnapshot
;
...
...
@@ -836,7 +803,6 @@ public class DataSourceRegistry implements DBPDataSourceRegistry
}
}
finally
{
monitor
.
done
();
finished
=
true
;
}
}
}
...
...
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/runtime/RuntimeUtils.java
浏览文件 @
601d7c52
...
...
@@ -24,6 +24,7 @@ import org.apache.commons.jexl2.JexlException;
import
org.eclipse.core.resources.IFile
;
import
org.eclipse.core.resources.IResource
;
import
org.eclipse.core.runtime.*
;
import
org.eclipse.core.runtime.jobs.Job
;
import
org.eclipse.jface.dialogs.IDialogConstants
;
import
org.eclipse.jface.operation.IRunnableContext
;
import
org.eclipse.jface.operation.IRunnableWithProgress
;
...
...
@@ -44,6 +45,7 @@ import org.jkiss.dbeaver.model.runtime.DBRProcessDescriptor;
import
org.jkiss.dbeaver.model.runtime.DBRProgressMonitor
;
import
org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress
;
import
org.jkiss.dbeaver.model.runtime.DBRShellCommand
;
import
org.jkiss.dbeaver.registry.DataSourceDescriptor
;
import
org.jkiss.dbeaver.ui.UIUtils
;
import
org.jkiss.dbeaver.ui.dialogs.ConfirmationDialog
;
import
org.jkiss.dbeaver.ui.views.process.ShellProcessView
;
...
...
@@ -59,10 +61,7 @@ import java.net.URI;
import
java.net.URISyntaxException
;
import
java.net.URL
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.*
;
/**
* RuntimeUtils
...
...
@@ -624,4 +623,59 @@ public class RuntimeUtils {
}
}
public
static
boolean
runTask
(
final
DBRRunnableWithProgress
task
,
final
long
waitTime
)
{
final
MonitoringTask
monitoringTask
=
new
MonitoringTask
(
task
);
Job
monitorJob
=
new
AbstractJob
(
"Disconnect from data sources"
)
{
@Override
protected
IStatus
run
(
DBRProgressMonitor
monitor
)
{
try
{
monitoringTask
.
run
(
monitor
);
}
catch
(
InvocationTargetException
e
)
{
return
RuntimeUtils
.
makeExceptionStatus
(
e
.
getTargetException
());
}
catch
(
InterruptedException
e
)
{
// do nothing
}
return
Status
.
OK_STATUS
;
}
};
monitorJob
.
schedule
();
// Wait for job to finish
long
startTime
=
System
.
currentTimeMillis
();
if
(
waitTime
>
0
)
{
while
(!
monitoringTask
.
finished
&&
System
.
currentTimeMillis
()
-
startTime
<
waitTime
)
{
try
{
Thread
.
sleep
(
50
);
}
catch
(
InterruptedException
e
)
{
break
;
}
}
}
return
monitoringTask
.
finished
;
}
private
static
class
MonitoringTask
implements
DBRRunnableWithProgress
{
private
final
DBRRunnableWithProgress
task
;
volatile
boolean
finished
;
private
MonitoringTask
(
DBRRunnableWithProgress
task
)
{
this
.
task
=
task
;
}
public
boolean
isFinished
()
{
return
finished
;
}
@Override
public
void
run
(
DBRProgressMonitor
monitor
)
throws
InvocationTargetException
,
InterruptedException
{
try
{
task
.
run
(
monitor
);
}
finally
{
monitor
.
done
();
finished
=
true
;
}
}
}
}
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/runtime/jobs/DisconnectJob.java
浏览文件 @
601d7c52
...
...
@@ -28,13 +28,12 @@ import org.jkiss.dbeaver.registry.DataSourceDescriptor;
import
org.jkiss.dbeaver.runtime.RuntimeUtils
;
/**
* DisconnectJob
* Disconnect
Job
*/
public
class
DisconnectJob
extends
EventProcessorJob
{
public
DisconnectJob
(
DataSourceDescriptor
container
)
public
DisconnectJob
(
DataSourceDescriptor
container
)
{
super
(
NLS
.
bind
(
CoreMessages
.
runtime_jobs_disconnect_name
,
container
.
getName
()),
container
);
setUser
(
true
);
...
...
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/runtime/sql/SQLQueryJob.java
浏览文件 @
601d7c52
...
...
@@ -533,7 +533,7 @@ public class SQLQueryJob extends DataSourceJob
// Retrieve source entity
if
(
result
!=
null
)
{
DBCResultSetMetaData
rsMeta
=
resultSet
.
getMeta
();
String
sourceName
=
null
;
String
sourceName
=
null
;
//resultSet.getResultSetName();
for
(
DBCAttributeMetaData
attr
:
rsMeta
.
getAttributes
())
{
String
entityName
=
attr
.
getEntityName
();
if
(!
CommonUtils
.
isEmpty
(
entityName
))
{
...
...
@@ -610,10 +610,8 @@ public class SQLQueryJob extends DataSourceJob
private
boolean
keepStatementOpen
()
{
// Only in single query mode and if pref option set to true
DBSDataSourceContainer
container
=
getDataSourceContainer
();
return
queries
.
size
()
==
1
&&
container
!=
null
&&
container
.
getPreferenceStore
().
getBoolean
(
DBeaverPreferences
.
KEEP_STATEMENT_OPEN
);
getDataSourceContainer
().
getPreferenceStore
().
getBoolean
(
DBeaverPreferences
.
KEEP_STATEMENT_OPEN
);
}
private
void
closeStatement
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录