Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
77ae94b0
D
dbeaver
项目概览
suliangchun
/
dbeaver
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
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,发现更多精彩内容 >>
提交
77ae94b0
编写于
1月 17, 2018
作者:
A
Alexander Fedorov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#2556 extract worker logic to the base session
上级
c5cf9ba5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
146 addition
and
139 deletion
+146
-139
plugins/org.jkiss.dbeaver.debug.core/src/org/jkiss/dbeaver/debug/DBGBaseSession.java
...ebug.core/src/org/jkiss/dbeaver/debug/DBGBaseSession.java
+136
-0
plugins/org.jkiss.dbeaver.ext.postgresql.debug.core/src/org/jkiss/dbeaver/ext/postgresql/debug/internal/impl/PostgreDebugSession.java
...t/postgresql/debug/internal/impl/PostgreDebugSession.java
+10
-139
未找到文件。
plugins/org.jkiss.dbeaver.debug.core/src/org/jkiss/dbeaver/debug/DBGBaseSession.java
浏览文件 @
77ae94b0
package
org.jkiss.dbeaver.debug
;
import
java.sql.Connection
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.FutureTask
;
import
java.util.concurrent.locks.ReentrantReadWriteLock
;
import
org.jkiss.dbeaver.Log
;
import
org.jkiss.dbeaver.model.impl.jdbc.JDBCExecutionContext
;
import
org.jkiss.dbeaver.model.runtime.VoidProgressMonitor
;
public
abstract
class
DBGBaseSession
implements
DBGSession
{
private
static
final
Log
log
=
Log
.
getLog
(
DBGBaseSession
.
class
);
protected
final
ReentrantReadWriteLock
lock
=
new
ReentrantReadWriteLock
(
true
);
private
final
DBGBaseController
controller
;
protected
FutureTask
<
DBGEvent
>
task
;
private
Thread
workerThread
=
null
;
private
JDBCExecutionContext
connection
=
null
;
public
DBGBaseSession
(
DBGBaseController
controller
)
{
this
.
controller
=
controller
;
}
/**
* Return connection used in debug session
*
* @return java.sql.Connection
* @throws DBGException
*/
//FIXME: rework to DBC API
protected
Connection
getConnection
()
throws
DBGException
{
try
{
return
((
JDBCExecutionContext
)
connection
).
getConnection
(
new
VoidProgressMonitor
());
}
catch
(
SQLException
e
)
{
throw
new
DBGException
(
"SQL error"
,
e
);
}
}
//FIXME: should be known during construction
protected
void
setConnection
(
JDBCExecutionContext
connection
)
{
this
.
connection
=
connection
;
}
public
DBGBaseController
getController
()
{
return
controller
;
}
/**
* Return true if debug session up and running on server
*
* @return boolean
*/
public
boolean
isAttached
()
{
return
connection
!=
null
;
}
/**
* Return true if session up and running debug thread
*
* @return boolean
*/
public
boolean
isWaiting
()
{
return
(
task
==
null
?
false
:
!
task
.
isDone
())
&&
(
workerThread
==
null
?
false
:
workerThread
.
isAlive
());
}
/**
* Return true if session waiting target connection (on breakpoint, after step or continue) in debug thread
*
* @return boolean
*/
public
boolean
isDone
(){
if
(
task
==
null
)
return
true
;
if
(
task
.
isDone
())
{
try
{
DBGEvent
dbgEvent
=
task
.
get
();
getController
().
fireEvent
(
dbgEvent
);
}
catch
(
InterruptedException
e
)
{
log
.
error
(
"DEBUG INTERRUPT ERROR "
,
e
);
return
false
;
}
catch
(
ExecutionException
e
)
{
log
.
error
(
"DEBUG WARNING "
,
e
);
return
false
;
}
return
true
;
}
return
false
;
}
/**
* Start thread for SQL command
*
* @param commandSQL
* @param name
* @throws DBGException
*/
protected
void
runAsync
(
String
commandSQL
,
String
name
,
DBGEvent
event
)
throws
DBGException
{
Connection
connection
=
getConnection
();
try
(
Statement
stmt
=
connection
.
createStatement
())
{
connection
.
setAutoCommit
(
false
);
DBGWorker
worker
=
new
DBGWorker
(
connection
,
commandSQL
,
event
);
task
=
new
FutureTask
<
DBGEvent
>(
worker
);
workerThread
=
new
Thread
(
task
);
workerThread
.
setName
(
name
);
workerThread
.
start
();
}
catch
(
SQLException
e
)
{
throw
new
DBGException
(
"SQL error"
,
e
);
}
}
public
void
close
()
{
lock
.
writeLock
().
lock
();
try
{
if
(!
isDone
())
{
task
.
cancel
(
true
);
}
connection
.
close
();
}
finally
{
lock
.
writeLock
().
unlock
();
}
}
}
plugins/org.jkiss.dbeaver.ext.postgresql.debug.core/src/org/jkiss/dbeaver/ext/postgresql/debug/internal/impl/PostgreDebugSession.java
浏览文件 @
77ae94b0
...
...
@@ -18,18 +18,13 @@
package
org.jkiss.dbeaver.ext.postgresql.debug.internal.impl
;
import
java.sql.Connection
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.FutureTask
;
import
java.util.concurrent.locks.ReentrantReadWriteLock
;
import
org.jkiss.dbeaver.Log
;
import
org.jkiss.dbeaver.debug.DBGBaseController
;
import
org.jkiss.dbeaver.debug.DBGBaseSession
;
import
org.jkiss.dbeaver.debug.DBGBreakpointDescriptor
;
...
...
@@ -37,14 +32,10 @@ import org.jkiss.dbeaver.debug.DBGBreakpointProperties;
import
org.jkiss.dbeaver.debug.DBGEvent
;
import
org.jkiss.dbeaver.debug.DBGException
;
import
org.jkiss.dbeaver.debug.DBGObjectDescriptor
;
import
org.jkiss.dbeaver.debug.DBGSession
;
import
org.jkiss.dbeaver.debug.DBGSessionInfo
;
import
org.jkiss.dbeaver.debug.DBGStackFrame
;
import
org.jkiss.dbeaver.debug.DBGVariable
;
import
org.jkiss.dbeaver.debug.DBGWorker
;
import
org.jkiss.dbeaver.model.exec.DBCExecutionContext
;
import
org.jkiss.dbeaver.model.impl.jdbc.JDBCExecutionContext
;
import
org.jkiss.dbeaver.model.runtime.VoidProgressMonitor
;
/**
* Typical scenario for debug session <br/>
...
...
@@ -63,13 +54,9 @@ import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
*/
public
class
PostgreDebugSession
extends
DBGBaseSession
{
private
static
final
Log
log
=
Log
.
getLog
(
PostgreDebugSession
.
class
);
private
final
DBGSessionInfo
sessionInfo
;
private
final
Object
targetId
;
private
JDBCExecutionContext
connection
=
null
;
private
int
sessionId
=
-
1
;
private
static
final
String
SQL_ATTACH
=
"select pldbg_wait_for_target(?sessionid)"
;
...
...
@@ -96,14 +83,8 @@ public class PostgreDebugSession extends DBGBaseSession {
private
static
final
String
SQL_DROP_BREAKPOINT
=
"select pldbg_drop_breakpoint(?sessionid, ?obj, ?line)"
;
private
static
final
String
SQL_ATTACH_BREAKPOINT
=
"select pldbg_wait_for_breakpoint(?sessionid)"
;
private
final
ReentrantReadWriteLock
lock
=
new
ReentrantReadWriteLock
(
true
);
private
List
<
PostgreDebugBreakpointDescriptor
>
breakpoints
=
new
ArrayList
<
PostgreDebugBreakpointDescriptor
>(
1
);
private
FutureTask
<
DBGEvent
>
task
;
private
Thread
workerThread
=
null
;
/**
* Create session with two description
* after creation session need to be attached to postgres procedure by attach method
...
...
@@ -133,14 +114,14 @@ public class PostgreDebugSession extends DBGBaseSession {
try
{
this
.
connection
=
connection
;
setConnection
(
connection
)
;
try
(
Statement
stmt
=
getConnection
(
connection
).
createStatement
();
try
(
Statement
stmt
=
getConnection
().
createStatement
();
ResultSet
rs
=
stmt
.
executeQuery
(
SQL_LISTEN
))
{
if
(
rs
.
next
())
{
sessionId
=
rs
.
getInt
(
"sessionid"
);
getConnection
(
connection
).
setClientInfo
(
"ApplicationName"
,
"Debug Mode : "
+
String
.
valueOf
(
sessionId
));
getConnection
().
setClientInfo
(
"ApplicationName"
,
"Debug Mode : "
+
String
.
valueOf
(
sessionId
));
}
else
{
throw
new
DBGException
(
"Unable to create debug instance"
);
}
...
...
@@ -173,16 +154,6 @@ public class PostgreDebugSession extends DBGBaseSession {
}
/**
* @param connectionTarget - DBCExecutionContext of debug client (will be used in debug process)
* @return Connection - java.sql.Connection
* @throws SQLException
*/
private
static
Connection
getConnection
(
DBCExecutionContext
connectionTarget
)
throws
SQLException
{
return
((
JDBCExecutionContext
)
connectionTarget
).
getConnection
(
new
VoidProgressMonitor
());
}
@Override
public
DBGSessionInfo
getSessionInfo
()
{
return
sessionInfo
;
...
...
@@ -296,10 +267,10 @@ public class PostgreDebugSession extends DBGBaseSession {
acquireReadLock
();
try
(
Statement
stmt
=
getConnection
(
connection
).
createStatement
())
{
try
(
Statement
stmt
=
getConnection
().
createStatement
())
{
stmt
.
execute
(
SQL_ABORT
.
replaceAll
(
"\\?sessionid"
,
String
.
valueOf
(
sessionId
)));
//FIXME: move to finally?
task
=
null
;
}
catch
(
SQLException
e
)
{
...
...
@@ -310,24 +281,6 @@ public class PostgreDebugSession extends DBGBaseSession {
}
public
void
close
()
{
lock
.
writeLock
().
lock
();
try
{
if
(!
isDone
())
{
task
.
cancel
(
true
);
}
connection
.
close
();
}
finally
{
lock
.
writeLock
().
unlock
();
}
}
@Override
public
List
<
DBGVariable
<?>>
getVariables
()
throws
DBGException
{
...
...
@@ -336,7 +289,7 @@ public class PostgreDebugSession extends DBGBaseSession {
List
<
DBGVariable
<?>>
vars
=
new
ArrayList
<>();
String
sql
=
SQL_GET_VARS
.
replaceAll
(
"\\?sessionid"
,
String
.
valueOf
(
sessionId
));
try
(
Statement
stmt
=
getConnection
(
connection
).
createStatement
();
ResultSet
rs
=
stmt
.
executeQuery
(
sql
))
{
try
(
Statement
stmt
=
getConnection
().
createStatement
();
ResultSet
rs
=
stmt
.
executeQuery
(
sql
))
{
while
(
rs
.
next
())
{
String
name
=
rs
.
getString
(
"name"
);
...
...
@@ -367,7 +320,7 @@ public class PostgreDebugSession extends DBGBaseSession {
acquireReadLock
();
try
(
PreparedStatement
stmt
=
getConnection
(
connection
).
prepareStatement
(
SQL_SET_VAR
))
{
try
(
PreparedStatement
stmt
=
getConnection
().
prepareStatement
(
SQL_SET_VAR
))
{
if
(
variable
instanceof
PostgreDebugVariable
){
...
...
@@ -408,7 +361,7 @@ public class PostgreDebugSession extends DBGBaseSession {
List
<
DBGStackFrame
>
stack
=
new
ArrayList
<
DBGStackFrame
>(
1
);
String
sql
=
SQL_GET_STACK
.
replaceAll
(
"\\?sessionid"
,
String
.
valueOf
(
getSessionId
()));
try
(
Statement
stmt
=
getConnection
(
connection
).
createStatement
();
ResultSet
rs
=
stmt
.
executeQuery
(
sql
))
{
try
(
Statement
stmt
=
getConnection
().
createStatement
();
ResultSet
rs
=
stmt
.
executeQuery
(
sql
))
{
while
(
rs
.
next
())
{
int
level
=
rs
.
getInt
(
"level"
);
String
targetname
=
rs
.
getString
(
"targetname"
);
...
...
@@ -427,23 +380,9 @@ public class PostgreDebugSession extends DBGBaseSession {
return
stack
;
}
/**
* Return connection used in debug session
*
* @return java.sql.Connection
* @throws DBGException
*/
private
Connection
getConnection
()
throws
DBGException
{
try
{
return
getConnection
(
connection
);
}
catch
(
SQLException
e
)
{
throw
new
DBGException
(
"SQL error"
,
e
);
}
}
@Override
public
String
toString
()
{
return
"PostgreDebugSession "
+
(
isWaiting
()
?
"WAITING"
:
"READY"
)
+
" [
connection="
+
connection
+
",
sessionId="
+
sessionId
+
", breakpoints="
+
breakpoints
+
"targetId=("
return
"PostgreDebugSession "
+
(
isWaiting
()
?
"WAITING"
:
"READY"
)
+
" [sessionId="
+
sessionId
+
", breakpoints="
+
breakpoints
+
"targetId=("
+
targetId
+
") Session=("
+
sessionInfo
.
toString
()
+
") "
+
"]"
;
}
...
...
@@ -452,81 +391,13 @@ public class PostgreDebugSession extends DBGBaseSession {
return
sessionId
;
}
/**
* Return true if session up and running debug thread
*
* @return boolean
*/
public
boolean
isWaiting
()
{
return
(
task
==
null
?
false
:
!
task
.
isDone
())
&&
(
workerThread
==
null
?
false
:
workerThread
.
isAlive
());
}
/**
* Return true if session waiting target connection (on breakpoint, after step or continue) in debug thread
*
* @return boolean
*/
public
boolean
isDone
(){
if
(
task
==
null
)
return
true
;
if
(
task
.
isDone
())
{
try
{
DBGEvent
dbgEvent
=
task
.
get
();
getController
().
fireEvent
(
dbgEvent
);
}
catch
(
InterruptedException
e
)
{
log
.
error
(
"DEBUG INTERRUPT ERROR "
,
e
);
return
false
;
}
catch
(
ExecutionException
e
)
{
log
.
error
(
"DEBUG WARNING "
,
e
);
return
false
;
}
return
true
;
}
return
false
;
}
/**
* Return true if debug session up and running on server
*
* @return boolean
*/
public
boolean
isAttached
()
{
return
(
connection
!=
null
&&
sessionId
>
0
);
}
/**
* Start thread for SQL command
*
* @param commandSQL
* @param name
* @throws DBGException
*/
private
void
runAsync
(
String
commandSQL
,
String
name
,
DBGEvent
event
)
throws
DBGException
{
Connection
connection
=
getConnection
();
try
(
Statement
stmt
=
connection
.
createStatement
())
{
connection
.
setAutoCommit
(
false
);
DBGWorker
worker
=
new
DBGWorker
(
connection
,
commandSQL
,
event
);
task
=
new
FutureTask
<
DBGEvent
>(
worker
);
workerThread
=
new
Thread
(
task
);
workerThread
.
setName
(
name
);
workerThread
.
start
();
}
catch
(
SQLException
e
)
{
throw
new
DBGException
(
"SQL error"
,
e
);
}
return
super
.
isAttached
()
&&
(
sessionId
>
0
);
}
/**
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录