001: /* Copyright 2002 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal.groups;
007:
008: import org.jasig.portal.concurrency.IEntityLock;
009:
010: /**
011: * Extends <code>EntityGroupImpl</code> to make it lockable for writing.
012: * <p>
013: * @author Dan Ellentuck
014: * @version $Revision: 34758 $
015: */
016:
017: public class LockableEntityGroupImpl extends EntityGroupImpl implements
018: ILockableEntityGroup {
019: protected IEntityLock lock;
020:
021: /**
022: * LockableEntityGroupImpl constructor.
023: * @param groupKey java.lang.String
024: * @param groupType java.lang.Class
025: * @exception GroupsException
026: */
027: public LockableEntityGroupImpl(String groupKey, Class groupType)
028: throws GroupsException {
029: super (groupKey, groupType);
030: }
031:
032: /**
033: * Delegates to the factory.
034: */
035: public void delete() throws GroupsException {
036: getLockableGroupService().deleteGroup(this );
037: }
038:
039: /**
040: * @return org.jasig.portal.concurrency.IEntityLock
041: */
042: public IEntityLock getLock() {
043: return lock;
044: }
045:
046: /**
047: * @return org.jasig.portal.groups.ILockableGroupService
048: */
049: protected ILockableGroupService getLockableGroupService()
050: throws GroupsException {
051: return (ILockableGroupService) super .getLocalGroupService();
052: }
053:
054: /**
055: * Ask the service to update this group (in the store), update the
056: * back-pointers of the updated members, and force the retrieval of
057: * containing groups in case the memberships of THIS group have
058: * changed during the time the group has been locked.
059: */
060: private void primUpdate(boolean renewLock) throws GroupsException {
061: getLockableGroupService().updateGroup(this , renewLock);
062: clearPendingUpdates();
063: setGroupKeysInitialized(false);
064: }
065:
066: /**
067: * Ask the service to update this group (in the store), update the
068: * back-pointers of the updated members, and force the retrieval of
069: * containing groups in case the memberships of THIS group have
070: * changed during the time the group has been locked.
071: */
072: private void primUpdateMembers(boolean renewLock)
073: throws GroupsException {
074: getLockableGroupService().updateGroupMembers(this , renewLock);
075: clearPendingUpdates();
076: setGroupKeysInitialized(false);
077: }
078:
079: /**
080: * @param newLock org.jasig.portal.concurrency.IEntityLock
081: */
082: public void setLock(IEntityLock newLock) {
083: lock = newLock;
084: }
085:
086: /**
087: */
088: public String toString() {
089: return "LockableEntityGroupImpl (" + getKey() + ") "
090: + getName();
091: }
092:
093: /**
094: *
095: */
096: public void update() throws GroupsException {
097: primUpdate(false);
098: }
099:
100: /**
101: *
102: */
103: public void updateAndRenewLock() throws GroupsException {
104: primUpdate(true);
105: }
106:
107: /**
108: *
109: */
110: public void updateMembers() throws GroupsException {
111: primUpdateMembers(false);
112: }
113:
114: /**
115: *
116: */
117: public void updateMembersAndRenewLock() throws GroupsException {
118: primUpdateMembers(true);
119: }
120:
121: }
|