View Javadoc
1   package org.apache.fulcrum.security.torque.dynamic;
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.Role;
24  import org.apache.fulcrum.security.torque.TorqueAbstractRoleManager;
25  import org.apache.fulcrum.security.torque.om.TorqueDynamicRole;
26  import org.apache.fulcrum.security.torque.om.TorqueDynamicRolePeer;
27  import org.apache.torque.NoRowsException;
28  import org.apache.torque.TooManyRowsException;
29  import org.apache.torque.TorqueException;
30  import org.apache.torque.criteria.Criteria;
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 TorqueDynamicRoleManagerImpl extends TorqueAbstractRoleManager
38  {
39      /**
40  	 * Serial
41  	 */
42  	private static final long serialVersionUID = 907083674412091946L;
43  
44      /* (non-Javadoc)
45       * @see org.apache.fulcrum.security.torque.TorqueAbstractRoleManager#doSelectAllRoles(java.sql.Connection)
46       */
47      @SuppressWarnings("unchecked")
48  	protected <T extends Role> List<T> doSelectAllRoles(Connection con) throws TorqueException
49      {
50          Criteria criteria = new Criteria(TorqueDynamicRolePeer.DATABASE_NAME);
51  
52          return (List<T>)TorqueDynamicRolePeer.doSelect(criteria, con);
53      }
54  
55      /* (non-Javadoc)
56       * @see org.apache.fulcrum.security.torque.TorqueAbstractRoleManager#doSelectById(java.lang.Integer, java.sql.Connection)
57       */
58      @SuppressWarnings("unchecked")
59  	protected <T extends Role> T doSelectById(Integer id, Connection con) throws NoRowsException, TooManyRowsException, TorqueException
60      {
61          return (T) TorqueDynamicRolePeer.retrieveByPK(id, con);
62      }
63  
64      /* (non-Javadoc)
65       * @see org.apache.fulcrum.security.torque.TorqueAbstractRoleManager#doSelectByName(java.lang.String, java.sql.Connection)
66       */
67      @SuppressWarnings("unchecked")
68  	protected <T extends Role> T doSelectByName(String name, Connection con) throws NoRowsException, TooManyRowsException, TorqueException
69      {
70          Criteria criteria = new Criteria(TorqueDynamicRolePeer.DATABASE_NAME);
71          criteria.where(TorqueDynamicRolePeer.ROLE_NAME, name);
72          criteria.setIgnoreCase(true);
73          criteria.setSingleRecord(true);
74  
75          List<TorqueDynamicRole> roles = TorqueDynamicRolePeer.doSelect(criteria, con);
76  
77          if (roles.isEmpty())
78          {
79              throw new NoRowsException(name);
80          }
81  
82          return (T) roles.get(0);
83      }
84  }