2
Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; version 2 of the License.
8
This program is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License
14
along with this program; if not, write to the Free Software
15
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
import java.sql.PreparedStatement;
21
import java.sql.SQLException;
23
public class BatchDeleteQueryAllPrimitivesTest extends JDBCQueryTest {
25
/** Test delete queries using AllPrimitives.
26
drop table if exists allprimitives;
27
create table allprimitives (
28
id int not null primary key,
30
int_not_null_hash int not null,
31
int_not_null_btree int not null,
32
int_not_null_both int not null,
33
int_not_null_none int not null,
39
byte_not_null_hash tinyint not null,
40
byte_not_null_btree tinyint not null,
41
byte_not_null_both tinyint not null,
42
byte_not_null_none tinyint not null,
43
byte_null_hash tinyint,
44
byte_null_btree tinyint,
45
byte_null_both tinyint,
46
byte_null_none tinyint,
48
short_not_null_hash smallint not null,
49
short_not_null_btree smallint not null,
50
short_not_null_both smallint not null,
51
short_not_null_none smallint not null,
52
short_null_hash smallint,
53
short_null_btree smallint,
54
short_null_both smallint,
55
short_null_none smallint,
57
long_not_null_hash bigint not null,
58
long_not_null_btree bigint not null,
59
long_not_null_both bigint not null,
60
long_not_null_none bigint not null,
61
long_null_hash bigint,
62
long_null_btree bigint,
63
long_null_both bigint,
68
public String tableName() {
69
return "allprimitives";
73
public void createInstances(int numberOfInstances) {
74
for (int i = 0; i < numberOfInstances; ++i) {
75
createAllPrimitiveInstance(i);
79
public void testDeleteEqualByPrimaryKey() {
80
deleteEqualQuery("id", "PRIMARY", 5, 1);
81
deleteEqualQuery("id", "PRIMARY", 5, 0);
83
connection.setAutoCommit(false);
84
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM allprimitives where id = ?");
85
// delete 4 through 9 (excluding 5 which is already gone)
86
for (int i = 4; i < 9; ++i) {
87
preparedStatement.setInt(1, i);
88
preparedStatement.addBatch();
90
int[] results = preparedStatement.executeBatch();
92
for (int i = 0; i < 5; ++i) {
93
int expected = (i == 1) ? 0:1;
94
errorIfNotEqual("testDeleteEqualByPrimaryKey result " + i, expected, results[i]);
96
} catch (SQLException e) {
97
error(e.getMessage());
99
equalQuery("id", "PRIMARY", 0, 0);
100
equalQuery("id", "PRIMARY", 1, 1);
101
equalQuery("id", "PRIMARY", 2, 2);
102
equalQuery("id", "PRIMARY", 3, 3);
103
equalQuery("id", "PRIMARY", 4);
104
equalQuery("id", "PRIMARY", 5);
105
equalQuery("id", "PRIMARY", 6);
106
equalQuery("id", "PRIMARY", 7);
107
equalQuery("id", "PRIMARY", 8);
108
equalQuery("id", "PRIMARY", 9, 9);