001    /**
002     * Copyright (c) 2000-present 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.impl;
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.UserGroupGroupRole;
022    import com.liferay.portal.model.impl.UserGroupGroupRoleImpl;
023    import com.liferay.portal.service.persistence.UserGroupGroupRoleFinder;
024    import com.liferay.util.dao.orm.CustomSQLUtil;
025    
026    import java.util.List;
027    
028    /**
029     * @author Norbert Kocsis
030     * @author Drew Brokke
031     */
032    public class UserGroupGroupRoleFinderImpl
033            extends UserGroupGroupRoleFinderBaseImpl
034            implements UserGroupGroupRoleFinder {
035    
036            public static final String FIND_BY_GROUP_ROLE_TYPE =
037                    UserGroupGroupRoleFinder.class.getName() + ".findByGroupRoleType";
038    
039            public static final String FIND_BY_USER_GROUPS_USERS =
040                    UserGroupGroupRoleFinder.class.getName() + ".findByUserGroupsUsers";
041    
042            @Override
043            public List<UserGroupGroupRole> findByGroupRoleType(
044                    long groupId, int roleType) {
045    
046                    Session session = null;
047    
048                    try {
049                            session = openSession();
050    
051                            String sql = CustomSQLUtil.get(FIND_BY_GROUP_ROLE_TYPE);
052    
053                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
054    
055                            q.addEntity("UserGroupGroupRole", UserGroupGroupRoleImpl.class);
056    
057                            QueryPos qPos = QueryPos.getInstance(q);
058    
059                            qPos.add(groupId);
060                            qPos.add(roleType);
061    
062                            return q.list(true);
063                    }
064                    catch (Exception e) {
065                            throw new SystemException(e);
066                    }
067                    finally {
068                            closeSession(session);
069                    }
070            }
071    
072            @Override
073            public List<UserGroupGroupRole> findByUserGroupsUsers(long userId) {
074                    Session session = null;
075    
076                    try {
077                            session = openSession();
078    
079                            String sql = CustomSQLUtil.get(FIND_BY_USER_GROUPS_USERS);
080    
081                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
082    
083                            q.addEntity("UserGroupGroupRole", UserGroupGroupRoleImpl.class);
084    
085                            QueryPos qPos = QueryPos.getInstance(q);
086    
087                            qPos.add(userId);
088    
089                            return q.list(true);
090                    }
091                    catch (Exception e) {
092                            throw new SystemException(e);
093                    }
094                    finally {
095                            closeSession(session);
096                    }
097            }
098    
099    }