KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > transactionsDiscRack > business > disc > DiscGeneratorImpl


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: DiscGeneratorImpl.java,v 1.1 2004/08/16 10:48:50 slobodan Exp $
22  */

23
24 package transactionsDiscRack.business.disc;
25
26
27 import transactionsDiscRack.data.disc.*;
28 import transactionsDiscRack.spec.*;
29 import transactionsDiscRack.business.TransactionsDiscRackBusinessException;
30 import transactionsDiscRack.data.person.PersonDO;
31
32 import com.lutris.dods.builder.generator.query.*;
33 import com.lutris.appserver.server.sql.ObjectId;
34 import org.enhydra.dods.exceptions.AssertionDataObjectException;
35 import com.lutris.appserver.server.sql.DBTransaction;
36 import org.enhydra.dods.*;
37 /**
38  * Used to find the instances of disc.
39  */

40 public class DiscGeneratorImpl implements DiscGenerator {
41     
42     /**
43      * The findDiscsForPerson method performs a database query to
44      * return an array of <CODE>Disc</CODE> objects
45      * representing all the rows in the <CODE>disc</CODE> table
46      * that have and owner matching <CODE>Person owner</CODE>.
47      *
48      * @param owner The owner of the discs
49      * @return
50      * array of discs.
51      * @exception DiscRackBusinessException
52      * If there is a problem retrieving disc information.
53      */

54     public Disc[] findDiscsForPerson(Person owner)
55         throws TransactionsDiscRackBusinessException {
56         DiscImpl[] theDiscArray = null;
57     DBTransaction trans = null;
58         
59         try {
60         try{
61         trans = DODS.getDatabaseManager().createTransaction();
62         }catch(Exception JavaDoc ex){
63         throw new TransactionsDiscRackBusinessException("Error creating transaction!", ex);
64         }
65             DiscQuery query = new DiscQuery(trans);
66             //set query
67
query.setQueryOwner(PersonDO.createExisting(owner.getHandle(),trans));
68             // Order discs alphabetically by artist
69
query.addOrderByArtist();
70             DiscDO[] DOarray = query.getDOArray();
71             theDiscArray = new DiscImpl[ DOarray.length ];
72             for ( int i = 0; i < DOarray.length; i++ )
73             theDiscArray[i] = new DiscImpl(DOarray[i]);
74         if (DOarray.length == 0)
75         trans.release();
76         }catch(Exception JavaDoc ex) {
77         if (trans != null)
78         trans.release();
79             throw new TransactionsDiscRackBusinessException("Exception in findDiscsForPerson()", ex);
80         }
81         
82         return theDiscArray;
83     }
84     
85     /**
86      * The findDiscByID method performs a database query to
87      * return a <CODE>Disc</CODE> object
88      * representing the row in the <CODE>disc</CODE> table
89      * that matches the object id.
90      *
91      * @param id , the object id of the disc table.
92      * @return
93      * the disc. null if there isn't a person associated
94      * the id
95      * @exception DiscRackBusinessException
96      * if there is a problem retrieving person information.
97      */

98     public Disc findDiscByID(String JavaDoc id)
99         throws TransactionsDiscRackBusinessException {
100         DiscImpl theDisc = null;
101     DBTransaction trans = null;
102         
103         try {
104         try{
105         trans = DODS.getDatabaseManager().createTransaction();
106         }catch(Exception JavaDoc ex){
107         throw new TransactionsDiscRackBusinessException("Error creating transaction!", ex);
108         }
109             DiscQuery query = new DiscQuery(trans);
110             //set query
111
query.setQueryOId(new ObjectId(id));
112             // Throw an exception if more than one user by this name is found
113
query.requireUniqueInstance();
114             DiscDO theDiscDO = query.getNextDO();
115             theDisc = new DiscImpl(theDiscDO);
116             return theDisc;
117         }catch(Exception JavaDoc ex) {
118         if (trans != null)
119         trans.release();
120             throw new TransactionsDiscRackBusinessException("Exception in findDiscsByID()", ex);
121         }
122     }
123     
124    
125     
126 }
127
128
Popular Tags