1 /* 2 Copyright 2010 Sun Microsystems, Inc. 3 All rights reserved. Use is subject to license terms. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License, version 2.0, 7 as published by the Free Software Foundation. 8 9 This program is also distributed with certain software (including 10 but not limited to OpenSSL) that is licensed under separate terms, 11 as designated in a particular file or component or in included license 12 documentation. The authors of MySQL hereby grant you an additional 13 permission to link the program and your derivative works with the 14 separately licensed software that they have included with MySQL. 15 16 This program is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 GNU General Public License, version 2.0, for more details. 20 21 You should have received a copy of the GNU General Public License 22 along with this program; if not, write to the Free Software 23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 */ 25 26 package testsuite.clusterj; 27 28 import testsuite.clusterj.model.Employee; 29 30 public class FindByPrimaryKeyTest extends AbstractClusterJModelTest { 31 32 private static final String tablename = "t_basic"; 33 34 private static final int NUMBER_TO_INSERT = 60; 35 36 @Override localSetUp()37 public void localSetUp() { 38 createSessionFactory(); 39 session = sessionFactory.getSession(); 40 createEmployeeInstances(NUMBER_TO_INSERT); 41 tx = session.currentTransaction(); 42 tx.begin(); 43 session.deletePersistentAll(Employee.class); 44 tx.commit(); 45 addTearDownClasses(Employee.class); 46 } 47 testFind()48 public void testFind() { 49 // first, create instances to find 50 tx = session.currentTransaction(); 51 tx.begin(); 52 53 int count = 0; 54 55 for (int i = 0; i < NUMBER_TO_INSERT; ++i) { 56 // must be done with an active transaction 57 session.makePersistent(employees.get(i)); 58 ++count; 59 } 60 tx.commit(); 61 62 tx.begin(); 63 64 for (int i = 0; i < NUMBER_TO_INSERT; ++i) { 65 // must be done with an active transaction 66 Employee e = session.find(Employee.class, i); 67 // make sure all fields were fetched 68 consistencyCheck(e); 69 // see if it is the right Employee 70 int actualId = e.getId(); 71 if (actualId != i) { 72 error("Expected Employee.id " + i + " but got " + actualId); 73 } 74 } 75 tx.commit(); 76 failOnError(); 77 } 78 } 79