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