KickJava   Java API By Example, From Geeks To Geeks.

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


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: Disc.java,v 1.1 2004/09/03 13:41:25 sinisa Exp $
22  */

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

38 public class Disc {
39    /**
40     * The DO of the disc.
41     */

42    protected DiscDO myDO = null;
43
44    /**
45     * The public constructor.
46     */

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

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

74    public String JavaDoc getHandle()
75       throws DiscRackBusinessException {
76       try {
77          return this.myDO.getHandle();
78       } catch(DatabaseManagerException ex) {
79           throw new DiscRackBusinessException("Error getting disc's handle", ex);
80       }
81    }
82
83
84
85    /**
86       * Gets the status of DO
87       *
88       * @return is Do null.
89       */

90    public boolean isDONull(){
91     return myDO==null;
92    }
93
94
95
96
97    /**
98     * Gets the title for the disc
99     *
100     * @return the title.
101     * @exception DiscRackBusinessException if an error occurs
102     * retrieving data (usually due to an underlying data layer
103     * error).
104     */

105    public String JavaDoc getTitle() throws DiscRackBusinessException {
106       try {
107          return myDO.getTitle();
108       } catch(DataObjectException ex) {
109          throw new DiscRackBusinessException("Error getting disc's title", ex);
110       }
111    }
112
113
114    /**
115     * Gets the version for the disc
116     *
117     * @return the version.
118     * @exception DiscRackBusinessException if an error occurs
119     * retrieving data (usually due to an underlying data layer
120     * error).
121     */

122    public int getVersion() throws DiscRackBusinessException {
123       try {
124          return myDO.getVersion();
125       }catch(Exception JavaDoc ex) {
126          throw new DiscRackBusinessException("Error getting disc's version", ex);
127       }
128    }
129
130
131
132    /**
133     * Gets the artist for the disc
134     *
135     * @return the artist.
136     * @exception DiscRackBusinessException if an error occurs
137     * retrieving data (usually due to an underlying data layer
138     * error).
139     */

140    public String JavaDoc getArtist() throws DiscRackBusinessException {
141       try {
142          return myDO.getArtist();
143       } catch(DataObjectException ex) {
144          throw new DiscRackBusinessException("Error getting disc's artist", ex);
145       }
146    }
147
148    /**
149     * Gets the genre for the disc
150     *
151     * @return the genre.
152     * @exception DiscRackBusinessException if an error occurs
153     * retrieving data (usually due to an underlying data layer
154     * error).
155     */

156    public String JavaDoc getGenre() throws DiscRackBusinessException {
157       try {
158          return myDO.getGenre();
159       } catch(DataObjectException ex) {
160          throw new DiscRackBusinessException("Error getting disc's genre", ex);
161       }
162    }
163
164    /**
165     * Gets the preference for the disc
166     *
167     * @return true if like the disc, false if not
168     * @exception DiscRackBusinessException if an error occurs
169     * retrieving data (usually due to an underlying data layer
170     * error).
171     */

172    public boolean isLiked() throws DiscRackBusinessException {
173       try {
174          return myDO.getIsLiked();
175       } catch(DataObjectException ex) {
176          throw new DiscRackBusinessException("Error getting disc's likedness", ex);
177       }
178    }
179
180    /**
181     * Sets the title for the disc.
182     *
183     * @param the title.
184     * @exception DiscRackBusinessException if an error occurs
185     * setting the data (usually due to an underlying data layer
186     * error).
187     */

188    public void setTitle(String JavaDoc title)
189       throws DiscRackBusinessException {
190       try {
191          this.myDO .setTitle(title);
192       } catch(DataObjectException ex) {
193          throw new DiscRackBusinessException("Error setting disc's title", ex);
194       }
195    }
196
197    /**
198     * Sets the artist for the disc.
199     *
200     * @param the artist.
201     * @exception DiscRackBusinessException if an error occurs
202     * setting the data (usually due to an underlying data layer
203     * error).
204     */

205    public void setArtist(String JavaDoc artist)
206       throws DiscRackBusinessException {
207       try {
208          this.myDO.setArtist(artist);
209       } catch(DataObjectException ex) {
210          throw new DiscRackBusinessException("Error setting disc's artist", ex);
211       }
212    }
213
214    /**
215     * Sets the genre for the disc.
216     *
217     * @param the genre.
218     * @exception DiscRackBusinessException if an error occurs
219     * setting the data (usually due to an underlying data layer
220     * error).
221     */

222    public void setGenre(String JavaDoc genre) throws DiscRackBusinessException {
223       try {
224          this.myDO.setGenre(genre);
225       } catch(DataObjectException ex) {
226          throw new DiscRackBusinessException("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.getHandle()));
241       } catch(DataObjectException ex) {
242          throw new DiscRackBusinessException("Error setting disc's owner", ex);
243       }
244    }
245
246    /**
247     * Sets the preference for the disc.
248     *
249     * @param the preference.
250     * @exception DiscRackBusinessException if an error occurs
251     * setting the data (usually due to an underlying data layer
252     * error).
253     */

254    public void setLiked(boolean isLiked) throws DiscRackBusinessException {
255       try {
256          this.myDO.setIsLiked(isLiked);
257       } catch(DataObjectException ex) {
258          throw new DiscRackBusinessException("Error setting disc's likedness", ex);
259       }
260    }
261
262
263
264    /**
265     * Sets the version for the disc.
266     *
267     * @param the version.
268     * @exception DiscRackBusinessException if an error occurs
269     * setting the data (usually due to an underlying data layer
270     * error).
271     */

272    public void setVersion(int ver) throws DiscRackBusinessException {
273       try {
274          this.myDO.setVersion(ver);
275       } catch(Exception JavaDoc ex) {
276          throw new DiscRackBusinessException("Error setting disc's likedness", ex);
277       }
278    }
279
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,AssertionDataObjectException {
291       try {
292          //this.myDO.commit();
293
this.myDO.save();
294       } catch(AssertionDataObjectException ex) {
295          throw new AssertionDataObjectException("Read-only cache: DML opertions not allowed.", ex);
296       } catch(Exception JavaDoc ex) {
297          throw new DiscRackBusinessException("Error saving disc", ex);
298       }
299    }
300
301    /**
302     * Deletes the disc from the database.
303     *
304     * @exception DiscRackBusinessException if an error occurs
305     * deleting data (usually due to an underlying data layer
306     * error).
307     */

308    public void delete() throws DiscRackBusinessException, AssertionDataObjectException {
309       try {
310           this.myDO.delete();
311       } catch(AssertionDataObjectException ex) {
312           throw new AssertionDataObjectException("DML opertions not allowed.", ex);
313       } catch(Exception JavaDoc ex) {
314           throw new DiscRackBusinessException("Error deleting disc", ex);
315       }
316    }
317 }
318
Popular Tags