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