KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > discRack > biz > person > PersonFactory


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: PersonFactory.java,v 1.4 2004/02/05 10:24:50 slobodan Exp $
22  */

23 package org.enhydra.barracuda.discRack.biz.person;
24
25 import org.enhydra.barracuda.discRack.data.person.*;
26 import org.enhydra.barracuda.discRack.biz.DiscRackBusinessException;
27 import com.lutris.dods.builder.generator.query.*;
28 import com.lutris.appserver.server.Enhydra;
29 import com.lutris.logging.*;
30
31
32 /**
33  * Used to find the instance of Person.
34  */

35 public class PersonFactory {
36     
37     /**
38      * The findPerson method performs a database query to
39      * return a <CODE>Person</CODE> object
40      * representing the row in the <CODE>person</CODE> table
41      * that matches login name with the username.
42      *
43      * @param username, the login name of the person.
44      * @return
45      * the person. null if there isn't a person associated
46      * the username
47      * @exception DiscRackBusinessException
48      * if there is a problem retrieving person information.
49      */

50      public static Person findPerson(String JavaDoc username)
51         throws DiscRackBusinessException {
52         try {
53             PersonQuery query = new PersonQuery();
54             // set query.
55
query.setQueryLogin(username);
56             // Throw an exception if more than one user by this name is found
57
query.requireUniqueInstance();
58             
59             PersonDO[] foundPerson = query.getDOArray();
60             if(foundPerson.length != 0) {
61                 return new Person(foundPerson[0]);
62             } else {
63                 return null;
64             }
65         } catch(NonUniqueQueryException ex) {
66             Enhydra.getLogChannel().write(Logger.DEBUG,
67                                           "Non-unique user found in database: " +
68                                           ex.getMessage());
69             throw new DiscRackBusinessException("More than one user found with username: " +
70                                                 username);
71         } catch(DataObjectException ex) {
72             throw new DiscRackBusinessException("Database error retrieving user: ", ex);
73         } catch(QueryException ex) {
74             throw new DiscRackBusinessException("Query exception retrieving user: ", ex);
75         }
76
77     }
78 }
79
Popular Tags