From do-not-reply at jboss.org Fri Oct 16 04:08:49 2009
Content-Type: multipart/mixed; boundary="===============5271443780269397044=="
MIME-Version: 1.0
From: do-not-reply at jboss.org
To: exo-jcr-commits at lists.jboss.org
Subject: [exo-jcr-commits] exo-jcr SVN: r287 - in
core/trunk/component/organization/api/src/main/java/org/exoplatform/services/organization:
cache and 1 other directory.
Date: Fri, 16 Oct 2009 04:08:49 -0400
Message-ID: <200910160808.n9G88niV002747@svn01.web.mwc.hst.phx2.redhat.com>
--===============5271443780269397044==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Author: tolusha
Date: 2009-10-16 04:08:49 -0400 (Fri, 16 Oct 2009)
New Revision: 287
Added:
core/trunk/component/organization/api/src/main/java/org/exoplatform/serv=
ices/organization/cache/
core/trunk/component/organization/api/src/main/java/org/exoplatform/serv=
ices/organization/cache/CacheableGroupHandlerImpl.java
core/trunk/component/organization/api/src/main/java/org/exoplatform/serv=
ices/organization/cache/CacheableMembershipHandlerImpl.java
core/trunk/component/organization/api/src/main/java/org/exoplatform/serv=
ices/organization/cache/CacheableMembershipTypeHandlerImpl.java
core/trunk/component/organization/api/src/main/java/org/exoplatform/serv=
ices/organization/cache/CacheableUserHandlerImpl.java
core/trunk/component/organization/api/src/main/java/org/exoplatform/serv=
ices/organization/cache/CacheableUserProfileHandlerImpl.java
core/trunk/component/organization/api/src/main/java/org/exoplatform/serv=
ices/organization/cache/MembershipCacheKey.java
core/trunk/component/organization/api/src/main/java/org/exoplatform/serv=
ices/organization/cache/OrganizationCacheHandler.java
Log:
EXOJCR-186: cacheable handlers
Added: core/trunk/component/organization/api/src/main/java/org/exoplatform/=
services/organization/cache/CacheableGroupHandlerImpl.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- core/trunk/component/organization/api/src/main/java/org/exoplatform/ser=
vices/organization/cache/CacheableGroupHandlerImpl.java =
(rev 0)
+++ core/trunk/component/organization/api/src/main/java/org/exoplatform/ser=
vices/organization/cache/CacheableGroupHandlerImpl.java 2009-10-16 08:08:49=
UTC (rev 287)
@@ -0,0 +1,191 @@
+/*
+ * Copyright (C) 2003-2009 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see.
+ */
+package org.exoplatform.services.organization.cache;
+
+import org.exoplatform.services.cache.ExoCache;
+import org.exoplatform.services.organization.Group;
+import org.exoplatform.services.organization.GroupEventListener;
+import org.exoplatform.services.organization.GroupHandler;
+import org.exoplatform.services.organization.Membership;
+import org.exoplatform.services.organization.UserHandler;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * Created by The eXo Platform SAS.
+ * =
+ *
Date: 2009
+ *
+ * @author Anatoliy=
Bazko =
+ * @version $Id$
+ */
+public class CacheableGroupHandlerImpl implements GroupHandler
+{
+
+ private final ExoCache groupCache;
+
+ private final ExoCache membershipCache;
+
+ private final GroupHandler groupHandler;
+
+ /**
+ * CacheableUserHandler constructor.
+ *
+ * @param OrganizationCacheHandler
+ * - organization cache handler
+ * @param handler
+ * - user handler
+ */
+ public CacheableGroupHandlerImpl(OrganizationCacheHandler organizationC=
acheHandler, GroupHandler handler)
+ {
+ this.groupCache =3D organizationCacheHandler.getGroupCache();
+ this.membershipCache =3D organizationCacheHandler.getMembershipCache=
();
+ this.groupHandler =3D handler;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addChild(Group parent, Group child, boolean broadcast) thro=
ws Exception
+ {
+ groupHandler.addChild(parent, child, broadcast);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addGroupEventListener(GroupEventListener listener)
+ {
+ groupHandler.addGroupEventListener(listener);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void createGroup(Group group, boolean broadcast) throws Exception
+ {
+ groupHandler.createGroup(group, broadcast);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Group createGroupInstance()
+ {
+ return groupHandler.createGroupInstance();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Group findGroupById(String groupId) throws Exception
+ {
+ Group group =3D (Group)groupCache.get(groupId);
+ if (group !=3D null)
+ return group;
+
+ group =3D groupHandler.findGroupById(groupId);
+ if (group !=3D null)
+ groupCache.put(groupId, group);
+
+ return group;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Collection findGroupByMembership(String userName, String members=
hipType) throws Exception
+ {
+ Collection groups =3D groupHandler.findGroupByMembership(user=
Name, membershipType);
+
+ for (Group group : groups)
+ groupCache.put(group.getId(), groups);
+
+ return groups;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Collection findGroups(Group parent) throws Exception
+ {
+ Collection groups =3D groupHandler.findGroups(parent);
+ for (Group group : groups)
+ groupCache.put(group.getId(), groups);
+
+ return groups;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Collection findGroupsOfUser(String user) throws Exception
+ {
+ Collection groups =3D groupHandler.findGroupsOfUser(user);
+ for (Group group : groups)
+ groupCache.put(group.getId(), groups);
+
+ return groups;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Collection getAllGroups() throws Exception
+ {
+ Collection groups =3D groupHandler.getAllGroups();
+ for (Group group : groups)
+ groupCache.put(group.getId(), groups);
+
+ return groups;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Group removeGroup(Group group, boolean broadcast) throws Excepti=
on
+ {
+ Group gr =3D groupHandler.removeGroup(group, broadcast);
+ if (gr !=3D null)
+ {
+ groupCache.remove(gr.getId());
+
+ List memberships =3D membershipCache.getCachedObjects=
();
+ for (Membership membership : memberships)
+ {
+ if (membership.getGroupId().equals(gr.getId()))
+ {
+ membershipCache.remove(membership.getId());
+ membershipCache.remove(new MembershipCacheKey(membership));
+ }
+ }
+ }
+
+ return gr;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void saveGroup(Group group, boolean broadcast) throws Exception
+ {
+ groupHandler.saveGroup(group, broadcast);
+ groupCache.put(group.getId(), group);
+ }
+
+}
Property changes on: core/trunk/component/organization/api/src/main/java/or=
g/exoplatform/services/organization/cache/CacheableGroupHandlerImpl.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: core/trunk/component/organization/api/src/main/java/org/exoplatform/=
services/organization/cache/CacheableMembershipHandlerImpl.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- core/trunk/component/organization/api/src/main/java/org/exoplatform/ser=
vices/organization/cache/CacheableMembershipHandlerImpl.java =
(rev 0)
+++ core/trunk/component/organization/api/src/main/java/org/exoplatform/ser=
vices/organization/cache/CacheableMembershipHandlerImpl.java 2009-10-16 08:=
08:49 UTC (rev 287)
@@ -0,0 +1,208 @@
+/*
+ * Copyright (C) 2003-2009 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see.
+ */
+package org.exoplatform.services.organization.cache;
+
+import com.sun.org.apache.bcel.internal.generic.RETURN;
+
+import org.exoplatform.services.cache.ExoCache;
+import org.exoplatform.services.organization.Group;
+import org.exoplatform.services.organization.Membership;
+import org.exoplatform.services.organization.MembershipEventListener;
+import org.exoplatform.services.organization.MembershipHandler;
+import org.exoplatform.services.organization.MembershipType;
+import org.exoplatform.services.organization.User;
+import java.util.Collection;
+
+/**
+ * Created by The eXo Platform SAS.
+ * =
+ *
Date: 2009
+ *
+ * @author Anatoliy=
Bazko =
+ * @version $Id$
+ */
+public class CacheableMembershipHandlerImpl implements MembershipHandler
+{
+
+ private final ExoCache membershipCache;
+
+ private final MembershipHandler membershipHandler;
+
+ /**
+ * CacheableUserHandler constructor.
+ *
+ * @param organizationCacheHandler
+ * - organization cache handler
+ * @param membershipHandler
+ * - membership handler
+ */
+ public CacheableMembershipHandlerImpl(OrganizationCacheHandler organiza=
tionCacheHandler,
+ MembershipHandler membershipHandler)
+ {
+ this.membershipCache =3D organizationCacheHandler.getMembershipCache=
();
+ this.membershipHandler =3D membershipHandler;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addMembershipEventListener(MembershipEventListener listener)
+ {
+ membershipHandler.addMembershipEventListener(listener);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void createMembership(Membership m, boolean broadcast) throws Ex=
ception
+ {
+ membershipHandler.createMembership(m, broadcast);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Membership createMembershipInstance()
+ {
+ return membershipHandler.createMembershipInstance();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Membership findMembership(String id) throws Exception
+ {
+ Membership membership =3D (Membership)membershipCache.get(id);
+ if (membership !=3D null)
+ return membership;
+
+ membership =3D membershipHandler.findMembership(id);
+
+ if (membership !=3D null)
+ {
+ membershipCache.put(membership.getId(), membership);
+ membershipCache.put(new MembershipCacheKey(membership), membershi=
p);
+ }
+
+ return membership;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Membership findMembershipByUserGroupAndType(String userName, Str=
ing groupId, String type) throws Exception
+ {
+ Membership membership =3D (Membership)membershipCache.get(new Member=
shipCacheKey(userName, groupId, type));
+ if (membership !=3D null)
+ return membership;
+
+ membership =3D membershipHandler.findMembershipByUserGroupAndType(us=
erName, groupId, type);
+
+ if (membership !=3D null)
+ {
+ membershipCache.put(membership.getId(), membership);
+ membershipCache.put(new MembershipCacheKey(membership), membershi=
p);
+ }
+
+ return membership;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Collection findMembershipsByGroup(Group group) throws Exception
+ {
+ Collection memberships =3D membershipHandler.findMembers=
hipsByGroup(group);
+ for (Membership membership : memberships)
+ {
+ membershipCache.put(membership.getId(), membership);
+ membershipCache.put(new MembershipCacheKey(membership), membershi=
p);
+ }
+
+ return memberships;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Collection findMembershipsByUser(String userName) throws Excepti=
on
+ {
+ Collection memberships =3D membershipHandler.findMembers=
hipsByUser(userName);
+ for (Membership membership : memberships)
+ {
+ membershipCache.put(membership.getId(), membership);
+ membershipCache.put(new MembershipCacheKey(membership), membershi=
p);
+ }
+
+ return memberships;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Collection findMembershipsByUserAndGroup(String userName, String=
groupId) throws Exception
+ {
+ Collection memberships =3D membershipHandler.findMembers=
hipsByUserAndGroup(userName, groupId);
+ for (Membership membership : memberships)
+ {
+ membershipCache.put(membership.getId(), membership);
+ membershipCache.put(new MembershipCacheKey(membership), membershi=
p);
+ }
+
+ return memberships;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void linkMembership(User user, Group group, MembershipType m, bo=
olean broadcast) throws Exception
+ {
+ membershipHandler.linkMembership(user, group, m, broadcast);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Membership removeMembership(String id, boolean broadcast) throws=
Exception
+ {
+ Membership membership =3D membershipHandler.removeMembership(id, bro=
adcast);
+ if (membership !=3D null)
+ {
+ membershipCache.remove(membership.getId());
+ membershipCache.remove(new MembershipCacheKey(membership));
+ }
+
+ return membership;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Collection removeMembershipByUser(String username, boolean broad=
cast) throws Exception
+ {
+ Collection memberships =3D membershipHandler.removeMembe=
rshipByUser(username, broadcast);
+
+ for (Membership membership : memberships)
+ {
+ membershipCache.remove(membership.getId());
+ membershipCache.remove(new MembershipCacheKey(membership));
+ }
+
+ return memberships;
+ }
+
+}
Property changes on: core/trunk/component/organization/api/src/main/java/or=
g/exoplatform/services/organization/cache/CacheableMembershipHandlerImpl.ja=
va
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: core/trunk/component/organization/api/src/main/java/org/exoplatform/=
services/organization/cache/CacheableMembershipTypeHandlerImpl.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- core/trunk/component/organization/api/src/main/java/org/exoplatform/ser=
vices/organization/cache/CacheableMembershipTypeHandlerImpl.java =
(rev 0)
+++ core/trunk/component/organization/api/src/main/java/org/exoplatform/ser=
vices/organization/cache/CacheableMembershipTypeHandlerImpl.java 2009-10-16=
08:08:49 UTC (rev 287)
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2003-2009 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see.
+ */
+package org.exoplatform.services.organization.cache;
+
+import org.exoplatform.services.cache.ExoCache;
+import org.exoplatform.services.organization.Group;
+import org.exoplatform.services.organization.Membership;
+import org.exoplatform.services.organization.MembershipType;
+import org.exoplatform.services.organization.MembershipTypeHandler;
+import org.exoplatform.services.organization.UserHandler;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * Created by The eXo Platform SAS.
+ * =
+ *
Date: 2009
+ *
+ * @author Anatoliy=
Bazko =
+ * @version $Id$
+ */
+public class CacheableMembershipTypeHandlerImpl implements MembershipTypeH=
andler
+{
+
+ private final ExoCache membershipTypeCache;
+
+ private final ExoCache membershipCache;
+
+ private final MembershipTypeHandler membershipTypeHandler;
+
+ /**
+ * CacheableMembershipTypeHandler constructor.
+ *
+ * @param organizationCacheHandler
+ * - organization cache handler
+ * @param membershipTypeHandler
+ * - membership type handler
+ */
+ public CacheableMembershipTypeHandlerImpl(OrganizationCacheHandler orga=
nizationCacheHandler,
+ MembershipTypeHandler membershipTypeHandler)
+ {
+ this.membershipTypeCache =3D organizationCacheHandler.getMembershipT=
ypeCache();
+ this.membershipCache =3D organizationCacheHandler.getMembershipCache=
();
+ this.membershipTypeHandler =3D membershipTypeHandler;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public MembershipType createMembershipType(MembershipType mt, boolean b=
roadcast) throws Exception
+ {
+ MembershipType membershipType =3D membershipTypeHandler.createMember=
shipType(mt, broadcast);
+ membershipTypeCache.put(membershipType.getName(), membershipType);
+
+ return membershipType;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public MembershipType createMembershipTypeInstance()
+ {
+ return membershipTypeHandler.createMembershipTypeInstance();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public MembershipType findMembershipType(String name) throws Exception
+ {
+ MembershipType membershipType =3D (MembershipType)membershipTypeCach=
e.get(name);
+ if (membershipType !=3D null)
+ return membershipType;
+
+ membershipType =3D membershipTypeHandler.findMembershipType(name);
+ if (membershipType !=3D null)
+ membershipTypeCache.put(name, membershipType);
+
+ return membershipType;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Collection findMembershipTypes() throws Exception
+ {
+
+ Collection membershipTypes =3D membershipTypeHandler=
.findMembershipTypes();
+ for (MembershipType membershipType : membershipTypes)
+ membershipTypeCache.put(membershipType.getName(), membershipType);
+
+ return membershipTypes;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public MembershipType removeMembershipType(String name, boolean broadca=
st) throws Exception
+ {
+ MembershipType membershipType =3D membershipTypeHandler.removeMember=
shipType(name, broadcast);
+ if (membershipType !=3D null)
+ {
+ membershipTypeCache.remove(name);
+
+ List memberships =3D membershipCache.getCachedObjects=
();
+ for (Membership membership : memberships)
+ {
+ if (membership.getMembershipType().equals(name))
+ {
+ membershipCache.remove(membership.getId());
+ membershipCache.remove(new MembershipCacheKey(membership));
+ }
+ }
+ }
+
+ return membershipType;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public MembershipType saveMembershipType(MembershipType mt, boolean bro=
adcast) throws Exception
+ {
+ MembershipType membershipType =3D membershipTypeHandler.saveMembersh=
ipType(mt, broadcast);
+ membershipTypeCache.put(membershipType.getName(), membershipType);
+
+ return membershipType;
+ }
+
+}
Property changes on: core/trunk/component/organization/api/src/main/java/or=
g/exoplatform/services/organization/cache/CacheableMembershipTypeHandlerImp=
l.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: core/trunk/component/organization/api/src/main/java/org/exoplatform/=
services/organization/cache/CacheableUserHandlerImpl.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- core/trunk/component/organization/api/src/main/java/org/exoplatform/ser=
vices/organization/cache/CacheableUserHandlerImpl.java =
(rev 0)
+++ core/trunk/component/organization/api/src/main/java/org/exoplatform/ser=
vices/organization/cache/CacheableUserHandlerImpl.java 2009-10-16 08:08:49 =
UTC (rev 287)
@@ -0,0 +1,181 @@
+/*
+ * Copyright (C) 2003-2009 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see.
+ */
+package org.exoplatform.services.organization.cache;
+
+import org.exoplatform.commons.utils.PageList;
+import org.exoplatform.services.cache.ExoCache;
+import org.exoplatform.services.organization.Membership;
+import org.exoplatform.services.organization.Query;
+import org.exoplatform.services.organization.User;
+import org.exoplatform.services.organization.UserEventListener;
+import org.exoplatform.services.organization.UserHandler;
+
+import java.util.List;
+
+/**
+ * Created by The eXo Platform SAS.
+ * =
+ *
Date: 2009
+ *
+ * @author Anatoliy=
Bazko =
+ * @version $Id$
+ */
+public class CacheableUserHandlerImpl implements UserHandler
+{
+
+ private final ExoCache userCache;
+
+ private final ExoCache userProfileCache;
+
+ private final ExoCache membershipCache;
+
+ private final UserHandler userHandler;
+
+ /**
+ * CacheableUserHandler constructor.
+ *
+ * @param cacheHandler
+ * - cache handler
+ * @param userHandler
+ * - user handler
+ */
+ public CacheableUserHandlerImpl(OrganizationCacheHandler organizationCa=
cheHandler, UserHandler userHandler)
+ {
+ this.userCache =3D organizationCacheHandler.getUserCache();
+ this.userProfileCache =3D organizationCacheHandler.getUserProfileCac=
he();
+ this.membershipCache =3D organizationCacheHandler.getMembershipCache=
();
+ this.userHandler =3D userHandler;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addUserEventListener(UserEventListener listener)
+ {
+ userHandler.addUserEventListener(listener);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean authenticate(String username, String password) throws Ex=
ception
+ {
+ boolean authenticated =3D userHandler.authenticate(username, passwor=
d);
+ userCache.remove(username);
+
+ return authenticated;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void createUser(User user, boolean broadcast) throws Exception
+ {
+ userHandler.createUser(user, broadcast);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public User createUserInstance()
+ {
+ return userHandler.createUserInstance();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public User createUserInstance(String username)
+ {
+ return userHandler.createUserInstance(username);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public User findUserByName(String userName) throws Exception
+ {
+ User user =3D (User)userCache.get(userName);
+ if (user !=3D null)
+ return user;
+
+ user =3D userHandler.findUserByName(userName);
+ if (user !=3D null)
+ userCache.put(userName, user);
+
+ return user;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public PageList findUsers(Query query) throws Exception
+ {
+ return userHandler.findUsers(query);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public PageList findUsersByGroup(String groupId) throws Exception
+ {
+ return userHandler.findUsersByGroup(groupId);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public PageList getUserPageList(int pageSize) throws Exception
+ {
+ return userHandler.getUserPageList(pageSize);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public User removeUser(String userName, boolean broadcast) throws Excep=
tion
+ {
+ User user =3D userHandler.removeUser(userName, broadcast);
+ if (user !=3D null)
+ {
+ userCache.remove(userName);
+ userProfileCache.remove(userName);
+
+ List memberships =3D membershipCache.getCachedObjects=
();
+ for (Membership membership : memberships)
+ {
+ if (membership.getUserName().equals(userName))
+ {
+ membershipCache.remove(membership.getId());
+ membershipCache.remove(new MembershipCacheKey(membership));
+ }
+ }
+ }
+
+ return user;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void saveUser(User user, boolean broadcast) throws Exception
+ {
+ userHandler.saveUser(user, broadcast);
+ userCache.put(user.getUserName(), user);
+ }
+
+}
Property changes on: core/trunk/component/organization/api/src/main/java/or=
g/exoplatform/services/organization/cache/CacheableUserHandlerImpl.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: core/trunk/component/organization/api/src/main/java/org/exoplatform/=
services/organization/cache/CacheableUserProfileHandlerImpl.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- core/trunk/component/organization/api/src/main/java/org/exoplatform/ser=
vices/organization/cache/CacheableUserProfileHandlerImpl.java =
(rev 0)
+++ core/trunk/component/organization/api/src/main/java/org/exoplatform/ser=
vices/organization/cache/CacheableUserProfileHandlerImpl.java 2009-10-16 08=
:08:49 UTC (rev 287)
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2003-2009 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see.
+ */
+package org.exoplatform.services.organization.cache;
+
+import org.exoplatform.services.cache.ExoCache;
+import org.exoplatform.services.organization.UserHandler;
+import org.exoplatform.services.organization.UserProfile;
+import org.exoplatform.services.organization.UserProfileEventListener;
+import org.exoplatform.services.organization.UserProfileHandler;
+
+import java.util.Collection;
+
+/**
+ * Created by The eXo Platform SAS.
+ * =
+ *
Date: 2009
+ *
+ * @author Anatoliy=
Bazko =
+ * @version $Id$
+ */
+public class CacheableUserProfileHandlerImpl implements UserProfileHandler
+{
+
+ private final ExoCache userProfileCache;
+
+ private final UserProfileHandler userProfileHandler;
+
+ /**
+ * CacheableUserHandler constructor.
+ *
+ * @param organizationCacheHandler
+ * - organization cache handler
+ * @param userProfileHandler
+ * - user profile handler
+ */
+ public CacheableUserProfileHandlerImpl(OrganizationCacheHandler organiz=
ationCacheHandler,
+ UserProfileHandler userProfileHandler)
+ {
+ this.userProfileCache =3D organizationCacheHandler.getUserProfileCac=
he();
+ this.userProfileHandler =3D userProfileHandler;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addUserProfileEventListener(UserProfileEventListener listen=
er)
+ {
+ userProfileHandler.addUserProfileEventListener(listener);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public UserProfile createUserProfileInstance()
+ {
+ return userProfileHandler.createUserProfileInstance();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public UserProfile createUserProfileInstance(String userName)
+ {
+ return userProfileHandler.createUserProfileInstance(userName);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public UserProfile findUserProfileByName(String userName) throws Except=
ion
+ {
+ UserProfile userProfile =3D (UserProfile)userProfileCache.get(userNa=
me);
+ if (userProfile !=3D null)
+ return userProfile;
+
+ userProfile =3D userProfileHandler.findUserProfileByName(userName);
+ if (userProfile !=3D null)
+ userProfileCache.put(userName, userProfile);
+
+ return userProfile;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Collection findUserProfiles() throws Exception
+ {
+ Collection userProfiles =3D userProfileHandler.findUser=
Profiles();
+ for (UserProfile userProfile : userProfiles)
+ userProfileCache.put(userProfile.getUserName(), userProfile);
+
+ return userProfiles;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public UserProfile removeUserProfile(String userName, boolean broadcast=
) throws Exception
+ {
+ UserProfile userProfile =3D userProfileHandler.removeUserProfile(use=
rName, broadcast);
+ if (userProfile !=3D null)
+ userProfileCache.remove(userName);
+
+ return userProfile;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void saveUserProfile(UserProfile profile, boolean broadcast) thr=
ows Exception
+ {
+ userProfileHandler.saveUserProfile(profile, broadcast);
+ userProfileCache.put(profile.getUserName(), profile);
+ }
+
+}
Property changes on: core/trunk/component/organization/api/src/main/java/or=
g/exoplatform/services/organization/cache/CacheableUserProfileHandlerImpl.j=
ava
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: core/trunk/component/organization/api/src/main/java/org/exoplatform/=
services/organization/cache/MembershipCacheKey.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- core/trunk/component/organization/api/src/main/java/org/exoplatform/ser=
vices/organization/cache/MembershipCacheKey.java (r=
ev 0)
+++ core/trunk/component/organization/api/src/main/java/org/exoplatform/ser=
vices/organization/cache/MembershipCacheKey.java 2009-10-16 08:08:49 UTC (r=
ev 287)
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2003-2009 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see.
+ */
+package org.exoplatform.services.organization.cache;
+
+import org.exoplatform.services.organization.Membership;
+
+import java.io.Serializable;
+
+/**
+ * Created by The eXo Platform SAS.
+ * =
+ *
Date: 2009
+ *
+ * @author Anatoliy=
Bazko =
+ * @version $Id$
+ */
+/**
+ * Will be used as key for cacheMembership.
+ */
+public class MembershipCacheKey implements Serializable
+{
+ /**
+ * serialVersionUID.
+ */
+ private static final long serialVersionUID =3D -188435911917156440L;
+
+ private final String userName;
+
+ private final String groupId;
+
+ private final String type;
+
+ private final int hashcode;
+
+ public MembershipCacheKey(String userName, String groupId, String type)
+ {
+ this.userName =3D userName;
+ this.groupId =3D groupId;
+ this.type =3D type;
+
+ final int prime =3D 31;
+ int result =3D 1;
+ result =3D prime * result + ((groupId =3D=3D null) ? 0 : groupId.has=
hCode());
+ result =3D prime * result + ((type =3D=3D null) ? 0 : type.hashCode(=
));
+ hashcode =3D prime * result + ((userName =3D=3D null) ? 0 : userName=
.hashCode());
+ }
+
+ public MembershipCacheKey(Membership m)
+ {
+ this.userName =3D m.getUserName();
+ this.groupId =3D m.getGroupId();
+ this.type =3D m.getMembershipType();
+
+ final int prime =3D 31;
+ int result =3D 1;
+ result =3D prime * result + ((groupId =3D=3D null) ? 0 : groupId.has=
hCode());
+ result =3D prime * result + ((type =3D=3D null) ? 0 : type.hashCode(=
));
+ hashcode =3D prime * result + ((userName =3D=3D null) ? 0 : userName=
.hashCode());
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return hashcode;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this =3D=3D obj)
+ return true;
+ if (obj =3D=3D null)
+ return false;
+ if (getClass() !=3D obj.getClass())
+ return false;
+ MembershipCacheKey other =3D (MembershipCacheKey)obj;
+ if (groupId =3D=3D null)
+ {
+ if (other.groupId !=3D null)
+ return false;
+ }
+ else if (!groupId.equals(other.groupId))
+ return false;
+ if (type =3D=3D null)
+ {
+ if (other.type !=3D null)
+ return false;
+ }
+ else if (!type.equals(other.type))
+ return false;
+ if (userName =3D=3D null)
+ {
+ if (other.userName !=3D null)
+ return false;
+ }
+ else if (!userName.equals(other.userName))
+ return false;
+ return true;
+ }
+
+}
\ No newline at end of file
Property changes on: core/trunk/component/organization/api/src/main/java/or=
g/exoplatform/services/organization/cache/MembershipCacheKey.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: core/trunk/component/organization/api/src/main/java/org/exoplatform/=
services/organization/cache/OrganizationCacheHandler.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- core/trunk/component/organization/api/src/main/java/org/exoplatform/ser=
vices/organization/cache/OrganizationCacheHandler.java =
(rev 0)
+++ core/trunk/component/organization/api/src/main/java/org/exoplatform/ser=
vices/organization/cache/OrganizationCacheHandler.java 2009-10-16 08:08:49 =
UTC (rev 287)
@@ -0,0 +1,146 @@
+/*
+ * Copyright (C) 2003-2009 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see.
+ */
+package org.exoplatform.services.organization.cache;
+
+import org.exoplatform.services.cache.CacheService;
+import org.exoplatform.services.cache.ExoCache;
+import org.exoplatform.services.organization.impl.GroupImpl;
+import org.exoplatform.services.organization.impl.MembershipImpl;
+import org.exoplatform.services.organization.impl.MembershipTypeImpl;
+import org.exoplatform.services.organization.impl.UserImpl;
+import org.exoplatform.services.organization.impl.UserProfileImpl;
+
+/**
+ * Created by The eXo Platform SAS.
+ * =
+ *
Date: 2009
+ *
+ * @author Anatoliy=
Bazko =
+ * @version $Id$
+ */
+public class OrganizationCacheHandler
+{
+
+ /**
+ * Use cache.
+ */
+ private final ExoCache userCache;
+
+ /**
+ * User profile cache.
+ */
+ private final ExoCache userProfileCache;
+
+ /**
+ * Membership cache.
+ */
+ private final ExoCache membershipCache;
+
+ /**
+ * Membership type cache.
+ */
+ private final ExoCache membershipTypeCache;
+
+ /**
+ * Group cache. =
+ */
+ private final ExoCache groupCache;
+
+ /**
+ * OrganizationCacheHandler constructor.
+ *
+ * @param cservice
+ * cache service
+ */
+ public OrganizationCacheHandler(CacheService cservice)
+ {
+ userCache =3D cservice.getCacheInstance(UserImpl.class.getName());
+ userProfileCache =3D cservice.getCacheInstance(UserProfileImpl.class=
.getName());
+ membershipCache =3D cservice.getCacheInstance(MembershipImpl.class.g=
etName());
+ membershipTypeCache =3D cservice.getCacheInstance(MembershipTypeImpl=
.class.getName());
+ groupCache =3D cservice.getCacheInstance(GroupImpl.class.getName());
+ }
+
+ /**
+ * OrganizationCacheHandler constructor.
+ *
+ * @param cservice
+ * cache service
+ * @param lifeTime
+ * lifetime cache param
+ */
+ public OrganizationCacheHandler(CacheService cservice, long lifeTime)
+ {
+ this(cservice);
+
+ userCache.setLiveTime(lifeTime);
+ userProfileCache.setLiveTime(lifeTime);
+ membershipCache.setLiveTime(lifeTime);
+ membershipTypeCache.setLiveTime(lifeTime);
+ groupCache.setLiveTime(lifeTime);
+ }
+
+ /**
+ * Returns user profile cache.
+ *
+ * @return user profile cache
+ */
+ public ExoCache getUserProfileCache()
+ {
+ return userProfileCache;
+ }
+
+ /**
+ * Returns user cache.
+ *
+ * @return user cache
+ */
+ public ExoCache getUserCache()
+ {
+ return userCache;
+ }
+
+ /**
+ * Returns membership type cache.
+ *
+ * @return membership type cache
+ */
+ public ExoCache getMembershipTypeCache()
+ {
+ return membershipTypeCache;
+ }
+
+ /**
+ * Returns membership cache.
+ *
+ * @return membership cache
+ */
+ public ExoCache getMembershipCache()
+ {
+ return membershipCache;
+ }
+
+ /**
+ * Returns group cache.
+ *
+ * @return group cache
+ */
+ public ExoCache getGroupCache()
+ {
+ return groupCache;
+ }
+}
Property changes on: core/trunk/component/organization/api/src/main/java/or=
g/exoplatform/services/organization/cache/OrganizationCacheHandler.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
--===============5271443780269397044==--