/** * 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.portlet.trash.service.persistence.impl; import aQute.bnd.annotation.ProviderType; import com.liferay.portal.kernel.bean.BeanReference; import com.liferay.portal.kernel.dao.orm.EntityCache; import com.liferay.portal.kernel.dao.orm.EntityCacheUtil; import com.liferay.portal.kernel.dao.orm.FinderCache; import com.liferay.portal.kernel.dao.orm.FinderCacheUtil; import com.liferay.portal.kernel.dao.orm.FinderPath; import com.liferay.portal.kernel.dao.orm.Query; import com.liferay.portal.kernel.dao.orm.QueryPos; import com.liferay.portal.kernel.dao.orm.QueryUtil; import com.liferay.portal.kernel.dao.orm.Session; import com.liferay.portal.kernel.log.Log; import com.liferay.portal.kernel.log.LogFactoryUtil; 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.OrderByComparator; import com.liferay.portal.kernel.util.StringBundler; import com.liferay.portal.kernel.util.StringPool; import com.liferay.portlet.trash.model.impl.TrashEntryImpl; import com.liferay.portlet.trash.model.impl.TrashEntryModelImpl; import com.liferay.trash.kernel.exception.NoSuchEntryException; import com.liferay.trash.kernel.model.TrashEntry; import com.liferay.trash.kernel.service.persistence.TrashEntryPersistence; import java.io.Serializable; import java.sql.Timestamp; 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 trash entry service. * * <p> * Caching information and settings can be found in <code>portal.properties</code> * </p> * * @author Brian Wing Shun Chan * @see TrashEntryPersistence * @see com.liferay.trash.kernel.service.persistence.TrashEntryUtil * @generated */ @ProviderType public class TrashEntryPersistenceImpl extends BasePersistenceImpl<TrashEntry> implements TrashEntryPersistence { /* * NOTE FOR DEVELOPERS: * * Never modify or reference this class directly. Always use {@link TrashEntryUtil} to access the trash entry persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class. */ public static final String FINDER_CLASS_NAME_ENTITY = TrashEntryImpl.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(TrashEntryModelImpl.ENTITY_CACHE_ENABLED, TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]); public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED, TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]); public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED, TrashEntryModelImpl.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(TrashEntryModelImpl.ENTITY_CACHE_ENABLED, TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.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(TrashEntryModelImpl.ENTITY_CACHE_ENABLED, TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId", new String[] { Long.class.getName() }, TrashEntryModelImpl.GROUPID_COLUMN_BITMASK | TrashEntryModelImpl.CREATEDATE_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED, TrashEntryModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId", new String[] { Long.class.getName() }); /** * Returns all the trash entries where groupId = ?. * * @param groupId the group ID * @return the matching trash entries */ @Override public List<TrashEntry> findByGroupId(long groupId) { return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the trash entries 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 TrashEntryModelImpl}. 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 trash entries * @param end the upper bound of the range of trash entries (not inclusive) * @return the range of matching trash entries */ @Override public List<TrashEntry> findByGroupId(long groupId, int start, int end) { return findByGroupId(groupId, start, end, null); } /** * Returns an ordered range of all the trash entries 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 TrashEntryModelImpl}. 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 trash entries * @param end the upper bound of the range of trash entries (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching trash entries */ @Override public List<TrashEntry> findByGroupId(long groupId, int start, int end, OrderByComparator<TrashEntry> orderByComparator) { return findByGroupId(groupId, start, end, orderByComparator, true); } /** * Returns an ordered range of all the trash entries 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 TrashEntryModelImpl}. 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 trash entries * @param end the upper bound of the range of trash entries (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 trash entries */ @Override public List<TrashEntry> findByGroupId(long groupId, int start, int end, OrderByComparator<TrashEntry> 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<TrashEntry> list = null; if (retrieveFromCache) { list = (List<TrashEntry>)finderCache.getResult(finderPath, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (TrashEntry trashEntry : list) { if ((groupId != trashEntry.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_TRASHENTRY_WHERE); query.append(_FINDER_COLUMN_GROUPID_GROUPID_2); if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(TrashEntryModelImpl.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<TrashEntry>)QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<TrashEntry>)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 trash entry 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 trash entry * @throws NoSuchEntryException if a matching trash entry could not be found */ @Override public TrashEntry findByGroupId_First(long groupId, OrderByComparator<TrashEntry> orderByComparator) throws NoSuchEntryException { TrashEntry trashEntry = fetchByGroupId_First(groupId, orderByComparator); if (trashEntry != null) { return trashEntry; } 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 NoSuchEntryException(msg.toString()); } /** * Returns the first trash entry 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 trash entry, or <code>null</code> if a matching trash entry could not be found */ @Override public TrashEntry fetchByGroupId_First(long groupId, OrderByComparator<TrashEntry> orderByComparator) { List<TrashEntry> list = findByGroupId(groupId, 0, 1, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the last trash entry 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 trash entry * @throws NoSuchEntryException if a matching trash entry could not be found */ @Override public TrashEntry findByGroupId_Last(long groupId, OrderByComparator<TrashEntry> orderByComparator) throws NoSuchEntryException { TrashEntry trashEntry = fetchByGroupId_Last(groupId, orderByComparator); if (trashEntry != null) { return trashEntry; } 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 NoSuchEntryException(msg.toString()); } /** * Returns the last trash entry 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 trash entry, or <code>null</code> if a matching trash entry could not be found */ @Override public TrashEntry fetchByGroupId_Last(long groupId, OrderByComparator<TrashEntry> orderByComparator) { int count = countByGroupId(groupId); if (count == 0) { return null; } List<TrashEntry> list = findByGroupId(groupId, count - 1, count, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the trash entries before and after the current trash entry in the ordered set where groupId = ?. * * @param entryId the primary key of the current trash entry * @param groupId the group ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next trash entry * @throws NoSuchEntryException if a trash entry with the primary key could not be found */ @Override public TrashEntry[] findByGroupId_PrevAndNext(long entryId, long groupId, OrderByComparator<TrashEntry> orderByComparator) throws NoSuchEntryException { TrashEntry trashEntry = findByPrimaryKey(entryId); Session session = null; try { session = openSession(); TrashEntry[] array = new TrashEntryImpl[3]; array[0] = getByGroupId_PrevAndNext(session, trashEntry, groupId, orderByComparator, true); array[1] = trashEntry; array[2] = getByGroupId_PrevAndNext(session, trashEntry, groupId, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected TrashEntry getByGroupId_PrevAndNext(Session session, TrashEntry trashEntry, long groupId, OrderByComparator<TrashEntry> 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_TRASHENTRY_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(TrashEntryModelImpl.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(trashEntry); for (Object value : values) { qPos.add(value); } } List<TrashEntry> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Removes all the trash entries where groupId = ? from the database. * * @param groupId the group ID */ @Override public void removeByGroupId(long groupId) { for (TrashEntry trashEntry : findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) { remove(trashEntry); } } /** * Returns the number of trash entries where groupId = ?. * * @param groupId the group ID * @return the number of matching trash entries */ @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_TRASHENTRY_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 = "trashEntry.groupId = ?"; public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED, TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId", new String[] { Long.class.getName(), Integer.class.getName(), Integer.class.getName(), OrderByComparator.class.getName() }); public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED, TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId", new String[] { Long.class.getName() }, TrashEntryModelImpl.COMPANYID_COLUMN_BITMASK | TrashEntryModelImpl.CREATEDATE_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED, TrashEntryModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId", new String[] { Long.class.getName() }); /** * Returns all the trash entries where companyId = ?. * * @param companyId the company ID * @return the matching trash entries */ @Override public List<TrashEntry> findByCompanyId(long companyId) { return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the trash entries where companyId = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TrashEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param companyId the company ID * @param start the lower bound of the range of trash entries * @param end the upper bound of the range of trash entries (not inclusive) * @return the range of matching trash entries */ @Override public List<TrashEntry> findByCompanyId(long companyId, int start, int end) { return findByCompanyId(companyId, start, end, null); } /** * Returns an ordered range of all the trash entries where companyId = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TrashEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param companyId the company ID * @param start the lower bound of the range of trash entries * @param end the upper bound of the range of trash entries (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching trash entries */ @Override public List<TrashEntry> findByCompanyId(long companyId, int start, int end, OrderByComparator<TrashEntry> orderByComparator) { return findByCompanyId(companyId, start, end, orderByComparator, true); } /** * Returns an ordered range of all the trash entries where companyId = ?. * * <p> * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TrashEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param companyId the company ID * @param start the lower bound of the range of trash entries * @param end the upper bound of the range of trash entries (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 trash entries */ @Override public List<TrashEntry> findByCompanyId(long companyId, int start, int end, OrderByComparator<TrashEntry> orderByComparator, boolean retrieveFromCache) { boolean pagination = true; FinderPath finderPath = null; Object[] finderArgs = null; if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) { pagination = false; finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID; finderArgs = new Object[] { companyId }; } else { finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID; finderArgs = new Object[] { companyId, start, end, orderByComparator }; } List<TrashEntry> list = null; if (retrieveFromCache) { list = (List<TrashEntry>)finderCache.getResult(finderPath, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (TrashEntry trashEntry : list) { if ((companyId != trashEntry.getCompanyId())) { list = null; break; } } } } if (list == null) { StringBundler query = null; if (orderByComparator != null) { query = new StringBundler(3 + (orderByComparator.getOrderByFields().length * 2)); } else { query = new StringBundler(3); } query.append(_SQL_SELECT_TRASHENTRY_WHERE); query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2); if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(TrashEntryModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); if (!pagination) { list = (List<TrashEntry>)QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<TrashEntry>)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 trash entry in the ordered set where companyId = ?. * * @param companyId the company ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching trash entry * @throws NoSuchEntryException if a matching trash entry could not be found */ @Override public TrashEntry findByCompanyId_First(long companyId, OrderByComparator<TrashEntry> orderByComparator) throws NoSuchEntryException { TrashEntry trashEntry = fetchByCompanyId_First(companyId, orderByComparator); if (trashEntry != null) { return trashEntry; } StringBundler msg = new StringBundler(4); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("companyId="); msg.append(companyId); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchEntryException(msg.toString()); } /** * Returns the first trash entry in the ordered set where companyId = ?. * * @param companyId the company ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching trash entry, or <code>null</code> if a matching trash entry could not be found */ @Override public TrashEntry fetchByCompanyId_First(long companyId, OrderByComparator<TrashEntry> orderByComparator) { List<TrashEntry> list = findByCompanyId(companyId, 0, 1, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the last trash entry in the ordered set where companyId = ?. * * @param companyId the company ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching trash entry * @throws NoSuchEntryException if a matching trash entry could not be found */ @Override public TrashEntry findByCompanyId_Last(long companyId, OrderByComparator<TrashEntry> orderByComparator) throws NoSuchEntryException { TrashEntry trashEntry = fetchByCompanyId_Last(companyId, orderByComparator); if (trashEntry != null) { return trashEntry; } StringBundler msg = new StringBundler(4); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("companyId="); msg.append(companyId); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchEntryException(msg.toString()); } /** * Returns the last trash entry in the ordered set where companyId = ?. * * @param companyId the company ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching trash entry, or <code>null</code> if a matching trash entry could not be found */ @Override public TrashEntry fetchByCompanyId_Last(long companyId, OrderByComparator<TrashEntry> orderByComparator) { int count = countByCompanyId(companyId); if (count == 0) { return null; } List<TrashEntry> list = findByCompanyId(companyId, count - 1, count, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the trash entries before and after the current trash entry in the ordered set where companyId = ?. * * @param entryId the primary key of the current trash entry * @param companyId the company ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next trash entry * @throws NoSuchEntryException if a trash entry with the primary key could not be found */ @Override public TrashEntry[] findByCompanyId_PrevAndNext(long entryId, long companyId, OrderByComparator<TrashEntry> orderByComparator) throws NoSuchEntryException { TrashEntry trashEntry = findByPrimaryKey(entryId); Session session = null; try { session = openSession(); TrashEntry[] array = new TrashEntryImpl[3]; array[0] = getByCompanyId_PrevAndNext(session, trashEntry, companyId, orderByComparator, true); array[1] = trashEntry; array[2] = getByCompanyId_PrevAndNext(session, trashEntry, companyId, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected TrashEntry getByCompanyId_PrevAndNext(Session session, TrashEntry trashEntry, long companyId, OrderByComparator<TrashEntry> 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_TRASHENTRY_WHERE); query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2); if (orderByComparator != null) { String[] orderByConditionFields = orderByComparator.getOrderByConditionFields(); if (orderByConditionFields.length > 0) { query.append(WHERE_AND); } for (int i = 0; i < orderByConditionFields.length; i++) { query.append(_ORDER_BY_ENTITY_ALIAS); query.append(orderByConditionFields[i]); if ((i + 1) < orderByConditionFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN_HAS_NEXT); } else { query.append(WHERE_LESSER_THAN_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(WHERE_GREATER_THAN); } else { query.append(WHERE_LESSER_THAN); } } } query.append(ORDER_BY_CLAUSE); String[] orderByFields = orderByComparator.getOrderByFields(); for (int i = 0; i < orderByFields.length; i++) { query.append(_ORDER_BY_ENTITY_ALIAS); query.append(orderByFields[i]); if ((i + 1) < orderByFields.length) { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC_HAS_NEXT); } else { query.append(ORDER_BY_DESC_HAS_NEXT); } } else { if (orderByComparator.isAscending() ^ previous) { query.append(ORDER_BY_ASC); } else { query.append(ORDER_BY_DESC); } } } } else { query.append(TrashEntryModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Query q = session.createQuery(sql); q.setFirstResult(0); q.setMaxResults(2); QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(trashEntry); for (Object value : values) { qPos.add(value); } } List<TrashEntry> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Removes all the trash entries where companyId = ? from the database. * * @param companyId the company ID */ @Override public void removeByCompanyId(long companyId) { for (TrashEntry trashEntry : findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) { remove(trashEntry); } } /** * Returns the number of trash entries where companyId = ?. * * @param companyId the company ID * @return the number of matching trash entries */ @Override public int countByCompanyId(long companyId) { FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID; Object[] finderArgs = new Object[] { companyId }; Long count = (Long)finderCache.getResult(finderPath, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(2); query.append(_SQL_COUNT_TRASHENTRY_WHERE); query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(companyId); count = (Long)q.uniqueResult(); finderCache.putResult(finderPath, finderArgs, count); } catch (Exception e) { finderCache.removeResult(finderPath, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); } private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "trashEntry.companyId = ?"; public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LTCD = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED, TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_LtCD", new String[] { Long.class.getName(), Date.class.getName(), Integer.class.getName(), Integer.class.getName(), OrderByComparator.class.getName() }); public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LTCD = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED, TrashEntryModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_LtCD", new String[] { Long.class.getName(), Date.class.getName() }); /** * Returns all the trash entries where groupId = ? and createDate < ?. * * @param groupId the group ID * @param createDate the create date * @return the matching trash entries */ @Override public List<TrashEntry> findByG_LtCD(long groupId, Date createDate) { return findByG_LtCD(groupId, createDate, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the trash entries where groupId = ? and createDate < ?. * * <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 TrashEntryModelImpl}. 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 createDate the create date * @param start the lower bound of the range of trash entries * @param end the upper bound of the range of trash entries (not inclusive) * @return the range of matching trash entries */ @Override public List<TrashEntry> findByG_LtCD(long groupId, Date createDate, int start, int end) { return findByG_LtCD(groupId, createDate, start, end, null); } /** * Returns an ordered range of all the trash entries where groupId = ? and createDate < ?. * * <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 TrashEntryModelImpl}. 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 createDate the create date * @param start the lower bound of the range of trash entries * @param end the upper bound of the range of trash entries (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching trash entries */ @Override public List<TrashEntry> findByG_LtCD(long groupId, Date createDate, int start, int end, OrderByComparator<TrashEntry> orderByComparator) { return findByG_LtCD(groupId, createDate, start, end, orderByComparator, true); } /** * Returns an ordered range of all the trash entries where groupId = ? and createDate < ?. * * <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 TrashEntryModelImpl}. 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 createDate the create date * @param start the lower bound of the range of trash entries * @param end the upper bound of the range of trash entries (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 trash entries */ @Override public List<TrashEntry> findByG_LtCD(long groupId, Date createDate, int start, int end, OrderByComparator<TrashEntry> orderByComparator, boolean retrieveFromCache) { boolean pagination = true; FinderPath finderPath = null; Object[] finderArgs = null; finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LTCD; finderArgs = new Object[] { groupId, createDate, start, end, orderByComparator }; List<TrashEntry> list = null; if (retrieveFromCache) { list = (List<TrashEntry>)finderCache.getResult(finderPath, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (TrashEntry trashEntry : list) { if ((groupId != trashEntry.getGroupId()) || (createDate.getTime() <= trashEntry.getCreateDate() .getTime())) { 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_TRASHENTRY_WHERE); query.append(_FINDER_COLUMN_G_LTCD_GROUPID_2); boolean bindCreateDate = false; if (createDate == null) { query.append(_FINDER_COLUMN_G_LTCD_CREATEDATE_1); } else { bindCreateDate = true; query.append(_FINDER_COLUMN_G_LTCD_CREATEDATE_2); } if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(TrashEntryModelImpl.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 (bindCreateDate) { qPos.add(new Timestamp(createDate.getTime())); } if (!pagination) { list = (List<TrashEntry>)QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<TrashEntry>)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 trash entry in the ordered set where groupId = ? and createDate < ?. * * @param groupId the group ID * @param createDate the create date * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching trash entry * @throws NoSuchEntryException if a matching trash entry could not be found */ @Override public TrashEntry findByG_LtCD_First(long groupId, Date createDate, OrderByComparator<TrashEntry> orderByComparator) throws NoSuchEntryException { TrashEntry trashEntry = fetchByG_LtCD_First(groupId, createDate, orderByComparator); if (trashEntry != null) { return trashEntry; } StringBundler msg = new StringBundler(6); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("groupId="); msg.append(groupId); msg.append(", createDate="); msg.append(createDate); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchEntryException(msg.toString()); } /** * Returns the first trash entry in the ordered set where groupId = ? and createDate < ?. * * @param groupId the group ID * @param createDate the create date * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching trash entry, or <code>null</code> if a matching trash entry could not be found */ @Override public TrashEntry fetchByG_LtCD_First(long groupId, Date createDate, OrderByComparator<TrashEntry> orderByComparator) { List<TrashEntry> list = findByG_LtCD(groupId, createDate, 0, 1, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the last trash entry in the ordered set where groupId = ? and createDate < ?. * * @param groupId the group ID * @param createDate the create date * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching trash entry * @throws NoSuchEntryException if a matching trash entry could not be found */ @Override public TrashEntry findByG_LtCD_Last(long groupId, Date createDate, OrderByComparator<TrashEntry> orderByComparator) throws NoSuchEntryException { TrashEntry trashEntry = fetchByG_LtCD_Last(groupId, createDate, orderByComparator); if (trashEntry != null) { return trashEntry; } StringBundler msg = new StringBundler(6); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("groupId="); msg.append(groupId); msg.append(", createDate="); msg.append(createDate); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchEntryException(msg.toString()); } /** * Returns the last trash entry in the ordered set where groupId = ? and createDate < ?. * * @param groupId the group ID * @param createDate the create date * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching trash entry, or <code>null</code> if a matching trash entry could not be found */ @Override public TrashEntry fetchByG_LtCD_Last(long groupId, Date createDate, OrderByComparator<TrashEntry> orderByComparator) { int count = countByG_LtCD(groupId, createDate); if (count == 0) { return null; } List<TrashEntry> list = findByG_LtCD(groupId, createDate, count - 1, count, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the trash entries before and after the current trash entry in the ordered set where groupId = ? and createDate < ?. * * @param entryId the primary key of the current trash entry * @param groupId the group ID * @param createDate the create date * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the previous, current, and next trash entry * @throws NoSuchEntryException if a trash entry with the primary key could not be found */ @Override public TrashEntry[] findByG_LtCD_PrevAndNext(long entryId, long groupId, Date createDate, OrderByComparator<TrashEntry> orderByComparator) throws NoSuchEntryException { TrashEntry trashEntry = findByPrimaryKey(entryId); Session session = null; try { session = openSession(); TrashEntry[] array = new TrashEntryImpl[3]; array[0] = getByG_LtCD_PrevAndNext(session, trashEntry, groupId, createDate, orderByComparator, true); array[1] = trashEntry; array[2] = getByG_LtCD_PrevAndNext(session, trashEntry, groupId, createDate, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected TrashEntry getByG_LtCD_PrevAndNext(Session session, TrashEntry trashEntry, long groupId, Date createDate, OrderByComparator<TrashEntry> 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_TRASHENTRY_WHERE); query.append(_FINDER_COLUMN_G_LTCD_GROUPID_2); boolean bindCreateDate = false; if (createDate == null) { query.append(_FINDER_COLUMN_G_LTCD_CREATEDATE_1); } else { bindCreateDate = true; query.append(_FINDER_COLUMN_G_LTCD_CREATEDATE_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(TrashEntryModelImpl.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 (bindCreateDate) { qPos.add(new Timestamp(createDate.getTime())); } if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(trashEntry); for (Object value : values) { qPos.add(value); } } List<TrashEntry> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Removes all the trash entries where groupId = ? and createDate < ? from the database. * * @param groupId the group ID * @param createDate the create date */ @Override public void removeByG_LtCD(long groupId, Date createDate) { for (TrashEntry trashEntry : findByG_LtCD(groupId, createDate, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) { remove(trashEntry); } } /** * Returns the number of trash entries where groupId = ? and createDate < ?. * * @param groupId the group ID * @param createDate the create date * @return the number of matching trash entries */ @Override public int countByG_LtCD(long groupId, Date createDate) { FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LTCD; Object[] finderArgs = new Object[] { groupId, createDate }; Long count = (Long)finderCache.getResult(finderPath, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(3); query.append(_SQL_COUNT_TRASHENTRY_WHERE); query.append(_FINDER_COLUMN_G_LTCD_GROUPID_2); boolean bindCreateDate = false; if (createDate == null) { query.append(_FINDER_COLUMN_G_LTCD_CREATEDATE_1); } else { bindCreateDate = true; query.append(_FINDER_COLUMN_G_LTCD_CREATEDATE_2); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); if (bindCreateDate) { qPos.add(new Timestamp(createDate.getTime())); } 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_LTCD_GROUPID_2 = "trashEntry.groupId = ? AND "; private static final String _FINDER_COLUMN_G_LTCD_CREATEDATE_1 = "trashEntry.createDate IS NULL"; private static final String _FINDER_COLUMN_G_LTCD_CREATEDATE_2 = "trashEntry.createDate < ?"; public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED, TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_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_G_C = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED, TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C", new String[] { Long.class.getName(), Long.class.getName() }, TrashEntryModelImpl.GROUPID_COLUMN_BITMASK | TrashEntryModelImpl.CLASSNAMEID_COLUMN_BITMASK | TrashEntryModelImpl.CREATEDATE_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED, TrashEntryModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C", new String[] { Long.class.getName(), Long.class.getName() }); /** * Returns all the trash entries where groupId = ? and classNameId = ?. * * @param groupId the group ID * @param classNameId the class name ID * @return the matching trash entries */ @Override public List<TrashEntry> findByG_C(long groupId, long classNameId) { return findByG_C(groupId, classNameId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the trash entries where groupId = ? 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 TrashEntryModelImpl}. 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 classNameId the class name ID * @param start the lower bound of the range of trash entries * @param end the upper bound of the range of trash entries (not inclusive) * @return the range of matching trash entries */ @Override public List<TrashEntry> findByG_C(long groupId, long classNameId, int start, int end) { return findByG_C(groupId, classNameId, start, end, null); } /** * Returns an ordered range of all the trash entries where groupId = ? 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 TrashEntryModelImpl}. 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 classNameId the class name ID * @param start the lower bound of the range of trash entries * @param end the upper bound of the range of trash entries (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching trash entries */ @Override public List<TrashEntry> findByG_C(long groupId, long classNameId, int start, int end, OrderByComparator<TrashEntry> orderByComparator) { return findByG_C(groupId, classNameId, start, end, orderByComparator, true); } /** * Returns an ordered range of all the trash entries where groupId = ? 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 TrashEntryModelImpl}. 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 classNameId the class name ID * @param start the lower bound of the range of trash entries * @param end the upper bound of the range of trash entries (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 trash entries */ @Override public List<TrashEntry> findByG_C(long groupId, long classNameId, int start, int end, OrderByComparator<TrashEntry> 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_C; finderArgs = new Object[] { groupId, classNameId }; } else { finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C; finderArgs = new Object[] { groupId, classNameId, start, end, orderByComparator }; } List<TrashEntry> list = null; if (retrieveFromCache) { list = (List<TrashEntry>)finderCache.getResult(finderPath, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (TrashEntry trashEntry : list) { if ((groupId != trashEntry.getGroupId()) || (classNameId != trashEntry.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_TRASHENTRY_WHERE); query.append(_FINDER_COLUMN_G_C_GROUPID_2); query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2); if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(TrashEntryModelImpl.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(classNameId); if (!pagination) { list = (List<TrashEntry>)QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<TrashEntry>)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 trash entry in the ordered set where groupId = ? and classNameId = ?. * * @param groupId the group ID * @param classNameId the class name ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching trash entry * @throws NoSuchEntryException if a matching trash entry could not be found */ @Override public TrashEntry findByG_C_First(long groupId, long classNameId, OrderByComparator<TrashEntry> orderByComparator) throws NoSuchEntryException { TrashEntry trashEntry = fetchByG_C_First(groupId, classNameId, orderByComparator); if (trashEntry != null) { return trashEntry; } StringBundler msg = new StringBundler(6); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("groupId="); msg.append(groupId); msg.append(", classNameId="); msg.append(classNameId); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchEntryException(msg.toString()); } /** * Returns the first trash entry in the ordered set where groupId = ? and classNameId = ?. * * @param groupId the group ID * @param classNameId the class name ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the first matching trash entry, or <code>null</code> if a matching trash entry could not be found */ @Override public TrashEntry fetchByG_C_First(long groupId, long classNameId, OrderByComparator<TrashEntry> orderByComparator) { List<TrashEntry> list = findByG_C(groupId, classNameId, 0, 1, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the last trash entry in the ordered set where groupId = ? and classNameId = ?. * * @param groupId the group ID * @param classNameId the class name ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching trash entry * @throws NoSuchEntryException if a matching trash entry could not be found */ @Override public TrashEntry findByG_C_Last(long groupId, long classNameId, OrderByComparator<TrashEntry> orderByComparator) throws NoSuchEntryException { TrashEntry trashEntry = fetchByG_C_Last(groupId, classNameId, orderByComparator); if (trashEntry != null) { return trashEntry; } StringBundler msg = new StringBundler(6); msg.append(_NO_SUCH_ENTITY_WITH_KEY); msg.append("groupId="); msg.append(groupId); msg.append(", classNameId="); msg.append(classNameId); msg.append(StringPool.CLOSE_CURLY_BRACE); throw new NoSuchEntryException(msg.toString()); } /** * Returns the last trash entry in the ordered set where groupId = ? and classNameId = ?. * * @param groupId the group ID * @param classNameId the class name ID * @param orderByComparator the comparator to order the set by (optionally <code>null</code>) * @return the last matching trash entry, or <code>null</code> if a matching trash entry could not be found */ @Override public TrashEntry fetchByG_C_Last(long groupId, long classNameId, OrderByComparator<TrashEntry> orderByComparator) { int count = countByG_C(groupId, classNameId); if (count == 0) { return null; } List<TrashEntry> list = findByG_C(groupId, classNameId, count - 1, count, orderByComparator); if (!list.isEmpty()) { return list.get(0); } return null; } /** * Returns the trash entries before and after the current trash entry in the ordered set where groupId = ? and classNameId = ?. * * @param entryId the primary key of the current trash entry * @param groupId the group 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 trash entry * @throws NoSuchEntryException if a trash entry with the primary key could not be found */ @Override public TrashEntry[] findByG_C_PrevAndNext(long entryId, long groupId, long classNameId, OrderByComparator<TrashEntry> orderByComparator) throws NoSuchEntryException { TrashEntry trashEntry = findByPrimaryKey(entryId); Session session = null; try { session = openSession(); TrashEntry[] array = new TrashEntryImpl[3]; array[0] = getByG_C_PrevAndNext(session, trashEntry, groupId, classNameId, orderByComparator, true); array[1] = trashEntry; array[2] = getByG_C_PrevAndNext(session, trashEntry, groupId, classNameId, orderByComparator, false); return array; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } protected TrashEntry getByG_C_PrevAndNext(Session session, TrashEntry trashEntry, long groupId, long classNameId, OrderByComparator<TrashEntry> 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_TRASHENTRY_WHERE); query.append(_FINDER_COLUMN_G_C_GROUPID_2); query.append(_FINDER_COLUMN_G_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(TrashEntryModelImpl.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(classNameId); if (orderByComparator != null) { Object[] values = orderByComparator.getOrderByConditionValues(trashEntry); for (Object value : values) { qPos.add(value); } } List<TrashEntry> list = q.list(); if (list.size() == 2) { return list.get(1); } else { return null; } } /** * Removes all the trash entries where groupId = ? and classNameId = ? from the database. * * @param groupId the group ID * @param classNameId the class name ID */ @Override public void removeByG_C(long groupId, long classNameId) { for (TrashEntry trashEntry : findByG_C(groupId, classNameId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) { remove(trashEntry); } } /** * Returns the number of trash entries where groupId = ? and classNameId = ?. * * @param groupId the group ID * @param classNameId the class name ID * @return the number of matching trash entries */ @Override public int countByG_C(long groupId, long classNameId) { FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C; Object[] finderArgs = new Object[] { groupId, classNameId }; Long count = (Long)finderCache.getResult(finderPath, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(3); query.append(_SQL_COUNT_TRASHENTRY_WHERE); query.append(_FINDER_COLUMN_G_C_GROUPID_2); query.append(_FINDER_COLUMN_G_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(groupId); 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_G_C_GROUPID_2 = "trashEntry.groupId = ? AND "; private static final String _FINDER_COLUMN_G_C_CLASSNAMEID_2 = "trashEntry.classNameId = ?"; public static final FinderPath FINDER_PATH_FETCH_BY_C_C = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED, TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByC_C", new String[] { Long.class.getName(), Long.class.getName() }, TrashEntryModelImpl.CLASSNAMEID_COLUMN_BITMASK | TrashEntryModelImpl.CLASSPK_COLUMN_BITMASK); public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED, TrashEntryModelImpl.FINDER_CACHE_ENABLED, Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C", new String[] { Long.class.getName(), Long.class.getName() }); /** * Returns the trash entry where classNameId = ? and classPK = ? or throws a {@link NoSuchEntryException} if it could not be found. * * @param classNameId the class name ID * @param classPK the class pk * @return the matching trash entry * @throws NoSuchEntryException if a matching trash entry could not be found */ @Override public TrashEntry findByC_C(long classNameId, long classPK) throws NoSuchEntryException { TrashEntry trashEntry = fetchByC_C(classNameId, classPK); if (trashEntry == null) { StringBundler msg = new StringBundler(6); msg.append(_NO_SUCH_ENTITY_WITH_KEY); 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 NoSuchEntryException(msg.toString()); } return trashEntry; } /** * Returns the trash entry where classNameId = ? and classPK = ? or returns <code>null</code> if it could not be found. Uses the finder cache. * * @param classNameId the class name ID * @param classPK the class pk * @return the matching trash entry, or <code>null</code> if a matching trash entry could not be found */ @Override public TrashEntry fetchByC_C(long classNameId, long classPK) { return fetchByC_C(classNameId, classPK, true); } /** * Returns the trash entry where classNameId = ? and classPK = ? or returns <code>null</code> if it could not be found, optionally using the finder cache. * * @param classNameId the class name ID * @param classPK the class pk * @param retrieveFromCache whether to retrieve from the finder cache * @return the matching trash entry, or <code>null</code> if a matching trash entry could not be found */ @Override public TrashEntry fetchByC_C(long classNameId, long classPK, boolean retrieveFromCache) { Object[] finderArgs = new Object[] { classNameId, classPK }; Object result = null; if (retrieveFromCache) { result = finderCache.getResult(FINDER_PATH_FETCH_BY_C_C, finderArgs, this); } if (result instanceof TrashEntry) { TrashEntry trashEntry = (TrashEntry)result; if ((classNameId != trashEntry.getClassNameId()) || (classPK != trashEntry.getClassPK())) { result = null; } } if (result == null) { StringBundler query = new StringBundler(4); query.append(_SQL_SELECT_TRASHENTRY_WHERE); query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2); query.append(_FINDER_COLUMN_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(classNameId); qPos.add(classPK); List<TrashEntry> list = q.list(); if (list.isEmpty()) { finderCache.putResult(FINDER_PATH_FETCH_BY_C_C, finderArgs, list); } else { TrashEntry trashEntry = list.get(0); result = trashEntry; cacheResult(trashEntry); if ((trashEntry.getClassNameId() != classNameId) || (trashEntry.getClassPK() != classPK)) { finderCache.putResult(FINDER_PATH_FETCH_BY_C_C, finderArgs, trashEntry); } } } catch (Exception e) { finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C, finderArgs); throw processException(e); } finally { closeSession(session); } } if (result instanceof List<?>) { return null; } else { return (TrashEntry)result; } } /** * Removes the trash entry where classNameId = ? and classPK = ? from the database. * * @param classNameId the class name ID * @param classPK the class pk * @return the trash entry that was removed */ @Override public TrashEntry removeByC_C(long classNameId, long classPK) throws NoSuchEntryException { TrashEntry trashEntry = findByC_C(classNameId, classPK); return remove(trashEntry); } /** * Returns the number of trash entries where classNameId = ? and classPK = ?. * * @param classNameId the class name ID * @param classPK the class pk * @return the number of matching trash entries */ @Override public int countByC_C(long classNameId, long classPK) { FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C; Object[] finderArgs = new Object[] { classNameId, classPK }; Long count = (Long)finderCache.getResult(finderPath, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(3); query.append(_SQL_COUNT_TRASHENTRY_WHERE); query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2); query.append(_FINDER_COLUMN_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(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_CLASSNAMEID_2 = "trashEntry.classNameId = ? AND "; private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "trashEntry.classPK = ?"; public TrashEntryPersistenceImpl() { setModelClass(TrashEntry.class); } /** * Caches the trash entry in the entity cache if it is enabled. * * @param trashEntry the trash entry */ @Override public void cacheResult(TrashEntry trashEntry) { entityCache.putResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED, TrashEntryImpl.class, trashEntry.getPrimaryKey(), trashEntry); finderCache.putResult(FINDER_PATH_FETCH_BY_C_C, new Object[] { trashEntry.getClassNameId(), trashEntry.getClassPK() }, trashEntry); trashEntry.resetOriginalValues(); } /** * Caches the trash entries in the entity cache if it is enabled. * * @param trashEntries the trash entries */ @Override public void cacheResult(List<TrashEntry> trashEntries) { for (TrashEntry trashEntry : trashEntries) { if (entityCache.getResult( TrashEntryModelImpl.ENTITY_CACHE_ENABLED, TrashEntryImpl.class, trashEntry.getPrimaryKey()) == null) { cacheResult(trashEntry); } else { trashEntry.resetOriginalValues(); } } } /** * Clears the cache for all trash entries. * * <p> * The {@link EntityCache} and {@link FinderCache} are both cleared by this method. * </p> */ @Override public void clearCache() { entityCache.clearCache(TrashEntryImpl.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 trash entry. * * <p> * The {@link EntityCache} and {@link FinderCache} are both cleared by this method. * </p> */ @Override public void clearCache(TrashEntry trashEntry) { entityCache.removeResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED, TrashEntryImpl.class, trashEntry.getPrimaryKey()); finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); clearUniqueFindersCache((TrashEntryModelImpl)trashEntry, true); } @Override public void clearCache(List<TrashEntry> trashEntries) { finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); for (TrashEntry trashEntry : trashEntries) { entityCache.removeResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED, TrashEntryImpl.class, trashEntry.getPrimaryKey()); clearUniqueFindersCache((TrashEntryModelImpl)trashEntry, true); } } protected void cacheUniqueFindersCache( TrashEntryModelImpl trashEntryModelImpl) { Object[] args = new Object[] { trashEntryModelImpl.getClassNameId(), trashEntryModelImpl.getClassPK() }; finderCache.putResult(FINDER_PATH_COUNT_BY_C_C, args, Long.valueOf(1), false); finderCache.putResult(FINDER_PATH_FETCH_BY_C_C, args, trashEntryModelImpl, false); } protected void clearUniqueFindersCache( TrashEntryModelImpl trashEntryModelImpl, boolean clearCurrent) { if (clearCurrent) { Object[] args = new Object[] { trashEntryModelImpl.getClassNameId(), trashEntryModelImpl.getClassPK() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args); finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C, args); } if ((trashEntryModelImpl.getColumnBitmask() & FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) { Object[] args = new Object[] { trashEntryModelImpl.getOriginalClassNameId(), trashEntryModelImpl.getOriginalClassPK() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args); finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C, args); } } /** * Creates a new trash entry with the primary key. Does not add the trash entry to the database. * * @param entryId the primary key for the new trash entry * @return the new trash entry */ @Override public TrashEntry create(long entryId) { TrashEntry trashEntry = new TrashEntryImpl(); trashEntry.setNew(true); trashEntry.setPrimaryKey(entryId); trashEntry.setCompanyId(companyProvider.getCompanyId()); return trashEntry; } /** * Removes the trash entry with the primary key from the database. Also notifies the appropriate model listeners. * * @param entryId the primary key of the trash entry * @return the trash entry that was removed * @throws NoSuchEntryException if a trash entry with the primary key could not be found */ @Override public TrashEntry remove(long entryId) throws NoSuchEntryException { return remove((Serializable)entryId); } /** * Removes the trash entry with the primary key from the database. Also notifies the appropriate model listeners. * * @param primaryKey the primary key of the trash entry * @return the trash entry that was removed * @throws NoSuchEntryException if a trash entry with the primary key could not be found */ @Override public TrashEntry remove(Serializable primaryKey) throws NoSuchEntryException { Session session = null; try { session = openSession(); TrashEntry trashEntry = (TrashEntry)session.get(TrashEntryImpl.class, primaryKey); if (trashEntry == null) { if (_log.isDebugEnabled()) { _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey); } throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey); } return remove(trashEntry); } catch (NoSuchEntryException nsee) { throw nsee; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } } @Override protected TrashEntry removeImpl(TrashEntry trashEntry) { trashEntry = toUnwrappedModel(trashEntry); Session session = null; try { session = openSession(); if (!session.contains(trashEntry)) { trashEntry = (TrashEntry)session.get(TrashEntryImpl.class, trashEntry.getPrimaryKeyObj()); } if (trashEntry != null) { session.delete(trashEntry); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } if (trashEntry != null) { clearCache(trashEntry); } return trashEntry; } @Override public TrashEntry updateImpl(TrashEntry trashEntry) { trashEntry = toUnwrappedModel(trashEntry); boolean isNew = trashEntry.isNew(); TrashEntryModelImpl trashEntryModelImpl = (TrashEntryModelImpl)trashEntry; Session session = null; try { session = openSession(); if (trashEntry.isNew()) { session.save(trashEntry); trashEntry.setNew(false); } else { trashEntry = (TrashEntry)session.merge(trashEntry); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); if (!TrashEntryModelImpl.COLUMN_BITMASK_ENABLED) { finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); } else if (isNew) { Object[] args = new Object[] { trashEntryModelImpl.getGroupId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID, args); args = new Object[] { trashEntryModelImpl.getCompanyId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID, args); args = new Object[] { trashEntryModelImpl.getGroupId(), trashEntryModelImpl.getClassNameId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C, args); finderCache.removeResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL, FINDER_ARGS_EMPTY); } else { if ((trashEntryModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) { Object[] args = new Object[] { trashEntryModelImpl.getOriginalGroupId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID, args); args = new Object[] { trashEntryModelImpl.getGroupId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID, args); } if ((trashEntryModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) { Object[] args = new Object[] { trashEntryModelImpl.getOriginalCompanyId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID, args); args = new Object[] { trashEntryModelImpl.getCompanyId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID, args); } if ((trashEntryModelImpl.getColumnBitmask() & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) { Object[] args = new Object[] { trashEntryModelImpl.getOriginalGroupId(), trashEntryModelImpl.getOriginalClassNameId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C, args); args = new Object[] { trashEntryModelImpl.getGroupId(), trashEntryModelImpl.getClassNameId() }; finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C, args); finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C, args); } } entityCache.putResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED, TrashEntryImpl.class, trashEntry.getPrimaryKey(), trashEntry, false); clearUniqueFindersCache(trashEntryModelImpl, false); cacheUniqueFindersCache(trashEntryModelImpl); trashEntry.resetOriginalValues(); return trashEntry; } protected TrashEntry toUnwrappedModel(TrashEntry trashEntry) { if (trashEntry instanceof TrashEntryImpl) { return trashEntry; } TrashEntryImpl trashEntryImpl = new TrashEntryImpl(); trashEntryImpl.setNew(trashEntry.isNew()); trashEntryImpl.setPrimaryKey(trashEntry.getPrimaryKey()); trashEntryImpl.setEntryId(trashEntry.getEntryId()); trashEntryImpl.setGroupId(trashEntry.getGroupId()); trashEntryImpl.setCompanyId(trashEntry.getCompanyId()); trashEntryImpl.setUserId(trashEntry.getUserId()); trashEntryImpl.setUserName(trashEntry.getUserName()); trashEntryImpl.setCreateDate(trashEntry.getCreateDate()); trashEntryImpl.setClassNameId(trashEntry.getClassNameId()); trashEntryImpl.setClassPK(trashEntry.getClassPK()); trashEntryImpl.setSystemEventSetKey(trashEntry.getSystemEventSetKey()); trashEntryImpl.setTypeSettings(trashEntry.getTypeSettings()); trashEntryImpl.setStatus(trashEntry.getStatus()); return trashEntryImpl; } /** * Returns the trash entry 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 trash entry * @return the trash entry * @throws NoSuchEntryException if a trash entry with the primary key could not be found */ @Override public TrashEntry findByPrimaryKey(Serializable primaryKey) throws NoSuchEntryException { TrashEntry trashEntry = fetchByPrimaryKey(primaryKey); if (trashEntry == null) { if (_log.isDebugEnabled()) { _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey); } throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey); } return trashEntry; } /** * Returns the trash entry with the primary key or throws a {@link NoSuchEntryException} if it could not be found. * * @param entryId the primary key of the trash entry * @return the trash entry * @throws NoSuchEntryException if a trash entry with the primary key could not be found */ @Override public TrashEntry findByPrimaryKey(long entryId) throws NoSuchEntryException { return findByPrimaryKey((Serializable)entryId); } /** * Returns the trash entry with the primary key or returns <code>null</code> if it could not be found. * * @param primaryKey the primary key of the trash entry * @return the trash entry, or <code>null</code> if a trash entry with the primary key could not be found */ @Override public TrashEntry fetchByPrimaryKey(Serializable primaryKey) { Serializable serializable = entityCache.getResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED, TrashEntryImpl.class, primaryKey); if (serializable == nullModel) { return null; } TrashEntry trashEntry = (TrashEntry)serializable; if (trashEntry == null) { Session session = null; try { session = openSession(); trashEntry = (TrashEntry)session.get(TrashEntryImpl.class, primaryKey); if (trashEntry != null) { cacheResult(trashEntry); } else { entityCache.putResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED, TrashEntryImpl.class, primaryKey, nullModel); } } catch (Exception e) { entityCache.removeResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED, TrashEntryImpl.class, primaryKey); throw processException(e); } finally { closeSession(session); } } return trashEntry; } /** * Returns the trash entry with the primary key or returns <code>null</code> if it could not be found. * * @param entryId the primary key of the trash entry * @return the trash entry, or <code>null</code> if a trash entry with the primary key could not be found */ @Override public TrashEntry fetchByPrimaryKey(long entryId) { return fetchByPrimaryKey((Serializable)entryId); } @Override public Map<Serializable, TrashEntry> fetchByPrimaryKeys( Set<Serializable> primaryKeys) { if (primaryKeys.isEmpty()) { return Collections.emptyMap(); } Map<Serializable, TrashEntry> map = new HashMap<Serializable, TrashEntry>(); if (primaryKeys.size() == 1) { Iterator<Serializable> iterator = primaryKeys.iterator(); Serializable primaryKey = iterator.next(); TrashEntry trashEntry = fetchByPrimaryKey(primaryKey); if (trashEntry != null) { map.put(primaryKey, trashEntry); } return map; } Set<Serializable> uncachedPrimaryKeys = null; for (Serializable primaryKey : primaryKeys) { Serializable serializable = entityCache.getResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED, TrashEntryImpl.class, primaryKey); if (serializable != nullModel) { if (serializable == null) { if (uncachedPrimaryKeys == null) { uncachedPrimaryKeys = new HashSet<Serializable>(); } uncachedPrimaryKeys.add(primaryKey); } else { map.put(primaryKey, (TrashEntry)serializable); } } } if (uncachedPrimaryKeys == null) { return map; } StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1); query.append(_SQL_SELECT_TRASHENTRY_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 (TrashEntry trashEntry : (List<TrashEntry>)q.list()) { map.put(trashEntry.getPrimaryKeyObj(), trashEntry); cacheResult(trashEntry); uncachedPrimaryKeys.remove(trashEntry.getPrimaryKeyObj()); } for (Serializable primaryKey : uncachedPrimaryKeys) { entityCache.putResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED, TrashEntryImpl.class, primaryKey, nullModel); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } return map; } /** * Returns all the trash entries. * * @return the trash entries */ @Override public List<TrashEntry> findAll() { return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); } /** * Returns a range of all the trash entries. * * <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 TrashEntryModelImpl}. 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 trash entries * @param end the upper bound of the range of trash entries (not inclusive) * @return the range of trash entries */ @Override public List<TrashEntry> findAll(int start, int end) { return findAll(start, end, null); } /** * Returns an ordered range of all the trash entries. * * <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 TrashEntryModelImpl}. 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 trash entries * @param end the upper bound of the range of trash entries (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of trash entries */ @Override public List<TrashEntry> findAll(int start, int end, OrderByComparator<TrashEntry> orderByComparator) { return findAll(start, end, orderByComparator, true); } /** * Returns an ordered range of all the trash entries. * * <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 TrashEntryModelImpl}. 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 trash entries * @param end the upper bound of the range of trash entries (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 trash entries */ @Override public List<TrashEntry> findAll(int start, int end, OrderByComparator<TrashEntry> 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<TrashEntry> list = null; if (retrieveFromCache) { list = (List<TrashEntry>)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_TRASHENTRY); appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); sql = query.toString(); } else { sql = _SQL_SELECT_TRASHENTRY; if (pagination) { sql = sql.concat(TrashEntryModelImpl.ORDER_BY_JPQL); } } Session session = null; try { session = openSession(); Query q = session.createQuery(sql); if (!pagination) { list = (List<TrashEntry>)QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<TrashEntry>)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 trash entries from the database. * */ @Override public void removeAll() { for (TrashEntry trashEntry : findAll()) { remove(trashEntry); } } /** * Returns the number of trash entries. * * @return the number of trash entries */ @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_TRASHENTRY); 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 TrashEntryModelImpl.TABLE_COLUMNS_MAP; } /** * Initializes the trash entry persistence. */ public void afterPropertiesSet() { } public void destroy() { entityCache.removeCache(TrashEntryImpl.class.getName()); finderCache.removeCache(FINDER_CLASS_NAME_ENTITY); finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION); finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION); } @BeanReference(type = CompanyProviderWrapper.class) protected CompanyProvider companyProvider; protected EntityCache entityCache = EntityCacheUtil.getEntityCache(); protected FinderCache finderCache = FinderCacheUtil.getFinderCache(); private static final String _SQL_SELECT_TRASHENTRY = "SELECT trashEntry FROM TrashEntry trashEntry"; private static final String _SQL_SELECT_TRASHENTRY_WHERE_PKS_IN = "SELECT trashEntry FROM TrashEntry trashEntry WHERE entryId IN ("; private static final String _SQL_SELECT_TRASHENTRY_WHERE = "SELECT trashEntry FROM TrashEntry trashEntry WHERE "; private static final String _SQL_COUNT_TRASHENTRY = "SELECT COUNT(trashEntry) FROM TrashEntry trashEntry"; private static final String _SQL_COUNT_TRASHENTRY_WHERE = "SELECT COUNT(trashEntry) FROM TrashEntry trashEntry WHERE "; private static final String _ORDER_BY_ENTITY_ALIAS = "trashEntry."; private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No TrashEntry exists with the primary key "; private static final String _NO_SUCH_ENTITY_WITH_KEY = "No TrashEntry exists with the key {"; private static final Log _log = LogFactoryUtil.getLog(TrashEntryPersistenceImpl.class); }