MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BatchDeleteQueryAllPrimitivesTest.java
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 
24 
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 }