You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by tv...@apache.org on 2007/04/05 19:28:55 UTC
svn commit: r525904 [2/4] - in
/jakarta/turbine/fulcrum/trunk/security/torque: ./ schema/ src/java/
src/java/org/apache/ src/java/org/apache/fulcrum/security/torque/
src/java/org/apache/fulcrum/security/torque/basic/
src/java/org/apache/fulcrum/securit...
Modified: jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/TorqueAbstractUserManager.java
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/TorqueAbstractUserManager.java?view=diff&rev=525904&r1=525903&r2=525904
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/TorqueAbstractUserManager.java (original)
+++ jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/TorqueAbstractUserManager.java Thu Apr 5 10:28:53 2007
@@ -15,22 +15,18 @@
* limitations under the License.
*/
import java.sql.Connection;
-import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.apache.fulcrum.security.entity.User;
import org.apache.fulcrum.security.spi.AbstractUserManager;
-import org.apache.fulcrum.security.torque.om.TorqueUser;
-import org.apache.fulcrum.security.torque.om.TorqueUserPeer;
import org.apache.fulcrum.security.util.DataBackendException;
import org.apache.fulcrum.security.util.EntityExistsException;
import org.apache.fulcrum.security.util.UnknownEntityException;
import org.apache.fulcrum.security.util.UserSet;
import org.apache.torque.NoRowsException;
+import org.apache.torque.TooManyRowsException;
import org.apache.torque.TorqueException;
-import org.apache.torque.om.SimpleKey;
-import org.apache.torque.util.Criteria;
import org.apache.torque.util.Transaction;
/**
* This implementation persists to a database via Torque.
@@ -41,14 +37,120 @@
public abstract class TorqueAbstractUserManager extends AbstractUserManager
{
/**
- * Provides the attached object lists for the given user
- *
- * @param user the user for which the lists should be retrieved
+ * Get all specialized Users
+ *
* @param con a database connection
+ *
+ * @return a List of User instances
+ *
+ * @throws TorqueException if any database error occurs
*/
- protected abstract void attachObjectsForUser(User user, Connection con)
- throws TorqueException, DataBackendException;
-
+ protected abstract List doSelectAllUsers(Connection con)
+ throws TorqueException;
+
+ /**
+ * Get a specialized User by name
+ *
+ * @param name the name of the group
+ * @param con a database connection
+ *
+ * @return a User instance
+ *
+ * @throws NoRowsException if no such group exists
+ * @throws TooManyRowsException if multiple groups with the given name exist
+ * @throws TorqueException if any other database error occurs
+ */
+ protected abstract User doSelectByName(String name, Connection con)
+ throws NoRowsException, TooManyRowsException, TorqueException;
+
+ /**
+ * Get a specialized User by id
+ *
+ * @param id the id of the group
+ * @param con a database connection
+ *
+ * @return a User instance
+ *
+ * @throws NoRowsException if no such group exists
+ * @throws TooManyRowsException if multiple groups with the given id exist
+ * @throws TorqueException if any other database error occurs
+ */
+ protected abstract User doSelectById(Integer id, Connection con)
+ throws NoRowsException, TooManyRowsException, TorqueException;
+
+ /**
+ * Removes an user account from the system.
+ *
+ * @param user the object describing the account to be removed.
+ * @throws DataBackendException if there was an error accessing the data
+ * backend.
+ * @throws UnknownEntityException if the user account is not present.
+ */
+ public synchronized void removeUser(User user) throws DataBackendException, UnknownEntityException
+ {
+ try
+ {
+ ((TorqueAbstractSecurityEntity)user).delete();
+ }
+ catch (TorqueException e)
+ {
+ throw new DataBackendException("Removing User '" + user.getName() + "' failed", e);
+ }
+ }
+
+ /**
+ * Creates new user account with specified attributes.
+ *
+ * @param user the object describing account to be created.
+ * @param password The password to use for the account.
+ *
+ * @throws DataBackendException if there was an error accessing the
+ * data backend.
+ * @throws EntityExistsException if the user account already exists.
+ */
+ protected synchronized User persistNewUser(User user) throws DataBackendException
+ {
+ try
+ {
+ ((TorqueAbstractSecurityEntity)user).save();
+ }
+ catch (Exception e)
+ {
+ throw new DataBackendException("Adding User '" + user.getName() + "' failed", e);
+ }
+
+ return user;
+ }
+
+ /**
+ * Stores User attributes. The User is required to exist in the system.
+ *
+ * @param role The User to be stored.
+ * @throws DataBackendException if there was an error accessing the data
+ * backend.
+ * @throws UnknownEntityException if the role does not exist.
+ */
+ public synchronized void saveUser(User user) throws DataBackendException, UnknownEntityException
+ {
+ if (checkExists(user))
+ {
+ try
+ {
+ TorqueAbstractSecurityEntity u = (TorqueAbstractSecurityEntity)user;
+ u.setNew(false);
+ u.save();
+ }
+ catch (Exception e)
+ {
+ throw new DataBackendException("Saving User '" + user.getName() + "' failed", e);
+ }
+ }
+ else
+ {
+ throw new UnknownEntityException("Unknown user '" + user + "'");
+ }
+ }
+
/**
* Check whether a specified user's account exists.
*
@@ -61,26 +163,42 @@
*/
public boolean checkExists(String userName) throws DataBackendException
{
- List users;
-
+ boolean exists = false;
+
+ Connection con = null;
+
try
{
- Criteria criteria = new Criteria();
- criteria.add(TorqueUserPeer.LOGIN_NAME, userName.toLowerCase());
-
- users = TorqueUserPeer.doSelect(criteria);
+ con = Transaction.begin(((TorqueAbstractSecurityEntity)getUserInstance()).getDatabaseName());
+
+ doSelectByName(userName, con);
+
+ Transaction.commit(con);
+ con = null;
+
+ exists = true;
+ }
+ catch (NoRowsException e)
+ {
+ exists = false;
+ }
+ catch (TooManyRowsException e)
+ {
+ throw new DataBackendException("Multiple Users with same username '" + userName + "'");
}
catch (TorqueException e)
{
throw new DataBackendException("Error retrieving user information", e);
}
-
- if (users.size() > 1)
+ finally
{
- throw new DataBackendException("Multiple Users with same username '" + userName + "'");
+ if (con != null)
+ {
+ Transaction.safeRollback(con);
+ }
}
-
- return (users.size() == 1);
+
+ return exists;
}
/**
@@ -96,49 +214,41 @@
*/
public User getUser(String userName) throws UnknownEntityException, DataBackendException
{
- User user = getUserInstance();
- List users = Collections.EMPTY_LIST;
+ User user = null;
Connection con = null;
-
+
try
{
- con = Transaction.begin(TorqueUserPeer.DATABASE_NAME);
+ con = Transaction.begin(((TorqueAbstractSecurityEntity)getUserInstance()).getDatabaseName());
- Criteria criteria = new Criteria();
- criteria.add(TorqueUserPeer.LOGIN_NAME, userName.toLowerCase());
-
- users = TorqueUserPeer.doSelect(criteria, con);
-
- if (users.size() == 1)
- {
- TorqueUser u = (TorqueUser) users.get(0);
-
- user.setId(u.getId());
- user.setName(u.getName());
- user.setPassword(u.getPassword());
-
- // Add attached objects if they exist
- attachObjectsForUser(user, con);
- }
+ user = doSelectByName(userName.toLowerCase(), con);
+
+ // Add attached objects if they exist
+ ((TorqueAbstractSecurityEntity)user).retrieveAttachedObjects(con);
Transaction.commit(con);
+ con = null;
}
- catch (TorqueException e)
- {
- Transaction.safeRollback(con);
- throw new DataBackendException("Error retrieving user information", e);
- }
-
- if (users.size() == 0)
+ catch (NoRowsException e)
{
throw new UnknownEntityException("Unknown user '" + userName + "'");
}
-
- if (users.size() > 1)
+ catch (TooManyRowsException e)
{
throw new DataBackendException("Multiple Users with same username '" + userName + "'");
}
-
+ catch (TorqueException e)
+ {
+ throw new DataBackendException("Error retrieving user information", e);
+ }
+ finally
+ {
+ if (con != null)
+ {
+ Transaction.safeRollback(con);
+ }
+ }
+
return user;
}
@@ -153,119 +263,39 @@
{
UserSet userSet = new UserSet();
Connection con = null;
-
+
try
{
- con = Transaction.begin(TorqueUserPeer.DATABASE_NAME);
+ con = Transaction.begin(((TorqueAbstractSecurityEntity)getUserInstance()).getDatabaseName());
- List users = TorqueUserPeer.doSelect(new Criteria(), con);
-
+ List users = doSelectAllUsers(con);
+
for (Iterator i = users.iterator(); i.hasNext();)
{
- User user = getUserInstance();
- TorqueUser u = (TorqueUser)i.next();
- user.setId(u.getId());
- user.setName(u.getName());
- user.setPassword(u.getPassword());
-
+ User user = (User)i.next();
+
// Add attached objects if they exist
- attachObjectsForUser(user, con);
+ ((TorqueAbstractSecurityEntity)user).retrieveAttachedObjects(con);
userSet.add(user);
}
-
+
Transaction.commit(con);
+ con = null;
}
catch (TorqueException e)
{
- Transaction.safeRollback(con);
throw new DataBackendException("Error retrieving all users", e);
}
-
- return userSet;
- }
-
- /**
- * Removes an user account from the system.
- *
- * @param user the object describing the account to be removed.
- * @throws DataBackendException if there was an error accessing the data
- * backend.
- * @throws UnknownEntityException if the user account is not present.
- */
- public synchronized void removeUser(User user) throws DataBackendException, UnknownEntityException
- {
- try
+ finally
{
- TorqueUserPeer.doDelete(SimpleKey.keyFor((Integer)user.getId()));
- }
- catch (TorqueException e)
- {
- throw new DataBackendException("Removing User '" + user + "' failed", e);
- }
- }
-
- /**
- * Creates new user account with specified attributes.
- *
- * @param user the object describing account to be created.
- * @param password The password to use for the account.
- *
- * @throws DataBackendException if there was an error accessing the
- * data backend.
- * @throws EntityExistsException if the user account already exists.
- */
- protected synchronized User persistNewUser(User user) throws DataBackendException
- {
- try
- {
- TorqueUser u = new TorqueUser();
-
- u.setName(user.getName());
- u.setPassword(user.getPassword());
- u.save();
-
- user.setId(u.getId());
- }
- catch (Exception e)
- {
- throw new DataBackendException("Adding User '" + user + "' failed", e);
- }
-
- return user;
- }
-
- /**
- * Stores User attributes. The User is required to exist in the system.
- *
- * @param role The User to be stored.
- * @throws DataBackendException if there was an error accessing the data
- * backend.
- * @throws UnknownEntityException if the role does not exist.
- */
- public synchronized void saveUser(User user) throws DataBackendException, UnknownEntityException
- {
- if (checkExists(user))
- {
- try
- {
- TorqueUser u = new TorqueUser();
-
- u.setId((Integer)user.getId());
- u.setName(user.getName());
- u.setPassword(user.getPassword());
- u.setNew(false);
- u.save();
- }
- catch (Exception e)
+ if (con != null)
{
- throw new DataBackendException("Saving User '" + user + "' failed", e);
+ Transaction.safeRollback(con);
}
}
- else
- {
- throw new UnknownEntityException("Unknown user '" + user + "'");
- }
+
+ return userSet;
}
/**
@@ -279,46 +309,47 @@
* @throws UnknownEntityException
* if the user does not exist.
*/
- public User getUserById(Object id)
- throws DataBackendException, UnknownEntityException
+ public User getUserById(Object id) throws DataBackendException, UnknownEntityException
{
- User user = getUserInstance();
-
+ User user;
+
if (id != null && id instanceof Integer)
{
Connection con = null;
try
{
- con = Transaction.begin(TorqueUserPeer.DATABASE_NAME);
+ con = Transaction.begin(((TorqueAbstractSecurityEntity)getUserInstance()).getDatabaseName());
- TorqueUser u = TorqueUserPeer.retrieveByPK((Integer)id, con);
-
- user.setId(u.getId());
- user.setName(u.getName());
- user.setPassword(u.getPassword());
-
+ user = doSelectById((Integer)id, con);
+
// Add attached objects if they exist
- attachObjectsForUser(user, con);
+ ((TorqueAbstractSecurityEntity)user).retrieveAttachedObjects(con);
Transaction.commit(con);
+ con = null;
}
catch (NoRowsException e)
{
- Transaction.safeRollback(con);
throw new UnknownEntityException("User with id '" + id + "' does not exist.", e);
}
catch (TorqueException e)
{
- Transaction.safeRollback(con);
throw new DataBackendException("Error retrieving user information", e);
}
+ finally
+ {
+ if (con != null)
+ {
+ Transaction.safeRollback(con);
+ }
+ }
}
else
{
- throw new UnknownEntityException("Invalid user id '" + user.getId() + "'");
+ throw new UnknownEntityException("Invalid user id '" + id + "'");
}
-
+
return user;
}
}
Added: jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueAbstractBasicGroup.java
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueAbstractBasicGroup.java?view=auto&rev=525904
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueAbstractBasicGroup.java (added)
+++ jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueAbstractBasicGroup.java Thu Apr 5 10:28:53 2007
@@ -0,0 +1,193 @@
+package org.apache.fulcrum.security.torque.basic;
+/*
+ * Copyright 2001-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import java.sql.Connection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.fulcrum.security.entity.User;
+import org.apache.fulcrum.security.model.basic.entity.BasicGroup;
+import org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity;
+import org.apache.fulcrum.security.torque.om.TorqueBasicGroupPeer;
+import org.apache.fulcrum.security.torque.om.TorqueBasicUser;
+import org.apache.fulcrum.security.torque.om.TorqueBasicUserGroup;
+import org.apache.fulcrum.security.torque.om.TorqueBasicUserGroupPeer;
+import org.apache.fulcrum.security.util.UserSet;
+import org.apache.torque.TorqueException;
+import org.apache.torque.om.SimpleKey;
+import org.apache.torque.util.Criteria;
+/**
+ * This abstract class provides the SecurityInterface to the managers.
+ *
+ * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
+ * @version $Id:$
+ */
+public abstract class TorqueAbstractBasicGroup extends TorqueAbstractSecurityEntity
+ implements BasicGroup
+{
+ /** a cache of user objects */
+ private Set userSet = null;
+
+ /**
+ * Forward reference to generated code
+ *
+ * Get a list of association objects, pre-populated with their TorqueBasicUser
+ * objects.
+ *
+ * @param criteria Criteria to define the selection of records
+ * @throws TorqueException
+ *
+ * @return a list of User/Group relations
+ */
+ protected abstract List getTorqueBasicUserGroupsJoinTorqueBasicUser(Criteria criteria)
+ throws TorqueException;
+
+ /**
+ * @see org.apache.fulcrum.security.model.basic.entity.BasicGroup#addUser(org.apache.fulcrum.security.entity.User)
+ */
+ public void addUser(User user)
+ {
+ getUsers().add(user);
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.basic.entity.BasicGroup#getUsers()
+ */
+ public UserSet getUsers()
+ {
+ if (userSet == null)
+ {
+ userSet = new UserSet();
+ }
+ else if(!(userSet instanceof UserSet))
+ {
+ userSet = new UserSet(userSet);
+ }
+
+ return (UserSet)userSet;
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.basic.entity.BasicGroup#getUsersAsSet()
+ */
+ public Set getUsersAsSet()
+ {
+ return userSet;
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.basic.entity.BasicGroup#removeUser(org.apache.fulcrum.security.entity.User)
+ */
+ public void removeUser(User user)
+ {
+ getUsers().remove(user);
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.basic.entity.BasicGroup#setUsers(org.apache.fulcrum.security.util.UserSet)
+ */
+ public void setUsers(UserSet userSet)
+ {
+ if(userSet != null)
+ {
+ this.userSet = userSet;
+ }
+ else
+ {
+ this.userSet = new UserSet();
+ }
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.basic.entity.BasicGroup#setUsersAsSet(java.util.Set)
+ */
+ public void setUsersAsSet(Set users)
+ {
+ setUsers(new UserSet(users));
+ }
+
+ /**
+ * Retrieve attached objects such as users, permissions,....
+ */
+ public void retrieveAttachedObjects(Connection con) throws TorqueException
+ {
+ this.userSet = new UserSet();
+
+ // the generated method that allows a Connection parameter is missing
+ List usergroups = getTorqueBasicUserGroupsJoinTorqueBasicUser(new Criteria());
+
+ for (Iterator i = usergroups.iterator(); i.hasNext();)
+ {
+ TorqueBasicUserGroup tbug = (TorqueBasicUserGroup)i.next();
+ userSet.add(tbug.getTorqueBasicUser());
+ }
+ }
+
+ /**
+ * Update this instance to the database with all dependend objects
+ *
+ * @param con A database connection
+ */
+ public void update(Connection con) throws TorqueException
+ {
+ if (userSet != null)
+ {
+ Criteria criteria = new Criteria();
+
+ /* remove old entries */
+ criteria.add(TorqueBasicUserGroupPeer.GROUP_ID, getEntityId());
+ TorqueBasicUserGroupPeer.doDelete(criteria, con);
+
+ for (Iterator i = userSet.iterator(); i.hasNext();)
+ {
+ TorqueBasicUser user = (TorqueBasicUser)i.next();
+
+ TorqueBasicUserGroup ug = new TorqueBasicUserGroup();
+ ug.setUserId(user.getEntityId());
+ ug.setGroupId(getEntityId());
+ ug.save(con);
+ }
+ }
+
+ try
+ {
+ save(con);
+ }
+ catch (Exception e)
+ {
+ throw new TorqueException(e);
+ }
+ }
+
+ /**
+ * Get the name of the connnection pool associated to this object
+ *
+ * @return the logical Torque database name
+ */
+ public String getDatabaseName()
+ {
+ return TorqueBasicGroupPeer.DATABASE_NAME;
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#delete()
+ */
+ public void delete() throws TorqueException
+ {
+ TorqueBasicGroupPeer.doDelete(SimpleKey.keyFor(getEntityId()));
+ }
+}
\ No newline at end of file
Added: jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueAbstractBasicUser.java
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueAbstractBasicUser.java?view=auto&rev=525904
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueAbstractBasicUser.java (added)
+++ jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueAbstractBasicUser.java Thu Apr 5 10:28:53 2007
@@ -0,0 +1,192 @@
+package org.apache.fulcrum.security.torque.basic;
+/*
+ * Copyright 2001-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import java.sql.Connection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.fulcrum.security.entity.Group;
+import org.apache.fulcrum.security.model.basic.entity.BasicUser;
+import org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity;
+import org.apache.fulcrum.security.torque.om.TorqueBasicGroup;
+import org.apache.fulcrum.security.torque.om.TorqueBasicUserGroup;
+import org.apache.fulcrum.security.torque.om.TorqueBasicUserGroupPeer;
+import org.apache.fulcrum.security.torque.om.TorqueBasicUserPeer;
+import org.apache.fulcrum.security.util.GroupSet;
+import org.apache.torque.TorqueException;
+import org.apache.torque.om.SimpleKey;
+import org.apache.torque.util.Criteria;
+/**
+ * This abstract class provides the SecurityInterface to the managers.
+ *
+ * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
+ * @version $Id:$
+ */
+public abstract class TorqueAbstractBasicUser extends TorqueAbstractSecurityEntity
+ implements BasicUser
+{
+ /** a cache of group objects */
+ private Set groupSet = null;
+
+ /**
+ * Forward reference to generated code
+ *
+ * Get a list of association objects, pre-populated with their TorqueBasicGroup
+ * objects.
+ *
+ * @param criteria Criteria to define the selection of records
+ * @throws TorqueException
+ *
+ * @return a list of User/Group relations
+ */
+ protected abstract List getTorqueBasicUserGroupsJoinTorqueBasicGroup(Criteria criteria)
+ throws TorqueException;
+
+ /**
+ * @see org.apache.fulcrum.security.model.basic.entity.BasicUser#addGroup(org.apache.fulcrum.security.entity.Group)
+ */
+ public void addGroup(Group group)
+ {
+ getGroups().add(group);
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.basic.entity.BasicUser#getGroups()
+ */
+ public GroupSet getGroups()
+ {
+ if (groupSet == null)
+ {
+ groupSet = new GroupSet();
+ }
+ else if(!(groupSet instanceof GroupSet))
+ {
+ groupSet = new GroupSet(groupSet);
+ }
+
+ return (GroupSet)groupSet;
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.basic.entity.BasicUser#getGroupsAsSet()
+ */
+ public Set getGroupsAsSet()
+ {
+ return groupSet;
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.basic.entity.BasicUser#removeGroup(org.apache.fulcrum.security.entity.Group)
+ */
+ public void removeGroup(Group group)
+ {
+ getGroups().remove(group);
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.basic.entity.BasicUser#setGroups(org.apache.fulcrum.security.util.GroupSet)
+ */
+ public void setGroups(GroupSet groups)
+ {
+ if(groups != null)
+ {
+ this.groupSet = groups;
+ }
+ else
+ {
+ this.groupSet = new GroupSet();
+ }
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.basic.entity.BasicUser#setGroupsAsSet(java.util.Set)
+ */
+ public void setGroupsAsSet(Set groups)
+ {
+ setGroups(new GroupSet(groups));
+ }
+
+ /**
+ * Retrieve attached objects such as users, permissions,....
+ */
+ public void retrieveAttachedObjects(Connection con) throws TorqueException
+ {
+ this.groupSet = new GroupSet();
+
+ List usergroups = getTorqueBasicUserGroupsJoinTorqueBasicGroup(new Criteria());
+
+ for (Iterator i = usergroups.iterator(); i.hasNext();)
+ {
+ TorqueBasicUserGroup tbug = (TorqueBasicUserGroup)i.next();
+ groupSet.add(tbug.getTorqueBasicGroup());
+ }
+ }
+
+ /**
+ * Update this instance to the database with all dependend objects
+ *
+ * @param con A database connection
+ */
+ public void update(Connection con) throws TorqueException
+ {
+ if (groupSet != null)
+ {
+ Criteria criteria = new Criteria();
+
+ /* remove old entries */
+ criteria.add(TorqueBasicUserGroupPeer.USER_ID, getEntityId());
+ TorqueBasicUserGroupPeer.doDelete(criteria, con);
+
+ for (Iterator i = groupSet.iterator(); i.hasNext();)
+ {
+ TorqueBasicGroup group = (TorqueBasicGroup)i.next();
+
+ TorqueBasicUserGroup ug = new TorqueBasicUserGroup();
+ ug.setUserId(getEntityId());
+ ug.setGroupId(group.getEntityId());
+ ug.save(con);
+ }
+ }
+
+ try
+ {
+ save(con);
+ }
+ catch (Exception e)
+ {
+ throw new TorqueException(e);
+ }
+ }
+
+ /**
+ * Get the name of the connnection pool associated to this object
+ *
+ * @return the logical Torque database name
+ */
+ public String getDatabaseName()
+ {
+ return TorqueBasicUserPeer.DATABASE_NAME;
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#delete()
+ */
+ public void delete() throws TorqueException
+ {
+ TorqueBasicUserPeer.doDelete(SimpleKey.keyFor(getEntityId()));
+ }
+}
\ No newline at end of file
Modified: jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueBasicGroupManagerImpl.java
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueBasicGroupManagerImpl.java?view=diff&rev=525904&r1=525903&r2=525904
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueBasicGroupManagerImpl.java (original)
+++ jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueBasicGroupManagerImpl.java Thu Apr 5 10:28:53 2007
@@ -15,19 +15,13 @@
* limitations under the License.
*/
import java.sql.Connection;
-import java.util.Iterator;
import java.util.List;
-import org.apache.fulcrum.security.UserManager;
import org.apache.fulcrum.security.entity.Group;
-import org.apache.fulcrum.security.entity.User;
-import org.apache.fulcrum.security.model.basic.entity.BasicGroup;
import org.apache.fulcrum.security.torque.TorqueAbstractGroupManager;
-import org.apache.fulcrum.security.torque.om.TorqueBasicUserGroupPeer;
-import org.apache.fulcrum.security.torque.om.TorqueUser;
-import org.apache.fulcrum.security.torque.om.TorqueUserPeer;
-import org.apache.fulcrum.security.util.DataBackendException;
-import org.apache.fulcrum.security.util.UserSet;
+import org.apache.fulcrum.security.torque.om.TorqueBasicGroupPeer;
+import org.apache.torque.NoRowsException;
+import org.apache.torque.TooManyRowsException;
import org.apache.torque.TorqueException;
import org.apache.torque.util.Criteria;
/**
@@ -39,34 +33,43 @@
public class TorqueBasicGroupManagerImpl extends TorqueAbstractGroupManager
{
/**
- * Provides the users for the given group
- *
- * @param group the group for which the users should be retrieved
- * @param con a database connection
+ * @see org.apache.fulcrum.security.torque.TorqueAbstractGroupManager#doSelectAllGroups(java.sql.Connection)
*/
- protected void attachObjectsForGroup(Group group, Connection con)
- throws TorqueException, DataBackendException
+ protected List doSelectAllGroups(Connection con)
+ throws TorqueException
{
- UserSet userSet = new UserSet();
-
- Criteria criteria = new Criteria();
- criteria.addJoin(TorqueBasicUserGroupPeer.USER_ID, TorqueUserPeer.USER_ID);
- criteria.add(TorqueBasicUserGroupPeer.GROUP_ID, (Integer)group.getId());
-
- List users = TorqueUserPeer.doSelect(criteria, con);
- UserManager userManager = getUserManager();
+ Criteria criteria = new Criteria(TorqueBasicGroupPeer.DATABASE_NAME);
+
+ return TorqueBasicGroupPeer.doSelect(criteria, con);
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.torque.TorqueAbstractGroupManager#doSelectById(java.lang.Integer, java.sql.Connection)
+ */
+ protected Group doSelectById(Integer id, Connection con)
+ throws NoRowsException, TooManyRowsException, TorqueException
+ {
+ return TorqueBasicGroupPeer.retrieveByPK(id, con);
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.torque.TorqueAbstractGroupManager#doSelectByName(java.lang.String, java.sql.Connection)
+ */
+ protected Group doSelectByName(String name, Connection con)
+ throws NoRowsException, TooManyRowsException, TorqueException
+ {
+ Criteria criteria = new Criteria(TorqueBasicGroupPeer.DATABASE_NAME);
+ criteria.add(TorqueBasicGroupPeer.GROUP_NAME, name);
+ criteria.setIgnoreCase(true);
+ criteria.setSingleRecord(true);
+
+ List groups = TorqueBasicGroupPeer.doSelect(criteria, con);
- for (Iterator i = users.iterator(); i.hasNext();)
+ if (groups.isEmpty())
{
- TorqueUser u = (TorqueUser)i.next();
- User user = userManager.getUserInstance();
-
- user.setId(u.getId());
- user.setName(u.getName());
- user.setPassword(u.getPassword());
- userSet.add(user);
+ throw new NoRowsException(name);
}
- ((BasicGroup)group).setUsers(userSet);
+ return (Group)groups.get(0);
}
}
Modified: jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueBasicModelManagerImpl.java
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueBasicModelManagerImpl.java?view=diff&rev=525904&r1=525903&r2=525904
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueBasicModelManagerImpl.java (original)
+++ jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueBasicModelManagerImpl.java Thu Apr 5 10:28:53 2007
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+import java.sql.Connection;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -24,12 +25,11 @@
import org.apache.fulcrum.security.model.basic.entity.BasicGroup;
import org.apache.fulcrum.security.model.basic.entity.BasicUser;
import org.apache.fulcrum.security.spi.AbstractManager;
-import org.apache.fulcrum.security.torque.om.TorqueBasicUserGroup;
-import org.apache.fulcrum.security.torque.om.TorqueBasicUserGroupPeer;
+import org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity;
import org.apache.fulcrum.security.util.DataBackendException;
import org.apache.fulcrum.security.util.UnknownEntityException;
import org.apache.torque.TorqueException;
-import org.apache.torque.util.Criteria;
+import org.apache.torque.util.Transaction;
/**
* This implementation persists to a database via Torque.
*
@@ -49,29 +49,39 @@
*/
public synchronized void grant(User user, Group group) throws DataBackendException, UnknownEntityException
{
- boolean groupExists = false;
- boolean userExists = false;
+ boolean groupExists = getGroupManager().checkExists(group);
+ boolean userExists = getUserManager().checkExists(user);
- try
+ if (groupExists && userExists)
{
- groupExists = getGroupManager().checkExists(group);
- userExists = getUserManager().checkExists(user);
- if (groupExists && userExists)
+ ((BasicUser) user).addGroup(group);
+ ((BasicGroup) group).addUser(user);
+
+ Connection con = null;
+
+ try
{
- ((BasicUser) user).addGroup(group);
- ((BasicGroup) group).addUser(user);
+ con = Transaction.begin(((TorqueAbstractSecurityEntity)user).getDatabaseName());
- TorqueBasicUserGroup ug = new TorqueBasicUserGroup();
- ug.setGroupId((Integer)group.getId());
- ug.setUserId((Integer)user.getId());
- ug.save();
-
- return;
+ ((TorqueAbstractSecurityEntity)user).update(con);
+ ((TorqueAbstractSecurityEntity)group).update(con);
+
+ Transaction.commit(con);
+ con = null;
}
- }
- catch (Exception e)
- {
- throw new DataBackendException("grant('" + user.getName() + user.getId() + "', '" + group.getName() + group.getId() + "') failed", e);
+ catch (TorqueException e)
+ {
+ throw new DataBackendException("grant('" + user.getName() + user.getId() + "', '" + group.getName() + group.getId() + "') failed", e);
+ }
+ finally
+ {
+ if (con != null)
+ {
+ Transaction.safeRollback(con);
+ }
+ }
+
+ return;
}
if (!groupExists)
@@ -96,29 +106,39 @@
*/
public synchronized void revoke(User user, Group group) throws DataBackendException, UnknownEntityException
{
- boolean groupExists = false;
- boolean userExists = false;
+ boolean groupExists = getGroupManager().checkExists(group);
+ boolean userExists = getUserManager().checkExists(user);
- try
+ if (groupExists && userExists)
{
- groupExists = getGroupManager().checkExists(group);
- userExists = getUserManager().checkExists(user);
- if (groupExists && userExists)
+ ((BasicUser) user).removeGroup(group);
+ ((BasicGroup) group).removeUser(user);
+
+ Connection con = null;
+
+ try
{
- ((BasicUser) user).removeGroup(group);
- ((BasicGroup) group).removeUser(user);
+ con = Transaction.begin(((TorqueAbstractSecurityEntity)user).getDatabaseName());
- Criteria criteria = new Criteria();
- criteria.add(TorqueBasicUserGroupPeer.GROUP_ID, (Integer)group.getId());
- criteria.add(TorqueBasicUserGroupPeer.USER_ID, (Integer)user.getId());
- TorqueBasicUserGroupPeer.doDelete(criteria);
-
- return;
+ ((TorqueAbstractSecurityEntity)user).update(con);
+ ((TorqueAbstractSecurityEntity)group).update(con);
+
+ Transaction.commit(con);
+ con = null;
}
- }
- catch (TorqueException e)
- {
- throw new DataBackendException("revoke('" + user.getName() + "', '" + group.getName() + "') failed", e);
+ catch (TorqueException e)
+ {
+ throw new DataBackendException("grant('" + user.getName() + user.getId() + "', '" + group.getName() + group.getId() + "') failed", e);
+ }
+ finally
+ {
+ if (con != null)
+ {
+ Transaction.safeRollback(con);
+ }
+ }
+
+ return;
}
if (!groupExists)
@@ -144,8 +164,8 @@
public synchronized void revokeAll(User user)
throws DataBackendException, UnknownEntityException
{
- boolean userExists = false;
- userExists = getUserManager().checkExists(user);
+ boolean userExists = getUserManager().checkExists(user);
+
if (userExists)
{
BasicUser u = (BasicUser) user;
@@ -158,16 +178,28 @@
Group group = (Group)i.next();
u.removeGroup(group);
}
-
+
+ Connection con = null;
+
try
{
- Criteria criteria = new Criteria();
- criteria.add(TorqueBasicUserGroupPeer.USER_ID, (Integer)user.getId());
- TorqueBasicUserGroupPeer.doDelete(criteria);
+ con = Transaction.begin(((TorqueAbstractSecurityEntity)user).getDatabaseName());
+
+ ((TorqueAbstractSecurityEntity)user).update(con);
+
+ Transaction.commit(con);
+ con = null;
}
catch (TorqueException e)
{
- throw new DataBackendException("revokeAll('" + user.getName() + "') failed", e);
+ throw new DataBackendException("revokeAll('" + user.getName() + user.getId() + "') failed", e);
+ }
+ finally
+ {
+ if (con != null)
+ {
+ Transaction.safeRollback(con);
+ }
}
return;
Modified: jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueBasicUserManagerImpl.java
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueBasicUserManagerImpl.java?view=diff&rev=525904&r1=525903&r2=525904
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueBasicUserManagerImpl.java (original)
+++ jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/basic/TorqueBasicUserManagerImpl.java Thu Apr 5 10:28:53 2007
@@ -15,19 +15,13 @@
* limitations under the License.
*/
import java.sql.Connection;
-import java.util.Iterator;
import java.util.List;
-import org.apache.fulcrum.security.GroupManager;
-import org.apache.fulcrum.security.entity.Group;
import org.apache.fulcrum.security.entity.User;
-import org.apache.fulcrum.security.model.basic.entity.BasicUser;
import org.apache.fulcrum.security.torque.TorqueAbstractUserManager;
-import org.apache.fulcrum.security.torque.om.TorqueBasicUserGroupPeer;
-import org.apache.fulcrum.security.torque.om.TorqueGroup;
-import org.apache.fulcrum.security.torque.om.TorqueGroupPeer;
-import org.apache.fulcrum.security.util.DataBackendException;
-import org.apache.fulcrum.security.util.GroupSet;
+import org.apache.fulcrum.security.torque.om.TorqueBasicUserPeer;
+import org.apache.torque.NoRowsException;
+import org.apache.torque.TooManyRowsException;
import org.apache.torque.TorqueException;
import org.apache.torque.util.Criteria;
/**
@@ -39,33 +33,40 @@
public class TorqueBasicUserManagerImpl extends TorqueAbstractUserManager
{
/**
- * Provides the groups for the given user
- *
- * @param user the user for which the groups should be retrieved
- * @param con a database connection
+ * @see org.apache.fulcrum.security.torque.TorqueAbstractUserManager#doSelectAllUsers(java.sql.Connection)
*/
- protected void attachObjectsForUser(User user, Connection con)
- throws TorqueException, DataBackendException
+ protected List doSelectAllUsers(Connection con) throws TorqueException
{
- GroupSet groupSet = new GroupSet();
-
- Criteria criteria = new Criteria();
- criteria.addJoin(TorqueBasicUserGroupPeer.GROUP_ID, TorqueGroupPeer.GROUP_ID);
- criteria.add(TorqueBasicUserGroupPeer.USER_ID, (Integer)user.getId());
-
- List groups = TorqueGroupPeer.doSelect(criteria, con);
- GroupManager groupManager = getGroupManager();
+ Criteria criteria = new Criteria(TorqueBasicUserPeer.DATABASE_NAME);
+
+ return TorqueBasicUserPeer.doSelect(criteria, con);
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.torque.TorqueAbstractUserManager#doSelectById(java.lang.Integer, java.sql.Connection)
+ */
+ protected User doSelectById(Integer id, Connection con) throws NoRowsException, TooManyRowsException, TorqueException
+ {
+ return TorqueBasicUserPeer.retrieveByPK(id, con);
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.torque.TorqueAbstractUserManager#doSelectByName(java.lang.String, java.sql.Connection)
+ */
+ protected User doSelectByName(String name, Connection con) throws NoRowsException, TooManyRowsException, TorqueException
+ {
+ Criteria criteria = new Criteria(TorqueBasicUserPeer.DATABASE_NAME);
+ criteria.add(TorqueBasicUserPeer.LOGIN_NAME, name);
+ criteria.setIgnoreCase(true);
+ criteria.setSingleRecord(true);
+
+ List users = TorqueBasicUserPeer.doSelect(criteria, con);
- for (Iterator i = groups.iterator(); i.hasNext();)
+ if (users.isEmpty())
{
- TorqueGroup g = (TorqueGroup)i.next();
- Group group = groupManager.getGroupInstance();
-
- group.setId(g.getId());
- group.setName(g.getName());
- groupSet.add(group);
+ throw new NoRowsException(name);
}
- ((BasicUser)user).setGroups(groupSet);
+ return (User)users.get(0);
}
}
Added: jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueAbstractDynamicGroup.java
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueAbstractDynamicGroup.java?view=auto&rev=525904
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueAbstractDynamicGroup.java (added)
+++ jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueAbstractDynamicGroup.java Thu Apr 5 10:28:53 2007
@@ -0,0 +1,305 @@
+package org.apache.fulcrum.security.torque.dynamic;
+/*
+ * Copyright 2001-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import java.sql.Connection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.fulcrum.security.entity.Role;
+import org.apache.fulcrum.security.entity.User;
+import org.apache.fulcrum.security.model.dynamic.entity.DynamicGroup;
+import org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicGroupPeer;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicGroupRole;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicGroupRolePeer;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicRole;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicUser;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicUserGroup;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicUserGroupPeer;
+import org.apache.fulcrum.security.util.RoleSet;
+import org.apache.fulcrum.security.util.UserSet;
+import org.apache.torque.TorqueException;
+import org.apache.torque.om.SimpleKey;
+import org.apache.torque.util.Criteria;
+/**
+ * This abstract class provides the SecurityInterface to the managers.
+ *
+ * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
+ * @version $Id:$
+ */
+public abstract class TorqueAbstractDynamicGroup extends TorqueAbstractSecurityEntity
+ implements DynamicGroup
+{
+ /** a cache of user objects */
+ private Set userSet = null;
+
+ /** a cache of role objects */
+ private Set roleSet = null;
+
+ /**
+ * Forward reference to generated code
+ *
+ * Get a list of association objects, pre-populated with their TorqueDynamicUser
+ * objects.
+ *
+ * @param criteria Criteria to define the selection of records
+ * @throws TorqueException
+ *
+ * @return a list of User/Group relations
+ */
+ protected abstract List getTorqueDynamicUserGroupsJoinTorqueDynamicUser(Criteria criteria)
+ throws TorqueException;
+
+ /**
+ * Forward reference to generated code
+ *
+ * Get a list of association objects, pre-populated with their TorqueDynamicRole
+ * objects.
+ *
+ * @param criteria Criteria to define the selection of records
+ * @throws TorqueException
+ *
+ * @return a list of Role/Group relations
+ */
+ protected abstract List getTorqueDynamicGroupRolesJoinTorqueDynamicRole(Criteria criteria)
+ throws TorqueException;
+
+ /**
+ * @see org.apache.fulcrum.security.model.basic.entity.BasicGroup#addUser(org.apache.fulcrum.security.entity.User)
+ */
+ public void addUser(User user)
+ {
+ getUsers().add(user);
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.basic.entity.BasicGroup#getUsers()
+ */
+ public UserSet getUsers()
+ {
+ if (userSet == null)
+ {
+ userSet = new UserSet();
+ }
+ else if(!(userSet instanceof UserSet))
+ {
+ userSet = new UserSet(userSet);
+ }
+
+ return (UserSet)userSet;
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.basic.entity.BasicGroup#getUsersAsSet()
+ */
+ public Set getUsersAsSet()
+ {
+ return userSet;
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.basic.entity.BasicGroup#removeUser(org.apache.fulcrum.security.entity.User)
+ */
+ public void removeUser(User user)
+ {
+ getUsers().remove(user);
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.basic.entity.BasicGroup#setUsers(org.apache.fulcrum.security.util.UserSet)
+ */
+ public void setUsers(UserSet userSet)
+ {
+ if(userSet != null)
+ {
+ this.userSet = userSet;
+ }
+ else
+ {
+ this.userSet = new UserSet();
+ }
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.basic.entity.BasicGroup#setUsersAsSet(java.util.Set)
+ */
+ public void setUsersAsSet(Set users)
+ {
+ setUsers(new UserSet(users));
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicGroup#addRole(org.apache.fulcrum.security.entity.Role)
+ */
+ public void addRole(Role role)
+ {
+ getRoles().add(role);
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicGroup#getRoles()
+ */
+ public RoleSet getRoles()
+ {
+ if (roleSet == null)
+ {
+ roleSet = new RoleSet();
+ }
+ else if(!(roleSet instanceof RoleSet))
+ {
+ roleSet = new RoleSet(roleSet);
+ }
+
+ return (RoleSet)roleSet;
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicGroup#getRolesAsSet()
+ */
+ public Set getRolesAsSet()
+ {
+ return roleSet;
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicGroup#removeRole(org.apache.fulcrum.security.entity.Role)
+ */
+ public void removeRole(Role role)
+ {
+ getRoles().remove(role);
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicGroup#setRoles(org.apache.fulcrum.security.util.RoleSet)
+ */
+ public void setRoles(RoleSet roleSet)
+ {
+ if(roleSet != null)
+ {
+ this.roleSet = roleSet;
+ }
+ else
+ {
+ this.roleSet = new RoleSet();
+ }
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicGroup#setRolesAsSet(java.util.Set)
+ */
+ public void setRolesAsSet(Set roles)
+ {
+ setRoles(new RoleSet(roles));
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#getDatabaseName()
+ */
+ public String getDatabaseName()
+ {
+ return TorqueDynamicGroupPeer.DATABASE_NAME;
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#retrieveAttachedObjects(java.sql.Connection)
+ */
+ public void retrieveAttachedObjects(Connection con) throws TorqueException
+ {
+ this.userSet = new UserSet();
+
+ // the generated method that allows a Connection parameter is missing
+ List usergroups = getTorqueDynamicUserGroupsJoinTorqueDynamicUser(new Criteria());
+
+ for (Iterator i = usergroups.iterator(); i.hasNext();)
+ {
+ TorqueDynamicUserGroup tdug = (TorqueDynamicUserGroup)i.next();
+ userSet.add(tdug.getTorqueDynamicUser());
+ }
+
+ this.roleSet = new RoleSet();
+
+ // the generated method that allows a Connection parameter is missing
+ List grouproles = getTorqueDynamicGroupRolesJoinTorqueDynamicRole(new Criteria());
+
+ for (Iterator i = grouproles.iterator(); i.hasNext();)
+ {
+ TorqueDynamicGroupRole tdgr = (TorqueDynamicGroupRole)i.next();
+ roleSet.add(tdgr.getTorqueDynamicRole());
+ }
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#update(java.sql.Connection)
+ */
+ public void update(Connection con) throws TorqueException
+ {
+ if (userSet != null)
+ {
+ Criteria criteria = new Criteria();
+
+ /* remove old entries */
+ criteria.add(TorqueDynamicUserGroupPeer.GROUP_ID, getEntityId());
+ TorqueDynamicUserGroupPeer.doDelete(criteria, con);
+
+ for (Iterator i = userSet.iterator(); i.hasNext();)
+ {
+ TorqueDynamicUser user = (TorqueDynamicUser)i.next();
+
+ TorqueDynamicUserGroup ug = new TorqueDynamicUserGroup();
+ ug.setUserId(user.getEntityId());
+ ug.setGroupId(getEntityId());
+ ug.save(con);
+ }
+ }
+
+ if (roleSet != null)
+ {
+ Criteria criteria = new Criteria();
+
+ /* remove old entries */
+ criteria.add(TorqueDynamicGroupRolePeer.GROUP_ID, getEntityId());
+ TorqueDynamicGroupRolePeer.doDelete(criteria, con);
+
+ for (Iterator i = roleSet.iterator(); i.hasNext();)
+ {
+ TorqueDynamicRole role = (TorqueDynamicRole)i.next();
+
+ TorqueDynamicGroupRole gr = new TorqueDynamicGroupRole();
+ gr.setRoleId(role.getEntityId());
+ gr.setGroupId(getEntityId());
+ gr.save(con);
+ }
+ }
+
+ try
+ {
+ save(con);
+ }
+ catch (Exception e)
+ {
+ throw new TorqueException(e);
+ }
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#delete()
+ */
+ public void delete() throws TorqueException
+ {
+ TorqueDynamicGroupPeer.doDelete(SimpleKey.keyFor(getEntityId()));
+ }
+}
\ No newline at end of file
Added: jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueAbstractDynamicPermission.java
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueAbstractDynamicPermission.java?view=auto&rev=525904
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueAbstractDynamicPermission.java (added)
+++ jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueAbstractDynamicPermission.java Thu Apr 5 10:28:53 2007
@@ -0,0 +1,189 @@
+package org.apache.fulcrum.security.torque.dynamic;
+/*
+ * Copyright 2001-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import java.sql.Connection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.fulcrum.security.entity.Role;
+import org.apache.fulcrum.security.model.dynamic.entity.DynamicPermission;
+import org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicPermissionPeer;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicRole;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicRolePermission;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicRolePermissionPeer;
+import org.apache.fulcrum.security.util.RoleSet;
+import org.apache.torque.TorqueException;
+import org.apache.torque.om.SimpleKey;
+import org.apache.torque.util.Criteria;
+/**
+ * This abstract class provides the SecurityInterface to the managers.
+ *
+ * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
+ * @version $Id:$
+ */
+public abstract class TorqueAbstractDynamicPermission extends TorqueAbstractSecurityEntity
+ implements DynamicPermission
+{
+ /** a cache of role objects */
+ private Set roleSet = null;
+
+ /**
+ * Forward reference to generated code
+ *
+ * Get a list of association objects, pre-populated with their TorqueDynamicRole
+ * objects.
+ *
+ * @param criteria Criteria to define the selection of records
+ * @throws TorqueException
+ *
+ * @return a list of Role/Permission relations
+ */
+ protected abstract List getTorqueDynamicRolePermissionsJoinTorqueDynamicRole(Criteria criteria)
+ throws TorqueException;
+
+ /**
+ * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicPermission#addRole(org.apache.fulcrum.security.entity.Role)
+ */
+ public void addRole(Role role)
+ {
+ getRoles().add(role);
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicPermission#getRoles()
+ */
+ public RoleSet getRoles()
+ {
+ if (roleSet == null)
+ {
+ roleSet = new RoleSet();
+ }
+ else if(!(roleSet instanceof RoleSet))
+ {
+ roleSet = new RoleSet(roleSet);
+ }
+
+ return (RoleSet)roleSet;
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicPermission#getRolesAsSet()
+ */
+ public Set getRolesAsSet()
+ {
+ return roleSet;
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicPermission#removeRole(org.apache.fulcrum.security.entity.Role)
+ */
+ public void removeRole(Role role)
+ {
+ getRoles().remove(role);
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicPermission#setRoles(org.apache.fulcrum.security.util.RoleSet)
+ */
+ public void setRoles(RoleSet roleSet)
+ {
+ if (roleSet != null)
+ {
+ this.roleSet = roleSet;
+ }
+ else
+ {
+ this.roleSet = new RoleSet();
+ }
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicPermission#setRolesAsSet(java.util.Set)
+ */
+ public void setRolesAsSet(Set roles)
+ {
+ setRoles(new RoleSet(roles));
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#getDatabaseName()
+ */
+ public String getDatabaseName()
+ {
+ return TorqueDynamicPermissionPeer.DATABASE_NAME;
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#retrieveAttachedObjects(java.sql.Connection)
+ */
+ public void retrieveAttachedObjects(Connection con) throws TorqueException
+ {
+ this.roleSet = new RoleSet();
+
+ // the generated method that allows a Connection parameter is missing
+ List rolepermissions = getTorqueDynamicRolePermissionsJoinTorqueDynamicRole(new Criteria());
+
+ for (Iterator i = rolepermissions.iterator(); i.hasNext();)
+ {
+ TorqueDynamicRolePermission tdrp = (TorqueDynamicRolePermission)i.next();
+ roleSet.add(tdrp.getTorqueDynamicRole());
+ }
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#update(java.sql.Connection)
+ */
+ public void update(Connection con) throws TorqueException
+ {
+ if (roleSet != null)
+ {
+ Criteria criteria = new Criteria();
+
+ /* remove old entries */
+ criteria.add(TorqueDynamicRolePermissionPeer.PERMISSION_ID, getEntityId());
+ TorqueDynamicRolePermissionPeer.doDelete(criteria, con);
+
+ for (Iterator i = roleSet.iterator(); i.hasNext();)
+ {
+ TorqueDynamicRole role = (TorqueDynamicRole)i.next();
+
+ TorqueDynamicRolePermission rp = new TorqueDynamicRolePermission();
+ rp.setRoleId(role.getEntityId());
+ rp.setPermissionId(getEntityId());
+ rp.save(con);
+ }
+ }
+
+ try
+ {
+ save(con);
+ }
+ catch (Exception e)
+ {
+ throw new TorqueException(e);
+ }
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#delete()
+ */
+ public void delete() throws TorqueException
+ {
+ TorqueDynamicPermissionPeer.doDelete(SimpleKey.keyFor(getEntityId()));
+ }
+}
\ No newline at end of file
Added: jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueAbstractDynamicRole.java
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueAbstractDynamicRole.java?view=auto&rev=525904
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueAbstractDynamicRole.java (added)
+++ jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueAbstractDynamicRole.java Thu Apr 5 10:28:53 2007
@@ -0,0 +1,306 @@
+package org.apache.fulcrum.security.torque.dynamic;
+/*
+ * Copyright 2001-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import java.sql.Connection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.fulcrum.security.entity.Group;
+import org.apache.fulcrum.security.entity.Permission;
+import org.apache.fulcrum.security.model.dynamic.entity.DynamicRole;
+import org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicGroup;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicGroupRole;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicGroupRolePeer;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicPermission;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicPermissionPeer;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicRolePeer;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicRolePermission;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicRolePermissionPeer;
+import org.apache.fulcrum.security.util.GroupSet;
+import org.apache.fulcrum.security.util.PermissionSet;
+import org.apache.torque.TorqueException;
+import org.apache.torque.om.SimpleKey;
+import org.apache.torque.util.Criteria;
+/**
+ * This abstract class provides the SecurityInterface to the managers.
+ *
+ * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
+ * @version $Id:$
+ */
+public abstract class TorqueAbstractDynamicRole extends TorqueAbstractSecurityEntity
+ implements DynamicRole
+{
+ /** a cache of group objects */
+ private Set groupSet = null;
+
+ /** a cache of permission objects */
+ private Set permissionSet = null;
+
+ /**
+ * Forward reference to generated code
+ *
+ * Get a list of association objects, pre-populated with their TorqueDynamicPermission
+ * objects.
+ *
+ * @param criteria Criteria to define the selection of records
+ * @throws TorqueException
+ *
+ * @return a list of Role/Permission relations
+ */
+ protected abstract List getTorqueDynamicRolePermissionsJoinTorqueDynamicPermission(Criteria criteria)
+ throws TorqueException;
+
+ /**
+ * Forward reference to generated code
+ *
+ * Get a list of association objects, pre-populated with their TorqueDynamicGroup
+ * objects.
+ *
+ * @param criteria Criteria to define the selection of records
+ * @throws TorqueException
+ *
+ * @return a list of Group/Role relations
+ */
+ protected abstract List getTorqueDynamicGroupRolesJoinTorqueDynamicGroup(Criteria criteria)
+ throws TorqueException;
+
+ /**
+ * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#addGroup(org.apache.fulcrum.security.entity.Group)
+ */
+ public void addGroup(Group group)
+ {
+ getGroups().add(group);
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#addPermission(org.apache.fulcrum.security.entity.Permission)
+ */
+ public void addPermission(Permission permission)
+ {
+ getPermissions().add(permission);
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#getGroups()
+ */
+ public GroupSet getGroups()
+ {
+ if (groupSet == null)
+ {
+ groupSet = new GroupSet();
+ }
+ else if(!(groupSet instanceof GroupSet))
+ {
+ groupSet = new GroupSet(groupSet);
+ }
+
+ return (GroupSet)groupSet;
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#getGroupsAsSet()
+ */
+ public Set getGroupsAsSet()
+ {
+ return groupSet;
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#getPermissions()
+ */
+ public PermissionSet getPermissions()
+ {
+ if (permissionSet == null)
+ {
+ permissionSet = new PermissionSet();
+ }
+ else if(!(permissionSet instanceof PermissionSet))
+ {
+ permissionSet = new PermissionSet(permissionSet);
+ }
+
+ return (PermissionSet)permissionSet;
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#getPermissionsAsSet()
+ */
+ public Set getPermissionsAsSet()
+ {
+ return permissionSet;
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#removeGroup(org.apache.fulcrum.security.entity.Group)
+ */
+ public void removeGroup(Group group)
+ {
+ getGroups().remove(group);
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#removePermission(org.apache.fulcrum.security.entity.Permission)
+ */
+ public void removePermission(Permission permission)
+ {
+ getPermissions().remove(permission);
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#setGroups(org.apache.fulcrum.security.util.GroupSet)
+ */
+ public void setGroups(GroupSet groups)
+ {
+ if (groups != null)
+ {
+ this.groupSet = groups;
+ }
+ else
+ {
+ this.groupSet = new GroupSet();
+ }
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#setGroupsAsSet(java.util.Set)
+ */
+ public void setGroupsAsSet(Set groups)
+ {
+ setGroups(new GroupSet(groups));
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#setPermissions(org.apache.fulcrum.security.util.PermissionSet)
+ */
+ public void setPermissions(PermissionSet permissionSet)
+ {
+ if (permissionSet != null)
+ {
+ this.permissionSet = permissionSet;
+ }
+ else
+ {
+ this.permissionSet = new PermissionSet();
+ }
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#setPermissionsAsSet(java.util.Set)
+ */
+ public void setPermissionsAsSet(Set permissions)
+ {
+ setPermissions(new PermissionSet(permissions));
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#getDatabaseName()
+ */
+ public String getDatabaseName()
+ {
+ return TorqueDynamicPermissionPeer.DATABASE_NAME;
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#retrieveAttachedObjects(java.sql.Connection)
+ */
+ public void retrieveAttachedObjects(Connection con) throws TorqueException
+ {
+ this.permissionSet = new PermissionSet();
+
+ // the generated method that allows a Connection parameter is missing
+ List rolepermissions = getTorqueDynamicRolePermissionsJoinTorqueDynamicPermission(new Criteria());
+
+ for (Iterator i = rolepermissions.iterator(); i.hasNext();)
+ {
+ TorqueDynamicRolePermission tdrp = (TorqueDynamicRolePermission)i.next();
+ permissionSet.add(tdrp.getTorqueDynamicPermission());
+ }
+
+ this.groupSet = new GroupSet();
+
+ // the generated method that allows a Connection parameter is missing
+ List grouproles = getTorqueDynamicGroupRolesJoinTorqueDynamicGroup(new Criteria());
+
+ for (Iterator i = grouproles.iterator(); i.hasNext();)
+ {
+ TorqueDynamicGroupRole tdgr = (TorqueDynamicGroupRole)i.next();
+ groupSet.add(tdgr.getTorqueDynamicGroup());
+ }
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#update(java.sql.Connection)
+ */
+ public void update(Connection con) throws TorqueException
+ {
+ if (permissionSet != null)
+ {
+ Criteria criteria = new Criteria();
+
+ /* remove old entries */
+ criteria.add(TorqueDynamicRolePermissionPeer.ROLE_ID, getEntityId());
+ TorqueDynamicRolePermissionPeer.doDelete(criteria, con);
+
+ for (Iterator i = permissionSet.iterator(); i.hasNext();)
+ {
+ TorqueDynamicPermission permission = (TorqueDynamicPermission)i.next();
+
+ TorqueDynamicRolePermission rp = new TorqueDynamicRolePermission();
+ rp.setPermissionId(permission.getEntityId());
+ rp.setRoleId(getEntityId());
+ rp.save(con);
+ }
+ }
+
+ if (groupSet != null)
+ {
+ Criteria criteria = new Criteria();
+
+ /* remove old entries */
+ criteria.add(TorqueDynamicGroupRolePeer.ROLE_ID, getEntityId());
+ TorqueDynamicGroupRolePeer.doDelete(criteria, con);
+
+ for (Iterator i = groupSet.iterator(); i.hasNext();)
+ {
+ TorqueDynamicGroup group = (TorqueDynamicGroup)i.next();
+
+ TorqueDynamicGroupRole gr = new TorqueDynamicGroupRole();
+ gr.setGroupId(group.getEntityId());
+ gr.setRoleId(getEntityId());
+ gr.save(con);
+ }
+ }
+
+ try
+ {
+ save(con);
+ }
+ catch (Exception e)
+ {
+ throw new TorqueException(e);
+ }
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#delete()
+ */
+ public void delete() throws TorqueException
+ {
+ TorqueDynamicRolePeer.doDelete(SimpleKey.keyFor(getEntityId()));
+ }
+}
\ No newline at end of file
Added: jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueAbstractDynamicUser.java
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueAbstractDynamicUser.java?view=auto&rev=525904
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueAbstractDynamicUser.java (added)
+++ jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueAbstractDynamicUser.java Thu Apr 5 10:28:53 2007
@@ -0,0 +1,340 @@
+package org.apache.fulcrum.security.torque.dynamic;
+/*
+ * Copyright 2001-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import java.sql.Connection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.fulcrum.security.entity.Group;
+import org.apache.fulcrum.security.model.dynamic.entity.DynamicUser;
+import org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicGroup;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicUser;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicUserDelegates;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicUserDelegatesPeer;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicUserGroup;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicUserGroupPeer;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicUserPeer;
+import org.apache.fulcrum.security.util.GroupSet;
+import org.apache.torque.TorqueException;
+import org.apache.torque.om.SimpleKey;
+import org.apache.torque.util.Criteria;
+/**
+ * This abstract class provides the SecurityInterface to the managers.
+ *
+ * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
+ * @version $Id:$
+ */
+public abstract class TorqueAbstractDynamicUser extends TorqueAbstractSecurityEntity
+ implements DynamicUser
+{
+ /** a cache of group objects */
+ private Set groupSet = null;
+
+ /** a cache of delegator (user) objects */
+ private Set delegators = null;
+
+ /** a cache of delegatee(user) objects */
+ private Set delegatees = null;
+
+ /**
+ * Forward reference to generated code
+ *
+ * Get a list of association objects, pre-populated with their TorqueDynamicGroup
+ * objects.
+ *
+ * @param criteria Criteria to define the selection of records
+ * @throws TorqueException
+ *
+ * @return a list of User/Group relations
+ */
+ protected abstract List getTorqueDynamicUserGroupsJoinTorqueDynamicGroup(Criteria criteria)
+ throws TorqueException;
+
+ /**
+ * Forward reference to generated code
+ *
+ * Get a list of delegator association objects, pre-populated with their
+ * TorqueDynamicUserDelegates objects.
+ *
+ * @param criteria Criteria to define the selection of records
+ * @throws TorqueException
+ *
+ * @return a list of User/Delegator relations
+ */
+ protected abstract List getTorqueDynamicUserDelegatessRelatedByDelegateeUserIdJoinTorqueDynamicUserRelatedByDelegatorUserId(Criteria criteria)
+ throws TorqueException;
+
+ /**
+ * Forward reference to generated code
+ *
+ * Get a list of delegatee association objects, pre-populated with their
+ * TorqueDynamicUserDelegates objects.
+ *
+ * @param criteria Criteria to define the selection of records
+ * @throws TorqueException
+ *
+ * @return a list of User/Delegator relations
+ */
+ protected abstract List getTorqueDynamicUserDelegatessRelatedByDelegatorUserIdJoinTorqueDynamicUserRelatedByDelegateeUserId(Criteria criteria)
+ throws TorqueException;
+
+ /**
+ * @see org.apache.fulcrum.security.model.basic.entity.BasicUser#addGroup(org.apache.fulcrum.security.entity.Group)
+ */
+ public void addGroup(Group group)
+ {
+ getGroups().add(group);
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.basic.entity.BasicUser#getGroups()
+ */
+ public GroupSet getGroups()
+ {
+ if (groupSet == null)
+ {
+ groupSet = new GroupSet();
+ }
+ else if(!(groupSet instanceof GroupSet))
+ {
+ groupSet = new GroupSet(groupSet);
+ }
+
+ return (GroupSet)groupSet;
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.basic.entity.BasicUser#getGroupsAsSet()
+ */
+ public Set getGroupsAsSet()
+ {
+ return groupSet;
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.basic.entity.BasicUser#removeGroup(org.apache.fulcrum.security.entity.Group)
+ */
+ public void removeGroup(Group group)
+ {
+ getGroups().remove(group);
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.basic.entity.BasicUser#setGroups(org.apache.fulcrum.security.util.GroupSet)
+ */
+ public void setGroups(GroupSet groups)
+ {
+ if (groups != null)
+ {
+ this.groupSet = groups;
+ }
+ else
+ {
+ this.groupSet = new GroupSet();
+ }
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.basic.entity.BasicUser#setGroupsAsSet(java.util.Set)
+ */
+ public void setGroupsAsSet(Set groups)
+ {
+ setGroups(new GroupSet(groups));
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicUser#getDelegatees()
+ */
+ public Set getDelegatees()
+ {
+ if (delegatees == null)
+ {
+ delegatees = new HashSet();
+ }
+
+ return delegatees;
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicUser#getDelegators()
+ */
+ public Set getDelegators()
+ {
+ if (delegators == null)
+ {
+ delegators = new HashSet();
+ }
+
+ return delegators;
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicUser#setDelegatees(java.util.Set)
+ */
+ public void setDelegatees(Set delegatees)
+ {
+ if (delegatees != null)
+ {
+ this.delegatees = delegatees;
+ }
+ else
+ {
+ this.delegatees = new HashSet();
+ }
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicUser#setDelegators(java.util.Set)
+ */
+ public void setDelegators(Set delegates)
+ {
+ if (delegators != null)
+ {
+ this.delegators = delegates;
+ }
+ else
+ {
+ this.delegators = new HashSet();
+ }
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#getDatabaseName()
+ */
+ public String getDatabaseName()
+ {
+ return TorqueDynamicUserPeer.DATABASE_NAME;
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#retrieveAttachedObjects(java.sql.Connection)
+ */
+ public void retrieveAttachedObjects(Connection con) throws TorqueException
+ {
+ this.groupSet = new GroupSet();
+
+ List usergroups = getTorqueDynamicUserGroupsJoinTorqueDynamicGroup(new Criteria());
+
+ for (Iterator i = usergroups.iterator(); i.hasNext();)
+ {
+ TorqueDynamicUserGroup tdug = (TorqueDynamicUserGroup)i.next();
+ groupSet.add(tdug.getTorqueDynamicGroup());
+ }
+
+ this.delegators = new HashSet();
+
+ List delegatorlist = getTorqueDynamicUserDelegatessRelatedByDelegateeUserIdJoinTorqueDynamicUserRelatedByDelegatorUserId(new Criteria());
+
+ for (Iterator i = delegatorlist.iterator(); i.hasNext();)
+ {
+ TorqueDynamicUserDelegates tdud = (TorqueDynamicUserDelegates)i.next();
+ delegators.add(tdud.getTorqueDynamicUserRelatedByDelegatorUserId());
+ }
+
+ this.delegatees = new HashSet();
+
+ List delegateelist = getTorqueDynamicUserDelegatessRelatedByDelegatorUserIdJoinTorqueDynamicUserRelatedByDelegateeUserId(new Criteria());
+
+ for (Iterator i = delegateelist.iterator(); i.hasNext();)
+ {
+ TorqueDynamicUserDelegates tdud = (TorqueDynamicUserDelegates)i.next();
+ delegatees.add(tdud.getTorqueDynamicUserRelatedByDelegateeUserId());
+ }
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#update(java.sql.Connection)
+ */
+ public void update(Connection con) throws TorqueException
+ {
+ if (groupSet != null)
+ {
+ Criteria criteria = new Criteria();
+
+ /* remove old entries */
+ criteria.add(TorqueDynamicUserGroupPeer.USER_ID, getEntityId());
+ TorqueDynamicUserGroupPeer.doDelete(criteria, con);
+
+ for (Iterator i = groupSet.iterator(); i.hasNext();)
+ {
+ TorqueDynamicGroup group = (TorqueDynamicGroup)i.next();
+
+ TorqueDynamicUserGroup ug = new TorqueDynamicUserGroup();
+ ug.setUserId(getEntityId());
+ ug.setGroupId(group.getEntityId());
+ ug.save(con);
+ }
+ }
+
+ if (delegators != null)
+ {
+ Criteria criteria = new Criteria();
+
+ /* remove old entries */
+ criteria.add(TorqueDynamicUserDelegatesPeer.DELEGATEE_USER_ID, getEntityId());
+ TorqueDynamicUserDelegatesPeer.doDelete(criteria, con);
+
+ for (Iterator i = delegators.iterator(); i.hasNext();)
+ {
+ TorqueDynamicUser user = (TorqueDynamicUser)i.next();
+
+ TorqueDynamicUserDelegates ud = new TorqueDynamicUserDelegates();
+ ud.setDelegateeUserId(getEntityId());
+ ud.setDelegatorUserId(user.getEntityId());
+ ud.save(con);
+ }
+ }
+
+ if (delegatees != null)
+ {
+ Criteria criteria = new Criteria();
+
+ /* remove old entries */
+ criteria.add(TorqueDynamicUserDelegatesPeer.DELEGATOR_USER_ID, getEntityId());
+ TorqueDynamicUserDelegatesPeer.doDelete(criteria, con);
+
+ for (Iterator i = delegatees.iterator(); i.hasNext();)
+ {
+ TorqueDynamicUser user = (TorqueDynamicUser)i.next();
+
+ TorqueDynamicUserDelegates ud = new TorqueDynamicUserDelegates();
+ ud.setDelegatorUserId(getEntityId());
+ ud.setDelegateeUserId(user.getEntityId());
+ ud.save(con);
+ }
+ }
+
+ try
+ {
+ save(con);
+ }
+ catch (Exception e)
+ {
+ throw new TorqueException(e);
+ }
+ }
+
+ /**
+ * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#delete()
+ */
+ public void delete() throws TorqueException
+ {
+ TorqueDynamicUserPeer.doDelete(SimpleKey.keyFor(getEntityId()));
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org