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: PersonImpl.java,v 1.1 2006-09-11 12:44:39 sinisa Exp $
022: */
023:
024: package transactionsDiscRack.business.person;
025:
026: import transactionsDiscRack.data.person.*;
027: import transactionsDiscRack.spec.Person;
028: import transactionsDiscRack.business.TransactionsDiscRackBusinessException;
029:
030: import com.lutris.appserver.server.sql.DBTransaction;
031: import com.lutris.appserver.server.sql.DatabaseManagerException;
032: import com.lutris.dods.builder.generator.query.DataObjectException;
033: import org.enhydra.dods.exceptions.AssertionDataObjectException;
034:
035: /**
036: * Represents a person.
037: */
038: public class PersonImpl implements Person {
039: /**
040: * The DO of the Person.
041: */
042: protected String handle = null;
043:
044: protected String login = null;
045:
046: protected String password = null;
047:
048: protected String firstName = null;
049:
050: protected String lastName = null;
051:
052: /**
053: * The public constructor.
054: */
055: public PersonImpl() {
056: }
057:
058: /**
059: * The public constructor
060: *
061: * @param thePerson
062: * The data object of the person.
063: */
064: public PersonImpl(PersonDO thePerson)
065: throws TransactionsDiscRackBusinessException {
066: try {
067: handle = thePerson.get_Handle();
068: login = thePerson.getLogin();
069: password = thePerson.getPassword();
070: firstName = thePerson.getFirstname();
071: lastName = thePerson.getLastname();
072: } catch (DatabaseManagerException ex) {
073: throw new TransactionsDiscRackBusinessException(
074: "Error creating Person", ex);
075: } catch (DataObjectException ex) {
076: throw new TransactionsDiscRackBusinessException(
077: "Error creating Person", ex);
078: }
079: }
080:
081: /**
082: * Gets the object id for the person
083: *
084: * @return the object id.
085: * @exception DiscRackBusinessException
086: * if an error occurs retrieving data (usually due to an
087: * underlying data layer error).
088: */
089: public String getHandle() {
090: return handle;
091: }
092:
093: /**
094: * Gets the login name for the person
095: *
096: * @return the login name.
097: * @exception DiscRackBusinessException
098: * if an error occurs retrieving data (usually due to an
099: * underlying data layer error).
100: */
101: public String getLogin() {
102: return login;
103: }
104:
105: /**
106: * Gets the password for the person
107: *
108: * @return the password.
109: * @exception DiscRackBusinessException
110: * if an error occurs retrieving data (usually due to an
111: * underlying data layer error).
112: */
113: public String getPassword() {
114: return password;
115: }
116:
117: /**
118: * Gets the firstname for the person
119: *
120: * @return the firstname.
121: * @exception DiscRackBusinessException
122: * if an error occurs retrieving data (usually due to an
123: * underlying data layer error).
124: */
125: public String getFirstname() {
126: return firstName;
127: }
128:
129: /**
130: * Gets the lastname for the person
131: *
132: * @return the lastname.
133: * @exception DiscRackBusinessException
134: * if an error occurs retrieving data (usually due to an
135: * underlying data layer error).
136: */
137: public String getLastname() {
138: return lastName;
139: }
140:
141: /**
142: * Sets the login name for the person.
143: *
144: * @param login
145: * login name.
146: * @exception DiscRackBusinessException
147: * if an error occurs setting the data (usually due to an
148: * underlying data layer error).
149: */
150: public void setLogin(String login) {
151: this .login = login;
152: }
153:
154: /**
155: * Sets the password for the person.
156: *
157: * @param password
158: * @exception DiscRackBusinessException
159: * if an error occurs setting the data (usually due to an
160: * underlying data layer error).
161: */
162: public void setPassword(String password) {
163: this .password = password;
164: }
165:
166: /**
167: * Sets the firstname for the person.
168: *
169: * @param firstname
170: * @exception DiscRackBusinessException
171: * if an error occurs setting the data (usually due to an
172: * underlying data layer error).
173: */
174: public void setFirstname(String firstname) {
175: this .firstName = firstname;
176: }
177:
178: /**
179: * Sets the lastname for the person.
180: *
181: * @param lastname
182: * @exception DiscRackBusinessException
183: * if an error occurs setting the data (usually due to an
184: * underlying data layer error).
185: */
186: public void setLastname(String lastname) {
187: this .lastName = lastname;
188: }
189:
190: /**
191: * Commits all changes to the database.
192: *
193: * @exception DiscRackBusinessException
194: * if an error occurs retrieving data (usually due to an
195: * underlying data layer error).
196: */
197: public void save(DBTransaction transaction)
198: throws TransactionsDiscRackBusinessException,
199: AssertionDataObjectException {
200: try {
201: PersonDO myDO = PersonDO.createExisting(this .handle,
202: transaction);
203: if (myDO == null) {
204: // person creation
205: myDO = PersonDO.createVirgin(transaction);
206: }
207:
208: myDO.setLogin(this .login);
209: myDO.setPassword(this .password);
210: myDO.setFirstname(this .firstName);
211: myDO.setLastname(this .lastName);
212:
213: myDO.save(transaction);
214: } catch (AssertionDataObjectException ex) {
215: throw new AssertionDataObjectException(
216: "Read-only table: DML operations not allowed", ex);
217: } catch (Exception ex) {
218: throw new TransactionsDiscRackBusinessException(
219: "Error saving person", ex);
220: }
221: }
222:
223: }
|