KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > aop > basic > Person


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.aop.basic;
23
24 import java.util.ArrayList JavaDoc;
25
26 /**
27  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
28  * @version $Revision: 37406 $
29  */

30 public class Person
31 {
32    public Person()
33    {
34    }
35
36    public Person(String JavaDoc 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 JavaDoc();
44    }
45
46    private String JavaDoc name;
47    private int age;
48    private Address address;
49    private ArrayList JavaDoc 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 JavaDoc("Roll it back");
66    }
67
68    public void setNameTransactional(String JavaDoc newName)
69    {
70       name = newName;
71    }
72
73    public void setName(String JavaDoc newName)
74    {
75       name = newName;
76    }
77
78    public String JavaDoc 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 JavaDoc("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 JavaDoc 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 JavaDoc 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 JavaDoc("Roll it back");
157    }
158
159    public void addHobby(String JavaDoc hobbie)
160    {
161       hobbies.add(hobbie);
162    }
163
164 }
165
166
Popular Tags