Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
3ab5f276
提交
3ab5f276
authored
1月 15, 2008
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
--no commit message
--no commit message
上级
a49fa5aa
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
109 行增加
和
37 行删除
+109
-37
Call.java
h2/src/main/org/h2/command/dml/Call.java
+18
-1
ScriptCommand.java
h2/src/main/org/h2/command/dml/ScriptCommand.java
+4
-0
Set.java
h2/src/main/org/h2/command/dml/Set.java
+10
-0
SetTypes.java
h2/src/main/org/h2/command/dml/SetTypes.java
+2
-0
Database.java
h2/src/main/org/h2/engine/Database.java
+5
-4
BaseIndex.java
h2/src/main/org/h2/index/BaseIndex.java
+6
-8
_text_uk.properties
h2/src/main/org/h2/server/web/res/_text_uk.properties
+7
-7
NetUtils.java
h2/src/main/org/h2/util/NetUtils.java
+1
-1
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+12
-16
TestOptimizations.java
h2/src/test/org/h2/test/db/TestOptimizations.java
+17
-0
TestBatchUpdates.java
h2/src/test/org/h2/test/jdbc/TestBatchUpdates.java
+27
-0
没有找到文件。
h2/src/main/org/h2/command/dml/Call.java
浏览文件 @
3ab5f276
...
@@ -21,7 +21,7 @@ import org.h2.value.ValueResultSet;
...
@@ -21,7 +21,7 @@ import org.h2.value.ValueResultSet;
/**
/**
* This class represents the statement
* This class represents the statement
* CALL
* CALL
.
*/
*/
public
class
Call
extends
Prepared
{
public
class
Call
extends
Prepared
{
private
Expression
value
;
private
Expression
value
;
...
@@ -37,6 +37,23 @@ public class Call extends Prepared {
...
@@ -37,6 +37,23 @@ public class Call extends Prepared {
return
result
;
return
result
;
}
}
public
int
update
()
throws
SQLException
{
Value
v
=
value
.
getValue
(
session
);
int
type
=
v
.
getType
();
switch
(
type
)
{
case
Value
.
RESULT_SET
:
case
Value
.
ARRAY
:
// this will throw an exception
// methods returning a result set may not be called like this.
return
super
.
update
();
case
Value
.
UNKNOWN
:
case
Value
.
NULL
:
return
0
;
default
:
return
v
.
getInt
();
}
}
public
LocalResult
query
(
int
maxrows
)
throws
SQLException
{
public
LocalResult
query
(
int
maxrows
)
throws
SQLException
{
setCurrentRowNumber
(
1
);
setCurrentRowNumber
(
1
);
Value
v
=
value
.
getValue
(
session
);
Value
v
=
value
.
getValue
(
session
);
...
...
h2/src/main/org/h2/command/dml/ScriptCommand.java
浏览文件 @
3ab5f276
...
@@ -132,6 +132,10 @@ public class ScriptCommand extends ScriptBase {
...
@@ -132,6 +132,10 @@ public class ScriptCommand extends ScriptBase {
ObjectArray
settings
=
db
.
getAllSettings
();
ObjectArray
settings
=
db
.
getAllSettings
();
for
(
int
i
=
0
;
i
<
settings
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
settings
.
size
();
i
++)
{
Setting
setting
=
(
Setting
)
settings
.
get
(
i
);
Setting
setting
=
(
Setting
)
settings
.
get
(
i
);
if
(
setting
.
getName
().
equals
(
SetTypes
.
getTypeName
(
SetTypes
.
CREATE_BUILD
)))
{
// don't add CREATE_BUILD to the script (it is only set when creating the database)
continue
;
}
add
(
setting
.
getCreateSQL
(),
false
);
add
(
setting
.
getCreateSQL
(),
false
);
}
}
}
}
...
...
h2/src/main/org/h2/command/dml/Set.java
浏览文件 @
3ab5f276
...
@@ -280,6 +280,16 @@ public class Set extends Prepared {
...
@@ -280,6 +280,16 @@ public class Set extends Prepared {
database
.
setExclusiveSession
(
value
==
1
?
session
:
null
);
database
.
setExclusiveSession
(
value
==
1
?
session
:
null
);
break
;
break
;
}
}
case
SetTypes
.
CREATE_BUILD
:
{
session
.
getUser
().
checkAdmin
();
if
(
database
.
isStarting
())
{
// just ignore the command if not starting
// this avoids problems when running recovery scripts
int
value
=
getIntValue
();
addOrUpdateSetting
(
name
,
null
,
value
);
}
break
;
}
default
:
default
:
throw
Message
.
getInternalError
(
"type="
+
type
);
throw
Message
.
getInternalError
(
"type="
+
type
);
}
}
...
...
h2/src/main/org/h2/command/dml/SetTypes.java
浏览文件 @
3ab5f276
...
@@ -21,6 +21,7 @@ public class SetTypes {
...
@@ -21,6 +21,7 @@ public class SetTypes {
public
static
final
int
COMPRESS_LOB
=
23
,
ALLOW_LITERALS
=
24
,
MULTI_THREADED
=
25
,
SCHEMA
=
26
;
public
static
final
int
COMPRESS_LOB
=
23
,
ALLOW_LITERALS
=
24
,
MULTI_THREADED
=
25
,
SCHEMA
=
26
;
public
static
final
int
OPTIMIZE_REUSE_RESULTS
=
27
,
SCHEMA_SEARCH_PATH
=
28
,
UNDO_LOG
=
29
;
public
static
final
int
OPTIMIZE_REUSE_RESULTS
=
27
,
SCHEMA_SEARCH_PATH
=
28
,
UNDO_LOG
=
29
;
public
static
final
int
REFERENTIAL_INTEGRITY
=
30
,
MVCC
=
31
,
MAX_OPERATION_MEMORY
=
32
,
EXCLUSIVE
=
33
;
public
static
final
int
REFERENTIAL_INTEGRITY
=
30
,
MVCC
=
31
,
MAX_OPERATION_MEMORY
=
32
,
EXCLUSIVE
=
33
;
public
static
final
int
CREATE_BUILD
=
34
;
private
static
ObjectArray
types
=
new
ObjectArray
();
private
static
ObjectArray
types
=
new
ObjectArray
();
...
@@ -58,6 +59,7 @@ public class SetTypes {
...
@@ -58,6 +59,7 @@ public class SetTypes {
setType
(
MVCC
,
"MVCC"
);
setType
(
MVCC
,
"MVCC"
);
setType
(
MAX_OPERATION_MEMORY
,
"MAX_OPERATION_MEMORY"
);
setType
(
MAX_OPERATION_MEMORY
,
"MAX_OPERATION_MEMORY"
);
setType
(
EXCLUSIVE
,
"EXCLUSIVE"
);
setType
(
EXCLUSIVE
,
"EXCLUSIVE"
);
setType
(
CREATE_BUILD
,
"CREATE_BUILD"
);
}
}
private
static
void
setType
(
int
type
,
String
name
)
{
private
static
void
setType
(
int
type
,
String
name
)
{
...
...
h2/src/main/org/h2/engine/Database.java
浏览文件 @
3ab5f276
...
@@ -63,12 +63,12 @@ import org.h2.value.ValueInt;
...
@@ -63,12 +63,12 @@ import org.h2.value.ValueInt;
/**
/**
* There is one database object per open database.
* There is one database object per open database.
*
* The format of the meta data table is:
* id int, headPos int (for indexes), objectType int, sql varchar
*
* @since 2004-04-15 22:49
* @since 2004-04-15 22:49
*/
*/
/*
* MetaData format: int id int headPos (for indexes) int objectType String sql
*/
public
class
Database
implements
DataHandler
{
public
class
Database
implements
DataHandler
{
private
final
boolean
persistent
;
private
final
boolean
persistent
;
...
@@ -539,6 +539,7 @@ public class Database implements DataHandler {
...
@@ -539,6 +539,7 @@ public class Database implements DataHandler {
addDefaultSetting
(
systemSession
,
SetTypes
.
CACHE_SIZE
,
null
,
SysProperties
.
CACHE_SIZE_DEFAULT
);
addDefaultSetting
(
systemSession
,
SetTypes
.
CACHE_SIZE
,
null
,
SysProperties
.
CACHE_SIZE_DEFAULT
);
addDefaultSetting
(
systemSession
,
SetTypes
.
CLUSTER
,
Constants
.
CLUSTERING_DISABLED
,
0
);
addDefaultSetting
(
systemSession
,
SetTypes
.
CLUSTER
,
Constants
.
CLUSTERING_DISABLED
,
0
);
addDefaultSetting
(
systemSession
,
SetTypes
.
WRITE_DELAY
,
null
,
Constants
.
DEFAULT_WRITE_DELAY
);
addDefaultSetting
(
systemSession
,
SetTypes
.
WRITE_DELAY
,
null
,
Constants
.
DEFAULT_WRITE_DELAY
);
addDefaultSetting
(
systemSession
,
SetTypes
.
CREATE_BUILD
,
null
,
Constants
.
BUILD_ID
);
if
(!
readOnly
)
{
if
(!
readOnly
)
{
removeUnusedStorages
(
systemSession
);
removeUnusedStorages
(
systemSession
);
}
}
...
...
h2/src/main/org/h2/index/BaseIndex.java
浏览文件 @
3ab5f276
...
@@ -172,6 +172,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
...
@@ -172,6 +172,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
public
long
getCostRangeIndex
(
int
[]
masks
,
long
rowCount
)
throws
SQLException
{
public
long
getCostRangeIndex
(
int
[]
masks
,
long
rowCount
)
throws
SQLException
{
rowCount
+=
Constants
.
COST_ROW_OFFSET
;
rowCount
+=
Constants
.
COST_ROW_OFFSET
;
long
cost
=
rowCount
;
long
cost
=
rowCount
;
long
rows
=
rowCount
;
int
totalSelectivity
=
0
;
int
totalSelectivity
=
0
;
for
(
int
i
=
0
;
masks
!=
null
&&
i
<
columns
.
length
;
i
++)
{
for
(
int
i
=
0
;
masks
!=
null
&&
i
<
columns
.
length
;
i
++)
{
Column
column
=
columns
[
i
];
Column
column
=
columns
[
i
];
...
@@ -187,19 +188,16 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
...
@@ -187,19 +188,16 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
if
(
distinctRows
<=
0
)
{
if
(
distinctRows
<=
0
)
{
distinctRows
=
1
;
distinctRows
=
1
;
}
}
long
rowsSelected
=
rowCount
/
distinctRows
;
rows
=
Math
.
max
(
rowCount
/
distinctRows
,
1
);
if
(
rowsSelected
<
1
)
{
cost
=
getLookupCost
(
rowCount
)
+
rows
;
rowsSelected
=
1
;
}
cost
=
getLookupCost
(
rowCount
)
+
rowsSelected
;
}
else
if
((
mask
&
IndexCondition
.
RANGE
)
==
IndexCondition
.
RANGE
)
{
}
else
if
((
mask
&
IndexCondition
.
RANGE
)
==
IndexCondition
.
RANGE
)
{
cost
=
getLookupCost
(
rowCount
)
+
row
Count
/
4
;
cost
=
getLookupCost
(
rowCount
)
+
row
s
/
4
;
break
;
break
;
}
else
if
((
mask
&
IndexCondition
.
START
)
==
IndexCondition
.
START
)
{
}
else
if
((
mask
&
IndexCondition
.
START
)
==
IndexCondition
.
START
)
{
cost
=
getLookupCost
(
rowCount
)
+
row
Count
/
3
;
cost
=
getLookupCost
(
rowCount
)
+
row
s
/
3
;
break
;
break
;
}
else
if
((
mask
&
IndexCondition
.
END
)
==
IndexCondition
.
END
)
{
}
else
if
((
mask
&
IndexCondition
.
END
)
==
IndexCondition
.
END
)
{
cost
=
row
Count
/
3
;
cost
=
row
s
/
3
;
break
;
break
;
}
else
{
}
else
{
break
;
break
;
...
...
h2/src/main/org/h2/server/web/res/_text_uk.properties
浏览文件 @
3ab5f276
差异被折叠。
点击展开。
h2/src/main/org/h2/util/NetUtils.java
浏览文件 @
3ab5f276
...
@@ -75,7 +75,7 @@ public class NetUtils {
...
@@ -75,7 +75,7 @@ public class NetUtils {
}
}
synchronized
(
NetUtils
.
class
)
{
synchronized
(
NetUtils
.
class
)
{
if
(
bindAddress
==
null
)
{
if
(
bindAddress
==
null
)
{
bindAddress
=
InetAddress
.
getBy
Name
(
host
);
bindAddress
=
InetAddress
.
getBy
Address
(
InetAddress
.
getByName
(
host
).
getAddress
()
);
}
}
}
}
return
bindAddress
;
return
bindAddress
;
...
...
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
3ab5f276
...
@@ -150,29 +150,25 @@ java org.h2.test.TestAll timer
...
@@ -150,29 +150,25 @@ java org.h2.test.TestAll timer
/*
/*
h2CallableStatementBatchTest.zip
Roadmap:
h2-2007-12-27_test.zip
History:
History:
Roadmap:
Automatically switch source code before compiling
staging.trace.db.gz
There is a problem with the h2.bindAddress build. When it is binding to 127.0.0.1,
the bind function works perfectly and I could confirm it no longer
listen to the ports of other IP addresses. However, when it is binding to normal IP
addresses, it always got the following exception.
Caused by: org.h2.jdbc.JdbcSQLException: Connection is broken [90067-64]
at org.h2.message.Message.getSQLException(Message.java:89)
Remarks: I build with JDK 1.6
drop table logs;
Test Recovery with MAX_LOG_FILE_SIZE=1; test with various log file sizes
CREATE TABLE Logs(id INT PRIMARY KEY, procid INT);
CREATE unique INDEX procIdx ON Logs(procid, id);
@LOOP 1000 INSERT INTO Logs VALUES(?, MOD(?, 100000));
ANALYZE SAMPLE_SIZE 0;
script nodata;
EXPLAIN SELECT id FROM Logs WHERE procid=2 AND id<100;
allow queries as well in batch updates
Test H2 on OS X (result are here: h2-2007-12-27_test.zip)
CALL syntax should probably work for regular executeUpdate as well.
http://java.sun.com/j2se/1.4.2/docs/guide/jdbc/getstart/callablestatement.html#1000220
write to the db file what version was used to create a database
Docs:
H2 can emulate PostgreSQL server.
Web site:
Web site:
link to history page, bug page
link to history page, bug page
...
...
h2/src/test/org/h2/test/db/TestOptimizations.java
浏览文件 @
3ab5f276
...
@@ -24,6 +24,7 @@ public class TestOptimizations extends TestBase {
...
@@ -24,6 +24,7 @@ public class TestOptimizations extends TestBase {
if
(
config
.
networked
)
{
if
(
config
.
networked
)
{
return
;
return
;
}
}
testMultiColumnRangeQuery
();
testDistinctOptimization
();
testDistinctOptimization
();
testQueryCacheTimestamp
();
testQueryCacheTimestamp
();
testQueryCacheSpeed
();
testQueryCacheSpeed
();
...
@@ -34,6 +35,22 @@ public class TestOptimizations extends TestBase {
...
@@ -34,6 +35,22 @@ public class TestOptimizations extends TestBase {
testMinMaxCountOptimization
(
false
);
testMinMaxCountOptimization
(
false
);
}
}
private
void
testMultiColumnRangeQuery
()
throws
Exception
{
deleteDb
(
"optimizations"
);
Connection
conn
=
getConnection
(
"optimizations"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE Logs(id INT PRIMARY KEY, type INT)"
);
stat
.
execute
(
"CREATE unique INDEX type_index ON Logs(type, id)"
);
stat
.
execute
(
"INSERT INTO Logs SELECT X, MOD(X, 3) FROM SYSTEM_RANGE(1, 1000)"
);
stat
.
execute
(
"ANALYZE SAMPLE_SIZE 0"
);
ResultSet
rs
;
rs
=
stat
.
executeQuery
(
"EXPLAIN SELECT id FROM Logs WHERE id < 100 and type=2 AND id<100"
);
rs
.
next
();
String
plan
=
rs
.
getString
(
1
);
check
(
plan
.
indexOf
(
"TYPE_INDEX"
)
>
0
);
conn
.
close
();
}
private
void
testDistinctOptimization
()
throws
Exception
{
private
void
testDistinctOptimization
()
throws
Exception
{
deleteDb
(
"optimizations"
);
deleteDb
(
"optimizations"
);
Connection
conn
=
getConnection
(
"optimizations"
);
Connection
conn
=
getConnection
(
"optimizations"
);
...
...
h2/src/test/org/h2/test/jdbc/TestBatchUpdates.java
浏览文件 @
3ab5f276
...
@@ -7,6 +7,7 @@ package org.h2.test.jdbc;
...
@@ -7,6 +7,7 @@ package org.h2.test.jdbc;
import
java.io.ByteArrayOutputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.PrintStream
;
import
java.io.PrintStream
;
import
java.sql.BatchUpdateException
;
import
java.sql.BatchUpdateException
;
import
java.sql.CallableStatement
;
import
java.sql.Connection
;
import
java.sql.Connection
;
import
java.sql.DatabaseMetaData
;
import
java.sql.DatabaseMetaData
;
import
java.sql.PreparedStatement
;
import
java.sql.PreparedStatement
;
...
@@ -38,10 +39,36 @@ public class TestBatchUpdates extends TestBase {
...
@@ -38,10 +39,36 @@ public class TestBatchUpdates extends TestBase {
PreparedStatement
prep
;
PreparedStatement
prep
;
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
testExecuteCall
();
testException
();
testException
();
testCoffee
();
testCoffee
();
}
}
private
void
testExecuteCall
()
throws
Exception
{
deleteDb
(
"batchUpdates"
);
Connection
conn
=
getConnection
(
"batchUpdates"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE ALIAS updatePrices FOR \""
+
getClass
().
getName
()
+
".updatePrices\""
);
CallableStatement
call
=
conn
.
prepareCall
(
"{call updatePrices(?, ?)}"
);
call
.
setString
(
1
,
"Hello"
);
call
.
setFloat
(
2
,
1.4f
);
call
.
addBatch
();
call
.
setString
(
1
,
"World"
);
call
.
setFloat
(
2
,
3.2f
);
call
.
addBatch
();
int
[]
updateCounts
=
call
.
executeBatch
();
int
total
=
0
;
for
(
int
i
=
0
;
i
<
updateCounts
.
length
;
i
++)
{
total
+=
updateCounts
[
i
];
}
check
(
4
,
total
);
conn
.
close
();
}
public
static
int
updatePrices
(
String
s
,
double
f
)
{
return
(
int
)
f
;
}
private
void
testException
()
throws
Exception
{
private
void
testException
()
throws
Exception
{
deleteDb
(
"batchUpdates"
);
deleteDb
(
"batchUpdates"
);
Connection
conn
=
getConnection
(
"batchUpdates"
);
Connection
conn
=
getConnection
(
"batchUpdates"
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论