001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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 final String FIND_BY_O_G_R =
036                    OrgGroupPermissionFinder.class.getName() + ".findByO_G_R";
037    
038            @Override
039            public void removeByO_G_R(
040                            long organizationId, long groupId, long resourceId)
041                    throws SystemException {
042    
043                    Session session = null;
044    
045                    try {
046                            session = openSession();
047    
048                            String sql = CustomSQLUtil.get(FIND_BY_O_G_R);
049    
050                            SQLQuery q = session.createSQLQuery(sql);
051    
052                            q.addEntity("OrgGroupPermission", OrgGroupPermissionImpl.class);
053    
054                            QueryPos qPos = QueryPos.getInstance(q);
055    
056                            qPos.add(resourceId);
057                            qPos.add(organizationId);
058                            qPos.add(groupId);
059    
060                            Iterator<OrgGroupPermission> itr = q.iterate();
061    
062                            while (itr.hasNext()) {
063                                    OrgGroupPermission orgGroupPermission = itr.next();
064    
065                                    OrgGroupPermissionUtil.remove(
066                                            orgGroupPermission.getPrimaryKey());
067                            }
068                    }
069                    catch (Exception e) {
070                            throw new SystemException(e);
071                    }
072                    finally {
073                            closeSession(session);
074                    }
075            }
076    
077    }