001    /**
002     * Copyright (c) 2000-2013 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 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    }