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