1 22 package org.jboss.test.aop.bean; 23 import java.util.ArrayList ; 24 29 public class Person 30 { 31 public Person() {} 32 33 public Person(String name, 34 int age, 35 Address address) 36 { 37 this.name = name; 38 this.age = age; 39 this.address = address; 40 this.hobbies = new ArrayList (); 41 } 42 43 private String name; 44 private int age; 45 private Address address; 46 private ArrayList hobbies; 47 48 public void testOptimisticLock() 49 { 50 name = "Billy"; 51 requiresNew(); 52 } 53 54 public void requiresNew() 55 { 56 name = "William"; 57 } 58 59 public void testRollback() 60 { 61 name = "Billy"; 62 throw new RuntimeException ("Roll it back"); 63 } 64 65 public void setNameTransactional(String newName) 66 { 67 name = newName; 68 } 69 70 public void setName(String newName) 71 { 72 name = newName; 73 } 74 75 public String getName() 76 { 77 return name; 78 } 79 80 public int getAge() { return age; } 81 public void setAge(int newAge) { age = newAge; } 82 83 public void testDifferentFields() 84 { 85 age = 5; 86 requiresNew(); 87 } 88 89 public void testOptimisticLockWithAddress() 90 { 91 address.setCity("Billerica"); 92 requiresNewForAddress(); 93 } 94 95 public void requiresNewForAddress() 96 { 97 address.setCity("Rutland"); 98 } 99 100 101 public void testRollbackForAddress() 102 { 103 address.setCity("Billerica"); 104 throw new RuntimeException ("Roll it back"); 105 } 106 107 public void testDifferentFieldsForAddress() 108 { 109 address.setState("VT"); 110 requiresNewForAddress(); 111 } 112 113 public Address getAddress() { return address; } 114 public ArrayList getHobbies() { return hobbies; } 115 116 public void testListOptimisticLock() 117 { 118 hobbies.add("baseball"); 119 try 120 { 121 requiresNewForList(); 122 } 123 catch (RuntimeException ex) 124 { 125 ex.printStackTrace(); 126 throw ex; 127 } 128 } 129 130 public void requiresNewForList() 131 { 132 hobbies.add("football"); 133 } 134 135 136 public void testListRollback() 137 { 138 hobbies.add("tennis"); 139 throw new RuntimeException ("Roll it back"); 140 } 141 142 public void addHobby(String hobbie) 143 { 144 hobbies.add(hobbie); 145 } 146 147 } 148 149 | Popular Tags |