KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > transactionsDiscRack > business > person > PersonImpl


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: PersonImpl.java,v 1.1 2004/08/16 10:48:50 slobodan Exp $
22  */

23
24 package transactionsDiscRack.business.person;
25
26  
27 import transactionsDiscRack.data.person.*;
28 import transactionsDiscRack.data.disc.DiscDO;
29 import transactionsDiscRack.spec.Person;
30 import transactionsDiscRack.business.TransactionsDiscRackBusinessException;
31
32 import com.lutris.appserver.server.sql.DatabaseManagerException;
33 import com.lutris.appserver.server.sql.ObjectIdException;
34 import com.lutris.dods.builder.generator.query.DataObjectException;
35 import org.enhydra.dods.exceptions.AssertionDataObjectException;
36 import com.lutris.appserver.server.sql.DBTransaction;
37 import org.enhydra.dods.*;
38         
39 /**
40  * Represents a person.
41  */

42 public class PersonImpl implements Person,java.io.Serializable JavaDoc {
43     /**
44      * The DO of the Person.
45      */

46     protected PersonDO myDO = null;
47     
48     /**
49      * The public constructor.
50      */

51     public PersonImpl() throws TransactionsDiscRackBusinessException {
52     DBTransaction trans = null;
53         try {
54         try{
55         trans = DODS.getDatabaseManager().createTransaction();
56         }catch(Exception JavaDoc ex){
57         throw new DatabaseManagerException("Error creating transaction!", ex);
58         }
59         prep(trans);
60             this.myDO = PersonDO.createVirgin(trans);
61         } catch(DatabaseManagerException ex) {
62             throw new TransactionsDiscRackBusinessException("Error creating empty person", ex);
63         } catch(ObjectIdException ex) {
64             throw new TransactionsDiscRackBusinessException("Error creating object ID for person", ex);
65         }
66     }
67     
68     /** The public constructor
69      *
70      * @param thePerson The data object of the person.
71      */

72     public PersonImpl(PersonDO thePerson) {
73         this.myDO = thePerson;
74     }
75     
76     /**
77      * Gets the object id for the person
78      *
79      * @return the object id.
80      * @exception DiscRackBusinessException if an error occurs
81      * retrieving data (usually due to an underlying data layer
82      * error).
83      */

84     public String JavaDoc getHandle()
85         throws TransactionsDiscRackBusinessException {
86         try {
87             return this.myDO.getHandle();
88         } catch(DatabaseManagerException ex) {
89             throw new TransactionsDiscRackBusinessException("Error getting handle for person", ex);
90         }
91     }
92     
93     /**
94      * Gets the login name for the person
95      *
96      * @return the login name.
97      * @exception DiscRackBusinessException if an error occurs
98      * retrieving data (usually due to an underlying data layer
99      * error).
100      */

101     public String JavaDoc getLogin()
102         throws TransactionsDiscRackBusinessException {
103         try {
104             return myDO.getLogin();
105         } catch(DataObjectException ex) {
106             throw new TransactionsDiscRackBusinessException("Error getting user's login name", ex);
107         }
108     }
109     
110     /**
111      * Gets the password for the person
112      *
113      * @return the password.
114      * @exception DiscRackBusinessException if an error occurs
115      * retrieving data (usually due to an underlying data layer
116      * error).
117      */

118     public String JavaDoc getPassword()
119         throws TransactionsDiscRackBusinessException {
120         try {
121             return myDO.getPassword();
122         } catch(DataObjectException ex) {
123             throw new TransactionsDiscRackBusinessException("Error getting user's password", ex);
124         }
125     }
126     
127     /**
128      * Gets the firstname for the person
129      *
130      * @return the firstname.
131      * @exception DiscRackBusinessException if an error occurs
132      * retrieving data (usually due to an underlying data layer
133      * error).
134      */

135     public String JavaDoc getFirstname()
136         throws TransactionsDiscRackBusinessException {
137         try {
138             return myDO.getFirstname();
139         } catch(DataObjectException ex) {
140             throw new TransactionsDiscRackBusinessException("Error getting user's first name", ex);
141         }
142     }
143     
144     /**
145      * Gets the lastname for the person
146      *
147      * @return the lastname.
148      * @exception DiscRackBusinessException if an error occurs
149      * retrieving data (usually due to an underlying data layer
150      * error).
151      */

152     public String JavaDoc getLastname()
153         throws TransactionsDiscRackBusinessException {
154         try {
155             return myDO.getLastname();
156         } catch(DataObjectException ex) {
157             throw new TransactionsDiscRackBusinessException("Error getting user's last name", ex);
158         }
159     }
160     
161     /**
162      * Sets the login name for the person.
163      *
164      * @param login login name.
165      * @exception DiscRackBusinessException if an error occurs
166      * setting the data (usually due to an underlying data layer
167      * error).
168      */

169     public void setLogin(String JavaDoc login)
170         throws TransactionsDiscRackBusinessException {
171         try {
172             myDO.setLogin(login);
173         } catch(DataObjectException ex) {
174             throw new TransactionsDiscRackBusinessException("Error setting user's login name", ex);
175         }
176     }
177     
178     /**
179      * Sets the password for the person.
180      *
181      * @param password
182      * @exception DiscRackBusinessException if an error occurs
183      * setting the data (usually due to an underlying data layer
184      * error).
185      */

186     public void setPassword(String JavaDoc password)
187         throws TransactionsDiscRackBusinessException {
188         try {
189             myDO.setPassword(password);
190         } catch(DataObjectException ex) {
191             throw new TransactionsDiscRackBusinessException("Error setting user's password", ex);
192         }
193     }
194     
195     /**
196      * Sets the firstname for the person.
197      *
198      * @param firstname
199      * @exception DiscRackBusinessException if an error occurs
200      * setting the data (usually due to an underlying data layer
201      * error).
202      */

203     public void setFirstname(String JavaDoc firstname)
204         throws TransactionsDiscRackBusinessException {
205         try {
206             myDO.setFirstname(firstname);
207         } catch(DataObjectException ex) {
208             throw new TransactionsDiscRackBusinessException("Error setting user's first name", ex);
209         }
210     }
211     
212     /**
213      * Sets the lastname for the person.
214      *
215      * @param lastname
216      * @exception DiscRackBusinessException if an error occurs
217      * setting the data (usually due to an underlying data layer
218      * error).
219      */

220     public void setLastname(String JavaDoc lastname)
221         throws TransactionsDiscRackBusinessException {
222         try {
223             myDO.setLastname(lastname);
224         } catch(DataObjectException ex) {
225             throw new TransactionsDiscRackBusinessException("Error setting user's last name", ex);
226         }
227     }
228     
229     private void prep(DBTransaction trans) {
230     try {
231         PersonQuery query = new PersonQuery(trans);
232         query.setQueryHandle("0");
233         query.requireUniqueInstance();
234         query.getNextDO();
235     } catch (Exception JavaDoc exc){}
236     }
237     /**
238      * Commits all changes to the database.
239      *
240      * @exception DiscRackBusinessException if an error occurs
241      * retrieving data (usually due to an underlying data layer
242      * error).
243      */

244     public void save() throws TransactionsDiscRackBusinessException, AssertionDataObjectException {
245         try {
246             this.myDO.save();
247         this.myDO.get_transaction().commit();
248         }
249         catch (AssertionDataObjectException ex) {
250             throw new AssertionDataObjectException("Read-only table: DML operations not allowed", ex);
251         }
252         catch(Exception JavaDoc ex) {
253             throw new TransactionsDiscRackBusinessException("Error saving person", ex);
254         }
255     }
256     public void dbtRelease() {
257     myDO.get_transaction().release();
258     }
259 }
260
Popular Tags