001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.kernel.dao.orm.QueryPos;
018    import com.liferay.portal.kernel.dao.orm.SQLQuery;
019    import com.liferay.portal.kernel.dao.orm.Session;
020    import com.liferay.portal.kernel.exception.SystemException;
021    import com.liferay.portal.model.OrgGroupPermission;
022    import com.liferay.portal.model.impl.OrgGroupPermissionImpl;
023    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
024    import com.liferay.util.dao.orm.CustomSQLUtil;
025    
026    import java.util.Iterator;
027    
028    /**
029     * @author Brian Wing Shun Chan
030     */
031    public class OrgGroupPermissionFinderImpl
032            extends BasePersistenceImpl<OrgGroupPermission>
033            implements OrgGroupPermissionFinder {
034    
035            public static String FIND_BY_O_G_R =
036                    OrgGroupPermissionFinder.class.getName() + ".findByO_G_R";
037    
038            public void removeByO_G_R(
039                            long organizationId, long groupId, long resourceId)
040                    throws SystemException {
041    
042                    Session session = null;
043    
044                    try {
045                            session = openSession();
046    
047                            String sql = CustomSQLUtil.get(FIND_BY_O_G_R);
048    
049                            SQLQuery q = session.createSQLQuery(sql);
050    
051                            q.addEntity("OrgGroupPermission", OrgGroupPermissionImpl.class);
052    
053                            QueryPos qPos = QueryPos.getInstance(q);
054    
055                            qPos.add(resourceId);
056                            qPos.add(organizationId);
057                            qPos.add(groupId);
058    
059                            Iterator<OrgGroupPermission> itr = q.list().iterator();
060    
061                            while (itr.hasNext()) {
062                                    OrgGroupPermission orgGroupPermission = itr.next();
063    
064                                    OrgGroupPermissionUtil.remove(
065                                            orgGroupPermission.getPrimaryKey());
066                            }
067                    }
068                    catch (Exception e) {
069                            throw new SystemException(e);
070                    }
071                    finally {
072                            closeSession(session);
073                    }
074            }
075    
076    }