1 package org.apache.fulcrum.security.torque.security;
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.io.Serializable;
21 import java.sql.Connection;
22
23 import org.apache.fulcrum.security.entity.SecurityEntity;
24 import org.apache.fulcrum.security.util.DataBackendException;
25 import org.apache.torque.TorqueException;
26 import org.apache.torque.om.Persistent;
27 /**
28 * This abstract class provides the SecurityInterface to the managers.
29 *
30 * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
31 * @version $Id:$
32 */
33 public abstract class TorqueAbstractSecurityEntity
34 implements SecurityEntity, Serializable, Persistent
35 {
36 /** Serial version */
37 private static final long serialVersionUID = -4052254585021044275L;
38
39 /**
40 * Get a numeric entity id
41 *
42 * @return numeric id of this entity
43 */
44 public abstract Integer getEntityId();
45
46 /**
47 * Set a numeric entity id
48 *
49 * @param id numeric id of this entity
50 * @throws TorqueException database not found exception
51 */
52 public abstract void setEntityId(Integer id) throws TorqueException;
53
54 /**
55 * Get the name of the entity
56 *
57 * @return name of this entity
58 */
59 public abstract String getEntityName();
60
61 /**
62 * Set the name of the entity
63 *
64 * @param name the name of the entity
65 */
66 public abstract void setEntityName(String name);
67
68 /**
69 * Retrieve attached objects such as users, permissions, ...
70 *
71 * @param con A database connection
72 * @param lazy if <code>true</code>, may load some or all relationships later
73 * @throws TorqueException database not found exception
74 */
75 public abstract void retrieveAttachedObjects(Connection con, Boolean lazy) throws DataBackendException, TorqueException;
76
77
78 /**
79 * old contract, lazy is set to <code>false</code>.
80 *
81 * @param con A database connection
82 * @throws DataBackendException wrapper exception: user information not found exception
83 * @throws TorqueException
84 */
85 public abstract void retrieveAttachedObjects(Connection con) throws DataBackendException, TorqueException;
86
87 /**
88 * Update this instance to the database with all dependent objects
89 *
90 * @param con A database connection
91 * @throws TorqueException database not found exception
92 */
93 public abstract void update(Connection con) throws TorqueException;
94
95 /**
96 * Delete this entity
97 *
98 * @throws TorqueException if any database error occurs if any database operation fails
99 */
100 public abstract void delete() throws TorqueException;
101
102 /**
103 * @see org.apache.fulcrum.security.entity.SecurityEntity#getId()
104 */
105 @Override
106 public Object getId()
107 {
108 return getEntityId();
109 }
110
111 /**
112 * @see org.apache.fulcrum.security.entity.SecurityEntity#setId(java.lang.Object)
113 */
114 @Override
115 public void setId(Object id)
116 {
117 try
118 {
119 setEntityId((Integer)id);
120 }
121 catch (TorqueException e)
122 {
123 // should not happen
124 }
125 }
126
127 /**
128 * @see org.apache.fulcrum.security.entity.SecurityEntity#getName()
129 */
130 @Override
131 public String getName()
132 {
133 return getEntityName();
134 }
135
136 /**
137 * @see org.apache.fulcrum.security.entity.SecurityEntity#setName(java.lang.String)
138 */
139 @Override
140 public void setName(String name)
141 {
142 if (name != null)
143 {
144 setEntityName(name.toLowerCase());
145 }
146 }
147
148 }