2 Copyright (c) 2010, 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
18 package testsuite.clusterj;
20 import java.util.ArrayList;
21 import java.util.List;
22 import java.util.Properties;
24 import com.mysql.clusterj.Constants;
26 import testsuite.clusterj.model.Employee2;
28 public class FindByPrimaryKey2Test extends AbstractClusterJModelTest {
30 protected List<Employee2> employees2;
32 private static final int NUMBER_TO_INSERT = 1;
35 protected Properties modifyProperties() {
36 Properties modifiedProperties = new Properties();
37 modifiedProperties.putAll(props);
38 modifiedProperties.put(Constants.PROPERTY_CLUSTER_DATABASE, "test2");
39 return modifiedProperties;
43 public void localSetUp() {
44 createSessionFactory();
45 session = sessionFactory.getSession();
46 createEmployee2Instances(NUMBER_TO_INSERT);
47 tx = session.currentTransaction();
49 session.deletePersistentAll(Employee2.class);
51 addTearDownClasses(Employee2.class);
54 public void testFind() {
55 // first, create instances to find
56 tx = session.currentTransaction();
61 for (int i = 0; i < NUMBER_TO_INSERT; ++i) {
62 // must be done with an active transaction
63 session.makePersistent(employees2.get(i));
70 for (int i = 0; i < NUMBER_TO_INSERT; ++i) {
71 // must be done with an active transaction
72 Employee2 e = session.find(Employee2.class, i);
73 // see if it is the right Employee
74 int actualId = e.getId();
76 error("Expected Employee2.id " + i + " but got " + actualId);
83 protected void createEmployee2Instances(int count) {
84 employees2 = new ArrayList<Employee2>(count);
85 for (int i = 0; i < count; ++i) {
86 Employee2 emp = session.newInstance(Employee2.class);
88 emp.setName("Employee number " + i);