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