[exo-jcr-commits] exo-jcr SVN: r5154 - core/trunk/exo.core.component.organization.jdbc/src/main/java/org/exoplatform/services/organization/hibernate.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu Nov 3 05:45:39 EDT 2011
Author: tolusha
Date: 2011-11-03 05:45:39 -0400 (Thu, 03 Nov 2011)
New Revision: 5154
Modified:
core/trunk/exo.core.component.organization.jdbc/src/main/java/org/exoplatform/services/organization/hibernate/GroupDAOImpl.java
core/trunk/exo.core.component.organization.jdbc/src/main/java/org/exoplatform/services/organization/hibernate/MembershipDAOImpl.java
core/trunk/exo.core.component.organization.jdbc/src/main/java/org/exoplatform/services/organization/hibernate/UserDAOImpl.java
core/trunk/exo.core.component.organization.jdbc/src/main/java/org/exoplatform/services/organization/hibernate/UserProfileDAOImpl.java
Log:
EXOJCR-1594: do session.flush() before post events
Modified: core/trunk/exo.core.component.organization.jdbc/src/main/java/org/exoplatform/services/organization/hibernate/GroupDAOImpl.java
===================================================================
--- core/trunk/exo.core.component.organization.jdbc/src/main/java/org/exoplatform/services/organization/hibernate/GroupDAOImpl.java 2011-11-02 16:40:39 UTC (rev 5153)
+++ core/trunk/exo.core.component.organization.jdbc/src/main/java/org/exoplatform/services/organization/hibernate/GroupDAOImpl.java 2011-11-03 09:45:39 UTC (rev 5154)
@@ -93,16 +93,25 @@
listeners_.remove(listener);
}
+ /**
+ * {@inheritDoc}
+ */
final public Group createGroupInstance()
{
return new GroupImpl();
}
+ /**
+ * {@inheritDoc}
+ */
public void createGroup(Group group, boolean broadcast) throws Exception
{
addChild(null, group, broadcast);
}
+ /**
+ * {@inheritDoc}
+ */
public void addChild(Group parent, Group child, boolean broadcast) throws Exception
{
Session session = service_.openSession();
@@ -131,22 +140,31 @@
session = service_.openSession();
session.save(childImpl);
+ session.flush();
+
if (broadcast)
postSave(child, true);
- session.flush();
}
+ /**
+ * {@inheritDoc}
+ */
public void saveGroup(Group group, boolean broadcast) throws Exception
{
if (broadcast)
preSave(group, false);
+
Session session = service_.openSession();
session.update(group);
+ session.flush();
+
if (broadcast)
postSave(group, false);
- session.flush();
}
+ /**
+ * {@inheritDoc}
+ */
public Group removeGroup(Group group, boolean broadcast) throws Exception
{
if (broadcast)
@@ -164,19 +182,17 @@
for (int i = 0; i < entries.size(); i++)
removeGroup((Group)entries.get(i), broadcast);
MembershipDAOImpl.removeMembershipEntriesOfGroup(group, session);
+ session.flush();
+
if (broadcast)
postDelete(group);
- session.flush();
+
return group;
}
- static void removeGroupEntry(String groupName, Session session) throws Exception
- {
- List entries = session.createQuery(queryFindGroupByName).setString(0, groupName).list();
- for (int i = 0; i < entries.size(); i++)
- session.delete(entries.get(i));
- }
-
+ /**
+ * {@inheritDoc}
+ */
public Collection findGroupByMembership(String userName, String membershipType) throws Exception
{
Session session = service_.openSession();
@@ -185,6 +201,9 @@
return groups;
}
+ /**
+ * {@inheritDoc}
+ */
public Group findGroupByName(String groupName) throws Exception
{
Session session = service_.openSession();
@@ -192,6 +211,9 @@
return group;
}
+ /**
+ * {@inheritDoc}
+ */
public Group findGroupById(String groupId) throws Exception
{
Session session = service_.openSession();
@@ -199,6 +221,9 @@
return group;
}
+ /**
+ * {@inheritDoc}
+ */
public Collection findGroups(Group parent) throws Exception
{
Session session = service_.openSession();
@@ -212,6 +237,9 @@
}
+ /**
+ * {@inheritDoc}
+ */
public Collection findGroupsOfUser(String user) throws Exception
{
Session session = service_.openSession();
@@ -219,6 +247,9 @@
return session.createQuery(queryFindGroupsOfUser).setString(0, user).list();
}
+ /**
+ * {@inheritDoc}
+ */
public Collection getAllGroups() throws Exception
{
Session session = service_.openSession();
Modified: core/trunk/exo.core.component.organization.jdbc/src/main/java/org/exoplatform/services/organization/hibernate/MembershipDAOImpl.java
===================================================================
--- core/trunk/exo.core.component.organization.jdbc/src/main/java/org/exoplatform/services/organization/hibernate/MembershipDAOImpl.java 2011-11-02 16:40:39 UTC (rev 5153)
+++ core/trunk/exo.core.component.organization.jdbc/src/main/java/org/exoplatform/services/organization/hibernate/MembershipDAOImpl.java 2011-11-03 09:45:39 UTC (rev 5154)
@@ -143,13 +143,12 @@
Session session = service_.openSession();
session.save(m);
+ session.flush();
if (broadcast)
{
postSave(m, true);
}
-
- session.flush();
}
/**
@@ -189,11 +188,14 @@
{
if (broadcast)
preSave(m, false);
+
Session session = service_.openSession();
session.update(m);
+ session.flush();
+
if (broadcast)
postSave(m, false);
- session.flush();
+
}
/**
@@ -210,9 +212,10 @@
preDelete(m);
session = service_.openSession();
session.delete(m);
+ session.flush();
+
if (broadcast)
postDelete(m);
- session.flush();
}
return m;
}
@@ -233,9 +236,11 @@
preDelete(m);
Session session = service_.openSession();
session.delete(m);
+ session.flush();
+
if (broadcast)
postDelete(m);
- session.flush();
+
}
}
return collection;
Modified: core/trunk/exo.core.component.organization.jdbc/src/main/java/org/exoplatform/services/organization/hibernate/UserDAOImpl.java
===================================================================
--- core/trunk/exo.core.component.organization.jdbc/src/main/java/org/exoplatform/services/organization/hibernate/UserDAOImpl.java 2011-11-02 16:40:39 UTC (rev 5153)
+++ core/trunk/exo.core.component.organization.jdbc/src/main/java/org/exoplatform/services/organization/hibernate/UserDAOImpl.java 2011-11-03 09:45:39 UTC (rev 5154)
@@ -20,7 +20,6 @@
import org.exoplatform.commons.utils.LazyPageList;
import org.exoplatform.commons.utils.ListAccess;
-import org.exoplatform.commons.utils.SecurityHelper;
import org.exoplatform.services.cache.CacheService;
import org.exoplatform.services.cache.ExoCache;
import org.exoplatform.services.database.HibernateService;
@@ -35,9 +34,7 @@
import org.exoplatform.services.organization.impl.UserImpl;
import org.exoplatform.services.security.PasswordEncrypter;
import org.hibernate.Session;
-import org.hibernate.Transaction;
-import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
@@ -89,56 +86,62 @@
listeners_.remove(listener);
}
+ /**
+ * {@inheritDoc}
+ */
public User createUserInstance()
{
return new UserImpl();
}
+ /**
+ * {@inheritDoc}
+ */
public User createUserInstance(String username)
{
return new UserImpl(username);
}
+ /**
+ * {@inheritDoc}
+ */
public void createUser(User user, boolean broadcast) throws Exception
{
if (broadcast)
preSave(user, true);
final Session session = service_.openSession();
- Transaction transaction = SecurityHelper.doPrivilegedAction(new PrivilegedAction<Transaction>()
- {
- public Transaction run()
- {
- return session.beginTransaction();
- }
- });
UserImpl userImpl = (UserImpl)user;
userImpl.setId(user.getUserName());
session.save(user);
+ session.flush();
+
if (broadcast)
postSave(user, true);
- transaction.commit();
}
+ /**
+ * {@inheritDoc}
+ */
public void saveUser(User user, boolean broadcast) throws Exception
{
if (broadcast)
preSave(user, false);
+
Session session = service_.openSession();
+
session.merge(user);
- // session.update(user);
- if (broadcast)
- postSave(user, false);
session.flush();
cache_.put(user.getUserName(), user);
- }
- void createUserEntry(User user, Session session) throws Exception
- {
- session.save(user);
+ if (broadcast)
+ postSave(user, false);
}
+ /**
+ * {@inheritDoc}
+ */
public User removeUser(String userName, boolean broadcast) throws Exception
{
Session session = service_.openSession();
@@ -153,13 +156,19 @@
session.delete(foundUser);
((UserProfileDAOImpl)orgService.getUserProfileHandler()).removeUserProfileEntry(userName, session);
MembershipDAOImpl.removeMembershipEntriesOfUser(userName, session);
+
+ session.flush();
+ cache_.remove(userName);
+
if (broadcast)
postDelete(foundUser);
- session.flush();
- cache_.remove(userName);
+
return foundUser;
}
+ /**
+ * {@inheritDoc}
+ */
public User findUserByName(String userName) throws Exception
{
User user = (User)cache_.get(userName);
@@ -178,11 +187,17 @@
return user;
}
+ /**
+ * {@inheritDoc}
+ */
public LazyPageList<User> getUserPageList(int pageSize) throws Exception
{
return new LazyPageList<User>(findAllUsers(), 20);
}
+ /**
+ * {@inheritDoc}
+ */
public ListAccess<User> findAllUsers() throws Exception
{
String findQuery = "from o in class " + UserImpl.class.getName();
@@ -191,11 +206,17 @@
return new HibernateListAccess<User>(service_, findQuery, countQuery);
}
+ /**
+ * {@inheritDoc}
+ */
public boolean authenticate(String username, String password) throws Exception
{
return authenticate(username, password, null);
}
+ /**
+ * {@inheritDoc}
+ */
public boolean authenticate(String username, String password, PasswordEncrypter pe) throws Exception
{
User user = findUserByName(username);
@@ -223,11 +244,17 @@
return authenticated;
}
+ /**
+ * {@inheritDoc}
+ */
public LazyPageList<User> findUsers(Query q) throws Exception
{
return new LazyPageList<User>(findUsersByQuery(q), 20);
}
+ /**
+ * {@inheritDoc}
+ */
public ListAccess<User> findUsersByQuery(Query q) throws Exception
{
ObjectQuery oq = new ObjectQuery(UserImpl.class);
@@ -251,11 +278,17 @@
oq.getHibernateCountQueryWithBinding(), oq.getBindingFields());
}
+ /**
+ * {@inheritDoc}
+ */
public LazyPageList<User> findUsersByGroup(String groupId) throws Exception
{
return new LazyPageList<User>(findUsersByGroupId(groupId), 20);
}
+ /**
+ * {@inheritDoc}
+ */
public ListAccess<User> findUsersByGroupId(String groupId) throws Exception
{
String queryFindUsersInGroup =
@@ -270,6 +303,9 @@
return new HibernateListAccess<User>(service_, queryFindUsersInGroup, countUsersInGroup);
}
+ /**
+ * {@inheritDoc}
+ */
public Collection findUsersByGroupAndRole(String groupName, String role) throws Exception
{
String queryFindUsersByGroupAndRole =
Modified: core/trunk/exo.core.component.organization.jdbc/src/main/java/org/exoplatform/services/organization/hibernate/UserProfileDAOImpl.java
===================================================================
--- core/trunk/exo.core.component.organization.jdbc/src/main/java/org/exoplatform/services/organization/hibernate/UserProfileDAOImpl.java 2011-11-02 16:40:39 UTC (rev 5153)
+++ core/trunk/exo.core.component.organization.jdbc/src/main/java/org/exoplatform/services/organization/hibernate/UserProfileDAOImpl.java 2011-11-03 09:45:39 UTC (rev 5154)
@@ -78,25 +78,25 @@
listeners_.remove(listener);
}
+ /**
+ * {@inheritDoc}
+ */
final public UserProfile createUserProfileInstance()
{
return new UserProfileImpl();
}
+ /**
+ * {@inheritDoc}
+ */
public UserProfile createUserProfileInstance(String userName)
{
return new UserProfileImpl(userName);
}
- void createUserProfileEntry(UserProfile up, Session session) throws Exception
- {
- UserProfileData upd = new UserProfileData();
- upd.setUserProfile(up);
- session.save(upd);
- session.flush();
- cache_.remove(up.getUserName());
- }
-
+ /**
+ * {@inheritDoc}
+ */
public void saveUserProfile(UserProfile profile, boolean broadcast) throws Exception
{
Session session = service_.openSession();
@@ -108,26 +108,34 @@
upd.setUserProfile(profile);
if (broadcast)
preSave(profile, true);
+
session = service_.openSession();
session.save(profile.getUserName(), upd);
+ session.flush();
+ cache_.put(profile.getUserName(), profile);
+
if (broadcast)
postSave(profile, true);
- session.flush();
}
else
{
upd.setUserProfile(profile);
if (broadcast)
preSave(profile, false);
+
session = service_.openSession();
session.update(upd);
+ session.flush();
+ cache_.put(profile.getUserName(), profile);
+
if (broadcast)
postSave(profile, false);
- session.flush();
}
- cache_.put(profile.getUserName(), profile);
}
+ /**
+ * {@inheritDoc}
+ */
public UserProfile removeUserProfile(String userName, boolean broadcast) throws Exception
{
Session session = service_.openSession();
@@ -137,12 +145,15 @@
UserProfile profile = upd.getUserProfile();
if (broadcast)
preDelete(profile);
+
session = service_.openSession();
session.delete(upd);
+ session.flush();
+ cache_.remove(userName);
+
if (broadcast)
postDelete(profile);
- session.flush();
- cache_.remove(userName);
+
return profile;
}
catch (Exception exp)
@@ -151,6 +162,9 @@
}
}
+ /**
+ * {@inheritDoc}
+ */
public UserProfile findUserProfileByName(String userName) throws Exception
{
UserProfile up = (UserProfile)cache_.get(userName);
@@ -169,6 +183,9 @@
return up;
}
+ /**
+ * {@inheritDoc}
+ */
public UserProfile findUserProfileByName(String userName, Session session) throws Exception
{
UserProfileData upd = (UserProfileData)service_.findOne(session, queryFindUserProfileByName, userName);
@@ -189,6 +206,9 @@
}
}
+ /**
+ * {@inheritDoc}
+ */
public Collection findUserProfiles() throws Exception
{
Session session = service_.openSession();
More information about the exo-jcr-commits
mailing list