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