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