KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > discRack > business > disc > DiscImpl


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: DiscImpl.java,v 1.1 2004/08/16 09:39:19 slobodan Exp $
22  */

23
24 package discRack.business.disc;
25
26 import discRack.spec.*;
27 import discRack.data.person.PersonDO;
28 import discRack.data.disc.DiscDO;
29
30 import discRack.business.DiscRackBusinessException;
31
32 import com.lutris.appserver.server.sql.DatabaseManagerException;
33 import com.lutris.appserver.server.sql.ObjectIdException;
34 import com.lutris.dods.builder.generator.query.DataObjectException;
35 import org.enhydra.dods.exceptions.AssertionDataObjectException;
36
37 /**
38  * Represents a disc.
39  */

40 public class DiscImpl implements Disc{
41     /**
42      * The DO of the disc.
43      */

44     protected DiscDO myDO = null;
45
46     /**
47      * The public constructor.
48      */

49     public DiscImpl() throws DiscRackBusinessException {
50         try {
51             this.myDO = DiscDO.createVirgin();
52         } catch(DatabaseManagerException ex) {
53             throw new DiscRackBusinessException("Error creating empty Disc", ex);
54         } catch(ObjectIdException ex) {
55             throw new DiscRackBusinessException("Error creating empty Disc", ex);
56         }
57     }
58
59     /** The protected constructor
60      *
61      * @param theDisc The data object of the disc.
62      */

63     protected DiscImpl(DiscDO theDisc)
64         throws DiscRackBusinessException {
65         this.myDO = theDisc;
66     }
67
68     /**
69      * Gets the object id for the disc
70      *
71      * @return the object id.
72      * @exception DiscRackBusinessException if an error occurs
73      * retrieving data (usually due to an underlying data layer
74      * error).
75      */

76     public String JavaDoc getHandle()
77         throws DiscRackBusinessException {
78         try {
79             return this.myDO.getHandle();
80         } catch(DatabaseManagerException ex) {
81             throw new DiscRackBusinessException("Error getting disc's handle", ex);
82         }
83     }
84
85     /**
86      * Gets the title for the disc
87      *
88      * @return the title.
89      * @exception DiscRackBusinessException if an error occurs
90      * retrieving data (usually due to an underlying data layer
91      * error).
92      */

93     public String JavaDoc getTitle()
94         throws DiscRackBusinessException {
95         try {
96             return myDO.getTitle();
97         } catch(DataObjectException ex) {
98             throw new DiscRackBusinessException("Error getting disc's title", ex);
99         }
100     }
101     
102     /**
103      * Gets the artist for the disc
104      *
105      * @return the artist.
106      * @exception DiscRackBusinessException if an error occurs
107      * retrieving data (usually due to an underlying data layer
108      * error).
109      */

110     public String JavaDoc getArtist()
111         throws DiscRackBusinessException {
112         try {
113             return myDO.getArtist();
114         } catch(DataObjectException ex) {
115             throw new DiscRackBusinessException("Error getting disc's artist", ex);
116         }
117     }
118     
119     /**
120      * Gets the genre for the disc
121      *
122      * @return the genre.
123      * @exception DiscRackBusinessException if an error occurs
124      * retrieving data (usually due to an underlying data layer
125      * error).
126      */

127     public String JavaDoc getGenre()
128         throws DiscRackBusinessException {
129         try {
130             return myDO.getGenre();
131         } catch(DataObjectException ex) {
132             throw new DiscRackBusinessException("Error getting disc's genre", ex);
133         }
134     }
135     
136     /**
137      * Gets the preference for the disc
138      *
139      * @return true if like the disc, false if not
140      * @exception DiscRackBusinessException if an error occurs
141      * retrieving data (usually due to an underlying data layer
142      * error).
143      */

144     public boolean isLiked()
145         throws DiscRackBusinessException {
146         try {
147             return myDO.getIsLiked();
148         } catch(DataObjectException ex) {
149             throw new DiscRackBusinessException("Error getting disc's likedness", ex);
150         }
151     }
152     
153     /**
154      * Sets the title for the disc.
155      *
156      * @param title
157      * @exception DiscRackBusinessException if an error occurs
158      * setting the data (usually due to an underlying data layer
159      * error).
160      */

161     public void setTitle(String JavaDoc title)
162         throws DiscRackBusinessException {
163         try {
164             this.myDO .setTitle(title);
165         } catch(DataObjectException ex) {
166             throw new DiscRackBusinessException("Error setting disc's title", ex);
167         }
168     }
169     
170     /**
171      * Sets the artist for the disc.
172      *
173      * @param artist
174      * @exception DiscRackBusinessException if an error occurs
175      * setting the data (usually due to an underlying data layer
176      * error).
177      */

178     public void setArtist(String JavaDoc artist)
179         throws DiscRackBusinessException {
180         try {
181             this.myDO.setArtist(artist);
182         } catch(DataObjectException ex) {
183             throw new DiscRackBusinessException("Error setting disc's artist", ex);
184         }
185     }
186     
187     /**
188      * Sets the genre for the disc.
189      *
190      * @param genre
191      * @exception DiscRackBusinessException if an error occurs
192      * setting the data (usually due to an underlying data layer
193      * error).
194      */

195     public void setGenre(String JavaDoc genre)
196         throws DiscRackBusinessException {
197         try {
198             this.myDO.setGenre(genre);
199         } catch(DataObjectException ex) {
200             throw new DiscRackBusinessException("Error setting disc's genre", ex);
201         }
202     }
203     
204     /**
205      * Sets the owner for the disc.
206      *
207      * @param owner
208      * @exception DiscRackBusinessException if an error occurs
209      * setting the data (usually due to an underlying data layer
210      * error).
211      */

212     public void setOwner(Person owner)
213         throws DiscRackException
214     {
215         try {
216             this.myDO.setOwner(PersonDO.createExisting(owner.getHandle()));
217         } catch(DataObjectException ex) {
218             throw new DiscRackBusinessException("Error setting disc's owner", ex);
219         }
220     }
221     
222     /**
223      * Sets the preference for the disc.
224      *
225      * @param isLiked
226      * @exception DiscRackBusinessException if an error occurs
227      * setting the data (usually due to an underlying data layer
228      * error).
229      */

230     public void setLiked(boolean isLiked)
231         throws DiscRackBusinessException {
232         try {
233             this.myDO.setIsLiked(isLiked);
234         } catch(DataObjectException ex) {
235             throw new DiscRackBusinessException("Error setting disc's likedness", ex);
236         }
237     }
238     
239
240     /**
241      * Commits all changes to the database.
242      *
243      * @exception DiscRackBusinessException if an error occurs
244      * retrieving data (usually due to an underlying data layer
245      * error).
246      */

247     public void save()
248         throws DiscRackBusinessException, AssertionDataObjectException {
249         try {
250             this.myDO.commit();
251         }
252         catch (AssertionDataObjectException ex) {
253             throw new AssertionDataObjectException("Read-only table: DML operations not allowed", ex);
254         }
255         catch(Exception JavaDoc ex) {
256             throw new DiscRackBusinessException("Error saving disc", ex);
257         }
258     }
259     
260     /**
261      * Deletes the disc from the database.
262      *
263      * @exception DiscRackBusinessException if an error occurs
264      * deleting data (usually due to an underlying data layer
265      * error).
266      */

267     public void delete()
268         throws DiscRackBusinessException, AssertionDataObjectException {
269         try {
270             this.myDO.delete();
271         }
272         catch (AssertionDataObjectException ex) {
273             throw new AssertionDataObjectException("Read-only table: DML operations not allowed", ex);
274         }
275         catch(Exception JavaDoc ex) {
276             throw new DiscRackBusinessException("Error deleting disc", ex);
277         }
278     }
279 }
280
Popular Tags