1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.service.persistence;
16  
17  import com.liferay.portal.SystemException;
18  import com.liferay.portal.kernel.dao.orm.QueryPos;
19  import com.liferay.portal.kernel.dao.orm.SQLQuery;
20  import com.liferay.portal.kernel.dao.orm.Session;
21  import com.liferay.portal.model.OrgGroupPermission;
22  import com.liferay.portal.model.impl.OrgGroupPermissionImpl;
23  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
24  import com.liferay.util.dao.orm.CustomSQLUtil;
25  
26  import java.util.Iterator;
27  
28  /**
29   * <a href="OrgGroupPermissionFinderImpl.java.html"><b><i>View Source</i></b>
30   * </a>
31   *
32   * @author Brian Wing Shun Chan
33   */
34  public class OrgGroupPermissionFinderImpl
35      extends BasePersistenceImpl<OrgGroupPermission>
36      implements OrgGroupPermissionFinder {
37  
38      public static String FIND_BY_O_G_R =
39          OrgGroupPermissionFinder.class.getName() + ".findByO_G_R";
40  
41      public void removeByO_G_R(
42              long organizationId, long groupId, long resourceId)
43          throws SystemException {
44  
45          Session session = null;
46  
47          try {
48              session = openSession();
49  
50              String sql = CustomSQLUtil.get(FIND_BY_O_G_R);
51  
52              SQLQuery q = session.createSQLQuery(sql);
53  
54              q.addEntity("OrgGroupPermission", OrgGroupPermissionImpl.class);
55  
56              QueryPos qPos = QueryPos.getInstance(q);
57  
58              qPos.add(resourceId);
59              qPos.add(organizationId);
60              qPos.add(groupId);
61  
62              Iterator<OrgGroupPermission> itr = q.list().iterator();
63  
64              while (itr.hasNext()) {
65                  OrgGroupPermission orgGroupPermission = itr.next();
66  
67                  OrgGroupPermissionUtil.remove(
68                      orgGroupPermission.getPrimaryKey());
69              }
70          }
71          catch (Exception e) {
72              throw new SystemException(e);
73          }
74          finally {
75              closeSession(session);
76          }
77      }
78  
79  }