View Javadoc
1   package org.apache.fulcrum.security.torque.basic;
2   /*
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   */
20  import java.sql.Connection;
21  import java.util.List;
22  
23  import org.apache.fulcrum.security.entity.User;
24  import org.apache.fulcrum.security.torque.TorqueAbstractUserManager;
25  import org.apache.fulcrum.security.torque.om.TorqueBasicUserPeer;
26  import org.apache.torque.NoRowsException;
27  import org.apache.torque.TooManyRowsException;
28  import org.apache.torque.TorqueException;
29  import org.apache.torque.criteria.Criteria;
30  
31  /**
32   * This implementation persists to a database via Torque.
33   *
34   * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
35   * @version $Id:$
36   */
37  public class TorqueBasicUserManagerImpl extends TorqueAbstractUserManager
38  {
39      /**
40       * 
41       */
42      private static final long serialVersionUID = 1L;
43  
44      /**
45       * @see org.apache.fulcrum.security.torque.TorqueAbstractUserManager#doSelectAllUsers(java.sql.Connection)
46       */
47      @SuppressWarnings("unchecked")
48  	protected <T extends User> List<T> doSelectAllUsers(Connection con) throws TorqueException
49      {
50          Criteria criteria = new Criteria(TorqueBasicUserPeer.DATABASE_NAME);
51  
52          return (List<T>)TorqueBasicUserPeer.doSelect(criteria, con);
53      }
54  
55      /**
56       * @see org.apache.fulcrum.security.torque.TorqueAbstractUserManager#doSelectById(java.lang.Integer, java.sql.Connection)
57       */
58      @SuppressWarnings("unchecked")
59  	protected <T extends User> T doSelectById(Integer id, Connection con) throws NoRowsException, TooManyRowsException, TorqueException
60      {
61          return (T) TorqueBasicUserPeer.retrieveByPK(id, con);
62      }
63  
64      /**
65       * @see org.apache.fulcrum.security.torque.TorqueAbstractUserManager#doSelectByName(java.lang.String, java.sql.Connection)
66       */
67      @SuppressWarnings("unchecked")
68  	protected <T extends User> T doSelectByName(String name, Connection con) throws NoRowsException, TooManyRowsException, TorqueException
69      {
70          Criteria criteria = new Criteria(TorqueBasicUserPeer.DATABASE_NAME);
71          criteria.where(TorqueBasicUserPeer.LOGIN_NAME, name);
72          criteria.setIgnoreCase(true);
73          criteria.setSingleRecord(true);
74  
75          T t = (T)TorqueBasicUserPeer.doSelectSingleRecord(criteria, con);
76          if (t == null)
77          {
78              throw new NoRowsException(name);
79          }
80  
81          return t;
82      }
83  }