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