/** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ package com.liferay.portal.service.persistence.impl; import aQute.bnd.annotation.ProviderType; import com.liferay.portal.kernel.bean.BeanReference; import com.liferay.portal.kernel.dao.orm.EntityCache; import com.liferay.portal.kernel.dao.orm.EntityCacheUtil; import com.liferay.portal.kernel.dao.orm.FinderCache; import com.liferay.portal.kernel.dao.orm.FinderCacheUtil; import com.liferay.portal.kernel.dao.orm.FinderPath; import com.liferay.portal.kernel.dao.orm.Query; import com.liferay.portal.kernel.dao.orm.QueryPos; import com.liferay.portal.kernel.dao.orm.QueryUtil; import com.liferay.portal.kernel.dao.orm.SQLQuery; import com.liferay.portal.kernel.dao.orm.Session; import com.liferay.portal.kernel.exception.NoSuchRoleException; import com.liferay.portal.kernel.log.Log; import com.liferay.portal.kernel.log.LogFactoryUtil; import com.liferay.portal.kernel.model.Role; import com.liferay.portal.kernel.security.permission.InlineSQLHelperUtil; import com.liferay.portal.kernel.service.ServiceContext; import com.liferay.portal.kernel.service.ServiceContextThreadLocal; import com.liferay.portal.kernel.service.persistence.CompanyProvider; import com.liferay.portal.kernel.service.persistence.CompanyProviderWrapper; import com.liferay.portal.kernel.service.persistence.GroupPersistence; import com.liferay.portal.kernel.service.persistence.RolePersistence; import com.liferay.portal.kernel.service.persistence.UserPersistence; import com.liferay.portal.kernel.service.persistence.impl.BasePersistenceImpl; import com.liferay.portal.kernel.service.persistence.impl.TableMapper; import com.liferay.portal.kernel.service.persistence.impl.TableMapperFactory; import com.liferay.portal.kernel.util.ArrayUtil; import com.liferay.portal.kernel.util.ListUtil; import com.liferay.portal.kernel.util.OrderByComparator; import com.liferay.portal.kernel.util.ReflectionUtil; import com.liferay.portal.kernel.util.SetUtil; import com.liferay.portal.kernel.util.StringBundler; import com.liferay.portal.kernel.util.StringPool; import com.liferay.portal.kernel.util.StringUtil; import com.liferay.portal.kernel.util.Validator; import com.liferay.portal.kernel.uuid.PortalUUIDUtil; import com.liferay.portal.model.impl.RoleImpl; import com.liferay.portal.model.impl.RoleModelImpl; import java.io.Serializable; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; /** * The persistence implementation for the role service. * * <p> * Caching information and settings can be found in <code>portal.properties</code> * </p> * * @author Brian Wing Shun Chan * @see RolePersistence * @see com.liferay.portal.kernel.service.persistence.RoleUtil * @generated */ @ProviderType public class RolePersistenceImpl extends BasePersistenceImpl<Role> implements RolePersistence { /* * NOTE FOR DEVELOPERS: * * Never modify or reference this class directly. Always use {@link RoleUtil} to access the role persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class. */ public static final String FINDER_CLASS_NAME_ENTITY = RoleImpl.class.getName(); public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY + ".List1"; public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY + ".List2"; public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]); public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]); public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]); public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid", new String[] { String.class.getName(), Integer.class.getName(), Integer.class.getName(), OrderByComparator.class.getName() }); public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid", new String[] { String.class.getName() }, RoleModelImpl.UUID_COLUMN_BITMASK | RoleModelImpl.NAME_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid", new String[] { String.class.getName() }); /** * Returns all the roles where uuid = ?. * * @param uuid the uuid * @return the matching roles */ @Override public List<Role> findByUuid(String uuid) { return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the roles where uuid = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param uuid the uuid * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @return the range of matching roles */ @Override public List<Role> findByUuid(String uuid, int start, int end) { return findByUuid(uuid, start, end, null); } /** * Returns an ordered range of all the roles where uuid = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param uuid the uuid * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching roles */ @Override public List<Role> findByUuid(String uuid, int start, int end, OrderByComparator<Role> orderByComparator) { return findByUuid(uuid, start, end, orderByComparator, true); } /** * Returns an ordered range of all the roles where uuid = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param uuid the uuid * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @param retrieveFromCache whether to retrieve from the finder cache * @return the ordered range of matching roles */ @Override public List<Role> findByUuid(String uuid, int start, int end, OrderByComparator<Role> orderByComparator, boolean retrieveFromCache) { boolean pagination = true; FinderPath finderPath = null; Object[] finderArgs = null; if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) { pagination = false; finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID; finderArgs = new Object[] { uuid }; } else { finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID; finderArgs = new Object[] { uuid, start, end, orderByComparator }; } List<Role> list = null; if (retrieveFromCache) { list = (List<Role>)finderCache.getResult(finderPath, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (Role role : list) { if (!Objects.equals(uuid, role.getUuid())) { list = null; break; } } } } if (list == null) { StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(3 + (orderByComparator.getOrderByFields().length * 2)); } else { query = new StringBundler(3); } query.append(_SQL_SELECT_ROLE_WHERE); boolean bindUuid = false; if (uuid == null) { query.append(_FINDER_COLUMN_UUID_UUID_1); } else if (uuid.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_UUID_UUID_3); } else { bindUuid = true; query.append(_FINDER_COLUMN_UUID_UUID_2); } if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(RoleModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); if (bindUuid) { qPos.add(uuid); } if (!pagination) { list = (List<Role>)QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<Role>)QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); finderCache.putResult(finderPath, finderArgs, list); } catch (Exception e) { finderCache.removeResult(finderPath, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; } /** * Returns the first role in the ordered set where uuid = ?. * * @param uuid the uuid * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching role * @throws NoSuchRoleException if a matching role could not be found */ @Override public Role findByUuid_First(String uuid, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { Role role = fetchByUuid_First(uuid, orderByComparator); if (role != null) { return role; } StringBundler msg = new StringBundler(4); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("uuid="); msg.append(uuid); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchRoleException(msg.toString()); } /** * Returns the first role in the ordered set where uuid = ?. * * @param uuid the uuid * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching role, or <code>null</code> if a matching role could not be found */ @Override public Role fetchByUuid_First(String uuid, OrderByComparator<Role> orderByComparator) { List<Role> list = findByUuid(uuid, 0, 1, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the last role in the ordered set where uuid = ?. * * @param uuid the uuid * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching role * @throws NoSuchRoleException if a matching role could not be found */ @Override public Role findByUuid_Last(String uuid, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { Role role = fetchByUuid_Last(uuid, orderByComparator); if (role != null) { return role; } StringBundler msg = new StringBundler(4); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("uuid="); msg.append(uuid); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchRoleException(msg.toString()); } /** * Returns the last role in the ordered set where uuid = ?. * * @param uuid the uuid * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching role, or <code>null</code> if a matching role could not be found */ @Override public Role fetchByUuid_Last(String uuid, OrderByComparator<Role> orderByComparator) { int count = countByUuid(uuid); if (count == 0) { return null; } List<Role> list = findByUuid(uuid, count - 1, count, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the roles before and after the current role in the ordered set where uuid = ?. * * @param roleId the primary key of the current role * @param uuid the uuid * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next role * @throws NoSuchRoleException if a role with the primary key could not be found */ @Override public Role[] findByUuid_PrevAndNext(long roleId, String uuid, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { Role role = findByPrimaryKey(roleId); Session session = null; try { session = openSession(); Role[] array = new RoleImpl[3]; array[0] = getByUuid_PrevAndNext(session, role, uuid, orderByComparator, true); array[1] = role; array[2] = getByUuid_PrevAndNext(session, role, uuid, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected Role getByUuid_PrevAndNext(Session session, Role role, String uuid, OrderByComparator<Role> orderByComparator, boolean previous) { StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(4 + (orderByComparator.getOrderByConditionFields().length * 3) + (orderByComparator.getOrderByFields().length * 3)); } else { query = new StringBundler(3); } query.append(_SQL_SELECT_ROLE_WHERE); boolean bindUuid = false; if (uuid == null) { query.append(_FINDER_COLUMN_UUID_UUID_1); } else if (uuid.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_UUID_UUID_3); } else { bindUuid = true; query.append(_FINDER_COLUMN_UUID_UUID_2); } if (orderByComparator != null) { String[] orderByConditionFields = orderByComparator.getOrderByConditionFields(); if (orderByConditionFields.length > 0) { query.append(WHERE_AND); } for (int i = 0; i < orderByConditionFields.length; i++) { query.append(_ORDER_BY_ENTITY_ALIAS); query.append(orderByConditionFields[i]); if ((i + 1) < orderByConditionFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN_HAS_NEXT); } else { query.append(WHERE_LESSER_THAN_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN); } else { query.append(WHERE_LESSER_THAN); } } } query.append(ORDER_BY_CLAUSE); String[] orderByFields = orderByComparator.getOrderByFields(); for (int i = 0; i < orderByFields.length; i++) { query.append(_ORDER_BY_ENTITY_ALIAS); query.append(orderByFields[i]); if ((i + 1) < orderByFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC_HAS_NEXT); } else { query.append(ORDER_BY_DESC_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC); } else { query.append(ORDER_BY_DESC); } } } } else { query.append(RoleModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Query q = session.createQuery(sql); q.setFirstResult(0); q.setMaxResults(2); QueryPos qPos = QueryPos.getInstance(q); if (bindUuid) { qPos.add(uuid); } if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(role); for (Object value : values) { qPos.add(value); } } List<Role> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Returns all the roles that the user has permission to view where uuid = ?. * * @param uuid the uuid * @return the matching roles that the user has permission to view */ @Override public List<Role> filterFindByUuid(String uuid) { return filterFindByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the roles that the user has permission to view where uuid = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param uuid the uuid * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @return the range of matching roles that the user has permission to view */ @Override public List<Role> filterFindByUuid(String uuid, int start, int end) { return filterFindByUuid(uuid, start, end, null); } /** * Returns an ordered range of all the roles that the user has permissions to view where uuid = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param uuid the uuid * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching roles that the user has permission to view */ @Override public List<Role> filterFindByUuid(String uuid, int start, int end, OrderByComparator<Role> orderByComparator) { if (!InlineSQLHelperUtil.isEnabled()) { return findByUuid(uuid, start, end, orderByComparator); } StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(3 + (orderByComparator.getOrderByFields().length * 2)); } else { query = new StringBundler(4); } if (getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_WHERE); } else { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1); } boolean bindUuid = false; if (uuid == null) { query.append(_FINDER_COLUMN_UUID_UUID_1_SQL); } else if (uuid.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_UUID_UUID_3_SQL); } else { bindUuid = true; query.append(_FINDER_COLUMN_UUID_UUID_2_SQL); } if (!getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2); } if (orderByComparator != null) { if (getDB().isSupportsInlineDistinct()) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator, true); } else { appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE, orderByComparator, true); } } else { if (getDB().isSupportsInlineDistinct()) { query.append(RoleModelImpl.ORDER_BY_JPQL); } else { query.append(RoleModelImpl.ORDER_BY_SQL); } } String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN); Session session = null; try { session = openSession(); SQLQuery q = session.createSynchronizedSQLQuery(sql); if (getDB().isSupportsInlineDistinct()) { q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class); } else { q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class); } QueryPos qPos = QueryPos.getInstance(q); if (bindUuid) { qPos.add(uuid); } return (List<Role>)QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } /** * Returns the roles before and after the current role in the ordered set of roles that the user has permission to view where uuid = ?. * * @param roleId the primary key of the current role * @param uuid the uuid * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next role * @throws NoSuchRoleException if a role with the primary key could not be found */ @Override public Role[] filterFindByUuid_PrevAndNext(long roleId, String uuid, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { if (!InlineSQLHelperUtil.isEnabled()) { return findByUuid_PrevAndNext(roleId, uuid, orderByComparator); } Role role = findByPrimaryKey(roleId); Session session = null; try { session = openSession(); Role[] array = new RoleImpl[3]; array[0] = filterGetByUuid_PrevAndNext(session, role, uuid, orderByComparator, true); array[1] = role; array[2] = filterGetByUuid_PrevAndNext(session, role, uuid, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected Role filterGetByUuid_PrevAndNext(Session session, Role role, String uuid, OrderByComparator<Role> orderByComparator, boolean previous) { StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(5 + (orderByComparator.getOrderByConditionFields().length * 3) + (orderByComparator.getOrderByFields().length * 3)); } else { query = new StringBundler(4); } if (getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_WHERE); } else { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1); } boolean bindUuid = false; if (uuid == null) { query.append(_FINDER_COLUMN_UUID_UUID_1_SQL); } else if (uuid.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_UUID_UUID_3_SQL); } else { bindUuid = true; query.append(_FINDER_COLUMN_UUID_UUID_2_SQL); } if (!getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2); } if (orderByComparator != null) { String[] orderByConditionFields = orderByComparator.getOrderByConditionFields(); if (orderByConditionFields.length > 0) { query.append(WHERE_AND); } for (int i = 0; i < orderByConditionFields.length; i++) { if (getDB().isSupportsInlineDistinct()) { query.append(_ORDER_BY_ENTITY_ALIAS); } else { query.append(_ORDER_BY_ENTITY_TABLE); } query.append(orderByConditionFields[i]); if ((i + 1) < orderByConditionFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN_HAS_NEXT); } else { query.append(WHERE_LESSER_THAN_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN); } else { query.append(WHERE_LESSER_THAN); } } } query.append(ORDER_BY_CLAUSE); String[] orderByFields = orderByComparator.getOrderByFields(); for (int i = 0; i < orderByFields.length; i++) { if (getDB().isSupportsInlineDistinct()) { query.append(_ORDER_BY_ENTITY_ALIAS); } else { query.append(_ORDER_BY_ENTITY_TABLE); } query.append(orderByFields[i]); if ((i + 1) < orderByFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC_HAS_NEXT); } else { query.append(ORDER_BY_DESC_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC); } else { query.append(ORDER_BY_DESC); } } } } else { if (getDB().isSupportsInlineDistinct()) { query.append(RoleModelImpl.ORDER_BY_JPQL); } else { query.append(RoleModelImpl.ORDER_BY_SQL); } } String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.setFirstResult(0); q.setMaxResults(2); if (getDB().isSupportsInlineDistinct()) { q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class); } else { q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class); } QueryPos qPos = QueryPos.getInstance(q); if (bindUuid) { qPos.add(uuid); } if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(role); for (Object value : values) { qPos.add(value); } } List<Role> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Removes all the roles where uuid = ? from the database. * * @param uuid the uuid */ @Override public void removeByUuid(String uuid) { for (Role role : findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) { remove(role); } } /** * Returns the number of roles where uuid = ?. * * @param uuid the uuid * @return the number of matching roles */ @Override public int countByUuid(String uuid) { FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID; Object[] finderArgs = new Object[] { uuid }; Long count = (Long)finderCache.getResult(finderPath, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(2); query.append(_SQL_COUNT_ROLE_WHERE); boolean bindUuid = false; if (uuid == null) { query.append(_FINDER_COLUMN_UUID_UUID_1); } else if (uuid.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_UUID_UUID_3); } else { bindUuid = true; query.append(_FINDER_COLUMN_UUID_UUID_2); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); if (bindUuid) { qPos.add(uuid); } count = (Long)q.uniqueResult(); finderCache.putResult(finderPath, finderArgs, count); } catch (Exception e) { finderCache.removeResult(finderPath, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); } /** * Returns the number of roles that the user has permission to view where uuid = ?. * * @param uuid the uuid * @return the number of matching roles that the user has permission to view */ @Override public int filterCountByUuid(String uuid) { if (!InlineSQLHelperUtil.isEnabled()) { return countByUuid(uuid); } StringBundler query = new StringBundler(2); query.append(_FILTER_SQL_COUNT_ROLE_WHERE); boolean bindUuid = false; if (uuid == null) { query.append(_FINDER_COLUMN_UUID_UUID_1_SQL); } else if (uuid.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_UUID_UUID_3_SQL); } else { bindUuid = true; query.append(_FINDER_COLUMN_UUID_UUID_2_SQL); } String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN); Session session = null; try { session = openSession(); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.addScalar(COUNT_COLUMN_NAME, com.liferay.portal.kernel.dao.orm.Type.LONG); QueryPos qPos = QueryPos.getInstance(q); if (bindUuid) { qPos.add(uuid); } Long count = (Long)q.uniqueResult(); return count.intValue(); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } private static final String _FINDER_COLUMN_UUID_UUID_1 = "role.uuid IS NULL"; private static final String _FINDER_COLUMN_UUID_UUID_2 = "role.uuid = ?"; private static final String _FINDER_COLUMN_UUID_UUID_3 = "(role.uuid IS NULL OR role.uuid = '')"; private static final String _FINDER_COLUMN_UUID_UUID_1_SQL = "role.uuid_ IS NULL"; private static final String _FINDER_COLUMN_UUID_UUID_2_SQL = "role.uuid_ = ?"; private static final String _FINDER_COLUMN_UUID_UUID_3_SQL = "(role.uuid_ IS NULL OR role.uuid_ = '')"; public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C", new String[] { String.class.getName(), Long.class.getName(), Integer.class.getName(), Integer.class.getName(), OrderByComparator.class.getName() }); public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C", new String[] { String.class.getName(), Long.class.getName() }, RoleModelImpl.UUID_COLUMN_BITMASK | RoleModelImpl.COMPANYID_COLUMN_BITMASK | RoleModelImpl.NAME_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C", new String[] { String.class.getName(), Long.class.getName() }); /** * Returns all the roles where uuid = ? and companyId = ?. * * @param uuid the uuid * @param companyId the company ID * @return the matching roles */ @Override public List<Role> findByUuid_C(String uuid, long companyId) { return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the roles where uuid = ? and companyId = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param uuid the uuid * @param companyId the company ID * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @return the range of matching roles */ @Override public List<Role> findByUuid_C(String uuid, long companyId, int start, int end) { return findByUuid_C(uuid, companyId, start, end, null); } /** * Returns an ordered range of all the roles where uuid = ? and companyId = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param uuid the uuid * @param companyId the company ID * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching roles */ @Override public List<Role> findByUuid_C(String uuid, long companyId, int start, int end, OrderByComparator<Role> orderByComparator) { return findByUuid_C(uuid, companyId, start, end, orderByComparator, true); } /** * Returns an ordered range of all the roles where uuid = ? and companyId = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param uuid the uuid * @param companyId the company ID * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @param retrieveFromCache whether to retrieve from the finder cache * @return the ordered range of matching roles */ @Override public List<Role> findByUuid_C(String uuid, long companyId, int start, int end, OrderByComparator<Role> orderByComparator, boolean retrieveFromCache) { boolean pagination = true; FinderPath finderPath = null; Object[] finderArgs = null; if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) { pagination = false; finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C; finderArgs = new Object[] { uuid, companyId }; } else { finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C; finderArgs = new Object[] { uuid, companyId, start, end, orderByComparator }; } List<Role> list = null; if (retrieveFromCache) { list = (List<Role>)finderCache.getResult(finderPath, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (Role role : list) { if (!Objects.equals(uuid, role.getUuid()) || (companyId != role.getCompanyId())) { list = null; break; } } } } if (list == null) { StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(4 + (orderByComparator.getOrderByFields().length * 2)); } else { query = new StringBundler(4); } query.append(_SQL_SELECT_ROLE_WHERE); boolean bindUuid = false; if (uuid == null) { query.append(_FINDER_COLUMN_UUID_C_UUID_1); } else if (uuid.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_UUID_C_UUID_3); } else { bindUuid = true; query.append(_FINDER_COLUMN_UUID_C_UUID_2); } query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2); if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(RoleModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); if (bindUuid) { qPos.add(uuid); } qPos.add(companyId); if (!pagination) { list = (List<Role>)QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<Role>)QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); finderCache.putResult(finderPath, finderArgs, list); } catch (Exception e) { finderCache.removeResult(finderPath, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; } /** * Returns the first role in the ordered set where uuid = ? and companyId = ?. * * @param uuid the uuid * @param companyId the company ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching role * @throws NoSuchRoleException if a matching role could not be found */ @Override public Role findByUuid_C_First(String uuid, long companyId, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { Role role = fetchByUuid_C_First(uuid, companyId, orderByComparator); if (role != null) { return role; } StringBundler msg = new StringBundler(6); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("uuid="); msg.append(uuid); msg.append(", companyId="); msg.append(companyId); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchRoleException(msg.toString()); } /** * Returns the first role in the ordered set where uuid = ? and companyId = ?. * * @param uuid the uuid * @param companyId the company ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching role, or <code>null</code> if a matching role could not be found */ @Override public Role fetchByUuid_C_First(String uuid, long companyId, OrderByComparator<Role> orderByComparator) { List<Role> list = findByUuid_C(uuid, companyId, 0, 1, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the last role in the ordered set where uuid = ? and companyId = ?. * * @param uuid the uuid * @param companyId the company ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching role * @throws NoSuchRoleException if a matching role could not be found */ @Override public Role findByUuid_C_Last(String uuid, long companyId, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { Role role = fetchByUuid_C_Last(uuid, companyId, orderByComparator); if (role != null) { return role; } StringBundler msg = new StringBundler(6); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("uuid="); msg.append(uuid); msg.append(", companyId="); msg.append(companyId); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchRoleException(msg.toString()); } /** * Returns the last role in the ordered set where uuid = ? and companyId = ?. * * @param uuid the uuid * @param companyId the company ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching role, or <code>null</code> if a matching role could not be found */ @Override public Role fetchByUuid_C_Last(String uuid, long companyId, OrderByComparator<Role> orderByComparator) { int count = countByUuid_C(uuid, companyId); if (count == 0) { return null; } List<Role> list = findByUuid_C(uuid, companyId, count - 1, count, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the roles before and after the current role in the ordered set where uuid = ? and companyId = ?. * * @param roleId the primary key of the current role * @param uuid the uuid * @param companyId the company ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next role * @throws NoSuchRoleException if a role with the primary key could not be found */ @Override public Role[] findByUuid_C_PrevAndNext(long roleId, String uuid, long companyId, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { Role role = findByPrimaryKey(roleId); Session session = null; try { session = openSession(); Role[] array = new RoleImpl[3]; array[0] = getByUuid_C_PrevAndNext(session, role, uuid, companyId, orderByComparator, true); array[1] = role; array[2] = getByUuid_C_PrevAndNext(session, role, uuid, companyId, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected Role getByUuid_C_PrevAndNext(Session session, Role role, String uuid, long companyId, OrderByComparator<Role> orderByComparator, boolean previous) { StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(5 + (orderByComparator.getOrderByConditionFields().length * 3) + (orderByComparator.getOrderByFields().length * 3)); } else { query = new StringBundler(4); } query.append(_SQL_SELECT_ROLE_WHERE); boolean bindUuid = false; if (uuid == null) { query.append(_FINDER_COLUMN_UUID_C_UUID_1); } else if (uuid.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_UUID_C_UUID_3); } else { bindUuid = true; query.append(_FINDER_COLUMN_UUID_C_UUID_2); } query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2); if (orderByComparator != null) { String[] orderByConditionFields = orderByComparator.getOrderByConditionFields(); if (orderByConditionFields.length > 0) { query.append(WHERE_AND); } for (int i = 0; i < orderByConditionFields.length; i++) { query.append(_ORDER_BY_ENTITY_ALIAS); query.append(orderByConditionFields[i]); if ((i + 1) < orderByConditionFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN_HAS_NEXT); } else { query.append(WHERE_LESSER_THAN_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN); } else { query.append(WHERE_LESSER_THAN); } } } query.append(ORDER_BY_CLAUSE); String[] orderByFields = orderByComparator.getOrderByFields(); for (int i = 0; i < orderByFields.length; i++) { query.append(_ORDER_BY_ENTITY_ALIAS); query.append(orderByFields[i]); if ((i + 1) < orderByFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC_HAS_NEXT); } else { query.append(ORDER_BY_DESC_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC); } else { query.append(ORDER_BY_DESC); } } } } else { query.append(RoleModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Query q = session.createQuery(sql); q.setFirstResult(0); q.setMaxResults(2); QueryPos qPos = QueryPos.getInstance(q); if (bindUuid) { qPos.add(uuid); } qPos.add(companyId); if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(role); for (Object value : values) { qPos.add(value); } } List<Role> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Returns all the roles that the user has permission to view where uuid = ? and companyId = ?. * * @param uuid the uuid * @param companyId the company ID * @return the matching roles that the user has permission to view */ @Override public List<Role> filterFindByUuid_C(String uuid, long companyId) { return filterFindByUuid_C(uuid, companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the roles that the user has permission to view where uuid = ? and companyId = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param uuid the uuid * @param companyId the company ID * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @return the range of matching roles that the user has permission to view */ @Override public List<Role> filterFindByUuid_C(String uuid, long companyId, int start, int end) { return filterFindByUuid_C(uuid, companyId, start, end, null); } /** * Returns an ordered range of all the roles that the user has permissions to view where uuid = ? and companyId = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param uuid the uuid * @param companyId the company ID * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching roles that the user has permission to view */ @Override public List<Role> filterFindByUuid_C(String uuid, long companyId, int start, int end, OrderByComparator<Role> orderByComparator) { if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) { return findByUuid_C(uuid, companyId, start, end, orderByComparator); } StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(4 + (orderByComparator.getOrderByFields().length * 2)); } else { query = new StringBundler(5); } if (getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_WHERE); } else { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1); } boolean bindUuid = false; if (uuid == null) { query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL); } else if (uuid.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL); } else { bindUuid = true; query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL); } query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2); if (!getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2); } if (orderByComparator != null) { if (getDB().isSupportsInlineDistinct()) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator, true); } else { appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE, orderByComparator, true); } } else { if (getDB().isSupportsInlineDistinct()) { query.append(RoleModelImpl.ORDER_BY_JPQL); } else { query.append(RoleModelImpl.ORDER_BY_SQL); } } String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN); Session session = null; try { session = openSession(); SQLQuery q = session.createSynchronizedSQLQuery(sql); if (getDB().isSupportsInlineDistinct()) { q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class); } else { q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class); } QueryPos qPos = QueryPos.getInstance(q); if (bindUuid) { qPos.add(uuid); } qPos.add(companyId); return (List<Role>)QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } /** * Returns the roles before and after the current role in the ordered set of roles that the user has permission to view where uuid = ? and companyId = ?. * * @param roleId the primary key of the current role * @param uuid the uuid * @param companyId the company ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next role * @throws NoSuchRoleException if a role with the primary key could not be found */ @Override public Role[] filterFindByUuid_C_PrevAndNext(long roleId, String uuid, long companyId, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) { return findByUuid_C_PrevAndNext(roleId, uuid, companyId, orderByComparator); } Role role = findByPrimaryKey(roleId); Session session = null; try { session = openSession(); Role[] array = new RoleImpl[3]; array[0] = filterGetByUuid_C_PrevAndNext(session, role, uuid, companyId, orderByComparator, true); array[1] = role; array[2] = filterGetByUuid_C_PrevAndNext(session, role, uuid, companyId, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected Role filterGetByUuid_C_PrevAndNext(Session session, Role role, String uuid, long companyId, OrderByComparator<Role> orderByComparator, boolean previous) { StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(6 + (orderByComparator.getOrderByConditionFields().length * 3) + (orderByComparator.getOrderByFields().length * 3)); } else { query = new StringBundler(5); } if (getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_WHERE); } else { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1); } boolean bindUuid = false; if (uuid == null) { query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL); } else if (uuid.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL); } else { bindUuid = true; query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL); } query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2); if (!getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2); } if (orderByComparator != null) { String[] orderByConditionFields = orderByComparator.getOrderByConditionFields(); if (orderByConditionFields.length > 0) { query.append(WHERE_AND); } for (int i = 0; i < orderByConditionFields.length; i++) { if (getDB().isSupportsInlineDistinct()) { query.append(_ORDER_BY_ENTITY_ALIAS); } else { query.append(_ORDER_BY_ENTITY_TABLE); } query.append(orderByConditionFields[i]); if ((i + 1) < orderByConditionFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN_HAS_NEXT); } else { query.append(WHERE_LESSER_THAN_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN); } else { query.append(WHERE_LESSER_THAN); } } } query.append(ORDER_BY_CLAUSE); String[] orderByFields = orderByComparator.getOrderByFields(); for (int i = 0; i < orderByFields.length; i++) { if (getDB().isSupportsInlineDistinct()) { query.append(_ORDER_BY_ENTITY_ALIAS); } else { query.append(_ORDER_BY_ENTITY_TABLE); } query.append(orderByFields[i]); if ((i + 1) < orderByFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC_HAS_NEXT); } else { query.append(ORDER_BY_DESC_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC); } else { query.append(ORDER_BY_DESC); } } } } else { if (getDB().isSupportsInlineDistinct()) { query.append(RoleModelImpl.ORDER_BY_JPQL); } else { query.append(RoleModelImpl.ORDER_BY_SQL); } } String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.setFirstResult(0); q.setMaxResults(2); if (getDB().isSupportsInlineDistinct()) { q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class); } else { q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class); } QueryPos qPos = QueryPos.getInstance(q); if (bindUuid) { qPos.add(uuid); } qPos.add(companyId); if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(role); for (Object value : values) { qPos.add(value); } } List<Role> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Removes all the roles where uuid = ? and companyId = ? from the database. * * @param uuid the uuid * @param companyId the company ID */ @Override public void removeByUuid_C(String uuid, long companyId) { for (Role role : findByUuid_C(uuid, companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) { remove(role); } } /** * Returns the number of roles where uuid = ? and companyId = ?. * * @param uuid the uuid * @param companyId the company ID * @return the number of matching roles */ @Override public int countByUuid_C(String uuid, long companyId) { FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C; Object[] finderArgs = new Object[] { uuid, companyId }; Long count = (Long)finderCache.getResult(finderPath, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(3); query.append(_SQL_COUNT_ROLE_WHERE); boolean bindUuid = false; if (uuid == null) { query.append(_FINDER_COLUMN_UUID_C_UUID_1); } else if (uuid.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_UUID_C_UUID_3); } else { bindUuid = true; query.append(_FINDER_COLUMN_UUID_C_UUID_2); } query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); if (bindUuid) { qPos.add(uuid); } qPos.add(companyId); count = (Long)q.uniqueResult(); finderCache.putResult(finderPath, finderArgs, count); } catch (Exception e) { finderCache.removeResult(finderPath, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); } /** * Returns the number of roles that the user has permission to view where uuid = ? and companyId = ?. * * @param uuid the uuid * @param companyId the company ID * @return the number of matching roles that the user has permission to view */ @Override public int filterCountByUuid_C(String uuid, long companyId) { if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) { return countByUuid_C(uuid, companyId); } StringBundler query = new StringBundler(3); query.append(_FILTER_SQL_COUNT_ROLE_WHERE); boolean bindUuid = false; if (uuid == null) { query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL); } else if (uuid.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL); } else { bindUuid = true; query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL); } query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2); String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN); Session session = null; try { session = openSession(); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.addScalar(COUNT_COLUMN_NAME, com.liferay.portal.kernel.dao.orm.Type.LONG); QueryPos qPos = QueryPos.getInstance(q); if (bindUuid) { qPos.add(uuid); } qPos.add(companyId); Long count = (Long)q.uniqueResult(); return count.intValue(); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "role.uuid IS NULL AND "; private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "role.uuid = ? AND "; private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(role.uuid IS NULL OR role.uuid = '') AND "; private static final String _FINDER_COLUMN_UUID_C_UUID_1_SQL = "role.uuid_ IS NULL AND "; private static final String _FINDER_COLUMN_UUID_C_UUID_2_SQL = "role.uuid_ = ? AND "; private static final String _FINDER_COLUMN_UUID_C_UUID_3_SQL = "(role.uuid_ IS NULL OR role.uuid_ = '') AND "; private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "role.companyId = ?"; public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId", new String[] { Long.class.getName(), Integer.class.getName(), Integer.class.getName(), OrderByComparator.class.getName() }); public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId", new String[] { Long.class.getName() }, RoleModelImpl.COMPANYID_COLUMN_BITMASK | RoleModelImpl.NAME_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId", new String[] { Long.class.getName() }); /** * Returns all the roles where companyId = ?. * * @param companyId the company ID * @return the matching roles */ @Override public List<Role> findByCompanyId(long companyId) { return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the roles where companyId = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param companyId the company ID * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @return the range of matching roles */ @Override public List<Role> findByCompanyId(long companyId, int start, int end) { return findByCompanyId(companyId, start, end, null); } /** * Returns an ordered range of all the roles where companyId = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param companyId the company ID * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching roles */ @Override public List<Role> findByCompanyId(long companyId, int start, int end, OrderByComparator<Role> orderByComparator) { return findByCompanyId(companyId, start, end, orderByComparator, true); } /** * Returns an ordered range of all the roles where companyId = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param companyId the company ID * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @param retrieveFromCache whether to retrieve from the finder cache * @return the ordered range of matching roles */ @Override public List<Role> findByCompanyId(long companyId, int start, int end, OrderByComparator<Role> orderByComparator, boolean retrieveFromCache) { boolean pagination = true; FinderPath finderPath = null; Object[] finderArgs = null; if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) { pagination = false; finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID; finderArgs = new Object[] { companyId }; } else { finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID; finderArgs = new Object[] { companyId, start, end, orderByComparator }; } List<Role> list = null; if (retrieveFromCache) { list = (List<Role>)finderCache.getResult(finderPath, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (Role role : list) { if ((companyId != role.getCompanyId())) { list = null; break; } } } } if (list == null) { StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(3 + (orderByComparator.getOrderByFields().length * 2)); } else { query = new StringBundler(3); } query.append(_SQL_SELECT_ROLE_WHERE); query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2); if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(RoleModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); if (!pagination) { list = (List<Role>)QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<Role>)QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); finderCache.putResult(finderPath, finderArgs, list); } catch (Exception e) { finderCache.removeResult(finderPath, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; } /** * Returns the first role in the ordered set where companyId = ?. * * @param companyId the company ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching role * @throws NoSuchRoleException if a matching role could not be found */ @Override public Role findByCompanyId_First(long companyId, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { Role role = fetchByCompanyId_First(companyId, orderByComparator); if (role != null) { return role; } StringBundler msg = new StringBundler(4); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("companyId="); msg.append(companyId); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchRoleException(msg.toString()); } /** * Returns the first role in the ordered set where companyId = ?. * * @param companyId the company ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching role, or <code>null</code> if a matching role could not be found */ @Override public Role fetchByCompanyId_First(long companyId, OrderByComparator<Role> orderByComparator) { List<Role> list = findByCompanyId(companyId, 0, 1, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the last role in the ordered set where companyId = ?. * * @param companyId the company ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching role * @throws NoSuchRoleException if a matching role could not be found */ @Override public Role findByCompanyId_Last(long companyId, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { Role role = fetchByCompanyId_Last(companyId, orderByComparator); if (role != null) { return role; } StringBundler msg = new StringBundler(4); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("companyId="); msg.append(companyId); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchRoleException(msg.toString()); } /** * Returns the last role in the ordered set where companyId = ?. * * @param companyId the company ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching role, or <code>null</code> if a matching role could not be found */ @Override public Role fetchByCompanyId_Last(long companyId, OrderByComparator<Role> orderByComparator) { int count = countByCompanyId(companyId); if (count == 0) { return null; } List<Role> list = findByCompanyId(companyId, count - 1, count, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the roles before and after the current role in the ordered set where companyId = ?. * * @param roleId the primary key of the current role * @param companyId the company ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next role * @throws NoSuchRoleException if a role with the primary key could not be found */ @Override public Role[] findByCompanyId_PrevAndNext(long roleId, long companyId, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { Role role = findByPrimaryKey(roleId); Session session = null; try { session = openSession(); Role[] array = new RoleImpl[3]; array[0] = getByCompanyId_PrevAndNext(session, role, companyId, orderByComparator, true); array[1] = role; array[2] = getByCompanyId_PrevAndNext(session, role, companyId, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected Role getByCompanyId_PrevAndNext(Session session, Role role, long companyId, OrderByComparator<Role> orderByComparator, boolean previous) { StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(4 + (orderByComparator.getOrderByConditionFields().length * 3) + (orderByComparator.getOrderByFields().length * 3)); } else { query = new StringBundler(3); } query.append(_SQL_SELECT_ROLE_WHERE); query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2); if (orderByComparator != null) { String[] orderByConditionFields = orderByComparator.getOrderByConditionFields(); if (orderByConditionFields.length > 0) { query.append(WHERE_AND); } for (int i = 0; i < orderByConditionFields.length; i++) { query.append(_ORDER_BY_ENTITY_ALIAS); query.append(orderByConditionFields[i]); if ((i + 1) < orderByConditionFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN_HAS_NEXT); } else { query.append(WHERE_LESSER_THAN_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN); } else { query.append(WHERE_LESSER_THAN); } } } query.append(ORDER_BY_CLAUSE); String[] orderByFields = orderByComparator.getOrderByFields(); for (int i = 0; i < orderByFields.length; i++) { query.append(_ORDER_BY_ENTITY_ALIAS); query.append(orderByFields[i]); if ((i + 1) < orderByFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC_HAS_NEXT); } else { query.append(ORDER_BY_DESC_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC); } else { query.append(ORDER_BY_DESC); } } } } else { query.append(RoleModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Query q = session.createQuery(sql); q.setFirstResult(0); q.setMaxResults(2); QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(role); for (Object value : values) { qPos.add(value); } } List<Role> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Returns all the roles that the user has permission to view where companyId = ?. * * @param companyId the company ID * @return the matching roles that the user has permission to view */ @Override public List<Role> filterFindByCompanyId(long companyId) { return filterFindByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the roles that the user has permission to view where companyId = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param companyId the company ID * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @return the range of matching roles that the user has permission to view */ @Override public List<Role> filterFindByCompanyId(long companyId, int start, int end) { return filterFindByCompanyId(companyId, start, end, null); } /** * Returns an ordered range of all the roles that the user has permissions to view where companyId = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param companyId the company ID * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching roles that the user has permission to view */ @Override public List<Role> filterFindByCompanyId(long companyId, int start, int end, OrderByComparator<Role> orderByComparator) { if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) { return findByCompanyId(companyId, start, end, orderByComparator); } StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(3 + (orderByComparator.getOrderByFields().length * 2)); } else { query = new StringBundler(4); } if (getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_WHERE); } else { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1); } query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2); if (!getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2); } if (orderByComparator != null) { if (getDB().isSupportsInlineDistinct()) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator, true); } else { appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE, orderByComparator, true); } } else { if (getDB().isSupportsInlineDistinct()) { query.append(RoleModelImpl.ORDER_BY_JPQL); } else { query.append(RoleModelImpl.ORDER_BY_SQL); } } String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN); Session session = null; try { session = openSession(); SQLQuery q = session.createSynchronizedSQLQuery(sql); if (getDB().isSupportsInlineDistinct()) { q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class); } else { q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class); } QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); return (List<Role>)QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } /** * Returns the roles before and after the current role in the ordered set of roles that the user has permission to view where companyId = ?. * * @param roleId the primary key of the current role * @param companyId the company ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next role * @throws NoSuchRoleException if a role with the primary key could not be found */ @Override public Role[] filterFindByCompanyId_PrevAndNext(long roleId, long companyId, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) { return findByCompanyId_PrevAndNext(roleId, companyId, orderByComparator); } Role role = findByPrimaryKey(roleId); Session session = null; try { session = openSession(); Role[] array = new RoleImpl[3]; array[0] = filterGetByCompanyId_PrevAndNext(session, role, companyId, orderByComparator, true); array[1] = role; array[2] = filterGetByCompanyId_PrevAndNext(session, role, companyId, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected Role filterGetByCompanyId_PrevAndNext(Session session, Role role, long companyId, OrderByComparator<Role> orderByComparator, boolean previous) { StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(5 + (orderByComparator.getOrderByConditionFields().length * 3) + (orderByComparator.getOrderByFields().length * 3)); } else { query = new StringBundler(4); } if (getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_WHERE); } else { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1); } query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2); if (!getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2); } if (orderByComparator != null) { String[] orderByConditionFields = orderByComparator.getOrderByConditionFields(); if (orderByConditionFields.length > 0) { query.append(WHERE_AND); } for (int i = 0; i < orderByConditionFields.length; i++) { if (getDB().isSupportsInlineDistinct()) { query.append(_ORDER_BY_ENTITY_ALIAS); } else { query.append(_ORDER_BY_ENTITY_TABLE); } query.append(orderByConditionFields[i]); if ((i + 1) < orderByConditionFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN_HAS_NEXT); } else { query.append(WHERE_LESSER_THAN_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN); } else { query.append(WHERE_LESSER_THAN); } } } query.append(ORDER_BY_CLAUSE); String[] orderByFields = orderByComparator.getOrderByFields(); for (int i = 0; i < orderByFields.length; i++) { if (getDB().isSupportsInlineDistinct()) { query.append(_ORDER_BY_ENTITY_ALIAS); } else { query.append(_ORDER_BY_ENTITY_TABLE); } query.append(orderByFields[i]); if ((i + 1) < orderByFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC_HAS_NEXT); } else { query.append(ORDER_BY_DESC_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC); } else { query.append(ORDER_BY_DESC); } } } } else { if (getDB().isSupportsInlineDistinct()) { query.append(RoleModelImpl.ORDER_BY_JPQL); } else { query.append(RoleModelImpl.ORDER_BY_SQL); } } String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.setFirstResult(0); q.setMaxResults(2); if (getDB().isSupportsInlineDistinct()) { q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class); } else { q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class); } QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(role); for (Object value : values) { qPos.add(value); } } List<Role> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Removes all the roles where companyId = ? from the database. * * @param companyId the company ID */ @Override public void removeByCompanyId(long companyId) { for (Role role : findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) { remove(role); } } /** * Returns the number of roles where companyId = ?. * * @param companyId the company ID * @return the number of matching roles */ @Override public int countByCompanyId(long companyId) { FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID; Object[] finderArgs = new Object[] { companyId }; Long count = (Long)finderCache.getResult(finderPath, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(2); query.append(_SQL_COUNT_ROLE_WHERE); query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); count = (Long)q.uniqueResult(); finderCache.putResult(finderPath, finderArgs, count); } catch (Exception e) { finderCache.removeResult(finderPath, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); } /** * Returns the number of roles that the user has permission to view where companyId = ?. * * @param companyId the company ID * @return the number of matching roles that the user has permission to view */ @Override public int filterCountByCompanyId(long companyId) { if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) { return countByCompanyId(companyId); } StringBundler query = new StringBundler(2); query.append(_FILTER_SQL_COUNT_ROLE_WHERE); query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2); String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN); Session session = null; try { session = openSession(); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.addScalar(COUNT_COLUMN_NAME, com.liferay.portal.kernel.dao.orm.Type.LONG); QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); Long count = (Long)q.uniqueResult(); return count.intValue(); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "role.companyId = ?"; public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByName", new String[] { String.class.getName(), Integer.class.getName(), Integer.class.getName(), OrderByComparator.class.getName() }); public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByName", new String[] { String.class.getName() }, RoleModelImpl.NAME_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_COUNT_BY_NAME = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByName", new String[] { String.class.getName() }); /** * Returns all the roles where name = ?. * * @param name the name * @return the matching roles */ @Override public List<Role> findByName(String name) { return findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the roles where name = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param name the name * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @return the range of matching roles */ @Override public List<Role> findByName(String name, int start, int end) { return findByName(name, start, end, null); } /** * Returns an ordered range of all the roles where name = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param name the name * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching roles */ @Override public List<Role> findByName(String name, int start, int end, OrderByComparator<Role> orderByComparator) { return findByName(name, start, end, orderByComparator, true); } /** * Returns an ordered range of all the roles where name = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param name the name * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @param retrieveFromCache whether to retrieve from the finder cache * @return the ordered range of matching roles */ @Override public List<Role> findByName(String name, int start, int end, OrderByComparator<Role> orderByComparator, boolean retrieveFromCache) { boolean pagination = true; FinderPath finderPath = null; Object[] finderArgs = null; if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) { pagination = false; finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME; finderArgs = new Object[] { name }; } else { finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME; finderArgs = new Object[] { name, start, end, orderByComparator }; } List<Role> list = null; if (retrieveFromCache) { list = (List<Role>)finderCache.getResult(finderPath, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (Role role : list) { if (!Objects.equals(name, role.getName())) { list = null; break; } } } } if (list == null) { StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(3 + (orderByComparator.getOrderByFields().length * 2)); } else { query = new StringBundler(3); } query.append(_SQL_SELECT_ROLE_WHERE); boolean bindName = false; if (name == null) { query.append(_FINDER_COLUMN_NAME_NAME_1); } else if (name.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_NAME_NAME_3); } else { bindName = true; query.append(_FINDER_COLUMN_NAME_NAME_2); } if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(RoleModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); if (bindName) { qPos.add(name); } if (!pagination) { list = (List<Role>)QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<Role>)QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); finderCache.putResult(finderPath, finderArgs, list); } catch (Exception e) { finderCache.removeResult(finderPath, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; } /** * Returns the first role in the ordered set where name = ?. * * @param name the name * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching role * @throws NoSuchRoleException if a matching role could not be found */ @Override public Role findByName_First(String name, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { Role role = fetchByName_First(name, orderByComparator); if (role != null) { return role; } StringBundler msg = new StringBundler(4); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("name="); msg.append(name); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchRoleException(msg.toString()); } /** * Returns the first role in the ordered set where name = ?. * * @param name the name * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching role, or <code>null</code> if a matching role could not be found */ @Override public Role fetchByName_First(String name, OrderByComparator<Role> orderByComparator) { List<Role> list = findByName(name, 0, 1, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the last role in the ordered set where name = ?. * * @param name the name * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching role * @throws NoSuchRoleException if a matching role could not be found */ @Override public Role findByName_Last(String name, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { Role role = fetchByName_Last(name, orderByComparator); if (role != null) { return role; } StringBundler msg = new StringBundler(4); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("name="); msg.append(name); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchRoleException(msg.toString()); } /** * Returns the last role in the ordered set where name = ?. * * @param name the name * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching role, or <code>null</code> if a matching role could not be found */ @Override public Role fetchByName_Last(String name, OrderByComparator<Role> orderByComparator) { int count = countByName(name); if (count == 0) { return null; } List<Role> list = findByName(name, count - 1, count, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the roles before and after the current role in the ordered set where name = ?. * * @param roleId the primary key of the current role * @param name the name * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next role * @throws NoSuchRoleException if a role with the primary key could not be found */ @Override public Role[] findByName_PrevAndNext(long roleId, String name, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { Role role = findByPrimaryKey(roleId); Session session = null; try { session = openSession(); Role[] array = new RoleImpl[3]; array[0] = getByName_PrevAndNext(session, role, name, orderByComparator, true); array[1] = role; array[2] = getByName_PrevAndNext(session, role, name, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected Role getByName_PrevAndNext(Session session, Role role, String name, OrderByComparator<Role> orderByComparator, boolean previous) { StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(4 + (orderByComparator.getOrderByConditionFields().length * 3) + (orderByComparator.getOrderByFields().length * 3)); } else { query = new StringBundler(3); } query.append(_SQL_SELECT_ROLE_WHERE); boolean bindName = false; if (name == null) { query.append(_FINDER_COLUMN_NAME_NAME_1); } else if (name.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_NAME_NAME_3); } else { bindName = true; query.append(_FINDER_COLUMN_NAME_NAME_2); } if (orderByComparator != null) { String[] orderByConditionFields = orderByComparator.getOrderByConditionFields(); if (orderByConditionFields.length > 0) { query.append(WHERE_AND); } for (int i = 0; i < orderByConditionFields.length; i++) { query.append(_ORDER_BY_ENTITY_ALIAS); query.append(orderByConditionFields[i]); if ((i + 1) < orderByConditionFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN_HAS_NEXT); } else { query.append(WHERE_LESSER_THAN_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN); } else { query.append(WHERE_LESSER_THAN); } } } query.append(ORDER_BY_CLAUSE); String[] orderByFields = orderByComparator.getOrderByFields(); for (int i = 0; i < orderByFields.length; i++) { query.append(_ORDER_BY_ENTITY_ALIAS); query.append(orderByFields[i]); if ((i + 1) < orderByFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC_HAS_NEXT); } else { query.append(ORDER_BY_DESC_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC); } else { query.append(ORDER_BY_DESC); } } } } else { query.append(RoleModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Query q = session.createQuery(sql); q.setFirstResult(0); q.setMaxResults(2); QueryPos qPos = QueryPos.getInstance(q); if (bindName) { qPos.add(name); } if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(role); for (Object value : values) { qPos.add(value); } } List<Role> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Returns all the roles that the user has permission to view where name = ?. * * @param name the name * @return the matching roles that the user has permission to view */ @Override public List<Role> filterFindByName(String name) { return filterFindByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the roles that the user has permission to view where name = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param name the name * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @return the range of matching roles that the user has permission to view */ @Override public List<Role> filterFindByName(String name, int start, int end) { return filterFindByName(name, start, end, null); } /** * Returns an ordered range of all the roles that the user has permissions to view where name = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param name the name * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching roles that the user has permission to view */ @Override public List<Role> filterFindByName(String name, int start, int end, OrderByComparator<Role> orderByComparator) { if (!InlineSQLHelperUtil.isEnabled()) { return findByName(name, start, end, orderByComparator); } StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(3 + (orderByComparator.getOrderByFields().length * 2)); } else { query = new StringBundler(4); } if (getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_WHERE); } else { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1); } boolean bindName = false; if (name == null) { query.append(_FINDER_COLUMN_NAME_NAME_1); } else if (name.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_NAME_NAME_3); } else { bindName = true; query.append(_FINDER_COLUMN_NAME_NAME_2); } if (!getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2); } if (orderByComparator != null) { if (getDB().isSupportsInlineDistinct()) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator, true); } else { appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE, orderByComparator, true); } } else { if (getDB().isSupportsInlineDistinct()) { query.append(RoleModelImpl.ORDER_BY_JPQL); } else { query.append(RoleModelImpl.ORDER_BY_SQL); } } String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN); Session session = null; try { session = openSession(); SQLQuery q = session.createSynchronizedSQLQuery(sql); if (getDB().isSupportsInlineDistinct()) { q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class); } else { q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class); } QueryPos qPos = QueryPos.getInstance(q); if (bindName) { qPos.add(name); } return (List<Role>)QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } /** * Returns the roles before and after the current role in the ordered set of roles that the user has permission to view where name = ?. * * @param roleId the primary key of the current role * @param name the name * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next role * @throws NoSuchRoleException if a role with the primary key could not be found */ @Override public Role[] filterFindByName_PrevAndNext(long roleId, String name, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { if (!InlineSQLHelperUtil.isEnabled()) { return findByName_PrevAndNext(roleId, name, orderByComparator); } Role role = findByPrimaryKey(roleId); Session session = null; try { session = openSession(); Role[] array = new RoleImpl[3]; array[0] = filterGetByName_PrevAndNext(session, role, name, orderByComparator, true); array[1] = role; array[2] = filterGetByName_PrevAndNext(session, role, name, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected Role filterGetByName_PrevAndNext(Session session, Role role, String name, OrderByComparator<Role> orderByComparator, boolean previous) { StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(5 + (orderByComparator.getOrderByConditionFields().length * 3) + (orderByComparator.getOrderByFields().length * 3)); } else { query = new StringBundler(4); } if (getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_WHERE); } else { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1); } boolean bindName = false; if (name == null) { query.append(_FINDER_COLUMN_NAME_NAME_1); } else if (name.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_NAME_NAME_3); } else { bindName = true; query.append(_FINDER_COLUMN_NAME_NAME_2); } if (!getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2); } if (orderByComparator != null) { String[] orderByConditionFields = orderByComparator.getOrderByConditionFields(); if (orderByConditionFields.length > 0) { query.append(WHERE_AND); } for (int i = 0; i < orderByConditionFields.length; i++) { if (getDB().isSupportsInlineDistinct()) { query.append(_ORDER_BY_ENTITY_ALIAS); } else { query.append(_ORDER_BY_ENTITY_TABLE); } query.append(orderByConditionFields[i]); if ((i + 1) < orderByConditionFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN_HAS_NEXT); } else { query.append(WHERE_LESSER_THAN_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN); } else { query.append(WHERE_LESSER_THAN); } } } query.append(ORDER_BY_CLAUSE); String[] orderByFields = orderByComparator.getOrderByFields(); for (int i = 0; i < orderByFields.length; i++) { if (getDB().isSupportsInlineDistinct()) { query.append(_ORDER_BY_ENTITY_ALIAS); } else { query.append(_ORDER_BY_ENTITY_TABLE); } query.append(orderByFields[i]); if ((i + 1) < orderByFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC_HAS_NEXT); } else { query.append(ORDER_BY_DESC_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC); } else { query.append(ORDER_BY_DESC); } } } } else { if (getDB().isSupportsInlineDistinct()) { query.append(RoleModelImpl.ORDER_BY_JPQL); } else { query.append(RoleModelImpl.ORDER_BY_SQL); } } String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.setFirstResult(0); q.setMaxResults(2); if (getDB().isSupportsInlineDistinct()) { q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class); } else { q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class); } QueryPos qPos = QueryPos.getInstance(q); if (bindName) { qPos.add(name); } if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(role); for (Object value : values) { qPos.add(value); } } List<Role> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Removes all the roles where name = ? from the database. * * @param name the name */ @Override public void removeByName(String name) { for (Role role : findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) { remove(role); } } /** * Returns the number of roles where name = ?. * * @param name the name * @return the number of matching roles */ @Override public int countByName(String name) { FinderPath finderPath = FINDER_PATH_COUNT_BY_NAME; Object[] finderArgs = new Object[] { name }; Long count = (Long)finderCache.getResult(finderPath, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(2); query.append(_SQL_COUNT_ROLE_WHERE); boolean bindName = false; if (name == null) { query.append(_FINDER_COLUMN_NAME_NAME_1); } else if (name.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_NAME_NAME_3); } else { bindName = true; query.append(_FINDER_COLUMN_NAME_NAME_2); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); if (bindName) { qPos.add(name); } count = (Long)q.uniqueResult(); finderCache.putResult(finderPath, finderArgs, count); } catch (Exception e) { finderCache.removeResult(finderPath, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); } /** * Returns the number of roles that the user has permission to view where name = ?. * * @param name the name * @return the number of matching roles that the user has permission to view */ @Override public int filterCountByName(String name) { if (!InlineSQLHelperUtil.isEnabled()) { return countByName(name); } StringBundler query = new StringBundler(2); query.append(_FILTER_SQL_COUNT_ROLE_WHERE); boolean bindName = false; if (name == null) { query.append(_FINDER_COLUMN_NAME_NAME_1); } else if (name.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_NAME_NAME_3); } else { bindName = true; query.append(_FINDER_COLUMN_NAME_NAME_2); } String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN); Session session = null; try { session = openSession(); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.addScalar(COUNT_COLUMN_NAME, com.liferay.portal.kernel.dao.orm.Type.LONG); QueryPos qPos = QueryPos.getInstance(q); if (bindName) { qPos.add(name); } Long count = (Long)q.uniqueResult(); return count.intValue(); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } private static final String _FINDER_COLUMN_NAME_NAME_1 = "role.name IS NULL"; private static final String _FINDER_COLUMN_NAME_NAME_2 = "role.name = ?"; private static final String _FINDER_COLUMN_NAME_NAME_3 = "(role.name IS NULL OR role.name = '')"; public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByType", new String[] { Integer.class.getName(), Integer.class.getName(), Integer.class.getName(), OrderByComparator.class.getName() }); public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByType", new String[] { Integer.class.getName() }, RoleModelImpl.TYPE_COLUMN_BITMASK | RoleModelImpl.NAME_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_COUNT_BY_TYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByType", new String[] { Integer.class.getName() }); /** * Returns all the roles where type = ?. * * @param type the type * @return the matching roles */ @Override public List<Role> findByType(int type) { return findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the roles where type = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param type the type * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @return the range of matching roles */ @Override public List<Role> findByType(int type, int start, int end) { return findByType(type, start, end, null); } /** * Returns an ordered range of all the roles where type = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param type the type * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching roles */ @Override public List<Role> findByType(int type, int start, int end, OrderByComparator<Role> orderByComparator) { return findByType(type, start, end, orderByComparator, true); } /** * Returns an ordered range of all the roles where type = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param type the type * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @param retrieveFromCache whether to retrieve from the finder cache * @return the ordered range of matching roles */ @Override public List<Role> findByType(int type, int start, int end, OrderByComparator<Role> orderByComparator, boolean retrieveFromCache) { boolean pagination = true; FinderPath finderPath = null; Object[] finderArgs = null; if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) { pagination = false; finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE; finderArgs = new Object[] { type }; } else { finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE; finderArgs = new Object[] { type, start, end, orderByComparator }; } List<Role> list = null; if (retrieveFromCache) { list = (List<Role>)finderCache.getResult(finderPath, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (Role role : list) { if ((type != role.getType())) { list = null; break; } } } } if (list == null) { StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(3 + (orderByComparator.getOrderByFields().length * 2)); } else { query = new StringBundler(3); } query.append(_SQL_SELECT_ROLE_WHERE); query.append(_FINDER_COLUMN_TYPE_TYPE_2); if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(RoleModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(type); if (!pagination) { list = (List<Role>)QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<Role>)QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); finderCache.putResult(finderPath, finderArgs, list); } catch (Exception e) { finderCache.removeResult(finderPath, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; } /** * Returns the first role in the ordered set where type = ?. * * @param type the type * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching role * @throws NoSuchRoleException if a matching role could not be found */ @Override public Role findByType_First(int type, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { Role role = fetchByType_First(type, orderByComparator); if (role != null) { return role; } StringBundler msg = new StringBundler(4); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("type="); msg.append(type); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchRoleException(msg.toString()); } /** * Returns the first role in the ordered set where type = ?. * * @param type the type * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching role, or <code>null</code> if a matching role could not be found */ @Override public Role fetchByType_First(int type, OrderByComparator<Role> orderByComparator) { List<Role> list = findByType(type, 0, 1, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the last role in the ordered set where type = ?. * * @param type the type * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching role * @throws NoSuchRoleException if a matching role could not be found */ @Override public Role findByType_Last(int type, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { Role role = fetchByType_Last(type, orderByComparator); if (role != null) { return role; } StringBundler msg = new StringBundler(4); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("type="); msg.append(type); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchRoleException(msg.toString()); } /** * Returns the last role in the ordered set where type = ?. * * @param type the type * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching role, or <code>null</code> if a matching role could not be found */ @Override public Role fetchByType_Last(int type, OrderByComparator<Role> orderByComparator) { int count = countByType(type); if (count == 0) { return null; } List<Role> list = findByType(type, count - 1, count, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the roles before and after the current role in the ordered set where type = ?. * * @param roleId the primary key of the current role * @param type the type * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next role * @throws NoSuchRoleException if a role with the primary key could not be found */ @Override public Role[] findByType_PrevAndNext(long roleId, int type, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { Role role = findByPrimaryKey(roleId); Session session = null; try { session = openSession(); Role[] array = new RoleImpl[3]; array[0] = getByType_PrevAndNext(session, role, type, orderByComparator, true); array[1] = role; array[2] = getByType_PrevAndNext(session, role, type, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected Role getByType_PrevAndNext(Session session, Role role, int type, OrderByComparator<Role> orderByComparator, boolean previous) { StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(4 + (orderByComparator.getOrderByConditionFields().length * 3) + (orderByComparator.getOrderByFields().length * 3)); } else { query = new StringBundler(3); } query.append(_SQL_SELECT_ROLE_WHERE); query.append(_FINDER_COLUMN_TYPE_TYPE_2); if (orderByComparator != null) { String[] orderByConditionFields = orderByComparator.getOrderByConditionFields(); if (orderByConditionFields.length > 0) { query.append(WHERE_AND); } for (int i = 0; i < orderByConditionFields.length; i++) { query.append(_ORDER_BY_ENTITY_ALIAS); query.append(orderByConditionFields[i]); if ((i + 1) < orderByConditionFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN_HAS_NEXT); } else { query.append(WHERE_LESSER_THAN_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN); } else { query.append(WHERE_LESSER_THAN); } } } query.append(ORDER_BY_CLAUSE); String[] orderByFields = orderByComparator.getOrderByFields(); for (int i = 0; i < orderByFields.length; i++) { query.append(_ORDER_BY_ENTITY_ALIAS); query.append(orderByFields[i]); if ((i + 1) < orderByFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC_HAS_NEXT); } else { query.append(ORDER_BY_DESC_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC); } else { query.append(ORDER_BY_DESC); } } } } else { query.append(RoleModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Query q = session.createQuery(sql); q.setFirstResult(0); q.setMaxResults(2); QueryPos qPos = QueryPos.getInstance(q); qPos.add(type); if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(role); for (Object value : values) { qPos.add(value); } } List<Role> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Returns all the roles that the user has permission to view where type = ?. * * @param type the type * @return the matching roles that the user has permission to view */ @Override public List<Role> filterFindByType(int type) { return filterFindByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the roles that the user has permission to view where type = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param type the type * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @return the range of matching roles that the user has permission to view */ @Override public List<Role> filterFindByType(int type, int start, int end) { return filterFindByType(type, start, end, null); } /** * Returns an ordered range of all the roles that the user has permissions to view where type = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param type the type * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching roles that the user has permission to view */ @Override public List<Role> filterFindByType(int type, int start, int end, OrderByComparator<Role> orderByComparator) { if (!InlineSQLHelperUtil.isEnabled()) { return findByType(type, start, end, orderByComparator); } StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(3 + (orderByComparator.getOrderByFields().length * 2)); } else { query = new StringBundler(4); } if (getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_WHERE); } else { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1); } query.append(_FINDER_COLUMN_TYPE_TYPE_2_SQL); if (!getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2); } if (orderByComparator != null) { if (getDB().isSupportsInlineDistinct()) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator, true); } else { appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE, orderByComparator, true); } } else { if (getDB().isSupportsInlineDistinct()) { query.append(RoleModelImpl.ORDER_BY_JPQL); } else { query.append(RoleModelImpl.ORDER_BY_SQL); } } String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN); Session session = null; try { session = openSession(); SQLQuery q = session.createSynchronizedSQLQuery(sql); if (getDB().isSupportsInlineDistinct()) { q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class); } else { q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class); } QueryPos qPos = QueryPos.getInstance(q); qPos.add(type); return (List<Role>)QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } /** * Returns the roles before and after the current role in the ordered set of roles that the user has permission to view where type = ?. * * @param roleId the primary key of the current role * @param type the type * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next role * @throws NoSuchRoleException if a role with the primary key could not be found */ @Override public Role[] filterFindByType_PrevAndNext(long roleId, int type, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { if (!InlineSQLHelperUtil.isEnabled()) { return findByType_PrevAndNext(roleId, type, orderByComparator); } Role role = findByPrimaryKey(roleId); Session session = null; try { session = openSession(); Role[] array = new RoleImpl[3]; array[0] = filterGetByType_PrevAndNext(session, role, type, orderByComparator, true); array[1] = role; array[2] = filterGetByType_PrevAndNext(session, role, type, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected Role filterGetByType_PrevAndNext(Session session, Role role, int type, OrderByComparator<Role> orderByComparator, boolean previous) { StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(5 + (orderByComparator.getOrderByConditionFields().length * 3) + (orderByComparator.getOrderByFields().length * 3)); } else { query = new StringBundler(4); } if (getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_WHERE); } else { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1); } query.append(_FINDER_COLUMN_TYPE_TYPE_2_SQL); if (!getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2); } if (orderByComparator != null) { String[] orderByConditionFields = orderByComparator.getOrderByConditionFields(); if (orderByConditionFields.length > 0) { query.append(WHERE_AND); } for (int i = 0; i < orderByConditionFields.length; i++) { if (getDB().isSupportsInlineDistinct()) { query.append(_ORDER_BY_ENTITY_ALIAS); } else { query.append(_ORDER_BY_ENTITY_TABLE); } query.append(orderByConditionFields[i]); if ((i + 1) < orderByConditionFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN_HAS_NEXT); } else { query.append(WHERE_LESSER_THAN_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN); } else { query.append(WHERE_LESSER_THAN); } } } query.append(ORDER_BY_CLAUSE); String[] orderByFields = orderByComparator.getOrderByFields(); for (int i = 0; i < orderByFields.length; i++) { if (getDB().isSupportsInlineDistinct()) { query.append(_ORDER_BY_ENTITY_ALIAS); } else { query.append(_ORDER_BY_ENTITY_TABLE); } query.append(orderByFields[i]); if ((i + 1) < orderByFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC_HAS_NEXT); } else { query.append(ORDER_BY_DESC_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC); } else { query.append(ORDER_BY_DESC); } } } } else { if (getDB().isSupportsInlineDistinct()) { query.append(RoleModelImpl.ORDER_BY_JPQL); } else { query.append(RoleModelImpl.ORDER_BY_SQL); } } String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.setFirstResult(0); q.setMaxResults(2); if (getDB().isSupportsInlineDistinct()) { q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class); } else { q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class); } QueryPos qPos = QueryPos.getInstance(q); qPos.add(type); if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(role); for (Object value : values) { qPos.add(value); } } List<Role> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Removes all the roles where type = ? from the database. * * @param type the type */ @Override public void removeByType(int type) { for (Role role : findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) { remove(role); } } /** * Returns the number of roles where type = ?. * * @param type the type * @return the number of matching roles */ @Override public int countByType(int type) { FinderPath finderPath = FINDER_PATH_COUNT_BY_TYPE; Object[] finderArgs = new Object[] { type }; Long count = (Long)finderCache.getResult(finderPath, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(2); query.append(_SQL_COUNT_ROLE_WHERE); query.append(_FINDER_COLUMN_TYPE_TYPE_2); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(type); count = (Long)q.uniqueResult(); finderCache.putResult(finderPath, finderArgs, count); } catch (Exception e) { finderCache.removeResult(finderPath, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); } /** * Returns the number of roles that the user has permission to view where type = ?. * * @param type the type * @return the number of matching roles that the user has permission to view */ @Override public int filterCountByType(int type) { if (!InlineSQLHelperUtil.isEnabled()) { return countByType(type); } StringBundler query = new StringBundler(2); query.append(_FILTER_SQL_COUNT_ROLE_WHERE); query.append(_FINDER_COLUMN_TYPE_TYPE_2_SQL); String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN); Session session = null; try { session = openSession(); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.addScalar(COUNT_COLUMN_NAME, com.liferay.portal.kernel.dao.orm.Type.LONG); QueryPos qPos = QueryPos.getInstance(q); qPos.add(type); Long count = (Long)q.uniqueResult(); return count.intValue(); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } private static final String _FINDER_COLUMN_TYPE_TYPE_2 = "role.type = ?"; private static final String _FINDER_COLUMN_TYPE_TYPE_2_SQL = "role.type_ = ?"; public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_SUBTYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findBySubtype", new String[] { String.class.getName(), Integer.class.getName(), Integer.class.getName(), OrderByComparator.class.getName() }); public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findBySubtype", new String[] { String.class.getName() }, RoleModelImpl.SUBTYPE_COLUMN_BITMASK | RoleModelImpl.NAME_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_COUNT_BY_SUBTYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countBySubtype", new String[] { String.class.getName() }); /** * Returns all the roles where subtype = ?. * * @param subtype the subtype * @return the matching roles */ @Override public List<Role> findBySubtype(String subtype) { return findBySubtype(subtype, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the roles where subtype = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param subtype the subtype * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @return the range of matching roles */ @Override public List<Role> findBySubtype(String subtype, int start, int end) { return findBySubtype(subtype, start, end, null); } /** * Returns an ordered range of all the roles where subtype = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param subtype the subtype * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching roles */ @Override public List<Role> findBySubtype(String subtype, int start, int end, OrderByComparator<Role> orderByComparator) { return findBySubtype(subtype, start, end, orderByComparator, true); } /** * Returns an ordered range of all the roles where subtype = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param subtype the subtype * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @param retrieveFromCache whether to retrieve from the finder cache * @return the ordered range of matching roles */ @Override public List<Role> findBySubtype(String subtype, int start, int end, OrderByComparator<Role> orderByComparator, boolean retrieveFromCache) { boolean pagination = true; FinderPath finderPath = null; Object[] finderArgs = null; if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) { pagination = false; finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE; finderArgs = new Object[] { subtype }; } else { finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_SUBTYPE; finderArgs = new Object[] { subtype, start, end, orderByComparator }; } List<Role> list = null; if (retrieveFromCache) { list = (List<Role>)finderCache.getResult(finderPath, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (Role role : list) { if (!Objects.equals(subtype, role.getSubtype())) { list = null; break; } } } } if (list == null) { StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(3 + (orderByComparator.getOrderByFields().length * 2)); } else { query = new StringBundler(3); } query.append(_SQL_SELECT_ROLE_WHERE); boolean bindSubtype = false; if (subtype == null) { query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1); } else if (subtype.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3); } else { bindSubtype = true; query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2); } if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(RoleModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); if (bindSubtype) { qPos.add(subtype); } if (!pagination) { list = (List<Role>)QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<Role>)QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); finderCache.putResult(finderPath, finderArgs, list); } catch (Exception e) { finderCache.removeResult(finderPath, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; } /** * Returns the first role in the ordered set where subtype = ?. * * @param subtype the subtype * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching role * @throws NoSuchRoleException if a matching role could not be found */ @Override public Role findBySubtype_First(String subtype, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { Role role = fetchBySubtype_First(subtype, orderByComparator); if (role != null) { return role; } StringBundler msg = new StringBundler(4); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("subtype="); msg.append(subtype); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchRoleException(msg.toString()); } /** * Returns the first role in the ordered set where subtype = ?. * * @param subtype the subtype * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching role, or <code>null</code> if a matching role could not be found */ @Override public Role fetchBySubtype_First(String subtype, OrderByComparator<Role> orderByComparator) { List<Role> list = findBySubtype(subtype, 0, 1, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the last role in the ordered set where subtype = ?. * * @param subtype the subtype * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching role * @throws NoSuchRoleException if a matching role could not be found */ @Override public Role findBySubtype_Last(String subtype, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { Role role = fetchBySubtype_Last(subtype, orderByComparator); if (role != null) { return role; } StringBundler msg = new StringBundler(4); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("subtype="); msg.append(subtype); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchRoleException(msg.toString()); } /** * Returns the last role in the ordered set where subtype = ?. * * @param subtype the subtype * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching role, or <code>null</code> if a matching role could not be found */ @Override public Role fetchBySubtype_Last(String subtype, OrderByComparator<Role> orderByComparator) { int count = countBySubtype(subtype); if (count == 0) { return null; } List<Role> list = findBySubtype(subtype, count - 1, count, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the roles before and after the current role in the ordered set where subtype = ?. * * @param roleId the primary key of the current role * @param subtype the subtype * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next role * @throws NoSuchRoleException if a role with the primary key could not be found */ @Override public Role[] findBySubtype_PrevAndNext(long roleId, String subtype, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { Role role = findByPrimaryKey(roleId); Session session = null; try { session = openSession(); Role[] array = new RoleImpl[3]; array[0] = getBySubtype_PrevAndNext(session, role, subtype, orderByComparator, true); array[1] = role; array[2] = getBySubtype_PrevAndNext(session, role, subtype, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected Role getBySubtype_PrevAndNext(Session session, Role role, String subtype, OrderByComparator<Role> orderByComparator, boolean previous) { StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(4 + (orderByComparator.getOrderByConditionFields().length * 3) + (orderByComparator.getOrderByFields().length * 3)); } else { query = new StringBundler(3); } query.append(_SQL_SELECT_ROLE_WHERE); boolean bindSubtype = false; if (subtype == null) { query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1); } else if (subtype.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3); } else { bindSubtype = true; query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2); } if (orderByComparator != null) { String[] orderByConditionFields = orderByComparator.getOrderByConditionFields(); if (orderByConditionFields.length > 0) { query.append(WHERE_AND); } for (int i = 0; i < orderByConditionFields.length; i++) { query.append(_ORDER_BY_ENTITY_ALIAS); query.append(orderByConditionFields[i]); if ((i + 1) < orderByConditionFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN_HAS_NEXT); } else { query.append(WHERE_LESSER_THAN_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN); } else { query.append(WHERE_LESSER_THAN); } } } query.append(ORDER_BY_CLAUSE); String[] orderByFields = orderByComparator.getOrderByFields(); for (int i = 0; i < orderByFields.length; i++) { query.append(_ORDER_BY_ENTITY_ALIAS); query.append(orderByFields[i]); if ((i + 1) < orderByFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC_HAS_NEXT); } else { query.append(ORDER_BY_DESC_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC); } else { query.append(ORDER_BY_DESC); } } } } else { query.append(RoleModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Query q = session.createQuery(sql); q.setFirstResult(0); q.setMaxResults(2); QueryPos qPos = QueryPos.getInstance(q); if (bindSubtype) { qPos.add(subtype); } if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(role); for (Object value : values) { qPos.add(value); } } List<Role> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Returns all the roles that the user has permission to view where subtype = ?. * * @param subtype the subtype * @return the matching roles that the user has permission to view */ @Override public List<Role> filterFindBySubtype(String subtype) { return filterFindBySubtype(subtype, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the roles that the user has permission to view where subtype = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param subtype the subtype * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @return the range of matching roles that the user has permission to view */ @Override public List<Role> filterFindBySubtype(String subtype, int start, int end) { return filterFindBySubtype(subtype, start, end, null); } /** * Returns an ordered range of all the roles that the user has permissions to view where subtype = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param subtype the subtype * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching roles that the user has permission to view */ @Override public List<Role> filterFindBySubtype(String subtype, int start, int end, OrderByComparator<Role> orderByComparator) { if (!InlineSQLHelperUtil.isEnabled()) { return findBySubtype(subtype, start, end, orderByComparator); } StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(3 + (orderByComparator.getOrderByFields().length * 2)); } else { query = new StringBundler(4); } if (getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_WHERE); } else { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1); } boolean bindSubtype = false; if (subtype == null) { query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1); } else if (subtype.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3); } else { bindSubtype = true; query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2); } if (!getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2); } if (orderByComparator != null) { if (getDB().isSupportsInlineDistinct()) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator, true); } else { appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE, orderByComparator, true); } } else { if (getDB().isSupportsInlineDistinct()) { query.append(RoleModelImpl.ORDER_BY_JPQL); } else { query.append(RoleModelImpl.ORDER_BY_SQL); } } String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN); Session session = null; try { session = openSession(); SQLQuery q = session.createSynchronizedSQLQuery(sql); if (getDB().isSupportsInlineDistinct()) { q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class); } else { q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class); } QueryPos qPos = QueryPos.getInstance(q); if (bindSubtype) { qPos.add(subtype); } return (List<Role>)QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } /** * Returns the roles before and after the current role in the ordered set of roles that the user has permission to view where subtype = ?. * * @param roleId the primary key of the current role * @param subtype the subtype * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next role * @throws NoSuchRoleException if a role with the primary key could not be found */ @Override public Role[] filterFindBySubtype_PrevAndNext(long roleId, String subtype, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { if (!InlineSQLHelperUtil.isEnabled()) { return findBySubtype_PrevAndNext(roleId, subtype, orderByComparator); } Role role = findByPrimaryKey(roleId); Session session = null; try { session = openSession(); Role[] array = new RoleImpl[3]; array[0] = filterGetBySubtype_PrevAndNext(session, role, subtype, orderByComparator, true); array[1] = role; array[2] = filterGetBySubtype_PrevAndNext(session, role, subtype, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected Role filterGetBySubtype_PrevAndNext(Session session, Role role, String subtype, OrderByComparator<Role> orderByComparator, boolean previous) { StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(5 + (orderByComparator.getOrderByConditionFields().length * 3) + (orderByComparator.getOrderByFields().length * 3)); } else { query = new StringBundler(4); } if (getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_WHERE); } else { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1); } boolean bindSubtype = false; if (subtype == null) { query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1); } else if (subtype.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3); } else { bindSubtype = true; query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2); } if (!getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2); } if (orderByComparator != null) { String[] orderByConditionFields = orderByComparator.getOrderByConditionFields(); if (orderByConditionFields.length > 0) { query.append(WHERE_AND); } for (int i = 0; i < orderByConditionFields.length; i++) { if (getDB().isSupportsInlineDistinct()) { query.append(_ORDER_BY_ENTITY_ALIAS); } else { query.append(_ORDER_BY_ENTITY_TABLE); } query.append(orderByConditionFields[i]); if ((i + 1) < orderByConditionFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN_HAS_NEXT); } else { query.append(WHERE_LESSER_THAN_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN); } else { query.append(WHERE_LESSER_THAN); } } } query.append(ORDER_BY_CLAUSE); String[] orderByFields = orderByComparator.getOrderByFields(); for (int i = 0; i < orderByFields.length; i++) { if (getDB().isSupportsInlineDistinct()) { query.append(_ORDER_BY_ENTITY_ALIAS); } else { query.append(_ORDER_BY_ENTITY_TABLE); } query.append(orderByFields[i]); if ((i + 1) < orderByFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC_HAS_NEXT); } else { query.append(ORDER_BY_DESC_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC); } else { query.append(ORDER_BY_DESC); } } } } else { if (getDB().isSupportsInlineDistinct()) { query.append(RoleModelImpl.ORDER_BY_JPQL); } else { query.append(RoleModelImpl.ORDER_BY_SQL); } } String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.setFirstResult(0); q.setMaxResults(2); if (getDB().isSupportsInlineDistinct()) { q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class); } else { q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class); } QueryPos qPos = QueryPos.getInstance(q); if (bindSubtype) { qPos.add(subtype); } if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(role); for (Object value : values) { qPos.add(value); } } List<Role> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Removes all the roles where subtype = ? from the database. * * @param subtype the subtype */ @Override public void removeBySubtype(String subtype) { for (Role role : findBySubtype(subtype, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) { remove(role); } } /** * Returns the number of roles where subtype = ?. * * @param subtype the subtype * @return the number of matching roles */ @Override public int countBySubtype(String subtype) { FinderPath finderPath = FINDER_PATH_COUNT_BY_SUBTYPE; Object[] finderArgs = new Object[] { subtype }; Long count = (Long)finderCache.getResult(finderPath, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(2); query.append(_SQL_COUNT_ROLE_WHERE); boolean bindSubtype = false; if (subtype == null) { query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1); } else if (subtype.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3); } else { bindSubtype = true; query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); if (bindSubtype) { qPos.add(subtype); } count = (Long)q.uniqueResult(); finderCache.putResult(finderPath, finderArgs, count); } catch (Exception e) { finderCache.removeResult(finderPath, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); } /** * Returns the number of roles that the user has permission to view where subtype = ?. * * @param subtype the subtype * @return the number of matching roles that the user has permission to view */ @Override public int filterCountBySubtype(String subtype) { if (!InlineSQLHelperUtil.isEnabled()) { return countBySubtype(subtype); } StringBundler query = new StringBundler(2); query.append(_FILTER_SQL_COUNT_ROLE_WHERE); boolean bindSubtype = false; if (subtype == null) { query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1); } else if (subtype.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3); } else { bindSubtype = true; query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2); } String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN); Session session = null; try { session = openSession(); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.addScalar(COUNT_COLUMN_NAME, com.liferay.portal.kernel.dao.orm.Type.LONG); QueryPos qPos = QueryPos.getInstance(q); if (bindSubtype) { qPos.add(subtype); } Long count = (Long)q.uniqueResult(); return count.intValue(); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_1 = "role.subtype IS NULL"; private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_2 = "role.subtype = ?"; private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_3 = "(role.subtype IS NULL OR role.subtype = '')"; public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByC_N", new String[] { Long.class.getName(), String.class.getName() }, RoleModelImpl.COMPANYID_COLUMN_BITMASK | RoleModelImpl.NAME_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N", new String[] { Long.class.getName(), String.class.getName() }); /** * Returns the role where companyId = ? and name = ? or throws a {@link NoSuchRoleException} if it could not be found. * * @param companyId the company ID * @param name the name * @return the matching role * @throws NoSuchRoleException if a matching role could not be found */ @Override public Role findByC_N(long companyId, String name) throws NoSuchRoleException { Role role = fetchByC_N(companyId, name); if (role == null) { StringBundler msg = new StringBundler(6); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("companyId="); msg.append(companyId); msg.append(", name="); msg.append(name); msg.append(StringPool.CLOSE_CURLY_BRACE); if (_log.isDebugEnabled()) { _log.debug(msg.toString()); } throw new NoSuchRoleException(msg.toString()); } return role; } /** * Returns the role where companyId = ? and name = ? or returns <code>null</code> if it could not be found. Uses the finder cache. * * @param companyId the company ID * @param name the name * @return the matching role, or <code>null</code> if a matching role could not be found */ @Override public Role fetchByC_N(long companyId, String name) { return fetchByC_N(companyId, name, true); } /** * Returns the role where companyId = ? and name = ? or returns <code>null</code> if it could not be found, optionally using the finder cache. * * @param companyId the company ID * @param name the name * @param retrieveFromCache whether to retrieve from the finder cache * @return the matching role, or <code>null</code> if a matching role could not be found */ @Override public Role fetchByC_N(long companyId, String name, boolean retrieveFromCache) { Object[] finderArgs = new Object[] { companyId, name }; Object result = null; if (retrieveFromCache) { result = finderCache.getResult(FINDER_PATH_FETCH_BY_C_N, finderArgs, this); } if (result instanceof Role) { Role role = (Role)result; if ((companyId != role.getCompanyId()) || !Objects.equals(name, role.getName())) { result = null; } } if (result == null) { StringBundler query = new StringBundler(4); query.append(_SQL_SELECT_ROLE_WHERE); query.append(_FINDER_COLUMN_C_N_COMPANYID_2); boolean bindName = false; if (name == null) { query.append(_FINDER_COLUMN_C_N_NAME_1); } else if (name.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_C_N_NAME_3); } else { bindName = true; query.append(_FINDER_COLUMN_C_N_NAME_2); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); if (bindName) { qPos.add(StringUtil.toLowerCase(name)); } List<Role> list = q.list(); if (list.isEmpty()) { finderCache.putResult(FINDER_PATH_FETCH_BY_C_N, finderArgs, list); } else { Role role = list.get(0); result = role; cacheResult(role); if ((role.getCompanyId() != companyId) || (role.getName() == null) || !role.getName().equals(name)) { finderCache.putResult(FINDER_PATH_FETCH_BY_C_N, finderArgs, role); } } } catch (Exception e) { finderCache.removeResult(FINDER_PATH_FETCH_BY_C_N, finderArgs); throw processException(e); } finally { closeSession(session); } } if (result instanceof List<?>) { return null; } else { return (Role)result; } } /** * Removes the role where companyId = ? and name = ? from the database. * * @param companyId the company ID * @param name the name * @return the role that was removed */ @Override public Role removeByC_N(long companyId, String name) throws NoSuchRoleException { Role role = findByC_N(companyId, name); return remove(role); } /** * Returns the number of roles where companyId = ? and name = ?. * * @param companyId the company ID * @param name the name * @return the number of matching roles */ @Override public int countByC_N(long companyId, String name) { FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N; Object[] finderArgs = new Object[] { companyId, name }; Long count = (Long)finderCache.getResult(finderPath, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(3); query.append(_SQL_COUNT_ROLE_WHERE); query.append(_FINDER_COLUMN_C_N_COMPANYID_2); boolean bindName = false; if (name == null) { query.append(_FINDER_COLUMN_C_N_NAME_1); } else if (name.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_C_N_NAME_3); } else { bindName = true; query.append(_FINDER_COLUMN_C_N_NAME_2); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); if (bindName) { qPos.add(StringUtil.toLowerCase(name)); } count = (Long)q.uniqueResult(); finderCache.putResult(finderPath, finderArgs, count); } catch (Exception e) { finderCache.removeResult(finderPath, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); } private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "role.companyId = ? AND "; private static final String _FINDER_COLUMN_C_N_NAME_1 = "role.name IS NULL"; private static final String _FINDER_COLUMN_C_N_NAME_2 = "lower(role.name) = ?"; private static final String _FINDER_COLUMN_C_N_NAME_3 = "(role.name IS NULL OR role.name = '')"; public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_T", new String[] { Long.class.getName(), Integer.class.getName(), Integer.class.getName(), Integer.class.getName(), OrderByComparator.class.getName() }); public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_T", new String[] { Long.class.getName(), Integer.class.getName() }, RoleModelImpl.COMPANYID_COLUMN_BITMASK | RoleModelImpl.TYPE_COLUMN_BITMASK | RoleModelImpl.NAME_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_COUNT_BY_C_T = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_T", new String[] { Long.class.getName(), Integer.class.getName() }); public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_T = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_T", new String[] { Long.class.getName(), Integer.class.getName() }); /** * Returns all the roles where companyId = ? and type = ?. * * @param companyId the company ID * @param type the type * @return the matching roles */ @Override public List<Role> findByC_T(long companyId, int type) { return findByC_T(companyId, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the roles where companyId = ? and type = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param companyId the company ID * @param type the type * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @return the range of matching roles */ @Override public List<Role> findByC_T(long companyId, int type, int start, int end) { return findByC_T(companyId, type, start, end, null); } /** * Returns an ordered range of all the roles where companyId = ? and type = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param companyId the company ID * @param type the type * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching roles */ @Override public List<Role> findByC_T(long companyId, int type, int start, int end, OrderByComparator<Role> orderByComparator) { return findByC_T(companyId, type, start, end, orderByComparator, true); } /** * Returns an ordered range of all the roles where companyId = ? and type = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param companyId the company ID * @param type the type * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @param retrieveFromCache whether to retrieve from the finder cache * @return the ordered range of matching roles */ @Override public List<Role> findByC_T(long companyId, int type, int start, int end, OrderByComparator<Role> orderByComparator, boolean retrieveFromCache) { boolean pagination = true; FinderPath finderPath = null; Object[] finderArgs = null; if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) { pagination = false; finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T; finderArgs = new Object[] { companyId, type }; } else { finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T; finderArgs = new Object[] { companyId, type, start, end, orderByComparator }; } List<Role> list = null; if (retrieveFromCache) { list = (List<Role>)finderCache.getResult(finderPath, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (Role role : list) { if ((companyId != role.getCompanyId()) || (type != role.getType())) { list = null; break; } } } } if (list == null) { StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(4 + (orderByComparator.getOrderByFields().length * 2)); } else { query = new StringBundler(4); } query.append(_SQL_SELECT_ROLE_WHERE); query.append(_FINDER_COLUMN_C_T_COMPANYID_2); query.append(_FINDER_COLUMN_C_T_TYPE_2); if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(RoleModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); qPos.add(type); if (!pagination) { list = (List<Role>)QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<Role>)QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); finderCache.putResult(finderPath, finderArgs, list); } catch (Exception e) { finderCache.removeResult(finderPath, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; } /** * Returns the first role in the ordered set where companyId = ? and type = ?. * * @param companyId the company ID * @param type the type * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching role * @throws NoSuchRoleException if a matching role could not be found */ @Override public Role findByC_T_First(long companyId, int type, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { Role role = fetchByC_T_First(companyId, type, orderByComparator); if (role != null) { return role; } StringBundler msg = new StringBundler(6); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("companyId="); msg.append(companyId); msg.append(", type="); msg.append(type); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchRoleException(msg.toString()); } /** * Returns the first role in the ordered set where companyId = ? and type = ?. * * @param companyId the company ID * @param type the type * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching role, or <code>null</code> if a matching role could not be found */ @Override public Role fetchByC_T_First(long companyId, int type, OrderByComparator<Role> orderByComparator) { List<Role> list = findByC_T(companyId, type, 0, 1, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the last role in the ordered set where companyId = ? and type = ?. * * @param companyId the company ID * @param type the type * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching role * @throws NoSuchRoleException if a matching role could not be found */ @Override public Role findByC_T_Last(long companyId, int type, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { Role role = fetchByC_T_Last(companyId, type, orderByComparator); if (role != null) { return role; } StringBundler msg = new StringBundler(6); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("companyId="); msg.append(companyId); msg.append(", type="); msg.append(type); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchRoleException(msg.toString()); } /** * Returns the last role in the ordered set where companyId = ? and type = ?. * * @param companyId the company ID * @param type the type * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching role, or <code>null</code> if a matching role could not be found */ @Override public Role fetchByC_T_Last(long companyId, int type, OrderByComparator<Role> orderByComparator) { int count = countByC_T(companyId, type); if (count == 0) { return null; } List<Role> list = findByC_T(companyId, type, count - 1, count, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the roles before and after the current role in the ordered set where companyId = ? and type = ?. * * @param roleId the primary key of the current role * @param companyId the company ID * @param type the type * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next role * @throws NoSuchRoleException if a role with the primary key could not be found */ @Override public Role[] findByC_T_PrevAndNext(long roleId, long companyId, int type, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { Role role = findByPrimaryKey(roleId); Session session = null; try { session = openSession(); Role[] array = new RoleImpl[3]; array[0] = getByC_T_PrevAndNext(session, role, companyId, type, orderByComparator, true); array[1] = role; array[2] = getByC_T_PrevAndNext(session, role, companyId, type, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected Role getByC_T_PrevAndNext(Session session, Role role, long companyId, int type, OrderByComparator<Role> orderByComparator, boolean previous) { StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(5 + (orderByComparator.getOrderByConditionFields().length * 3) + (orderByComparator.getOrderByFields().length * 3)); } else { query = new StringBundler(4); } query.append(_SQL_SELECT_ROLE_WHERE); query.append(_FINDER_COLUMN_C_T_COMPANYID_2); query.append(_FINDER_COLUMN_C_T_TYPE_2); if (orderByComparator != null) { String[] orderByConditionFields = orderByComparator.getOrderByConditionFields(); if (orderByConditionFields.length > 0) { query.append(WHERE_AND); } for (int i = 0; i < orderByConditionFields.length; i++) { query.append(_ORDER_BY_ENTITY_ALIAS); query.append(orderByConditionFields[i]); if ((i + 1) < orderByConditionFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN_HAS_NEXT); } else { query.append(WHERE_LESSER_THAN_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN); } else { query.append(WHERE_LESSER_THAN); } } } query.append(ORDER_BY_CLAUSE); String[] orderByFields = orderByComparator.getOrderByFields(); for (int i = 0; i < orderByFields.length; i++) { query.append(_ORDER_BY_ENTITY_ALIAS); query.append(orderByFields[i]); if ((i + 1) < orderByFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC_HAS_NEXT); } else { query.append(ORDER_BY_DESC_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC); } else { query.append(ORDER_BY_DESC); } } } } else { query.append(RoleModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Query q = session.createQuery(sql); q.setFirstResult(0); q.setMaxResults(2); QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); qPos.add(type); if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(role); for (Object value : values) { qPos.add(value); } } List<Role> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Returns all the roles that the user has permission to view where companyId = ? and type = ?. * * @param companyId the company ID * @param type the type * @return the matching roles that the user has permission to view */ @Override public List<Role> filterFindByC_T(long companyId, int type) { return filterFindByC_T(companyId, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the roles that the user has permission to view where companyId = ? and type = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param companyId the company ID * @param type the type * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @return the range of matching roles that the user has permission to view */ @Override public List<Role> filterFindByC_T(long companyId, int type, int start, int end) { return filterFindByC_T(companyId, type, start, end, null); } /** * Returns an ordered range of all the roles that the user has permissions to view where companyId = ? and type = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param companyId the company ID * @param type the type * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching roles that the user has permission to view */ @Override public List<Role> filterFindByC_T(long companyId, int type, int start, int end, OrderByComparator<Role> orderByComparator) { if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) { return findByC_T(companyId, type, start, end, orderByComparator); } StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(4 + (orderByComparator.getOrderByFields().length * 2)); } else { query = new StringBundler(5); } if (getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_WHERE); } else { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1); } query.append(_FINDER_COLUMN_C_T_COMPANYID_2); query.append(_FINDER_COLUMN_C_T_TYPE_2_SQL); if (!getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2); } if (orderByComparator != null) { if (getDB().isSupportsInlineDistinct()) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator, true); } else { appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE, orderByComparator, true); } } else { if (getDB().isSupportsInlineDistinct()) { query.append(RoleModelImpl.ORDER_BY_JPQL); } else { query.append(RoleModelImpl.ORDER_BY_SQL); } } String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN); Session session = null; try { session = openSession(); SQLQuery q = session.createSynchronizedSQLQuery(sql); if (getDB().isSupportsInlineDistinct()) { q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class); } else { q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class); } QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); qPos.add(type); return (List<Role>)QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } /** * Returns the roles before and after the current role in the ordered set of roles that the user has permission to view where companyId = ? and type = ?. * * @param roleId the primary key of the current role * @param companyId the company ID * @param type the type * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next role * @throws NoSuchRoleException if a role with the primary key could not be found */ @Override public Role[] filterFindByC_T_PrevAndNext(long roleId, long companyId, int type, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) { return findByC_T_PrevAndNext(roleId, companyId, type, orderByComparator); } Role role = findByPrimaryKey(roleId); Session session = null; try { session = openSession(); Role[] array = new RoleImpl[3]; array[0] = filterGetByC_T_PrevAndNext(session, role, companyId, type, orderByComparator, true); array[1] = role; array[2] = filterGetByC_T_PrevAndNext(session, role, companyId, type, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected Role filterGetByC_T_PrevAndNext(Session session, Role role, long companyId, int type, OrderByComparator<Role> orderByComparator, boolean previous) { StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(6 + (orderByComparator.getOrderByConditionFields().length * 3) + (orderByComparator.getOrderByFields().length * 3)); } else { query = new StringBundler(5); } if (getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_WHERE); } else { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1); } query.append(_FINDER_COLUMN_C_T_COMPANYID_2); query.append(_FINDER_COLUMN_C_T_TYPE_2_SQL); if (!getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2); } if (orderByComparator != null) { String[] orderByConditionFields = orderByComparator.getOrderByConditionFields(); if (orderByConditionFields.length > 0) { query.append(WHERE_AND); } for (int i = 0; i < orderByConditionFields.length; i++) { if (getDB().isSupportsInlineDistinct()) { query.append(_ORDER_BY_ENTITY_ALIAS); } else { query.append(_ORDER_BY_ENTITY_TABLE); } query.append(orderByConditionFields[i]); if ((i + 1) < orderByConditionFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN_HAS_NEXT); } else { query.append(WHERE_LESSER_THAN_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN); } else { query.append(WHERE_LESSER_THAN); } } } query.append(ORDER_BY_CLAUSE); String[] orderByFields = orderByComparator.getOrderByFields(); for (int i = 0; i < orderByFields.length; i++) { if (getDB().isSupportsInlineDistinct()) { query.append(_ORDER_BY_ENTITY_ALIAS); } else { query.append(_ORDER_BY_ENTITY_TABLE); } query.append(orderByFields[i]); if ((i + 1) < orderByFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC_HAS_NEXT); } else { query.append(ORDER_BY_DESC_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC); } else { query.append(ORDER_BY_DESC); } } } } else { if (getDB().isSupportsInlineDistinct()) { query.append(RoleModelImpl.ORDER_BY_JPQL); } else { query.append(RoleModelImpl.ORDER_BY_SQL); } } String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.setFirstResult(0); q.setMaxResults(2); if (getDB().isSupportsInlineDistinct()) { q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class); } else { q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class); } QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); qPos.add(type); if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(role); for (Object value : values) { qPos.add(value); } } List<Role> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Returns all the roles that the user has permission to view where companyId = ? and type = any ?. * * @param companyId the company ID * @param types the types * @return the matching roles that the user has permission to view */ @Override public List<Role> filterFindByC_T(long companyId, int[] types) { return filterFindByC_T(companyId, types, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the roles that the user has permission to view where companyId = ? and type = any ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param companyId the company ID * @param types the types * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @return the range of matching roles that the user has permission to view */ @Override public List<Role> filterFindByC_T(long companyId, int[] types, int start, int end) { return filterFindByC_T(companyId, types, start, end, null); } /** * Returns an ordered range of all the roles that the user has permission to view where companyId = ? and type = any ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param companyId the company ID * @param types the types * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching roles that the user has permission to view */ @Override public List<Role> filterFindByC_T(long companyId, int[] types, int start, int end, OrderByComparator<Role> orderByComparator) { if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) { return findByC_T(companyId, types, start, end, orderByComparator); } if (types == null) { types = new int[0]; } else if (types.length > 1) { types = ArrayUtil.unique(types); Arrays.sort(types); } StringBundler query = new StringBundler(); if (getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_WHERE); } else { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1); } query.append(_FINDER_COLUMN_C_T_COMPANYID_2); if (types.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_C_T_TYPE_7_SQL); query.append(StringUtil.merge(types)); query.append(StringPool.CLOSE_PARENTHESIS); query.append(StringPool.CLOSE_PARENTHESIS); } query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)), query.index() - 1); if (!getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2); } if (orderByComparator != null) { if (getDB().isSupportsInlineDistinct()) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator, true); } else { appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE, orderByComparator, true); } } else { if (getDB().isSupportsInlineDistinct()) { query.append(RoleModelImpl.ORDER_BY_JPQL); } else { query.append(RoleModelImpl.ORDER_BY_SQL); } } String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN); Session session = null; try { session = openSession(); SQLQuery q = session.createSynchronizedSQLQuery(sql); if (getDB().isSupportsInlineDistinct()) { q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class); } else { q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class); } QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); return (List<Role>)QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } /** * Returns all the roles where companyId = ? and type = any ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param companyId the company ID * @param types the types * @return the matching roles */ @Override public List<Role> findByC_T(long companyId, int[] types) { return findByC_T(companyId, types, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the roles where companyId = ? and type = any ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param companyId the company ID * @param types the types * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @return the range of matching roles */ @Override public List<Role> findByC_T(long companyId, int[] types, int start, int end) { return findByC_T(companyId, types, start, end, null); } /** * Returns an ordered range of all the roles where companyId = ? and type = any ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param companyId the company ID * @param types the types * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching roles */ @Override public List<Role> findByC_T(long companyId, int[] types, int start, int end, OrderByComparator<Role> orderByComparator) { return findByC_T(companyId, types, start, end, orderByComparator, true); } /** * Returns an ordered range of all the roles where companyId = ? and type = ?, optionally using the finder cache. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param companyId the company ID * @param type the type * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @param retrieveFromCache whether to retrieve from the finder cache * @return the ordered range of matching roles */ @Override public List<Role> findByC_T(long companyId, int[] types, int start, int end, OrderByComparator<Role> orderByComparator, boolean retrieveFromCache) { if (types == null) { types = new int[0]; } else if (types.length > 1) { types = ArrayUtil.unique(types); Arrays.sort(types); } if (types.length == 1) { return findByC_T(companyId, types[0], start, end, orderByComparator); } boolean pagination = true; Object[] finderArgs = null; if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) { pagination = false; finderArgs = new Object[] { companyId, StringUtil.merge(types) }; } else { finderArgs = new Object[] { companyId, StringUtil.merge(types), start, end, orderByComparator }; } List<Role> list = null; if (retrieveFromCache) { list = (List<Role>)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (Role role : list) { if ((companyId != role.getCompanyId()) || !ArrayUtil.contains(types, role.getType())) { list = null; break; } } } } if (list == null) { StringBundler query = new StringBundler(); query.append(_SQL_SELECT_ROLE_WHERE); query.append(_FINDER_COLUMN_C_T_COMPANYID_2); if (types.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_C_T_TYPE_7); query.append(StringUtil.merge(types)); query.append(StringPool.CLOSE_PARENTHESIS); query.append(StringPool.CLOSE_PARENTHESIS); } query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)), query.index() - 1); if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(RoleModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); if (!pagination) { list = (List<Role>)QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<Role>)QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T, finderArgs, list); } catch (Exception e) { finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; } /** * Removes all the roles where companyId = ? and type = ? from the database. * * @param companyId the company ID * @param type the type */ @Override public void removeByC_T(long companyId, int type) { for (Role role : findByC_T(companyId, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) { remove(role); } } /** * Returns the number of roles where companyId = ? and type = ?. * * @param companyId the company ID * @param type the type * @return the number of matching roles */ @Override public int countByC_T(long companyId, int type) { FinderPath finderPath = FINDER_PATH_COUNT_BY_C_T; Object[] finderArgs = new Object[] { companyId, type }; Long count = (Long)finderCache.getResult(finderPath, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(3); query.append(_SQL_COUNT_ROLE_WHERE); query.append(_FINDER_COLUMN_C_T_COMPANYID_2); query.append(_FINDER_COLUMN_C_T_TYPE_2); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); qPos.add(type); count = (Long)q.uniqueResult(); finderCache.putResult(finderPath, finderArgs, count); } catch (Exception e) { finderCache.removeResult(finderPath, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); } /** * Returns the number of roles where companyId = ? and type = any ?. * * @param companyId the company ID * @param types the types * @return the number of matching roles */ @Override public int countByC_T(long companyId, int[] types) { if (types == null) { types = new int[0]; } else if (types.length > 1) { types = ArrayUtil.unique(types); Arrays.sort(types); } Object[] finderArgs = new Object[] { companyId, StringUtil.merge(types) }; Long count = (Long)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_T, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(); query.append(_SQL_COUNT_ROLE_WHERE); query.append(_FINDER_COLUMN_C_T_COMPANYID_2); if (types.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_C_T_TYPE_7); query.append(StringUtil.merge(types)); query.append(StringPool.CLOSE_PARENTHESIS); query.append(StringPool.CLOSE_PARENTHESIS); } query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)), query.index() - 1); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); count = (Long)q.uniqueResult(); finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_T, finderArgs, count); } catch (Exception e) { finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_T, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); } /** * Returns the number of roles that the user has permission to view where companyId = ? and type = ?. * * @param companyId the company ID * @param type the type * @return the number of matching roles that the user has permission to view */ @Override public int filterCountByC_T(long companyId, int type) { if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) { return countByC_T(companyId, type); } StringBundler query = new StringBundler(3); query.append(_FILTER_SQL_COUNT_ROLE_WHERE); query.append(_FINDER_COLUMN_C_T_COMPANYID_2); query.append(_FINDER_COLUMN_C_T_TYPE_2_SQL); String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN); Session session = null; try { session = openSession(); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.addScalar(COUNT_COLUMN_NAME, com.liferay.portal.kernel.dao.orm.Type.LONG); QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); qPos.add(type); Long count = (Long)q.uniqueResult(); return count.intValue(); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } /** * Returns the number of roles that the user has permission to view where companyId = ? and type = any ?. * * @param companyId the company ID * @param types the types * @return the number of matching roles that the user has permission to view */ @Override public int filterCountByC_T(long companyId, int[] types) { if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) { return countByC_T(companyId, types); } if (types == null) { types = new int[0]; } else if (types.length > 1) { types = ArrayUtil.unique(types); Arrays.sort(types); } StringBundler query = new StringBundler(); query.append(_FILTER_SQL_COUNT_ROLE_WHERE); query.append(_FINDER_COLUMN_C_T_COMPANYID_2); if (types.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_C_T_TYPE_7_SQL); query.append(StringUtil.merge(types)); query.append(StringPool.CLOSE_PARENTHESIS); query.append(StringPool.CLOSE_PARENTHESIS); } query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)), query.index() - 1); String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN); Session session = null; try { session = openSession(); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.addScalar(COUNT_COLUMN_NAME, com.liferay.portal.kernel.dao.orm.Type.LONG); QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); Long count = (Long)q.uniqueResult(); return count.intValue(); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } private static final String _FINDER_COLUMN_C_T_COMPANYID_2 = "role.companyId = ? AND "; private static final String _FINDER_COLUMN_C_T_TYPE_2 = "role.type = ?"; private static final String _FINDER_COLUMN_C_T_TYPE_7 = "role.type IN ("; private static final String _FINDER_COLUMN_C_T_TYPE_2_SQL = "role.type_ = ?"; private static final String _FINDER_COLUMN_C_T_TYPE_7_SQL = "role.type_ IN ("; public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_S", new String[] { Integer.class.getName(), String.class.getName(), Integer.class.getName(), Integer.class.getName(), OrderByComparator.class.getName() }); public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_S", new String[] { Integer.class.getName(), String.class.getName() }, RoleModelImpl.TYPE_COLUMN_BITMASK | RoleModelImpl.SUBTYPE_COLUMN_BITMASK | RoleModelImpl.NAME_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_S", new String[] { Integer.class.getName(), String.class.getName() }); /** * Returns all the roles where type = ? and subtype = ?. * * @param type the type * @param subtype the subtype * @return the matching roles */ @Override public List<Role> findByT_S(int type, String subtype) { return findByT_S(type, subtype, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the roles where type = ? and subtype = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param type the type * @param subtype the subtype * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @return the range of matching roles */ @Override public List<Role> findByT_S(int type, String subtype, int start, int end) { return findByT_S(type, subtype, start, end, null); } /** * Returns an ordered range of all the roles where type = ? and subtype = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param type the type * @param subtype the subtype * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching roles */ @Override public List<Role> findByT_S(int type, String subtype, int start, int end, OrderByComparator<Role> orderByComparator) { return findByT_S(type, subtype, start, end, orderByComparator, true); } /** * Returns an ordered range of all the roles where type = ? and subtype = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param type the type * @param subtype the subtype * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @param retrieveFromCache whether to retrieve from the finder cache * @return the ordered range of matching roles */ @Override public List<Role> findByT_S(int type, String subtype, int start, int end, OrderByComparator<Role> orderByComparator, boolean retrieveFromCache) { boolean pagination = true; FinderPath finderPath = null; Object[] finderArgs = null; if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) { pagination = false; finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S; finderArgs = new Object[] { type, subtype }; } else { finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S; finderArgs = new Object[] { type, subtype, start, end, orderByComparator }; } List<Role> list = null; if (retrieveFromCache) { list = (List<Role>)finderCache.getResult(finderPath, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (Role role : list) { if ((type != role.getType()) || !Objects.equals(subtype, role.getSubtype())) { list = null; break; } } } } if (list == null) { StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(4 + (orderByComparator.getOrderByFields().length * 2)); } else { query = new StringBundler(4); } query.append(_SQL_SELECT_ROLE_WHERE); query.append(_FINDER_COLUMN_T_S_TYPE_2); boolean bindSubtype = false; if (subtype == null) { query.append(_FINDER_COLUMN_T_S_SUBTYPE_1); } else if (subtype.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_T_S_SUBTYPE_3); } else { bindSubtype = true; query.append(_FINDER_COLUMN_T_S_SUBTYPE_2); } if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(RoleModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(type); if (bindSubtype) { qPos.add(subtype); } if (!pagination) { list = (List<Role>)QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<Role>)QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); finderCache.putResult(finderPath, finderArgs, list); } catch (Exception e) { finderCache.removeResult(finderPath, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; } /** * Returns the first role in the ordered set where type = ? and subtype = ?. * * @param type the type * @param subtype the subtype * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching role * @throws NoSuchRoleException if a matching role could not be found */ @Override public Role findByT_S_First(int type, String subtype, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { Role role = fetchByT_S_First(type, subtype, orderByComparator); if (role != null) { return role; } StringBundler msg = new StringBundler(6); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("type="); msg.append(type); msg.append(", subtype="); msg.append(subtype); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchRoleException(msg.toString()); } /** * Returns the first role in the ordered set where type = ? and subtype = ?. * * @param type the type * @param subtype the subtype * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching role, or <code>null</code> if a matching role could not be found */ @Override public Role fetchByT_S_First(int type, String subtype, OrderByComparator<Role> orderByComparator) { List<Role> list = findByT_S(type, subtype, 0, 1, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the last role in the ordered set where type = ? and subtype = ?. * * @param type the type * @param subtype the subtype * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching role * @throws NoSuchRoleException if a matching role could not be found */ @Override public Role findByT_S_Last(int type, String subtype, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { Role role = fetchByT_S_Last(type, subtype, orderByComparator); if (role != null) { return role; } StringBundler msg = new StringBundler(6); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("type="); msg.append(type); msg.append(", subtype="); msg.append(subtype); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchRoleException(msg.toString()); } /** * Returns the last role in the ordered set where type = ? and subtype = ?. * * @param type the type * @param subtype the subtype * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching role, or <code>null</code> if a matching role could not be found */ @Override public Role fetchByT_S_Last(int type, String subtype, OrderByComparator<Role> orderByComparator) { int count = countByT_S(type, subtype); if (count == 0) { return null; } List<Role> list = findByT_S(type, subtype, count - 1, count, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the roles before and after the current role in the ordered set where type = ? and subtype = ?. * * @param roleId the primary key of the current role * @param type the type * @param subtype the subtype * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next role * @throws NoSuchRoleException if a role with the primary key could not be found */ @Override public Role[] findByT_S_PrevAndNext(long roleId, int type, String subtype, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { Role role = findByPrimaryKey(roleId); Session session = null; try { session = openSession(); Role[] array = new RoleImpl[3]; array[0] = getByT_S_PrevAndNext(session, role, type, subtype, orderByComparator, true); array[1] = role; array[2] = getByT_S_PrevAndNext(session, role, type, subtype, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected Role getByT_S_PrevAndNext(Session session, Role role, int type, String subtype, OrderByComparator<Role> orderByComparator, boolean previous) { StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(5 + (orderByComparator.getOrderByConditionFields().length * 3) + (orderByComparator.getOrderByFields().length * 3)); } else { query = new StringBundler(4); } query.append(_SQL_SELECT_ROLE_WHERE); query.append(_FINDER_COLUMN_T_S_TYPE_2); boolean bindSubtype = false; if (subtype == null) { query.append(_FINDER_COLUMN_T_S_SUBTYPE_1); } else if (subtype.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_T_S_SUBTYPE_3); } else { bindSubtype = true; query.append(_FINDER_COLUMN_T_S_SUBTYPE_2); } if (orderByComparator != null) { String[] orderByConditionFields = orderByComparator.getOrderByConditionFields(); if (orderByConditionFields.length > 0) { query.append(WHERE_AND); } for (int i = 0; i < orderByConditionFields.length; i++) { query.append(_ORDER_BY_ENTITY_ALIAS); query.append(orderByConditionFields[i]); if ((i + 1) < orderByConditionFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN_HAS_NEXT); } else { query.append(WHERE_LESSER_THAN_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN); } else { query.append(WHERE_LESSER_THAN); } } } query.append(ORDER_BY_CLAUSE); String[] orderByFields = orderByComparator.getOrderByFields(); for (int i = 0; i < orderByFields.length; i++) { query.append(_ORDER_BY_ENTITY_ALIAS); query.append(orderByFields[i]); if ((i + 1) < orderByFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC_HAS_NEXT); } else { query.append(ORDER_BY_DESC_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC); } else { query.append(ORDER_BY_DESC); } } } } else { query.append(RoleModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Query q = session.createQuery(sql); q.setFirstResult(0); q.setMaxResults(2); QueryPos qPos = QueryPos.getInstance(q); qPos.add(type); if (bindSubtype) { qPos.add(subtype); } if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(role); for (Object value : values) { qPos.add(value); } } List<Role> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Returns all the roles that the user has permission to view where type = ? and subtype = ?. * * @param type the type * @param subtype the subtype * @return the matching roles that the user has permission to view */ @Override public List<Role> filterFindByT_S(int type, String subtype) { return filterFindByT_S(type, subtype, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the roles that the user has permission to view where type = ? and subtype = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param type the type * @param subtype the subtype * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @return the range of matching roles that the user has permission to view */ @Override public List<Role> filterFindByT_S(int type, String subtype, int start, int end) { return filterFindByT_S(type, subtype, start, end, null); } /** * Returns an ordered range of all the roles that the user has permissions to view where type = ? and subtype = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param type the type * @param subtype the subtype * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching roles that the user has permission to view */ @Override public List<Role> filterFindByT_S(int type, String subtype, int start, int end, OrderByComparator<Role> orderByComparator) { if (!InlineSQLHelperUtil.isEnabled()) { return findByT_S(type, subtype, start, end, orderByComparator); } StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(4 + (orderByComparator.getOrderByFields().length * 2)); } else { query = new StringBundler(5); } if (getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_WHERE); } else { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1); } query.append(_FINDER_COLUMN_T_S_TYPE_2_SQL); boolean bindSubtype = false; if (subtype == null) { query.append(_FINDER_COLUMN_T_S_SUBTYPE_1); } else if (subtype.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_T_S_SUBTYPE_3); } else { bindSubtype = true; query.append(_FINDER_COLUMN_T_S_SUBTYPE_2); } if (!getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2); } if (orderByComparator != null) { if (getDB().isSupportsInlineDistinct()) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator, true); } else { appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE, orderByComparator, true); } } else { if (getDB().isSupportsInlineDistinct()) { query.append(RoleModelImpl.ORDER_BY_JPQL); } else { query.append(RoleModelImpl.ORDER_BY_SQL); } } String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN); Session session = null; try { session = openSession(); SQLQuery q = session.createSynchronizedSQLQuery(sql); if (getDB().isSupportsInlineDistinct()) { q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class); } else { q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class); } QueryPos qPos = QueryPos.getInstance(q); qPos.add(type); if (bindSubtype) { qPos.add(subtype); } return (List<Role>)QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } /** * Returns the roles before and after the current role in the ordered set of roles that the user has permission to view where type = ? and subtype = ?. * * @param roleId the primary key of the current role * @param type the type * @param subtype the subtype * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next role * @throws NoSuchRoleException if a role with the primary key could not be found */ @Override public Role[] filterFindByT_S_PrevAndNext(long roleId, int type, String subtype, OrderByComparator<Role> orderByComparator) throws NoSuchRoleException { if (!InlineSQLHelperUtil.isEnabled()) { return findByT_S_PrevAndNext(roleId, type, subtype, orderByComparator); } Role role = findByPrimaryKey(roleId); Session session = null; try { session = openSession(); Role[] array = new RoleImpl[3]; array[0] = filterGetByT_S_PrevAndNext(session, role, type, subtype, orderByComparator, true); array[1] = role; array[2] = filterGetByT_S_PrevAndNext(session, role, type, subtype, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected Role filterGetByT_S_PrevAndNext(Session session, Role role, int type, String subtype, OrderByComparator<Role> orderByComparator, boolean previous) { StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(6 + (orderByComparator.getOrderByConditionFields().length * 3) + (orderByComparator.getOrderByFields().length * 3)); } else { query = new StringBundler(5); } if (getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_WHERE); } else { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1); } query.append(_FINDER_COLUMN_T_S_TYPE_2_SQL); boolean bindSubtype = false; if (subtype == null) { query.append(_FINDER_COLUMN_T_S_SUBTYPE_1); } else if (subtype.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_T_S_SUBTYPE_3); } else { bindSubtype = true; query.append(_FINDER_COLUMN_T_S_SUBTYPE_2); } if (!getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2); } if (orderByComparator != null) { String[] orderByConditionFields = orderByComparator.getOrderByConditionFields(); if (orderByConditionFields.length > 0) { query.append(WHERE_AND); } for (int i = 0; i < orderByConditionFields.length; i++) { if (getDB().isSupportsInlineDistinct()) { query.append(_ORDER_BY_ENTITY_ALIAS); } else { query.append(_ORDER_BY_ENTITY_TABLE); } query.append(orderByConditionFields[i]); if ((i + 1) < orderByConditionFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN_HAS_NEXT); } else { query.append(WHERE_LESSER_THAN_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN); } else { query.append(WHERE_LESSER_THAN); } } } query.append(ORDER_BY_CLAUSE); String[] orderByFields = orderByComparator.getOrderByFields(); for (int i = 0; i < orderByFields.length; i++) { if (getDB().isSupportsInlineDistinct()) { query.append(_ORDER_BY_ENTITY_ALIAS); } else { query.append(_ORDER_BY_ENTITY_TABLE); } query.append(orderByFields[i]); if ((i + 1) < orderByFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC_HAS_NEXT); } else { query.append(ORDER_BY_DESC_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC); } else { query.append(ORDER_BY_DESC); } } } } else { if (getDB().isSupportsInlineDistinct()) { query.append(RoleModelImpl.ORDER_BY_JPQL); } else { query.append(RoleModelImpl.ORDER_BY_SQL); } } String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.setFirstResult(0); q.setMaxResults(2); if (getDB().isSupportsInlineDistinct()) { q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class); } else { q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class); } QueryPos qPos = QueryPos.getInstance(q); qPos.add(type); if (bindSubtype) { qPos.add(subtype); } if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(role); for (Object value : values) { qPos.add(value); } } List<Role> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Removes all the roles where type = ? and subtype = ? from the database. * * @param type the type * @param subtype the subtype */ @Override public void removeByT_S(int type, String subtype) { for (Role role : findByT_S(type, subtype, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) { remove(role); } } /** * Returns the number of roles where type = ? and subtype = ?. * * @param type the type * @param subtype the subtype * @return the number of matching roles */ @Override public int countByT_S(int type, String subtype) { FinderPath finderPath = FINDER_PATH_COUNT_BY_T_S; Object[] finderArgs = new Object[] { type, subtype }; Long count = (Long)finderCache.getResult(finderPath, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(3); query.append(_SQL_COUNT_ROLE_WHERE); query.append(_FINDER_COLUMN_T_S_TYPE_2); boolean bindSubtype = false; if (subtype == null) { query.append(_FINDER_COLUMN_T_S_SUBTYPE_1); } else if (subtype.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_T_S_SUBTYPE_3); } else { bindSubtype = true; query.append(_FINDER_COLUMN_T_S_SUBTYPE_2); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(type); if (bindSubtype) { qPos.add(subtype); } count = (Long)q.uniqueResult(); finderCache.putResult(finderPath, finderArgs, count); } catch (Exception e) { finderCache.removeResult(finderPath, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); } /** * Returns the number of roles that the user has permission to view where type = ? and subtype = ?. * * @param type the type * @param subtype the subtype * @return the number of matching roles that the user has permission to view */ @Override public int filterCountByT_S(int type, String subtype) { if (!InlineSQLHelperUtil.isEnabled()) { return countByT_S(type, subtype); } StringBundler query = new StringBundler(3); query.append(_FILTER_SQL_COUNT_ROLE_WHERE); query.append(_FINDER_COLUMN_T_S_TYPE_2_SQL); boolean bindSubtype = false; if (subtype == null) { query.append(_FINDER_COLUMN_T_S_SUBTYPE_1); } else if (subtype.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_T_S_SUBTYPE_3); } else { bindSubtype = true; query.append(_FINDER_COLUMN_T_S_SUBTYPE_2); } String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN); Session session = null; try { session = openSession(); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.addScalar(COUNT_COLUMN_NAME, com.liferay.portal.kernel.dao.orm.Type.LONG); QueryPos qPos = QueryPos.getInstance(q); qPos.add(type); if (bindSubtype) { qPos.add(subtype); } Long count = (Long)q.uniqueResult(); return count.intValue(); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } private static final String _FINDER_COLUMN_T_S_TYPE_2 = "role.type = ? AND "; private static final String _FINDER_COLUMN_T_S_TYPE_2_SQL = "role.type_ = ? AND "; private static final String _FINDER_COLUMN_T_S_SUBTYPE_1 = "role.subtype IS NULL"; private static final String _FINDER_COLUMN_T_S_SUBTYPE_2 = "role.subtype = ?"; private static final String _FINDER_COLUMN_T_S_SUBTYPE_3 = "(role.subtype IS NULL OR role.subtype = '')"; public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_C", new String[] { Long.class.getName(), Long.class.getName(), Long.class.getName(), Integer.class.getName(), Integer.class.getName(), OrderByComparator.class.getName() }); public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_C", new String[] { Long.class.getName(), Long.class.getName(), Long.class.getName() }, RoleModelImpl.COMPANYID_COLUMN_BITMASK | RoleModelImpl.CLASSNAMEID_COLUMN_BITMASK | RoleModelImpl.CLASSPK_COLUMN_BITMASK | RoleModelImpl.NAME_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_FETCH_BY_C_C_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByC_C_C", new String[] { Long.class.getName(), Long.class.getName(), Long.class.getName() }, RoleModelImpl.COMPANYID_COLUMN_BITMASK | RoleModelImpl.CLASSNAMEID_COLUMN_BITMASK | RoleModelImpl.CLASSPK_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C", new String[] { Long.class.getName(), Long.class.getName(), Long.class.getName() }); public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_C_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_C_C", new String[] { Long.class.getName(), Long.class.getName(), Long.class.getName() }); /** * Returns all the roles where companyId = ? and classNameId = ? and classPK = any ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param companyId the company ID * @param classNameId the class name ID * @param classPKs the class pks * @return the matching roles */ @Override public List<Role> findByC_C_C(long companyId, long classNameId, long[] classPKs) { return findByC_C_C(companyId, classNameId, classPKs, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the roles where companyId = ? and classNameId = ? and classPK = any ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param companyId the company ID * @param classNameId the class name ID * @param classPKs the class pks * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @return the range of matching roles */ @Override public List<Role> findByC_C_C(long companyId, long classNameId, long[] classPKs, int start, int end) { return findByC_C_C(companyId, classNameId, classPKs, start, end, null); } /** * Returns an ordered range of all the roles where companyId = ? and classNameId = ? and classPK = any ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param companyId the company ID * @param classNameId the class name ID * @param classPKs the class pks * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching roles */ @Override public List<Role> findByC_C_C(long companyId, long classNameId, long[] classPKs, int start, int end, OrderByComparator<Role> orderByComparator) { return findByC_C_C(companyId, classNameId, classPKs, start, end, orderByComparator, true); } /** * Returns an ordered range of all the roles where companyId = ? and classNameId = ? and classPK = ?, optionally using the finder cache. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param companyId the company ID * @param classNameId the class name ID * @param classPK the class pk * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @param retrieveFromCache whether to retrieve from the finder cache * @return the ordered range of matching roles */ @Override public List<Role> findByC_C_C(long companyId, long classNameId, long[] classPKs, int start, int end, OrderByComparator<Role> orderByComparator, boolean retrieveFromCache) { if (classPKs == null) { classPKs = new long[0]; } else if (classPKs.length > 1) { classPKs = ArrayUtil.unique(classPKs); Arrays.sort(classPKs); } if (classPKs.length == 1) { Role role = fetchByC_C_C(companyId, classNameId, classPKs[0]); if (role == null) { return Collections.emptyList(); } else { List<Role> list = new ArrayList<Role>(1); list.add(role); return list; } } boolean pagination = true; Object[] finderArgs = null; if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) { pagination = false; finderArgs = new Object[] { companyId, classNameId, StringUtil.merge(classPKs) }; } else { finderArgs = new Object[] { companyId, classNameId, StringUtil.merge(classPKs), start, end, orderByComparator }; } List<Role> list = null; if (retrieveFromCache) { list = (List<Role>)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (Role role : list) { if ((companyId != role.getCompanyId()) || (classNameId != role.getClassNameId()) || !ArrayUtil.contains(classPKs, role.getClassPK())) { list = null; break; } } } } if (list == null) { StringBundler query = new StringBundler(); query.append(_SQL_SELECT_ROLE_WHERE); query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2); query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2); if (classPKs.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_C_C_C_CLASSPK_7); query.append(StringUtil.merge(classPKs)); query.append(StringPool.CLOSE_PARENTHESIS); query.append(StringPool.CLOSE_PARENTHESIS); } query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)), query.index() - 1); if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(RoleModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); qPos.add(classNameId); if (!pagination) { list = (List<Role>)QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<Role>)QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C, finderArgs, list); } catch (Exception e) { finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; } /** * Returns the role where companyId = ? and classNameId = ? and classPK = ? or throws a {@link NoSuchRoleException} if it could not be found. * * @param companyId the company ID * @param classNameId the class name ID * @param classPK the class pk * @return the matching role * @throws NoSuchRoleException if a matching role could not be found */ @Override public Role findByC_C_C(long companyId, long classNameId, long classPK) throws NoSuchRoleException { Role role = fetchByC_C_C(companyId, classNameId, classPK); if (role == null) { StringBundler msg = new StringBundler(8); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("companyId="); msg.append(companyId); msg.append(", classNameId="); msg.append(classNameId); msg.append(", classPK="); msg.append(classPK); msg.append(StringPool.CLOSE_CURLY_BRACE); if (_log.isDebugEnabled()) { _log.debug(msg.toString()); } throw new NoSuchRoleException(msg.toString()); } return role; } /** * Returns the role where companyId = ? and classNameId = ? and classPK = ? or returns <code>null</code> if it could not be found. Uses the finder cache. * * @param companyId the company ID * @param classNameId the class name ID * @param classPK the class pk * @return the matching role, or <code>null</code> if a matching role could not be found */ @Override public Role fetchByC_C_C(long companyId, long classNameId, long classPK) { return fetchByC_C_C(companyId, classNameId, classPK, true); } /** * Returns the role where companyId = ? and classNameId = ? and classPK = ? or returns <code>null</code> if it could not be found, optionally using the finder cache. * * @param companyId the company ID * @param classNameId the class name ID * @param classPK the class pk * @param retrieveFromCache whether to retrieve from the finder cache * @return the matching role, or <code>null</code> if a matching role could not be found */ @Override public Role fetchByC_C_C(long companyId, long classNameId, long classPK, boolean retrieveFromCache) { Object[] finderArgs = new Object[] { companyId, classNameId, classPK }; Object result = null; if (retrieveFromCache) { result = finderCache.getResult(FINDER_PATH_FETCH_BY_C_C_C, finderArgs, this); } if (result instanceof Role) { Role role = (Role)result; if ((companyId != role.getCompanyId()) || (classNameId != role.getClassNameId()) || (classPK != role.getClassPK())) { result = null; } } if (result == null) { StringBundler query = new StringBundler(5); query.append(_SQL_SELECT_ROLE_WHERE); query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2); query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2); query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); qPos.add(classNameId); qPos.add(classPK); List<Role> list = q.list(); if (list.isEmpty()) { finderCache.putResult(FINDER_PATH_FETCH_BY_C_C_C, finderArgs, list); } else { Role role = list.get(0); result = role; cacheResult(role); if ((role.getCompanyId() != companyId) || (role.getClassNameId() != classNameId) || (role.getClassPK() != classPK)) { finderCache.putResult(FINDER_PATH_FETCH_BY_C_C_C, finderArgs, role); } } } catch (Exception e) { finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C_C, finderArgs); throw processException(e); } finally { closeSession(session); } } if (result instanceof List<?>) { return null; } else { return (Role)result; } } /** * Removes the role where companyId = ? and classNameId = ? and classPK = ? from the database. * * @param companyId the company ID * @param classNameId the class name ID * @param classPK the class pk * @return the role that was removed */ @Override public Role removeByC_C_C(long companyId, long classNameId, long classPK) throws NoSuchRoleException { Role role = findByC_C_C(companyId, classNameId, classPK); return remove(role); } /** * Returns the number of roles where companyId = ? and classNameId = ? and classPK = ?. * * @param companyId the company ID * @param classNameId the class name ID * @param classPK the class pk * @return the number of matching roles */ @Override public int countByC_C_C(long companyId, long classNameId, long classPK) { FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_C; Object[] finderArgs = new Object[] { companyId, classNameId, classPK }; Long count = (Long)finderCache.getResult(finderPath, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(4); query.append(_SQL_COUNT_ROLE_WHERE); query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2); query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2); query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); qPos.add(classNameId); qPos.add(classPK); count = (Long)q.uniqueResult(); finderCache.putResult(finderPath, finderArgs, count); } catch (Exception e) { finderCache.removeResult(finderPath, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); } /** * Returns the number of roles where companyId = ? and classNameId = ? and classPK = any ?. * * @param companyId the company ID * @param classNameId the class name ID * @param classPKs the class pks * @return the number of matching roles */ @Override public int countByC_C_C(long companyId, long classNameId, long[] classPKs) { if (classPKs == null) { classPKs = new long[0]; } else if (classPKs.length > 1) { classPKs = ArrayUtil.unique(classPKs); Arrays.sort(classPKs); } Object[] finderArgs = new Object[] { companyId, classNameId, StringUtil.merge(classPKs) }; Long count = (Long)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_C_C, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(); query.append(_SQL_COUNT_ROLE_WHERE); query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2); query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2); if (classPKs.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_C_C_C_CLASSPK_7); query.append(StringUtil.merge(classPKs)); query.append(StringPool.CLOSE_PARENTHESIS); query.append(StringPool.CLOSE_PARENTHESIS); } query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)), query.index() - 1); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); qPos.add(classNameId); count = (Long)q.uniqueResult(); finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_C_C, finderArgs, count); } catch (Exception e) { finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_C_C, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); } /** * Returns the number of roles that the user has permission to view where companyId = ? and classNameId = ? and classPK = ?. * * @param companyId the company ID * @param classNameId the class name ID * @param classPK the class pk * @return the number of matching roles that the user has permission to view */ @Override public int filterCountByC_C_C(long companyId, long classNameId, long classPK) { if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) { return countByC_C_C(companyId, classNameId, classPK); } StringBundler query = new StringBundler(4); query.append(_FILTER_SQL_COUNT_ROLE_WHERE); query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2); query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2); query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2); String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN); Session session = null; try { session = openSession(); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.addScalar(COUNT_COLUMN_NAME, com.liferay.portal.kernel.dao.orm.Type.LONG); QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); qPos.add(classNameId); qPos.add(classPK); Long count = (Long)q.uniqueResult(); return count.intValue(); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } /** * Returns the number of roles that the user has permission to view where companyId = ? and classNameId = ? and classPK = any ?. * * @param companyId the company ID * @param classNameId the class name ID * @param classPKs the class pks * @return the number of matching roles that the user has permission to view */ @Override public int filterCountByC_C_C(long companyId, long classNameId, long[] classPKs) { if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) { return countByC_C_C(companyId, classNameId, classPKs); } if (classPKs == null) { classPKs = new long[0]; } else if (classPKs.length > 1) { classPKs = ArrayUtil.unique(classPKs); Arrays.sort(classPKs); } StringBundler query = new StringBundler(); query.append(_FILTER_SQL_COUNT_ROLE_WHERE); query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2); query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2); if (classPKs.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_C_C_C_CLASSPK_7); query.append(StringUtil.merge(classPKs)); query.append(StringPool.CLOSE_PARENTHESIS); query.append(StringPool.CLOSE_PARENTHESIS); } query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)), query.index() - 1); String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN); Session session = null; try { session = openSession(); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.addScalar(COUNT_COLUMN_NAME, com.liferay.portal.kernel.dao.orm.Type.LONG); QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); qPos.add(classNameId); Long count = (Long)q.uniqueResult(); return count.intValue(); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "role.companyId = ? AND "; private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "role.classNameId = ? AND "; private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "role.classPK = ?"; private static final String _FINDER_COLUMN_C_C_C_CLASSPK_7 = "role.classPK IN ("; public RolePersistenceImpl() { setModelClass(Role.class); try { Field field = ReflectionUtil.getDeclaredField(BasePersistenceImpl.class, "_dbColumnNames"); Map<String, String> dbColumnNames = new HashMap<String, String>(); dbColumnNames.put("uuid", "uuid_"); dbColumnNames.put("type", "type_"); field.set(this, dbColumnNames); } catch (Exception e) { if (_log.isDebugEnabled()) { _log.debug(e, e); } } } /** * Caches the role in the entity cache if it is enabled. * * @param role the role */ @Override public void cacheResult(Role role) { entityCache.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleImpl.class, role.getPrimaryKey(), role); finderCache.putResult(FINDER_PATH_FETCH_BY_C_N, new Object[] { role.getCompanyId(), role.getName() }, role); finderCache.putResult(FINDER_PATH_FETCH_BY_C_C_C, new Object[] { role.getCompanyId(), role.getClassNameId(), role.getClassPK() }, role); role.resetOriginalValues(); } /** * Caches the roles in the entity cache if it is enabled. * * @param roles the roles */ @Override public void cacheResult(List<Role> roles) { for (Role role : roles) { if (entityCache.getResult(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleImpl.class, role.getPrimaryKey()) == null) { cacheResult(role); } else { role.resetOriginalValues(); } } } /** * Clears the cache for all roles. * * <p> * The {@link EntityCache} and {@link FinderCache} are both cleared by this method. * </p> */ @Override public void clearCache() { entityCache.clearCache(RoleImpl.class); finderCache.clearCache(FINDER_CLASS_NAME_ENTITY); finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); } /** * Clears the cache for the role. * * <p> * The {@link EntityCache} and {@link FinderCache} are both cleared by this method. * </p> */ @Override public void clearCache(Role role) { entityCache.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleImpl.class, role.getPrimaryKey()); finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); clearUniqueFindersCache((RoleModelImpl)role, true); } @Override public void clearCache(List<Role> roles) { finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); for (Role role : roles) { entityCache.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleImpl.class, role.getPrimaryKey()); clearUniqueFindersCache((RoleModelImpl)role, true); } } protected void cacheUniqueFindersCache(RoleModelImpl roleModelImpl) { Object[] args = new Object[] { roleModelImpl.getCompanyId(), roleModelImpl.getName() }; finderCache.putResult(FINDER_PATH_COUNT_BY_C_N, args, Long.valueOf(1), false); finderCache.putResult(FINDER_PATH_FETCH_BY_C_N, args, roleModelImpl, false); args = new Object[] { roleModelImpl.getCompanyId(), roleModelImpl.getClassNameId(), roleModelImpl.getClassPK() }; finderCache.putResult(FINDER_PATH_COUNT_BY_C_C_C, args, Long.valueOf(1), false); finderCache.putResult(FINDER_PATH_FETCH_BY_C_C_C, args, roleModelImpl, false); } protected void clearUniqueFindersCache(RoleModelImpl roleModelImpl, boolean clearCurrent) { if (clearCurrent) { Object[] args = new Object[] { roleModelImpl.getCompanyId(), roleModelImpl.getName() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_C_N, args); finderCache.removeResult(FINDER_PATH_FETCH_BY_C_N, args); } if ((roleModelImpl.getColumnBitmask() & FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) { Object[] args = new Object[] { roleModelImpl.getOriginalCompanyId(), roleModelImpl.getOriginalName() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_C_N, args); finderCache.removeResult(FINDER_PATH_FETCH_BY_C_N, args); } if (clearCurrent) { Object[] args = new Object[] { roleModelImpl.getCompanyId(), roleModelImpl.getClassNameId(), roleModelImpl.getClassPK() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args); finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C_C, args); } if ((roleModelImpl.getColumnBitmask() & FINDER_PATH_FETCH_BY_C_C_C.getColumnBitmask()) != 0) { Object[] args = new Object[] { roleModelImpl.getOriginalCompanyId(), roleModelImpl.getOriginalClassNameId(), roleModelImpl.getOriginalClassPK() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args); finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C_C, args); } } /** * Creates a new role with the primary key. Does not add the role to the database. * * @param roleId the primary key for the new role * @return the new role */ @Override public Role create(long roleId) { Role role = new RoleImpl(); role.setNew(true); role.setPrimaryKey(roleId); String uuid = PortalUUIDUtil.generate(); role.setUuid(uuid); role.setCompanyId(companyProvider.getCompanyId()); return role; } /** * Removes the role with the primary key from the database. Also notifies the appropriate model listeners. * * @param roleId the primary key of the role * @return the role that was removed * @throws NoSuchRoleException if a role with the primary key could not be found */ @Override public Role remove(long roleId) throws NoSuchRoleException { return remove((Serializable)roleId); } /** * Removes the role with the primary key from the database. Also notifies the appropriate model listeners. * * @param primaryKey the primary key of the role * @return the role that was removed * @throws NoSuchRoleException if a role with the primary key could not be found */ @Override public Role remove(Serializable primaryKey) throws NoSuchRoleException { Session session = null; try { session = openSession(); Role role = (Role)session.get(RoleImpl.class, primaryKey); if (role == null) { if (_log.isDebugEnabled()) { _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey); } throw new NoSuchRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey); } return remove(role); } catch (NoSuchRoleException nsee) { throw nsee; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } @Override protected Role removeImpl(Role role) { role = toUnwrappedModel(role); roleToGroupTableMapper.deleteLeftPrimaryKeyTableMappings(role.getPrimaryKey()); roleToUserTableMapper.deleteLeftPrimaryKeyTableMappings(role.getPrimaryKey()); Session session = null; try { session = openSession(); if (!session.contains(role)) { role = (Role)session.get(RoleImpl.class, role.getPrimaryKeyObj()); } if (role != null) { session.delete(role); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } if (role != null) { clearCache(role); } return role; } @Override public Role updateImpl(Role role) { role = toUnwrappedModel(role); boolean isNew = role.isNew(); RoleModelImpl roleModelImpl = (RoleModelImpl)role; if (Validator.isNull(role.getUuid())) { String uuid = PortalUUIDUtil.generate(); role.setUuid(uuid); } ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext(); Date now = new Date(); if (isNew && (role.getCreateDate() == null)) { if (serviceContext == null) { role.setCreateDate(now); } else { role.setCreateDate(serviceContext.getCreateDate(now)); } } if (!roleModelImpl.hasSetModifiedDate()) { if (serviceContext == null) { role.setModifiedDate(now); } else { role.setModifiedDate(serviceContext.getModifiedDate(now)); } } Session session = null; try { session = openSession(); if (role.isNew()) { session.save(role); role.setNew(false); } else { role = (Role)session.merge(role); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); if (!RoleModelImpl.COLUMN_BITMASK_ENABLED) { finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); } else if (isNew) { Object[] args = new Object[] { roleModelImpl.getUuid() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID, args); args = new Object[] { roleModelImpl.getUuid(), roleModelImpl.getCompanyId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C, args); args = new Object[] { roleModelImpl.getCompanyId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID, args); args = new Object[] { roleModelImpl.getName() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_NAME, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME, args); args = new Object[] { roleModelImpl.getType() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_TYPE, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE, args); args = new Object[] { roleModelImpl.getSubtype() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_SUBTYPE, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE, args); args = new Object[] { roleModelImpl.getCompanyId(), roleModelImpl.getType() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_C_T, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T, args); args = new Object[] { roleModelImpl.getType(), roleModelImpl.getSubtype() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_T_S, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S, args); args = new Object[] { roleModelImpl.getCompanyId(), roleModelImpl.getClassNameId(), roleModelImpl.getClassPK() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C, args); finderCache.removeResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL, FINDER_ARGS_EMPTY); } else { if ((roleModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) { Object[] args = new Object[] { roleModelImpl.getOriginalUuid() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID, args); args = new Object[] { roleModelImpl.getUuid() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID, args); } if ((roleModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) { Object[] args = new Object[] { roleModelImpl.getOriginalUuid(), roleModelImpl.getOriginalCompanyId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C, args); args = new Object[] { roleModelImpl.getUuid(), roleModelImpl.getCompanyId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C, args); } if ((roleModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) { Object[] args = new Object[] { roleModelImpl.getOriginalCompanyId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID, args); args = new Object[] { roleModelImpl.getCompanyId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID, args); } if ((roleModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME.getColumnBitmask()) != 0) { Object[] args = new Object[] { roleModelImpl.getOriginalName() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_NAME, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME, args); args = new Object[] { roleModelImpl.getName() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_NAME, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME, args); } if ((roleModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE.getColumnBitmask()) != 0) { Object[] args = new Object[] { roleModelImpl.getOriginalType() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_TYPE, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE, args); args = new Object[] { roleModelImpl.getType() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_TYPE, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE, args); } if ((roleModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE.getColumnBitmask()) != 0) { Object[] args = new Object[] { roleModelImpl.getOriginalSubtype() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_SUBTYPE, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE, args); args = new Object[] { roleModelImpl.getSubtype() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_SUBTYPE, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE, args); } if ((roleModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T.getColumnBitmask()) != 0) { Object[] args = new Object[] { roleModelImpl.getOriginalCompanyId(), roleModelImpl.getOriginalType() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_C_T, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T, args); args = new Object[] { roleModelImpl.getCompanyId(), roleModelImpl.getType() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_C_T, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T, args); } if ((roleModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S.getColumnBitmask()) != 0) { Object[] args = new Object[] { roleModelImpl.getOriginalType(), roleModelImpl.getOriginalSubtype() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_T_S, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S, args); args = new Object[] { roleModelImpl.getType(), roleModelImpl.getSubtype() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_T_S, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S, args); } if ((roleModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C.getColumnBitmask()) != 0) { Object[] args = new Object[] { roleModelImpl.getOriginalCompanyId(), roleModelImpl.getOriginalClassNameId(), roleModelImpl.getOriginalClassPK() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C, args); args = new Object[] { roleModelImpl.getCompanyId(), roleModelImpl.getClassNameId(), roleModelImpl.getClassPK() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C, args); } } entityCache.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleImpl.class, role.getPrimaryKey(), role, false); clearUniqueFindersCache(roleModelImpl, false); cacheUniqueFindersCache(roleModelImpl); role.resetOriginalValues(); return role; } protected Role toUnwrappedModel(Role role) { if (role instanceof RoleImpl) { return role; } RoleImpl roleImpl = new RoleImpl(); roleImpl.setNew(role.isNew()); roleImpl.setPrimaryKey(role.getPrimaryKey()); roleImpl.setMvccVersion(role.getMvccVersion()); roleImpl.setUuid(role.getUuid()); roleImpl.setRoleId(role.getRoleId()); roleImpl.setCompanyId(role.getCompanyId()); roleImpl.setUserId(role.getUserId()); roleImpl.setUserName(role.getUserName()); roleImpl.setCreateDate(role.getCreateDate()); roleImpl.setModifiedDate(role.getModifiedDate()); roleImpl.setClassNameId(role.getClassNameId()); roleImpl.setClassPK(role.getClassPK()); roleImpl.setName(role.getName()); roleImpl.setTitle(role.getTitle()); roleImpl.setDescription(role.getDescription()); roleImpl.setType(role.getType()); roleImpl.setSubtype(role.getSubtype()); return roleImpl; } /** * Returns the role with the primary key or throws a {@link com.liferay.portal.kernel.exception.NoSuchModelException} if it could not be found. * * @param primaryKey the primary key of the role * @return the role * @throws NoSuchRoleException if a role with the primary key could not be found */ @Override public Role findByPrimaryKey(Serializable primaryKey) throws NoSuchRoleException { Role role = fetchByPrimaryKey(primaryKey); if (role == null) { if (_log.isDebugEnabled()) { _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey); } throw new NoSuchRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey); } return role; } /** * Returns the role with the primary key or throws a {@link NoSuchRoleException} if it could not be found. * * @param roleId the primary key of the role * @return the role * @throws NoSuchRoleException if a role with the primary key could not be found */ @Override public Role findByPrimaryKey(long roleId) throws NoSuchRoleException { return findByPrimaryKey((Serializable)roleId); } /** * Returns the role with the primary key or returns <code>null</code> if it could not be found. * * @param primaryKey the primary key of the role * @return the role, or <code>null</code> if a role with the primary key could not be found */ @Override public Role fetchByPrimaryKey(Serializable primaryKey) { Serializable serializable = entityCache.getResult(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleImpl.class, primaryKey); if (serializable == nullModel) { return null; } Role role = (Role)serializable; if (role == null) { Session session = null; try { session = openSession(); role = (Role)session.get(RoleImpl.class, primaryKey); if (role != null) { cacheResult(role); } else { entityCache.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleImpl.class, primaryKey, nullModel); } } catch (Exception e) { entityCache.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleImpl.class, primaryKey); throw processException(e); } finally { closeSession(session); } } return role; } /** * Returns the role with the primary key or returns <code>null</code> if it could not be found. * * @param roleId the primary key of the role * @return the role, or <code>null</code> if a role with the primary key could not be found */ @Override public Role fetchByPrimaryKey(long roleId) { return fetchByPrimaryKey((Serializable)roleId); } @Override public Map<Serializable, Role> fetchByPrimaryKeys( Set<Serializable> primaryKeys) { if (primaryKeys.isEmpty()) { return Collections.emptyMap(); } Map<Serializable, Role> map = new HashMap<Serializable, Role>(); if (primaryKeys.size() == 1) { Iterator<Serializable> iterator = primaryKeys.iterator(); Serializable primaryKey = iterator.next(); Role role = fetchByPrimaryKey(primaryKey); if (role != null) { map.put(primaryKey, role); } return map; } Set<Serializable> uncachedPrimaryKeys = null; for (Serializable primaryKey : primaryKeys) { Serializable serializable = entityCache.getResult(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleImpl.class, primaryKey); if (serializable != nullModel) { if (serializable == null) { if (uncachedPrimaryKeys == null) { uncachedPrimaryKeys = new HashSet<Serializable>(); } uncachedPrimaryKeys.add(primaryKey); } else { map.put(primaryKey, (Role)serializable); } } } if (uncachedPrimaryKeys == null) { return map; } StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1); query.append(_SQL_SELECT_ROLE_WHERE_PKS_IN); for (Serializable primaryKey : uncachedPrimaryKeys) { query.append((long)primaryKey); query.append(StringPool.COMMA); } query.setIndex(query.index() - 1); query.append(StringPool.CLOSE_PARENTHESIS); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); for (Role role : (List<Role>)q.list()) { map.put(role.getPrimaryKeyObj(), role); cacheResult(role); uncachedPrimaryKeys.remove(role.getPrimaryKeyObj()); } for (Serializable primaryKey : uncachedPrimaryKeys) { entityCache.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED, RoleImpl.class, primaryKey, nullModel); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } return map; } /** * Returns all the roles. * * @return the roles */ @Override public List<Role> findAll() { return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the roles. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @return the range of roles */ @Override public List<Role> findAll(int start, int end) { return findAll(start, end, null); } /** * Returns an ordered range of all the roles. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of roles */ @Override public List<Role> findAll(int start, int end, OrderByComparator<Role> orderByComparator) { return findAll(start, end, orderByComparator, true); } /** * Returns an ordered range of all the roles. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @param retrieveFromCache whether to retrieve from the finder cache * @return the ordered range of roles */ @Override public List<Role> findAll(int start, int end, OrderByComparator<Role> orderByComparator, boolean retrieveFromCache) { boolean pagination = true; FinderPath finderPath = null; Object[] finderArgs = null; if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) { pagination = false; finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL; finderArgs = FINDER_ARGS_EMPTY; } else { finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL; finderArgs = new Object[] { start, end, orderByComparator }; } List<Role> list = null; if (retrieveFromCache) { list = (List<Role>)finderCache.getResult(finderPath, finderArgs, this); } if (list == null) { StringBundler query = null; String sql = null; if (orderByComparator != null) { query = new StringBundler(2 + (orderByComparator.getOrderByFields().length * 2)); query.append(_SQL_SELECT_ROLE); appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); sql = query.toString(); } else { sql = _SQL_SELECT_ROLE; if (pagination) { sql = sql.concat(RoleModelImpl.ORDER_BY_JPQL); } } Session session = null; try { session = openSession(); Query q = session.createQuery(sql); if (!pagination) { list = (List<Role>)QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<Role>)QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); finderCache.putResult(finderPath, finderArgs, list); } catch (Exception e) { finderCache.removeResult(finderPath, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; } /** * Removes all the roles from the database. * */ @Override public void removeAll() { for (Role role : findAll()) { remove(role); } } /** * Returns the number of roles. * * @return the number of roles */ @Override public int countAll() { Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY, this); if (count == null) { Session session = null; try { session = openSession(); Query q = session.createQuery(_SQL_COUNT_ROLE); count = (Long)q.uniqueResult(); finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY, count); } catch (Exception e) { finderCache.removeResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY); throw processException(e); } finally { closeSession(session); } } return count.intValue(); } /** * Returns the primaryKeys of groups associated with the role. * * @param pk the primary key of the role * @return long[] of the primaryKeys of groups associated with the role */ @Override public long[] getGroupPrimaryKeys(long pk) { long[] pks = roleToGroupTableMapper.getRightPrimaryKeys(pk); return pks.clone(); } /** * Returns all the groups associated with the role. * * @param pk the primary key of the role * @return the groups associated with the role */ @Override public List<com.liferay.portal.kernel.model.Group> getGroups(long pk) { return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS); } /** * Returns a range of all the groups associated with the role. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param pk the primary key of the role * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @return the range of groups associated with the role */ @Override public List<com.liferay.portal.kernel.model.Group> getGroups(long pk, int start, int end) { return getGroups(pk, start, end, null); } /** * Returns an ordered range of all the groups associated with the role. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param pk the primary key of the role * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of groups associated with the role */ @Override public List<com.liferay.portal.kernel.model.Group> getGroups(long pk, int start, int end, OrderByComparator<com.liferay.portal.kernel.model.Group> orderByComparator) { return roleToGroupTableMapper.getRightBaseModels(pk, start, end, orderByComparator); } /** * Returns the number of groups associated with the role. * * @param pk the primary key of the role * @return the number of groups associated with the role */ @Override public int getGroupsSize(long pk) { long[] pks = roleToGroupTableMapper.getRightPrimaryKeys(pk); return pks.length; } /** * Returns <code>true</code> if the group is associated with the role. * * @param pk the primary key of the role * @param groupPK the primary key of the group * @return <code>true</code> if the group is associated with the role; <code>false</code> otherwise */ @Override public boolean containsGroup(long pk, long groupPK) { return roleToGroupTableMapper.containsTableMapping(pk, groupPK); } /** * Returns <code>true</code> if the role has any groups associated with it. * * @param pk the primary key of the role to check for associations with groups * @return <code>true</code> if the role has any groups associated with it; <code>false</code> otherwise */ @Override public boolean containsGroups(long pk) { if (getGroupsSize(pk) > 0) { return true; } else { return false; } } /** * Adds an association between the role and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache. * * @param pk the primary key of the role * @param groupPK the primary key of the group */ @Override public void addGroup(long pk, long groupPK) { Role role = fetchByPrimaryKey(pk); if (role == null) { roleToGroupTableMapper.addTableMapping(companyProvider.getCompanyId(), pk, groupPK); } else { roleToGroupTableMapper.addTableMapping(role.getCompanyId(), pk, groupPK); } } /** * Adds an association between the role and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache. * * @param pk the primary key of the role * @param group the group */ @Override public void addGroup(long pk, com.liferay.portal.kernel.model.Group group) { Role role = fetchByPrimaryKey(pk); if (role == null) { roleToGroupTableMapper.addTableMapping(companyProvider.getCompanyId(), pk, group.getPrimaryKey()); } else { roleToGroupTableMapper.addTableMapping(role.getCompanyId(), pk, group.getPrimaryKey()); } } /** * Adds an association between the role and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache. * * @param pk the primary key of the role * @param groupPKs the primary keys of the groups */ @Override public void addGroups(long pk, long[] groupPKs) { long companyId = 0; Role role = fetchByPrimaryKey(pk); if (role == null) { companyId = companyProvider.getCompanyId(); } else { companyId = role.getCompanyId(); } roleToGroupTableMapper.addTableMappings(companyId, pk, groupPKs); } /** * Adds an association between the role and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache. * * @param pk the primary key of the role * @param groups the groups */ @Override public void addGroups(long pk, List<com.liferay.portal.kernel.model.Group> groups) { addGroups(pk, ListUtil.toLongArray(groups, com.liferay.portal.kernel.model.Group.GROUP_ID_ACCESSOR)); } /** * Clears all associations between the role and its groups. Also notifies the appropriate model listeners and clears the mapping table finder cache. * * @param pk the primary key of the role to clear the associated groups from */ @Override public void clearGroups(long pk) { roleToGroupTableMapper.deleteLeftPrimaryKeyTableMappings(pk); } /** * Removes the association between the role and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache. * * @param pk the primary key of the role * @param groupPK the primary key of the group */ @Override public void removeGroup(long pk, long groupPK) { roleToGroupTableMapper.deleteTableMapping(pk, groupPK); } /** * Removes the association between the role and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache. * * @param pk the primary key of the role * @param group the group */ @Override public void removeGroup(long pk, com.liferay.portal.kernel.model.Group group) { roleToGroupTableMapper.deleteTableMapping(pk, group.getPrimaryKey()); } /** * Removes the association between the role and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache. * * @param pk the primary key of the role * @param groupPKs the primary keys of the groups */ @Override public void removeGroups(long pk, long[] groupPKs) { roleToGroupTableMapper.deleteTableMappings(pk, groupPKs); } /** * Removes the association between the role and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache. * * @param pk the primary key of the role * @param groups the groups */ @Override public void removeGroups(long pk, List<com.liferay.portal.kernel.model.Group> groups) { removeGroups(pk, ListUtil.toLongArray(groups, com.liferay.portal.kernel.model.Group.GROUP_ID_ACCESSOR)); } /** * Sets the groups associated with the role, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache. * * @param pk the primary key of the role * @param groupPKs the primary keys of the groups to be associated with the role */ @Override public void setGroups(long pk, long[] groupPKs) { Set<Long> newGroupPKsSet = SetUtil.fromArray(groupPKs); Set<Long> oldGroupPKsSet = SetUtil.fromArray(roleToGroupTableMapper.getRightPrimaryKeys( pk)); Set<Long> removeGroupPKsSet = new HashSet<Long>(oldGroupPKsSet); removeGroupPKsSet.removeAll(newGroupPKsSet); roleToGroupTableMapper.deleteTableMappings(pk, ArrayUtil.toLongArray(removeGroupPKsSet)); newGroupPKsSet.removeAll(oldGroupPKsSet); long companyId = 0; Role role = fetchByPrimaryKey(pk); if (role == null) { companyId = companyProvider.getCompanyId(); } else { companyId = role.getCompanyId(); } roleToGroupTableMapper.addTableMappings(companyId, pk, ArrayUtil.toLongArray(newGroupPKsSet)); } /** * Sets the groups associated with the role, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache. * * @param pk the primary key of the role * @param groups the groups to be associated with the role */ @Override public void setGroups(long pk, List<com.liferay.portal.kernel.model.Group> groups) { try { long[] groupPKs = new long[groups.size()]; for (int i = 0; i < groups.size(); i++) { com.liferay.portal.kernel.model.Group group = groups.get(i); groupPKs[i] = group.getPrimaryKey(); } setGroups(pk, groupPKs); } catch (Exception e) { throw processException(e); } } /** * Returns the primaryKeys of users associated with the role. * * @param pk the primary key of the role * @return long[] of the primaryKeys of users associated with the role */ @Override public long[] getUserPrimaryKeys(long pk) { long[] pks = roleToUserTableMapper.getRightPrimaryKeys(pk); return pks.clone(); } /** * Returns all the users associated with the role. * * @param pk the primary key of the role * @return the users associated with the role */ @Override public List<com.liferay.portal.kernel.model.User> getUsers(long pk) { return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS); } /** * Returns a range of all the users associated with the role. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param pk the primary key of the role * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @return the range of users associated with the role */ @Override public List<com.liferay.portal.kernel.model.User> getUsers(long pk, int start, int end) { return getUsers(pk, start, end, null); } /** * Returns an ordered range of all the users associated with the role. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param pk the primary key of the role * @param start the lower bound of the range of roles * @param end the upper bound of the range of roles (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of users associated with the role */ @Override public List<com.liferay.portal.kernel.model.User> getUsers(long pk, int start, int end, OrderByComparator<com.liferay.portal.kernel.model.User> orderByComparator) { return roleToUserTableMapper.getRightBaseModels(pk, start, end, orderByComparator); } /** * Returns the number of users associated with the role. * * @param pk the primary key of the role * @return the number of users associated with the role */ @Override public int getUsersSize(long pk) { long[] pks = roleToUserTableMapper.getRightPrimaryKeys(pk); return pks.length; } /** * Returns <code>true</code> if the user is associated with the role. * * @param pk the primary key of the role * @param userPK the primary key of the user * @return <code>true</code> if the user is associated with the role; <code>false</code> otherwise */ @Override public boolean containsUser(long pk, long userPK) { return roleToUserTableMapper.containsTableMapping(pk, userPK); } /** * Returns <code>true</code> if the role has any users associated with it. * * @param pk the primary key of the role to check for associations with users * @return <code>true</code> if the role has any users associated with it; <code>false</code> otherwise */ @Override public boolean containsUsers(long pk) { if (getUsersSize(pk) > 0) { return true; } else { return false; } } /** * Adds an association between the role and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache. * * @param pk the primary key of the role * @param userPK the primary key of the user */ @Override public void addUser(long pk, long userPK) { Role role = fetchByPrimaryKey(pk); if (role == null) { roleToUserTableMapper.addTableMapping(companyProvider.getCompanyId(), pk, userPK); } else { roleToUserTableMapper.addTableMapping(role.getCompanyId(), pk, userPK); } } /** * Adds an association between the role and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache. * * @param pk the primary key of the role * @param user the user */ @Override public void addUser(long pk, com.liferay.portal.kernel.model.User user) { Role role = fetchByPrimaryKey(pk); if (role == null) { roleToUserTableMapper.addTableMapping(companyProvider.getCompanyId(), pk, user.getPrimaryKey()); } else { roleToUserTableMapper.addTableMapping(role.getCompanyId(), pk, user.getPrimaryKey()); } } /** * Adds an association between the role and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache. * * @param pk the primary key of the role * @param userPKs the primary keys of the users */ @Override public void addUsers(long pk, long[] userPKs) { long companyId = 0; Role role = fetchByPrimaryKey(pk); if (role == null) { companyId = companyProvider.getCompanyId(); } else { companyId = role.getCompanyId(); } roleToUserTableMapper.addTableMappings(companyId, pk, userPKs); } /** * Adds an association between the role and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache. * * @param pk the primary key of the role * @param users the users */ @Override public void addUsers(long pk, List<com.liferay.portal.kernel.model.User> users) { addUsers(pk, ListUtil.toLongArray(users, com.liferay.portal.kernel.model.User.USER_ID_ACCESSOR)); } /** * Clears all associations between the role and its users. Also notifies the appropriate model listeners and clears the mapping table finder cache. * * @param pk the primary key of the role to clear the associated users from */ @Override public void clearUsers(long pk) { roleToUserTableMapper.deleteLeftPrimaryKeyTableMappings(pk); } /** * Removes the association between the role and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache. * * @param pk the primary key of the role * @param userPK the primary key of the user */ @Override public void removeUser(long pk, long userPK) { roleToUserTableMapper.deleteTableMapping(pk, userPK); } /** * Removes the association between the role and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache. * * @param pk the primary key of the role * @param user the user */ @Override public void removeUser(long pk, com.liferay.portal.kernel.model.User user) { roleToUserTableMapper.deleteTableMapping(pk, user.getPrimaryKey()); } /** * Removes the association between the role and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache. * * @param pk the primary key of the role * @param userPKs the primary keys of the users */ @Override public void removeUsers(long pk, long[] userPKs) { roleToUserTableMapper.deleteTableMappings(pk, userPKs); } /** * Removes the association between the role and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache. * * @param pk the primary key of the role * @param users the users */ @Override public void removeUsers(long pk, List<com.liferay.portal.kernel.model.User> users) { removeUsers(pk, ListUtil.toLongArray(users, com.liferay.portal.kernel.model.User.USER_ID_ACCESSOR)); } /** * Sets the users associated with the role, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache. * * @param pk the primary key of the role * @param userPKs the primary keys of the users to be associated with the role */ @Override public void setUsers(long pk, long[] userPKs) { Set<Long> newUserPKsSet = SetUtil.fromArray(userPKs); Set<Long> oldUserPKsSet = SetUtil.fromArray(roleToUserTableMapper.getRightPrimaryKeys( pk)); Set<Long> removeUserPKsSet = new HashSet<Long>(oldUserPKsSet); removeUserPKsSet.removeAll(newUserPKsSet); roleToUserTableMapper.deleteTableMappings(pk, ArrayUtil.toLongArray(removeUserPKsSet)); newUserPKsSet.removeAll(oldUserPKsSet); long companyId = 0; Role role = fetchByPrimaryKey(pk); if (role == null) { companyId = companyProvider.getCompanyId(); } else { companyId = role.getCompanyId(); } roleToUserTableMapper.addTableMappings(companyId, pk, ArrayUtil.toLongArray(newUserPKsSet)); } /** * Sets the users associated with the role, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache. * * @param pk the primary key of the role * @param users the users to be associated with the role */ @Override public void setUsers(long pk, List<com.liferay.portal.kernel.model.User> users) { try { long[] userPKs = new long[users.size()]; for (int i = 0; i < users.size(); i++) { com.liferay.portal.kernel.model.User user = users.get(i); userPKs[i] = user.getPrimaryKey(); } setUsers(pk, userPKs); } catch (Exception e) { throw processException(e); } } @Override public Set<String> getBadColumnNames() { return _badColumnNames; } @Override protected Map<String, Integer> getTableColumnsMap() { return RoleModelImpl.TABLE_COLUMNS_MAP; } /** * Initializes the role persistence. */ public void afterPropertiesSet() { roleToGroupTableMapper = TableMapperFactory.getTableMapper("Groups_Roles", "companyId", "roleId", "groupId", this, groupPersistence); roleToUserTableMapper = TableMapperFactory.getTableMapper("Users_Roles", "companyId", "roleId", "userId", this, userPersistence); } public void destroy() { entityCache.removeCache(RoleImpl.class.getName()); finderCache.removeCache(FINDER_CLASS_NAME_ENTITY); finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); TableMapperFactory.removeTableMapper("Groups_Roles"); TableMapperFactory.removeTableMapper("Users_Roles"); } @BeanReference(type = CompanyProviderWrapper.class) protected CompanyProvider companyProvider; protected EntityCache entityCache = EntityCacheUtil.getEntityCache(); protected FinderCache finderCache = FinderCacheUtil.getFinderCache(); @BeanReference(type = GroupPersistence.class) protected GroupPersistence groupPersistence; protected TableMapper<Role, com.liferay.portal.kernel.model.Group> roleToGroupTableMapper; @BeanReference(type = UserPersistence.class) protected UserPersistence userPersistence; protected TableMapper<Role, com.liferay.portal.kernel.model.User> roleToUserTableMapper; private static final String _SQL_SELECT_ROLE = "SELECT role FROM Role role"; private static final String _SQL_SELECT_ROLE_WHERE_PKS_IN = "SELECT role FROM Role role WHERE roleId IN ("; private static final String _SQL_SELECT_ROLE_WHERE = "SELECT role FROM Role role WHERE "; private static final String _SQL_COUNT_ROLE = "SELECT COUNT(role) FROM Role role"; private static final String _SQL_COUNT_ROLE_WHERE = "SELECT COUNT(role) FROM Role role WHERE "; private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "role.roleId"; private static final String _FILTER_SQL_SELECT_ROLE_WHERE = "SELECT DISTINCT {role.*} FROM Role_ role WHERE "; private static final String _FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1 = "SELECT {Role_.*} FROM (SELECT DISTINCT role.roleId FROM Role_ role WHERE "; private static final String _FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2 = ") TEMP_TABLE INNER JOIN Role_ ON TEMP_TABLE.roleId = Role_.roleId"; private static final String _FILTER_SQL_COUNT_ROLE_WHERE = "SELECT COUNT(DISTINCT role.roleId) AS COUNT_VALUE FROM Role_ role WHERE "; private static final String _FILTER_ENTITY_ALIAS = "role"; private static final String _FILTER_ENTITY_TABLE = "Role_"; private static final String _ORDER_BY_ENTITY_ALIAS = "role."; private static final String _ORDER_BY_ENTITY_TABLE = "Role_."; private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Role exists with the primary key "; private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Role exists with the key {"; private static final Log _log = LogFactoryUtil.getLog(RolePersistenceImpl.class); private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] { "uuid", "type" }); }