001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.trash.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.dao.orm.EntityCache;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCache;
023    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024    import com.liferay.portal.kernel.dao.orm.FinderPath;
025    import com.liferay.portal.kernel.dao.orm.Query;
026    import com.liferay.portal.kernel.dao.orm.QueryPos;
027    import com.liferay.portal.kernel.dao.orm.QueryUtil;
028    import com.liferay.portal.kernel.dao.orm.Session;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.OrderByComparator;
032    import com.liferay.portal.kernel.util.StringBundler;
033    import com.liferay.portal.kernel.util.StringPool;
034    import com.liferay.portal.model.CacheModel;
035    import com.liferay.portal.service.persistence.CompanyProvider;
036    import com.liferay.portal.service.persistence.CompanyProviderWrapper;
037    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
038    
039    import com.liferay.portlet.trash.exception.NoSuchEntryException;
040    import com.liferay.portlet.trash.model.TrashEntry;
041    import com.liferay.portlet.trash.model.impl.TrashEntryImpl;
042    import com.liferay.portlet.trash.model.impl.TrashEntryModelImpl;
043    import com.liferay.portlet.trash.service.persistence.TrashEntryPersistence;
044    
045    import java.io.Serializable;
046    
047    import java.sql.Timestamp;
048    
049    import java.util.Collections;
050    import java.util.Date;
051    import java.util.HashMap;
052    import java.util.HashSet;
053    import java.util.Iterator;
054    import java.util.List;
055    import java.util.Map;
056    import java.util.Set;
057    
058    /**
059     * The persistence implementation for the trash entry service.
060     *
061     * <p>
062     * Caching information and settings can be found in <code>portal.properties</code>
063     * </p>
064     *
065     * @author Brian Wing Shun Chan
066     * @see TrashEntryPersistence
067     * @see com.liferay.portlet.trash.service.persistence.TrashEntryUtil
068     * @generated
069     */
070    @ProviderType
071    public class TrashEntryPersistenceImpl extends BasePersistenceImpl<TrashEntry>
072            implements TrashEntryPersistence {
073            /*
074             * NOTE FOR DEVELOPERS:
075             *
076             * 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.
077             */
078            public static final String FINDER_CLASS_NAME_ENTITY = TrashEntryImpl.class.getName();
079            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
080                    ".List1";
081            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
082                    ".List2";
083            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
084                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
085                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
086            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
087                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
088                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
089            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
090                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
091                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
092            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
093                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
094                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
095                            new String[] {
096                                    Long.class.getName(),
097                                    
098                            Integer.class.getName(), Integer.class.getName(),
099                                    OrderByComparator.class.getName()
100                            });
101            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
102                    new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
103                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
104                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
105                            new String[] { Long.class.getName() },
106                            TrashEntryModelImpl.GROUPID_COLUMN_BITMASK |
107                            TrashEntryModelImpl.CREATEDATE_COLUMN_BITMASK);
108            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
109                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
110                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
111                            new String[] { Long.class.getName() });
112    
113            /**
114             * Returns all the trash entries where groupId = &#63;.
115             *
116             * @param groupId the group ID
117             * @return the matching trash entries
118             */
119            @Override
120            public List<TrashEntry> findByGroupId(long groupId) {
121                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
122            }
123    
124            /**
125             * Returns a range of all the trash entries where groupId = &#63;.
126             *
127             * <p>
128             * 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.
129             * </p>
130             *
131             * @param groupId the group ID
132             * @param start the lower bound of the range of trash entries
133             * @param end the upper bound of the range of trash entries (not inclusive)
134             * @return the range of matching trash entries
135             */
136            @Override
137            public List<TrashEntry> findByGroupId(long groupId, int start, int end) {
138                    return findByGroupId(groupId, start, end, null);
139            }
140    
141            /**
142             * Returns an ordered range of all the trash entries where groupId = &#63;.
143             *
144             * <p>
145             * 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.
146             * </p>
147             *
148             * @param groupId the group ID
149             * @param start the lower bound of the range of trash entries
150             * @param end the upper bound of the range of trash entries (not inclusive)
151             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
152             * @return the ordered range of matching trash entries
153             */
154            @Override
155            public List<TrashEntry> findByGroupId(long groupId, int start, int end,
156                    OrderByComparator<TrashEntry> orderByComparator) {
157                    return findByGroupId(groupId, start, end, orderByComparator, true);
158            }
159    
160            /**
161             * Returns an ordered range of all the trash entries where groupId = &#63;.
162             *
163             * <p>
164             * 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.
165             * </p>
166             *
167             * @param groupId the group ID
168             * @param start the lower bound of the range of trash entries
169             * @param end the upper bound of the range of trash entries (not inclusive)
170             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
171             * @param retrieveFromCache whether to retrieve from the finder cache
172             * @return the ordered range of matching trash entries
173             */
174            @Override
175            public List<TrashEntry> findByGroupId(long groupId, int start, int end,
176                    OrderByComparator<TrashEntry> orderByComparator,
177                    boolean retrieveFromCache) {
178                    boolean pagination = true;
179                    FinderPath finderPath = null;
180                    Object[] finderArgs = null;
181    
182                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
183                                    (orderByComparator == null)) {
184                            pagination = false;
185                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
186                            finderArgs = new Object[] { groupId };
187                    }
188                    else {
189                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
190                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
191                    }
192    
193                    List<TrashEntry> list = null;
194    
195                    if (retrieveFromCache) {
196                            list = (List<TrashEntry>)finderCache.getResult(finderPath,
197                                            finderArgs, this);
198    
199                            if ((list != null) && !list.isEmpty()) {
200                                    for (TrashEntry trashEntry : list) {
201                                            if ((groupId != trashEntry.getGroupId())) {
202                                                    list = null;
203    
204                                                    break;
205                                            }
206                                    }
207                            }
208                    }
209    
210                    if (list == null) {
211                            StringBundler query = null;
212    
213                            if (orderByComparator != null) {
214                                    query = new StringBundler(3 +
215                                                    (orderByComparator.getOrderByFields().length * 3));
216                            }
217                            else {
218                                    query = new StringBundler(3);
219                            }
220    
221                            query.append(_SQL_SELECT_TRASHENTRY_WHERE);
222    
223                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
224    
225                            if (orderByComparator != null) {
226                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
227                                            orderByComparator);
228                            }
229                            else
230                             if (pagination) {
231                                    query.append(TrashEntryModelImpl.ORDER_BY_JPQL);
232                            }
233    
234                            String sql = query.toString();
235    
236                            Session session = null;
237    
238                            try {
239                                    session = openSession();
240    
241                                    Query q = session.createQuery(sql);
242    
243                                    QueryPos qPos = QueryPos.getInstance(q);
244    
245                                    qPos.add(groupId);
246    
247                                    if (!pagination) {
248                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
249                                                            start, end, false);
250    
251                                            Collections.sort(list);
252    
253                                            list = Collections.unmodifiableList(list);
254                                    }
255                                    else {
256                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
257                                                            start, end);
258                                    }
259    
260                                    cacheResult(list);
261    
262                                    finderCache.putResult(finderPath, finderArgs, list);
263                            }
264                            catch (Exception e) {
265                                    finderCache.removeResult(finderPath, finderArgs);
266    
267                                    throw processException(e);
268                            }
269                            finally {
270                                    closeSession(session);
271                            }
272                    }
273    
274                    return list;
275            }
276    
277            /**
278             * Returns the first trash entry in the ordered set where groupId = &#63;.
279             *
280             * @param groupId the group ID
281             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
282             * @return the first matching trash entry
283             * @throws NoSuchEntryException if a matching trash entry could not be found
284             */
285            @Override
286            public TrashEntry findByGroupId_First(long groupId,
287                    OrderByComparator<TrashEntry> orderByComparator)
288                    throws NoSuchEntryException {
289                    TrashEntry trashEntry = fetchByGroupId_First(groupId, orderByComparator);
290    
291                    if (trashEntry != null) {
292                            return trashEntry;
293                    }
294    
295                    StringBundler msg = new StringBundler(4);
296    
297                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
298    
299                    msg.append("groupId=");
300                    msg.append(groupId);
301    
302                    msg.append(StringPool.CLOSE_CURLY_BRACE);
303    
304                    throw new NoSuchEntryException(msg.toString());
305            }
306    
307            /**
308             * Returns the first trash entry in the ordered set where groupId = &#63;.
309             *
310             * @param groupId the group ID
311             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
312             * @return the first matching trash entry, or <code>null</code> if a matching trash entry could not be found
313             */
314            @Override
315            public TrashEntry fetchByGroupId_First(long groupId,
316                    OrderByComparator<TrashEntry> orderByComparator) {
317                    List<TrashEntry> list = findByGroupId(groupId, 0, 1, orderByComparator);
318    
319                    if (!list.isEmpty()) {
320                            return list.get(0);
321                    }
322    
323                    return null;
324            }
325    
326            /**
327             * Returns the last trash entry in the ordered set where groupId = &#63;.
328             *
329             * @param groupId the group ID
330             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
331             * @return the last matching trash entry
332             * @throws NoSuchEntryException if a matching trash entry could not be found
333             */
334            @Override
335            public TrashEntry findByGroupId_Last(long groupId,
336                    OrderByComparator<TrashEntry> orderByComparator)
337                    throws NoSuchEntryException {
338                    TrashEntry trashEntry = fetchByGroupId_Last(groupId, orderByComparator);
339    
340                    if (trashEntry != null) {
341                            return trashEntry;
342                    }
343    
344                    StringBundler msg = new StringBundler(4);
345    
346                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
347    
348                    msg.append("groupId=");
349                    msg.append(groupId);
350    
351                    msg.append(StringPool.CLOSE_CURLY_BRACE);
352    
353                    throw new NoSuchEntryException(msg.toString());
354            }
355    
356            /**
357             * Returns the last trash entry in the ordered set where groupId = &#63;.
358             *
359             * @param groupId the group ID
360             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
361             * @return the last matching trash entry, or <code>null</code> if a matching trash entry could not be found
362             */
363            @Override
364            public TrashEntry fetchByGroupId_Last(long groupId,
365                    OrderByComparator<TrashEntry> orderByComparator) {
366                    int count = countByGroupId(groupId);
367    
368                    if (count == 0) {
369                            return null;
370                    }
371    
372                    List<TrashEntry> list = findByGroupId(groupId, count - 1, count,
373                                    orderByComparator);
374    
375                    if (!list.isEmpty()) {
376                            return list.get(0);
377                    }
378    
379                    return null;
380            }
381    
382            /**
383             * Returns the trash entries before and after the current trash entry in the ordered set where groupId = &#63;.
384             *
385             * @param entryId the primary key of the current trash entry
386             * @param groupId the group ID
387             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
388             * @return the previous, current, and next trash entry
389             * @throws NoSuchEntryException if a trash entry with the primary key could not be found
390             */
391            @Override
392            public TrashEntry[] findByGroupId_PrevAndNext(long entryId, long groupId,
393                    OrderByComparator<TrashEntry> orderByComparator)
394                    throws NoSuchEntryException {
395                    TrashEntry trashEntry = findByPrimaryKey(entryId);
396    
397                    Session session = null;
398    
399                    try {
400                            session = openSession();
401    
402                            TrashEntry[] array = new TrashEntryImpl[3];
403    
404                            array[0] = getByGroupId_PrevAndNext(session, trashEntry, groupId,
405                                            orderByComparator, true);
406    
407                            array[1] = trashEntry;
408    
409                            array[2] = getByGroupId_PrevAndNext(session, trashEntry, groupId,
410                                            orderByComparator, false);
411    
412                            return array;
413                    }
414                    catch (Exception e) {
415                            throw processException(e);
416                    }
417                    finally {
418                            closeSession(session);
419                    }
420            }
421    
422            protected TrashEntry getByGroupId_PrevAndNext(Session session,
423                    TrashEntry trashEntry, long groupId,
424                    OrderByComparator<TrashEntry> orderByComparator, boolean previous) {
425                    StringBundler query = null;
426    
427                    if (orderByComparator != null) {
428                            query = new StringBundler(6 +
429                                            (orderByComparator.getOrderByFields().length * 6));
430                    }
431                    else {
432                            query = new StringBundler(3);
433                    }
434    
435                    query.append(_SQL_SELECT_TRASHENTRY_WHERE);
436    
437                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
438    
439                    if (orderByComparator != null) {
440                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
441    
442                            if (orderByConditionFields.length > 0) {
443                                    query.append(WHERE_AND);
444                            }
445    
446                            for (int i = 0; i < orderByConditionFields.length; i++) {
447                                    query.append(_ORDER_BY_ENTITY_ALIAS);
448                                    query.append(orderByConditionFields[i]);
449    
450                                    if ((i + 1) < orderByConditionFields.length) {
451                                            if (orderByComparator.isAscending() ^ previous) {
452                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
453                                            }
454                                            else {
455                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
456                                            }
457                                    }
458                                    else {
459                                            if (orderByComparator.isAscending() ^ previous) {
460                                                    query.append(WHERE_GREATER_THAN);
461                                            }
462                                            else {
463                                                    query.append(WHERE_LESSER_THAN);
464                                            }
465                                    }
466                            }
467    
468                            query.append(ORDER_BY_CLAUSE);
469    
470                            String[] orderByFields = orderByComparator.getOrderByFields();
471    
472                            for (int i = 0; i < orderByFields.length; i++) {
473                                    query.append(_ORDER_BY_ENTITY_ALIAS);
474                                    query.append(orderByFields[i]);
475    
476                                    if ((i + 1) < orderByFields.length) {
477                                            if (orderByComparator.isAscending() ^ previous) {
478                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
479                                            }
480                                            else {
481                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
482                                            }
483                                    }
484                                    else {
485                                            if (orderByComparator.isAscending() ^ previous) {
486                                                    query.append(ORDER_BY_ASC);
487                                            }
488                                            else {
489                                                    query.append(ORDER_BY_DESC);
490                                            }
491                                    }
492                            }
493                    }
494                    else {
495                            query.append(TrashEntryModelImpl.ORDER_BY_JPQL);
496                    }
497    
498                    String sql = query.toString();
499    
500                    Query q = session.createQuery(sql);
501    
502                    q.setFirstResult(0);
503                    q.setMaxResults(2);
504    
505                    QueryPos qPos = QueryPos.getInstance(q);
506    
507                    qPos.add(groupId);
508    
509                    if (orderByComparator != null) {
510                            Object[] values = orderByComparator.getOrderByConditionValues(trashEntry);
511    
512                            for (Object value : values) {
513                                    qPos.add(value);
514                            }
515                    }
516    
517                    List<TrashEntry> list = q.list();
518    
519                    if (list.size() == 2) {
520                            return list.get(1);
521                    }
522                    else {
523                            return null;
524                    }
525            }
526    
527            /**
528             * Removes all the trash entries where groupId = &#63; from the database.
529             *
530             * @param groupId the group ID
531             */
532            @Override
533            public void removeByGroupId(long groupId) {
534                    for (TrashEntry trashEntry : findByGroupId(groupId, QueryUtil.ALL_POS,
535                                    QueryUtil.ALL_POS, null)) {
536                            remove(trashEntry);
537                    }
538            }
539    
540            /**
541             * Returns the number of trash entries where groupId = &#63;.
542             *
543             * @param groupId the group ID
544             * @return the number of matching trash entries
545             */
546            @Override
547            public int countByGroupId(long groupId) {
548                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
549    
550                    Object[] finderArgs = new Object[] { groupId };
551    
552                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
553    
554                    if (count == null) {
555                            StringBundler query = new StringBundler(2);
556    
557                            query.append(_SQL_COUNT_TRASHENTRY_WHERE);
558    
559                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
560    
561                            String sql = query.toString();
562    
563                            Session session = null;
564    
565                            try {
566                                    session = openSession();
567    
568                                    Query q = session.createQuery(sql);
569    
570                                    QueryPos qPos = QueryPos.getInstance(q);
571    
572                                    qPos.add(groupId);
573    
574                                    count = (Long)q.uniqueResult();
575    
576                                    finderCache.putResult(finderPath, finderArgs, count);
577                            }
578                            catch (Exception e) {
579                                    finderCache.removeResult(finderPath, finderArgs);
580    
581                                    throw processException(e);
582                            }
583                            finally {
584                                    closeSession(session);
585                            }
586                    }
587    
588                    return count.intValue();
589            }
590    
591            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "trashEntry.groupId = ?";
592            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
593                    new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
594                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
595                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
596                            new String[] {
597                                    Long.class.getName(),
598                                    
599                            Integer.class.getName(), Integer.class.getName(),
600                                    OrderByComparator.class.getName()
601                            });
602            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
603                    new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
604                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
605                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
606                            new String[] { Long.class.getName() },
607                            TrashEntryModelImpl.COMPANYID_COLUMN_BITMASK |
608                            TrashEntryModelImpl.CREATEDATE_COLUMN_BITMASK);
609            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
610                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
611                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
612                            new String[] { Long.class.getName() });
613    
614            /**
615             * Returns all the trash entries where companyId = &#63;.
616             *
617             * @param companyId the company ID
618             * @return the matching trash entries
619             */
620            @Override
621            public List<TrashEntry> findByCompanyId(long companyId) {
622                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
623                            null);
624            }
625    
626            /**
627             * Returns a range of all the trash entries where companyId = &#63;.
628             *
629             * <p>
630             * 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.
631             * </p>
632             *
633             * @param companyId the company ID
634             * @param start the lower bound of the range of trash entries
635             * @param end the upper bound of the range of trash entries (not inclusive)
636             * @return the range of matching trash entries
637             */
638            @Override
639            public List<TrashEntry> findByCompanyId(long companyId, int start, int end) {
640                    return findByCompanyId(companyId, start, end, null);
641            }
642    
643            /**
644             * Returns an ordered range of all the trash entries where companyId = &#63;.
645             *
646             * <p>
647             * 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.
648             * </p>
649             *
650             * @param companyId the company ID
651             * @param start the lower bound of the range of trash entries
652             * @param end the upper bound of the range of trash entries (not inclusive)
653             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
654             * @return the ordered range of matching trash entries
655             */
656            @Override
657            public List<TrashEntry> findByCompanyId(long companyId, int start, int end,
658                    OrderByComparator<TrashEntry> orderByComparator) {
659                    return findByCompanyId(companyId, start, end, orderByComparator, true);
660            }
661    
662            /**
663             * Returns an ordered range of all the trash entries where companyId = &#63;.
664             *
665             * <p>
666             * 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.
667             * </p>
668             *
669             * @param companyId the company ID
670             * @param start the lower bound of the range of trash entries
671             * @param end the upper bound of the range of trash entries (not inclusive)
672             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
673             * @param retrieveFromCache whether to retrieve from the finder cache
674             * @return the ordered range of matching trash entries
675             */
676            @Override
677            public List<TrashEntry> findByCompanyId(long companyId, int start, int end,
678                    OrderByComparator<TrashEntry> orderByComparator,
679                    boolean retrieveFromCache) {
680                    boolean pagination = true;
681                    FinderPath finderPath = null;
682                    Object[] finderArgs = null;
683    
684                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
685                                    (orderByComparator == null)) {
686                            pagination = false;
687                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
688                            finderArgs = new Object[] { companyId };
689                    }
690                    else {
691                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
692                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
693                    }
694    
695                    List<TrashEntry> list = null;
696    
697                    if (retrieveFromCache) {
698                            list = (List<TrashEntry>)finderCache.getResult(finderPath,
699                                            finderArgs, this);
700    
701                            if ((list != null) && !list.isEmpty()) {
702                                    for (TrashEntry trashEntry : list) {
703                                            if ((companyId != trashEntry.getCompanyId())) {
704                                                    list = null;
705    
706                                                    break;
707                                            }
708                                    }
709                            }
710                    }
711    
712                    if (list == null) {
713                            StringBundler query = null;
714    
715                            if (orderByComparator != null) {
716                                    query = new StringBundler(3 +
717                                                    (orderByComparator.getOrderByFields().length * 3));
718                            }
719                            else {
720                                    query = new StringBundler(3);
721                            }
722    
723                            query.append(_SQL_SELECT_TRASHENTRY_WHERE);
724    
725                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
726    
727                            if (orderByComparator != null) {
728                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
729                                            orderByComparator);
730                            }
731                            else
732                             if (pagination) {
733                                    query.append(TrashEntryModelImpl.ORDER_BY_JPQL);
734                            }
735    
736                            String sql = query.toString();
737    
738                            Session session = null;
739    
740                            try {
741                                    session = openSession();
742    
743                                    Query q = session.createQuery(sql);
744    
745                                    QueryPos qPos = QueryPos.getInstance(q);
746    
747                                    qPos.add(companyId);
748    
749                                    if (!pagination) {
750                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
751                                                            start, end, false);
752    
753                                            Collections.sort(list);
754    
755                                            list = Collections.unmodifiableList(list);
756                                    }
757                                    else {
758                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
759                                                            start, end);
760                                    }
761    
762                                    cacheResult(list);
763    
764                                    finderCache.putResult(finderPath, finderArgs, list);
765                            }
766                            catch (Exception e) {
767                                    finderCache.removeResult(finderPath, finderArgs);
768    
769                                    throw processException(e);
770                            }
771                            finally {
772                                    closeSession(session);
773                            }
774                    }
775    
776                    return list;
777            }
778    
779            /**
780             * Returns the first trash entry in the ordered set where companyId = &#63;.
781             *
782             * @param companyId the company ID
783             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
784             * @return the first matching trash entry
785             * @throws NoSuchEntryException if a matching trash entry could not be found
786             */
787            @Override
788            public TrashEntry findByCompanyId_First(long companyId,
789                    OrderByComparator<TrashEntry> orderByComparator)
790                    throws NoSuchEntryException {
791                    TrashEntry trashEntry = fetchByCompanyId_First(companyId,
792                                    orderByComparator);
793    
794                    if (trashEntry != null) {
795                            return trashEntry;
796                    }
797    
798                    StringBundler msg = new StringBundler(4);
799    
800                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
801    
802                    msg.append("companyId=");
803                    msg.append(companyId);
804    
805                    msg.append(StringPool.CLOSE_CURLY_BRACE);
806    
807                    throw new NoSuchEntryException(msg.toString());
808            }
809    
810            /**
811             * Returns the first trash entry in the ordered set where companyId = &#63;.
812             *
813             * @param companyId the company ID
814             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
815             * @return the first matching trash entry, or <code>null</code> if a matching trash entry could not be found
816             */
817            @Override
818            public TrashEntry fetchByCompanyId_First(long companyId,
819                    OrderByComparator<TrashEntry> orderByComparator) {
820                    List<TrashEntry> list = findByCompanyId(companyId, 0, 1,
821                                    orderByComparator);
822    
823                    if (!list.isEmpty()) {
824                            return list.get(0);
825                    }
826    
827                    return null;
828            }
829    
830            /**
831             * Returns the last trash entry in the ordered set where companyId = &#63;.
832             *
833             * @param companyId the company ID
834             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
835             * @return the last matching trash entry
836             * @throws NoSuchEntryException if a matching trash entry could not be found
837             */
838            @Override
839            public TrashEntry findByCompanyId_Last(long companyId,
840                    OrderByComparator<TrashEntry> orderByComparator)
841                    throws NoSuchEntryException {
842                    TrashEntry trashEntry = fetchByCompanyId_Last(companyId,
843                                    orderByComparator);
844    
845                    if (trashEntry != null) {
846                            return trashEntry;
847                    }
848    
849                    StringBundler msg = new StringBundler(4);
850    
851                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
852    
853                    msg.append("companyId=");
854                    msg.append(companyId);
855    
856                    msg.append(StringPool.CLOSE_CURLY_BRACE);
857    
858                    throw new NoSuchEntryException(msg.toString());
859            }
860    
861            /**
862             * Returns the last trash entry in the ordered set where companyId = &#63;.
863             *
864             * @param companyId the company ID
865             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
866             * @return the last matching trash entry, or <code>null</code> if a matching trash entry could not be found
867             */
868            @Override
869            public TrashEntry fetchByCompanyId_Last(long companyId,
870                    OrderByComparator<TrashEntry> orderByComparator) {
871                    int count = countByCompanyId(companyId);
872    
873                    if (count == 0) {
874                            return null;
875                    }
876    
877                    List<TrashEntry> list = findByCompanyId(companyId, count - 1, count,
878                                    orderByComparator);
879    
880                    if (!list.isEmpty()) {
881                            return list.get(0);
882                    }
883    
884                    return null;
885            }
886    
887            /**
888             * Returns the trash entries before and after the current trash entry in the ordered set where companyId = &#63;.
889             *
890             * @param entryId the primary key of the current trash entry
891             * @param companyId the company ID
892             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
893             * @return the previous, current, and next trash entry
894             * @throws NoSuchEntryException if a trash entry with the primary key could not be found
895             */
896            @Override
897            public TrashEntry[] findByCompanyId_PrevAndNext(long entryId,
898                    long companyId, OrderByComparator<TrashEntry> orderByComparator)
899                    throws NoSuchEntryException {
900                    TrashEntry trashEntry = findByPrimaryKey(entryId);
901    
902                    Session session = null;
903    
904                    try {
905                            session = openSession();
906    
907                            TrashEntry[] array = new TrashEntryImpl[3];
908    
909                            array[0] = getByCompanyId_PrevAndNext(session, trashEntry,
910                                            companyId, orderByComparator, true);
911    
912                            array[1] = trashEntry;
913    
914                            array[2] = getByCompanyId_PrevAndNext(session, trashEntry,
915                                            companyId, orderByComparator, false);
916    
917                            return array;
918                    }
919                    catch (Exception e) {
920                            throw processException(e);
921                    }
922                    finally {
923                            closeSession(session);
924                    }
925            }
926    
927            protected TrashEntry getByCompanyId_PrevAndNext(Session session,
928                    TrashEntry trashEntry, long companyId,
929                    OrderByComparator<TrashEntry> orderByComparator, boolean previous) {
930                    StringBundler query = null;
931    
932                    if (orderByComparator != null) {
933                            query = new StringBundler(6 +
934                                            (orderByComparator.getOrderByFields().length * 6));
935                    }
936                    else {
937                            query = new StringBundler(3);
938                    }
939    
940                    query.append(_SQL_SELECT_TRASHENTRY_WHERE);
941    
942                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
943    
944                    if (orderByComparator != null) {
945                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
946    
947                            if (orderByConditionFields.length > 0) {
948                                    query.append(WHERE_AND);
949                            }
950    
951                            for (int i = 0; i < orderByConditionFields.length; i++) {
952                                    query.append(_ORDER_BY_ENTITY_ALIAS);
953                                    query.append(orderByConditionFields[i]);
954    
955                                    if ((i + 1) < orderByConditionFields.length) {
956                                            if (orderByComparator.isAscending() ^ previous) {
957                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
958                                            }
959                                            else {
960                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
961                                            }
962                                    }
963                                    else {
964                                            if (orderByComparator.isAscending() ^ previous) {
965                                                    query.append(WHERE_GREATER_THAN);
966                                            }
967                                            else {
968                                                    query.append(WHERE_LESSER_THAN);
969                                            }
970                                    }
971                            }
972    
973                            query.append(ORDER_BY_CLAUSE);
974    
975                            String[] orderByFields = orderByComparator.getOrderByFields();
976    
977                            for (int i = 0; i < orderByFields.length; i++) {
978                                    query.append(_ORDER_BY_ENTITY_ALIAS);
979                                    query.append(orderByFields[i]);
980    
981                                    if ((i + 1) < orderByFields.length) {
982                                            if (orderByComparator.isAscending() ^ previous) {
983                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
984                                            }
985                                            else {
986                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
987                                            }
988                                    }
989                                    else {
990                                            if (orderByComparator.isAscending() ^ previous) {
991                                                    query.append(ORDER_BY_ASC);
992                                            }
993                                            else {
994                                                    query.append(ORDER_BY_DESC);
995                                            }
996                                    }
997                            }
998                    }
999                    else {
1000                            query.append(TrashEntryModelImpl.ORDER_BY_JPQL);
1001                    }
1002    
1003                    String sql = query.toString();
1004    
1005                    Query q = session.createQuery(sql);
1006    
1007                    q.setFirstResult(0);
1008                    q.setMaxResults(2);
1009    
1010                    QueryPos qPos = QueryPos.getInstance(q);
1011    
1012                    qPos.add(companyId);
1013    
1014                    if (orderByComparator != null) {
1015                            Object[] values = orderByComparator.getOrderByConditionValues(trashEntry);
1016    
1017                            for (Object value : values) {
1018                                    qPos.add(value);
1019                            }
1020                    }
1021    
1022                    List<TrashEntry> list = q.list();
1023    
1024                    if (list.size() == 2) {
1025                            return list.get(1);
1026                    }
1027                    else {
1028                            return null;
1029                    }
1030            }
1031    
1032            /**
1033             * Removes all the trash entries where companyId = &#63; from the database.
1034             *
1035             * @param companyId the company ID
1036             */
1037            @Override
1038            public void removeByCompanyId(long companyId) {
1039                    for (TrashEntry trashEntry : findByCompanyId(companyId,
1040                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1041                            remove(trashEntry);
1042                    }
1043            }
1044    
1045            /**
1046             * Returns the number of trash entries where companyId = &#63;.
1047             *
1048             * @param companyId the company ID
1049             * @return the number of matching trash entries
1050             */
1051            @Override
1052            public int countByCompanyId(long companyId) {
1053                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
1054    
1055                    Object[] finderArgs = new Object[] { companyId };
1056    
1057                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1058    
1059                    if (count == null) {
1060                            StringBundler query = new StringBundler(2);
1061    
1062                            query.append(_SQL_COUNT_TRASHENTRY_WHERE);
1063    
1064                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1065    
1066                            String sql = query.toString();
1067    
1068                            Session session = null;
1069    
1070                            try {
1071                                    session = openSession();
1072    
1073                                    Query q = session.createQuery(sql);
1074    
1075                                    QueryPos qPos = QueryPos.getInstance(q);
1076    
1077                                    qPos.add(companyId);
1078    
1079                                    count = (Long)q.uniqueResult();
1080    
1081                                    finderCache.putResult(finderPath, finderArgs, count);
1082                            }
1083                            catch (Exception e) {
1084                                    finderCache.removeResult(finderPath, finderArgs);
1085    
1086                                    throw processException(e);
1087                            }
1088                            finally {
1089                                    closeSession(session);
1090                            }
1091                    }
1092    
1093                    return count.intValue();
1094            }
1095    
1096            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "trashEntry.companyId = ?";
1097            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LTCD = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
1098                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
1099                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_LtCD",
1100                            new String[] {
1101                                    Long.class.getName(), Date.class.getName(),
1102                                    
1103                            Integer.class.getName(), Integer.class.getName(),
1104                                    OrderByComparator.class.getName()
1105                            });
1106            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LTCD = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
1107                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
1108                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_LtCD",
1109                            new String[] { Long.class.getName(), Date.class.getName() });
1110    
1111            /**
1112             * Returns all the trash entries where groupId = &#63; and createDate &lt; &#63;.
1113             *
1114             * @param groupId the group ID
1115             * @param createDate the create date
1116             * @return the matching trash entries
1117             */
1118            @Override
1119            public List<TrashEntry> findByG_LtCD(long groupId, Date createDate) {
1120                    return findByG_LtCD(groupId, createDate, QueryUtil.ALL_POS,
1121                            QueryUtil.ALL_POS, null);
1122            }
1123    
1124            /**
1125             * Returns a range of all the trash entries where groupId = &#63; and createDate &lt; &#63;.
1126             *
1127             * <p>
1128             * 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.
1129             * </p>
1130             *
1131             * @param groupId the group ID
1132             * @param createDate the create date
1133             * @param start the lower bound of the range of trash entries
1134             * @param end the upper bound of the range of trash entries (not inclusive)
1135             * @return the range of matching trash entries
1136             */
1137            @Override
1138            public List<TrashEntry> findByG_LtCD(long groupId, Date createDate,
1139                    int start, int end) {
1140                    return findByG_LtCD(groupId, createDate, start, end, null);
1141            }
1142    
1143            /**
1144             * Returns an ordered range of all the trash entries where groupId = &#63; and createDate &lt; &#63;.
1145             *
1146             * <p>
1147             * 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.
1148             * </p>
1149             *
1150             * @param groupId the group ID
1151             * @param createDate the create date
1152             * @param start the lower bound of the range of trash entries
1153             * @param end the upper bound of the range of trash entries (not inclusive)
1154             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1155             * @return the ordered range of matching trash entries
1156             */
1157            @Override
1158            public List<TrashEntry> findByG_LtCD(long groupId, Date createDate,
1159                    int start, int end, OrderByComparator<TrashEntry> orderByComparator) {
1160                    return findByG_LtCD(groupId, createDate, start, end, orderByComparator,
1161                            true);
1162            }
1163    
1164            /**
1165             * Returns an ordered range of all the trash entries where groupId = &#63; and createDate &lt; &#63;.
1166             *
1167             * <p>
1168             * 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.
1169             * </p>
1170             *
1171             * @param groupId the group ID
1172             * @param createDate the create date
1173             * @param start the lower bound of the range of trash entries
1174             * @param end the upper bound of the range of trash entries (not inclusive)
1175             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1176             * @param retrieveFromCache whether to retrieve from the finder cache
1177             * @return the ordered range of matching trash entries
1178             */
1179            @Override
1180            public List<TrashEntry> findByG_LtCD(long groupId, Date createDate,
1181                    int start, int end, OrderByComparator<TrashEntry> orderByComparator,
1182                    boolean retrieveFromCache) {
1183                    boolean pagination = true;
1184                    FinderPath finderPath = null;
1185                    Object[] finderArgs = null;
1186    
1187                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LTCD;
1188                    finderArgs = new Object[] {
1189                                    groupId, createDate,
1190                                    
1191                                    start, end, orderByComparator
1192                            };
1193    
1194                    List<TrashEntry> list = null;
1195    
1196                    if (retrieveFromCache) {
1197                            list = (List<TrashEntry>)finderCache.getResult(finderPath,
1198                                            finderArgs, this);
1199    
1200                            if ((list != null) && !list.isEmpty()) {
1201                                    for (TrashEntry trashEntry : list) {
1202                                            if ((groupId != trashEntry.getGroupId()) ||
1203                                                            (createDate.getTime() <= trashEntry.getCreateDate()
1204                                                                                                                                       .getTime())) {
1205                                                    list = null;
1206    
1207                                                    break;
1208                                            }
1209                                    }
1210                            }
1211                    }
1212    
1213                    if (list == null) {
1214                            StringBundler query = null;
1215    
1216                            if (orderByComparator != null) {
1217                                    query = new StringBundler(4 +
1218                                                    (orderByComparator.getOrderByFields().length * 3));
1219                            }
1220                            else {
1221                                    query = new StringBundler(4);
1222                            }
1223    
1224                            query.append(_SQL_SELECT_TRASHENTRY_WHERE);
1225    
1226                            query.append(_FINDER_COLUMN_G_LTCD_GROUPID_2);
1227    
1228                            boolean bindCreateDate = false;
1229    
1230                            if (createDate == null) {
1231                                    query.append(_FINDER_COLUMN_G_LTCD_CREATEDATE_1);
1232                            }
1233                            else {
1234                                    bindCreateDate = true;
1235    
1236                                    query.append(_FINDER_COLUMN_G_LTCD_CREATEDATE_2);
1237                            }
1238    
1239                            if (orderByComparator != null) {
1240                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1241                                            orderByComparator);
1242                            }
1243                            else
1244                             if (pagination) {
1245                                    query.append(TrashEntryModelImpl.ORDER_BY_JPQL);
1246                            }
1247    
1248                            String sql = query.toString();
1249    
1250                            Session session = null;
1251    
1252                            try {
1253                                    session = openSession();
1254    
1255                                    Query q = session.createQuery(sql);
1256    
1257                                    QueryPos qPos = QueryPos.getInstance(q);
1258    
1259                                    qPos.add(groupId);
1260    
1261                                    if (bindCreateDate) {
1262                                            qPos.add(new Timestamp(createDate.getTime()));
1263                                    }
1264    
1265                                    if (!pagination) {
1266                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
1267                                                            start, end, false);
1268    
1269                                            Collections.sort(list);
1270    
1271                                            list = Collections.unmodifiableList(list);
1272                                    }
1273                                    else {
1274                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
1275                                                            start, end);
1276                                    }
1277    
1278                                    cacheResult(list);
1279    
1280                                    finderCache.putResult(finderPath, finderArgs, list);
1281                            }
1282                            catch (Exception e) {
1283                                    finderCache.removeResult(finderPath, finderArgs);
1284    
1285                                    throw processException(e);
1286                            }
1287                            finally {
1288                                    closeSession(session);
1289                            }
1290                    }
1291    
1292                    return list;
1293            }
1294    
1295            /**
1296             * Returns the first trash entry in the ordered set where groupId = &#63; and createDate &lt; &#63;.
1297             *
1298             * @param groupId the group ID
1299             * @param createDate the create date
1300             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1301             * @return the first matching trash entry
1302             * @throws NoSuchEntryException if a matching trash entry could not be found
1303             */
1304            @Override
1305            public TrashEntry findByG_LtCD_First(long groupId, Date createDate,
1306                    OrderByComparator<TrashEntry> orderByComparator)
1307                    throws NoSuchEntryException {
1308                    TrashEntry trashEntry = fetchByG_LtCD_First(groupId, createDate,
1309                                    orderByComparator);
1310    
1311                    if (trashEntry != null) {
1312                            return trashEntry;
1313                    }
1314    
1315                    StringBundler msg = new StringBundler(6);
1316    
1317                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1318    
1319                    msg.append("groupId=");
1320                    msg.append(groupId);
1321    
1322                    msg.append(", createDate=");
1323                    msg.append(createDate);
1324    
1325                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1326    
1327                    throw new NoSuchEntryException(msg.toString());
1328            }
1329    
1330            /**
1331             * Returns the first trash entry in the ordered set where groupId = &#63; and createDate &lt; &#63;.
1332             *
1333             * @param groupId the group ID
1334             * @param createDate the create date
1335             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1336             * @return the first matching trash entry, or <code>null</code> if a matching trash entry could not be found
1337             */
1338            @Override
1339            public TrashEntry fetchByG_LtCD_First(long groupId, Date createDate,
1340                    OrderByComparator<TrashEntry> orderByComparator) {
1341                    List<TrashEntry> list = findByG_LtCD(groupId, createDate, 0, 1,
1342                                    orderByComparator);
1343    
1344                    if (!list.isEmpty()) {
1345                            return list.get(0);
1346                    }
1347    
1348                    return null;
1349            }
1350    
1351            /**
1352             * Returns the last trash entry in the ordered set where groupId = &#63; and createDate &lt; &#63;.
1353             *
1354             * @param groupId the group ID
1355             * @param createDate the create date
1356             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1357             * @return the last matching trash entry
1358             * @throws NoSuchEntryException if a matching trash entry could not be found
1359             */
1360            @Override
1361            public TrashEntry findByG_LtCD_Last(long groupId, Date createDate,
1362                    OrderByComparator<TrashEntry> orderByComparator)
1363                    throws NoSuchEntryException {
1364                    TrashEntry trashEntry = fetchByG_LtCD_Last(groupId, createDate,
1365                                    orderByComparator);
1366    
1367                    if (trashEntry != null) {
1368                            return trashEntry;
1369                    }
1370    
1371                    StringBundler msg = new StringBundler(6);
1372    
1373                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1374    
1375                    msg.append("groupId=");
1376                    msg.append(groupId);
1377    
1378                    msg.append(", createDate=");
1379                    msg.append(createDate);
1380    
1381                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1382    
1383                    throw new NoSuchEntryException(msg.toString());
1384            }
1385    
1386            /**
1387             * Returns the last trash entry in the ordered set where groupId = &#63; and createDate &lt; &#63;.
1388             *
1389             * @param groupId the group ID
1390             * @param createDate the create date
1391             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1392             * @return the last matching trash entry, or <code>null</code> if a matching trash entry could not be found
1393             */
1394            @Override
1395            public TrashEntry fetchByG_LtCD_Last(long groupId, Date createDate,
1396                    OrderByComparator<TrashEntry> orderByComparator) {
1397                    int count = countByG_LtCD(groupId, createDate);
1398    
1399                    if (count == 0) {
1400                            return null;
1401                    }
1402    
1403                    List<TrashEntry> list = findByG_LtCD(groupId, createDate, count - 1,
1404                                    count, orderByComparator);
1405    
1406                    if (!list.isEmpty()) {
1407                            return list.get(0);
1408                    }
1409    
1410                    return null;
1411            }
1412    
1413            /**
1414             * Returns the trash entries before and after the current trash entry in the ordered set where groupId = &#63; and createDate &lt; &#63;.
1415             *
1416             * @param entryId the primary key of the current trash entry
1417             * @param groupId the group ID
1418             * @param createDate the create date
1419             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1420             * @return the previous, current, and next trash entry
1421             * @throws NoSuchEntryException if a trash entry with the primary key could not be found
1422             */
1423            @Override
1424            public TrashEntry[] findByG_LtCD_PrevAndNext(long entryId, long groupId,
1425                    Date createDate, OrderByComparator<TrashEntry> orderByComparator)
1426                    throws NoSuchEntryException {
1427                    TrashEntry trashEntry = findByPrimaryKey(entryId);
1428    
1429                    Session session = null;
1430    
1431                    try {
1432                            session = openSession();
1433    
1434                            TrashEntry[] array = new TrashEntryImpl[3];
1435    
1436                            array[0] = getByG_LtCD_PrevAndNext(session, trashEntry, groupId,
1437                                            createDate, orderByComparator, true);
1438    
1439                            array[1] = trashEntry;
1440    
1441                            array[2] = getByG_LtCD_PrevAndNext(session, trashEntry, groupId,
1442                                            createDate, orderByComparator, false);
1443    
1444                            return array;
1445                    }
1446                    catch (Exception e) {
1447                            throw processException(e);
1448                    }
1449                    finally {
1450                            closeSession(session);
1451                    }
1452            }
1453    
1454            protected TrashEntry getByG_LtCD_PrevAndNext(Session session,
1455                    TrashEntry trashEntry, long groupId, Date createDate,
1456                    OrderByComparator<TrashEntry> orderByComparator, boolean previous) {
1457                    StringBundler query = null;
1458    
1459                    if (orderByComparator != null) {
1460                            query = new StringBundler(6 +
1461                                            (orderByComparator.getOrderByFields().length * 6));
1462                    }
1463                    else {
1464                            query = new StringBundler(3);
1465                    }
1466    
1467                    query.append(_SQL_SELECT_TRASHENTRY_WHERE);
1468    
1469                    query.append(_FINDER_COLUMN_G_LTCD_GROUPID_2);
1470    
1471                    boolean bindCreateDate = false;
1472    
1473                    if (createDate == null) {
1474                            query.append(_FINDER_COLUMN_G_LTCD_CREATEDATE_1);
1475                    }
1476                    else {
1477                            bindCreateDate = true;
1478    
1479                            query.append(_FINDER_COLUMN_G_LTCD_CREATEDATE_2);
1480                    }
1481    
1482                    if (orderByComparator != null) {
1483                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1484    
1485                            if (orderByConditionFields.length > 0) {
1486                                    query.append(WHERE_AND);
1487                            }
1488    
1489                            for (int i = 0; i < orderByConditionFields.length; i++) {
1490                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1491                                    query.append(orderByConditionFields[i]);
1492    
1493                                    if ((i + 1) < orderByConditionFields.length) {
1494                                            if (orderByComparator.isAscending() ^ previous) {
1495                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1496                                            }
1497                                            else {
1498                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1499                                            }
1500                                    }
1501                                    else {
1502                                            if (orderByComparator.isAscending() ^ previous) {
1503                                                    query.append(WHERE_GREATER_THAN);
1504                                            }
1505                                            else {
1506                                                    query.append(WHERE_LESSER_THAN);
1507                                            }
1508                                    }
1509                            }
1510    
1511                            query.append(ORDER_BY_CLAUSE);
1512    
1513                            String[] orderByFields = orderByComparator.getOrderByFields();
1514    
1515                            for (int i = 0; i < orderByFields.length; i++) {
1516                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1517                                    query.append(orderByFields[i]);
1518    
1519                                    if ((i + 1) < orderByFields.length) {
1520                                            if (orderByComparator.isAscending() ^ previous) {
1521                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1522                                            }
1523                                            else {
1524                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1525                                            }
1526                                    }
1527                                    else {
1528                                            if (orderByComparator.isAscending() ^ previous) {
1529                                                    query.append(ORDER_BY_ASC);
1530                                            }
1531                                            else {
1532                                                    query.append(ORDER_BY_DESC);
1533                                            }
1534                                    }
1535                            }
1536                    }
1537                    else {
1538                            query.append(TrashEntryModelImpl.ORDER_BY_JPQL);
1539                    }
1540    
1541                    String sql = query.toString();
1542    
1543                    Query q = session.createQuery(sql);
1544    
1545                    q.setFirstResult(0);
1546                    q.setMaxResults(2);
1547    
1548                    QueryPos qPos = QueryPos.getInstance(q);
1549    
1550                    qPos.add(groupId);
1551    
1552                    if (bindCreateDate) {
1553                            qPos.add(new Timestamp(createDate.getTime()));
1554                    }
1555    
1556                    if (orderByComparator != null) {
1557                            Object[] values = orderByComparator.getOrderByConditionValues(trashEntry);
1558    
1559                            for (Object value : values) {
1560                                    qPos.add(value);
1561                            }
1562                    }
1563    
1564                    List<TrashEntry> list = q.list();
1565    
1566                    if (list.size() == 2) {
1567                            return list.get(1);
1568                    }
1569                    else {
1570                            return null;
1571                    }
1572            }
1573    
1574            /**
1575             * Removes all the trash entries where groupId = &#63; and createDate &lt; &#63; from the database.
1576             *
1577             * @param groupId the group ID
1578             * @param createDate the create date
1579             */
1580            @Override
1581            public void removeByG_LtCD(long groupId, Date createDate) {
1582                    for (TrashEntry trashEntry : findByG_LtCD(groupId, createDate,
1583                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1584                            remove(trashEntry);
1585                    }
1586            }
1587    
1588            /**
1589             * Returns the number of trash entries where groupId = &#63; and createDate &lt; &#63;.
1590             *
1591             * @param groupId the group ID
1592             * @param createDate the create date
1593             * @return the number of matching trash entries
1594             */
1595            @Override
1596            public int countByG_LtCD(long groupId, Date createDate) {
1597                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LTCD;
1598    
1599                    Object[] finderArgs = new Object[] { groupId, createDate };
1600    
1601                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1602    
1603                    if (count == null) {
1604                            StringBundler query = new StringBundler(3);
1605    
1606                            query.append(_SQL_COUNT_TRASHENTRY_WHERE);
1607    
1608                            query.append(_FINDER_COLUMN_G_LTCD_GROUPID_2);
1609    
1610                            boolean bindCreateDate = false;
1611    
1612                            if (createDate == null) {
1613                                    query.append(_FINDER_COLUMN_G_LTCD_CREATEDATE_1);
1614                            }
1615                            else {
1616                                    bindCreateDate = true;
1617    
1618                                    query.append(_FINDER_COLUMN_G_LTCD_CREATEDATE_2);
1619                            }
1620    
1621                            String sql = query.toString();
1622    
1623                            Session session = null;
1624    
1625                            try {
1626                                    session = openSession();
1627    
1628                                    Query q = session.createQuery(sql);
1629    
1630                                    QueryPos qPos = QueryPos.getInstance(q);
1631    
1632                                    qPos.add(groupId);
1633    
1634                                    if (bindCreateDate) {
1635                                            qPos.add(new Timestamp(createDate.getTime()));
1636                                    }
1637    
1638                                    count = (Long)q.uniqueResult();
1639    
1640                                    finderCache.putResult(finderPath, finderArgs, count);
1641                            }
1642                            catch (Exception e) {
1643                                    finderCache.removeResult(finderPath, finderArgs);
1644    
1645                                    throw processException(e);
1646                            }
1647                            finally {
1648                                    closeSession(session);
1649                            }
1650                    }
1651    
1652                    return count.intValue();
1653            }
1654    
1655            private static final String _FINDER_COLUMN_G_LTCD_GROUPID_2 = "trashEntry.groupId = ? AND ";
1656            private static final String _FINDER_COLUMN_G_LTCD_CREATEDATE_1 = "trashEntry.createDate IS NULL";
1657            private static final String _FINDER_COLUMN_G_LTCD_CREATEDATE_2 = "trashEntry.createDate < ?";
1658            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
1659                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
1660                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
1661                            new String[] {
1662                                    Long.class.getName(), Long.class.getName(),
1663                                    
1664                            Integer.class.getName(), Integer.class.getName(),
1665                                    OrderByComparator.class.getName()
1666                            });
1667            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
1668                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
1669                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
1670                            new String[] { Long.class.getName(), Long.class.getName() },
1671                            TrashEntryModelImpl.GROUPID_COLUMN_BITMASK |
1672                            TrashEntryModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1673                            TrashEntryModelImpl.CREATEDATE_COLUMN_BITMASK);
1674            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
1675                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
1676                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
1677                            new String[] { Long.class.getName(), Long.class.getName() });
1678    
1679            /**
1680             * Returns all the trash entries where groupId = &#63; and classNameId = &#63;.
1681             *
1682             * @param groupId the group ID
1683             * @param classNameId the class name ID
1684             * @return the matching trash entries
1685             */
1686            @Override
1687            public List<TrashEntry> findByG_C(long groupId, long classNameId) {
1688                    return findByG_C(groupId, classNameId, QueryUtil.ALL_POS,
1689                            QueryUtil.ALL_POS, null);
1690            }
1691    
1692            /**
1693             * Returns a range of all the trash entries where groupId = &#63; and classNameId = &#63;.
1694             *
1695             * <p>
1696             * 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.
1697             * </p>
1698             *
1699             * @param groupId the group ID
1700             * @param classNameId the class name ID
1701             * @param start the lower bound of the range of trash entries
1702             * @param end the upper bound of the range of trash entries (not inclusive)
1703             * @return the range of matching trash entries
1704             */
1705            @Override
1706            public List<TrashEntry> findByG_C(long groupId, long classNameId,
1707                    int start, int end) {
1708                    return findByG_C(groupId, classNameId, start, end, null);
1709            }
1710    
1711            /**
1712             * Returns an ordered range of all the trash entries where groupId = &#63; and classNameId = &#63;.
1713             *
1714             * <p>
1715             * 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.
1716             * </p>
1717             *
1718             * @param groupId the group ID
1719             * @param classNameId the class name ID
1720             * @param start the lower bound of the range of trash entries
1721             * @param end the upper bound of the range of trash entries (not inclusive)
1722             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1723             * @return the ordered range of matching trash entries
1724             */
1725            @Override
1726            public List<TrashEntry> findByG_C(long groupId, long classNameId,
1727                    int start, int end, OrderByComparator<TrashEntry> orderByComparator) {
1728                    return findByG_C(groupId, classNameId, start, end, orderByComparator,
1729                            true);
1730            }
1731    
1732            /**
1733             * Returns an ordered range of all the trash entries where groupId = &#63; and classNameId = &#63;.
1734             *
1735             * <p>
1736             * 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.
1737             * </p>
1738             *
1739             * @param groupId the group ID
1740             * @param classNameId the class name ID
1741             * @param start the lower bound of the range of trash entries
1742             * @param end the upper bound of the range of trash entries (not inclusive)
1743             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1744             * @param retrieveFromCache whether to retrieve from the finder cache
1745             * @return the ordered range of matching trash entries
1746             */
1747            @Override
1748            public List<TrashEntry> findByG_C(long groupId, long classNameId,
1749                    int start, int end, OrderByComparator<TrashEntry> orderByComparator,
1750                    boolean retrieveFromCache) {
1751                    boolean pagination = true;
1752                    FinderPath finderPath = null;
1753                    Object[] finderArgs = null;
1754    
1755                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1756                                    (orderByComparator == null)) {
1757                            pagination = false;
1758                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
1759                            finderArgs = new Object[] { groupId, classNameId };
1760                    }
1761                    else {
1762                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
1763                            finderArgs = new Object[] {
1764                                            groupId, classNameId,
1765                                            
1766                                            start, end, orderByComparator
1767                                    };
1768                    }
1769    
1770                    List<TrashEntry> list = null;
1771    
1772                    if (retrieveFromCache) {
1773                            list = (List<TrashEntry>)finderCache.getResult(finderPath,
1774                                            finderArgs, this);
1775    
1776                            if ((list != null) && !list.isEmpty()) {
1777                                    for (TrashEntry trashEntry : list) {
1778                                            if ((groupId != trashEntry.getGroupId()) ||
1779                                                            (classNameId != trashEntry.getClassNameId())) {
1780                                                    list = null;
1781    
1782                                                    break;
1783                                            }
1784                                    }
1785                            }
1786                    }
1787    
1788                    if (list == null) {
1789                            StringBundler query = null;
1790    
1791                            if (orderByComparator != null) {
1792                                    query = new StringBundler(4 +
1793                                                    (orderByComparator.getOrderByFields().length * 3));
1794                            }
1795                            else {
1796                                    query = new StringBundler(4);
1797                            }
1798    
1799                            query.append(_SQL_SELECT_TRASHENTRY_WHERE);
1800    
1801                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1802    
1803                            query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
1804    
1805                            if (orderByComparator != null) {
1806                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1807                                            orderByComparator);
1808                            }
1809                            else
1810                             if (pagination) {
1811                                    query.append(TrashEntryModelImpl.ORDER_BY_JPQL);
1812                            }
1813    
1814                            String sql = query.toString();
1815    
1816                            Session session = null;
1817    
1818                            try {
1819                                    session = openSession();
1820    
1821                                    Query q = session.createQuery(sql);
1822    
1823                                    QueryPos qPos = QueryPos.getInstance(q);
1824    
1825                                    qPos.add(groupId);
1826    
1827                                    qPos.add(classNameId);
1828    
1829                                    if (!pagination) {
1830                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
1831                                                            start, end, false);
1832    
1833                                            Collections.sort(list);
1834    
1835                                            list = Collections.unmodifiableList(list);
1836                                    }
1837                                    else {
1838                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
1839                                                            start, end);
1840                                    }
1841    
1842                                    cacheResult(list);
1843    
1844                                    finderCache.putResult(finderPath, finderArgs, list);
1845                            }
1846                            catch (Exception e) {
1847                                    finderCache.removeResult(finderPath, finderArgs);
1848    
1849                                    throw processException(e);
1850                            }
1851                            finally {
1852                                    closeSession(session);
1853                            }
1854                    }
1855    
1856                    return list;
1857            }
1858    
1859            /**
1860             * Returns the first trash entry in the ordered set where groupId = &#63; and classNameId = &#63;.
1861             *
1862             * @param groupId the group ID
1863             * @param classNameId the class name ID
1864             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1865             * @return the first matching trash entry
1866             * @throws NoSuchEntryException if a matching trash entry could not be found
1867             */
1868            @Override
1869            public TrashEntry findByG_C_First(long groupId, long classNameId,
1870                    OrderByComparator<TrashEntry> orderByComparator)
1871                    throws NoSuchEntryException {
1872                    TrashEntry trashEntry = fetchByG_C_First(groupId, classNameId,
1873                                    orderByComparator);
1874    
1875                    if (trashEntry != null) {
1876                            return trashEntry;
1877                    }
1878    
1879                    StringBundler msg = new StringBundler(6);
1880    
1881                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1882    
1883                    msg.append("groupId=");
1884                    msg.append(groupId);
1885    
1886                    msg.append(", classNameId=");
1887                    msg.append(classNameId);
1888    
1889                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1890    
1891                    throw new NoSuchEntryException(msg.toString());
1892            }
1893    
1894            /**
1895             * Returns the first trash entry in the ordered set where groupId = &#63; and classNameId = &#63;.
1896             *
1897             * @param groupId the group ID
1898             * @param classNameId the class name ID
1899             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1900             * @return the first matching trash entry, or <code>null</code> if a matching trash entry could not be found
1901             */
1902            @Override
1903            public TrashEntry fetchByG_C_First(long groupId, long classNameId,
1904                    OrderByComparator<TrashEntry> orderByComparator) {
1905                    List<TrashEntry> list = findByG_C(groupId, classNameId, 0, 1,
1906                                    orderByComparator);
1907    
1908                    if (!list.isEmpty()) {
1909                            return list.get(0);
1910                    }
1911    
1912                    return null;
1913            }
1914    
1915            /**
1916             * Returns the last trash entry in the ordered set where groupId = &#63; and classNameId = &#63;.
1917             *
1918             * @param groupId the group ID
1919             * @param classNameId the class name ID
1920             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1921             * @return the last matching trash entry
1922             * @throws NoSuchEntryException if a matching trash entry could not be found
1923             */
1924            @Override
1925            public TrashEntry findByG_C_Last(long groupId, long classNameId,
1926                    OrderByComparator<TrashEntry> orderByComparator)
1927                    throws NoSuchEntryException {
1928                    TrashEntry trashEntry = fetchByG_C_Last(groupId, classNameId,
1929                                    orderByComparator);
1930    
1931                    if (trashEntry != null) {
1932                            return trashEntry;
1933                    }
1934    
1935                    StringBundler msg = new StringBundler(6);
1936    
1937                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1938    
1939                    msg.append("groupId=");
1940                    msg.append(groupId);
1941    
1942                    msg.append(", classNameId=");
1943                    msg.append(classNameId);
1944    
1945                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1946    
1947                    throw new NoSuchEntryException(msg.toString());
1948            }
1949    
1950            /**
1951             * Returns the last trash entry in the ordered set where groupId = &#63; and classNameId = &#63;.
1952             *
1953             * @param groupId the group ID
1954             * @param classNameId the class name ID
1955             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1956             * @return the last matching trash entry, or <code>null</code> if a matching trash entry could not be found
1957             */
1958            @Override
1959            public TrashEntry fetchByG_C_Last(long groupId, long classNameId,
1960                    OrderByComparator<TrashEntry> orderByComparator) {
1961                    int count = countByG_C(groupId, classNameId);
1962    
1963                    if (count == 0) {
1964                            return null;
1965                    }
1966    
1967                    List<TrashEntry> list = findByG_C(groupId, classNameId, count - 1,
1968                                    count, orderByComparator);
1969    
1970                    if (!list.isEmpty()) {
1971                            return list.get(0);
1972                    }
1973    
1974                    return null;
1975            }
1976    
1977            /**
1978             * Returns the trash entries before and after the current trash entry in the ordered set where groupId = &#63; and classNameId = &#63;.
1979             *
1980             * @param entryId the primary key of the current trash entry
1981             * @param groupId the group ID
1982             * @param classNameId the class name ID
1983             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1984             * @return the previous, current, and next trash entry
1985             * @throws NoSuchEntryException if a trash entry with the primary key could not be found
1986             */
1987            @Override
1988            public TrashEntry[] findByG_C_PrevAndNext(long entryId, long groupId,
1989                    long classNameId, OrderByComparator<TrashEntry> orderByComparator)
1990                    throws NoSuchEntryException {
1991                    TrashEntry trashEntry = findByPrimaryKey(entryId);
1992    
1993                    Session session = null;
1994    
1995                    try {
1996                            session = openSession();
1997    
1998                            TrashEntry[] array = new TrashEntryImpl[3];
1999    
2000                            array[0] = getByG_C_PrevAndNext(session, trashEntry, groupId,
2001                                            classNameId, orderByComparator, true);
2002    
2003                            array[1] = trashEntry;
2004    
2005                            array[2] = getByG_C_PrevAndNext(session, trashEntry, groupId,
2006                                            classNameId, orderByComparator, false);
2007    
2008                            return array;
2009                    }
2010                    catch (Exception e) {
2011                            throw processException(e);
2012                    }
2013                    finally {
2014                            closeSession(session);
2015                    }
2016            }
2017    
2018            protected TrashEntry getByG_C_PrevAndNext(Session session,
2019                    TrashEntry trashEntry, long groupId, long classNameId,
2020                    OrderByComparator<TrashEntry> orderByComparator, boolean previous) {
2021                    StringBundler query = null;
2022    
2023                    if (orderByComparator != null) {
2024                            query = new StringBundler(6 +
2025                                            (orderByComparator.getOrderByFields().length * 6));
2026                    }
2027                    else {
2028                            query = new StringBundler(3);
2029                    }
2030    
2031                    query.append(_SQL_SELECT_TRASHENTRY_WHERE);
2032    
2033                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2034    
2035                    query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
2036    
2037                    if (orderByComparator != null) {
2038                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2039    
2040                            if (orderByConditionFields.length > 0) {
2041                                    query.append(WHERE_AND);
2042                            }
2043    
2044                            for (int i = 0; i < orderByConditionFields.length; i++) {
2045                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2046                                    query.append(orderByConditionFields[i]);
2047    
2048                                    if ((i + 1) < orderByConditionFields.length) {
2049                                            if (orderByComparator.isAscending() ^ previous) {
2050                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2051                                            }
2052                                            else {
2053                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2054                                            }
2055                                    }
2056                                    else {
2057                                            if (orderByComparator.isAscending() ^ previous) {
2058                                                    query.append(WHERE_GREATER_THAN);
2059                                            }
2060                                            else {
2061                                                    query.append(WHERE_LESSER_THAN);
2062                                            }
2063                                    }
2064                            }
2065    
2066                            query.append(ORDER_BY_CLAUSE);
2067    
2068                            String[] orderByFields = orderByComparator.getOrderByFields();
2069    
2070                            for (int i = 0; i < orderByFields.length; i++) {
2071                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2072                                    query.append(orderByFields[i]);
2073    
2074                                    if ((i + 1) < orderByFields.length) {
2075                                            if (orderByComparator.isAscending() ^ previous) {
2076                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2077                                            }
2078                                            else {
2079                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2080                                            }
2081                                    }
2082                                    else {
2083                                            if (orderByComparator.isAscending() ^ previous) {
2084                                                    query.append(ORDER_BY_ASC);
2085                                            }
2086                                            else {
2087                                                    query.append(ORDER_BY_DESC);
2088                                            }
2089                                    }
2090                            }
2091                    }
2092                    else {
2093                            query.append(TrashEntryModelImpl.ORDER_BY_JPQL);
2094                    }
2095    
2096                    String sql = query.toString();
2097    
2098                    Query q = session.createQuery(sql);
2099    
2100                    q.setFirstResult(0);
2101                    q.setMaxResults(2);
2102    
2103                    QueryPos qPos = QueryPos.getInstance(q);
2104    
2105                    qPos.add(groupId);
2106    
2107                    qPos.add(classNameId);
2108    
2109                    if (orderByComparator != null) {
2110                            Object[] values = orderByComparator.getOrderByConditionValues(trashEntry);
2111    
2112                            for (Object value : values) {
2113                                    qPos.add(value);
2114                            }
2115                    }
2116    
2117                    List<TrashEntry> list = q.list();
2118    
2119                    if (list.size() == 2) {
2120                            return list.get(1);
2121                    }
2122                    else {
2123                            return null;
2124                    }
2125            }
2126    
2127            /**
2128             * Removes all the trash entries where groupId = &#63; and classNameId = &#63; from the database.
2129             *
2130             * @param groupId the group ID
2131             * @param classNameId the class name ID
2132             */
2133            @Override
2134            public void removeByG_C(long groupId, long classNameId) {
2135                    for (TrashEntry trashEntry : findByG_C(groupId, classNameId,
2136                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2137                            remove(trashEntry);
2138                    }
2139            }
2140    
2141            /**
2142             * Returns the number of trash entries where groupId = &#63; and classNameId = &#63;.
2143             *
2144             * @param groupId the group ID
2145             * @param classNameId the class name ID
2146             * @return the number of matching trash entries
2147             */
2148            @Override
2149            public int countByG_C(long groupId, long classNameId) {
2150                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
2151    
2152                    Object[] finderArgs = new Object[] { groupId, classNameId };
2153    
2154                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2155    
2156                    if (count == null) {
2157                            StringBundler query = new StringBundler(3);
2158    
2159                            query.append(_SQL_COUNT_TRASHENTRY_WHERE);
2160    
2161                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2162    
2163                            query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
2164    
2165                            String sql = query.toString();
2166    
2167                            Session session = null;
2168    
2169                            try {
2170                                    session = openSession();
2171    
2172                                    Query q = session.createQuery(sql);
2173    
2174                                    QueryPos qPos = QueryPos.getInstance(q);
2175    
2176                                    qPos.add(groupId);
2177    
2178                                    qPos.add(classNameId);
2179    
2180                                    count = (Long)q.uniqueResult();
2181    
2182                                    finderCache.putResult(finderPath, finderArgs, count);
2183                            }
2184                            catch (Exception e) {
2185                                    finderCache.removeResult(finderPath, finderArgs);
2186    
2187                                    throw processException(e);
2188                            }
2189                            finally {
2190                                    closeSession(session);
2191                            }
2192                    }
2193    
2194                    return count.intValue();
2195            }
2196    
2197            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "trashEntry.groupId = ? AND ";
2198            private static final String _FINDER_COLUMN_G_C_CLASSNAMEID_2 = "trashEntry.classNameId = ?";
2199            public static final FinderPath FINDER_PATH_FETCH_BY_C_C = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2200                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
2201                            FINDER_CLASS_NAME_ENTITY, "fetchByC_C",
2202                            new String[] { Long.class.getName(), Long.class.getName() },
2203                            TrashEntryModelImpl.CLASSNAMEID_COLUMN_BITMASK |
2204                            TrashEntryModelImpl.CLASSPK_COLUMN_BITMASK);
2205            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2206                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2207                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
2208                            new String[] { Long.class.getName(), Long.class.getName() });
2209    
2210            /**
2211             * Returns the trash entry where classNameId = &#63; and classPK = &#63; or throws a {@link NoSuchEntryException} if it could not be found.
2212             *
2213             * @param classNameId the class name ID
2214             * @param classPK the class p k
2215             * @return the matching trash entry
2216             * @throws NoSuchEntryException if a matching trash entry could not be found
2217             */
2218            @Override
2219            public TrashEntry findByC_C(long classNameId, long classPK)
2220                    throws NoSuchEntryException {
2221                    TrashEntry trashEntry = fetchByC_C(classNameId, classPK);
2222    
2223                    if (trashEntry == null) {
2224                            StringBundler msg = new StringBundler(6);
2225    
2226                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2227    
2228                            msg.append("classNameId=");
2229                            msg.append(classNameId);
2230    
2231                            msg.append(", classPK=");
2232                            msg.append(classPK);
2233    
2234                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2235    
2236                            if (_log.isWarnEnabled()) {
2237                                    _log.warn(msg.toString());
2238                            }
2239    
2240                            throw new NoSuchEntryException(msg.toString());
2241                    }
2242    
2243                    return trashEntry;
2244            }
2245    
2246            /**
2247             * Returns the trash entry where classNameId = &#63; and classPK = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2248             *
2249             * @param classNameId the class name ID
2250             * @param classPK the class p k
2251             * @return the matching trash entry, or <code>null</code> if a matching trash entry could not be found
2252             */
2253            @Override
2254            public TrashEntry fetchByC_C(long classNameId, long classPK) {
2255                    return fetchByC_C(classNameId, classPK, true);
2256            }
2257    
2258            /**
2259             * Returns the trash entry where classNameId = &#63; and classPK = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2260             *
2261             * @param classNameId the class name ID
2262             * @param classPK the class p k
2263             * @param retrieveFromCache whether to retrieve from the finder cache
2264             * @return the matching trash entry, or <code>null</code> if a matching trash entry could not be found
2265             */
2266            @Override
2267            public TrashEntry fetchByC_C(long classNameId, long classPK,
2268                    boolean retrieveFromCache) {
2269                    Object[] finderArgs = new Object[] { classNameId, classPK };
2270    
2271                    Object result = null;
2272    
2273                    if (retrieveFromCache) {
2274                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_C_C,
2275                                            finderArgs, this);
2276                    }
2277    
2278                    if (result instanceof TrashEntry) {
2279                            TrashEntry trashEntry = (TrashEntry)result;
2280    
2281                            if ((classNameId != trashEntry.getClassNameId()) ||
2282                                            (classPK != trashEntry.getClassPK())) {
2283                                    result = null;
2284                            }
2285                    }
2286    
2287                    if (result == null) {
2288                            StringBundler query = new StringBundler(4);
2289    
2290                            query.append(_SQL_SELECT_TRASHENTRY_WHERE);
2291    
2292                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2293    
2294                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
2295    
2296                            String sql = query.toString();
2297    
2298                            Session session = null;
2299    
2300                            try {
2301                                    session = openSession();
2302    
2303                                    Query q = session.createQuery(sql);
2304    
2305                                    QueryPos qPos = QueryPos.getInstance(q);
2306    
2307                                    qPos.add(classNameId);
2308    
2309                                    qPos.add(classPK);
2310    
2311                                    List<TrashEntry> list = q.list();
2312    
2313                                    if (list.isEmpty()) {
2314                                            finderCache.putResult(FINDER_PATH_FETCH_BY_C_C, finderArgs,
2315                                                    list);
2316                                    }
2317                                    else {
2318                                            TrashEntry trashEntry = list.get(0);
2319    
2320                                            result = trashEntry;
2321    
2322                                            cacheResult(trashEntry);
2323    
2324                                            if ((trashEntry.getClassNameId() != classNameId) ||
2325                                                            (trashEntry.getClassPK() != classPK)) {
2326                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_C,
2327                                                            finderArgs, trashEntry);
2328                                            }
2329                                    }
2330                            }
2331                            catch (Exception e) {
2332                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C, finderArgs);
2333    
2334                                    throw processException(e);
2335                            }
2336                            finally {
2337                                    closeSession(session);
2338                            }
2339                    }
2340    
2341                    if (result instanceof List<?>) {
2342                            return null;
2343                    }
2344                    else {
2345                            return (TrashEntry)result;
2346                    }
2347            }
2348    
2349            /**
2350             * Removes the trash entry where classNameId = &#63; and classPK = &#63; from the database.
2351             *
2352             * @param classNameId the class name ID
2353             * @param classPK the class p k
2354             * @return the trash entry that was removed
2355             */
2356            @Override
2357            public TrashEntry removeByC_C(long classNameId, long classPK)
2358                    throws NoSuchEntryException {
2359                    TrashEntry trashEntry = findByC_C(classNameId, classPK);
2360    
2361                    return remove(trashEntry);
2362            }
2363    
2364            /**
2365             * Returns the number of trash entries where classNameId = &#63; and classPK = &#63;.
2366             *
2367             * @param classNameId the class name ID
2368             * @param classPK the class p k
2369             * @return the number of matching trash entries
2370             */
2371            @Override
2372            public int countByC_C(long classNameId, long classPK) {
2373                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
2374    
2375                    Object[] finderArgs = new Object[] { classNameId, classPK };
2376    
2377                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2378    
2379                    if (count == null) {
2380                            StringBundler query = new StringBundler(3);
2381    
2382                            query.append(_SQL_COUNT_TRASHENTRY_WHERE);
2383    
2384                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2385    
2386                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
2387    
2388                            String sql = query.toString();
2389    
2390                            Session session = null;
2391    
2392                            try {
2393                                    session = openSession();
2394    
2395                                    Query q = session.createQuery(sql);
2396    
2397                                    QueryPos qPos = QueryPos.getInstance(q);
2398    
2399                                    qPos.add(classNameId);
2400    
2401                                    qPos.add(classPK);
2402    
2403                                    count = (Long)q.uniqueResult();
2404    
2405                                    finderCache.putResult(finderPath, finderArgs, count);
2406                            }
2407                            catch (Exception e) {
2408                                    finderCache.removeResult(finderPath, finderArgs);
2409    
2410                                    throw processException(e);
2411                            }
2412                            finally {
2413                                    closeSession(session);
2414                            }
2415                    }
2416    
2417                    return count.intValue();
2418            }
2419    
2420            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "trashEntry.classNameId = ? AND ";
2421            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "trashEntry.classPK = ?";
2422    
2423            public TrashEntryPersistenceImpl() {
2424                    setModelClass(TrashEntry.class);
2425            }
2426    
2427            /**
2428             * Caches the trash entry in the entity cache if it is enabled.
2429             *
2430             * @param trashEntry the trash entry
2431             */
2432            @Override
2433            public void cacheResult(TrashEntry trashEntry) {
2434                    entityCache.putResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2435                            TrashEntryImpl.class, trashEntry.getPrimaryKey(), trashEntry);
2436    
2437                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_C,
2438                            new Object[] { trashEntry.getClassNameId(), trashEntry.getClassPK() },
2439                            trashEntry);
2440    
2441                    trashEntry.resetOriginalValues();
2442            }
2443    
2444            /**
2445             * Caches the trash entries in the entity cache if it is enabled.
2446             *
2447             * @param trashEntries the trash entries
2448             */
2449            @Override
2450            public void cacheResult(List<TrashEntry> trashEntries) {
2451                    for (TrashEntry trashEntry : trashEntries) {
2452                            if (entityCache.getResult(
2453                                                    TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2454                                                    TrashEntryImpl.class, trashEntry.getPrimaryKey()) == null) {
2455                                    cacheResult(trashEntry);
2456                            }
2457                            else {
2458                                    trashEntry.resetOriginalValues();
2459                            }
2460                    }
2461            }
2462    
2463            /**
2464             * Clears the cache for all trash entries.
2465             *
2466             * <p>
2467             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
2468             * </p>
2469             */
2470            @Override
2471            public void clearCache() {
2472                    entityCache.clearCache(TrashEntryImpl.class);
2473    
2474                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
2475                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2476                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2477            }
2478    
2479            /**
2480             * Clears the cache for the trash entry.
2481             *
2482             * <p>
2483             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
2484             * </p>
2485             */
2486            @Override
2487            public void clearCache(TrashEntry trashEntry) {
2488                    entityCache.removeResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2489                            TrashEntryImpl.class, trashEntry.getPrimaryKey());
2490    
2491                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2492                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2493    
2494                    clearUniqueFindersCache((TrashEntryModelImpl)trashEntry);
2495            }
2496    
2497            @Override
2498            public void clearCache(List<TrashEntry> trashEntries) {
2499                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2500                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2501    
2502                    for (TrashEntry trashEntry : trashEntries) {
2503                            entityCache.removeResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2504                                    TrashEntryImpl.class, trashEntry.getPrimaryKey());
2505    
2506                            clearUniqueFindersCache((TrashEntryModelImpl)trashEntry);
2507                    }
2508            }
2509    
2510            protected void cacheUniqueFindersCache(
2511                    TrashEntryModelImpl trashEntryModelImpl, boolean isNew) {
2512                    if (isNew) {
2513                            Object[] args = new Object[] {
2514                                            trashEntryModelImpl.getClassNameId(),
2515                                            trashEntryModelImpl.getClassPK()
2516                                    };
2517    
2518                            finderCache.putResult(FINDER_PATH_COUNT_BY_C_C, args,
2519                                    Long.valueOf(1));
2520                            finderCache.putResult(FINDER_PATH_FETCH_BY_C_C, args,
2521                                    trashEntryModelImpl);
2522                    }
2523                    else {
2524                            if ((trashEntryModelImpl.getColumnBitmask() &
2525                                            FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
2526                                    Object[] args = new Object[] {
2527                                                    trashEntryModelImpl.getClassNameId(),
2528                                                    trashEntryModelImpl.getClassPK()
2529                                            };
2530    
2531                                    finderCache.putResult(FINDER_PATH_COUNT_BY_C_C, args,
2532                                            Long.valueOf(1));
2533                                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_C, args,
2534                                            trashEntryModelImpl);
2535                            }
2536                    }
2537            }
2538    
2539            protected void clearUniqueFindersCache(
2540                    TrashEntryModelImpl trashEntryModelImpl) {
2541                    Object[] args = new Object[] {
2542                                    trashEntryModelImpl.getClassNameId(),
2543                                    trashEntryModelImpl.getClassPK()
2544                            };
2545    
2546                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
2547                    finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
2548    
2549                    if ((trashEntryModelImpl.getColumnBitmask() &
2550                                    FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
2551                            args = new Object[] {
2552                                            trashEntryModelImpl.getOriginalClassNameId(),
2553                                            trashEntryModelImpl.getOriginalClassPK()
2554                                    };
2555    
2556                            finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
2557                            finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
2558                    }
2559            }
2560    
2561            /**
2562             * Creates a new trash entry with the primary key. Does not add the trash entry to the database.
2563             *
2564             * @param entryId the primary key for the new trash entry
2565             * @return the new trash entry
2566             */
2567            @Override
2568            public TrashEntry create(long entryId) {
2569                    TrashEntry trashEntry = new TrashEntryImpl();
2570    
2571                    trashEntry.setNew(true);
2572                    trashEntry.setPrimaryKey(entryId);
2573    
2574                    trashEntry.setCompanyId(companyProvider.getCompanyId());
2575    
2576                    return trashEntry;
2577            }
2578    
2579            /**
2580             * Removes the trash entry with the primary key from the database. Also notifies the appropriate model listeners.
2581             *
2582             * @param entryId the primary key of the trash entry
2583             * @return the trash entry that was removed
2584             * @throws NoSuchEntryException if a trash entry with the primary key could not be found
2585             */
2586            @Override
2587            public TrashEntry remove(long entryId) throws NoSuchEntryException {
2588                    return remove((Serializable)entryId);
2589            }
2590    
2591            /**
2592             * Removes the trash entry with the primary key from the database. Also notifies the appropriate model listeners.
2593             *
2594             * @param primaryKey the primary key of the trash entry
2595             * @return the trash entry that was removed
2596             * @throws NoSuchEntryException if a trash entry with the primary key could not be found
2597             */
2598            @Override
2599            public TrashEntry remove(Serializable primaryKey)
2600                    throws NoSuchEntryException {
2601                    Session session = null;
2602    
2603                    try {
2604                            session = openSession();
2605    
2606                            TrashEntry trashEntry = (TrashEntry)session.get(TrashEntryImpl.class,
2607                                            primaryKey);
2608    
2609                            if (trashEntry == null) {
2610                                    if (_log.isWarnEnabled()) {
2611                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2612                                    }
2613    
2614                                    throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2615                                            primaryKey);
2616                            }
2617    
2618                            return remove(trashEntry);
2619                    }
2620                    catch (NoSuchEntryException nsee) {
2621                            throw nsee;
2622                    }
2623                    catch (Exception e) {
2624                            throw processException(e);
2625                    }
2626                    finally {
2627                            closeSession(session);
2628                    }
2629            }
2630    
2631            @Override
2632            protected TrashEntry removeImpl(TrashEntry trashEntry) {
2633                    trashEntry = toUnwrappedModel(trashEntry);
2634    
2635                    Session session = null;
2636    
2637                    try {
2638                            session = openSession();
2639    
2640                            if (!session.contains(trashEntry)) {
2641                                    trashEntry = (TrashEntry)session.get(TrashEntryImpl.class,
2642                                                    trashEntry.getPrimaryKeyObj());
2643                            }
2644    
2645                            if (trashEntry != null) {
2646                                    session.delete(trashEntry);
2647                            }
2648                    }
2649                    catch (Exception e) {
2650                            throw processException(e);
2651                    }
2652                    finally {
2653                            closeSession(session);
2654                    }
2655    
2656                    if (trashEntry != null) {
2657                            clearCache(trashEntry);
2658                    }
2659    
2660                    return trashEntry;
2661            }
2662    
2663            @Override
2664            public TrashEntry updateImpl(TrashEntry trashEntry) {
2665                    trashEntry = toUnwrappedModel(trashEntry);
2666    
2667                    boolean isNew = trashEntry.isNew();
2668    
2669                    TrashEntryModelImpl trashEntryModelImpl = (TrashEntryModelImpl)trashEntry;
2670    
2671                    Session session = null;
2672    
2673                    try {
2674                            session = openSession();
2675    
2676                            if (trashEntry.isNew()) {
2677                                    session.save(trashEntry);
2678    
2679                                    trashEntry.setNew(false);
2680                            }
2681                            else {
2682                                    trashEntry = (TrashEntry)session.merge(trashEntry);
2683                            }
2684                    }
2685                    catch (Exception e) {
2686                            throw processException(e);
2687                    }
2688                    finally {
2689                            closeSession(session);
2690                    }
2691    
2692                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2693    
2694                    if (isNew || !TrashEntryModelImpl.COLUMN_BITMASK_ENABLED) {
2695                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2696                    }
2697    
2698                    else {
2699                            if ((trashEntryModelImpl.getColumnBitmask() &
2700                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
2701                                    Object[] args = new Object[] {
2702                                                    trashEntryModelImpl.getOriginalGroupId()
2703                                            };
2704    
2705                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2706                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2707                                            args);
2708    
2709                                    args = new Object[] { trashEntryModelImpl.getGroupId() };
2710    
2711                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2712                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2713                                            args);
2714                            }
2715    
2716                            if ((trashEntryModelImpl.getColumnBitmask() &
2717                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
2718                                    Object[] args = new Object[] {
2719                                                    trashEntryModelImpl.getOriginalCompanyId()
2720                                            };
2721    
2722                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
2723                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
2724                                            args);
2725    
2726                                    args = new Object[] { trashEntryModelImpl.getCompanyId() };
2727    
2728                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
2729                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
2730                                            args);
2731                            }
2732    
2733                            if ((trashEntryModelImpl.getColumnBitmask() &
2734                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
2735                                    Object[] args = new Object[] {
2736                                                    trashEntryModelImpl.getOriginalGroupId(),
2737                                                    trashEntryModelImpl.getOriginalClassNameId()
2738                                            };
2739    
2740                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
2741                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
2742                                            args);
2743    
2744                                    args = new Object[] {
2745                                                    trashEntryModelImpl.getGroupId(),
2746                                                    trashEntryModelImpl.getClassNameId()
2747                                            };
2748    
2749                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
2750                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
2751                                            args);
2752                            }
2753                    }
2754    
2755                    entityCache.putResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2756                            TrashEntryImpl.class, trashEntry.getPrimaryKey(), trashEntry, false);
2757    
2758                    clearUniqueFindersCache(trashEntryModelImpl);
2759                    cacheUniqueFindersCache(trashEntryModelImpl, isNew);
2760    
2761                    trashEntry.resetOriginalValues();
2762    
2763                    return trashEntry;
2764            }
2765    
2766            protected TrashEntry toUnwrappedModel(TrashEntry trashEntry) {
2767                    if (trashEntry instanceof TrashEntryImpl) {
2768                            return trashEntry;
2769                    }
2770    
2771                    TrashEntryImpl trashEntryImpl = new TrashEntryImpl();
2772    
2773                    trashEntryImpl.setNew(trashEntry.isNew());
2774                    trashEntryImpl.setPrimaryKey(trashEntry.getPrimaryKey());
2775    
2776                    trashEntryImpl.setEntryId(trashEntry.getEntryId());
2777                    trashEntryImpl.setGroupId(trashEntry.getGroupId());
2778                    trashEntryImpl.setCompanyId(trashEntry.getCompanyId());
2779                    trashEntryImpl.setUserId(trashEntry.getUserId());
2780                    trashEntryImpl.setUserName(trashEntry.getUserName());
2781                    trashEntryImpl.setCreateDate(trashEntry.getCreateDate());
2782                    trashEntryImpl.setClassNameId(trashEntry.getClassNameId());
2783                    trashEntryImpl.setClassPK(trashEntry.getClassPK());
2784                    trashEntryImpl.setSystemEventSetKey(trashEntry.getSystemEventSetKey());
2785                    trashEntryImpl.setTypeSettings(trashEntry.getTypeSettings());
2786                    trashEntryImpl.setStatus(trashEntry.getStatus());
2787    
2788                    return trashEntryImpl;
2789            }
2790    
2791            /**
2792             * Returns the trash entry with the primary key or throws a {@link com.liferay.portal.exception.NoSuchModelException} if it could not be found.
2793             *
2794             * @param primaryKey the primary key of the trash entry
2795             * @return the trash entry
2796             * @throws NoSuchEntryException if a trash entry with the primary key could not be found
2797             */
2798            @Override
2799            public TrashEntry findByPrimaryKey(Serializable primaryKey)
2800                    throws NoSuchEntryException {
2801                    TrashEntry trashEntry = fetchByPrimaryKey(primaryKey);
2802    
2803                    if (trashEntry == null) {
2804                            if (_log.isWarnEnabled()) {
2805                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2806                            }
2807    
2808                            throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2809                                    primaryKey);
2810                    }
2811    
2812                    return trashEntry;
2813            }
2814    
2815            /**
2816             * Returns the trash entry with the primary key or throws a {@link NoSuchEntryException} if it could not be found.
2817             *
2818             * @param entryId the primary key of the trash entry
2819             * @return the trash entry
2820             * @throws NoSuchEntryException if a trash entry with the primary key could not be found
2821             */
2822            @Override
2823            public TrashEntry findByPrimaryKey(long entryId)
2824                    throws NoSuchEntryException {
2825                    return findByPrimaryKey((Serializable)entryId);
2826            }
2827    
2828            /**
2829             * Returns the trash entry with the primary key or returns <code>null</code> if it could not be found.
2830             *
2831             * @param primaryKey the primary key of the trash entry
2832             * @return the trash entry, or <code>null</code> if a trash entry with the primary key could not be found
2833             */
2834            @Override
2835            public TrashEntry fetchByPrimaryKey(Serializable primaryKey) {
2836                    TrashEntry trashEntry = (TrashEntry)entityCache.getResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2837                                    TrashEntryImpl.class, primaryKey);
2838    
2839                    if (trashEntry == _nullTrashEntry) {
2840                            return null;
2841                    }
2842    
2843                    if (trashEntry == null) {
2844                            Session session = null;
2845    
2846                            try {
2847                                    session = openSession();
2848    
2849                                    trashEntry = (TrashEntry)session.get(TrashEntryImpl.class,
2850                                                    primaryKey);
2851    
2852                                    if (trashEntry != null) {
2853                                            cacheResult(trashEntry);
2854                                    }
2855                                    else {
2856                                            entityCache.putResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2857                                                    TrashEntryImpl.class, primaryKey, _nullTrashEntry);
2858                                    }
2859                            }
2860                            catch (Exception e) {
2861                                    entityCache.removeResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2862                                            TrashEntryImpl.class, primaryKey);
2863    
2864                                    throw processException(e);
2865                            }
2866                            finally {
2867                                    closeSession(session);
2868                            }
2869                    }
2870    
2871                    return trashEntry;
2872            }
2873    
2874            /**
2875             * Returns the trash entry with the primary key or returns <code>null</code> if it could not be found.
2876             *
2877             * @param entryId the primary key of the trash entry
2878             * @return the trash entry, or <code>null</code> if a trash entry with the primary key could not be found
2879             */
2880            @Override
2881            public TrashEntry fetchByPrimaryKey(long entryId) {
2882                    return fetchByPrimaryKey((Serializable)entryId);
2883            }
2884    
2885            @Override
2886            public Map<Serializable, TrashEntry> fetchByPrimaryKeys(
2887                    Set<Serializable> primaryKeys) {
2888                    if (primaryKeys.isEmpty()) {
2889                            return Collections.emptyMap();
2890                    }
2891    
2892                    Map<Serializable, TrashEntry> map = new HashMap<Serializable, TrashEntry>();
2893    
2894                    if (primaryKeys.size() == 1) {
2895                            Iterator<Serializable> iterator = primaryKeys.iterator();
2896    
2897                            Serializable primaryKey = iterator.next();
2898    
2899                            TrashEntry trashEntry = fetchByPrimaryKey(primaryKey);
2900    
2901                            if (trashEntry != null) {
2902                                    map.put(primaryKey, trashEntry);
2903                            }
2904    
2905                            return map;
2906                    }
2907    
2908                    Set<Serializable> uncachedPrimaryKeys = null;
2909    
2910                    for (Serializable primaryKey : primaryKeys) {
2911                            TrashEntry trashEntry = (TrashEntry)entityCache.getResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2912                                            TrashEntryImpl.class, primaryKey);
2913    
2914                            if (trashEntry == null) {
2915                                    if (uncachedPrimaryKeys == null) {
2916                                            uncachedPrimaryKeys = new HashSet<Serializable>();
2917                                    }
2918    
2919                                    uncachedPrimaryKeys.add(primaryKey);
2920                            }
2921                            else {
2922                                    map.put(primaryKey, trashEntry);
2923                            }
2924                    }
2925    
2926                    if (uncachedPrimaryKeys == null) {
2927                            return map;
2928                    }
2929    
2930                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
2931                                    1);
2932    
2933                    query.append(_SQL_SELECT_TRASHENTRY_WHERE_PKS_IN);
2934    
2935                    for (Serializable primaryKey : uncachedPrimaryKeys) {
2936                            query.append(String.valueOf(primaryKey));
2937    
2938                            query.append(StringPool.COMMA);
2939                    }
2940    
2941                    query.setIndex(query.index() - 1);
2942    
2943                    query.append(StringPool.CLOSE_PARENTHESIS);
2944    
2945                    String sql = query.toString();
2946    
2947                    Session session = null;
2948    
2949                    try {
2950                            session = openSession();
2951    
2952                            Query q = session.createQuery(sql);
2953    
2954                            for (TrashEntry trashEntry : (List<TrashEntry>)q.list()) {
2955                                    map.put(trashEntry.getPrimaryKeyObj(), trashEntry);
2956    
2957                                    cacheResult(trashEntry);
2958    
2959                                    uncachedPrimaryKeys.remove(trashEntry.getPrimaryKeyObj());
2960                            }
2961    
2962                            for (Serializable primaryKey : uncachedPrimaryKeys) {
2963                                    entityCache.putResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2964                                            TrashEntryImpl.class, primaryKey, _nullTrashEntry);
2965                            }
2966                    }
2967                    catch (Exception e) {
2968                            throw processException(e);
2969                    }
2970                    finally {
2971                            closeSession(session);
2972                    }
2973    
2974                    return map;
2975            }
2976    
2977            /**
2978             * Returns all the trash entries.
2979             *
2980             * @return the trash entries
2981             */
2982            @Override
2983            public List<TrashEntry> findAll() {
2984                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2985            }
2986    
2987            /**
2988             * Returns a range of all the trash entries.
2989             *
2990             * <p>
2991             * 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.
2992             * </p>
2993             *
2994             * @param start the lower bound of the range of trash entries
2995             * @param end the upper bound of the range of trash entries (not inclusive)
2996             * @return the range of trash entries
2997             */
2998            @Override
2999            public List<TrashEntry> findAll(int start, int end) {
3000                    return findAll(start, end, null);
3001            }
3002    
3003            /**
3004             * Returns an ordered range of all the trash entries.
3005             *
3006             * <p>
3007             * 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.
3008             * </p>
3009             *
3010             * @param start the lower bound of the range of trash entries
3011             * @param end the upper bound of the range of trash entries (not inclusive)
3012             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3013             * @return the ordered range of trash entries
3014             */
3015            @Override
3016            public List<TrashEntry> findAll(int start, int end,
3017                    OrderByComparator<TrashEntry> orderByComparator) {
3018                    return findAll(start, end, orderByComparator, true);
3019            }
3020    
3021            /**
3022             * Returns an ordered range of all the trash entries.
3023             *
3024             * <p>
3025             * 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.
3026             * </p>
3027             *
3028             * @param start the lower bound of the range of trash entries
3029             * @param end the upper bound of the range of trash entries (not inclusive)
3030             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3031             * @param retrieveFromCache whether to retrieve from the finder cache
3032             * @return the ordered range of trash entries
3033             */
3034            @Override
3035            public List<TrashEntry> findAll(int start, int end,
3036                    OrderByComparator<TrashEntry> orderByComparator,
3037                    boolean retrieveFromCache) {
3038                    boolean pagination = true;
3039                    FinderPath finderPath = null;
3040                    Object[] finderArgs = null;
3041    
3042                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3043                                    (orderByComparator == null)) {
3044                            pagination = false;
3045                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3046                            finderArgs = FINDER_ARGS_EMPTY;
3047                    }
3048                    else {
3049                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3050                            finderArgs = new Object[] { start, end, orderByComparator };
3051                    }
3052    
3053                    List<TrashEntry> list = null;
3054    
3055                    if (retrieveFromCache) {
3056                            list = (List<TrashEntry>)finderCache.getResult(finderPath,
3057                                            finderArgs, this);
3058                    }
3059    
3060                    if (list == null) {
3061                            StringBundler query = null;
3062                            String sql = null;
3063    
3064                            if (orderByComparator != null) {
3065                                    query = new StringBundler(2 +
3066                                                    (orderByComparator.getOrderByFields().length * 3));
3067    
3068                                    query.append(_SQL_SELECT_TRASHENTRY);
3069    
3070                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3071                                            orderByComparator);
3072    
3073                                    sql = query.toString();
3074                            }
3075                            else {
3076                                    sql = _SQL_SELECT_TRASHENTRY;
3077    
3078                                    if (pagination) {
3079                                            sql = sql.concat(TrashEntryModelImpl.ORDER_BY_JPQL);
3080                                    }
3081                            }
3082    
3083                            Session session = null;
3084    
3085                            try {
3086                                    session = openSession();
3087    
3088                                    Query q = session.createQuery(sql);
3089    
3090                                    if (!pagination) {
3091                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
3092                                                            start, end, false);
3093    
3094                                            Collections.sort(list);
3095    
3096                                            list = Collections.unmodifiableList(list);
3097                                    }
3098                                    else {
3099                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
3100                                                            start, end);
3101                                    }
3102    
3103                                    cacheResult(list);
3104    
3105                                    finderCache.putResult(finderPath, finderArgs, list);
3106                            }
3107                            catch (Exception e) {
3108                                    finderCache.removeResult(finderPath, finderArgs);
3109    
3110                                    throw processException(e);
3111                            }
3112                            finally {
3113                                    closeSession(session);
3114                            }
3115                    }
3116    
3117                    return list;
3118            }
3119    
3120            /**
3121             * Removes all the trash entries from the database.
3122             *
3123             */
3124            @Override
3125            public void removeAll() {
3126                    for (TrashEntry trashEntry : findAll()) {
3127                            remove(trashEntry);
3128                    }
3129            }
3130    
3131            /**
3132             * Returns the number of trash entries.
3133             *
3134             * @return the number of trash entries
3135             */
3136            @Override
3137            public int countAll() {
3138                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
3139                                    FINDER_ARGS_EMPTY, this);
3140    
3141                    if (count == null) {
3142                            Session session = null;
3143    
3144                            try {
3145                                    session = openSession();
3146    
3147                                    Query q = session.createQuery(_SQL_COUNT_TRASHENTRY);
3148    
3149                                    count = (Long)q.uniqueResult();
3150    
3151                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
3152                                            count);
3153                            }
3154                            catch (Exception e) {
3155                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
3156                                            FINDER_ARGS_EMPTY);
3157    
3158                                    throw processException(e);
3159                            }
3160                            finally {
3161                                    closeSession(session);
3162                            }
3163                    }
3164    
3165                    return count.intValue();
3166            }
3167    
3168            @Override
3169            protected Map<String, Integer> getTableColumnsMap() {
3170                    return TrashEntryModelImpl.TABLE_COLUMNS_MAP;
3171            }
3172    
3173            /**
3174             * Initializes the trash entry persistence.
3175             */
3176            public void afterPropertiesSet() {
3177            }
3178    
3179            public void destroy() {
3180                    entityCache.removeCache(TrashEntryImpl.class.getName());
3181                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
3182                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3183                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3184            }
3185    
3186            @BeanReference(type = CompanyProviderWrapper.class)
3187            protected CompanyProvider companyProvider;
3188            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
3189            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
3190            private static final String _SQL_SELECT_TRASHENTRY = "SELECT trashEntry FROM TrashEntry trashEntry";
3191            private static final String _SQL_SELECT_TRASHENTRY_WHERE_PKS_IN = "SELECT trashEntry FROM TrashEntry trashEntry WHERE entryId IN (";
3192            private static final String _SQL_SELECT_TRASHENTRY_WHERE = "SELECT trashEntry FROM TrashEntry trashEntry WHERE ";
3193            private static final String _SQL_COUNT_TRASHENTRY = "SELECT COUNT(trashEntry) FROM TrashEntry trashEntry";
3194            private static final String _SQL_COUNT_TRASHENTRY_WHERE = "SELECT COUNT(trashEntry) FROM TrashEntry trashEntry WHERE ";
3195            private static final String _ORDER_BY_ENTITY_ALIAS = "trashEntry.";
3196            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No TrashEntry exists with the primary key ";
3197            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No TrashEntry exists with the key {";
3198            private static final Log _log = LogFactoryUtil.getLog(TrashEntryPersistenceImpl.class);
3199            private static final TrashEntry _nullTrashEntry = new TrashEntryImpl() {
3200                            @Override
3201                            public Object clone() {
3202                                    return this;
3203                            }
3204    
3205                            @Override
3206                            public CacheModel<TrashEntry> toCacheModel() {
3207                                    return _nullTrashEntryCacheModel;
3208                            }
3209                    };
3210    
3211            private static final CacheModel<TrashEntry> _nullTrashEntryCacheModel = new CacheModel<TrashEntry>() {
3212                            @Override
3213                            public TrashEntry toEntityModel() {
3214                                    return _nullTrashEntry;
3215                            }
3216                    };
3217    }