KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > transactionsDiscRack > business > person > PersonGeneratorImpl


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

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

41 public class PersonGeneratorImpl implements PersonGenerator {
42     
43     /**
44      * The findPerson method performs a database query to
45      * return a <CODE>Person</CODE> object
46      * representing the row in the <CODE>person</CODE> table
47      * that matches login name with the username.
48      *
49      * @param username the login name of the person.
50      * @return
51      * the person. null if there isn't a person associated
52      * the username
53      * @exception DiscRackBusinessException
54      * if there is a problem retrieving person information.
55      */

56       
57      public Person findPerson(String JavaDoc username)
58         throws TransactionsDiscRackBusinessException {
59      DBTransaction trans = null;
60         try {
61         try{
62         trans = DODS.getDatabaseManager().createTransaction();
63         }catch(Exception JavaDoc ex){
64         throw new TransactionsDiscRackBusinessException("Error creating transaction!", ex);
65         }
66             PersonQuery query = new PersonQuery(trans);
67             // set query.
68
query.setQueryLogin(username);
69             // Throw an exception if more than one user by this name is found
70
query.requireUniqueInstance();
71             
72             PersonDO[] foundPerson = query.getDOArray();
73             if(foundPerson.length != 0) {
74                 return new PersonImpl(foundPerson[0]);
75             } else {
76         trans.release();
77                 return null;
78             }
79         } catch(NonUniqueQueryException ex) {
80             Enhydra.getLogChannel().write(Logger.DEBUG,
81                                           "Non-unique user found in database: " +
82                                           ex.getMessage());
83         if (trans != null)
84         trans.release();
85             throw new TransactionsDiscRackBusinessException("More than one user found with username: " +
86                                                 username);
87         } catch(DataObjectException ex) {
88         if (trans != null)
89         trans.release();
90             throw new TransactionsDiscRackBusinessException("Database error retrieving user: ", ex);
91         } catch(QueryException ex) {
92         if (trans != null)
93         trans.release();
94             throw new TransactionsDiscRackBusinessException("Query exception retrieving user: ", ex);
95         }
96
97     }
98    
99     
100     
101     
102 }
103
Popular Tags