Changeset 3150
- Timestamp:
- Feb 26, 2007, 11:44:59 AM (16 years ago)
- Location:
- branches/2.2.2/src/core
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.2/src/core/common-queries.xml
r3136 r3150 202 202 <description> 203 203 Load the ID of all users which has a quota group from one of the given groups. 204 </description> 205 </query> 206 207 <query id="GET_USER_IDS_FOR_PROJECT" type="HQL"> 208 <sql> 209 SELECT up.userId 210 FROM UserProjects up 211 WHERE up.projectId = :projectId 212 </sql> 213 <description> 214 Load the ID of all users which are direct member of the given project 215 </description> 216 </query> 217 218 <query id="GET_GROUP_IDS_FOR_PROJECT" type="HQL"> 219 <sql> 220 SELECT gp.groupId 221 FROM GroupProjects gp 222 WHERE gp.projectId = :projectId 223 </sql> 224 <description> 225 Load the ID of all groups which are direct member of the given project 204 226 </description> 205 227 </query> -
branches/2.2.2/src/core/net/sf/basedb/core/Group.java
r2898 r3150 29 29 import net.sf.basedb.core.query.Hql; 30 30 31 import java.util.Collection; 31 32 import java.util.HashSet; 32 33 import java.util.Set; … … 124 125 public static Set<Integer> getGroupsRecursive(DbControl dc, Set<Integer> groups) 125 126 { 127 return getGroupsRecursive(dc.getHibernateSession(), groups); 128 } 129 130 static Set<Integer> getGroupsRecursive(org.hibernate.Session session, Collection<Integer> groups) 131 { 126 132 Set<Integer> allGroups = new HashSet<Integer>(groups); 127 133 if (allGroups.size() > 0) 128 134 { 129 135 130 org.hibernate.Query query = HibernateUtil.getPredefinedQuery( dc.getHibernateSession(),136 org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session, 131 137 "GET_CHILDGROUPS_IDS_FOR_GROUPS"); 132 138 /* … … 143 149 return allGroups; 144 150 } 151 145 152 146 153 /** -
branches/2.2.2/src/core/net/sf/basedb/core/Keyring.java
r2981 r3150 450 450 Load all users which are member of at least one group where the 451 451 logged in user is also a member and put that information 452 in the {@link #users} variable. 452 in the {@link #users} variable. If a project is active, also load the members 453 and owner of that project. 453 454 */ 454 455 private void loadUsers(org.hibernate.Session session) 455 456 throws BaseException 456 457 { 457 Set<Integer> temp ;458 Set<Integer> temp = new HashSet<Integer>(); 458 459 try 459 460 { … … 468 469 */ 469 470 query.setParameterList("groups", groups, org.hibernate.Hibernate.INTEGER); 470 temp = new HashSet<Integer>(HibernateUtil.loadList(Integer.class, query));471 temp.addAll(HibernateUtil.loadList(Integer.class, query)); 471 472 472 473 // Get the users that have a quota group among the same groups … … 479 480 query.setParameterList("groups", groups, org.hibernate.Hibernate.INTEGER); 480 481 temp.addAll(HibernateUtil.loadList(Integer.class, query)); 482 } 483 484 if (projectId != 0) 485 { 486 // Get the owner of the active project 487 ProjectData pd = HibernateUtil.loadData(session, ProjectData.class, projectId); 488 temp.add(pd.getOwner().getId()); 481 489 482 users = Collections.unmodifiableSet(temp); 483 } 490 // Get direct members of the active project 491 org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session, "GET_USER_IDS_FOR_PROJECT"); 492 /* 493 SELECT up.userId 494 FROM UserProjects up 495 WHERE up.projectId = :projectId 496 */ 497 query.setInteger("projectId", projectId); 498 temp.addAll(HibernateUtil.loadList(Integer.class, query)); 499 500 // Get groups that are direct members of the active project 501 query = HibernateUtil.getPredefinedQuery(session, "GET_GROUP_IDS_FOR_PROJECT"); 502 /* 503 SELECT gp.groupId 504 FROM GroupProjects gp 505 WHERE gp.projectId = :projectId 506 */ 507 query.setInteger("projectId", projectId); 508 // Load the direct groups and subgroups 509 Set<Integer> projectGroups = Group.getGroupsRecursive(session, HibernateUtil.loadList(Integer.class, query)); 510 511 // Load users that are members of the project groups 512 temp.addAll(User.getAllMembers(session, projectGroups)); 513 514 } 515 users = Collections.unmodifiableSet(temp); 484 516 } 485 517 catch (HibernateException ex) … … 717 749 { 718 750 if (getReload() && !reload()) projectData = null; 751 int oldProjectId = projectId; 719 752 if (projectData == null) 720 753 { … … 725 758 { 726 759 projectId = projectData.getId(); 727 org.hibernate.Session session = null; 728 org.hibernate.Transaction tx = null; 729 try 730 { 731 session = HibernateUtil.newSession(); 732 tx = HibernateUtil.newTransaction(session); 733 loadMaxProjectPermission(session, projectData); 734 loadProjectKeys(session); 735 } 736 catch (BaseException ex) 737 { 738 projectId = 0; 739 maxProjectPermission = 0; 740 throw ex; 741 } 742 finally 743 { 744 if (tx != null) HibernateUtil.commit(tx); 745 if (session != null) HibernateUtil.close(session); 746 } 747 } 760 } 761 reload = projectId != oldProjectId; 748 762 } 749 763 -
branches/2.2.2/src/core/net/sf/basedb/core/User.java
r2902 r3150 36 36 37 37 import java.util.ArrayList; 38 import java.util.Collection; 38 39 import java.util.Date; 39 40 import java.util.HashSet; … … 124 125 public static Set<Integer> getAllMembers(DbControl dc, Set<Integer> groupIds) 125 126 { 127 return getAllMembers(dc.getHibernateSession(), groupIds); 128 } 129 130 static Set<Integer> getAllMembers(org.hibernate.Session session, Collection<Integer> groupIds) 131 { 126 132 Set<Integer> userIds = new HashSet<Integer>(); 127 133 if (groupIds != null && groupIds.size() > 0) 128 134 { 129 org.hibernate.Session session = dc.getHibernateSession();130 135 // Get the users which are members of the same groups 131 136 org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session, "GET_USER_IDS_FOR_GROUPS"); … … 149 154 } 150 155 return userIds; 151 152 } 156 } 157 153 158 154 159 /**
Note: See TracChangeset
for help on using the changeset viewer.