Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
2a83a1ba
提交
2a83a1ba
authored
6月 05, 2008
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
the lucene index was always recreated and never closed
上级
4ba52d30
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
212 行增加
和
101 行删除
+212
-101
CloseListener.java
h2/src/main/org/h2/api/CloseListener.java
+26
-0
Trigger.java
h2/src/main/org/h2/api/Trigger.java
+1
-1
Database.java
h2/src/main/org/h2/engine/Database.java
+6
-0
FunctionAlias.java
h2/src/main/org/h2/engine/FunctionAlias.java
+149
-96
FullTextLucene.java
h2/src/main/org/h2/fulltext/FullTextLucene.java
+17
-3
TriggerObject.java
h2/src/main/org/h2/schema/TriggerObject.java
+13
-1
没有找到文件。
h2/src/main/org/h2/api/CloseListener.java
0 → 100644
浏览文件 @
2a83a1ba
/*
* Copyright 2004-2008 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
api
;
import
java.sql.SQLException
;
/**
* A trigger that implements this interface will be notified when the database
* is closed.
*/
public
interface
CloseListener
{
/**
* This method is called when the database is closed.
* If the method throws an exception, it will be logged, but
* closing the database will continue.
*
* @throws SQLException
*/
void
close
()
throws
SQLException
;
}
h2/src/main/org/h2/api/Trigger.java
浏览文件 @
2a83a1ba
h2/src/main/org/h2/engine/Database.java
浏览文件 @
2a83a1ba
...
@@ -34,6 +34,7 @@ import org.h2.result.SearchRow;
...
@@ -34,6 +34,7 @@ import org.h2.result.SearchRow;
import
org.h2.schema.Schema
;
import
org.h2.schema.Schema
;
import
org.h2.schema.SchemaObject
;
import
org.h2.schema.SchemaObject
;
import
org.h2.schema.Sequence
;
import
org.h2.schema.Sequence
;
import
org.h2.schema.TriggerObject
;
import
org.h2.store.DataHandler
;
import
org.h2.store.DataHandler
;
import
org.h2.store.DataPage
;
import
org.h2.store.DataPage
;
import
org.h2.store.DiskFile
;
import
org.h2.store.DiskFile
;
...
@@ -1043,6 +1044,11 @@ public class Database implements DataHandler {
...
@@ -1043,6 +1044,11 @@ public class Database implements DataHandler {
Sequence
sequence
=
(
Sequence
)
sequences
.
get
(
i
);
Sequence
sequence
=
(
Sequence
)
sequences
.
get
(
i
);
sequence
.
close
();
sequence
.
close
();
}
}
ObjectArray
triggers
=
getAllSchemaObjects
(
DbObject
.
TRIGGER
);
for
(
int
i
=
0
;
i
<
triggers
.
size
();
i
++)
{
TriggerObject
trigger
=
(
TriggerObject
)
triggers
.
get
(
i
);
trigger
.
close
();
}
meta
.
close
(
systemSession
);
meta
.
close
(
systemSession
);
systemSession
.
commit
(
true
);
systemSession
.
commit
(
true
);
indexSummaryValid
=
true
;
indexSummaryValid
=
true
;
...
...
h2/src/main/org/h2/engine/FunctionAlias.java
浏览文件 @
2a83a1ba
...
@@ -18,21 +18,22 @@ import org.h2.message.Message;
...
@@ -18,21 +18,22 @@ import org.h2.message.Message;
import
org.h2.message.Trace
;
import
org.h2.message.Trace
;
import
org.h2.table.Table
;
import
org.h2.table.Table
;
import
org.h2.util.ClassUtils
;
import
org.h2.util.ClassUtils
;
import
org.h2.util.ObjectArray
;
import
org.h2.value.DataType
;
import
org.h2.value.DataType
;
import
org.h2.value.Value
;
import
org.h2.value.Value
;
import
org.h2.value.ValueNull
;
import
org.h2.value.ValueNull
;
/**
/**
* Represents a user-defined function, or alias.
* Represents a user-defined function, or alias.
*
* @author Thomas Mueller
* @author Gary Tong
*/
*/
public
class
FunctionAlias
extends
DbObjectBase
{
public
class
FunctionAlias
extends
DbObjectBase
{
private
boolean
hasConnectionParam
;
private
String
className
;
private
String
className
;
private
String
methodName
;
private
String
methodName
;
private
Method
javaMethod
;
private
JavaMethod
[]
javaMethods
;
private
int
paramCount
;
private
int
dataType
;
public
FunctionAlias
(
Database
db
,
int
id
,
String
name
,
String
javaClassMethod
,
boolean
force
)
throws
SQLException
{
public
FunctionAlias
(
Database
db
,
int
id
,
String
name
,
String
javaClassMethod
,
boolean
force
)
throws
SQLException
{
initDbObjectBase
(
db
,
id
,
name
,
Trace
.
FUNCTION
);
initDbObjectBase
(
db
,
id
,
name
,
Trace
.
FUNCTION
);
...
@@ -55,38 +56,38 @@ public class FunctionAlias extends DbObjectBase {
...
@@ -55,38 +56,38 @@ public class FunctionAlias extends DbObjectBase {
}
}
private
synchronized
void
load
()
throws
SQLException
{
private
synchronized
void
load
()
throws
SQLException
{
if
(
javaMethod
!=
null
)
{
if
(
javaMethod
s
!=
null
)
{
return
;
return
;
}
}
Class
javaClass
=
ClassUtils
.
loadUserClass
(
className
);
Class
javaClass
=
ClassUtils
.
loadUserClass
(
className
);
Method
[]
methods
=
javaClass
.
getMethods
();
Method
[]
methods
=
javaClass
.
getMethods
();
ObjectArray
list
=
new
ObjectArray
();
for
(
int
i
=
0
;
i
<
methods
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
methods
.
length
;
i
++)
{
Method
m
=
methods
[
i
];
Method
m
=
methods
[
i
];
if
(!
Modifier
.
isStatic
(
m
.
getModifiers
()))
{
if
(!
Modifier
.
isStatic
(
m
.
getModifiers
()))
{
continue
;
continue
;
}
}
if
(
m
.
getName
().
equals
(
methodName
))
{
if
(
m
.
getName
().
equals
(
methodName
)
||
getMethodSignature
(
m
).
equals
(
methodName
))
{
javaMethod
=
m
;
JavaMethod
javaMethod
=
new
JavaMethod
(
m
);
break
;
for
(
int
j
=
0
;
j
<
list
.
size
();
j
++)
{
}
else
if
(
getMethodSignature
(
m
).
equals
(
methodName
))
{
JavaMethod
old
=
(
JavaMethod
)
list
.
get
(
j
);
javaMethod
=
m
;
if
(
old
.
paramCount
==
javaMethod
.
paramCount
)
{
break
;
throw
Message
.
getSQLException
(
ErrorCode
.
METHODS_MUST_HAVE_DIFFERENT_PARAMETER_COUNTS_2
,
new
String
[]
{
old
.
method
.
toString
(),
javaMethod
.
method
.
toString
()
}
}
);
}
}
if
(
javaMethod
==
null
)
{
throw
Message
.
getSQLException
(
ErrorCode
.
METHOD_NOT_FOUND_1
,
methodName
+
" ("
+
className
+
")"
);
}
}
Class
[]
paramClasses
=
javaMethod
.
getParameterTypes
();
list
.
add
(
javaMethod
);
paramCount
=
paramClasses
.
length
;
if
(
paramCount
>
0
)
{
Class
paramClass
=
paramClasses
[
0
];
if
(
Connection
.
class
.
isAssignableFrom
(
paramClass
))
{
hasConnectionParam
=
true
;
paramCount
--;
}
}
}
}
Class
returnClass
=
javaMethod
.
getReturnType
();
if
(
list
.
size
()
==
0
)
{
dataType
=
DataType
.
getTypeFromClass
(
returnClass
);
throw
Message
.
getSQLException
(
ErrorCode
.
METHOD_NOT_FOUND_1
,
methodName
+
" ("
+
className
+
")"
);
}
javaMethods
=
new
JavaMethod
[
list
.
size
()];
list
.
toArray
(
javaMethods
);
}
}
private
String
getMethodSignature
(
Method
m
)
{
private
String
getMethodSignature
(
Method
m
)
{
...
@@ -110,15 +111,6 @@ public class FunctionAlias extends DbObjectBase {
...
@@ -110,15 +111,6 @@ public class FunctionAlias extends DbObjectBase {
return
buff
.
toString
();
return
buff
.
toString
();
}
}
public
Class
[]
getColumnClasses
()
throws
SQLException
{
load
();
return
javaMethod
.
getParameterTypes
();
}
public
int
getDataType
()
{
return
dataType
;
}
public
String
getCreateSQLForCopy
(
Table
table
,
String
quotedName
)
{
public
String
getCreateSQLForCopy
(
Table
table
,
String
quotedName
)
{
throw
Message
.
getInternalError
();
throw
Message
.
getInternalError
();
}
}
...
@@ -144,7 +136,7 @@ public class FunctionAlias extends DbObjectBase {
...
@@ -144,7 +136,7 @@ public class FunctionAlias extends DbObjectBase {
database
.
removeMeta
(
session
,
getId
());
database
.
removeMeta
(
session
,
getId
());
className
=
null
;
className
=
null
;
methodName
=
null
;
methodName
=
null
;
javaMethod
=
null
;
javaMethod
s
=
null
;
invalidate
();
invalidate
();
}
}
...
@@ -152,6 +144,76 @@ public class FunctionAlias extends DbObjectBase {
...
@@ -152,6 +144,76 @@ public class FunctionAlias extends DbObjectBase {
throw
Message
.
getUnsupportedException
();
throw
Message
.
getUnsupportedException
();
}
}
/**
* Find the Java method that matches the arguments.
*
* @param args the argument list
* @return the Java method
* @throws SQLException if no matching method could be found
*/
public
JavaMethod
findJavaMethod
(
Expression
[]
args
)
throws
SQLException
{
load
();
for
(
int
i
=
0
;
i
<
javaMethods
.
length
;
i
++)
{
if
(
javaMethods
[
i
].
paramCount
==
args
.
length
)
{
return
javaMethods
[
i
];
}
}
throw
Message
.
getSQLException
(
ErrorCode
.
METHOD_NOT_FOUND_1
,
methodName
+
" ("
+
className
+
")"
);
}
public
String
getJavaClassName
()
{
return
this
.
className
;
}
public
String
getJavaMethodName
()
{
return
this
.
methodName
;
}
/**
* Get the Java methods mapped by this function.
*
* @return the Java methods.
*/
public
JavaMethod
[]
getJavaMethods
()
throws
SQLException
{
load
();
return
javaMethods
;
}
/**
* There may be multiple Java methods that match a function name.
* Each method must have a different number of parameters however.
* This helper class represents one such method.
*/
public
static
class
JavaMethod
{
Method
method
;
boolean
hasConnectionParam
;
int
paramCount
;
int
dataType
;
JavaMethod
(
Method
method
)
throws
SQLException
{
this
.
method
=
method
;
Class
[]
paramClasses
=
method
.
getParameterTypes
();
paramCount
=
paramClasses
.
length
;
if
(
paramCount
>
0
)
{
Class
paramClass
=
paramClasses
[
0
];
if
(
Connection
.
class
.
isAssignableFrom
(
paramClass
))
{
hasConnectionParam
=
true
;
paramCount
--;
}
}
Class
returnClass
=
method
.
getReturnType
();
dataType
=
DataType
.
getTypeFromClass
(
returnClass
);
}
/**
* Check if this function requires a database connection.
*
* @return if the function requires a connection
*/
public
boolean
hasConnectionParam
()
{
return
this
.
hasConnectionParam
;
}
/**
/**
* Call the user-defined function and return the value.
* Call the user-defined function and return the value.
*
*
...
@@ -160,9 +222,8 @@ public class FunctionAlias extends DbObjectBase {
...
@@ -160,9 +222,8 @@ public class FunctionAlias extends DbObjectBase {
* @param columnList true if the function should only return the column list
* @param columnList true if the function should only return the column list
* @return the value
* @return the value
*/
*/
public
synchronized
Value
getValue
(
Session
session
,
Expression
[]
args
,
boolean
columnList
)
throws
SQLException
{
public
Value
getValue
(
Session
session
,
Expression
[]
args
,
boolean
columnList
)
throws
SQLException
{
load
();
Class
[]
paramClasses
=
method
.
getParameterTypes
();
Class
[]
paramClasses
=
javaMethod
.
getParameterTypes
();
Object
[]
params
=
new
Object
[
paramClasses
.
length
];
Object
[]
params
=
new
Object
[
paramClasses
.
length
];
int
p
=
0
;
int
p
=
0
;
if
(
hasConnectionParam
&&
params
.
length
>
0
)
{
if
(
hasConnectionParam
&&
params
.
length
>
0
)
{
...
@@ -199,7 +260,7 @@ public class FunctionAlias extends DbObjectBase {
...
@@ -199,7 +260,7 @@ public class FunctionAlias extends DbObjectBase {
session
.
setAutoCommit
(
false
);
session
.
setAutoCommit
(
false
);
try
{
try
{
Object
returnValue
;
Object
returnValue
;
returnValue
=
javaM
ethod
.
invoke
(
null
,
params
);
returnValue
=
m
ethod
.
invoke
(
null
,
params
);
if
(
returnValue
==
null
)
{
if
(
returnValue
==
null
)
{
return
ValueNull
.
INSTANCE
;
return
ValueNull
.
INSTANCE
;
}
}
...
@@ -213,26 +274,18 @@ public class FunctionAlias extends DbObjectBase {
...
@@ -213,26 +274,18 @@ public class FunctionAlias extends DbObjectBase {
}
}
}
}
public
int
getParameterCount
()
throws
SQLException
{
public
Class
[]
getColumnClasses
()
throws
SQLException
{
load
();
return
method
.
getParameterTypes
();
return
paramCount
;
}
}
public
String
getJavaClassNam
e
()
{
public
int
getDataTyp
e
()
{
return
this
.
classNam
e
;
return
dataTyp
e
;
}
}
public
String
getJavaMethodName
()
{
public
int
getParameterCount
()
throws
SQLException
{
return
this
.
methodName
;
return
paramCount
;
}
}
/**
* Check if this function requires a database connection.
*
* @return if the function requires a connection
*/
public
boolean
hasConnectionParam
()
{
return
this
.
hasConnectionParam
;
}
}
}
}
h2/src/main/org/h2/fulltext/FullTextLucene.java
浏览文件 @
2a83a1ba
...
@@ -32,6 +32,7 @@ import org.apache.lucene.search.Hits;
...
@@ -32,6 +32,7 @@ import org.apache.lucene.search.Hits;
import
org.apache.lucene.search.IndexSearcher
;
import
org.apache.lucene.search.IndexSearcher
;
import
org.apache.lucene.search.Query
;
import
org.apache.lucene.search.Query
;
import
org.apache.lucene.search.Searcher
;
import
org.apache.lucene.search.Searcher
;
import
org.h2.api.CloseListener
;
import
org.h2.api.Trigger
;
import
org.h2.api.Trigger
;
import
org.h2.command.Parser
;
import
org.h2.command.Parser
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
...
@@ -50,7 +51,7 @@ import org.h2.util.StringUtils;
...
@@ -50,7 +51,7 @@ import org.h2.util.StringUtils;
*/
*/
public
class
FullTextLucene
extends
FullText
public
class
FullTextLucene
extends
FullText
//## Java 1.4 begin ##
//## Java 1.4 begin ##
implements
Trigger
implements
Trigger
,
CloseListener
//## Java 1.4 end ##
//## Java 1.4 end ##
{
{
...
@@ -574,8 +575,9 @@ implements Trigger
...
@@ -574,8 +575,9 @@ implements Trigger
synchronized
(
indexers
)
{
synchronized
(
indexers
)
{
indexer
=
(
IndexModifier
)
indexers
.
get
(
path
);
indexer
=
(
IndexModifier
)
indexers
.
get
(
path
);
if
(
indexer
==
null
)
{
if
(
indexer
==
null
)
{
// TODO: create flag = true means re-create
Analyzer
analyzer
=
new
StandardAnalyzer
();
indexer
=
new
IndexModifier
(
path
,
new
StandardAnalyzer
(),
true
);
boolean
create
=
!
IndexReader
.
indexExists
(
path
);
indexer
=
new
IndexModifier
(
path
,
analyzer
,
create
);
indexers
.
put
(
path
,
indexer
);
indexers
.
put
(
path
,
indexer
);
}
}
}
}
...
@@ -613,6 +615,18 @@ implements Trigger
...
@@ -613,6 +615,18 @@ implements Trigger
index
[
i
]
=
found
;
index
[
i
]
=
found
;
}
}
}
}
public
void
close
()
throws
SQLException
{
try
{
if
(
indexer
!=
null
)
{
indexer
.
flush
();
indexer
.
close
();
indexer
=
null
;
}
}
catch
(
Exception
e
)
{
throw
convertException
(
e
);
}
}
//## Java 1.4 end ##
//## Java 1.4 end ##
}
}
h2/src/main/org/h2/schema/TriggerObject.java
浏览文件 @
2a83a1ba
...
@@ -9,6 +9,7 @@ package org.h2.schema;
...
@@ -9,6 +9,7 @@ package org.h2.schema;
import
java.sql.Connection
;
import
java.sql.Connection
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
org.h2.api.CloseListener
;
import
org.h2.api.Trigger
;
import
org.h2.api.Trigger
;
import
org.h2.command.Parser
;
import
org.h2.command.Parser
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.ErrorCode
;
...
@@ -313,7 +314,7 @@ public class TriggerObject extends SchemaObjectBase {
...
@@ -313,7 +314,7 @@ public class TriggerObject extends SchemaObjectBase {
}
}
/**
/**
* Get the trigger class name
* Get the trigger class name
.
*
*
* @return the class name
* @return the class name
*/
*/
...
@@ -321,4 +322,15 @@ public class TriggerObject extends SchemaObjectBase {
...
@@ -321,4 +322,15 @@ public class TriggerObject extends SchemaObjectBase {
return
triggerClassName
;
return
triggerClassName
;
}
}
/**
* Close the trigger.
*/
public
void
close
()
throws
SQLException
{
if
(
triggerCallback
!=
null
)
{
if
(
triggerCallback
instanceof
CloseListener
)
{
((
CloseListener
)
triggerCallback
).
close
();
}
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论