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: DiscImpl.java,v 1.1 2006-09-11 12:39:40 sinisa Exp $
022: */
023:
024: package jtaDiscRack.business.disc;
025:
026: import jtaDiscRack.spec.*;
027: import jtaDiscRack.data.person.PersonDO;
028: import jtaDiscRack.data.disc.*;
029:
030: import jtaDiscRack.business.JtaDiscRackBusinessException;
031:
032: import com.lutris.appserver.server.sql.DatabaseManagerException;
033: import com.lutris.dods.builder.generator.query.DataObjectException;
034: import org.enhydra.dods.exceptions.AssertionDataObjectException;
035:
036: /**
037: * Represents a disc.
038: */
039: public class DiscImpl implements Disc {
040: /**
041: * The attributes of the disc.
042: */
043:
044: protected String handle = null;
045:
046: protected String title = null;
047:
048: protected String artist = null;
049:
050: protected String genre = null;
051:
052: protected boolean isLiked = false;
053:
054: protected String owner = null;
055:
056: /**
057: * The public constructor.
058: */
059: public DiscImpl() {
060: }
061:
062: /**
063: * The protected constructor
064: *
065: * @param theDisc
066: * The data object of the disc.
067: */
068: protected DiscImpl(DiscDO theDisc)
069: throws JtaDiscRackBusinessException {
070: try {
071: handle = theDisc.get_Handle();
072: title = theDisc.getTitle();
073: artist = theDisc.getArtist();
074: genre = theDisc.getGenre();
075: isLiked = theDisc.getIsLiked();
076: owner = theDisc.getOwner().get_Handle();
077: } catch (DataObjectException ex) {
078: throw new JtaDiscRackBusinessException(
079: "Error creating Disc", ex);
080: } catch (DatabaseManagerException ex) {
081: throw new JtaDiscRackBusinessException(
082: "Error creating Disc", ex);
083: }
084: }
085:
086: /**
087: * Gets the object id for the disc
088: *
089: * @return the object id.
090: * @exception DiscRackBusinessException
091: * if an error occurs retrieving data (usually due to an
092: * underlying data layer error).
093: */
094: public String getHandle() {
095: return handle;
096: }
097:
098: /**
099: * Gets the title for the disc
100: *
101: * @return the title.
102: * @exception DiscRackBusinessException
103: * if an error occurs retrieving data (usually due to an
104: * underlying data layer error).
105: */
106: public String getTitle() {
107: return title;
108: }
109:
110: /**
111: * Gets the artist for the disc
112: *
113: * @return the artist.
114: * @exception DiscRackBusinessException
115: * if an error occurs retrieving data (usually due to an
116: * underlying data layer error).
117: */
118: public String getArtist() {
119: return artist;
120: }
121:
122: /**
123: * Gets the genre for the disc
124: *
125: * @return the genre.
126: * @exception DiscRackBusinessException
127: * if an error occurs retrieving data (usually due to an
128: * underlying data layer error).
129: */
130: public String getGenre() {
131: return genre;
132: }
133:
134: /**
135: * Gets the preference for the disc
136: *
137: * @return true if like the disc, false if not
138: * @exception DiscRackBusinessException
139: * if an error occurs retrieving data (usually due to an
140: * underlying data layer error).
141: */
142: public boolean isLiked() {
143: return isLiked;
144: }
145:
146: /**
147: * Sets the title for the disc.
148: *
149: * @param title
150: * @exception DiscRackBusinessException
151: * if an error occurs setting the data (usually due to an
152: * underlying data layer error).
153: */
154: public void setTitle(String title) {
155: this .title = title;
156: }
157:
158: /**
159: * Sets the artist for the disc.
160: *
161: * @param artist
162: * @exception DiscRackBusinessException
163: * if an error occurs setting the data (usually due to an
164: * underlying data layer error).
165: */
166: public void setArtist(String artist) {
167: this .artist = artist;
168: }
169:
170: /**
171: * Sets the genre for the disc.
172: *
173: * @param genre
174: * @exception DiscRackBusinessException
175: * if an error occurs setting the data (usually due to an
176: * underlying data layer error).
177: */
178: public void setGenre(String genre) {
179: this .genre = genre;
180: }
181:
182: /**
183: * Sets the owner for the disc.
184: *
185: * @param owner
186: * @exception DiscRackBusinessException
187: * if an error occurs setting the data (usually due to an
188: * underlying data layer error).
189: */
190: public void setOwner(String ownerHandle) {
191: this .owner = ownerHandle;
192: }
193:
194: /**
195: * Sets the preference for the disc.
196: *
197: * @param isLiked
198: * @exception DiscRackBusinessException
199: * if an error occurs setting the data (usually due to an
200: * underlying data layer error).
201: */
202: public void setLiked(boolean isLiked) {
203: this .isLiked = isLiked;
204: }
205:
206: /**
207: * Commits all changes to the database.
208: *
209: * @exception DiscRackBusinessException
210: * if an error occurs retrieving data (usually due to an
211: * underlying data layer error).
212: */
213: public void save() throws JtaDiscRackBusinessException,
214: AssertionDataObjectException {
215: try {
216: PersonDO personDO = PersonDO.createExisting(this .owner);
217: DiscDO myDO = DiscDO.createExisting(this .handle);
218:
219: if (myDO == null) {
220: // disc creation
221: myDO = DiscDO.createVirgin();
222: }
223: myDO.setTitle(this .title);
224: myDO.setArtist(this .artist);
225: myDO.setGenre(this .genre);
226: myDO.setIsLiked(this .isLiked);
227: myDO.setOwner(personDO);
228:
229: myDO.save();
230: } catch (AssertionDataObjectException ex) {
231: throw new AssertionDataObjectException(
232: "Read-only table: DML operations not allowed", ex);
233: } catch (Exception ex) {
234: throw new JtaDiscRackBusinessException("Error saving disc",
235: ex);
236: }
237: }
238:
239: /**
240: * Deletes the disc from the database.
241: *
242: * @exception DiscRackBusinessException
243: * if an error occurs deleting data (usually due to an
244: * underlying data layer error).
245: */
246: public void delete() throws JtaDiscRackBusinessException,
247: AssertionDataObjectException {
248: try {
249: DiscDO myDO = DiscDO.createExisting(this .handle);
250: myDO.delete();
251: } catch (AssertionDataObjectException ex) {
252: throw new AssertionDataObjectException(
253: "Read-only table: DML operations not allowed", ex);
254: } catch (Exception ex) {
255: throw new JtaDiscRackBusinessException(
256: "Error deleting disc", ex);
257: }
258: }
259: }
|