001package org.apache.fulcrum.security.torque.security;
002/*
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *   http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing,
014 * software distributed under the License is distributed on an
015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 * KIND, either express or implied.  See the License for the
017 * specific language governing permissions and limitations
018 * under the License.
019 */
020import java.io.Serializable;
021import java.sql.Connection;
022
023import org.apache.fulcrum.security.entity.SecurityEntity;
024import org.apache.fulcrum.security.util.DataBackendException;
025import org.apache.torque.TorqueException;
026import org.apache.torque.om.Persistent;
027/**
028 * This abstract class provides the SecurityInterface to the managers.
029 *
030 * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
031 * @version $Id:$
032 */
033public abstract class TorqueAbstractSecurityEntity
034    implements SecurityEntity, Serializable, Persistent
035{
036    /** Serial version */
037        private static final long serialVersionUID = -4052254585021044275L;
038
039        /**
040     * Get a numeric entity id
041     *
042     * @return numeric id of this entity
043     */
044    public abstract Integer getEntityId();
045
046    /**
047     * Set a numeric entity id
048     *
049     * @param id numeric id of this entity
050     * @throws TorqueException database not found exception
051     */
052    public abstract void setEntityId(Integer id) throws TorqueException;
053
054    /**
055     * Get the name of the entity
056     *
057     * @return name of this entity
058     */
059    public abstract String getEntityName();
060
061    /**
062     * Set the name of the entity
063     *
064     * @param name the name of the entity
065     */
066    public abstract void setEntityName(String name);
067     
068    /**
069     * Retrieve attached objects such as users, permissions, ...
070     * 
071     * @param con A database connection
072     * @param lazy if <code>true</code>, may load some or all relationships later
073     * @throws TorqueException database not found exception
074     */
075    public abstract void retrieveAttachedObjects(Connection con, Boolean lazy) throws DataBackendException, TorqueException;
076    
077    
078    /**
079     * old contract, lazy is set to <code>false</code>.
080     *
081     * @param con A database connection
082     * @throws DataBackendException wrapper exception: user information not found exception
083     * @throws TorqueException 
084     */
085    public abstract void retrieveAttachedObjects(Connection con) throws DataBackendException, TorqueException;
086
087    /**
088     * Update this instance to the database with all dependent objects
089     *
090     * @param con A database connection
091     * @throws TorqueException database not found exception
092     */
093    public abstract void update(Connection con) throws TorqueException;
094    
095    /**
096     * Delete this entity
097     *
098     * @throws TorqueException  if any database error occurs if any database operation fails
099     */
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}