001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.aop.bean;
023:
024: import java.util.ArrayList;
025:
026: /**
027: *
028: * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
029: * @version $Revision: 57211 $
030: */
031: public class Person {
032: public Person() {
033: }
034:
035: public Person(String name, int age, Address address) {
036: this .name = name;
037: this .age = age;
038: this .address = address;
039: this .hobbies = new ArrayList();
040: }
041:
042: private String name;
043: private int age;
044: private Address address;
045: private ArrayList hobbies;
046:
047: public void testOptimisticLock() {
048: name = "Billy";
049: requiresNew();
050: }
051:
052: public void requiresNew() {
053: name = "William";
054: }
055:
056: public void testRollback() {
057: name = "Billy";
058: throw new RuntimeException("Roll it back");
059: }
060:
061: public void setNameTransactional(String newName) {
062: name = newName;
063: }
064:
065: public void setName(String newName) {
066: name = newName;
067: }
068:
069: public String getName() {
070: return name;
071: }
072:
073: public int getAge() {
074: return age;
075: }
076:
077: public void setAge(int newAge) {
078: age = newAge;
079: }
080:
081: public void testDifferentFields() {
082: age = 5;
083: requiresNew();
084: }
085:
086: public void testOptimisticLockWithAddress() {
087: address.setCity("Billerica");
088: requiresNewForAddress();
089: }
090:
091: public void requiresNewForAddress() {
092: address.setCity("Rutland");
093: }
094:
095: public void testRollbackForAddress() {
096: address.setCity("Billerica");
097: throw new RuntimeException("Roll it back");
098: }
099:
100: public void testDifferentFieldsForAddress() {
101: address.setState("VT");
102: requiresNewForAddress();
103: }
104:
105: public Address getAddress() {
106: return address;
107: }
108:
109: public ArrayList getHobbies() {
110: return hobbies;
111: }
112:
113: public void testListOptimisticLock() {
114: hobbies.add("baseball");
115: try {
116: requiresNewForList();
117: } catch (RuntimeException ex) {
118: ex.printStackTrace();
119: throw ex;
120: }
121: }
122:
123: public void requiresNewForList() {
124: hobbies.add("football");
125: }
126:
127: public void testListRollback() {
128: hobbies.add("tennis");
129: throw new RuntimeException("Roll it back");
130: }
131:
132: public void addHobby(String hobbie) {
133: hobbies.add(hobbie);
134: }
135:
136: }
|