001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: *
021: * $Id: Person.java,v 1.1 2006-06-27 12:03:06 sinisa Exp $
022: */
023:
024: package jtaDiscRack.business.person;
025:
026: import jtaDiscRack.business.JtaDiscRackBusinessException;
027: import jtaDiscRack.business.XaTransactionSupport;
028: import jtaDiscRack.data.person.*;
029: import com.lutris.appserver.server.sql.DatabaseManagerException;
030: import com.lutris.dods.builder.generator.query.DataObjectException;
031: import org.enhydra.dods.exceptions.AssertionDataObjectException;
032:
033: /**
034: * Represents a person.
035: */
036: public class Person extends XaTransactionSupport {
037:
038: /*
039: * Person attributes
040: */
041: private String handle = null;
042:
043: private String firstname = null;
044:
045: private String lastname = null;
046:
047: private String login = null;
048:
049: private String password = null;
050:
051: /**
052: * The public constructor.
053: */
054: public Person() throws JtaDiscRackBusinessException {
055:
056: }
057:
058: /** The public constructor
059: *
060: * @param thePerson. The data object of the person.
061: */
062: public Person(PersonDO thePerson)
063: throws JtaDiscRackBusinessException {
064: try {
065: handle = thePerson.get_Handle();
066: firstname = thePerson.getFirstname();
067: lastname = thePerson.getLastname();
068: login = thePerson.getLogin();
069: password = thePerson.getPassword();
070: } catch (DatabaseManagerException dbme) {
071: dbme.printStackTrace();
072: throw new JtaDiscRackBusinessException(
073: "Error creating Person", dbme);
074: } catch (DataObjectException doe) {
075: doe.printStackTrace();
076: throw new JtaDiscRackBusinessException(
077: "Error creating Person", doe);
078: }
079: }
080:
081: /**
082: * Gets the object id for the person
083: *
084: * @return the object id.
085: * @exception DiscRackBusinessException if an error occurs
086: * retrieving data (usually due to an underlying data layer
087: * error).
088: */
089: public String getHandle() throws JtaDiscRackBusinessException {
090: return handle;
091: }
092:
093: /**
094: * Gets the login name for the person
095: *
096: * @return the login name.
097: * @exception DiscRackBusinessException if an error occurs
098: * retrieving data (usually due to an underlying data layer
099: * error).
100: */
101: public String getLogin() throws JtaDiscRackBusinessException {
102: return login;
103: }
104:
105: /**
106: * Gets the password for the person
107: *
108: * @return the password.
109: * @exception DiscRackBusinessException if an error occurs
110: * retrieving data (usually due to an underlying data layer
111: * error).
112: */
113: public String getPassword() throws JtaDiscRackBusinessException {
114: return password;
115: }
116:
117: /**
118: * Gets the firstname for the person
119: *
120: * @return the firstname.
121: * @exception DiscRackBusinessException if an error occurs
122: * retrieving data (usually due to an underlying data layer
123: * error).
124: */
125: public String getFirstname() throws JtaDiscRackBusinessException {
126: return firstname;
127: }
128:
129: /**
130: * Gets the lastname for the person
131: *
132: * @return the lastname.
133: * @exception DiscRackBusinessException if an error occurs
134: * retrieving data (usually due to an underlying data layer
135: * error).
136: */
137: public String getLastname() throws JtaDiscRackBusinessException {
138: return lastname;
139: }
140:
141: /**
142: * Sets the login name for the person.
143: *
144: * @param the login name.
145: * @exception DiscRackBusinessException if an error occurs
146: * setting the data (usually due to an underlying data layer
147: * error).
148: */
149: public void setLogin(String login)
150: throws JtaDiscRackBusinessException {
151: this .login = login;
152: }
153:
154: /**
155: * Sets the password for the person.
156: *
157: * @param the password.
158: * @exception DiscRackBusinessException if an error occurs
159: * setting the data (usually due to an underlying data layer
160: * error).
161: */
162: public void setPassword(String password)
163: throws JtaDiscRackBusinessException {
164: this .password = password;
165: }
166:
167: /**
168: * Sets the firstname for the person.
169: *
170: * @param the firstname.
171: * @exception DiscRackBusinessException if an error occurs
172: * setting the data (usually due to an underlying data layer
173: * error).
174: */
175: public void setFirstname(String firstname)
176: throws JtaDiscRackBusinessException {
177: this .firstname = firstname;
178: }
179:
180: /**
181: * Sets the lastname for the person.
182: *
183: * @param the lastname.
184: * @exception DiscRackBusinessException if an error occurs
185: * setting the data (usually due to an underlying data layer
186: * error).
187: */
188: public void setLastname(String lastname)
189: throws JtaDiscRackBusinessException {
190: this .lastname = lastname;
191: }
192:
193: /**
194: * Commits all changes to the database.
195: *
196: * @exception DiscRackBusinessException if an error occurs
197: * retrieving data (usually due to an underlying data layer
198: * error).
199: */
200: public void save() throws JtaDiscRackBusinessException,
201: AssertionDataObjectException {
202:
203: initTransaction();
204:
205: boolean doCommit = true;
206:
207: try {
208: PersonDO myDO = PersonDO.createExisting(this .handle);
209: if (myDO == null) {
210: // person creation
211: myDO = PersonDO.createVirgin();
212: }
213:
214: myDO.setLogin(this .login);
215: myDO.setPassword(this .password);
216: myDO.setFirstname(this .firstname);
217: myDO.setLastname(this .lastname);
218:
219: myDO.save();
220: } catch (AssertionDataObjectException ex) {
221: doCommit = false;
222: ex.printStackTrace();
223: throw new AssertionDataObjectException(
224: "DML opertions not allowed.", ex);
225: } catch (Exception ex) {
226: doCommit = false;
227: ex.printStackTrace();
228: throw new JtaDiscRackBusinessException(
229: "Error saving person", ex);
230: } finally {
231: if (doCommit) {
232: commitTransaction();
233: } else {
234: rollbackTransaction();
235: }
236: }
237: }
238: }
|