Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
0458f3d4
提交
0458f3d4
authored
6月 24, 2013
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Formatting, javadocs, more secure secret
上级
06b743c0
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
31 行增加
和
20 行删除
+31
-20
PgServer.java
h2/src/main/org/h2/server/pg/PgServer.java
+13
-6
PgServerThread.java
h2/src/main/org/h2/server/pg/PgServerThread.java
+18
-14
没有找到文件。
h2/src/main/org/h2/server/pg/PgServer.java
浏览文件 @
0458f3d4
...
@@ -79,8 +79,9 @@ public class PgServer implements Service {
...
@@ -79,8 +79,9 @@ public class PgServer implements Service {
private
boolean
stop
;
private
boolean
stop
;
private
boolean
trace
;
private
boolean
trace
;
private
ServerSocket
serverSocket
;
private
ServerSocket
serverSocket
;
private
final
Set
<
PgServerThread
>
running
=
Collections
.
synchronizedSet
(
new
HashSet
<
PgServerThread
>());
private
final
Set
<
PgServerThread
>
running
=
Collections
.
private
final
AtomicInteger
pid
=
new
AtomicInteger
(
0
);
synchronizedSet
(
new
HashSet
<
PgServerThread
>());
private
final
AtomicInteger
pid
=
new
AtomicInteger
();
private
String
baseDir
;
private
String
baseDir
;
private
boolean
allowOthers
;
private
boolean
allowOthers
;
private
boolean
isDaemon
;
private
boolean
isDaemon
;
...
@@ -260,11 +261,13 @@ public class PgServer implements Service {
...
@@ -260,11 +261,13 @@ public class PgServer implements Service {
}
}
/**
/**
* @return the thread with the given process-id
* Get the thread with the given process id.
*
* @return the thread
*/
*/
PgServerThread
getThread
(
int
processId
)
{
PgServerThread
getThread
(
int
processId
)
{
for
(
PgServerThread
c
:
New
.
arrayList
(
running
))
{
for
(
PgServerThread
c
:
New
.
arrayList
(
running
))
{
if
(
c
.
getProcessId
()
==
processId
)
{
if
(
c
.
getProcessId
()
==
processId
)
{
return
c
;
return
c
;
}
}
}
}
...
@@ -457,8 +460,12 @@ public class PgServer implements Service {
...
@@ -457,8 +460,12 @@ public class PgServer implements Service {
}
}
/**
/**
* A fake wrapper around pg_get_expr(expr_text, relation_oid), in PG it decompiles the "internal form of an
* A fake wrapper around pg_get_expr(expr_text, relation_oid), in PostgreSQL
* expression, assuming that any Vars in it refer to the relation indicated by the second parameter".
* it "decompiles the internal form of an expression, assuming that any vars
* in it refer to the relation indicated by the second parameter".
*
* @param exprText the expression text
* @param relationOid the relation object id
*/
*/
public
static
String
getPgExpr
(
String
exprText
,
int
relationOid
)
{
public
static
String
getPgExpr
(
String
exprText
,
int
relationOid
)
{
return
null
;
return
null
;
...
...
h2/src/main/org/h2/server/pg/PgServerThread.java
浏览文件 @
0458f3d4
...
@@ -29,7 +29,7 @@ import java.sql.Types;
...
@@ -29,7 +29,7 @@ import java.sql.Types;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.Properties
;
import
java.util.Properties
;
import
java.util.Random
;
import
org.h2.command.CommandInterface
;
import
org.h2.command.CommandInterface
;
import
org.h2.constant.SysProperties
;
import
org.h2.constant.SysProperties
;
import
org.h2.engine.ConnectionInfo
;
import
org.h2.engine.ConnectionInfo
;
...
@@ -40,6 +40,7 @@ import org.h2.message.DbException;
...
@@ -40,6 +40,7 @@ import org.h2.message.DbException;
import
org.h2.mvstore.DataUtils
;
import
org.h2.mvstore.DataUtils
;
import
org.h2.util.IOUtils
;
import
org.h2.util.IOUtils
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.MathUtils
;
import
org.h2.util.ScriptReader
;
import
org.h2.util.ScriptReader
;
import
org.h2.util.StringUtils
;
import
org.h2.util.StringUtils
;
import
org.h2.util.Utils
;
import
org.h2.util.Utils
;
...
@@ -74,7 +75,7 @@ public class PgServerThread implements Runnable {
...
@@ -74,7 +75,7 @@ public class PgServerThread implements Runnable {
PgServerThread
(
Socket
socket
,
PgServer
server
)
{
PgServerThread
(
Socket
socket
,
PgServer
server
)
{
this
.
server
=
server
;
this
.
server
=
server
;
this
.
socket
=
socket
;
this
.
socket
=
socket
;
this
.
secret
=
new
Random
().
nextInt
();
this
.
secret
=
(
int
)
MathUtils
.
secureRandomLong
();
}
}
@Override
@Override
...
@@ -151,10 +152,10 @@ public class PgServerThread implements Runnable {
...
@@ -151,10 +152,10 @@ public class PgServerThread implements Runnable {
int
pid
=
readInt
();
int
pid
=
readInt
();
int
key
=
readInt
();
int
key
=
readInt
();
PgServerThread
c
=
server
.
getThread
(
pid
);
PgServerThread
c
=
server
.
getThread
(
pid
);
if
(
c
!=
null
)
{
if
(
c
!=
null
)
{
c
.
cancelRequest
(
key
);
c
.
cancelRequest
(
key
);
}
else
{
}
else
{
sendErrorResponse
(
"unknown process: "
+
pid
);
sendErrorResponse
(
"unknown process: "
+
pid
);
}
}
close
();
close
();
}
else
if
(
version
==
80877103
)
{
}
else
if
(
version
==
80877103
)
{
...
@@ -354,7 +355,7 @@ public class PgServerThread implements Runnable {
...
@@ -354,7 +355,7 @@ public class PgServerThread implements Runnable {
sendCommandComplete
(
prep
,
prep
.
getUpdateCount
());
sendCommandComplete
(
prep
,
prep
.
getUpdateCount
());
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
if
(
prep
.
i
sCancelled
())
{
if
(
prep
.
wa
sCancelled
())
{
sendCancelQueryResponse
();
sendCancelQueryResponse
();
}
else
{
}
else
{
sendErrorResponse
(
e
);
sendErrorResponse
(
e
);
...
@@ -401,7 +402,7 @@ public class PgServerThread implements Runnable {
...
@@ -401,7 +402,7 @@ public class PgServerThread implements Runnable {
sendCommandComplete
(
stat
,
stat
.
getUpdateCount
());
sendCommandComplete
(
stat
,
stat
.
getUpdateCount
());
}
}
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
if
(
stat
!=
null
&&
stat
.
i
sCancelled
())
{
if
(
stat
!=
null
&&
stat
.
wa
sCancelled
())
{
sendCancelQueryResponse
();
sendCancelQueryResponse
();
}
else
{
}
else
{
sendErrorResponse
(
e
);
sendErrorResponse
(
e
);
...
@@ -491,7 +492,7 @@ public class PgServerThread implements Runnable {
...
@@ -491,7 +492,7 @@ public class PgServerThread implements Runnable {
break
;
break
;
default
:
default
:
String
s
=
rs
.
getString
(
column
);
String
s
=
rs
.
getString
(
column
);
if
(
s
==
null
)
{
if
(
s
==
null
)
{
writeInt
(-
1
);
writeInt
(-
1
);
}
else
{
}
else
{
byte
[]
data
=
s
.
getBytes
(
getEncoding
());
byte
[]
data
=
s
.
getBytes
(
getEncoding
());
...
@@ -524,7 +525,7 @@ public class PgServerThread implements Runnable {
...
@@ -524,7 +525,7 @@ public class PgServerThread implements Runnable {
break
;
break
;
case
PgServer
.
PG_TYPE_BYTEA
:
case
PgServer
.
PG_TYPE_BYTEA
:
byte
[]
data
=
rs
.
getBytes
(
column
);
byte
[]
data
=
rs
.
getBytes
(
column
);
if
(
data
==
null
)
{
if
(
data
==
null
)
{
writeInt
(-
1
);
writeInt
(-
1
);
}
else
{
}
else
{
writeInt
(
data
.
length
);
writeInt
(
data
.
length
);
...
@@ -548,7 +549,7 @@ public class PgServerThread implements Runnable {
...
@@ -548,7 +549,7 @@ public class PgServerThread implements Runnable {
boolean
text
=
(
i
>=
formatCodes
.
length
)
||
(
formatCodes
[
i
]
==
0
);
boolean
text
=
(
i
>=
formatCodes
.
length
)
||
(
formatCodes
[
i
]
==
0
);
int
col
=
i
+
1
;
int
col
=
i
+
1
;
int
paramLen
=
readInt
();
int
paramLen
=
readInt
();
if
(
paramLen
==
-
1
)
{
if
(
paramLen
==
-
1
)
{
prep
.
setNull
(
i
,
Types
.
NULL
);
prep
.
setNull
(
i
,
Types
.
NULL
);
}
else
if
(
text
)
{
}
else
if
(
text
)
{
// plain text
// plain text
...
@@ -679,7 +680,7 @@ public class PgServerThread implements Runnable {
...
@@ -679,7 +680,7 @@ public class PgServerThread implements Runnable {
// type = PgServer.PG_TYPE_INT2VECTOR;
// type = PgServer.PG_TYPE_INT2VECTOR;
// }
// }
precision
[
i
]
=
meta
.
getColumnDisplaySize
(
i
+
1
);
precision
[
i
]
=
meta
.
getColumnDisplaySize
(
i
+
1
);
if
(
type
!=
Types
.
NULL
)
{
if
(
type
!=
Types
.
NULL
)
{
server
.
checkType
(
pgType
);
server
.
checkType
(
pgType
);
}
}
types
[
i
]
=
pgType
;
types
[
i
]
=
pgType
;
...
@@ -705,8 +706,12 @@ public class PgServerThread implements Runnable {
...
@@ -705,8 +706,12 @@ public class PgServerThread implements Runnable {
}
}
}
}
/** @return should the given type be formatted as binary or plain text? */
/**
private
boolean
formatAsText
(
int
pgType
)
{
* Check whether the given type should be formatted as text.
*
* @return true for binary
*/
private
static
boolean
formatAsText
(
int
pgType
)
{
switch
(
pgType
)
{
switch
(
pgType
)
{
// TODO: add more types to send as binary once compatibility is confirmed
// TODO: add more types to send as binary once compatibility is confirmed
case
PgServer
.
PG_TYPE_BYTEA
:
case
PgServer
.
PG_TYPE_BYTEA
:
...
@@ -956,8 +961,7 @@ public class PgServerThread implements Runnable {
...
@@ -956,8 +961,7 @@ public class PgServerThread implements Runnable {
* @param secret the private key of the command
* @param secret the private key of the command
*/
*/
private
synchronized
void
cancelRequest
(
int
secret
)
throws
IOException
{
private
synchronized
void
cancelRequest
(
int
secret
)
throws
IOException
{
if
(
activeRequest
!=
null
)
if
(
activeRequest
!=
null
)
{
{
if
(
secret
!=
this
.
secret
)
{
if
(
secret
!=
this
.
secret
)
{
sendErrorResponse
(
"invalid cancel secret"
);
sendErrorResponse
(
"invalid cancel secret"
);
return
;
return
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论