Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
1196666c
提交
1196666c
authored
6月 25, 2013
作者:
noelgrandin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add support for spatial datatype GEOMETRY.
上级
9a883bad
显示空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
307 行增加
和
9 行删除
+307
-9
help.csv
h2/src/docsrc/help/help.csv
+12
-0
changelog.html
h2/src/docsrc/html/changelog.html
+1
-0
Data.java
h2/src/main/org/h2/store/Data.java
+23
-0
DataType.java
h2/src/main/org/h2/value/DataType.java
+18
-1
Value.java
h2/src/main/org/h2/value/Value.java
+16
-1
ValueGeometry.java
h2/src/main/org/h2/value/ValueGeometry.java
+162
-0
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+9
-7
TestSpatial.java
h2/src/test/org/h2/test/db/TestSpatial.java
+64
-0
Build.java
h2/src/tools/org/h2/build/Build.java
+2
-0
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
1196666c
...
...
@@ -2335,6 +2335,18 @@ and ""ResultSet.getObject(..)"" or ""ResultSet.getArray(..)"" to retrieve the va
ARRAY
"
"Data Types","GEOMETRY Type","
GEOMETRY
","
A spatial geometry type, based on the com.vividsolutions.jts library.
Normally represented in textual format using the WKT (Well Known Text) format.
Use a quoted string containing a KWB formatted string or ""PreparedStatement.setObject()"" to store values,
and ""ResultSet.getObject(..)"" or ""ResultSet.getString(..)"" to retrieve the values.
","
ARRAY
"
"Functions (Aggregate)","AVG","
AVG ( [ DISTINCT ] { numeric } )
","
...
...
h2/src/docsrc/html/changelog.html
浏览文件 @
1196666c
...
...
@@ -42,6 +42,7 @@ Change Log
</li><li>
Issue 479: Support for SUBSTRING without a FROM condition, patch from Andrew Franklin.
</li><li>
Issue 472: PgServer does not work with any recent Postgres JDBC driver, patch from Andrew Franklin.
</li><li>
Add syntax for passing additional parameters into custom TableEngine implementations.
</li><li>
Add support for spatial datatype GEOMETRY.
</li></ul>
<h2>
Version 1.3.172 (2013-05-25)
</h2>
...
...
h2/src/main/org/h2/store/Data.java
浏览文件 @
1196666c
...
...
@@ -38,6 +38,7 @@ import org.h2.value.ValueDate;
import
org.h2.value.ValueDecimal
;
import
org.h2.value.ValueDouble
;
import
org.h2.value.ValueFloat
;
import
org.h2.value.ValueGeometry
;
import
org.h2.value.ValueInt
;
import
org.h2.value.ValueJavaObject
;
import
org.h2.value.ValueLob
;
...
...
@@ -670,6 +671,20 @@ public class Data {
}
break
;
}
case
Value
.
GEOMETRY
:
{
writeByte
((
byte
)
type
);
byte
[]
b
=
v
.
getBytes
();
int
len
=
b
.
length
;
if
(
len
<
32
)
{
writeByte
((
byte
)
(
BYTES_0_31
+
len
));
write
(
b
,
0
,
b
.
length
);
}
else
{
writeByte
((
byte
)
type
);
writeVarInt
(
b
.
length
);
write
(
b
,
0
,
b
.
length
);
}
break
;
}
default
:
DbException
.
throwInternalError
(
"type="
+
v
.
getType
());
}
...
...
@@ -1074,6 +1089,14 @@ public class Data {
}
return
len
;
}
case
Value
.
GEOMETRY
:
{
byte
[]
b
=
v
.
getBytesNoCopy
();
int
len
=
b
.
length
;
if
(
len
<
32
)
{
return
1
+
b
.
length
;
}
return
1
+
getVarIntLen
(
b
.
length
)
+
b
.
length
;
}
default
:
throw
DbException
.
throwInternalError
(
"type="
+
v
.
getType
());
}
...
...
h2/src/main/org/h2/value/DataType.java
浏览文件 @
1196666c
...
...
@@ -22,7 +22,6 @@ import java.sql.Types;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.UUID
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
import
org.h2.engine.Constants
;
...
...
@@ -323,6 +322,11 @@ public class DataType {
// 80 for ValueLob, 24 for String
104
);
add
(
Value
.
GEOMETRY
,
Types
.
OTHER
,
"Geometry"
,
createString
(
false
),
new
String
[]{
"GEOMETRY"
},
32
);
DataType
dataType
=
new
DataType
();
dataType
.
prefix
=
"("
;
dataType
.
suffix
=
"')"
;
...
...
@@ -594,6 +598,13 @@ public class DataType {
}
return
ValueResultSet
.
get
(
rs
);
}
case
Value
.
GEOMETRY
:
{
com
.
vividsolutions
.
jts
.
geom
.
Geometry
x
=
(
com
.
vividsolutions
.
jts
.
geom
.
Geometry
)
rs
.
getObject
(
columnIndex
);
if
(
x
==
null
)
{
return
ValueNull
.
INSTANCE
;
}
return
ValueGeometry
.
get
(
x
);
}
default
:
throw
DbException
.
throwInternalError
(
"type="
+
type
);
}
...
...
@@ -671,6 +682,8 @@ public class DataType {
return
Array
.
class
.
getName
();
case
Value
.
RESULT_SET
:
return
ResultSet
.
class
.
getName
();
case
Value
.
GEOMETRY
:
return
com
.
vividsolutions
.
jts
.
geom
.
Geometry
.
class
.
getName
();
default
:
throw
DbException
.
throwInternalError
(
"type="
+
type
);
}
...
...
@@ -832,6 +845,8 @@ public class DataType {
}
else
if
(
Object
[].
class
.
isAssignableFrom
(
x
))
{
// this includes String[] and so on
return
Value
.
ARRAY
;
}
else
if
(
com
.
vividsolutions
.
jts
.
geom
.
Geometry
.
class
.
isAssignableFrom
(
x
))
{
return
Value
.
GEOMETRY
;
}
else
{
return
Value
.
JAVA_OBJECT
;
}
...
...
@@ -920,6 +935,8 @@ public class DataType {
return
ValueArray
.
get
(
x
.
getClass
().
getComponentType
(),
v
);
}
else
if
(
x
instanceof
Character
)
{
return
ValueStringFixed
.
get
(((
Character
)
x
).
toString
());
}
else
if
(
x
instanceof
com
.
vividsolutions
.
jts
.
geom
.
Geometry
)
{
return
ValueGeometry
.
get
((
com
.
vividsolutions
.
jts
.
geom
.
Geometry
)
x
);
}
else
{
return
ValueJavaObject
.
getNoCopy
(
x
,
null
);
}
...
...
h2/src/main/org/h2/value/Value.java
浏览文件 @
1196666c
...
...
@@ -151,10 +151,15 @@ public abstract class Value {
*/
public
static
final
int
STRING_FIXED
=
21
;
/**
* The value type for string values with a fixed size.
*/
public
static
final
int
GEOMETRY
=
22
;
/**
* The number of value types.
*/
public
static
final
int
TYPE_COUNT
=
STRING_FIXED
+
1
;
public
static
final
int
TYPE_COUNT
=
GEOMETRY
+
1
;
private
static
SoftReference
<
Value
[]>
softCache
=
new
SoftReference
<
Value
[]>(
null
);
private
static
final
BigDecimal
MAX_LONG_DECIMAL
=
BigDecimal
.
valueOf
(
Long
.
MAX_VALUE
);
...
...
@@ -294,6 +299,8 @@ public abstract class Value {
return
42
;
case
JAVA_OBJECT:
return
43
;
case
GEOMETRY:
return
44
;
case
ARRAY:
return
50
;
case
RESULT_SET:
...
...
@@ -725,6 +732,7 @@ public abstract class Value {
case
BLOB:
return
ValueBytes
.
getNoCopy
(
getBytesNoCopy
());
case
UUID:
case
GEOMETRY:
return
ValueBytes
.
getNoCopy
(
getBytes
());
case
BYTE:
return
ValueBytes
.
getNoCopy
(
new
byte
[]{
getByte
()});
...
...
@@ -781,6 +789,11 @@ public abstract class Value {
return
ValueUuid
.
get
(
getBytesNoCopy
());
}
}
case
GEOMETRY:
switch
(
getType
())
{
case
BYTES:
return
ValueGeometry
.
get
(
getBytesNoCopy
());
}
}
// conversion by parsing the string value
String
s
=
getString
();
...
...
@@ -847,6 +860,8 @@ public abstract class Value {
}
case
UUID:
return
ValueUuid
.
get
(
s
);
case
GEOMETRY:
return
ValueGeometry
.
get
(
s
);
default
:
throw
DbException
.
throwInternalError
(
"type="
+
targetType
);
}
...
...
h2/src/main/org/h2/value/ValueGeometry.java
0 → 100644
浏览文件 @
1196666c
/*
* Copyright 2004-2013 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
.
value
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
org.h2.message.DbException
;
import
com.vividsolutions.jts.io.ParseException
;
import
com.vividsolutions.jts.io.WKBReader
;
import
com.vividsolutions.jts.io.WKBWriter
;
import
com.vividsolutions.jts.io.WKTReader
;
import
com.vividsolutions.jts.io.WKTWriter
;
/**
* Implementation of the GEOMETRY data type.
*/
public
class
ValueGeometry
extends
Value
{
/**
* The value.
*/
private
final
com
.
vividsolutions
.
jts
.
geom
.
Geometry
geometry
;
private
ValueGeometry
(
com
.
vividsolutions
.
jts
.
geom
.
Geometry
geometry
)
{
this
.
geometry
=
geometry
;
}
/**
* Get or create a geometry value for the given geometry.
*
* @param g the geometry
* @return the value
*/
public
static
ValueGeometry
get
(
com
.
vividsolutions
.
jts
.
geom
.
Geometry
g
)
{
return
(
ValueGeometry
)
Value
.
cache
(
new
ValueGeometry
(
g
));
}
/**
* Get or create a geometry value for the given geometry.
*
* @param s the WKT representation of the geometry
* @return the value
*/
public
static
ValueGeometry
get
(
String
s
)
{
return
(
ValueGeometry
)
Value
.
cache
(
new
ValueGeometry
(
fromWKT
(
s
)));
}
/**
* Get or create a geometry value for the given geometry.
*
* @param bytes the WKB representation of the geometry
* @return the value
*/
public
static
ValueGeometry
get
(
byte
[]
bytes
)
{
return
(
ValueGeometry
)
Value
.
cache
(
new
ValueGeometry
(
fromWKB
(
bytes
)));
}
@Override
public
int
getType
()
{
return
Value
.
GEOMETRY
;
}
@Override
public
String
getSQL
()
{
return
"'"
+
toWKT
()
+
"'"
;
}
@Override
protected
int
compareSecure
(
Value
v
,
CompareMode
mode
)
{
com
.
vividsolutions
.
jts
.
geom
.
Geometry
g
=
((
ValueGeometry
)
v
).
geometry
;
return
this
.
geometry
.
compareTo
(
g
);
}
@Override
public
String
getString
()
{
return
toWKT
();
}
@Override
public
long
getPrecision
()
{
return
toWKT
().
length
();
}
@Override
public
int
hashCode
()
{
return
this
.
geometry
.
hashCode
();
}
@Override
public
Object
getObject
()
{
return
geometry
;
}
@Override
public
byte
[]
getBytes
()
{
return
toWKB
();
}
@Override
public
void
set
(
PreparedStatement
prep
,
int
parameterIndex
)
throws
SQLException
{
prep
.
setObject
(
parameterIndex
,
geometry
);
}
@Override
public
int
getDisplaySize
()
{
return
toWKT
().
length
();
}
@Override
public
int
getMemory
()
{
return
toWKB
().
length
+
24
;
}
@Override
public
boolean
equals
(
Object
other
)
{
return
other
instanceof
ValueGeometry
&&
geometry
.
equals
(((
ValueGeometry
)
other
).
geometry
);
}
/**
* Convert to Well-Known-Text format.
*/
public
String
toWKT
()
{
WKTWriter
w
=
new
WKTWriter
();
return
w
.
write
(
this
.
geometry
);
}
/**
* Convert to Well-Known-Binary format.
*/
public
byte
[]
toWKB
()
{
WKBWriter
w
=
new
WKBWriter
();
return
w
.
write
(
this
.
geometry
);
}
/**
* Convert from Well-Known-Text format.
*/
private
static
com
.
vividsolutions
.
jts
.
geom
.
Geometry
fromWKT
(
String
s
)
{
WKTReader
r
=
new
WKTReader
();
try
{
return
r
.
read
(
s
);
}
catch
(
ParseException
ex
)
{
throw
DbException
.
convert
(
ex
);
}
}
/**
* Convert from Well-Known-Binary format.
*/
private
static
com
.
vividsolutions
.
jts
.
geom
.
Geometry
fromWKB
(
byte
[]
bytes
)
{
WKBReader
r
=
new
WKBReader
();
try
{
return
r
.
read
(
bytes
);
}
catch
(
ParseException
ex
)
{
throw
DbException
.
convert
(
ex
);
}
}
}
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
1196666c
...
...
@@ -63,6 +63,7 @@ import org.h2.test.db.TestSequence;
import
org.h2.test.db.TestSessionsLocks
;
import
org.h2.test.db.TestShow
;
import
org.h2.test.db.TestSpaceReuse
;
import
org.h2.test.db.TestSpatial
;
import
org.h2.test.db.TestSpeed
;
import
org.h2.test.db.TestTableEngines
;
import
org.h2.test.db.TestTempTables
;
...
...
@@ -106,16 +107,16 @@ import org.h2.test.mvcc.TestMvcc3;
import
org.h2.test.mvcc.TestMvccMultiThreaded
;
import
org.h2.test.rowlock.TestRowLocks
;
import
org.h2.test.server.TestAutoServer
;
import
org.h2.test.server.TestInit
;
import
org.h2.test.server.TestNestedLoop
;
import
org.h2.test.server.TestWeb
;
import
org.h2.test.server.TestInit
;
import
org.h2.test.store.TestCacheConcurrentLIRS
;
import
org.h2.test.store.TestCacheLIRS
;
import
org.h2.test.store.TestCacheLongKeyLIRS
;
import
org.h2.test.store.TestConcurrent
;
import
org.h2.test.store.TestDataUtils
;
import
org.h2.test.store.TestMVStore
;
import
org.h2.test.store.TestMVRTree
;
import
org.h2.test.store.TestMVStore
;
import
org.h2.test.store.TestMVTableEngine
;
import
org.h2.test.store.TestObjectDataType
;
import
org.h2.test.store.TestSpinLock
;
...
...
@@ -159,12 +160,10 @@ import org.h2.test.unit.TestFtp;
import
org.h2.test.unit.TestIntArray
;
import
org.h2.test.unit.TestIntIntHashMap
;
import
org.h2.test.unit.TestJmx
;
import
org.h2.test.unit.TestModifyOnWrite
;
import
org.h2.test.unit.TestObjectDeserialization
;
import
org.h2.test.unit.TestSort
;
import
org.h2.test.unit.TestTraceSystem
;
import
org.h2.test.unit.TestMathUtils
;
import
org.h2.test.unit.TestModifyOnWrite
;
import
org.h2.test.unit.TestNetUtils
;
import
org.h2.test.unit.TestObjectDeserialization
;
import
org.h2.test.unit.TestOldVersion
;
import
org.h2.test.unit.TestOverflow
;
import
org.h2.test.unit.TestPageStore
;
...
...
@@ -178,10 +177,12 @@ import org.h2.test.unit.TestSampleApps;
import
org.h2.test.unit.TestScriptReader
;
import
org.h2.test.unit.TestSecurity
;
import
org.h2.test.unit.TestShell
;
import
org.h2.test.unit.TestSort
;
import
org.h2.test.unit.TestStreams
;
import
org.h2.test.unit.TestStringCache
;
import
org.h2.test.unit.TestStringUtils
;
import
org.h2.test.unit.TestTools
;
import
org.h2.test.unit.TestTraceSystem
;
import
org.h2.test.unit.TestUtils
;
import
org.h2.test.unit.TestValue
;
import
org.h2.test.unit.TestValueHashMap
;
...
...
@@ -191,8 +192,8 @@ import org.h2.test.utils.SelfDestructor;
import
org.h2.tools.DeleteDbFiles
;
import
org.h2.tools.Server
;
import
org.h2.util.Profiler
;
import
org.h2.util.Utils
;
import
org.h2.util.StringUtils
;
import
org.h2.util.Utils
;
/**
* The main test application. JUnit is not used because loops are easier to
...
...
@@ -621,6 +622,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
new
TestSequence
().
runTest
(
this
);
new
TestShow
().
runTest
(
this
);
new
TestSpaceReuse
().
runTest
(
this
);
new
TestSpatial
().
runTest
(
this
);
new
TestSpeed
().
runTest
(
this
);
new
TestTableEngines
().
runTest
(
this
);
new
TestTempTables
().
runTest
(
this
);
...
...
h2/src/test/org/h2/test/db/TestSpatial.java
0 → 100644
浏览文件 @
1196666c
/*
* Copyright 2004-2013 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
.
test
.
db
;
import
java.sql.Connection
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
org.h2.test.TestBase
;
import
com.vividsolutions.jts.geom.Coordinate
;
import
com.vividsolutions.jts.geom.GeometryFactory
;
import
com.vividsolutions.jts.geom.Polygon
;
/**
* Spatial datatype and index tests.
*/
public
class
TestSpatial
extends
TestBase
{
/**
* Run just this test.
*
* @param a ignored
*/
public
static
void
main
(
String
...
a
)
throws
Exception
{
TestBase
.
createCaller
().
init
().
test
();
}
@Override
public
void
test
()
throws
SQLException
{
deleteDb
(
"spatial"
);
testSpatialValues
();
deleteDb
(
"spatial"
);
}
private
void
testSpatialValues
()
throws
SQLException
{
deleteDb
(
"spatial"
);
Connection
conn
=
getConnection
(
"spatial"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create memory table test(id int primary key, poly geometry)"
);
stat
.
execute
(
"insert into test values(1, 'POLYGON ((1 1, 1 2, 2 2, 1 1))')"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select * from test"
);
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
1
));
assertEquals
(
"POLYGON ((1 1, 1 2, 2 2, 1 1))"
,
rs
.
getString
(
2
));
GeometryFactory
f
=
new
GeometryFactory
();
Polygon
poly
=
f
.
createPolygon
(
new
Coordinate
[]
{
new
Coordinate
(
1
,
1
),
new
Coordinate
(
1
,
2
),
new
Coordinate
(
2
,
2
),
new
Coordinate
(
1
,
1
)
});
assertTrue
(
poly
.
equals
(
rs
.
getObject
(
2
)));
rs
=
stat
.
executeQuery
(
"select * from test where poly = 'POLYGON ((1 1, 1 2, 2 2, 1 1))'"
);
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
1
));
stat
.
executeQuery
(
"select * from test where poly > 'POLYGON ((1 1, 1 2, 2 2, 1 1))'"
);
stat
.
executeQuery
(
"select * from test where poly < 'POLYGON ((1 1, 1 2, 2 2, 1 1))'"
);
stat
.
execute
(
"drop table test"
);
conn
.
close
();
deleteDb
(
"spatial"
);
}
}
h2/src/tools/org/h2/build/Build.java
浏览文件 @
1196666c
...
...
@@ -273,6 +273,8 @@ public class Build extends BuildBase {
"66ab449ff3aa5c4adfc82c89025cc983b422eb95"
,
offline
);
downloadOrVerify
(
"ext/org.osgi.enterprise-4.2.0.jar"
,
"org/osgi"
,
"org.osgi.enterprise"
,
"4.2.0"
,
"8634dcb0fc62196e820ed0f1062993c377f74972"
,
offline
);
downloadOrVerify
(
"ext/jts-1.13.jar"
,
"com.vividsolutions"
,
"jts"
,
"1.13"
,
"3ccfb9b60f04d71add996a666ceb8902904fd805"
,
offline
);
}
private
void
downloadOrVerify
(
String
target
,
String
group
,
String
artifact
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论