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:44:39 sinisa Exp $
22: */
23:
24: package transactionsDiscRack.business.person;
25:
26: import transactionsDiscRack.data.person.*;
27: import transactionsDiscRack.spec.*;
28: import transactionsDiscRack.business.TransactionsDiscRackBusinessException;
29:
30: import com.lutris.dods.builder.generator.query.*;
31: import com.lutris.appserver.server.Enhydra;
32: import com.lutris.appserver.server.sql.DBTransaction;
33: import com.lutris.logging.*;
34:
35: /**
36: * Used to find the instance of Person.
37: */
38: public class PersonGeneratorImpl implements PersonGenerator {
39:
40: /**
41: * The findPerson method performs a database query to
42: * return a <CODE>Person</CODE> object
43: * representing the row in the <CODE>person</CODE> table
44: * that matches login name with the username.
45: *
46: * @param username the login name of the person.
47: * @return
48: * the person. null if there isn't a person associated
49: * the username
50: * @exception DiscRackBusinessException
51: * if there is a problem retrieving person information.
52: */
53:
54: public Person findPerson(String username, DBTransaction transaction)
55: throws TransactionsDiscRackBusinessException {
56: try {
57: PersonQuery query = new PersonQuery(transaction);
58: // set query.
59: query.setQueryLogin(username);
60: // Throw an exception if more than one user by this name is found
61: query.requireUniqueInstance();
62:
63: PersonDO[] foundPerson = query.getDOArray();
64: if (foundPerson.length != 0) {
65: return new PersonImpl(foundPerson[0]);
66: } else {
67: return null;
68: }
69: } catch (NonUniqueQueryException ex) {
70: Enhydra.getLogChannel().write(
71: Logger.DEBUG,
72: "Non-unique user found in database: "
73: + ex.getMessage());
74: throw new TransactionsDiscRackBusinessException(
75: "More than one user found with username: "
76: + username);
77: } catch (DataObjectException ex) {
78: throw new TransactionsDiscRackBusinessException(
79: "Database error retrieving user: ", ex);
80: } catch (QueryException ex) {
81: throw new TransactionsDiscRackBusinessException(
82: "Query exception retrieving user: ", ex);
83: }
84: }
85:
86: }
|