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.Group;
24  import org.apache.fulcrum.security.torque.TorqueAbstractGroupManager;
25  import org.apache.fulcrum.security.torque.om.TorqueDynamicGroup;
26  import org.apache.fulcrum.security.torque.om.TorqueDynamicGroupPeer;
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 TorqueDynamicGroupManagerImpl extends TorqueAbstractGroupManager
38  {
39      /* (non-Javadoc)
40       * @see org.apache.fulcrum.security.torque.TorqueAbstractGroupManager#doSelectAllGroups(java.sql.Connection)
41       */
42      @SuppressWarnings("unchecked")
43  	protected <T extends Group> List<T> doSelectAllGroups(Connection con) throws TorqueException
44      {
45          Criteria criteria = new Criteria(TorqueDynamicGroupPeer.DATABASE_NAME);
46  
47          return (List<T>)TorqueDynamicGroupPeer.doSelect(criteria, con);
48      }
49  
50      /* (non-Javadoc)
51       * @see org.apache.fulcrum.security.torque.TorqueAbstractGroupManager#doSelectById(java.lang.Integer, java.sql.Connection)
52       */
53      @SuppressWarnings("unchecked")
54  	protected <T extends Group> T doSelectById(Integer id, Connection con) throws NoRowsException, TooManyRowsException, TorqueException
55      {
56          return (T) TorqueDynamicGroupPeer.retrieveByPK(id, con);
57      }
58  
59      /* (non-Javadoc)
60       * @see org.apache.fulcrum.security.torque.TorqueAbstractGroupManager#doSelectByName(java.lang.String, java.sql.Connection)
61       */
62      @SuppressWarnings("unchecked")
63  	protected <T extends Group> T doSelectByName(String name, Connection con) throws NoRowsException, TooManyRowsException, TorqueException
64      {
65          Criteria criteria = new Criteria(TorqueDynamicGroupPeer.DATABASE_NAME);
66          criteria.where(TorqueDynamicGroupPeer.GROUP_NAME, name);
67          criteria.setIgnoreCase(true);
68          criteria.setSingleRecord(true);
69  
70          List<TorqueDynamicGroup> groups = TorqueDynamicGroupPeer.doSelect(criteria, con);
71  
72          if (groups.isEmpty())
73          {
74              throw new NoRowsException(name);
75          }
76  
77          return (T) groups.get(0);
78      }
79  }