KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fulcrum > security > impl > db > entity > TurbineUserPeer


1 package org.apache.fulcrum.security.impl.db.entity;
2
3 /* ====================================================================
4  * The Apache Software License, Version 1.1
5  *
6  * Copyright (c) 2001 The Apache Software Foundation. All rights
7  * reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution,
22  * if any, must include the following acknowledgment:
23  * "This product includes software developed by the
24  * Apache Software Foundation (http://www.apache.org/)."
25  * Alternately, this acknowledgment may appear in the software itself,
26  * if and wherever such third-party acknowledgments normally appear.
27  *
28  * 4. The names "Apache" and "Apache Software Foundation" and
29  * "Apache Turbine" must not be used to endorse or promote products
30  * derived from this software without prior written permission. For
31  * written permission, please contact apache@apache.org.
32  *
33  * 5. Products derived from this software may not be called "Apache",
34  * "Apache Turbine", nor may "Apache" appear in their name, without
35  * prior written permission of the Apache Software Foundation.
36  *
37  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
41  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48  * SUCH DAMAGE.
49  * ====================================================================
50  *
51  * This software consists of voluntary contributions made by many
52  * individuals on behalf of the Apache Software Foundation. For more
53  * information on the Apache Software Foundation, please see
54  * <http://www.apache.org/>.
55  */

56
57 import java.util.List JavaDoc;
58 import org.apache.torque.TorqueException;
59 import org.apache.torque.util.BasePeer;
60 import org.apache.torque.util.Criteria;
61 import org.apache.fulcrum.security.TurbineSecurity;
62 import org.apache.fulcrum.security.entity.User;
63 import org.apache.fulcrum.security.util.DataBackendException;
64
65 /**
66  * This class handles all the database access for the User/User
67  * table. This table contains all the information for a given user.
68  *
69  * @author <a HREF="mailto:frank.kim@clearink.com">Frank Y. Kim</a>
70  * @author <a HREF="mailto:jmcnally@collab.net">John D. McNally</a>
71  * @author <a HREF="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
72  * @author <a HREF="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
73  * @version $Id: TurbineUserPeer.java,v 1.1 2004/11/12 10:25:43 epugh Exp $
74  */

75 public class TurbineUserPeer
76     extends org.apache.fulcrum.security.impl.db.entity.BaseTurbineUserPeer
77     implements org.apache.fulcrum.security.impl.db.entity.UserPeer
78 {
79     /** The key name for the username field. */
80     public static final String JavaDoc USERNAME = LOGIN_NAME; //"TURBINE_USER.LOGIN_NAME";
81

82     public static Class JavaDoc userClass = null;
83
84     /**
85      * The class that the Peer will make instances of.
86      * If the BO is abstract then you must implement this method
87      * in the BO.
88      *
89      * !! This is duplicated. This method is available in
90      * the DBSecurityService???
91      */

92     public static Class JavaDoc getOMClass()
93         throws TorqueException
94     {
95         if ( userClass == null )
96         {
97             String JavaDoc className = TurbineSecurity.getService()
98                 .getConfiguration().getString("user.class",
99                     "org.apache.fulcrum.security.impl.db.entity.TurbineUser");
100
101             try
102             {
103                 userClass = Class.forName(className);
104             }
105             catch (Exception JavaDoc e)
106             {
107                 throw new TorqueException(e);
108             }
109         }
110
111         return userClass;
112     }
113
114     /**
115      * Returns the full name of a column.
116      *
117      * @return A String with the full name of the column.
118      */

119     public static String JavaDoc getColumnName(String JavaDoc name)
120     {
121         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
122         sb.append(TABLE_NAME);
123         sb.append(".");
124         sb.append(name);
125         return sb.toString();
126     }
127
128     /**
129      * Returns the full name of a column.
130      *
131      * @return A String with the full name of the column.
132      * @deprecated use getColumnName(String name)
133      */

134     public String JavaDoc getFullColumnName(String JavaDoc name)
135     {
136         return getColumnName(name);
137     }
138
139     /**
140      * Get the name of this table.
141      *
142      * @return A String with the name of the table.
143      */

144     public static String JavaDoc getTableName()
145     {
146         return TABLE_NAME;
147     }
148
149     /**
150      * Checks if a User is defined in the system. The name
151      * is used as query criteria.
152      *
153      * @param permission The User to be checked.
154      * @return <code>true</code> if given User exists in the system.
155      * @throws DataBackendException when more than one User with
156      * the same name exists.
157      * @throws Exception, a generic exception.
158      */

159     public static boolean checkExists( User user )
160         throws DataBackendException, Exception JavaDoc
161     {
162         Criteria criteria = new Criteria();
163         criteria.addSelectColumn(USER_ID);
164         criteria.add(TurbineUserPeer.USERNAME, user.getUserName());
165         List JavaDoc results = BasePeer.doSelect(criteria);
166         if (results.size() > 1)
167         {
168             throw new DataBackendException("Multiple users named '" +
169                 user.getUserName() + "' exist!");
170         }
171         return (results.size() == 1);
172     }
173
174     /**
175      * Returns a List of all User objects.
176      *
177      * @return A List with all users in the system.
178      * @exception Exception, a generic exception.
179      */

180     public static List JavaDoc selectAllUsers()
181         throws Exception JavaDoc
182     {
183         Criteria criteria = new Criteria();
184         criteria.addAscendingOrderByColumn(TurbineUserPeer.LAST_NAME);
185         criteria.addAscendingOrderByColumn(TurbineUserPeer.FIRST_NAME);
186         criteria.setIgnoreCase(true);
187         return TurbineUserPeer.doSelect(criteria);
188     }
189
190     /**
191      * Returns a List of all confirmed User objects.
192      *
193      * @return A List with all confirmed users in the system.
194      * @exception Exception, a generic exception.
195      */

196     public static List JavaDoc selectAllConfirmedUsers()
197         throws Exception JavaDoc
198     {
199         Criteria criteria = new Criteria();
200         criteria.add ( User.CONFIRM_VALUE, User.CONFIRM_DATA );
201         criteria.addAscendingOrderByColumn(TurbineUserPeer.LAST_NAME);
202         criteria.addAscendingOrderByColumn(TurbineUserPeer.FIRST_NAME);
203         criteria.setIgnoreCase(true);
204         return TurbineUserPeer.doSelect(criteria);
205     }
206 }
207
Popular Tags