开发者

Slow repetitive execution of DDL and DML statements using JDBC

开发者 https://www.devze.com 2023-03-26 03:03 出处:网络
For integration tests running against 11 different RBDMS for a database abstraction library, I need to frequently reset the schema and/or data. This means, I run plenty of statements 开发者_运维知识库

For integration tests running against 11 different RBDMS for a database abstraction library, I need to frequently reset the schema and/or data. This means, I run plenty of statements 开发者_运维知识库for most test-cases.

Schema resets are only needed at the beginning of a test-suite. For example:

DROP VIEW
DROP TABLE
DROP SEQUENCE
DROP PROCEDURE
...

CREATE TABLE
...

Data-resets are only needed for tests that write data. For example:

DROP SEQUENCE
DELETE FROM TABLE ...

CREATE SEQUENCE
INSERT INTO TABLE ...

Read-only tests are quite fast, as they don't need any resetting. Inutitively, I'd just read a SQL file into memory and execute every statement using this:

// No bind variables, all hard parses
// Bind variables won't help much, though as the "hard-parse-reduction" isn't very big.
stmt = connection.createStatement();
stmt.execute(sql);

On some systems, this is quite slow. Is there any better way to do this with JDBC? Or do I have to accept the fact that this can be slow...?


Partial idea: for faster deletes, many DBMS have a "truncate table" statement.

Another partial idea: instead of deleting and reinstalling everything at the start of the test, you could just copy the files of an empty database. This will require in-depth knowledge of all 11 DBMS though, and you'll need to shutdown the processes.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号