Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
390b9472
提交
390b9472
authored
15 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove unused code.
上级
798a5049
master
noel-pr1
plus33-master
pr/267
stumc-Issue#576
version-1.4.198
version-1.4.197
version-1.4.196
version-1.4.195
version-1.4.194
version-1.4.193
version-1.4.192
version-1.4.191
version-1.4.190
version-1.4.188
version-1.4.187
version-1.4.186
version-1.4.185
version-1.4.184
version-1.4.183
version-1.4.182
version-1.4.181
version-1.4.178
version-1.4.177
version-1.3
version-1.2
version-1.1
version-1.0
无相关合并请求
隐藏空白字符变更
内嵌
并排
正在显示
15 个修改的文件
包含
276 行增加
和
293 行删除
+276
-293
changelog.html
h2/src/docsrc/html/changelog.html
+3
-1
Database.java
h2/src/main/org/h2/engine/Database.java
+6
-1
CipherFactory.java
h2/src/main/org/h2/security/CipherFactory.java
+176
-0
SecureSocketFactory.java
h2/src/main/org/h2/security/SecureSocketFactory.java
+0
-207
FileStore.java
h2/src/main/org/h2/store/FileStore.java
+6
-2
PageStore.java
h2/src/main/org/h2/store/PageStore.java
+12
-0
MultiDimension.java
h2/src/main/org/h2/tools/MultiDimension.java
+0
-44
NetUtils.java
h2/src/main/org/h2/util/NetUtils.java
+3
-3
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+11
-3
TestBase.java
h2/src/test/org/h2/test/TestBase.java
+3
-0
Database.java
h2/src/test/org/h2/test/bench/Database.java
+6
-1
TestIndex.java
h2/src/test/org/h2/test/db/TestIndex.java
+38
-0
TestMultiDimension.java
h2/src/test/org/h2/test/db/TestMultiDimension.java
+0
-27
TestPgServer.java
h2/src/test/org/h2/test/unit/TestPgServer.java
+9
-1
SecureKeyStoreBuilder.java
h2/src/tools/org/h2/dev/security/SecureKeyStoreBuilder.java
+3
-3
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
390b9472
...
...
@@ -18,7 +18,9 @@ Change Log
<h1>
Change Log
</h1>
<h2>
Next Version (unreleased)
</h2>
<ul><li>
The file system abstraction no longer throws SQL exceptions.
<ul><li>
Hash indexes now are only used for single column indexes.
</li><li>
The cache types WEAK_* and TQ are no longer supported.
</li><li>
The file system abstraction no longer throws SQL exceptions.
</li><li>
DatabaseEventListener.diskSpaceIsLow has changed.
</li><li>
The CompressTool no longer throw as SQL exceptions. Instead, it throws runtime exceptions.
</li><li>
SimpleResultSet.addColumn and addRow now can throw a IllegalStateException
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/engine/Database.java
浏览文件 @
390b9472
...
...
@@ -1749,7 +1749,12 @@ public class Database implements DataHandler {
* executing the SQL statement CHECKPOINT SYNC.
*/
public
void
sync
()
{
int
todo
;
if
(
readOnly
||
pageStore
==
null
)
{
return
;
}
synchronized
(
this
)
{
pageStore
.
sync
();
}
}
public
int
getMaxMemoryRows
()
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/security/CipherFactory.java
浏览文件 @
390b9472
...
...
@@ -6,14 +6,47 @@
*/
package
org
.
h2
.
security
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.net.InetAddress
;
import
java.net.InetSocketAddress
;
import
java.net.ServerSocket
;
import
java.net.Socket
;
import
java.security.KeyFactory
;
import
java.security.KeyStore
;
import
java.security.PrivateKey
;
import
java.security.cert.Certificate
;
import
java.security.cert.CertificateFactory
;
import
java.security.spec.PKCS8EncodedKeySpec
;
import
java.util.Properties
;
import
javax.net.ServerSocketFactory
;
import
javax.net.ssl.SSLServerSocket
;
import
javax.net.ssl.SSLServerSocketFactory
;
import
javax.net.ssl.SSLSocket
;
import
javax.net.ssl.SSLSocketFactory
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
import
org.h2.message.DbException
;
import
org.h2.util.IOUtils
;
import
org.h2.util.Utils
;
/**
* A factory to create new block cipher objects.
*/
public
class
CipherFactory
{
/**
* The default password to use for the .h2.keystore file
*/
public
static
final
String
KEYSTORE_PASSWORD
=
"h2pass"
;
private
static
final
String
KEYSTORE
=
".h2.keystore"
;
private
static
final
String
KEYSTORE_KEY
=
"javax.net.ssl.keyStore"
;
private
static
final
String
KEYSTORE_PASSWORD_KEY
=
"javax.net.ssl.keyStorePassword"
;
private
static
final
String
ANONYMOUS_CIPHER_SUITE
=
"SSL_DH_anon_WITH_RC4_128_MD5"
;
private
CipherFactory
()
{
// utility class
}
...
...
@@ -46,4 +79,147 @@ public class CipherFactory {
throw
DbException
.
getInvalidValueException
(
algorithm
,
"algorithm"
);
}
/**
* Create a secure client socket that is connected to the given address and port.
*
* @param address the address to connect to
* @param port the port
* @return the socket
*/
public
static
Socket
createSocket
(
InetAddress
address
,
int
port
)
throws
IOException
{
Socket
socket
=
null
;
//## Java 1.4 begin ##
setKeystore
();
SSLSocketFactory
f
=
(
SSLSocketFactory
)
SSLSocketFactory
.
getDefault
();
SSLSocket
secureSocket
=
(
SSLSocket
)
f
.
createSocket
();
secureSocket
.
connect
(
new
InetSocketAddress
(
address
,
port
),
SysProperties
.
SOCKET_CONNECT_TIMEOUT
);
if
(
SysProperties
.
ENABLE_ANONYMOUS_SSL
)
{
String
[]
list
=
secureSocket
.
getEnabledCipherSuites
();
list
=
addAnonymous
(
list
);
secureSocket
.
setEnabledCipherSuites
(
list
);
}
socket
=
secureSocket
;
//## Java 1.4 end ##
return
socket
;
}
/**
* Create a secure server socket. If a bind address is specified, the socket
* is only bound to this address.
*
* @param port the port to listen on
* @param bindAddress the address to bind to, or null to bind to all
* addresses
* @return the server socket
*/
public
static
ServerSocket
createServerSocket
(
int
port
,
InetAddress
bindAddress
)
throws
IOException
{
ServerSocket
socket
=
null
;
//## Java 1.4 begin ##
setKeystore
();
ServerSocketFactory
f
=
SSLServerSocketFactory
.
getDefault
();
SSLServerSocket
secureSocket
;
if
(
bindAddress
==
null
)
{
secureSocket
=
(
SSLServerSocket
)
f
.
createServerSocket
(
port
);
}
else
{
secureSocket
=
(
SSLServerSocket
)
f
.
createServerSocket
(
port
,
0
,
bindAddress
);
}
if
(
SysProperties
.
ENABLE_ANONYMOUS_SSL
)
{
String
[]
list
=
secureSocket
.
getEnabledCipherSuites
();
list
=
addAnonymous
(
list
);
secureSocket
.
setEnabledCipherSuites
(
list
);
}
socket
=
secureSocket
;
//## Java 1.4 end ##
return
socket
;
}
//## Java 1.4 begin ##
private
static
byte
[]
getKeyStoreBytes
(
KeyStore
store
,
String
password
)
throws
IOException
{
ByteArrayOutputStream
bout
=
new
ByteArrayOutputStream
();
try
{
store
.
store
(
bout
,
password
.
toCharArray
());
}
catch
(
Exception
e
)
{
throw
DbException
.
convertToIOException
(
e
);
}
return
bout
.
toByteArray
();
}
//## Java 1.4 end ##
/**
* Get the keystore object using the given password.
*
* @param password the keystore password
* @return the keystore
*/
//## Java 1.4 begin ##
public
static
KeyStore
getKeyStore
(
String
password
)
throws
IOException
{
try
{
// The following source code can be re-generated
// if you have a keystore file.
// This code is (hopefully) more Java version independent
// than using keystores directly. See also:
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4887561
// (1.4.2 cannot read keystore written with 1.4.1)
// --- generated code start ---
KeyStore
store
=
KeyStore
.
getInstance
(
KeyStore
.
getDefaultType
());
store
.
load
(
null
,
password
.
toCharArray
());
KeyFactory
keyFactory
=
KeyFactory
.
getInstance
(
"RSA"
);
store
.
load
(
null
,
password
.
toCharArray
());
PKCS8EncodedKeySpec
keySpec
=
new
PKCS8EncodedKeySpec
(
Utils
.
convertStringToBytes
(
"30820277020100300d06092a864886f70d0101010500048202613082025d02010002818100dc0a13c602b7141110eade2f051b54777b060d0f74e6a110f9cce81159f271ebc88d8e8aa1f743b505fc2e7dfe38d33b8d3f64d1b363d1af4d877833897954cbaec2fa384c22a415498cf306bb07ac09b76b001cd68bf77ea0a628f5101959cf2993a9c23dbee79b19305977f8715ae78d023471194cc900b231eecb0aaea98d02030100010281810099aa4ff4d0a09a5af0bd953cb10c4d08c3d98df565664ac5582e494314d5c3c92dddedd5d316a32a206be4ec084616fe57be15e27cad111aa3c21fa79e32258c6ca8430afc69eddd52d3b751b37da6b6860910b94653192c0db1d02abcfd6ce14c01f238eec7c20bd3bb750940004bacba2880349a9494d10e139ecb2355d101024100ffdc3defd9c05a2d377ef6019fa62b3fbd5b0020a04cc8533bca730e1f6fcf5dfceea1b044fbe17d9eababfbc7d955edad6bc60f9be826ad2c22ba77d19a9f65024100dc28d43fdbbc93852cc3567093157702bc16f156f709fb7db0d9eec028f41fd0edcd17224c866e66be1744141fb724a10fd741c8a96afdd9141b36d67fff6309024077b1cddbde0f69604bdcfe33263fb36ddf24aa3b9922327915b890f8a36648295d0139ecdf68c245652c4489c6257b58744fbdd961834a4cab201801a3b1e52d024100b17142e8991d1b350a0802624759d48ae2b8071a158ff91fabeb6a8f7c328e762143dc726b8529f42b1fab6220d1c676fdc27ba5d44e847c72c52064afd351a902407c6e23fe35bcfcd1a662aa82a2aa725fcece311644d5b6e3894853fd4ce9fe78218c957b1ff03fc9e5ef8ffeb6bd58235f6a215c97d354fdace7e781e4a63e8b"
));
PrivateKey
privateKey
=
keyFactory
.
generatePrivate
(
keySpec
);
Certificate
[]
certs
=
new
Certificate
[]
{
CertificateFactory
.
getInstance
(
"X.509"
)
.
generateCertificate
(
new
ByteArrayInputStream
(
Utils
.
convertStringToBytes
(
"3082018b3081f502044295ce6b300d06092a864886f70d0101040500300d310b3009060355040313024832301e170d3035303532363133323630335a170d3337303933303036353734375a300d310b300906035504031302483230819f300d06092a864886f70d010101050003818d0030818902818100dc0a13c602b7141110eade2f051b54777b060d0f74e6a110f9cce81159f271ebc88d8e8aa1f743b505fc2e7dfe38d33b8d3f64d1b363d1af4d877833897954cbaec2fa384c22a415498cf306bb07ac09b76b001cd68bf77ea0a628f5101959cf2993a9c23dbee79b19305977f8715ae78d023471194cc900b231eecb0aaea98d0203010001300d06092a864886f70d01010405000381810083f4401a279453701bef9a7681a5b8b24f153f7d18c7c892133d97bd5f13736be7505290a445a7d5ceb75522403e5097515cd966ded6351ff60d5193de34cd36e5cb04d380398e66286f99923fd92296645fd4ada45844d194dfd815e6cd57f385c117be982809028bba1116c85740b3d27a55b1a0948bf291ddba44bed337b9"
))),
};
store
.
setKeyEntry
(
"h2"
,
privateKey
,
password
.
toCharArray
(),
certs
);
// --- generated code end ---
return
store
;
}
catch
(
Exception
e
)
{
throw
DbException
.
convertToIOException
(
e
);
}
}
private
static
void
setKeystore
()
throws
IOException
{
Properties
p
=
System
.
getProperties
();
if
(
p
.
getProperty
(
KEYSTORE_KEY
)
==
null
)
{
String
fileName
=
IOUtils
.
getFileInUserHome
(
KEYSTORE
);
byte
[]
data
=
getKeyStoreBytes
(
getKeyStore
(
KEYSTORE_PASSWORD
),
KEYSTORE_PASSWORD
);
boolean
needWrite
=
true
;
if
(
IOUtils
.
exists
(
fileName
)
&&
IOUtils
.
length
(
fileName
)
==
data
.
length
)
{
// don't need to overwrite the file if it did not change
InputStream
fin
=
IOUtils
.
openFileInputStream
(
fileName
);
byte
[]
now
=
IOUtils
.
readBytesAndClose
(
fin
,
0
);
if
(
now
!=
null
&&
Utils
.
compareNotNull
(
data
,
now
)
==
0
)
{
needWrite
=
false
;
}
}
if
(
needWrite
)
{
try
{
OutputStream
out
=
IOUtils
.
openFileOutputStream
(
fileName
,
false
);
out
.
write
(
data
);
out
.
close
();
}
catch
(
Exception
e
)
{
throw
DbException
.
convertToIOException
(
e
);
}
}
String
absolutePath
=
IOUtils
.
getAbsolutePath
(
fileName
);
System
.
setProperty
(
KEYSTORE_KEY
,
absolutePath
);
}
if
(
p
.
getProperty
(
KEYSTORE_PASSWORD_KEY
)
==
null
)
{
System
.
setProperty
(
KEYSTORE_PASSWORD_KEY
,
KEYSTORE_PASSWORD
);
}
}
private
static
String
[]
addAnonymous
(
String
[]
list
)
{
String
[]
newList
=
new
String
[
list
.
length
+
1
];
System
.
arraycopy
(
list
,
0
,
newList
,
1
,
list
.
length
);
newList
[
0
]
=
ANONYMOUS_CIPHER_SUITE
;
return
newList
;
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/security/SecureSocketFactory.java
deleted
100644 → 0
浏览文件 @
798a5049
/*
* Copyright 2004-2010 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
.
security
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.net.InetAddress
;
import
java.net.InetSocketAddress
;
import
java.net.ServerSocket
;
import
java.net.Socket
;
import
java.security.KeyFactory
;
import
java.security.KeyStore
;
import
java.security.PrivateKey
;
import
java.security.cert.Certificate
;
import
java.security.cert.CertificateFactory
;
import
java.security.spec.PKCS8EncodedKeySpec
;
import
java.util.Properties
;
import
javax.net.ServerSocketFactory
;
import
javax.net.ssl.SSLServerSocket
;
import
javax.net.ssl.SSLServerSocketFactory
;
import
javax.net.ssl.SSLSocket
;
import
javax.net.ssl.SSLSocketFactory
;
import
org.h2.constant.SysProperties
;
import
org.h2.message.DbException
;
import
org.h2.util.Utils
;
import
org.h2.util.IOUtils
;
/**
* A factory to create encrypted sockets. To generate new keystore, use the
* SecureKeyStoreBuilder tool.
*/
public
class
SecureSocketFactory
{
/**
* The default password to use for the .h2.keystore file
*/
public
static
final
String
KEYSTORE_PASSWORD
=
"h2pass"
;
private
static
final
String
KEYSTORE
=
".h2.keystore"
;
private
static
final
String
KEYSTORE_KEY
=
"javax.net.ssl.keyStore"
;
private
static
final
String
KEYSTORE_PASSWORD_KEY
=
"javax.net.ssl.keyStorePassword"
;
private
static
final
String
ANONYMOUS_CIPHER_SUITE
=
"SSL_DH_anon_WITH_RC4_128_MD5"
;
private
SecureSocketFactory
()
{
// utility class
}
/**
* Create a secure client socket that is connected to the given address and port.
*
* @param address the address to connect to
* @param port the port
* @return the socket
*/
public
static
Socket
createSocket
(
InetAddress
address
,
int
port
)
throws
IOException
{
Socket
socket
=
null
;
//## Java 1.4 begin ##
setKeystore
();
SSLSocketFactory
f
=
(
SSLSocketFactory
)
SSLSocketFactory
.
getDefault
();
SSLSocket
secureSocket
=
(
SSLSocket
)
f
.
createSocket
();
secureSocket
.
connect
(
new
InetSocketAddress
(
address
,
port
),
SysProperties
.
SOCKET_CONNECT_TIMEOUT
);
if
(
SysProperties
.
ENABLE_ANONYMOUS_SSL
)
{
String
[]
list
=
secureSocket
.
getEnabledCipherSuites
();
list
=
addAnonymous
(
list
);
secureSocket
.
setEnabledCipherSuites
(
list
);
}
socket
=
secureSocket
;
//## Java 1.4 end ##
return
socket
;
}
/**
* Create a secure server socket. If a bind address is specified, the socket
* is only bound to this address.
*
* @param port the port to listen on
* @param bindAddress the address to bind to, or null to bind to all
* addresses
* @return the server socket
*/
public
static
ServerSocket
createServerSocket
(
int
port
,
InetAddress
bindAddress
)
throws
IOException
{
ServerSocket
socket
=
null
;
//## Java 1.4 begin ##
setKeystore
();
ServerSocketFactory
f
=
SSLServerSocketFactory
.
getDefault
();
SSLServerSocket
secureSocket
;
if
(
bindAddress
==
null
)
{
secureSocket
=
(
SSLServerSocket
)
f
.
createServerSocket
(
port
);
}
else
{
secureSocket
=
(
SSLServerSocket
)
f
.
createServerSocket
(
port
,
0
,
bindAddress
);
}
if
(
SysProperties
.
ENABLE_ANONYMOUS_SSL
)
{
String
[]
list
=
secureSocket
.
getEnabledCipherSuites
();
list
=
addAnonymous
(
list
);
secureSocket
.
setEnabledCipherSuites
(
list
);
}
socket
=
secureSocket
;
//## Java 1.4 end ##
return
socket
;
}
//## Java 1.4 begin ##
private
static
byte
[]
getBytes
(
String
hex
)
{
return
Utils
.
convertStringToBytes
(
hex
);
}
private
static
byte
[]
getKeyStoreBytes
(
KeyStore
store
,
String
password
)
throws
IOException
{
ByteArrayOutputStream
bout
=
new
ByteArrayOutputStream
();
try
{
store
.
store
(
bout
,
password
.
toCharArray
());
}
catch
(
Exception
e
)
{
throw
DbException
.
convertToIOException
(
e
);
}
return
bout
.
toByteArray
();
}
//## Java 1.4 end ##
/**
* Get the keystore object using the given password.
*
* @param password the keystore password
* @return the keystore
*/
//## Java 1.4 begin ##
public
static
KeyStore
getKeyStore
(
String
password
)
throws
IOException
{
try
{
// The following source code can be re-generated
// if you have a keystore file.
// This code is (hopefully) more Java version independent
// than using keystores directly. See also:
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4887561
// (1.4.2 cannot read keystore written with 1.4.1)
// --- generated code start ---
KeyStore
store
=
KeyStore
.
getInstance
(
KeyStore
.
getDefaultType
());
store
.
load
(
null
,
password
.
toCharArray
());
KeyFactory
keyFactory
=
KeyFactory
.
getInstance
(
"RSA"
);
store
.
load
(
null
,
password
.
toCharArray
());
PKCS8EncodedKeySpec
keySpec
=
new
PKCS8EncodedKeySpec
(
getBytes
(
"30820277020100300d06092a864886f70d0101010500048202613082025d02010002818100dc0a13c602b7141110eade2f051b54777b060d0f74e6a110f9cce81159f271ebc88d8e8aa1f743b505fc2e7dfe38d33b8d3f64d1b363d1af4d877833897954cbaec2fa384c22a415498cf306bb07ac09b76b001cd68bf77ea0a628f5101959cf2993a9c23dbee79b19305977f8715ae78d023471194cc900b231eecb0aaea98d02030100010281810099aa4ff4d0a09a5af0bd953cb10c4d08c3d98df565664ac5582e494314d5c3c92dddedd5d316a32a206be4ec084616fe57be15e27cad111aa3c21fa79e32258c6ca8430afc69eddd52d3b751b37da6b6860910b94653192c0db1d02abcfd6ce14c01f238eec7c20bd3bb750940004bacba2880349a9494d10e139ecb2355d101024100ffdc3defd9c05a2d377ef6019fa62b3fbd5b0020a04cc8533bca730e1f6fcf5dfceea1b044fbe17d9eababfbc7d955edad6bc60f9be826ad2c22ba77d19a9f65024100dc28d43fdbbc93852cc3567093157702bc16f156f709fb7db0d9eec028f41fd0edcd17224c866e66be1744141fb724a10fd741c8a96afdd9141b36d67fff6309024077b1cddbde0f69604bdcfe33263fb36ddf24aa3b9922327915b890f8a36648295d0139ecdf68c245652c4489c6257b58744fbdd961834a4cab201801a3b1e52d024100b17142e8991d1b350a0802624759d48ae2b8071a158ff91fabeb6a8f7c328e762143dc726b8529f42b1fab6220d1c676fdc27ba5d44e847c72c52064afd351a902407c6e23fe35bcfcd1a662aa82a2aa725fcece311644d5b6e3894853fd4ce9fe78218c957b1ff03fc9e5ef8ffeb6bd58235f6a215c97d354fdace7e781e4a63e8b"
));
PrivateKey
privateKey
=
keyFactory
.
generatePrivate
(
keySpec
);
Certificate
[]
certs
=
new
Certificate
[]
{
CertificateFactory
.
getInstance
(
"X.509"
)
.
generateCertificate
(
new
ByteArrayInputStream
(
getBytes
(
"3082018b3081f502044295ce6b300d06092a864886f70d0101040500300d310b3009060355040313024832301e170d3035303532363133323630335a170d3337303933303036353734375a300d310b300906035504031302483230819f300d06092a864886f70d010101050003818d0030818902818100dc0a13c602b7141110eade2f051b54777b060d0f74e6a110f9cce81159f271ebc88d8e8aa1f743b505fc2e7dfe38d33b8d3f64d1b363d1af4d877833897954cbaec2fa384c22a415498cf306bb07ac09b76b001cd68bf77ea0a628f5101959cf2993a9c23dbee79b19305977f8715ae78d023471194cc900b231eecb0aaea98d0203010001300d06092a864886f70d01010405000381810083f4401a279453701bef9a7681a5b8b24f153f7d18c7c892133d97bd5f13736be7505290a445a7d5ceb75522403e5097515cd966ded6351ff60d5193de34cd36e5cb04d380398e66286f99923fd92296645fd4ada45844d194dfd815e6cd57f385c117be982809028bba1116c85740b3d27a55b1a0948bf291ddba44bed337b9"
))),
};
store
.
setKeyEntry
(
"h2"
,
privateKey
,
password
.
toCharArray
(),
certs
);
// --- generated code end ---
return
store
;
}
catch
(
Exception
e
)
{
throw
DbException
.
convertToIOException
(
e
);
}
}
private
static
void
setKeystore
()
throws
IOException
{
Properties
p
=
System
.
getProperties
();
if
(
p
.
getProperty
(
KEYSTORE_KEY
)
==
null
)
{
String
fileName
=
IOUtils
.
getFileInUserHome
(
KEYSTORE
);
byte
[]
data
=
getKeyStoreBytes
(
getKeyStore
(
KEYSTORE_PASSWORD
),
KEYSTORE_PASSWORD
);
boolean
needWrite
=
true
;
if
(
IOUtils
.
exists
(
fileName
)
&&
IOUtils
.
length
(
fileName
)
==
data
.
length
)
{
// don't need to overwrite the file if it did not change
InputStream
fin
=
IOUtils
.
openFileInputStream
(
fileName
);
byte
[]
now
=
IOUtils
.
readBytesAndClose
(
fin
,
0
);
if
(
now
!=
null
&&
Utils
.
compareNotNull
(
data
,
now
)
==
0
)
{
needWrite
=
false
;
}
}
if
(
needWrite
)
{
try
{
OutputStream
out
=
IOUtils
.
openFileOutputStream
(
fileName
,
false
);
out
.
write
(
data
);
out
.
close
();
}
catch
(
Exception
e
)
{
throw
DbException
.
convertToIOException
(
e
);
}
}
String
absolutePath
=
IOUtils
.
getAbsolutePath
(
fileName
);
System
.
setProperty
(
KEYSTORE_KEY
,
absolutePath
);
}
if
(
p
.
getProperty
(
KEYSTORE_PASSWORD_KEY
)
==
null
)
{
System
.
setProperty
(
KEYSTORE_PASSWORD_KEY
,
KEYSTORE_PASSWORD
);
}
}
private
static
String
[]
addAnonymous
(
String
[]
list
)
{
String
[]
newList
=
new
String
[
list
.
length
+
1
];
System
.
arraycopy
(
list
,
0
,
newList
,
1
,
list
.
length
);
newList
[
0
]
=
ANONYMOUS_CIPHER_SUITE
;
return
newList
;
}
//## Java 1.4 end ##
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/store/FileStore.java
浏览文件 @
390b9472
...
...
@@ -448,8 +448,12 @@ public class FileStore {
* Call fsync. Depending on the operating system and hardware, this may or
* may not in fact write the changes.
*/
public
void
sync
()
throws
IOException
{
file
.
sync
();
public
void
sync
()
{
try
{
file
.
sync
();
}
catch
(
IOException
e
)
{
throw
DbException
.
convertIOException
(
e
,
name
);
}
}
/**
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/store/PageStore.java
浏览文件 @
390b9472
...
...
@@ -704,6 +704,18 @@ public class PageStore implements CacheWriter {
}
}
/**
* Flush the transaction log and sync the file.
*/
public
void
sync
()
{
if
(
file
!=
null
)
{
synchronized
(
database
)
{
log
.
flush
();
file
.
sync
();
}
}
}
public
Trace
getTrace
()
{
return
trace
;
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/tools/MultiDimension.java
浏览文件 @
390b9472
...
...
@@ -13,7 +13,6 @@ import java.util.ArrayList;
import
java.util.Collections
;
import
java.util.Comparator
;
import
org.h2.util.New
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
/**
...
...
@@ -146,49 +145,6 @@ public class MultiDimension implements Comparator<long[]> {
return
prep
.
executeQuery
();
}
/**
* Generates an optimized multi-dimensional range query.
* This query is database independent, however the performance is
* not as good as when using generatePreparedQuery
*
* @param table the table name
* @param columns the list of columns
* @param min the lower values
* @param max the upper values
* @param scalarColumn the column name of the computed scalar column
* @return the query
*/
public
String
generateQuery
(
String
table
,
String
scalarColumn
,
String
[]
columns
,
int
[]
min
,
int
[]
max
)
{
long
[][]
ranges
=
getMortonRanges
(
min
,
max
);
StatementBuilder
buff
=
new
StatementBuilder
(
"SELECT * FROM ("
);
for
(
long
[]
range
:
ranges
)
{
long
minScalar
=
range
[
0
];
long
maxScalar
=
range
[
1
];
buff
.
appendExceptFirst
(
" UNION ALL "
);
buff
.
append
(
"SELECT * FROM "
).
append
(
table
).
append
(
" WHERE "
).
append
(
scalarColumn
).
append
(
" BETWEEN "
).
append
(
minScalar
).
append
(
" AND "
).
append
(
maxScalar
);
}
buff
.
append
(
") WHERE "
);
int
i
=
0
;
buff
.
resetCount
();
for
(
String
col
:
columns
)
{
buff
.
appendExceptFirst
(
" AND "
);
buff
.
append
(
col
).
append
(
" BETWEEN "
).
append
(
min
[
i
]).
append
(
" AND "
).
append
(
max
[
i
]);
i
++;
}
return
buff
.
toString
();
}
/**
* Gets a list of ranges to be searched for a multi-dimensional range query
* where min <= value <= max. In most cases, the ranges will be larger
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/util/NetUtils.java
浏览文件 @
390b9472
...
...
@@ -17,7 +17,7 @@ import java.net.UnknownHostException;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
import
org.h2.message.DbException
;
import
org.h2.security.
SecureSocket
Factory
;
import
org.h2.security.
Cipher
Factory
;
/**
* This utility class contains socket helper functions.
...
...
@@ -103,7 +103,7 @@ public class NetUtils {
for
(
int
i
=
0
;;
i
++)
{
try
{
if
(
ssl
)
{
return
SecureSocket
Factory
.
createSocket
(
address
,
port
);
return
Cipher
Factory
.
createSocket
(
address
,
port
);
}
Socket
socket
=
new
Socket
();
socket
.
connect
(
new
InetSocketAddress
(
address
,
port
),
...
...
@@ -165,7 +165,7 @@ public class NetUtils {
try
{
InetAddress
bindAddress
=
getBindAddress
();
if
(
ssl
)
{
return
SecureSocket
Factory
.
createServerSocket
(
port
,
bindAddress
);
return
Cipher
Factory
.
createServerSocket
(
port
,
bindAddress
);
}
if
(
bindAddress
==
null
)
{
return
new
ServerSocket
(
port
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
390b9472
...
...
@@ -263,6 +263,11 @@ java org.h2.test.TestAll timer
*/
boolean
stopOnError
;
/**
* The cache type.
*/
String
cacheType
;
private
Server
server
;
/**
...
...
@@ -286,10 +291,10 @@ java org.h2.test.TestAll timer
System
.
setProperty
(
"h2.check2"
,
"true"
);
/*
implement FileStore.sync, Database.sync() (CHECKPOINT SYNC)
try to replace 'catch Exception' with 'catch DbException'
try again with -verbose:classes
rename Page* classes
move classes to the right packages
test Row.getMemorySize
remove CipherFactory
document in performance section:
PreparedStatement prep = conn.prepareStatement(
...
...
@@ -416,6 +421,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
deleteIndex
=
true
;
traceLevelFile
=
3
;
throttle
=
1
;
cacheType
=
"SOFT_LRU"
;
cipher
=
"XTEA"
;
test
();
...
...
@@ -424,6 +430,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
deleteIndex
=
false
;
traceLevelFile
=
1
;
throttle
=
0
;
cacheType
=
null
;
cipher
=
null
;
test
();
...
...
@@ -672,6 +679,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
appendIf
(
buff
,
codeCoverage
,
"codeCoverage"
);
appendIf
(
buff
,
mvcc
,
"mvcc"
);
appendIf
(
buff
,
cipher
!=
null
,
cipher
);
appendIf
(
buff
,
cacheType
!=
null
,
cacheType
);
appendIf
(
buff
,
jdk14
,
"jdk14"
);
appendIf
(
buff
,
smallLog
,
"smallLog"
);
appendIf
(
buff
,
ssl
,
"ssl"
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/TestBase.java
浏览文件 @
390b9472
...
...
@@ -264,6 +264,9 @@ public abstract class TestBase {
if
(
config
.
mvcc
&&
url
.
indexOf
(
"MVCC="
)
<
0
)
{
url
+=
";MVCC=TRUE"
;
}
if
(
config
.
cacheType
!=
null
&&
admin
&&
url
.
indexOf
(
"CACHE_TYPE="
)
<
0
)
{
url
+=
";CACHE_TYPE="
+
config
.
cacheType
;
}
if
(
config
.
diskResult
&&
admin
)
{
url
+=
";MAX_MEMORY_ROWS=100;CACHE_SIZE=0"
;
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/bench/Database.java
浏览文件 @
390b9472
...
...
@@ -101,7 +101,12 @@ class Database {
Thread
.
sleep
(
100
);
}
else
if
(
url
.
startsWith
(
"jdbc:hsqldb:hsql:"
))
{
if
(!
serverHSQLDB
)
{
Class
<
?
>
c
=
Class
.
forName
(
"org.hsqldb.Server"
);
Class
<
?
>
c
;
try
{
c
=
Class
.
forName
(
"org.hsqldb.server.Server"
);
}
catch
(
Exception
e
)
{
c
=
Class
.
forName
(
"org.hsqldb.Server"
);
}
Method
m
=
c
.
getMethod
(
"main"
,
String
[].
class
);
m
.
invoke
(
null
,
new
Object
[]
{
new
String
[]
{
"-database.0"
,
"data/mydb;hsqldb.default_table_type=cached"
,
"-dbname.0"
,
"xdb"
}
});
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestIndex.java
浏览文件 @
390b9472
...
...
@@ -11,10 +11,12 @@ import java.sql.PreparedStatement;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.HashMap
;
import
java.util.Random
;
import
org.h2.result.SortOrder
;
import
org.h2.test.TestBase
;
import
org.h2.util.New
;
/**
* Index tests.
...
...
@@ -36,6 +38,7 @@ public class TestIndex extends TestBase {
public
void
test
()
throws
SQLException
{
deleteDb
(
"index"
);
testNonUniqueHashIndex
();
testRenamePrimaryKey
();
testRandomized
();
testDescIndex
();
...
...
@@ -84,6 +87,41 @@ public class TestIndex extends TestBase {
deleteDb
(
"index"
);
}
private
void
testNonUniqueHashIndex
()
throws
SQLException
{
reconnect
();
stat
.
execute
(
"create memory table test(id bigint, data bigint)"
);
stat
.
execute
(
"create hash index on test(id)"
);
Random
rand
=
new
Random
(
1
);
PreparedStatement
prepInsert
=
conn
.
prepareStatement
(
"insert into test values(?, ?)"
);
PreparedStatement
prepDelete
=
conn
.
prepareStatement
(
"delete from test where id=?"
);
PreparedStatement
prepSelect
=
conn
.
prepareStatement
(
"select count(*) from test where id=?"
);
HashMap
<
Long
,
Integer
>
map
=
New
.
hashMap
();
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
long
key
=
rand
.
nextInt
(
10
)
*
1000000000L
;
Integer
r
=
map
.
get
(
key
);
int
result
=
r
==
null
?
0
:
(
int
)
r
;
if
(
rand
.
nextBoolean
())
{
prepSelect
.
setLong
(
1
,
key
);
ResultSet
rs
=
prepSelect
.
executeQuery
();
rs
.
next
();
assertEquals
(
result
,
rs
.
getInt
(
1
));
}
else
{
if
(
rand
.
nextBoolean
())
{
prepInsert
.
setLong
(
1
,
key
);
prepInsert
.
setInt
(
2
,
rand
.
nextInt
());
prepInsert
.
execute
();
map
.
put
(
key
,
result
+
1
);
}
else
{
prepDelete
.
setLong
(
1
,
key
);
prepDelete
.
execute
();
map
.
put
(
key
,
0
);
}
}
}
stat
.
execute
(
"drop table test"
);
conn
.
close
();
}
private
void
testRenamePrimaryKey
()
throws
SQLException
{
if
(
config
.
memory
)
{
return
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestMultiDimension.java
浏览文件 @
390b9472
...
...
@@ -113,33 +113,6 @@ public class TestMultiDimension extends TestBase {
}
assertFalse
(
rs2
.
next
());
}
trace
(
"multi: "
+
timeMulti
+
" regular: "
+
timeRegular
);
for
(
int
i
=
0
;
i
<
50
;
i
++)
{
int
size
=
rand
.
nextInt
(
max
/
10
);
int
minX
=
rand
.
nextInt
(
max
-
size
);
int
minY
=
rand
.
nextInt
(
max
-
size
);
int
minZ
=
rand
.
nextInt
(
max
-
size
);
int
maxX
=
minX
+
size
,
maxY
=
minY
+
size
,
maxZ
=
minZ
+
size
;
long
time1
=
System
.
currentTimeMillis
();
String
query1
=
MultiDimension
.
getInstance
().
generateQuery
(
"TEST"
,
"XYZ"
,
new
String
[]
{
"X"
,
"Y"
,
"Z"
},
new
int
[]
{
minX
,
minY
,
minZ
},
new
int
[]
{
minX
+
size
,
minY
+
size
,
minZ
+
size
});
ResultSet
rs1
=
conn
.
createStatement
().
executeQuery
(
query1
+
" ORDER BY X, Y, Z"
);
time1
=
System
.
currentTimeMillis
()
-
time1
;
long
time2
=
System
.
currentTimeMillis
();
String
query2
=
"SELECT * FROM TEST WHERE "
+
"X BETWEEN "
+
minX
+
" AND "
+
maxX
+
" AND "
+
"Y BETWEEN "
+
minY
+
" AND "
+
maxY
+
" AND "
+
"Z BETWEEN "
+
minZ
+
" AND "
+
maxZ
;
PreparedStatement
prep2
=
conn
.
prepareStatement
(
query2
+
" ORDER BY X, Y, Z"
);
ResultSet
rs2
=
prep2
.
executeQuery
();
time2
=
System
.
currentTimeMillis
()
-
time2
;
while
(
rs1
.
next
())
{
assertTrue
(
rs2
.
next
());
assertEquals
(
rs1
.
getInt
(
1
),
rs2
.
getInt
(
1
));
assertEquals
(
rs1
.
getInt
(
2
),
rs2
.
getInt
(
2
));
}
assertFalse
(
rs2
.
next
());
// it just has to work, no need to compare the performance
// trace("t1="+time1+" t2="+time2+" size="+size);
}
conn
.
close
();
deleteDb
(
"multiDimension"
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestPgServer.java
浏览文件 @
390b9472
...
...
@@ -61,6 +61,14 @@ public class TestPgServer extends TestBase {
conn
.
close
();
conn
=
DriverManager
.
getConnection
(
"jdbc:postgresql://localhost:5535/test"
,
"sa"
,
"sa"
);
stat
=
conn
.
createStatement
();
ResultSet
rs
;
stat
.
execute
(
"prepare test(int, int) as select ?1*?2"
);
rs
=
stat
.
executeQuery
(
"execute test(3, 2)"
);
rs
.
next
();
assertEquals
(
6
,
rs
.
getInt
(
1
));
stat
.
execute
(
"deallocate test"
);
stat
.
execute
(
"create table test(id int primary key, name varchar)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"insert into test values(?, ?)"
);
ParameterMetaData
meta
=
prep
.
getParameterMetaData
();
...
...
@@ -68,7 +76,7 @@ public class TestPgServer extends TestBase {
prep
.
setInt
(
1
,
1
);
prep
.
setString
(
2
,
"Hello"
);
prep
.
execute
();
ResultSet
rs
=
stat
.
executeQuery
(
"select * from test"
);
rs
=
stat
.
executeQuery
(
"select * from test"
);
rs
.
next
();
ResultSetMetaData
rsMeta
=
rs
.
getMetaData
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/dev/security/SecureKeyStoreBuilder.java
浏览文件 @
390b9472
...
...
@@ -15,7 +15,7 @@ import java.security.cert.Certificate;
import
java.security.cert.CertificateEncodingException
;
import
java.util.Enumeration
;
import
org.h2.security.
SecureSocket
Factory
;
import
org.h2.security.
Cipher
Factory
;
import
org.h2.util.Utils
;
/**
...
...
@@ -41,8 +41,8 @@ public class SecureKeyStoreBuilder {
* @param args the command line parameters
*/
public
static
void
main
(
String
...
args
)
throws
Exception
{
String
password
=
SecureSocket
Factory
.
KEYSTORE_PASSWORD
;
KeyStore
store
=
SecureSocket
Factory
.
getKeyStore
(
password
);
String
password
=
Cipher
Factory
.
KEYSTORE_PASSWORD
;
KeyStore
store
=
Cipher
Factory
.
getKeyStore
(
password
);
printKeystore
(
store
,
password
);
}
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论