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