Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
e5b577fa
提交
e5b577fa
authored
11月 02, 2015
作者:
S.Vladykin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
RowFactory added
上级
84fd6dae
隐藏空白字符变更
内嵌
并排
正在显示
25 个修改的文件
包含
329 行增加
和
194 行删除
+329
-194
Database.java
h2/src/main/org/h2/engine/Database.java
+21
-1
Session.java
h2/src/main/org/h2/engine/Session.java
+5
-2
UndoLogRecord.java
h2/src/main/org/h2/engine/UndoLogRecord.java
+1
-1
FunctionCursor.java
h2/src/main/org/h2/index/FunctionCursor.java
+5
-2
FunctionCursorResultSet.java
h2/src/main/org/h2/index/FunctionCursorResultSet.java
+1
-1
FunctionIndex.java
h2/src/main/org/h2/index/FunctionIndex.java
+1
-1
PageDataLeaf.java
h2/src/main/org/h2/index/PageDataLeaf.java
+2
-3
RangeCursor.java
h2/src/main/org/h2/index/RangeCursor.java
+7
-4
RangeIndex.java
h2/src/main/org/h2/index/RangeIndex.java
+2
-2
ScanIndex.java
h2/src/main/org/h2/index/ScanIndex.java
+1
-1
MVPrimaryIndex.java
h2/src/main/org/h2/mvstore/db/MVPrimaryIndex.java
+9
-7
ResultTempTable.java
h2/src/main/org/h2/result/ResultTempTable.java
+1
-1
Row.java
h2/src/main/org/h2/result/Row.java
+46
-137
RowFactory.java
h2/src/main/org/h2/result/RowFactory.java
+29
-0
RowImpl.java
h2/src/main/org/h2/result/RowImpl.java
+174
-0
RowList.java
h2/src/main/org/h2/result/RowList.java
+1
-1
PageLog.java
h2/src/main/org/h2/store/PageLog.java
+5
-4
MetaTable.java
h2/src/main/org/h2/table/MetaTable.java
+1
-1
RegularTable.java
h2/src/main/org/h2/table/RegularTable.java
+0
-10
Table.java
h2/src/main/org/h2/table/Table.java
+2
-2
Recover.java
h2/src/main/org/h2/tools/Recover.java
+2
-1
JdbcUtils.java
h2/src/main/org/h2/util/JdbcUtils.java
+5
-6
TestTableEngines.java
h2/src/test/org/h2/test/db/TestTableEngines.java
+2
-1
TestPageStore.java
h2/src/test/org/h2/test/unit/TestPageStore.java
+4
-3
MemoryFootprint.java
h2/src/test/org/h2/test/utils/MemoryFootprint.java
+2
-2
没有找到文件。
h2/src/main/org/h2/engine/Database.java
浏览文件 @
e5b577fa
...
...
@@ -31,6 +31,7 @@ import org.h2.message.Trace;
import
org.h2.message.TraceSystem
;
import
org.h2.mvstore.db.MVTableEngine
;
import
org.h2.result.Row
;
import
org.h2.result.RowFactory
;
import
org.h2.result.SearchRow
;
import
org.h2.schema.Schema
;
import
org.h2.schema.SchemaObject
;
...
...
@@ -191,6 +192,7 @@ public class Database implements DataHandler {
private
boolean
queryStatistics
;
private
int
queryStatisticsMaxEntries
=
Constants
.
QUERY_STATISTICS_MAX_ENTRIES
;
private
QueryStatisticsData
queryStatisticsData
;
private
final
RowFactory
rowFactory
;
public
Database
(
ConnectionInfo
ci
,
String
cipher
)
{
String
name
=
ci
.
getName
();
...
...
@@ -249,7 +251,17 @@ public class Database implements DataHandler {
ci
.
getProperty
(
"JAVA_OBJECT_SERIALIZER"
,
null
);
this
.
multiThreaded
=
ci
.
getProperty
(
"MULTI_THREADED"
,
false
);
String
rowFactoryClassName
=
ci
.
getProperty
(
"ROW_FACTORY"
);
if
(
rowFactoryClassName
!=
null
)
{
Class
<
RowFactory
>
rowFactoryClass
=
JdbcUtils
.
loadUserClass
(
rowFactoryClassName
);
try
{
rowFactory
=
rowFactoryClass
.
newInstance
();
}
catch
(
Exception
e
)
{
throw
DbException
.
convert
(
e
);
}
}
else
{
rowFactory
=
RowFactory
.
DEFAULT
;
}
boolean
closeAtVmShutdown
=
dbSettings
.
dbCloseOnExit
;
int
traceLevelFile
=
...
...
@@ -301,6 +313,14 @@ public class Database implements DataHandler {
}
}
public
Row
createRow
(
Value
[]
data
,
int
memory
)
{
return
rowFactory
.
createRow
(
data
,
memory
);
}
public
RowFactory
getRowFactory
()
{
return
rowFactory
;
}
public
static
void
setInitialPowerOffCount
(
int
count
)
{
initialPowerOffCount
=
count
;
}
...
...
h2/src/main/org/h2/engine/Session.java
浏览文件 @
e5b577fa
...
...
@@ -11,7 +11,6 @@ import java.util.HashSet;
import
java.util.Iterator
;
import
java.util.LinkedList
;
import
java.util.Random
;
import
org.h2.api.ErrorCode
;
import
org.h2.command.Command
;
import
org.h2.command.CommandInterface
;
...
...
@@ -142,6 +141,10 @@ public class Session extends SessionWithState {
this
.
currentSchemaName
=
Constants
.
SCHEMA_MAIN
;
}
public
Row
createRow
(
Value
[]
data
,
int
memory
)
{
return
database
.
createRow
(
data
,
memory
);
}
@Override
public
ArrayList
<
String
>
getClusterServers
()
{
return
new
ArrayList
<
String
>();
...
...
@@ -650,7 +653,7 @@ public class Session extends SessionWithState {
row
=
t
.
getRow
(
this
,
key
);
}
else
{
op
=
UndoLogRecord
.
DELETE
;
row
=
new
Row
(
value
.
getList
(),
Row
.
MEMORY_CALCULATE
);
row
=
create
Row
(
value
.
getList
(),
Row
.
MEMORY_CALCULATE
);
}
row
.
setKey
(
key
);
UndoLogRecord
log
=
new
UndoLogRecord
(
t
,
op
,
row
);
...
...
h2/src/main/org/h2/engine/UndoLogRecord.java
浏览文件 @
e5b577fa
...
...
@@ -221,7 +221,7 @@ public class UndoLogRecord {
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
values
[
i
]
=
buff
.
readValue
();
}
row
=
new
Row
(
values
,
Row
.
MEMORY_CALCULATE
);
row
=
getTable
().
getDatabase
().
create
Row
(
values
,
Row
.
MEMORY_CALCULATE
);
row
.
setKey
(
key
);
row
.
setDeleted
(
deleted
);
row
.
setSessionId
(
sessionId
);
...
...
h2/src/main/org/h2/index/FunctionCursor.java
浏览文件 @
e5b577fa
...
...
@@ -5,6 +5,7 @@
*/
package
org
.
h2
.
index
;
import
org.h2.engine.Session
;
import
org.h2.message.DbException
;
import
org.h2.result.ResultInterface
;
import
org.h2.result.Row
;
...
...
@@ -16,11 +17,13 @@ import org.h2.value.Value;
*/
public
class
FunctionCursor
implements
Cursor
{
private
Session
session
;
private
final
ResultInterface
result
;
private
Value
[]
values
;
private
Row
row
;
FunctionCursor
(
ResultInterface
result
)
{
FunctionCursor
(
Session
session
,
ResultInterface
result
)
{
this
.
session
=
session
;
this
.
result
=
result
;
}
...
...
@@ -30,7 +33,7 @@ public class FunctionCursor implements Cursor {
return
null
;
}
if
(
row
==
null
)
{
row
=
new
Row
(
values
,
1
);
row
=
session
.
create
Row
(
values
,
1
);
}
return
row
;
}
...
...
h2/src/main/org/h2/index/FunctionCursorResultSet.java
浏览文件 @
e5b577fa
...
...
@@ -42,7 +42,7 @@ public class FunctionCursorResultSet implements Cursor {
return
null
;
}
if
(
row
==
null
)
{
row
=
new
Row
(
values
,
1
);
row
=
session
.
create
Row
(
values
,
1
);
}
return
row
;
}
...
...
h2/src/main/org/h2/index/FunctionIndex.java
浏览文件 @
e5b577fa
...
...
@@ -45,7 +45,7 @@ public class FunctionIndex extends BaseIndex {
@Override
public
Cursor
find
(
Session
session
,
SearchRow
first
,
SearchRow
last
)
{
if
(
functionTable
.
isBufferResultSetToLocalTemp
())
{
return
new
FunctionCursor
(
functionTable
.
getResult
(
session
));
return
new
FunctionCursor
(
session
,
functionTable
.
getResult
(
session
));
}
return
new
FunctionCursorResultSet
(
session
,
functionTable
.
getResultSet
(
session
));
...
...
h2/src/main/org/h2/index/PageDataLeaf.java
浏览文件 @
e5b577fa
...
...
@@ -17,7 +17,6 @@ import org.h2.result.Row;
import
org.h2.store.Data
;
import
org.h2.store.Page
;
import
org.h2.store.PageStore
;
import
org.h2.table.RegularTable
;
import
org.h2.value.Value
;
/**
...
...
@@ -617,7 +616,7 @@ public class PageDataLeaf extends PageData {
* @param columnCount the number of columns
* @return the row
*/
private
static
Row
readRow
(
Data
data
,
int
pos
,
int
columnCount
)
{
private
Row
readRow
(
Data
data
,
int
pos
,
int
columnCount
)
{
Value
[]
values
=
new
Value
[
columnCount
];
synchronized
(
data
)
{
data
.
setPos
(
pos
);
...
...
@@ -625,7 +624,7 @@ public class PageDataLeaf extends PageData {
values
[
i
]
=
data
.
readValue
();
}
}
return
RegularTable
.
createRow
(
values
);
return
index
.
getDatabase
().
createRow
(
values
,
Row
.
MEMORY_CALCULATE
);
}
}
h2/src/main/org/h2/index/RangeCursor.java
浏览文件 @
e5b577fa
...
...
@@ -5,6 +5,7 @@
*/
package
org
.
h2
.
index
;
import
org.h2.engine.Session
;
import
org.h2.message.DbException
;
import
org.h2.result.Row
;
import
org.h2.result.SearchRow
;
...
...
@@ -16,16 +17,18 @@ import org.h2.value.ValueLong;
*/
class
RangeCursor
implements
Cursor
{
private
Session
session
;
private
boolean
beforeFirst
;
private
long
current
;
private
Row
currentRow
;
private
final
long
start
,
end
,
step
;
RangeCursor
(
long
start
,
long
end
)
{
this
(
start
,
end
,
1
);
RangeCursor
(
Session
session
,
long
start
,
long
end
)
{
this
(
s
ession
,
s
tart
,
end
,
1
);
}
RangeCursor
(
long
start
,
long
end
,
long
step
)
{
RangeCursor
(
Session
session
,
long
start
,
long
end
,
long
step
)
{
this
.
session
=
session
;
this
.
start
=
start
;
this
.
end
=
end
;
this
.
step
=
step
;
...
...
@@ -50,7 +53,7 @@ class RangeCursor implements Cursor {
}
else
{
current
+=
step
;
}
currentRow
=
new
Row
(
new
Value
[]{
ValueLong
.
get
(
current
)},
1
);
currentRow
=
session
.
create
Row
(
new
Value
[]{
ValueLong
.
get
(
current
)},
1
);
return
step
>
0
?
current
<=
end
:
current
>=
end
;
}
...
...
h2/src/main/org/h2/index/RangeIndex.java
浏览文件 @
e5b577fa
...
...
@@ -58,7 +58,7 @@ public class RangeIndex extends BaseIndex {
}
catch
(
Exception
e
)
{
// error when converting the value - ignore
}
return
new
RangeCursor
(
start
,
end
,
step
);
return
new
RangeCursor
(
s
ession
,
s
tart
,
end
,
step
);
}
@Override
...
...
@@ -100,7 +100,7 @@ public class RangeIndex extends BaseIndex {
@Override
public
Cursor
findFirstOrLast
(
Session
session
,
boolean
first
)
{
long
pos
=
first
?
rangeTable
.
getMin
(
session
)
:
rangeTable
.
getMax
(
session
);
return
new
RangeCursor
(
pos
,
pos
);
return
new
RangeCursor
(
session
,
pos
,
pos
);
}
@Override
...
...
h2/src/main/org/h2/index/ScanIndex.java
浏览文件 @
e5b577fa
...
...
@@ -143,7 +143,7 @@ public class ScanIndex extends BaseIndex {
rows
=
New
.
arrayList
();
firstFree
=
-
1
;
}
else
{
Row
free
=
new
Row
(
null
,
1
);
Row
free
=
session
.
create
Row
(
null
,
1
);
free
.
setKey
(
firstFree
);
long
key
=
row
.
getKey
();
if
(
rows
.
size
()
<=
key
)
{
...
...
h2/src/main/org/h2/mvstore/db/MVPrimaryIndex.java
浏览文件 @
e5b577fa
...
...
@@ -197,7 +197,7 @@ public class MVPrimaryIndex extends BaseIndex {
}
}
TransactionMap
<
Value
,
Value
>
map
=
getMap
(
session
);
return
new
MVStoreCursor
(
map
.
entryIterator
(
min
),
max
);
return
new
MVStoreCursor
(
session
,
map
.
entryIterator
(
min
),
max
);
}
@Override
...
...
@@ -210,7 +210,7 @@ public class MVPrimaryIndex extends BaseIndex {
TransactionMap
<
Value
,
Value
>
map
=
getMap
(
session
);
Value
v
=
map
.
get
(
ValueLong
.
get
(
key
));
ValueArray
array
=
(
ValueArray
)
v
;
Row
row
=
new
Row
(
array
.
getList
(),
0
);
Row
row
=
session
.
create
Row
(
array
.
getList
(),
0
);
row
.
setKey
(
key
);
return
row
;
}
...
...
@@ -260,14 +260,14 @@ public class MVPrimaryIndex extends BaseIndex {
TransactionMap
<
Value
,
Value
>
map
=
getMap
(
session
);
ValueLong
v
=
(
ValueLong
)
(
first
?
map
.
firstKey
()
:
map
.
lastKey
());
if
(
v
==
null
)
{
return
new
MVStoreCursor
(
Collections
return
new
MVStoreCursor
(
session
,
Collections
.<
Entry
<
Value
,
Value
>>
emptyList
().
iterator
(),
null
);
}
Value
value
=
map
.
get
(
v
);
Entry
<
Value
,
Value
>
e
=
new
DataUtils
.
MapEntry
<
Value
,
Value
>(
v
,
value
);
@SuppressWarnings
(
"unchecked"
)
List
<
Entry
<
Value
,
Value
>>
list
=
Arrays
.
asList
(
e
);
MVStoreCursor
c
=
new
MVStoreCursor
(
list
.
iterator
(),
v
);
MVStoreCursor
c
=
new
MVStoreCursor
(
session
,
list
.
iterator
(),
v
);
c
.
next
();
return
c
;
}
...
...
@@ -347,7 +347,7 @@ public class MVPrimaryIndex extends BaseIndex {
*/
Cursor
find
(
Session
session
,
ValueLong
first
,
ValueLong
last
)
{
TransactionMap
<
Value
,
Value
>
map
=
getMap
(
session
);
return
new
MVStoreCursor
(
map
.
entryIterator
(
first
),
last
);
return
new
MVStoreCursor
(
session
,
map
.
entryIterator
(
first
),
last
);
}
@Override
...
...
@@ -374,12 +374,14 @@ public class MVPrimaryIndex extends BaseIndex {
*/
class
MVStoreCursor
implements
Cursor
{
private
final
Session
session
;
private
final
Iterator
<
Entry
<
Value
,
Value
>>
it
;
private
final
ValueLong
last
;
private
Entry
<
Value
,
Value
>
current
;
private
Row
row
;
public
MVStoreCursor
(
Iterator
<
Entry
<
Value
,
Value
>>
it
,
ValueLong
last
)
{
public
MVStoreCursor
(
Session
session
,
Iterator
<
Entry
<
Value
,
Value
>>
it
,
ValueLong
last
)
{
this
.
session
=
session
;
this
.
it
=
it
;
this
.
last
=
last
;
}
...
...
@@ -389,7 +391,7 @@ public class MVPrimaryIndex extends BaseIndex {
if
(
row
==
null
)
{
if
(
current
!=
null
)
{
ValueArray
array
=
(
ValueArray
)
current
.
getValue
();
row
=
new
Row
(
array
.
getList
(),
0
);
row
=
session
.
create
Row
(
array
.
getList
(),
0
);
row
.
setKey
(
current
.
getKey
().
getLong
());
}
}
...
...
h2/src/main/org/h2/result/ResultTempTable.java
浏览文件 @
e5b577fa
...
...
@@ -288,7 +288,7 @@ public class ResultTempTable implements ResultExternal {
}
values
=
v2
;
}
return
new
Row
(
values
,
Row
.
MEMORY_CALCULATE
);
return
session
.
create
Row
(
values
,
Row
.
MEMORY_CALCULATE
);
}
private
Cursor
find
(
Row
row
)
{
...
...
h2/src/main/org/h2/result/Row.java
浏览文件 @
e5b577fa
...
...
@@ -5,77 +5,31 @@
*/
package
org
.
h2
.
result
;
import
org.h2.engine.Constants
;
import
org.h2.store.Data
;
import
org.h2.util.StatementBuilder
;
import
org.h2.value.Value
;
import
org.h2.value.ValueLong
;
/**
* Represents a row in a table.
*/
public
class
Row
implements
SearchRow
{
public
abstract
class
Row
implements
SearchRow
{
public
static
final
int
MEMORY_CALCULATE
=
-
1
;
public
static
final
Row
[]
EMPTY_ARRAY
=
{};
private
long
key
;
private
final
Value
[]
data
;
private
int
memory
;
private
int
version
;
private
boolean
deleted
;
private
int
sessionId
;
public
Row
(
Value
[]
data
,
int
memory
)
{
this
.
data
=
data
;
this
.
memory
=
memory
;
}
/**
* Get a copy of the row that is distinct from (not equal to) this row.
* This is used for FOR UPDATE to allow pseudo-updating a row.
*
* @return a new row with the same data
*/
public
Row
getCopy
()
{
Value
[]
d2
=
new
Value
[
data
.
length
];
System
.
arraycopy
(
data
,
0
,
d2
,
0
,
data
.
length
);
Row
r2
=
new
Row
(
d2
,
memory
);
r2
.
key
=
key
;
r2
.
version
=
version
+
1
;
r2
.
sessionId
=
sessionId
;
return
r2
;
}
@Override
public
void
setKeyAndVersion
(
SearchRow
row
)
{
setKey
(
row
.
getKey
());
setVersion
(
row
.
getVersion
());
}
@Override
public
int
getVersion
()
{
return
version
;
}
public
void
setVersion
(
int
version
)
{
this
.
version
=
version
;
}
public
abstract
Row
getCopy
();
@Override
public
long
getKey
()
{
return
key
;
}
@Override
public
void
setKey
(
long
key
)
{
this
.
key
=
key
;
}
@Override
public
Value
getValue
(
int
i
)
{
return
i
==
-
1
?
ValueLong
.
get
(
key
)
:
data
[
i
];
}
/**
* Set version.
*
* @param version row version
*/
public
abstract
void
setVersion
(
int
version
);
/**
* Get the number of bytes required for the data.
...
...
@@ -83,97 +37,52 @@ public class Row implements SearchRow {
* @param dummy the template buffer
* @return the number of bytes
*/
public
int
getByteCount
(
Data
dummy
)
{
int
size
=
0
;
for
(
Value
v
:
data
)
{
size
+=
dummy
.
getValueLen
(
v
);
}
return
size
;
}
@Override
public
void
setValue
(
int
i
,
Value
v
)
{
if
(
i
==
-
1
)
{
this
.
key
=
v
.
getLong
();
}
else
{
data
[
i
]
=
v
;
}
}
public
boolean
isEmpty
()
{
return
data
==
null
;
}
@Override
public
int
getColumnCount
()
{
return
data
.
length
;
}
public
abstract
int
getByteCount
(
Data
dummy
);
@Override
public
int
getMemory
()
{
if
(
memory
!=
MEMORY_CALCULATE
)
{
return
memory
;
}
int
m
=
Constants
.
MEMORY_ROW
;
if
(
data
!=
null
)
{
int
len
=
data
.
length
;
m
+=
Constants
.
MEMORY_OBJECT
+
len
*
Constants
.
MEMORY_POINTER
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
Value
v
=
data
[
i
];
if
(
v
!=
null
)
{
m
+=
v
.
getMemory
();
}
}
}
this
.
memory
=
m
;
return
m
;
}
@Override
public
String
toString
()
{
StatementBuilder
buff
=
new
StatementBuilder
(
"( /* key:"
);
buff
.
append
(
getKey
());
if
(
version
!=
0
)
{
buff
.
append
(
" v:"
+
version
);
}
if
(
isDeleted
())
{
buff
.
append
(
" deleted"
);
}
buff
.
append
(
" */ "
);
if
(
data
!=
null
)
{
for
(
Value
v
:
data
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
v
==
null
?
"null"
:
v
.
getTraceSQL
());
}
}
return
buff
.
append
(
')'
).
toString
();
}
/**
* Check if this is an empty row.
*
* @return {@code true} if the row is empty
*/
public
abstract
boolean
isEmpty
();
public
void
setDeleted
(
boolean
deleted
)
{
this
.
deleted
=
deleted
;
}
/**
* Mark the row as deleted.
*
* @param deleted deleted flag
*/
public
abstract
void
setDeleted
(
boolean
deleted
);
public
void
setSessionId
(
int
sessionId
)
{
this
.
sessionId
=
sessionId
;
}
/**
* Set session id.
*
* @param sessionId the session id
*/
public
abstract
void
setSessionId
(
int
sessionId
);
public
int
getSessionId
()
{
return
sessionId
;
}
/**
* Get session id.
*
* @return the session id
*/
public
abstract
int
getSessionId
();
/**
* This record has been committed. The session id is reset.
*/
public
void
commit
()
{
this
.
sessionId
=
0
;
}
public
boolean
isDeleted
()
{
return
deleted
;
}
public
abstract
void
commit
();
public
Value
[]
getValueList
()
{
return
data
;
}
/**
* Check if the row is deleted.
*
* @return {@code true} if the row is deleted
*/
public
abstract
boolean
isDeleted
();
/**
* Get values.
*
* @return values
*/
public
abstract
Value
[]
getValueList
();
}
h2/src/main/org/h2/result/RowFactory.java
0 → 100644
浏览文件 @
e5b577fa
package
org
.
h2
.
result
;
import
org.h2.value.Value
;
/**
* Creates rows.
*
* @author Sergi Vladykin
*/
public
interface
RowFactory
{
/**
* Default implementation of row factory.
*/
RowFactory
DEFAULT
=
new
RowFactory
()
{
@Override
public
Row
createRow
(
Value
[]
data
,
int
memory
)
{
return
new
RowImpl
(
data
,
memory
);
}
};
/**
* Create new row.
*
* @param data row values
* @param memory memory
* @return created row
*/
Row
createRow
(
Value
[]
data
,
int
memory
);
}
h2/src/main/org/h2/result/RowImpl.java
0 → 100644
浏览文件 @
e5b577fa
/*
* Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
result
;
import
org.h2.engine.Constants
;
import
org.h2.store.Data
;
import
org.h2.util.StatementBuilder
;
import
org.h2.value.Value
;
import
org.h2.value.ValueLong
;
/**
* Default row implementation.
*/
public
class
RowImpl
extends
Row
{
private
long
key
;
private
final
Value
[]
data
;
private
int
memory
;
private
int
version
;
private
boolean
deleted
;
private
int
sessionId
;
public
RowImpl
(
Value
[]
data
,
int
memory
)
{
this
.
data
=
data
;
this
.
memory
=
memory
;
}
/**
* Get a copy of the row that is distinct from (not equal to) this row.
* This is used for FOR UPDATE to allow pseudo-updating a row.
*
* @return a new row with the same data
*/
public
Row
getCopy
()
{
Value
[]
d2
=
new
Value
[
data
.
length
];
System
.
arraycopy
(
data
,
0
,
d2
,
0
,
data
.
length
);
RowImpl
r2
=
new
RowImpl
(
d2
,
memory
);
r2
.
key
=
key
;
r2
.
version
=
version
+
1
;
r2
.
sessionId
=
sessionId
;
return
r2
;
}
@Override
public
void
setKeyAndVersion
(
SearchRow
row
)
{
setKey
(
row
.
getKey
());
setVersion
(
row
.
getVersion
());
}
@Override
public
int
getVersion
()
{
return
version
;
}
public
void
setVersion
(
int
version
)
{
this
.
version
=
version
;
}
@Override
public
long
getKey
()
{
return
key
;
}
@Override
public
void
setKey
(
long
key
)
{
this
.
key
=
key
;
}
@Override
public
Value
getValue
(
int
i
)
{
return
i
==
-
1
?
ValueLong
.
get
(
key
)
:
data
[
i
];
}
/**
* Get the number of bytes required for the data.
*
* @param dummy the template buffer
* @return the number of bytes
*/
public
int
getByteCount
(
Data
dummy
)
{
int
size
=
0
;
for
(
Value
v
:
data
)
{
size
+=
dummy
.
getValueLen
(
v
);
}
return
size
;
}
@Override
public
void
setValue
(
int
i
,
Value
v
)
{
if
(
i
==
-
1
)
{
this
.
key
=
v
.
getLong
();
}
else
{
data
[
i
]
=
v
;
}
}
public
boolean
isEmpty
()
{
return
data
==
null
;
}
@Override
public
int
getColumnCount
()
{
return
data
.
length
;
}
@Override
public
int
getMemory
()
{
if
(
memory
!=
MEMORY_CALCULATE
)
{
return
memory
;
}
int
m
=
Constants
.
MEMORY_ROW
;
if
(
data
!=
null
)
{
int
len
=
data
.
length
;
m
+=
Constants
.
MEMORY_OBJECT
+
len
*
Constants
.
MEMORY_POINTER
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
Value
v
=
data
[
i
];
if
(
v
!=
null
)
{
m
+=
v
.
getMemory
();
}
}
}
this
.
memory
=
m
;
return
m
;
}
@Override
public
String
toString
()
{
StatementBuilder
buff
=
new
StatementBuilder
(
"( /* key:"
);
buff
.
append
(
getKey
());
if
(
version
!=
0
)
{
buff
.
append
(
" v:"
+
version
);
}
if
(
isDeleted
())
{
buff
.
append
(
" deleted"
);
}
buff
.
append
(
" */ "
);
if
(
data
!=
null
)
{
for
(
Value
v
:
data
)
{
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
v
==
null
?
"null"
:
v
.
getTraceSQL
());
}
}
return
buff
.
append
(
')'
).
toString
();
}
public
void
setDeleted
(
boolean
deleted
)
{
this
.
deleted
=
deleted
;
}
public
void
setSessionId
(
int
sessionId
)
{
this
.
sessionId
=
sessionId
;
}
public
int
getSessionId
()
{
return
sessionId
;
}
/**
* This record has been committed. The session id is reset.
*/
public
void
commit
()
{
this
.
sessionId
=
0
;
}
public
boolean
isDeleted
()
{
return
deleted
;
}
public
Value
[]
getValueList
()
{
return
data
;
}
}
h2/src/main/org/h2/result/RowList.java
浏览文件 @
e5b577fa
...
...
@@ -191,7 +191,7 @@ public class RowList {
}
values
[
i
]
=
v
;
}
Row
row
=
new
Row
(
values
,
mem
);
Row
row
=
session
.
create
Row
(
values
,
mem
);
row
.
setKey
(
key
);
row
.
setVersion
(
version
);
row
.
setDeleted
(
deleted
);
...
...
h2/src/main/org/h2/store/PageLog.java
浏览文件 @
e5b577fa
...
...
@@ -9,7 +9,6 @@ import java.io.IOException;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
org.h2.api.ErrorCode
;
import
org.h2.compress.CompressLZF
;
import
org.h2.engine.Session
;
...
...
@@ -17,6 +16,7 @@ import org.h2.engine.SysProperties;
import
org.h2.message.DbException
;
import
org.h2.message.Trace
;
import
org.h2.result.Row
;
import
org.h2.result.RowFactory
;
import
org.h2.util.BitField
;
import
org.h2.util.IntArray
;
import
org.h2.util.IntIntHashMap
;
...
...
@@ -316,7 +316,7 @@ public class PageLog {
}
else
if
(
x
==
ADD
)
{
int
sessionId
=
in
.
readVarInt
();
int
tableId
=
in
.
readVarInt
();
Row
row
=
readRow
(
in
,
data
);
Row
row
=
readRow
(
store
.
getDatabase
().
getRowFactory
(),
in
,
data
);
if
(
stage
==
RECOVERY_STAGE_UNDO
)
{
store
.
allocateIfIndexRoot
(
pos
,
tableId
,
row
);
}
else
if
(
stage
==
RECOVERY_STAGE_REDO
)
{
...
...
@@ -452,11 +452,12 @@ public class PageLog {
/**
* Read a row from an input stream.
*
* @param rowFactory the row factory
* @param in the input stream
* @param data a temporary buffer
* @return the row
*/
public
static
Row
readRow
(
DataReader
in
,
Data
data
)
throws
IOException
{
public
static
Row
readRow
(
RowFactory
rowFactory
,
DataReader
in
,
Data
data
)
throws
IOException
{
long
key
=
in
.
readVarLong
();
int
len
=
in
.
readVarInt
();
data
.
reset
();
...
...
@@ -467,7 +468,7 @@ public class PageLog {
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
values
[
i
]
=
data
.
readValue
();
}
Row
row
=
new
Row
(
values
,
Row
.
MEMORY_CALCULATE
);
Row
row
=
rowFactory
.
create
Row
(
values
,
Row
.
MEMORY_CALCULATE
);
row
.
setKey
(
key
);
return
row
;
}
...
...
h2/src/main/org/h2/table/MetaTable.java
浏览文件 @
e5b577fa
...
...
@@ -1978,7 +1978,7 @@ public class MetaTable extends Table {
v
=
col
.
convert
(
v
);
values
[
i
]
=
v
;
}
Row
row
=
new
Row
(
values
,
1
);
Row
row
=
database
.
create
Row
(
values
,
1
);
row
.
setKey
(
rows
.
size
());
rows
.
add
(
row
);
}
...
...
h2/src/main/org/h2/table/RegularTable.java
浏览文件 @
e5b577fa
...
...
@@ -681,16 +681,6 @@ public class RegularTable extends TableBase {
}
}
/**
* Create a row from the values.
*
* @param data the value list
* @return the row
*/
public
static
Row
createRow
(
Value
[]
data
)
{
return
new
Row
(
data
,
Row
.
MEMORY_CALCULATE
);
}
/**
* Set the row count of this table.
*
...
...
h2/src/main/org/h2/table/Table.java
浏览文件 @
e5b577fa
...
...
@@ -601,7 +601,7 @@ public abstract class Table extends SchemaObjectBase {
}
public
Row
getTemplateRow
()
{
return
new
Row
(
new
Value
[
columns
.
length
],
Row
.
MEMORY_CALCULATE
);
return
database
.
create
Row
(
new
Value
[
columns
.
length
],
Row
.
MEMORY_CALCULATE
);
}
/**
...
...
@@ -623,7 +623,7 @@ public abstract class Table extends SchemaObjectBase {
// Here can be concurrently produced more than one row, but it must be ok.
Value
[]
values
=
new
Value
[
columns
.
length
];
Arrays
.
fill
(
values
,
ValueNull
.
INSTANCE
);
nullRow
=
row
=
new
Row
(
values
,
1
);
nullRow
=
row
=
database
.
create
Row
(
values
,
1
);
}
return
row
;
}
...
...
h2/src/main/org/h2/tools/Recover.java
浏览文件 @
e5b577fa
...
...
@@ -44,6 +44,7 @@ import org.h2.mvstore.db.TransactionStore;
import
org.h2.mvstore.db.TransactionStore.TransactionMap
;
import
org.h2.mvstore.db.ValueDataType
;
import
org.h2.result.Row
;
import
org.h2.result.RowFactory
;
import
org.h2.result.SimpleRow
;
import
org.h2.security.SHA256
;
import
org.h2.store.Data
;
...
...
@@ -948,7 +949,7 @@ public class Recover extends Tool implements DataHandler {
}
else
if
(
x
==
PageLog
.
ADD
)
{
int
sessionId
=
in
.
readVarInt
();
setStorage
(
in
.
readVarInt
());
Row
row
=
PageLog
.
readRow
(
in
,
s
);
Row
row
=
PageLog
.
readRow
(
RowFactory
.
DEFAULT
,
in
,
s
);
writer
.
println
(
"-- session "
+
sessionId
+
" table "
+
storageId
+
" + "
+
row
.
toString
());
...
...
h2/src/main/org/h2/util/JdbcUtils.java
浏览文件 @
e5b577fa
...
...
@@ -19,10 +19,8 @@ import java.sql.Statement;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.Properties
;
import
javax.naming.Context
;
import
javax.sql.DataSource
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.JavaObjectSerializer
;
import
org.h2.engine.SysProperties
;
...
...
@@ -129,7 +127,8 @@ public class JdbcUtils {
* @param className the name of the class
* @return the class object
*/
public
static
Class
<?>
loadUserClass
(
String
className
)
{
@SuppressWarnings
(
"unchecked"
)
public
static
<
Z
>
Class
<
Z
>
loadUserClass
(
String
className
)
{
if
(
allowedClassNames
==
null
)
{
// initialize the static fields
String
s
=
SysProperties
.
ALLOWED_CLASSES
;
...
...
@@ -168,7 +167,7 @@ public class JdbcUtils {
try
{
Class
<?>
userClass
=
classFactory
.
loadClass
(
className
);
if
(!(
userClass
==
null
))
{
return
userClass
;
return
(
Class
<
Z
>)
userClass
;
}
}
catch
(
Exception
e
)
{
throw
DbException
.
get
(
...
...
@@ -178,10 +177,10 @@ public class JdbcUtils {
}
// Use local ClassLoader
try
{
return
Class
.
forName
(
className
);
return
(
Class
<
Z
>)
Class
.
forName
(
className
);
}
catch
(
ClassNotFoundException
e
)
{
try
{
return
Class
.
forName
(
return
(
Class
<
Z
>)
Class
.
forName
(
className
,
true
,
Thread
.
currentThread
().
getContextClassLoader
());
}
catch
(
Exception
e2
)
{
...
...
h2/src/test/org/h2/test/db/TestTableEngines.java
浏览文件 @
e5b577fa
...
...
@@ -836,7 +836,8 @@ public class TestTableEngines extends TestBase {
EndlessTable
(
CreateTableData
data
)
{
super
(
data
);
row
=
new
Row
(
new
Value
[]
{
ValueInt
.
get
(
1
),
ValueNull
.
INSTANCE
},
0
);
row
=
data
.
schema
.
getDatabase
().
createRow
(
new
Value
[]
{
ValueInt
.
get
(
1
),
ValueNull
.
INSTANCE
},
0
);
scanIndex
=
new
Auto
(
this
);
}
...
...
h2/src/test/org/h2/test/unit/TestPageStore.java
浏览文件 @
e5b577fa
...
...
@@ -20,6 +20,7 @@ import java.util.TreeSet;
import
org.h2.api.DatabaseEventListener
;
import
org.h2.api.ErrorCode
;
import
org.h2.result.Row
;
import
org.h2.result.RowImpl
;
import
org.h2.store.Page
;
import
org.h2.store.fs.FileUtils
;
import
org.h2.test.TestBase
;
...
...
@@ -272,14 +273,14 @@ public class TestPageStore extends TestBase {
private
void
testInsertDelete
()
{
Row
[]
x
=
new
Row
[
0
];
Row
r
=
new
Row
(
null
,
0
);
Row
r
=
new
Row
Impl
(
null
,
0
);
x
=
Page
.
insert
(
x
,
0
,
0
,
r
);
assertTrue
(
x
[
0
]
==
r
);
Row
r2
=
new
Row
(
null
,
0
);
Row
r2
=
new
Row
Impl
(
null
,
0
);
x
=
Page
.
insert
(
x
,
1
,
0
,
r2
);
assertTrue
(
x
[
0
]
==
r2
);
assertTrue
(
x
[
1
]
==
r
);
Row
r3
=
new
Row
(
null
,
0
);
Row
r3
=
new
Row
Impl
(
null
,
0
);
x
=
Page
.
insert
(
x
,
2
,
1
,
r3
);
assertTrue
(
x
[
0
]
==
r2
);
assertTrue
(
x
[
1
]
==
r3
);
...
...
h2/src/test/org/h2/test/utils/MemoryFootprint.java
浏览文件 @
e5b577fa
...
...
@@ -9,7 +9,7 @@ import java.lang.instrument.Instrumentation;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
org.h2.engine.Constants
;
import
org.h2.result.Row
;
import
org.h2.result.Row
Impl
;
import
org.h2.store.Data
;
import
org.h2.util.Profiler
;
import
org.h2.value.Value
;
...
...
@@ -34,7 +34,7 @@ public class MemoryFootprint {
print
(
"BigInteger"
,
new
BigInteger
(
"0"
));
print
(
"String"
,
new
String
(
"Hello"
));
print
(
"Data"
,
Data
.
create
(
null
,
10
));
print
(
"Row"
,
new
Row
(
new
Value
[
0
],
0
));
print
(
"Row"
,
new
Row
Impl
(
new
Value
[
0
],
0
));
System
.
out
.
println
();
for
(
int
i
=
1
;
i
<
128
;
i
+=
i
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论