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     */
031    public class UserGroupGroupRoleFinderImpl
032            extends BasePersistenceImpl<UserGroupGroupRole>
033            implements UserGroupGroupRoleFinder {
034    
035            public static final String FIND_BY_USER_GROUPS_USERS =
036                    UserGroupGroupRoleFinder.class.getName() + ".findByUserGroupsUsers";
037    
038            @Override
039            public List<UserGroupGroupRole> findByUserGroupsUsers(long userId) {
040                    Session session = null;
041    
042                    try {
043                            session = openSession();
044    
045                            String sql = CustomSQLUtil.get(FIND_BY_USER_GROUPS_USERS);
046    
047                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
048    
049                            q.addEntity("UserGroupGroupRole", UserGroupGroupRoleImpl.class);
050    
051                            QueryPos qPos = QueryPos.getInstance(q);
052    
053                            qPos.add(userId);
054    
055                            return q.list(true);
056                    }
057                    catch (Exception e) {
058                            throw new SystemException(e);
059                    }
060                    finally {
061                            closeSession(session);
062                    }
063            }
064    
065    }