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.UserGroupRole;
022    import com.liferay.portal.model.impl.UserGroupRoleImpl;
023    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
024    import com.liferay.util.dao.orm.CustomSQLUtil;
025    
026    import java.util.List;
027    
028    /**
029     * @author Brian Wing Shun Chan
030     */
031    public class UserGroupRoleFinderImpl
032            extends BasePersistenceImpl<UserGroupRole> implements UserGroupRoleFinder {
033    
034            public static final String FIND_BY_USER_USER_GROUP_GROUP_ROLE =
035                    UserGroupRoleFinder.class.getName() + ".findByUserUserGroupGroupRole";
036    
037            @Override
038            public List<UserGroupRole> findByUserUserGroupGroupRole(
039                            long userId, long groupId)
040                    throws SystemException {
041    
042                    Session session = null;
043    
044                    try {
045                            session = openSession();
046    
047                            String sql = CustomSQLUtil.get(FIND_BY_USER_USER_GROUP_GROUP_ROLE);
048    
049                            SQLQuery q = session.createSQLQuery(sql);
050    
051                            q.addEntity("UserGroupRole", UserGroupRoleImpl.class);
052    
053                            QueryPos qPos = QueryPos.getInstance(q);
054    
055                            qPos.add(userId);
056                            qPos.add(groupId);
057    
058                            return q.list(true);
059                    }
060                    catch (Exception e) {
061                            throw new SystemException(e);
062                    }
063                    finally {
064                            closeSession(session);
065                    }
066            }
067    
068    }