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