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