KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > transactionsDiscRack > 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 10:48:50 slobodan Exp $
22  */

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

43 public class DiscImpl implements Disc{
44     /**
45      * The DO of the disc.
46      */

47     protected DiscDO myDO = null;
48
49     /**
50      * The public constructor.
51      */

52     public DiscImpl() throws TransactionsDiscRackBusinessException {
53     DBTransaction trans = null;
54         try {
55         try{
56         trans = DODS.getDatabaseManager().createTransaction();
57         }catch(Exception JavaDoc ex){
58         throw new DatabaseManagerException("Error creating transaction!", ex);
59         }
60         prep(trans);
61             this.myDO = DiscDO.createVirgin(trans);
62         } catch(DatabaseManagerException ex) {
63             throw new TransactionsDiscRackBusinessException("Error creating empty Disc", ex);
64         } catch(ObjectIdException ex) {
65             throw new TransactionsDiscRackBusinessException("Error creating empty Disc", ex);
66         }
67     }
68
69     /** The protected constructor
70      *
71      * @param theDisc The data object of the disc.
72      */

73     protected DiscImpl(DiscDO theDisc)
74         throws TransactionsDiscRackBusinessException {
75         this.myDO = theDisc;
76     }
77
78     /**
79      * Gets the object id for the disc
80      *
81      * @return the object id.
82      * @exception DiscRackBusinessException if an error occurs
83      * retrieving data (usually due to an underlying data layer
84      * error).
85      */

86     public String JavaDoc getHandle()
87         throws TransactionsDiscRackBusinessException {
88         try {
89             return this.myDO.getHandle();
90         } catch(DatabaseManagerException ex) {
91             throw new TransactionsDiscRackBusinessException("Error getting disc's handle", ex);
92         }
93     }
94
95     /**
96      * Gets the title for the disc
97      *
98      * @return the title.
99      * @exception DiscRackBusinessException if an error occurs
100      * retrieving data (usually due to an underlying data layer
101      * error).
102      */

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

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

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

154     public boolean isLiked()
155         throws TransactionsDiscRackBusinessException {
156         try {
157             return myDO.getIsLiked();
158         } catch(DataObjectException ex) {
159             throw new TransactionsDiscRackBusinessException("Error getting disc's likedness", ex);
160         }
161     }
162     
163     /**
164      * Sets the title for the disc.
165      *
166      * @param title
167      * @exception DiscRackBusinessException if an error occurs
168      * setting the data (usually due to an underlying data layer
169      * error).
170      */

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

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

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

222     public void setOwner(Person owner)
223         throws TransactionsDiscRackException
224     {
225         try {
226             this.myDO.setOwner(PersonDO.createExisting(owner.getHandle(),myDO.get_transaction()));
227         } catch(DataObjectException ex) {
228         ex.printStackTrace();
229             throw new TransactionsDiscRackBusinessException("Error setting disc's owner", ex);
230         }
231     }
232     
233     /**
234      * Sets the preference for the disc.
235      *
236      * @param isLiked
237      * @exception DiscRackBusinessException if an error occurs
238      * setting the data (usually due to an underlying data layer
239      * error).
240      */

241     public void setLiked(boolean isLiked)
242         throws TransactionsDiscRackBusinessException {
243         try {
244             this.myDO.setIsLiked(isLiked);
245         } catch(DataObjectException ex) {
246             throw new TransactionsDiscRackBusinessException("Error setting disc's likedness", ex);
247         }
248     }
249     
250
251     /**
252      * Commits all changes to the database.
253      *
254      * @exception DiscRackBusinessException if an error occurs
255      * retrieving data (usually due to an underlying data layer
256      * error).
257      */

258     public void save()
259         throws TransactionsDiscRackBusinessException, AssertionDataObjectException {
260         try {
261             prep(this.myDO.get_transaction());
262             this.myDO.save();
263             this.myDO.get_transaction().commit();
264         }
265         catch (AssertionDataObjectException ex) {
266             throw new AssertionDataObjectException("Read-only table: DML operations not allowed", ex);
267         }
268         catch(Exception JavaDoc ex) {
269             throw new TransactionsDiscRackBusinessException("Error saving disc", ex);
270         }
271     }
272     private void prep(DBTransaction trans) {
273     try {
274         DiscQuery query = new DiscQuery(trans);
275         query.setQueryHandle("0");
276         query.requireUniqueInstance();
277         query.getNextDO();
278     } catch (Exception JavaDoc exc){}
279     }
280     
281     /**
282      * Deletes the disc from the database.
283      *
284      * @exception DiscRackBusinessException if an error occurs
285      * deleting data (usually due to an underlying data layer
286      * error).
287      */

288     public void delete()
289         throws TransactionsDiscRackBusinessException, AssertionDataObjectException {
290         try {
291             prep(this.myDO.get_transaction());
292             this.myDO.delete();
293         this.myDO.get_transaction().commit();
294         }
295         catch (AssertionDataObjectException ex) {
296             throw new AssertionDataObjectException("Read-only table: DML operations not allowed", ex);
297         }
298         catch(Exception JavaDoc ex) {
299             throw new TransactionsDiscRackBusinessException("Error deleting disc", ex);
300         }
301     }
302     /**
303      * Releases transaction
304      */

305     public void dbtRelease() {
306     myDO.get_transaction().release();
307     }
308 }
309
Popular Tags