Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
ef1a5ddc
提交
ef1a5ddc
authored
1月 08, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add JDBC 4.2 methods to JdbcStatement with implementations delegating to old methods
上级
cba8fa53
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
285 行增加
和
0 行删除
+285
-0
JdbcPreparedStatement.java
h2/src/main/org/h2/jdbc/JdbcPreparedStatement.java
+78
-0
JdbcStatement.java
h2/src/main/org/h2/jdbc/JdbcStatement.java
+162
-0
JdbcStatementBackwardsCompat.java
h2/src/main/org/h2/jdbc/JdbcStatementBackwardsCompat.java
+19
-0
TestStatement.java
h2/src/test/org/h2/test/jdbc/TestStatement.java
+26
-0
没有找到文件。
h2/src/main/org/h2/jdbc/JdbcPreparedStatement.java
浏览文件 @
ef1a5ddc
...
...
@@ -290,6 +290,22 @@ public class JdbcPreparedStatement extends JdbcStatement implements
}
}
/**
* Calling this method is not legal on a PreparedStatement.
*
* @param sql ignored
* @throws SQLException Unsupported Feature
*/
@Override
public
long
executeLargeUpdate
(
String
sql
)
throws
SQLException
{
try
{
debugCodeCall
(
"executeLargeUpdate"
,
sql
);
throw
DbException
.
get
(
ErrorCode
.
METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT
);
}
catch
(
Exception
e
)
{
throw
logAndConvert
(
e
);
}
}
/**
* Calling this method is not legal on a PreparedStatement.
*
...
...
@@ -1307,6 +1323,25 @@ public class JdbcPreparedStatement extends JdbcStatement implements
}
}
/**
* Calling this method is not legal on a PreparedStatement.
*
* @param sql ignored
* @param autoGeneratedKeys ignored
* @throws SQLException Unsupported Feature
*/
@Override
public
long
executeLargeUpdate
(
String
sql
,
int
autoGeneratedKeys
)
throws
SQLException
{
try
{
if
(
isDebugEnabled
())
{
debugCode
(
"executeLargeUpdate("
+
quote
(
sql
)+
", "
+
autoGeneratedKeys
+
");"
);
}
throw
DbException
.
get
(
ErrorCode
.
METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT
);
}
catch
(
Exception
e
)
{
throw
logAndConvert
(
e
);
}
}
/**
* Calling this method is not legal on a PreparedStatement.
...
...
@@ -1329,6 +1364,27 @@ public class JdbcPreparedStatement extends JdbcStatement implements
}
}
/**
* Calling this method is not legal on a PreparedStatement.
*
* @param sql ignored
* @param columnIndexes ignored
* @throws SQLException Unsupported Feature
*/
@Override
public
long
executeLargeUpdate
(
String
sql
,
int
[]
columnIndexes
)
throws
SQLException
{
try
{
if
(
isDebugEnabled
())
{
debugCode
(
"executeLargeUpdate("
+
quote
(
sql
)
+
", "
+
quoteIntArray
(
columnIndexes
)
+
");"
);
}
throw
DbException
.
get
(
ErrorCode
.
METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT
);
}
catch
(
Exception
e
)
{
throw
logAndConvert
(
e
);
}
}
/**
* Calling this method is not legal on a PreparedStatement.
*
...
...
@@ -1351,6 +1407,28 @@ public class JdbcPreparedStatement extends JdbcStatement implements
}
}
/**
* Calling this method is not legal on a PreparedStatement.
*
* @param sql ignored
* @param columnNames ignored
* @throws SQLException Unsupported Feature
*/
@Override
public
long
executeLargeUpdate
(
String
sql
,
String
[]
columnNames
)
throws
SQLException
{
try
{
if
(
isDebugEnabled
())
{
debugCode
(
"executeLargeUpdate("
+
quote
(
sql
)
+
", "
+
quoteArray
(
columnNames
)
+
");"
);
}
throw
DbException
.
get
(
ErrorCode
.
METHOD_NOT_ALLOWED_FOR_PREPARED_STATEMENT
);
}
catch
(
Exception
e
)
{
throw
logAndConvert
(
e
);
}
}
/**
* Calling this method is not legal on a PreparedStatement.
*
...
...
h2/src/main/org/h2/jdbc/JdbcStatement.java
浏览文件 @
ef1a5ddc
...
...
@@ -124,6 +124,33 @@ public class JdbcStatement extends TraceObject implements Statement, JdbcStateme
}
}
/**
* Executes a statement (insert, update, delete, create, drop)
* and returns the update count.
* If another result set exists for this statement, this will be closed
* (even if this statement fails).
*
* If auto commit is on, this statement will be committed.
* If the statement is a DDL statement (create, drop, alter) and does not
* throw an exception, the current transaction (if any) is committed after
* executing the statement.
*
* @param sql the SQL statement
* @return the update count (number of row affected by an insert,
* update or delete, or 0 if no rows or the statement was a
* create, drop, commit or rollback)
* @throws SQLException if a database error occurred or a
* select statement was executed
*/
public
long
executeLargeUpdate
(
String
sql
)
throws
SQLException
{
try
{
debugCodeCall
(
"executeLargeUpdate"
,
sql
);
return
executeUpdateInternal
(
sql
);
}
catch
(
Exception
e
)
{
throw
logAndConvert
(
e
);
}
}
private
int
executeUpdateInternal
(
String
sql
)
throws
SQLException
{
checkClosedForWrite
();
try
{
...
...
@@ -246,6 +273,25 @@ public class JdbcStatement extends TraceObject implements Statement, JdbcStateme
}
}
/**
* Returns the last update count of this statement.
*
* @return the update count (number of row affected by an insert, update or
* delete, or 0 if no rows or the statement was a create, drop,
* commit or rollback; -1 if the statement was a select).
* @throws SQLException if this object is closed or invalid
*/
@Override
public
long
getLargeUpdateCount
()
throws
SQLException
{
try
{
debugCodeCall
(
"getLargeUpdateCount"
);
checkClosed
();
return
updateCount
;
}
catch
(
Exception
e
)
{
throw
logAndConvert
(
e
);
}
}
/**
* Closes this statement.
* All result sets that where created by this statement
...
...
@@ -375,6 +421,23 @@ public class JdbcStatement extends TraceObject implements Statement, JdbcStateme
}
}
/**
* Gets the maximum number of rows for a ResultSet.
*
* @return the number of rows where 0 means no limit
* @throws SQLException if this object is closed
*/
@Override
public
long
getLargeMaxRows
()
throws
SQLException
{
try
{
debugCodeCall
(
"getLargeMaxRows"
);
checkClosed
();
return
maxRows
;
}
catch
(
Exception
e
)
{
throw
logAndConvert
(
e
);
}
}
/**
* Gets the maximum number of rows for a ResultSet.
*
...
...
@@ -395,6 +458,26 @@ public class JdbcStatement extends TraceObject implements Statement, JdbcStateme
}
}
/**
* Gets the maximum number of rows for a ResultSet.
*
* @param maxRows the number of rows where 0 means no limit
* @throws SQLException if this object is closed
*/
@Override
public
void
setLargeMaxRows
(
long
maxRows
)
throws
SQLException
{
try
{
debugCodeCall
(
"setLargeMaxRows"
,
maxRows
);
checkClosed
();
if
(
maxRows
<
0
)
{
throw
DbException
.
getInvalidValueException
(
"maxRows"
,
maxRows
);
}
this
.
maxRows
=
maxRows
<=
Integer
.
MAX_VALUE
?
(
int
)
maxRows
:
0
;
}
catch
(
Exception
e
)
{
throw
logAndConvert
(
e
);
}
}
/**
* Sets the number of rows suggested to read in one step.
* This value cannot be higher than the maximum rows (setMaxRows)
...
...
@@ -696,6 +779,23 @@ public class JdbcStatement extends TraceObject implements Statement, JdbcStateme
}
}
/**
* Executes the batch.
* If one of the batched statements fails, this database will continue.
*
* @return the array of update counts
*/
@Override
public
long
[]
executeLargeBatch
()
throws
SQLException
{
int
[]
intResult
=
executeBatch
();
int
count
=
intResult
.
length
;
long
[]
longResult
=
new
long
[
count
];
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
longResult
[
i
]
=
intResult
[
i
];
}
return
longResult
;
}
/**
* Return a result set that contains the last generated auto-increment key
* for this connection, if there was one. If no key was generated by the
...
...
@@ -797,6 +897,18 @@ public class JdbcStatement extends TraceObject implements Statement, JdbcStateme
}
}
@Override
public
long
executeLargeUpdate
(
String
sql
,
int
autoGeneratedKeys
)
throws
SQLException
{
try
{
if
(
isDebugEnabled
())
{
debugCode
(
"executeLargeUpdate("
+
quote
(
sql
)+
", "
+
autoGeneratedKeys
+
");"
);
}
return
executeUpdateInternal
(
sql
);
}
catch
(
Exception
e
)
{
throw
logAndConvert
(
e
);
}
}
/**
* Executes a statement and returns the update count.
* This method just calls executeUpdate(String sql) internally.
...
...
@@ -822,6 +934,31 @@ public class JdbcStatement extends TraceObject implements Statement, JdbcStateme
}
}
/**
* Executes a statement and returns the update count.
* This method just calls executeUpdate(String sql) internally.
* The method getGeneratedKeys supports at most one columns and row.
*
* @param sql the SQL statement
* @param columnIndexes ignored
* @return the update count (number of row affected by an insert,
* update or delete, or 0 if no rows or the statement was a
* create, drop, commit or rollback)
* @throws SQLException if a database error occurred or a
* select statement was executed
*/
@Override
public
long
executeLargeUpdate
(
String
sql
,
int
columnIndexes
[])
throws
SQLException
{
try
{
if
(
isDebugEnabled
())
{
debugCode
(
"executeLargeUpdate("
+
quote
(
sql
)+
", "
+
quoteIntArray
(
columnIndexes
)+
");"
);
}
return
executeUpdateInternal
(
sql
);
}
catch
(
Exception
e
)
{
throw
logAndConvert
(
e
);
}
}
/**
* Executes a statement and returns the update count.
* This method just calls executeUpdate(String sql) internally.
...
...
@@ -847,6 +984,31 @@ public class JdbcStatement extends TraceObject implements Statement, JdbcStateme
}
}
/**
* Executes a statement and returns the update count.
* This method just calls executeUpdate(String sql) internally.
* The method getGeneratedKeys supports at most one columns and row.
*
* @param sql the SQL statement
* @param columnNames ignored
* @return the update count (number of row affected by an insert,
* update or delete, or 0 if no rows or the statement was a
* create, drop, commit or rollback)
* @throws SQLException if a database error occurred or a
* select statement was executed
*/
@Override
public
long
executeLargeUpdate
(
String
sql
,
String
columnNames
[])
throws
SQLException
{
try
{
if
(
isDebugEnabled
())
{
debugCode
(
"executeLargeUpdate("
+
quote
(
sql
)+
", "
+
quoteArray
(
columnNames
)+
");"
);
}
return
executeUpdateInternal
(
sql
);
}
catch
(
Exception
e
)
{
throw
logAndConvert
(
e
);
}
}
/**
* Executes a statement and returns the update count.
* This method just calls execute(String sql) internally.
...
...
h2/src/main/org/h2/jdbc/JdbcStatementBackwardsCompat.java
浏览文件 @
ef1a5ddc
...
...
@@ -5,6 +5,8 @@
*/
package
org
.
h2
.
jdbc
;
import
java.sql.SQLException
;
/**
* Allows us to compile on older platforms, while still implementing the methods
* from the newer JDBC API.
...
...
@@ -13,4 +15,21 @@ public interface JdbcStatementBackwardsCompat {
// compatibility interface
// JDBC 4.2
long
getLargeUpdateCount
()
throws
SQLException
;
void
setLargeMaxRows
(
long
max
)
throws
SQLException
;
long
getLargeMaxRows
()
throws
SQLException
;
long
[]
executeLargeBatch
()
throws
SQLException
;
long
executeLargeUpdate
(
String
sql
)
throws
SQLException
;
long
executeLargeUpdate
(
String
sql
,
int
autoGeneratedKeys
)
throws
SQLException
;
long
executeLargeUpdate
(
String
sql
,
int
columnIndexes
[])
throws
SQLException
;
long
executeLargeUpdate
(
String
sql
,
String
columnNames
[])
throws
SQLException
;
}
h2/src/test/org/h2/test/jdbc/TestStatement.java
浏览文件 @
ef1a5ddc
...
...
@@ -11,6 +11,7 @@ import java.sql.ResultSet;
import
java.sql.SQLException
;
import
java.sql.Savepoint
;
import
java.sql.Statement
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
org.h2.api.ErrorCode
;
...
...
@@ -209,6 +210,7 @@ public class TestStatement extends TestBase {
ResultSet
rs
;
int
count
;
long
largeCount
;
boolean
result
;
stat
.
execute
(
"CREATE TABLE TEST(ID INT)"
);
...
...
@@ -256,6 +258,15 @@ public class TestStatement extends TestBase {
assertEquals
(
0
,
count
);
count
=
stat
.
executeUpdate
(
"DELETE FROM TEST WHERE ID=2"
);
assertEquals
(
1
,
count
);
largeCount
=
stat
.
executeLargeUpdate
(
"DELETE FROM TEST WHERE ID=-1"
);
assertEquals
(
0
,
largeCount
);
assertEquals
(
0
,
stat
.
getLargeUpdateCount
());
largeCount
=
stat
.
executeLargeUpdate
(
"INSERT INTO TEST(VALUE,ID) VALUES('JDBC',2)"
);
assertEquals
(
1
,
largeCount
);
assertEquals
(
1
,
stat
.
getLargeUpdateCount
());
largeCount
=
stat
.
executeLargeUpdate
(
"DELETE FROM TEST WHERE ID=2"
);
assertEquals
(
1
,
largeCount
);
assertEquals
(
1
,
stat
.
getLargeUpdateCount
());
assertThrows
(
ErrorCode
.
METHOD_NOT_ALLOWED_FOR_QUERY
,
stat
).
executeUpdate
(
"SELECT * FROM TEST"
);
...
...
@@ -428,6 +439,21 @@ public class TestStatement extends TestBase {
assertTrue
(
rs
.
next
());
assertEquals
(
"World"
,
rs
.
getString
(
"name"
));
assertFalse
(
rs
.
next
());
ps
=
conn
.
prepareStatement
(
"insert into test values(?, ?)"
);
ps
.
setInt
(
1
,
3
);
ps
.
setString
(
2
,
"v3"
);
ps
.
addBatch
();
ps
.
setInt
(
1
,
4
);
ps
.
setString
(
2
,
"v4"
);
ps
.
addBatch
();
assertTrue
(
Arrays
.
equals
(
new
int
[]
{
1
,
1
},
ps
.
executeBatch
()));
ps
.
setInt
(
1
,
5
);
ps
.
setString
(
2
,
"v5"
);
ps
.
addBatch
();
ps
.
setInt
(
1
,
6
);
ps
.
setString
(
2
,
"v6"
);
ps
.
addBatch
();
assertTrue
(
Arrays
.
equals
(
new
long
[]
{
1
,
1
},
ps
.
executeLargeBatch
()));
stat
.
execute
(
"drop table test"
);
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论