View Javadoc

1   package org.apache.turbine.om.security.peer;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.torque.Torque;
23  import org.apache.torque.TorqueException;
24  import org.apache.torque.util.BasePeer;
25  import org.apache.torque.util.Criteria;
26  import org.apache.turbine.util.db.map.TurbineMapBuilder;
27  
28  /***
29   * This class handles all database access for the
30   * ROLE_PERMISSION table.  This table contains all
31   * the permissions for a given role.
32   *
33   * @author <a href="mailto:frank.kim@clearink.com">Frank Y. Kim</a>
34   * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
35   * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
36   * @author <a href="mailto:jon@collab.net">Jon S. Stevens</a>
37   *
38   * @deprecated Use {@link org.apache.turbine.services.security.torque.TorqueSecurityService}
39   * instead.
40   *
41   * @version $Id: RolePermissionPeer.java 571795 2007-09-01 13:09:35Z tv $
42   */
43  public class RolePermissionPeer extends BasePeer
44  {
45      /*** Serial Version UID */
46      private static final long serialVersionUID = 4149656810524167640L;
47  
48     /*** The map builder for this Peer. */
49      private static final TurbineMapBuilder MAP_BUILDER;
50  
51      /*** The table name for this peer. */
52      public static final String TABLE_NAME;
53  
54      /*** The column name for the permission id field. */
55      public static final String PERMISSION_ID;
56  
57      /*** The column name for the role id field. */
58      public static final String ROLE_ID;
59  
60  
61      static
62      {
63          try
64          {
65              MAP_BUILDER = (TurbineMapBuilder) Torque.getMapBuilder(TurbineMapBuilder.class.getName());
66          }
67          catch (TorqueException e)
68          {
69              log.error("Could not initialize Peer", e);
70              throw new RuntimeException(e);
71          }
72  
73          TABLE_NAME = MAP_BUILDER.getTableRolePermission();
74          PERMISSION_ID = MAP_BUILDER.getRolePermission_PermissionId();
75          ROLE_ID = MAP_BUILDER.getRolePermission_RoleId();
76      }
77  
78      /***
79       * Deletes the mappings for a role_id.
80       *
81       * @param role_id An int with the role id.
82       * @exception Exception a generic exception.
83       */
84      public static void deleteRole(int role_id) throws Exception
85      {
86          Criteria criteria = new Criteria();
87          criteria.add(ROLE_ID, role_id);
88          doDelete(criteria);
89      }
90  
91      /***
92       * Deletes the mappings for a permission_id.
93       *
94       * @param permission_id An int with the permission id.
95       * @exception Exception a generic exception.
96       */
97      public static void deletePermission(int permission_id) throws Exception
98      {
99          Criteria criteria = new Criteria();
100         criteria.add(PERMISSION_ID, permission_id);
101         doDelete(criteria);
102     }
103 }