/** * 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.subscription.service.persistence.impl; import aQute.bnd.annotation.ProviderType; import com.liferay.portal.kernel.dao.orm.EntityCache; import com.liferay.portal.kernel.dao.orm.FinderCache; 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.Session; import com.liferay.portal.kernel.log.Log; import com.liferay.portal.kernel.log.LogFactoryUtil; 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.impl.BasePersistenceImpl; import com.liferay.portal.kernel.util.ArrayUtil; import com.liferay.portal.kernel.util.OrderByComparator; 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.spring.extender.service.ServiceReference; import com.liferay.subscription.exception.NoSuchSubscriptionException; import com.liferay.subscription.model.Subscription; import com.liferay.subscription.model.impl.SubscriptionImpl; import com.liferay.subscription.model.impl.SubscriptionModelImpl; import com.liferay.subscription.service.persistence.SubscriptionPersistence; import java.io.Serializable; 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.Set; /** * The persistence implementation for the subscription service. * * <p> * Caching information and settings can be found in <code>portal.properties</code> * </p> * * @author Brian Wing Shun Chan * @see SubscriptionPersistence * @see com.liferay.subscription.service.persistence.SubscriptionUtil * @generated */ @ProviderType public class SubscriptionPersistenceImpl extends BasePersistenceImpl<Subscription> implements SubscriptionPersistence { /* * NOTE FOR DEVELOPERS: * * Never modify or reference this class directly. Always use {@link SubscriptionUtil} to access the subscription persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class. */ public static final String FINDER_CLASS_NAME_ENTITY = SubscriptionImpl.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(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]); public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]); public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionModelImpl.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_GROUPID = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId", new String[] { Long.class.getName(), Integer.class.getName(), Integer.class.getName(), OrderByComparator.class.getName() }); public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId", new String[] { Long.class.getName() }, SubscriptionModelImpl.GROUPID_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId", new String[] { Long.class.getName() }); /** * Returns all the subscriptions where groupId = ?. * * @param groupId the group ID * @return the matching subscriptions */ @Override public List<Subscription> findByGroupId(long groupId) { return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the subscriptions where groupId = ?. * * <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 SubscriptionModelImpl}. 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 groupId the group ID * @param start the lower bound of the range of subscriptions * @param end the upper bound of the range of subscriptions (not inclusive) * @return the range of matching subscriptions */ @Override public List<Subscription> findByGroupId(long groupId, int start, int end) { return findByGroupId(groupId, start, end, null); } /** * Returns an ordered range of all the subscriptions where groupId = ?. * * <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 SubscriptionModelImpl}. 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 groupId the group ID * @param start the lower bound of the range of subscriptions * @param end the upper bound of the range of subscriptions (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching subscriptions */ @Override public List<Subscription> findByGroupId(long groupId, int start, int end, OrderByComparator<Subscription> orderByComparator) { return findByGroupId(groupId, start, end, orderByComparator, true); } /** * Returns an ordered range of all the subscriptions where groupId = ?. * * <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 SubscriptionModelImpl}. 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 groupId the group ID * @param start the lower bound of the range of subscriptions * @param end the upper bound of the range of subscriptions (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 subscriptions */ @Override public List<Subscription> findByGroupId(long groupId, int start, int end, OrderByComparator<Subscription> 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_GROUPID; finderArgs = new Object[] { groupId }; } else { finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID; finderArgs = new Object[] { groupId, start, end, orderByComparator }; } List<Subscription> list = null; if (retrieveFromCache) { list = (List<Subscription>)finderCache.getResult(finderPath, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (Subscription subscription : list) { if ((groupId != subscription.getGroupId())) { 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_SUBSCRIPTION_WHERE); query.append(_FINDER_COLUMN_GROUPID_GROUPID_2); if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(SubscriptionModelImpl.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(groupId); if (!pagination) { list = (List<Subscription>)QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<Subscription>)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 subscription in the ordered set where groupId = ?. * * @param groupId the group ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching subscription * @throws NoSuchSubscriptionException if a matching subscription could not be found */ @Override public Subscription findByGroupId_First(long groupId, OrderByComparator<Subscription> orderByComparator) throws NoSuchSubscriptionException { Subscription subscription = fetchByGroupId_First(groupId, orderByComparator); if (subscription != null) { return subscription; } StringBundler msg = new StringBundler(4); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("groupId="); msg.append(groupId); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchSubscriptionException(msg.toString()); } /** * Returns the first subscription in the ordered set where groupId = ?. * * @param groupId the group ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching subscription, or <code>null</code> if a matching subscription could not be found */ @Override public Subscription fetchByGroupId_First(long groupId, OrderByComparator<Subscription> orderByComparator) { List<Subscription> list = findByGroupId(groupId, 0, 1, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the last subscription in the ordered set where groupId = ?. * * @param groupId the group ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching subscription * @throws NoSuchSubscriptionException if a matching subscription could not be found */ @Override public Subscription findByGroupId_Last(long groupId, OrderByComparator<Subscription> orderByComparator) throws NoSuchSubscriptionException { Subscription subscription = fetchByGroupId_Last(groupId, orderByComparator); if (subscription != null) { return subscription; } StringBundler msg = new StringBundler(4); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("groupId="); msg.append(groupId); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchSubscriptionException(msg.toString()); } /** * Returns the last subscription in the ordered set where groupId = ?. * * @param groupId the group ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching subscription, or <code>null</code> if a matching subscription could not be found */ @Override public Subscription fetchByGroupId_Last(long groupId, OrderByComparator<Subscription> orderByComparator) { int count = countByGroupId(groupId); if (count == 0) { return null; } List<Subscription> list = findByGroupId(groupId, count - 1, count, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the subscriptions before and after the current subscription in the ordered set where groupId = ?. * * @param subscriptionId the primary key of the current subscription * @param groupId the group ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next subscription * @throws NoSuchSubscriptionException if a subscription with the primary key could not be found */ @Override public Subscription[] findByGroupId_PrevAndNext(long subscriptionId, long groupId, OrderByComparator<Subscription> orderByComparator) throws NoSuchSubscriptionException { Subscription subscription = findByPrimaryKey(subscriptionId); Session session = null; try { session = openSession(); Subscription[] array = new SubscriptionImpl[3]; array[0] = getByGroupId_PrevAndNext(session, subscription, groupId, orderByComparator, true); array[1] = subscription; array[2] = getByGroupId_PrevAndNext(session, subscription, groupId, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected Subscription getByGroupId_PrevAndNext(Session session, Subscription subscription, long groupId, OrderByComparator<Subscription> 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_SUBSCRIPTION_WHERE); query.append(_FINDER_COLUMN_GROUPID_GROUPID_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(SubscriptionModelImpl.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(groupId); if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(subscription); for (Object value : values) { qPos.add(value); } } List<Subscription> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Removes all the subscriptions where groupId = ? from the database. * * @param groupId the group ID */ @Override public void removeByGroupId(long groupId) { for (Subscription subscription : findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) { remove(subscription); } } /** * Returns the number of subscriptions where groupId = ?. * * @param groupId the group ID * @return the number of matching subscriptions */ @Override public int countByGroupId(long groupId) { FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID; Object[] finderArgs = new Object[] { groupId }; Long count = (Long)finderCache.getResult(finderPath, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(2); query.append(_SQL_COUNT_SUBSCRIPTION_WHERE); query.append(_FINDER_COLUMN_GROUPID_GROUPID_2); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); 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_GROUPID_GROUPID_2 = "subscription.groupId = ?"; public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId", new String[] { Long.class.getName(), Integer.class.getName(), Integer.class.getName(), OrderByComparator.class.getName() }); public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId", new String[] { Long.class.getName() }, SubscriptionModelImpl.USERID_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId", new String[] { Long.class.getName() }); /** * Returns all the subscriptions where userId = ?. * * @param userId the user ID * @return the matching subscriptions */ @Override public List<Subscription> findByUserId(long userId) { return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the subscriptions where userId = ?. * * <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 SubscriptionModelImpl}. 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 userId the user ID * @param start the lower bound of the range of subscriptions * @param end the upper bound of the range of subscriptions (not inclusive) * @return the range of matching subscriptions */ @Override public List<Subscription> findByUserId(long userId, int start, int end) { return findByUserId(userId, start, end, null); } /** * Returns an ordered range of all the subscriptions where userId = ?. * * <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 SubscriptionModelImpl}. 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 userId the user ID * @param start the lower bound of the range of subscriptions * @param end the upper bound of the range of subscriptions (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching subscriptions */ @Override public List<Subscription> findByUserId(long userId, int start, int end, OrderByComparator<Subscription> orderByComparator) { return findByUserId(userId, start, end, orderByComparator, true); } /** * Returns an ordered range of all the subscriptions where userId = ?. * * <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 SubscriptionModelImpl}. 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 userId the user ID * @param start the lower bound of the range of subscriptions * @param end the upper bound of the range of subscriptions (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 subscriptions */ @Override public List<Subscription> findByUserId(long userId, int start, int end, OrderByComparator<Subscription> 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_USERID; finderArgs = new Object[] { userId }; } else { finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID; finderArgs = new Object[] { userId, start, end, orderByComparator }; } List<Subscription> list = null; if (retrieveFromCache) { list = (List<Subscription>)finderCache.getResult(finderPath, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (Subscription subscription : list) { if ((userId != subscription.getUserId())) { 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_SUBSCRIPTION_WHERE); query.append(_FINDER_COLUMN_USERID_USERID_2); if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(SubscriptionModelImpl.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(userId); if (!pagination) { list = (List<Subscription>)QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<Subscription>)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 subscription in the ordered set where userId = ?. * * @param userId the user ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching subscription * @throws NoSuchSubscriptionException if a matching subscription could not be found */ @Override public Subscription findByUserId_First(long userId, OrderByComparator<Subscription> orderByComparator) throws NoSuchSubscriptionException { Subscription subscription = fetchByUserId_First(userId, orderByComparator); if (subscription != null) { return subscription; } StringBundler msg = new StringBundler(4); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("userId="); msg.append(userId); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchSubscriptionException(msg.toString()); } /** * Returns the first subscription in the ordered set where userId = ?. * * @param userId the user ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching subscription, or <code>null</code> if a matching subscription could not be found */ @Override public Subscription fetchByUserId_First(long userId, OrderByComparator<Subscription> orderByComparator) { List<Subscription> list = findByUserId(userId, 0, 1, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the last subscription in the ordered set where userId = ?. * * @param userId the user ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching subscription * @throws NoSuchSubscriptionException if a matching subscription could not be found */ @Override public Subscription findByUserId_Last(long userId, OrderByComparator<Subscription> orderByComparator) throws NoSuchSubscriptionException { Subscription subscription = fetchByUserId_Last(userId, orderByComparator); if (subscription != null) { return subscription; } StringBundler msg = new StringBundler(4); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("userId="); msg.append(userId); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchSubscriptionException(msg.toString()); } /** * Returns the last subscription in the ordered set where userId = ?. * * @param userId the user ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching subscription, or <code>null</code> if a matching subscription could not be found */ @Override public Subscription fetchByUserId_Last(long userId, OrderByComparator<Subscription> orderByComparator) { int count = countByUserId(userId); if (count == 0) { return null; } List<Subscription> list = findByUserId(userId, count - 1, count, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the subscriptions before and after the current subscription in the ordered set where userId = ?. * * @param subscriptionId the primary key of the current subscription * @param userId the user ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next subscription * @throws NoSuchSubscriptionException if a subscription with the primary key could not be found */ @Override public Subscription[] findByUserId_PrevAndNext(long subscriptionId, long userId, OrderByComparator<Subscription> orderByComparator) throws NoSuchSubscriptionException { Subscription subscription = findByPrimaryKey(subscriptionId); Session session = null; try { session = openSession(); Subscription[] array = new SubscriptionImpl[3]; array[0] = getByUserId_PrevAndNext(session, subscription, userId, orderByComparator, true); array[1] = subscription; array[2] = getByUserId_PrevAndNext(session, subscription, userId, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected Subscription getByUserId_PrevAndNext(Session session, Subscription subscription, long userId, OrderByComparator<Subscription> 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_SUBSCRIPTION_WHERE); query.append(_FINDER_COLUMN_USERID_USERID_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(SubscriptionModelImpl.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(userId); if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(subscription); for (Object value : values) { qPos.add(value); } } List<Subscription> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Removes all the subscriptions where userId = ? from the database. * * @param userId the user ID */ @Override public void removeByUserId(long userId) { for (Subscription subscription : findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) { remove(subscription); } } /** * Returns the number of subscriptions where userId = ?. * * @param userId the user ID * @return the number of matching subscriptions */ @Override public int countByUserId(long userId) { FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID; Object[] finderArgs = new Object[] { userId }; Long count = (Long)finderCache.getResult(finderPath, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(2); query.append(_SQL_COUNT_SUBSCRIPTION_WHERE); query.append(_FINDER_COLUMN_USERID_USERID_2); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(userId); 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_USERID_USERID_2 = "subscription.userId = ?"; public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U", new String[] { 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_G_U = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U", new String[] { Long.class.getName(), Long.class.getName() }, SubscriptionModelImpl.GROUPID_COLUMN_BITMASK | SubscriptionModelImpl.USERID_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U", new String[] { Long.class.getName(), Long.class.getName() }); /** * Returns all the subscriptions where groupId = ? and userId = ?. * * @param groupId the group ID * @param userId the user ID * @return the matching subscriptions */ @Override public List<Subscription> findByG_U(long groupId, long userId) { return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the subscriptions where groupId = ? and userId = ?. * * <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 SubscriptionModelImpl}. 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 groupId the group ID * @param userId the user ID * @param start the lower bound of the range of subscriptions * @param end the upper bound of the range of subscriptions (not inclusive) * @return the range of matching subscriptions */ @Override public List<Subscription> findByG_U(long groupId, long userId, int start, int end) { return findByG_U(groupId, userId, start, end, null); } /** * Returns an ordered range of all the subscriptions where groupId = ? and userId = ?. * * <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 SubscriptionModelImpl}. 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 groupId the group ID * @param userId the user ID * @param start the lower bound of the range of subscriptions * @param end the upper bound of the range of subscriptions (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching subscriptions */ @Override public List<Subscription> findByG_U(long groupId, long userId, int start, int end, OrderByComparator<Subscription> orderByComparator) { return findByG_U(groupId, userId, start, end, orderByComparator, true); } /** * Returns an ordered range of all the subscriptions where groupId = ? and userId = ?. * * <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 SubscriptionModelImpl}. 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 groupId the group ID * @param userId the user ID * @param start the lower bound of the range of subscriptions * @param end the upper bound of the range of subscriptions (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 subscriptions */ @Override public List<Subscription> findByG_U(long groupId, long userId, int start, int end, OrderByComparator<Subscription> 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_G_U; finderArgs = new Object[] { groupId, userId }; } else { finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U; finderArgs = new Object[] { groupId, userId, start, end, orderByComparator }; } List<Subscription> list = null; if (retrieveFromCache) { list = (List<Subscription>)finderCache.getResult(finderPath, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (Subscription subscription : list) { if ((groupId != subscription.getGroupId()) || (userId != subscription.getUserId())) { 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_SUBSCRIPTION_WHERE); query.append(_FINDER_COLUMN_G_U_GROUPID_2); query.append(_FINDER_COLUMN_G_U_USERID_2); if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(SubscriptionModelImpl.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(groupId); qPos.add(userId); if (!pagination) { list = (List<Subscription>)QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<Subscription>)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 subscription in the ordered set where groupId = ? and userId = ?. * * @param groupId the group ID * @param userId the user ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching subscription * @throws NoSuchSubscriptionException if a matching subscription could not be found */ @Override public Subscription findByG_U_First(long groupId, long userId, OrderByComparator<Subscription> orderByComparator) throws NoSuchSubscriptionException { Subscription subscription = fetchByG_U_First(groupId, userId, orderByComparator); if (subscription != null) { return subscription; } StringBundler msg = new StringBundler(6); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("groupId="); msg.append(groupId); msg.append(", userId="); msg.append(userId); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchSubscriptionException(msg.toString()); } /** * Returns the first subscription in the ordered set where groupId = ? and userId = ?. * * @param groupId the group ID * @param userId the user ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching subscription, or <code>null</code> if a matching subscription could not be found */ @Override public Subscription fetchByG_U_First(long groupId, long userId, OrderByComparator<Subscription> orderByComparator) { List<Subscription> list = findByG_U(groupId, userId, 0, 1, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the last subscription in the ordered set where groupId = ? and userId = ?. * * @param groupId the group ID * @param userId the user ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching subscription * @throws NoSuchSubscriptionException if a matching subscription could not be found */ @Override public Subscription findByG_U_Last(long groupId, long userId, OrderByComparator<Subscription> orderByComparator) throws NoSuchSubscriptionException { Subscription subscription = fetchByG_U_Last(groupId, userId, orderByComparator); if (subscription != null) { return subscription; } StringBundler msg = new StringBundler(6); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("groupId="); msg.append(groupId); msg.append(", userId="); msg.append(userId); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchSubscriptionException(msg.toString()); } /** * Returns the last subscription in the ordered set where groupId = ? and userId = ?. * * @param groupId the group ID * @param userId the user ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching subscription, or <code>null</code> if a matching subscription could not be found */ @Override public Subscription fetchByG_U_Last(long groupId, long userId, OrderByComparator<Subscription> orderByComparator) { int count = countByG_U(groupId, userId); if (count == 0) { return null; } List<Subscription> list = findByG_U(groupId, userId, count - 1, count, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the subscriptions before and after the current subscription in the ordered set where groupId = ? and userId = ?. * * @param subscriptionId the primary key of the current subscription * @param groupId the group ID * @param userId the user ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next subscription * @throws NoSuchSubscriptionException if a subscription with the primary key could not be found */ @Override public Subscription[] findByG_U_PrevAndNext(long subscriptionId, long groupId, long userId, OrderByComparator<Subscription> orderByComparator) throws NoSuchSubscriptionException { Subscription subscription = findByPrimaryKey(subscriptionId); Session session = null; try { session = openSession(); Subscription[] array = new SubscriptionImpl[3]; array[0] = getByG_U_PrevAndNext(session, subscription, groupId, userId, orderByComparator, true); array[1] = subscription; array[2] = getByG_U_PrevAndNext(session, subscription, groupId, userId, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected Subscription getByG_U_PrevAndNext(Session session, Subscription subscription, long groupId, long userId, OrderByComparator<Subscription> 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_SUBSCRIPTION_WHERE); query.append(_FINDER_COLUMN_G_U_GROUPID_2); query.append(_FINDER_COLUMN_G_U_USERID_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(SubscriptionModelImpl.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(groupId); qPos.add(userId); if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(subscription); for (Object value : values) { qPos.add(value); } } List<Subscription> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Removes all the subscriptions where groupId = ? and userId = ? from the database. * * @param groupId the group ID * @param userId the user ID */ @Override public void removeByG_U(long groupId, long userId) { for (Subscription subscription : findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) { remove(subscription); } } /** * Returns the number of subscriptions where groupId = ? and userId = ?. * * @param groupId the group ID * @param userId the user ID * @return the number of matching subscriptions */ @Override public int countByG_U(long groupId, long userId) { FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U; Object[] finderArgs = new Object[] { groupId, userId }; Long count = (Long)finderCache.getResult(finderPath, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(3); query.append(_SQL_COUNT_SUBSCRIPTION_WHERE); query.append(_FINDER_COLUMN_G_U_GROUPID_2); query.append(_FINDER_COLUMN_G_U_USERID_2); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); qPos.add(userId); 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_G_U_GROUPID_2 = "subscription.groupId = ? AND "; private static final String _FINDER_COLUMN_G_U_USERID_2 = "subscription.userId = ?"; public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C", new String[] { 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_U_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C", new String[] { Long.class.getName(), Long.class.getName() }, SubscriptionModelImpl.USERID_COLUMN_BITMASK | SubscriptionModelImpl.CLASSNAMEID_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_COUNT_BY_U_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C", new String[] { Long.class.getName(), Long.class.getName() }); /** * Returns all the subscriptions where userId = ? and classNameId = ?. * * @param userId the user ID * @param classNameId the class name ID * @return the matching subscriptions */ @Override public List<Subscription> findByU_C(long userId, long classNameId) { return findByU_C(userId, classNameId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the subscriptions where userId = ? and classNameId = ?. * * <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 SubscriptionModelImpl}. 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 userId the user ID * @param classNameId the class name ID * @param start the lower bound of the range of subscriptions * @param end the upper bound of the range of subscriptions (not inclusive) * @return the range of matching subscriptions */ @Override public List<Subscription> findByU_C(long userId, long classNameId, int start, int end) { return findByU_C(userId, classNameId, start, end, null); } /** * Returns an ordered range of all the subscriptions where userId = ? and classNameId = ?. * * <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 SubscriptionModelImpl}. 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 userId the user ID * @param classNameId the class name ID * @param start the lower bound of the range of subscriptions * @param end the upper bound of the range of subscriptions (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching subscriptions */ @Override public List<Subscription> findByU_C(long userId, long classNameId, int start, int end, OrderByComparator<Subscription> orderByComparator) { return findByU_C(userId, classNameId, start, end, orderByComparator, true); } /** * Returns an ordered range of all the subscriptions where userId = ? and classNameId = ?. * * <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 SubscriptionModelImpl}. 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 userId the user ID * @param classNameId the class name ID * @param start the lower bound of the range of subscriptions * @param end the upper bound of the range of subscriptions (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 subscriptions */ @Override public List<Subscription> findByU_C(long userId, long classNameId, int start, int end, OrderByComparator<Subscription> 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_U_C; finderArgs = new Object[] { userId, classNameId }; } else { finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C; finderArgs = new Object[] { userId, classNameId, start, end, orderByComparator }; } List<Subscription> list = null; if (retrieveFromCache) { list = (List<Subscription>)finderCache.getResult(finderPath, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (Subscription subscription : list) { if ((userId != subscription.getUserId()) || (classNameId != subscription.getClassNameId())) { 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_SUBSCRIPTION_WHERE); query.append(_FINDER_COLUMN_U_C_USERID_2); query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2); if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(SubscriptionModelImpl.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(userId); qPos.add(classNameId); if (!pagination) { list = (List<Subscription>)QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<Subscription>)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 subscription in the ordered set where userId = ? and classNameId = ?. * * @param userId the user ID * @param classNameId the class name ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching subscription * @throws NoSuchSubscriptionException if a matching subscription could not be found */ @Override public Subscription findByU_C_First(long userId, long classNameId, OrderByComparator<Subscription> orderByComparator) throws NoSuchSubscriptionException { Subscription subscription = fetchByU_C_First(userId, classNameId, orderByComparator); if (subscription != null) { return subscription; } StringBundler msg = new StringBundler(6); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("userId="); msg.append(userId); msg.append(", classNameId="); msg.append(classNameId); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchSubscriptionException(msg.toString()); } /** * Returns the first subscription in the ordered set where userId = ? and classNameId = ?. * * @param userId the user ID * @param classNameId the class name ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching subscription, or <code>null</code> if a matching subscription could not be found */ @Override public Subscription fetchByU_C_First(long userId, long classNameId, OrderByComparator<Subscription> orderByComparator) { List<Subscription> list = findByU_C(userId, classNameId, 0, 1, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the last subscription in the ordered set where userId = ? and classNameId = ?. * * @param userId the user ID * @param classNameId the class name ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching subscription * @throws NoSuchSubscriptionException if a matching subscription could not be found */ @Override public Subscription findByU_C_Last(long userId, long classNameId, OrderByComparator<Subscription> orderByComparator) throws NoSuchSubscriptionException { Subscription subscription = fetchByU_C_Last(userId, classNameId, orderByComparator); if (subscription != null) { return subscription; } StringBundler msg = new StringBundler(6); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("userId="); msg.append(userId); msg.append(", classNameId="); msg.append(classNameId); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchSubscriptionException(msg.toString()); } /** * Returns the last subscription in the ordered set where userId = ? and classNameId = ?. * * @param userId the user ID * @param classNameId the class name ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching subscription, or <code>null</code> if a matching subscription could not be found */ @Override public Subscription fetchByU_C_Last(long userId, long classNameId, OrderByComparator<Subscription> orderByComparator) { int count = countByU_C(userId, classNameId); if (count == 0) { return null; } List<Subscription> list = findByU_C(userId, classNameId, count - 1, count, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the subscriptions before and after the current subscription in the ordered set where userId = ? and classNameId = ?. * * @param subscriptionId the primary key of the current subscription * @param userId the user ID * @param classNameId the class name ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next subscription * @throws NoSuchSubscriptionException if a subscription with the primary key could not be found */ @Override public Subscription[] findByU_C_PrevAndNext(long subscriptionId, long userId, long classNameId, OrderByComparator<Subscription> orderByComparator) throws NoSuchSubscriptionException { Subscription subscription = findByPrimaryKey(subscriptionId); Session session = null; try { session = openSession(); Subscription[] array = new SubscriptionImpl[3]; array[0] = getByU_C_PrevAndNext(session, subscription, userId, classNameId, orderByComparator, true); array[1] = subscription; array[2] = getByU_C_PrevAndNext(session, subscription, userId, classNameId, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected Subscription getByU_C_PrevAndNext(Session session, Subscription subscription, long userId, long classNameId, OrderByComparator<Subscription> 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_SUBSCRIPTION_WHERE); query.append(_FINDER_COLUMN_U_C_USERID_2); query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_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(SubscriptionModelImpl.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(userId); qPos.add(classNameId); if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(subscription); for (Object value : values) { qPos.add(value); } } List<Subscription> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Removes all the subscriptions where userId = ? and classNameId = ? from the database. * * @param userId the user ID * @param classNameId the class name ID */ @Override public void removeByU_C(long userId, long classNameId) { for (Subscription subscription : findByU_C(userId, classNameId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) { remove(subscription); } } /** * Returns the number of subscriptions where userId = ? and classNameId = ?. * * @param userId the user ID * @param classNameId the class name ID * @return the number of matching subscriptions */ @Override public int countByU_C(long userId, long classNameId) { FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C; Object[] finderArgs = new Object[] { userId, classNameId }; Long count = (Long)finderCache.getResult(finderPath, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(3); query.append(_SQL_COUNT_SUBSCRIPTION_WHERE); query.append(_FINDER_COLUMN_U_C_USERID_2); query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(userId); qPos.add(classNameId); 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_U_C_USERID_2 = "subscription.userId = ? AND "; private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_2 = "subscription.classNameId = ?"; public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.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(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_C", new String[] { Long.class.getName(), Long.class.getName(), Long.class.getName() }, SubscriptionModelImpl.COMPANYID_COLUMN_BITMASK | SubscriptionModelImpl.CLASSNAMEID_COLUMN_BITMASK | SubscriptionModelImpl.CLASSPK_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionModelImpl.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() }); /** * Returns all the subscriptions where companyId = ? and classNameId = ? and classPK = ?. * * @param companyId the company ID * @param classNameId the class name ID * @param classPK the class pk * @return the matching subscriptions */ @Override public List<Subscription> findByC_C_C(long companyId, long classNameId, long classPK) { return findByC_C_C(companyId, classNameId, classPK, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the subscriptions where companyId = ? and classNameId = ? and classPK = ?. * * <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 SubscriptionModelImpl}. 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 subscriptions * @param end the upper bound of the range of subscriptions (not inclusive) * @return the range of matching subscriptions */ @Override public List<Subscription> findByC_C_C(long companyId, long classNameId, long classPK, int start, int end) { return findByC_C_C(companyId, classNameId, classPK, start, end, null); } /** * Returns an ordered range of all the subscriptions where companyId = ? and classNameId = ? and classPK = ?. * * <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 SubscriptionModelImpl}. 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 subscriptions * @param end the upper bound of the range of subscriptions (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching subscriptions */ @Override public List<Subscription> findByC_C_C(long companyId, long classNameId, long classPK, int start, int end, OrderByComparator<Subscription> orderByComparator) { return findByC_C_C(companyId, classNameId, classPK, start, end, orderByComparator, true); } /** * Returns an ordered range of all the subscriptions where companyId = ? and classNameId = ? and classPK = ?. * * <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 SubscriptionModelImpl}. 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 subscriptions * @param end the upper bound of the range of subscriptions (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 subscriptions */ @Override public List<Subscription> findByC_C_C(long companyId, long classNameId, long classPK, int start, int end, OrderByComparator<Subscription> 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_C_C; finderArgs = new Object[] { companyId, classNameId, classPK }; } else { finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C; finderArgs = new Object[] { companyId, classNameId, classPK, start, end, orderByComparator }; } List<Subscription> list = null; if (retrieveFromCache) { list = (List<Subscription>)finderCache.getResult(finderPath, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (Subscription subscription : list) { if ((companyId != subscription.getCompanyId()) || (classNameId != subscription.getClassNameId()) || (classPK != subscription.getClassPK())) { list = null; break; } } } } if (list == null) { StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(5 + (orderByComparator.getOrderByFields().length * 2)); } else { query = new StringBundler(5); } query.append(_SQL_SELECT_SUBSCRIPTION_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); if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(SubscriptionModelImpl.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); qPos.add(classPK); if (!pagination) { list = (List<Subscription>)QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<Subscription>)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 subscription in the ordered set where companyId = ? and classNameId = ? and classPK = ?. * * @param companyId the company ID * @param classNameId the class name ID * @param classPK the class pk * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching subscription * @throws NoSuchSubscriptionException if a matching subscription could not be found */ @Override public Subscription findByC_C_C_First(long companyId, long classNameId, long classPK, OrderByComparator<Subscription> orderByComparator) throws NoSuchSubscriptionException { Subscription subscription = fetchByC_C_C_First(companyId, classNameId, classPK, orderByComparator); if (subscription != null) { return subscription; } 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); throw new NoSuchSubscriptionException(msg.toString()); } /** * Returns the first subscription in the ordered set where companyId = ? and classNameId = ? and classPK = ?. * * @param companyId the company ID * @param classNameId the class name ID * @param classPK the class pk * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching subscription, or <code>null</code> if a matching subscription could not be found */ @Override public Subscription fetchByC_C_C_First(long companyId, long classNameId, long classPK, OrderByComparator<Subscription> orderByComparator) { List<Subscription> list = findByC_C_C(companyId, classNameId, classPK, 0, 1, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the last subscription in the ordered set where companyId = ? and classNameId = ? and classPK = ?. * * @param companyId the company ID * @param classNameId the class name ID * @param classPK the class pk * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching subscription * @throws NoSuchSubscriptionException if a matching subscription could not be found */ @Override public Subscription findByC_C_C_Last(long companyId, long classNameId, long classPK, OrderByComparator<Subscription> orderByComparator) throws NoSuchSubscriptionException { Subscription subscription = fetchByC_C_C_Last(companyId, classNameId, classPK, orderByComparator); if (subscription != null) { return subscription; } 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); throw new NoSuchSubscriptionException(msg.toString()); } /** * Returns the last subscription in the ordered set where companyId = ? and classNameId = ? and classPK = ?. * * @param companyId the company ID * @param classNameId the class name ID * @param classPK the class pk * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching subscription, or <code>null</code> if a matching subscription could not be found */ @Override public Subscription fetchByC_C_C_Last(long companyId, long classNameId, long classPK, OrderByComparator<Subscription> orderByComparator) { int count = countByC_C_C(companyId, classNameId, classPK); if (count == 0) { return null; } List<Subscription> list = findByC_C_C(companyId, classNameId, classPK, count - 1, count, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the subscriptions before and after the current subscription in the ordered set where companyId = ? and classNameId = ? and classPK = ?. * * @param subscriptionId the primary key of the current subscription * @param companyId the company ID * @param classNameId the class name ID * @param classPK the class pk * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next subscription * @throws NoSuchSubscriptionException if a subscription with the primary key could not be found */ @Override public Subscription[] findByC_C_C_PrevAndNext(long subscriptionId, long companyId, long classNameId, long classPK, OrderByComparator<Subscription> orderByComparator) throws NoSuchSubscriptionException { Subscription subscription = findByPrimaryKey(subscriptionId); Session session = null; try { session = openSession(); Subscription[] array = new SubscriptionImpl[3]; array[0] = getByC_C_C_PrevAndNext(session, subscription, companyId, classNameId, classPK, orderByComparator, true); array[1] = subscription; array[2] = getByC_C_C_PrevAndNext(session, subscription, companyId, classNameId, classPK, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected Subscription getByC_C_C_PrevAndNext(Session session, Subscription subscription, long companyId, long classNameId, long classPK, OrderByComparator<Subscription> 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); } query.append(_SQL_SELECT_SUBSCRIPTION_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); 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(SubscriptionModelImpl.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(classNameId); qPos.add(classPK); if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(subscription); for (Object value : values) { qPos.add(value); } } List<Subscription> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Removes all the subscriptions 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 */ @Override public void removeByC_C_C(long companyId, long classNameId, long classPK) { for (Subscription subscription : findByC_C_C(companyId, classNameId, classPK, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) { remove(subscription); } } /** * Returns the number of subscriptions 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 subscriptions */ @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_SUBSCRIPTION_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(); } private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "subscription.companyId = ? AND "; private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "subscription.classNameId = ? AND "; private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "subscription.classPK = ?"; public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_U_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_U_C_C", new String[] { Long.class.getName(), 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_U_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_U_C_C", new String[] { Long.class.getName(), Long.class.getName(), Long.class.getName(), Long.class.getName() }, SubscriptionModelImpl.COMPANYID_COLUMN_BITMASK | SubscriptionModelImpl.USERID_COLUMN_BITMASK | SubscriptionModelImpl.CLASSNAMEID_COLUMN_BITMASK | SubscriptionModelImpl.CLASSPK_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_FETCH_BY_C_U_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByC_U_C_C", new String[] { Long.class.getName(), Long.class.getName(), Long.class.getName(), Long.class.getName() }, SubscriptionModelImpl.COMPANYID_COLUMN_BITMASK | SubscriptionModelImpl.USERID_COLUMN_BITMASK | SubscriptionModelImpl.CLASSNAMEID_COLUMN_BITMASK | SubscriptionModelImpl.CLASSPK_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_COUNT_BY_C_U_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_U_C_C", new String[] { Long.class.getName(), Long.class.getName(), Long.class.getName(), Long.class.getName() }); public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_U_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_U_C_C", new String[] { Long.class.getName(), Long.class.getName(), Long.class.getName(), Long.class.getName() }); /** * Returns all the subscriptions where companyId = ? and userId = ? 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 SubscriptionModelImpl}. 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 userId the user ID * @param classNameId the class name ID * @param classPKs the class pks * @return the matching subscriptions */ @Override public List<Subscription> findByC_U_C_C(long companyId, long userId, long classNameId, long[] classPKs) { return findByC_U_C_C(companyId, userId, classNameId, classPKs, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the subscriptions where companyId = ? and userId = ? 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 SubscriptionModelImpl}. 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 userId the user ID * @param classNameId the class name ID * @param classPKs the class pks * @param start the lower bound of the range of subscriptions * @param end the upper bound of the range of subscriptions (not inclusive) * @return the range of matching subscriptions */ @Override public List<Subscription> findByC_U_C_C(long companyId, long userId, long classNameId, long[] classPKs, int start, int end) { return findByC_U_C_C(companyId, userId, classNameId, classPKs, start, end, null); } /** * Returns an ordered range of all the subscriptions where companyId = ? and userId = ? 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 SubscriptionModelImpl}. 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 userId the user ID * @param classNameId the class name ID * @param classPKs the class pks * @param start the lower bound of the range of subscriptions * @param end the upper bound of the range of subscriptions (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching subscriptions */ @Override public List<Subscription> findByC_U_C_C(long companyId, long userId, long classNameId, long[] classPKs, int start, int end, OrderByComparator<Subscription> orderByComparator) { return findByC_U_C_C(companyId, userId, classNameId, classPKs, start, end, orderByComparator, true); } /** * Returns an ordered range of all the subscriptions where companyId = ? and userId = ? 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 SubscriptionModelImpl}. 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 userId the user ID * @param classNameId the class name ID * @param classPK the class pk * @param start the lower bound of the range of subscriptions * @param end the upper bound of the range of subscriptions (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 subscriptions */ @Override public List<Subscription> findByC_U_C_C(long companyId, long userId, long classNameId, long[] classPKs, int start, int end, OrderByComparator<Subscription> 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) { Subscription subscription = fetchByC_U_C_C(companyId, userId, classNameId, classPKs[0]); if (subscription == null) { return Collections.emptyList(); } else { List<Subscription> list = new ArrayList<Subscription>(1); list.add(subscription); 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, userId, classNameId, StringUtil.merge(classPKs) }; } else { finderArgs = new Object[] { companyId, userId, classNameId, StringUtil.merge(classPKs), start, end, orderByComparator }; } List<Subscription> list = null; if (retrieveFromCache) { list = (List<Subscription>)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_U_C_C, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (Subscription subscription : list) { if ((companyId != subscription.getCompanyId()) || (userId != subscription.getUserId()) || (classNameId != subscription.getClassNameId()) || !ArrayUtil.contains(classPKs, subscription.getClassPK())) { list = null; break; } } } } if (list == null) { StringBundler query = new StringBundler(); query.append(_SQL_SELECT_SUBSCRIPTION_WHERE); query.append(_FINDER_COLUMN_C_U_C_C_COMPANYID_2); query.append(_FINDER_COLUMN_C_U_C_C_USERID_2); query.append(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2); if (classPKs.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_C_U_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(SubscriptionModelImpl.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(userId); qPos.add(classNameId); if (!pagination) { list = (List<Subscription>)QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<Subscription>)QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_U_C_C, finderArgs, list); } catch (Exception e) { finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_U_C_C, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; } /** * Returns the subscription where companyId = ? and userId = ? and classNameId = ? and classPK = ? or throws a {@link NoSuchSubscriptionException} if it could not be found. * * @param companyId the company ID * @param userId the user ID * @param classNameId the class name ID * @param classPK the class pk * @return the matching subscription * @throws NoSuchSubscriptionException if a matching subscription could not be found */ @Override public Subscription findByC_U_C_C(long companyId, long userId, long classNameId, long classPK) throws NoSuchSubscriptionException { Subscription subscription = fetchByC_U_C_C(companyId, userId, classNameId, classPK); if (subscription == null) { StringBundler msg = new StringBundler(10); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("companyId="); msg.append(companyId); msg.append(", userId="); msg.append(userId); 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 NoSuchSubscriptionException(msg.toString()); } return subscription; } /** * Returns the subscription where companyId = ? and userId = ? 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 userId the user ID * @param classNameId the class name ID * @param classPK the class pk * @return the matching subscription, or <code>null</code> if a matching subscription could not be found */ @Override public Subscription fetchByC_U_C_C(long companyId, long userId, long classNameId, long classPK) { return fetchByC_U_C_C(companyId, userId, classNameId, classPK, true); } /** * Returns the subscription where companyId = ? and userId = ? 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 userId the user ID * @param classNameId the class name ID * @param classPK the class pk * @param retrieveFromCache whether to retrieve from the finder cache * @return the matching subscription, or <code>null</code> if a matching subscription could not be found */ @Override public Subscription fetchByC_U_C_C(long companyId, long userId, long classNameId, long classPK, boolean retrieveFromCache) { Object[] finderArgs = new Object[] { companyId, userId, classNameId, classPK }; Object result = null; if (retrieveFromCache) { result = finderCache.getResult(FINDER_PATH_FETCH_BY_C_U_C_C, finderArgs, this); } if (result instanceof Subscription) { Subscription subscription = (Subscription)result; if ((companyId != subscription.getCompanyId()) || (userId != subscription.getUserId()) || (classNameId != subscription.getClassNameId()) || (classPK != subscription.getClassPK())) { result = null; } } if (result == null) { StringBundler query = new StringBundler(6); query.append(_SQL_SELECT_SUBSCRIPTION_WHERE); query.append(_FINDER_COLUMN_C_U_C_C_COMPANYID_2); query.append(_FINDER_COLUMN_C_U_C_C_USERID_2); query.append(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2); query.append(_FINDER_COLUMN_C_U_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(userId); qPos.add(classNameId); qPos.add(classPK); List<Subscription> list = q.list(); if (list.isEmpty()) { finderCache.putResult(FINDER_PATH_FETCH_BY_C_U_C_C, finderArgs, list); } else { Subscription subscription = list.get(0); result = subscription; cacheResult(subscription); if ((subscription.getCompanyId() != companyId) || (subscription.getUserId() != userId) || (subscription.getClassNameId() != classNameId) || (subscription.getClassPK() != classPK)) { finderCache.putResult(FINDER_PATH_FETCH_BY_C_U_C_C, finderArgs, subscription); } } } catch (Exception e) { finderCache.removeResult(FINDER_PATH_FETCH_BY_C_U_C_C, finderArgs); throw processException(e); } finally { closeSession(session); } } if (result instanceof List<?>) { return null; } else { return (Subscription)result; } } /** * Removes the subscription where companyId = ? and userId = ? and classNameId = ? and classPK = ? from the database. * * @param companyId the company ID * @param userId the user ID * @param classNameId the class name ID * @param classPK the class pk * @return the subscription that was removed */ @Override public Subscription removeByC_U_C_C(long companyId, long userId, long classNameId, long classPK) throws NoSuchSubscriptionException { Subscription subscription = findByC_U_C_C(companyId, userId, classNameId, classPK); return remove(subscription); } /** * Returns the number of subscriptions where companyId = ? and userId = ? and classNameId = ? and classPK = ?. * * @param companyId the company ID * @param userId the user ID * @param classNameId the class name ID * @param classPK the class pk * @return the number of matching subscriptions */ @Override public int countByC_U_C_C(long companyId, long userId, long classNameId, long classPK) { FinderPath finderPath = FINDER_PATH_COUNT_BY_C_U_C_C; Object[] finderArgs = new Object[] { companyId, userId, classNameId, classPK }; Long count = (Long)finderCache.getResult(finderPath, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(5); query.append(_SQL_COUNT_SUBSCRIPTION_WHERE); query.append(_FINDER_COLUMN_C_U_C_C_COMPANYID_2); query.append(_FINDER_COLUMN_C_U_C_C_USERID_2); query.append(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2); query.append(_FINDER_COLUMN_C_U_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(userId); 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 subscriptions where companyId = ? and userId = ? and classNameId = ? and classPK = any ?. * * @param companyId the company ID * @param userId the user ID * @param classNameId the class name ID * @param classPKs the class pks * @return the number of matching subscriptions */ @Override public int countByC_U_C_C(long companyId, long userId, 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, userId, classNameId, StringUtil.merge(classPKs) }; Long count = (Long)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_U_C_C, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(); query.append(_SQL_COUNT_SUBSCRIPTION_WHERE); query.append(_FINDER_COLUMN_C_U_C_C_COMPANYID_2); query.append(_FINDER_COLUMN_C_U_C_C_USERID_2); query.append(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2); if (classPKs.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_C_U_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(userId); qPos.add(classNameId); count = (Long)q.uniqueResult(); finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_U_C_C, finderArgs, count); } catch (Exception e) { finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_U_C_C, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); } private static final String _FINDER_COLUMN_C_U_C_C_COMPANYID_2 = "subscription.companyId = ? AND "; private static final String _FINDER_COLUMN_C_U_C_C_USERID_2 = "subscription.userId = ? AND "; private static final String _FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2 = "subscription.classNameId = ? AND "; private static final String _FINDER_COLUMN_C_U_C_C_CLASSPK_2 = "subscription.classPK = ?"; private static final String _FINDER_COLUMN_C_U_C_C_CLASSPK_7 = "subscription.classPK IN ("; public SubscriptionPersistenceImpl() { setModelClass(Subscription.class); } /** * Caches the subscription in the entity cache if it is enabled. * * @param subscription the subscription */ @Override public void cacheResult(Subscription subscription) { entityCache.putResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionImpl.class, subscription.getPrimaryKey(), subscription); finderCache.putResult(FINDER_PATH_FETCH_BY_C_U_C_C, new Object[] { subscription.getCompanyId(), subscription.getUserId(), subscription.getClassNameId(), subscription.getClassPK() }, subscription); subscription.resetOriginalValues(); } /** * Caches the subscriptions in the entity cache if it is enabled. * * @param subscriptions the subscriptions */ @Override public void cacheResult(List<Subscription> subscriptions) { for (Subscription subscription : subscriptions) { if (entityCache.getResult( SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionImpl.class, subscription.getPrimaryKey()) == null) { cacheResult(subscription); } else { subscription.resetOriginalValues(); } } } /** * Clears the cache for all subscriptions. * * <p> * The {@link EntityCache} and {@link FinderCache} are both cleared by this method. * </p> */ @Override public void clearCache() { entityCache.clearCache(SubscriptionImpl.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 subscription. * * <p> * The {@link EntityCache} and {@link FinderCache} are both cleared by this method. * </p> */ @Override public void clearCache(Subscription subscription) { entityCache.removeResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionImpl.class, subscription.getPrimaryKey()); finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); clearUniqueFindersCache((SubscriptionModelImpl)subscription, true); } @Override public void clearCache(List<Subscription> subscriptions) { finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); for (Subscription subscription : subscriptions) { entityCache.removeResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionImpl.class, subscription.getPrimaryKey()); clearUniqueFindersCache((SubscriptionModelImpl)subscription, true); } } protected void cacheUniqueFindersCache( SubscriptionModelImpl subscriptionModelImpl) { Object[] args = new Object[] { subscriptionModelImpl.getCompanyId(), subscriptionModelImpl.getUserId(), subscriptionModelImpl.getClassNameId(), subscriptionModelImpl.getClassPK() }; finderCache.putResult(FINDER_PATH_COUNT_BY_C_U_C_C, args, Long.valueOf(1), false); finderCache.putResult(FINDER_PATH_FETCH_BY_C_U_C_C, args, subscriptionModelImpl, false); } protected void clearUniqueFindersCache( SubscriptionModelImpl subscriptionModelImpl, boolean clearCurrent) { if (clearCurrent) { Object[] args = new Object[] { subscriptionModelImpl.getCompanyId(), subscriptionModelImpl.getUserId(), subscriptionModelImpl.getClassNameId(), subscriptionModelImpl.getClassPK() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_C_U_C_C, args); finderCache.removeResult(FINDER_PATH_FETCH_BY_C_U_C_C, args); } if ((subscriptionModelImpl.getColumnBitmask() & FINDER_PATH_FETCH_BY_C_U_C_C.getColumnBitmask()) != 0) { Object[] args = new Object[] { subscriptionModelImpl.getOriginalCompanyId(), subscriptionModelImpl.getOriginalUserId(), subscriptionModelImpl.getOriginalClassNameId(), subscriptionModelImpl.getOriginalClassPK() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_C_U_C_C, args); finderCache.removeResult(FINDER_PATH_FETCH_BY_C_U_C_C, args); } } /** * Creates a new subscription with the primary key. Does not add the subscription to the database. * * @param subscriptionId the primary key for the new subscription * @return the new subscription */ @Override public Subscription create(long subscriptionId) { Subscription subscription = new SubscriptionImpl(); subscription.setNew(true); subscription.setPrimaryKey(subscriptionId); subscription.setCompanyId(companyProvider.getCompanyId()); return subscription; } /** * Removes the subscription with the primary key from the database. Also notifies the appropriate model listeners. * * @param subscriptionId the primary key of the subscription * @return the subscription that was removed * @throws NoSuchSubscriptionException if a subscription with the primary key could not be found */ @Override public Subscription remove(long subscriptionId) throws NoSuchSubscriptionException { return remove((Serializable)subscriptionId); } /** * Removes the subscription with the primary key from the database. Also notifies the appropriate model listeners. * * @param primaryKey the primary key of the subscription * @return the subscription that was removed * @throws NoSuchSubscriptionException if a subscription with the primary key could not be found */ @Override public Subscription remove(Serializable primaryKey) throws NoSuchSubscriptionException { Session session = null; try { session = openSession(); Subscription subscription = (Subscription)session.get(SubscriptionImpl.class, primaryKey); if (subscription == null) { if (_log.isDebugEnabled()) { _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey); } throw new NoSuchSubscriptionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey); } return remove(subscription); } catch (NoSuchSubscriptionException nsee) { throw nsee; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } @Override protected Subscription removeImpl(Subscription subscription) { subscription = toUnwrappedModel(subscription); Session session = null; try { session = openSession(); if (!session.contains(subscription)) { subscription = (Subscription)session.get(SubscriptionImpl.class, subscription.getPrimaryKeyObj()); } if (subscription != null) { session.delete(subscription); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } if (subscription != null) { clearCache(subscription); } return subscription; } @Override public Subscription updateImpl(Subscription subscription) { subscription = toUnwrappedModel(subscription); boolean isNew = subscription.isNew(); SubscriptionModelImpl subscriptionModelImpl = (SubscriptionModelImpl)subscription; ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext(); Date now = new Date(); if (isNew && (subscription.getCreateDate() == null)) { if (serviceContext == null) { subscription.setCreateDate(now); } else { subscription.setCreateDate(serviceContext.getCreateDate(now)); } } if (!subscriptionModelImpl.hasSetModifiedDate()) { if (serviceContext == null) { subscription.setModifiedDate(now); } else { subscription.setModifiedDate(serviceContext.getModifiedDate(now)); } } Session session = null; try { session = openSession(); if (subscription.isNew()) { session.save(subscription); subscription.setNew(false); } else { subscription = (Subscription)session.merge(subscription); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); if (!SubscriptionModelImpl.COLUMN_BITMASK_ENABLED) { finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); } else if (isNew) { Object[] args = new Object[] { subscriptionModelImpl.getGroupId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID, args); args = new Object[] { subscriptionModelImpl.getUserId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID, args); args = new Object[] { subscriptionModelImpl.getGroupId(), subscriptionModelImpl.getUserId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U, args); args = new Object[] { subscriptionModelImpl.getUserId(), subscriptionModelImpl.getClassNameId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C, args); args = new Object[] { subscriptionModelImpl.getCompanyId(), subscriptionModelImpl.getClassNameId(), subscriptionModelImpl.getClassPK() }; 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[] { subscriptionModelImpl.getCompanyId(), subscriptionModelImpl.getUserId(), subscriptionModelImpl.getClassNameId(), subscriptionModelImpl.getClassPK() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_C_U_C_C, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_U_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 ((subscriptionModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) { Object[] args = new Object[] { subscriptionModelImpl.getOriginalGroupId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID, args); args = new Object[] { subscriptionModelImpl.getGroupId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID, args); } if ((subscriptionModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) { Object[] args = new Object[] { subscriptionModelImpl.getOriginalUserId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID, args); args = new Object[] { subscriptionModelImpl.getUserId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID, args); } if ((subscriptionModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U.getColumnBitmask()) != 0) { Object[] args = new Object[] { subscriptionModelImpl.getOriginalGroupId(), subscriptionModelImpl.getOriginalUserId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U, args); args = new Object[] { subscriptionModelImpl.getGroupId(), subscriptionModelImpl.getUserId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U, args); } if ((subscriptionModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C.getColumnBitmask()) != 0) { Object[] args = new Object[] { subscriptionModelImpl.getOriginalUserId(), subscriptionModelImpl.getOriginalClassNameId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C, args); args = new Object[] { subscriptionModelImpl.getUserId(), subscriptionModelImpl.getClassNameId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C, args); } if ((subscriptionModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C.getColumnBitmask()) != 0) { Object[] args = new Object[] { subscriptionModelImpl.getOriginalCompanyId(), subscriptionModelImpl.getOriginalClassNameId(), subscriptionModelImpl.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[] { subscriptionModelImpl.getCompanyId(), subscriptionModelImpl.getClassNameId(), subscriptionModelImpl.getClassPK() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C, args); } if ((subscriptionModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_U_C_C.getColumnBitmask()) != 0) { Object[] args = new Object[] { subscriptionModelImpl.getOriginalCompanyId(), subscriptionModelImpl.getOriginalUserId(), subscriptionModelImpl.getOriginalClassNameId(), subscriptionModelImpl.getOriginalClassPK() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_C_U_C_C, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_U_C_C, args); args = new Object[] { subscriptionModelImpl.getCompanyId(), subscriptionModelImpl.getUserId(), subscriptionModelImpl.getClassNameId(), subscriptionModelImpl.getClassPK() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_C_U_C_C, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_U_C_C, args); } } entityCache.putResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionImpl.class, subscription.getPrimaryKey(), subscription, false); clearUniqueFindersCache(subscriptionModelImpl, false); cacheUniqueFindersCache(subscriptionModelImpl); subscription.resetOriginalValues(); return subscription; } protected Subscription toUnwrappedModel(Subscription subscription) { if (subscription instanceof SubscriptionImpl) { return subscription; } SubscriptionImpl subscriptionImpl = new SubscriptionImpl(); subscriptionImpl.setNew(subscription.isNew()); subscriptionImpl.setPrimaryKey(subscription.getPrimaryKey()); subscriptionImpl.setMvccVersion(subscription.getMvccVersion()); subscriptionImpl.setSubscriptionId(subscription.getSubscriptionId()); subscriptionImpl.setGroupId(subscription.getGroupId()); subscriptionImpl.setCompanyId(subscription.getCompanyId()); subscriptionImpl.setUserId(subscription.getUserId()); subscriptionImpl.setUserName(subscription.getUserName()); subscriptionImpl.setCreateDate(subscription.getCreateDate()); subscriptionImpl.setModifiedDate(subscription.getModifiedDate()); subscriptionImpl.setClassNameId(subscription.getClassNameId()); subscriptionImpl.setClassPK(subscription.getClassPK()); subscriptionImpl.setFrequency(subscription.getFrequency()); return subscriptionImpl; } /** * Returns the subscription 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 subscription * @return the subscription * @throws NoSuchSubscriptionException if a subscription with the primary key could not be found */ @Override public Subscription findByPrimaryKey(Serializable primaryKey) throws NoSuchSubscriptionException { Subscription subscription = fetchByPrimaryKey(primaryKey); if (subscription == null) { if (_log.isDebugEnabled()) { _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey); } throw new NoSuchSubscriptionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey); } return subscription; } /** * Returns the subscription with the primary key or throws a {@link NoSuchSubscriptionException} if it could not be found. * * @param subscriptionId the primary key of the subscription * @return the subscription * @throws NoSuchSubscriptionException if a subscription with the primary key could not be found */ @Override public Subscription findByPrimaryKey(long subscriptionId) throws NoSuchSubscriptionException { return findByPrimaryKey((Serializable)subscriptionId); } /** * Returns the subscription with the primary key or returns <code>null</code> if it could not be found. * * @param primaryKey the primary key of the subscription * @return the subscription, or <code>null</code> if a subscription with the primary key could not be found */ @Override public Subscription fetchByPrimaryKey(Serializable primaryKey) { Serializable serializable = entityCache.getResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionImpl.class, primaryKey); if (serializable == nullModel) { return null; } Subscription subscription = (Subscription)serializable; if (subscription == null) { Session session = null; try { session = openSession(); subscription = (Subscription)session.get(SubscriptionImpl.class, primaryKey); if (subscription != null) { cacheResult(subscription); } else { entityCache.putResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionImpl.class, primaryKey, nullModel); } } catch (Exception e) { entityCache.removeResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionImpl.class, primaryKey); throw processException(e); } finally { closeSession(session); } } return subscription; } /** * Returns the subscription with the primary key or returns <code>null</code> if it could not be found. * * @param subscriptionId the primary key of the subscription * @return the subscription, or <code>null</code> if a subscription with the primary key could not be found */ @Override public Subscription fetchByPrimaryKey(long subscriptionId) { return fetchByPrimaryKey((Serializable)subscriptionId); } @Override public Map<Serializable, Subscription> fetchByPrimaryKeys( Set<Serializable> primaryKeys) { if (primaryKeys.isEmpty()) { return Collections.emptyMap(); } Map<Serializable, Subscription> map = new HashMap<Serializable, Subscription>(); if (primaryKeys.size() == 1) { Iterator<Serializable> iterator = primaryKeys.iterator(); Serializable primaryKey = iterator.next(); Subscription subscription = fetchByPrimaryKey(primaryKey); if (subscription != null) { map.put(primaryKey, subscription); } return map; } Set<Serializable> uncachedPrimaryKeys = null; for (Serializable primaryKey : primaryKeys) { Serializable serializable = entityCache.getResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionImpl.class, primaryKey); if (serializable != nullModel) { if (serializable == null) { if (uncachedPrimaryKeys == null) { uncachedPrimaryKeys = new HashSet<Serializable>(); } uncachedPrimaryKeys.add(primaryKey); } else { map.put(primaryKey, (Subscription)serializable); } } } if (uncachedPrimaryKeys == null) { return map; } StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1); query.append(_SQL_SELECT_SUBSCRIPTION_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 (Subscription subscription : (List<Subscription>)q.list()) { map.put(subscription.getPrimaryKeyObj(), subscription); cacheResult(subscription); uncachedPrimaryKeys.remove(subscription.getPrimaryKeyObj()); } for (Serializable primaryKey : uncachedPrimaryKeys) { entityCache.putResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED, SubscriptionImpl.class, primaryKey, nullModel); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } return map; } /** * Returns all the subscriptions. * * @return the subscriptions */ @Override public List<Subscription> findAll() { return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the subscriptions. * * <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 SubscriptionModelImpl}. 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 subscriptions * @param end the upper bound of the range of subscriptions (not inclusive) * @return the range of subscriptions */ @Override public List<Subscription> findAll(int start, int end) { return findAll(start, end, null); } /** * Returns an ordered range of all the subscriptions. * * <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 SubscriptionModelImpl}. 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 subscriptions * @param end the upper bound of the range of subscriptions (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of subscriptions */ @Override public List<Subscription> findAll(int start, int end, OrderByComparator<Subscription> orderByComparator) { return findAll(start, end, orderByComparator, true); } /** * Returns an ordered range of all the subscriptions. * * <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 SubscriptionModelImpl}. 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 subscriptions * @param end the upper bound of the range of subscriptions (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 subscriptions */ @Override public List<Subscription> findAll(int start, int end, OrderByComparator<Subscription> 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<Subscription> list = null; if (retrieveFromCache) { list = (List<Subscription>)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_SUBSCRIPTION); appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); sql = query.toString(); } else { sql = _SQL_SELECT_SUBSCRIPTION; if (pagination) { sql = sql.concat(SubscriptionModelImpl.ORDER_BY_JPQL); } } Session session = null; try { session = openSession(); Query q = session.createQuery(sql); if (!pagination) { list = (List<Subscription>)QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<Subscription>)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 subscriptions from the database. * */ @Override public void removeAll() { for (Subscription subscription : findAll()) { remove(subscription); } } /** * Returns the number of subscriptions. * * @return the number of subscriptions */ @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_SUBSCRIPTION); 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(); } @Override protected Map<String, Integer> getTableColumnsMap() { return SubscriptionModelImpl.TABLE_COLUMNS_MAP; } /** * Initializes the subscription persistence. */ public void afterPropertiesSet() { } public void destroy() { entityCache.removeCache(SubscriptionImpl.class.getName()); finderCache.removeCache(FINDER_CLASS_NAME_ENTITY); finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); } @ServiceReference(type = CompanyProviderWrapper.class) protected CompanyProvider companyProvider; @ServiceReference(type = EntityCache.class) protected EntityCache entityCache; @ServiceReference(type = FinderCache.class) protected FinderCache finderCache; private static final String _SQL_SELECT_SUBSCRIPTION = "SELECT subscription FROM Subscription subscription"; private static final String _SQL_SELECT_SUBSCRIPTION_WHERE_PKS_IN = "SELECT subscription FROM Subscription subscription WHERE subscriptionId IN ("; private static final String _SQL_SELECT_SUBSCRIPTION_WHERE = "SELECT subscription FROM Subscription subscription WHERE "; private static final String _SQL_COUNT_SUBSCRIPTION = "SELECT COUNT(subscription) FROM Subscription subscription"; private static final String _SQL_COUNT_SUBSCRIPTION_WHERE = "SELECT COUNT(subscription) FROM Subscription subscription WHERE "; private static final String _ORDER_BY_ENTITY_ALIAS = "subscription."; private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Subscription exists with the primary key "; private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Subscription exists with the key {"; private static final Log _log = LogFactoryUtil.getLog(SubscriptionPersistenceImpl.class); }