Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
1244fb71
提交
1244fb71
authored
5月 21, 2008
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
javadocs
上级
2c4da91e
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
245 行增加
和
38 行删除
+245
-38
Message.java
h2/src/main/org/h2/message/Message.java
+109
-21
Trace.java
h2/src/main/org/h2/message/Trace.java
+132
-14
TraceObject.java
h2/src/main/org/h2/message/TraceObject.java
+4
-3
没有找到文件。
h2/src/main/org/h2/message/Message.java
浏览文件 @
1244fb71
...
...
@@ -63,18 +63,17 @@ public class Message {
}
/**
* Gets the SQL Exception object for a specific SQLState. Supported
* SQL states are:
* Gets the SQL exception object for a specific error code.
*
* @param
sqlState the SQL stat
e
* @param
errorCode the error cod
e
* @param p1 the first parameter of the message
* @return the SQLException object
*/
public
static
JdbcSQLException
getSQLException
(
int
sqlStat
e
,
String
p1
)
{
return
getSQLException
(
sqlStat
e
,
new
String
[]
{
p1
});
public
static
JdbcSQLException
getSQLException
(
int
errorCod
e
,
String
p1
)
{
return
getSQLException
(
errorCod
e
,
new
String
[]
{
p1
});
}
p
ublic
static
String
translate
(
String
key
,
String
[]
param
)
{
p
rivate
static
String
translate
(
String
key
,
String
[]
param
)
{
String
message
=
MESSAGES
.
getProperty
(
key
);
if
(
message
==
null
)
{
message
=
"(Message "
+
key
+
" not found)"
;
...
...
@@ -86,62 +85,121 @@ public class Message {
return
message
;
}
public
static
JdbcSQLException
getSQLException
(
int
errorCode
,
String
[]
param
,
Throwable
cause
)
{
/**
* Gets the SQL exception object for a specific error code.
*
* @param errorCode the error code
* @param params the list of parameters of the message
* @param cause the cause of the exception
* @return the SQLException object
*/
public
static
JdbcSQLException
getSQLException
(
int
errorCode
,
String
[]
params
,
Throwable
cause
)
{
String
sqlstate
=
ErrorCode
.
getState
(
errorCode
);
String
message
=
translate
(
sqlstate
,
param
);
String
message
=
translate
(
sqlstate
,
param
s
);
return
new
JdbcSQLException
(
message
,
null
,
sqlstate
,
errorCode
,
cause
,
null
);
}
public
static
JdbcSQLException
getSQLException
(
int
errorCode
,
String
[]
param
)
{
return
getSQLException
(
errorCode
,
param
,
null
);
/**
* Gets the SQL exception object for a specific error code.
*
* @param errorCode the error code
* @param params the list of parameters of the message
* @return the SQLException object
*/
public
static
JdbcSQLException
getSQLException
(
int
errorCode
,
String
[]
params
)
{
return
getSQLException
(
errorCode
,
params
,
null
);
}
/**
* Constructs a syntax error SQL exception.
*
* @param sql the SQL statement
* @param index the position of the error in the SQL statement
* @return the SQLException object
*/
public
static
SQLException
getSyntaxError
(
String
sql
,
int
index
)
{
sql
=
StringUtils
.
addAsterisk
(
sql
,
index
);
return
getSQLException
(
ErrorCode
.
SYNTAX_ERROR_1
,
sql
);
}
/**
* Constructs a syntax error SQL exception.
*
* @param sql the SQL statement
* @param index the position of the error in the SQL statement
* @param expected the expected keyword at the given position
* @return the SQLException object
*/
public
static
SQLException
getSyntaxError
(
String
sql
,
int
index
,
String
expected
)
{
sql
=
StringUtils
.
addAsterisk
(
sql
,
index
);
return
getSQLException
(
ErrorCode
.
SYNTAX_ERROR_2
,
new
String
[]{
sql
,
expected
});
}
/**
* Gets the SQL
Exception object for a specific SQLStat
e.
* Gets the SQL
exception object for a specific error cod
e.
*
* @param sqlstate -
* the SQL State
* @param errorCode the error code
* @return the SQLException object
*/
public
static
JdbcSQLException
getSQLException
(
int
sqlstat
e
)
{
return
getSQLException
(
sqlstat
e
,
(
String
)
null
);
public
static
JdbcSQLException
getSQLException
(
int
errorCod
e
)
{
return
getSQLException
(
errorCod
e
,
(
String
)
null
);
}
/**
* Gets a SQL exception meaning this feature is not supported.
*
* @return the SQLException object
*/
public
static
JdbcSQLException
getUnsupportedException
()
{
return
getSQLException
(
ErrorCode
.
FEATURE_NOT_SUPPORTED
);
}
/**
* Gets a SQL exception meaning this value is invalid.
*
* @param value the value passed
* @param param the name of the parameter
* @return the SQLException object
*/
public
static
JdbcSQLException
getInvalidValueException
(
String
value
,
String
param
)
{
return
getSQLException
(
ErrorCode
.
INVALID_VALUE_2
,
new
String
[]{
value
,
param
});
}
/**
* Gets an internal error.
*
* @param s the message
* @return the error object
*/
public
static
Error
getInternalError
(
String
s
)
{
Error
e
=
new
Error
(
s
);
TraceSystem
.
traceThrowable
(
e
);
return
e
;
}
/**
* Gets an internal error.
*
* @param s the message
* @param e the root cause
* @return the error object
*/
public
static
Error
getInternalError
(
String
s
,
Exception
e
)
{
Error
e2
=
new
Error
(
s
);
//## Java 1.4 begin ##
Error
e2
=
new
Error
(
s
,
e
);
e2
.
initCause
(
e
);
//## Java 1.4 end ##
/*## Java 1.3 only begin ##
Error e2 = new Error(s);
## Java 1.3 only end ##*/
TraceSystem
.
traceThrowable
(
e2
);
return
e2
;
}
/**
* Attach a SQL statement to the exception if this is not already done.
*
* @param e the original SQL exception
* @param sql the SQL statement
* @return the error object
*/
public
static
SQLException
addSQL
(
SQLException
e
,
String
sql
)
{
if
(
e
instanceof
JdbcSQLException
)
{
JdbcSQLException
j
=
(
JdbcSQLException
)
e
;
...
...
@@ -156,6 +214,12 @@ public class Message {
}
}
/**
* Convert an exception to a SQL exception using the default mapping.
*
* @param e the root cause
* @return the SQL exception object
*/
public
static
SQLException
convert
(
Throwable
e
)
{
if
(
e
instanceof
InternalException
)
{
e
=
((
InternalException
)
e
).
getOriginalCause
();
...
...
@@ -175,6 +239,13 @@ public class Message {
return
getSQLException
(
ErrorCode
.
GENERAL_ERROR_1
,
new
String
[]{
e
.
toString
()},
e
);
}
/**
* Convert an IO exception to a SQL exception.
*
* @param e the root cause
* @param message the message
* @return the SQL exception object
*/
public
static
SQLException
convertIOException
(
IOException
e
,
String
message
)
{
if
(
message
==
null
)
{
return
getSQLException
(
ErrorCode
.
IO_EXCEPTION_1
,
new
String
[]{
e
.
toString
()},
e
);
...
...
@@ -183,14 +254,31 @@ public class Message {
}
}
/**
* Gets an internal error.
*
* @return the error object
*/
public
static
Error
getInternalError
()
{
return
getInternalError
(
"
u
nexpected code path"
);
return
getInternalError
(
"
U
nexpected code path"
);
}
/**
* Convert an exception to an internal runtime exception.
*
* @param e the root cause
* @return the error object
*/
public
static
InternalException
convertToInternal
(
Exception
e
)
{
return
new
InternalException
(
e
);
}
/**
* Convert an exception to an IO exception.
*
* @param e the root cause
* @return the IO exception
*/
public
static
IOException
convertToIOException
(
Throwable
e
)
{
if
(
e
instanceof
JdbcSQLException
)
{
JdbcSQLException
e2
=
(
JdbcSQLException
)
e
;
...
...
h2/src/main/org/h2/message/Trace.java
浏览文件 @
1244fb71
...
...
@@ -14,26 +14,89 @@ import org.h2.util.StringUtils;
*/
public
class
Trace
{
private
TraceWriter
traceWriter
;
private
String
module
;
private
String
lineSeparator
;
public
static
final
String
LOCK
=
"lock"
;
public
static
final
String
SETTING
=
"setting"
;
/**
* The trace module name for commands.
*/
public
static
final
String
COMMAND
=
"command"
;
public
static
final
String
INDEX
=
"index"
;
public
static
final
String
SEQUENCE
=
"sequence"
;
/**
* The trace module name for constraints.
*/
public
static
final
String
CONSTRAINT
=
"constraint"
;
public
static
final
String
USER
=
"user"
;
public
static
final
String
TRIGGER
=
"trigger"
;
/**
* The trace module name for databases.
*/
public
static
final
String
DATABASE
=
"database"
;
/**
* The trace module name for functions.
*/
public
static
final
String
FUNCTION
=
"function"
;
public
static
final
String
JDBC
=
"jdbc"
;
/**
* The trace module name for file locks.
*/
public
static
final
String
FILE_LOCK
=
"fileLock"
;
public
static
final
String
TABLE
=
"table"
;
/**
* The trace module name for indexes.
*/
public
static
final
String
INDEX
=
"index"
;
/**
* The trace module name for the JDBC API.
*/
public
static
final
String
JDBC
=
"jdbc"
;
/**
* The trace module name for locks.
*/
public
static
final
String
LOCK
=
"lock"
;
/**
* The trace module name for the transaction log.
*/
public
static
final
String
LOG
=
"log"
;
/**
* The trace module name for schemas.
*/
public
static
final
String
SCHEMA
=
"schema"
;
public
static
final
String
DATABASE
=
"database"
;
/**
* The trace module name for sessions.
*/
public
static
final
String
SESSION
=
"session"
;
/**
* The trace module name for sequences.
*/
public
static
final
String
SEQUENCE
=
"sequence"
;
/**
* The trace module name for settings.
*/
public
static
final
String
SETTING
=
"setting"
;
/**
* The trace module name for tables.
*/
public
static
final
String
TABLE
=
"table"
;
/**
* The trace module name for triggers.
*/
public
static
final
String
TRIGGER
=
"trigger"
;
/**
* The trace module name for users.
*/
public
static
final
String
USER
=
"user"
;
private
TraceWriter
traceWriter
;
private
String
module
;
private
String
lineSeparator
;
Trace
(
TraceWriter
traceWriter
,
String
module
)
{
this
.
traceWriter
=
traceWriter
;
...
...
@@ -41,36 +104,80 @@ public class Trace {
this
.
lineSeparator
=
SysProperties
.
LINE_SEPARATOR
;
}
/**
* Check if the trace level is equal or higher than INFO.
*
* @return true if it is
*/
public
boolean
isInfoEnabled
()
{
return
traceWriter
.
isEnabled
(
TraceSystem
.
INFO
);
}
/**
* Check if the trace level is equal or higher than DEBUG.
*
* @return true if it is
*/
public
boolean
isDebugEnabled
()
{
return
traceWriter
.
isEnabled
(
TraceSystem
.
DEBUG
);
}
/**
* Write a message with trace level ERROR to the trace system.
*
* @param s the message
*/
public
void
error
(
String
s
)
{
traceWriter
.
write
(
TraceSystem
.
ERROR
,
module
,
s
,
null
);
}
/**
* Write a message with trace level ERROR to the trace system.
*
* @param s the message
* @param t the exception
*/
public
void
error
(
String
s
,
Throwable
t
)
{
traceWriter
.
write
(
TraceSystem
.
ERROR
,
module
,
s
,
t
);
}
/**
* Write a message with trace level INFO to the trace system.
*
* @param s the message
*/
public
void
info
(
String
s
)
{
traceWriter
.
write
(
TraceSystem
.
INFO
,
module
,
s
,
null
);
}
/**
* Write Java source code with trace level DEBUG to the trace system.
*
* @param java the source cod
*/
public
void
debugCode
(
String
java
)
{
traceWriter
.
write
(
TraceSystem
.
DEBUG
,
module
,
lineSeparator
+
"/**/"
+
java
,
null
);
}
/**
* Write Java source code with trace level INFO to the trace system.
*
* @param java the source cod
*/
public
void
infoCode
(
String
java
)
{
traceWriter
.
write
(
TraceSystem
.
INFO
,
module
,
lineSeparator
+
"/**/"
+
java
,
null
);
}
/**
* Write a SQL statement with trace level INFO to the trace system.
*
* @param sql the SQL statement
* @param params the parameters used, in the for {1:...}
* @param count the update count
* @param time the time it took to run the statement in ms
*/
public
void
infoSQL
(
String
sql
,
String
params
,
int
count
,
long
time
)
{
StringBuffer
buff
=
new
StringBuffer
(
sql
.
length
()
+
20
);
StringBuffer
buff
=
new
StringBuffer
(
sql
.
length
()
+
params
.
length
()
+
20
);
buff
.
append
(
lineSeparator
);
buff
.
append
(
"/*SQL"
);
boolean
space
=
false
;
...
...
@@ -106,10 +213,21 @@ public class Trace {
traceWriter
.
write
(
TraceSystem
.
INFO
,
module
,
sql
,
null
);
}
/**
* Write a message with trace level DEBUG to the trace system.
*
* @param s the message
*/
public
void
debug
(
String
s
)
{
traceWriter
.
write
(
TraceSystem
.
DEBUG
,
module
,
s
,
null
);
}
/**
* Write a message with trace level DEBUG to the trace system.
*
* @param s the message
* @param t the exception
*/
public
void
debug
(
String
s
,
Throwable
t
)
{
traceWriter
.
write
(
TraceSystem
.
DEBUG
,
module
,
s
,
t
);
}
...
...
h2/src/main/org/h2/message/TraceObject.java
浏览文件 @
1244fb71
...
...
@@ -24,11 +24,11 @@ import org.h2.util.StringUtils;
* The base class for objects that can print trace information about themselves.
*/
public
class
TraceObject
{
p
ublic
static
final
int
CALLABLE_STATEMENT
=
0
,
CONNECTION
=
1
,
DATABASE_META_DATA
=
2
,
p
rotected
static
final
int
CALLABLE_STATEMENT
=
0
,
CONNECTION
=
1
,
DATABASE_META_DATA
=
2
,
PREPARED_STATEMENT
=
3
,
RESULT_SET
=
4
,
RESULT_SET_META_DATA
=
5
,
SAVEPOINT
=
6
,
SQL_EXCEPTION
=
7
,
STATEMENT
=
8
,
BLOB
=
9
,
CLOB
=
10
,
PARAMETER_META_DATA
=
11
;
p
ublic
static
final
int
DATA_SOURCE
=
12
,
XA_DATA_SOURCE
=
13
,
XID
=
14
,
ARRAY
=
15
;
p
rotected
static
final
int
DATA_SOURCE
=
12
,
XA_DATA_SOURCE
=
13
,
XID
=
14
,
ARRAY
=
15
;
private
static
final
int
LAST
=
ARRAY
+
1
;
private
Trace
trace
;
...
...
@@ -37,7 +37,8 @@ public class TraceObject {
"call"
,
"conn"
,
"dbMeta"
,
"prep"
,
"rs"
,
"rsMeta"
,
"sp"
,
"ex"
,
"stat"
,
"blob"
,
"clob"
,
"pMeta"
,
"ds"
,
"xads"
,
"xid"
,
"ar"
};
private
int
type
,
id
;
private
int
type
;
private
int
id
;
protected
void
setTrace
(
Trace
trace
,
int
type
,
int
id
)
{
this
.
trace
=
trace
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论