KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > discRack > business > 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.3 2005/02/21 08:34:42 slobodan Exp $
22  */

23
24
25
26 package discRack.business.person;
27
28 import discRack.data.person.*;
29 import discRack.business.DiscRackBusinessException;
30 import com.lutris.dods.builder.generator.query.*;
31 import java.util.*;
32
33 /**
34  * Used to find the instance of Person.
35  */

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

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