01: /*
02: * Enhydra Java Application Server Project
03: *
04: * The contents of this file are subject to the Enhydra Public License
05: * Version 1.1 (the "License"); you may not use this file except in
06: * compliance with the License. You may obtain a copy of the License on
07: * the Enhydra web site ( http://www.enhydra.org/ ).
08: *
09: * 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 2006-09-11 12:31:47 sinisa Exp $
22: */
23:
24: package discRack.business.person;
25:
26: import discRack.data.person.*;
27: import discRack.spec.*;
28: import discRack.business.DiscRackBusinessException;
29:
30: import com.lutris.dods.builder.generator.query.*;
31: import com.lutris.appserver.server.Enhydra;
32: import com.lutris.logging.*;
33:
34: /**
35: * Used to find the instance of Person.
36: */
37: public class PersonGeneratorImpl implements PersonGenerator {
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:
53: public Person findPerson(String username)
54: throws DiscRackBusinessException {
55: try {
56: PersonQuery query = new PersonQuery();
57: // set query.
58: query.setQueryLogin(username);
59: // Throw an exception if more than one user by this name is found
60: query.requireUniqueInstance();
61:
62: PersonDO[] foundPerson = query.getDOArray();
63: if (foundPerson.length != 0) {
64: return new PersonImpl(foundPerson[0]);
65: } else {
66: return null;
67: }
68: } catch (NonUniqueQueryException ex) {
69: Enhydra.getLogChannel().write(
70: Logger.DEBUG,
71: "Non-unique user found in database: "
72: + ex.getMessage());
73: throw new DiscRackBusinessException(
74: "More than one user found with username: "
75: + username);
76: } catch (DataObjectException ex) {
77: throw new DiscRackBusinessException(
78: "Database error retrieving user: ", ex);
79: } catch (QueryException ex) {
80: throw new DiscRackBusinessException(
81: "Query exception retrieving user: ", ex);
82: }
83:
84: }
85:
86: }
|