]> review.fuel-infra Code Review - packages/trusty/mysql-wsrep-5.6.git/blob
914bd2974891fde8721d9a230aa12584b6f00867
[packages/trusty/mysql-wsrep-5.6.git] /
1 /*
2    Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3
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.
7
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.
12
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
16 */
17
18 package jdbctest;
19
20 import java.sql.PreparedStatement;
21 import java.sql.SQLException;
22
23 public class BatchDeleteQueryAllPrimitivesTest extends JDBCQueryTest {
24
25     /** Test delete queries using AllPrimitives.
26 drop table if exists allprimitives;
27 create table allprimitives (
28  id int not null primary key,
29
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,
34  int_null_hash int,
35  int_null_btree int,
36  int_null_both int,
37  int_null_none int,
38
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,
47
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,
56
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,
64  long_null_none bigint
65      */
66
67     @Override
68     public String tableName() {
69         return "allprimitives";
70     }
71
72     @Override
73     public void createInstances(int numberOfInstances) {
74         for (int i = 0; i < numberOfInstances; ++i) {
75             createAllPrimitiveInstance(i);
76         }
77     }
78
79     public void testDeleteEqualByPrimaryKey() {
80         deleteEqualQuery("id", "PRIMARY", 5, 1);
81         deleteEqualQuery("id", "PRIMARY", 5, 0);
82         try {
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();
89             }
90             int[] results = preparedStatement.executeBatch();
91             connection.commit();
92             for (int i = 0; i < 5; ++i) {
93                 int expected = (i == 1) ? 0:1;
94                 errorIfNotEqual("testDeleteEqualByPrimaryKey result " + i, expected, results[i]);
95             }
96         } catch (SQLException e) {
97             error(e.getMessage());
98         }
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);
109         failOnError();
110     }
111
112 }