001    /**
002     * Copyright (c) 2000-2012 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;
016    
017    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderPath;
021    import com.liferay.portal.kernel.dao.orm.Query;
022    import com.liferay.portal.kernel.dao.orm.QueryPos;
023    import com.liferay.portal.kernel.dao.orm.QueryUtil;
024    import com.liferay.portal.kernel.dao.orm.Session;
025    import com.liferay.portal.kernel.exception.SystemException;
026    import com.liferay.portal.kernel.log.Log;
027    import com.liferay.portal.kernel.log.LogFactoryUtil;
028    import com.liferay.portal.kernel.util.CalendarUtil;
029    import com.liferay.portal.kernel.util.GetterUtil;
030    import com.liferay.portal.kernel.util.InstanceFactory;
031    import com.liferay.portal.kernel.util.OrderByComparator;
032    import com.liferay.portal.kernel.util.StringBundler;
033    import com.liferay.portal.kernel.util.StringPool;
034    import com.liferay.portal.kernel.util.StringUtil;
035    import com.liferay.portal.kernel.util.UnmodifiableList;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.model.CacheModel;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
040    
041    import com.liferay.portlet.trash.NoSuchEntryException;
042    import com.liferay.portlet.trash.model.TrashEntry;
043    import com.liferay.portlet.trash.model.impl.TrashEntryImpl;
044    import com.liferay.portlet.trash.model.impl.TrashEntryModelImpl;
045    
046    import java.io.Serializable;
047    
048    import java.util.ArrayList;
049    import java.util.Collections;
050    import java.util.Date;
051    import java.util.List;
052    
053    /**
054     * The persistence implementation for the trash entry service.
055     *
056     * <p>
057     * Caching information and settings can be found in <code>portal.properties</code>
058     * </p>
059     *
060     * @author Brian Wing Shun Chan
061     * @see TrashEntryPersistence
062     * @see TrashEntryUtil
063     * @generated
064     */
065    public class TrashEntryPersistenceImpl extends BasePersistenceImpl<TrashEntry>
066            implements TrashEntryPersistence {
067            /*
068             * NOTE FOR DEVELOPERS:
069             *
070             * 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.
071             */
072            public static final String FINDER_CLASS_NAME_ENTITY = TrashEntryImpl.class.getName();
073            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074                    ".List1";
075            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076                    ".List2";
077            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
078                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
079                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
080            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
081                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
082                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
083            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
084                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
085                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
086            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
087                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
088                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
089                            new String[] {
090                                    Long.class.getName(),
091                                    
092                            Integer.class.getName(), Integer.class.getName(),
093                                    OrderByComparator.class.getName()
094                            });
095            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
096                    new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
097                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
098                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
099                            new String[] { Long.class.getName() },
100                            TrashEntryModelImpl.GROUPID_COLUMN_BITMASK |
101                            TrashEntryModelImpl.CREATEDATE_COLUMN_BITMASK);
102            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
103                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
104                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
105                            new String[] { Long.class.getName() });
106    
107            /**
108             * Returns all the trash entries where groupId = &#63;.
109             *
110             * @param groupId the group ID
111             * @return the matching trash entries
112             * @throws SystemException if a system exception occurred
113             */
114            public List<TrashEntry> findByGroupId(long groupId)
115                    throws SystemException {
116                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
117            }
118    
119            /**
120             * Returns a range of all the trash entries where groupId = &#63;.
121             *
122             * <p>
123             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.trash.model.impl.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.
124             * </p>
125             *
126             * @param groupId the group ID
127             * @param start the lower bound of the range of trash entries
128             * @param end the upper bound of the range of trash entries (not inclusive)
129             * @return the range of matching trash entries
130             * @throws SystemException if a system exception occurred
131             */
132            public List<TrashEntry> findByGroupId(long groupId, int start, int end)
133                    throws SystemException {
134                    return findByGroupId(groupId, start, end, null);
135            }
136    
137            /**
138             * Returns an ordered range of all the trash entries where groupId = &#63;.
139             *
140             * <p>
141             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.trash.model.impl.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.
142             * </p>
143             *
144             * @param groupId the group ID
145             * @param start the lower bound of the range of trash entries
146             * @param end the upper bound of the range of trash entries (not inclusive)
147             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
148             * @return the ordered range of matching trash entries
149             * @throws SystemException if a system exception occurred
150             */
151            public List<TrashEntry> findByGroupId(long groupId, int start, int end,
152                    OrderByComparator orderByComparator) throws SystemException {
153                    boolean pagination = true;
154                    FinderPath finderPath = null;
155                    Object[] finderArgs = null;
156    
157                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
158                                    (orderByComparator == null)) {
159                            pagination = false;
160                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
161                            finderArgs = new Object[] { groupId };
162                    }
163                    else {
164                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
165                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
166                    }
167    
168                    List<TrashEntry> list = (List<TrashEntry>)FinderCacheUtil.getResult(finderPath,
169                                    finderArgs, this);
170    
171                    if ((list != null) && !list.isEmpty()) {
172                            for (TrashEntry trashEntry : list) {
173                                    if ((groupId != trashEntry.getGroupId())) {
174                                            list = null;
175    
176                                            break;
177                                    }
178                            }
179                    }
180    
181                    if (list == null) {
182                            StringBundler query = null;
183    
184                            if (orderByComparator != null) {
185                                    query = new StringBundler(3 +
186                                                    (orderByComparator.getOrderByFields().length * 3));
187                            }
188                            else {
189                                    query = new StringBundler(3);
190                            }
191    
192                            query.append(_SQL_SELECT_TRASHENTRY_WHERE);
193    
194                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
195    
196                            if (orderByComparator != null) {
197                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
198                                            orderByComparator);
199                            }
200                            else
201                             if (pagination) {
202                                    query.append(TrashEntryModelImpl.ORDER_BY_JPQL);
203                            }
204    
205                            String sql = query.toString();
206    
207                            Session session = null;
208    
209                            try {
210                                    session = openSession();
211    
212                                    Query q = session.createQuery(sql);
213    
214                                    QueryPos qPos = QueryPos.getInstance(q);
215    
216                                    qPos.add(groupId);
217    
218                                    if (!pagination) {
219                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
220                                                            start, end, false);
221    
222                                            Collections.sort(list);
223    
224                                            list = new UnmodifiableList<TrashEntry>(list);
225                                    }
226                                    else {
227                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
228                                                            start, end);
229                                    }
230    
231                                    cacheResult(list);
232    
233                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
234                            }
235                            catch (Exception e) {
236                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
237    
238                                    throw processException(e);
239                            }
240                            finally {
241                                    closeSession(session);
242                            }
243                    }
244    
245                    return list;
246            }
247    
248            /**
249             * Returns the first trash entry in the ordered set where groupId = &#63;.
250             *
251             * @param groupId the group ID
252             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
253             * @return the first matching trash entry
254             * @throws com.liferay.portlet.trash.NoSuchEntryException if a matching trash entry could not be found
255             * @throws SystemException if a system exception occurred
256             */
257            public TrashEntry findByGroupId_First(long groupId,
258                    OrderByComparator orderByComparator)
259                    throws NoSuchEntryException, SystemException {
260                    TrashEntry trashEntry = fetchByGroupId_First(groupId, orderByComparator);
261    
262                    if (trashEntry != null) {
263                            return trashEntry;
264                    }
265    
266                    StringBundler msg = new StringBundler(4);
267    
268                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
269    
270                    msg.append("groupId=");
271                    msg.append(groupId);
272    
273                    msg.append(StringPool.CLOSE_CURLY_BRACE);
274    
275                    throw new NoSuchEntryException(msg.toString());
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, or <code>null</code> if a matching trash entry could not be found
284             * @throws SystemException if a system exception occurred
285             */
286            public TrashEntry fetchByGroupId_First(long groupId,
287                    OrderByComparator orderByComparator) throws SystemException {
288                    List<TrashEntry> list = findByGroupId(groupId, 0, 1, orderByComparator);
289    
290                    if (!list.isEmpty()) {
291                            return list.get(0);
292                    }
293    
294                    return null;
295            }
296    
297            /**
298             * Returns the last trash entry in the ordered set where groupId = &#63;.
299             *
300             * @param groupId the group ID
301             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
302             * @return the last matching trash entry
303             * @throws com.liferay.portlet.trash.NoSuchEntryException if a matching trash entry could not be found
304             * @throws SystemException if a system exception occurred
305             */
306            public TrashEntry findByGroupId_Last(long groupId,
307                    OrderByComparator orderByComparator)
308                    throws NoSuchEntryException, SystemException {
309                    TrashEntry trashEntry = fetchByGroupId_Last(groupId, orderByComparator);
310    
311                    if (trashEntry != null) {
312                            return trashEntry;
313                    }
314    
315                    StringBundler msg = new StringBundler(4);
316    
317                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
318    
319                    msg.append("groupId=");
320                    msg.append(groupId);
321    
322                    msg.append(StringPool.CLOSE_CURLY_BRACE);
323    
324                    throw new NoSuchEntryException(msg.toString());
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, or <code>null</code> if a matching trash entry could not be found
333             * @throws SystemException if a system exception occurred
334             */
335            public TrashEntry fetchByGroupId_Last(long groupId,
336                    OrderByComparator orderByComparator) throws SystemException {
337                    int count = countByGroupId(groupId);
338    
339                    List<TrashEntry> list = findByGroupId(groupId, count - 1, count,
340                                    orderByComparator);
341    
342                    if (!list.isEmpty()) {
343                            return list.get(0);
344                    }
345    
346                    return null;
347            }
348    
349            /**
350             * Returns the trash entries before and after the current trash entry in the ordered set where groupId = &#63;.
351             *
352             * @param entryId the primary key of the current trash entry
353             * @param groupId the group ID
354             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
355             * @return the previous, current, and next trash entry
356             * @throws com.liferay.portlet.trash.NoSuchEntryException if a trash entry with the primary key could not be found
357             * @throws SystemException if a system exception occurred
358             */
359            public TrashEntry[] findByGroupId_PrevAndNext(long entryId, long groupId,
360                    OrderByComparator orderByComparator)
361                    throws NoSuchEntryException, SystemException {
362                    TrashEntry trashEntry = findByPrimaryKey(entryId);
363    
364                    Session session = null;
365    
366                    try {
367                            session = openSession();
368    
369                            TrashEntry[] array = new TrashEntryImpl[3];
370    
371                            array[0] = getByGroupId_PrevAndNext(session, trashEntry, groupId,
372                                            orderByComparator, true);
373    
374                            array[1] = trashEntry;
375    
376                            array[2] = getByGroupId_PrevAndNext(session, trashEntry, groupId,
377                                            orderByComparator, false);
378    
379                            return array;
380                    }
381                    catch (Exception e) {
382                            throw processException(e);
383                    }
384                    finally {
385                            closeSession(session);
386                    }
387            }
388    
389            protected TrashEntry getByGroupId_PrevAndNext(Session session,
390                    TrashEntry trashEntry, long groupId,
391                    OrderByComparator orderByComparator, boolean previous) {
392                    StringBundler query = null;
393    
394                    if (orderByComparator != null) {
395                            query = new StringBundler(6 +
396                                            (orderByComparator.getOrderByFields().length * 6));
397                    }
398                    else {
399                            query = new StringBundler(3);
400                    }
401    
402                    query.append(_SQL_SELECT_TRASHENTRY_WHERE);
403    
404                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
405    
406                    if (orderByComparator != null) {
407                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
408    
409                            if (orderByConditionFields.length > 0) {
410                                    query.append(WHERE_AND);
411                            }
412    
413                            for (int i = 0; i < orderByConditionFields.length; i++) {
414                                    query.append(_ORDER_BY_ENTITY_ALIAS);
415                                    query.append(orderByConditionFields[i]);
416    
417                                    if ((i + 1) < orderByConditionFields.length) {
418                                            if (orderByComparator.isAscending() ^ previous) {
419                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
420                                            }
421                                            else {
422                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
423                                            }
424                                    }
425                                    else {
426                                            if (orderByComparator.isAscending() ^ previous) {
427                                                    query.append(WHERE_GREATER_THAN);
428                                            }
429                                            else {
430                                                    query.append(WHERE_LESSER_THAN);
431                                            }
432                                    }
433                            }
434    
435                            query.append(ORDER_BY_CLAUSE);
436    
437                            String[] orderByFields = orderByComparator.getOrderByFields();
438    
439                            for (int i = 0; i < orderByFields.length; i++) {
440                                    query.append(_ORDER_BY_ENTITY_ALIAS);
441                                    query.append(orderByFields[i]);
442    
443                                    if ((i + 1) < orderByFields.length) {
444                                            if (orderByComparator.isAscending() ^ previous) {
445                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
446                                            }
447                                            else {
448                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
449                                            }
450                                    }
451                                    else {
452                                            if (orderByComparator.isAscending() ^ previous) {
453                                                    query.append(ORDER_BY_ASC);
454                                            }
455                                            else {
456                                                    query.append(ORDER_BY_DESC);
457                                            }
458                                    }
459                            }
460                    }
461                    else {
462                            query.append(TrashEntryModelImpl.ORDER_BY_JPQL);
463                    }
464    
465                    String sql = query.toString();
466    
467                    Query q = session.createQuery(sql);
468    
469                    q.setFirstResult(0);
470                    q.setMaxResults(2);
471    
472                    QueryPos qPos = QueryPos.getInstance(q);
473    
474                    qPos.add(groupId);
475    
476                    if (orderByComparator != null) {
477                            Object[] values = orderByComparator.getOrderByConditionValues(trashEntry);
478    
479                            for (Object value : values) {
480                                    qPos.add(value);
481                            }
482                    }
483    
484                    List<TrashEntry> list = q.list();
485    
486                    if (list.size() == 2) {
487                            return list.get(1);
488                    }
489                    else {
490                            return null;
491                    }
492            }
493    
494            /**
495             * Removes all the trash entries where groupId = &#63; from the database.
496             *
497             * @param groupId the group ID
498             * @throws SystemException if a system exception occurred
499             */
500            public void removeByGroupId(long groupId) throws SystemException {
501                    for (TrashEntry trashEntry : findByGroupId(groupId, QueryUtil.ALL_POS,
502                                    QueryUtil.ALL_POS, null)) {
503                            remove(trashEntry);
504                    }
505            }
506    
507            /**
508             * Returns the number of trash entries where groupId = &#63;.
509             *
510             * @param groupId the group ID
511             * @return the number of matching trash entries
512             * @throws SystemException if a system exception occurred
513             */
514            public int countByGroupId(long groupId) throws SystemException {
515                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
516    
517                    Object[] finderArgs = new Object[] { groupId };
518    
519                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
520                                    this);
521    
522                    if (count == null) {
523                            StringBundler query = new StringBundler(2);
524    
525                            query.append(_SQL_COUNT_TRASHENTRY_WHERE);
526    
527                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
528    
529                            String sql = query.toString();
530    
531                            Session session = null;
532    
533                            try {
534                                    session = openSession();
535    
536                                    Query q = session.createQuery(sql);
537    
538                                    QueryPos qPos = QueryPos.getInstance(q);
539    
540                                    qPos.add(groupId);
541    
542                                    count = (Long)q.uniqueResult();
543    
544                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
545                            }
546                            catch (Exception e) {
547                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
548    
549                                    throw processException(e);
550                            }
551                            finally {
552                                    closeSession(session);
553                            }
554                    }
555    
556                    return count.intValue();
557            }
558    
559            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "trashEntry.groupId = ?";
560            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
561                    new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
562                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
563                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
564                            new String[] {
565                                    Long.class.getName(),
566                                    
567                            Integer.class.getName(), Integer.class.getName(),
568                                    OrderByComparator.class.getName()
569                            });
570            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
571                    new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
572                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
573                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
574                            new String[] { Long.class.getName() },
575                            TrashEntryModelImpl.COMPANYID_COLUMN_BITMASK |
576                            TrashEntryModelImpl.CREATEDATE_COLUMN_BITMASK);
577            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
578                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
579                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
580                            new String[] { Long.class.getName() });
581    
582            /**
583             * Returns all the trash entries where companyId = &#63;.
584             *
585             * @param companyId the company ID
586             * @return the matching trash entries
587             * @throws SystemException if a system exception occurred
588             */
589            public List<TrashEntry> findByCompanyId(long companyId)
590                    throws SystemException {
591                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
592                            null);
593            }
594    
595            /**
596             * Returns a range of all the trash entries where companyId = &#63;.
597             *
598             * <p>
599             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.trash.model.impl.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.
600             * </p>
601             *
602             * @param companyId the company ID
603             * @param start the lower bound of the range of trash entries
604             * @param end the upper bound of the range of trash entries (not inclusive)
605             * @return the range of matching trash entries
606             * @throws SystemException if a system exception occurred
607             */
608            public List<TrashEntry> findByCompanyId(long companyId, int start, int end)
609                    throws SystemException {
610                    return findByCompanyId(companyId, start, end, null);
611            }
612    
613            /**
614             * Returns an ordered range of all the trash entries where companyId = &#63;.
615             *
616             * <p>
617             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.trash.model.impl.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.
618             * </p>
619             *
620             * @param companyId the company ID
621             * @param start the lower bound of the range of trash entries
622             * @param end the upper bound of the range of trash entries (not inclusive)
623             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
624             * @return the ordered range of matching trash entries
625             * @throws SystemException if a system exception occurred
626             */
627            public List<TrashEntry> findByCompanyId(long companyId, int start, int end,
628                    OrderByComparator orderByComparator) throws SystemException {
629                    boolean pagination = true;
630                    FinderPath finderPath = null;
631                    Object[] finderArgs = null;
632    
633                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
634                                    (orderByComparator == null)) {
635                            pagination = false;
636                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
637                            finderArgs = new Object[] { companyId };
638                    }
639                    else {
640                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
641                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
642                    }
643    
644                    List<TrashEntry> list = (List<TrashEntry>)FinderCacheUtil.getResult(finderPath,
645                                    finderArgs, this);
646    
647                    if ((list != null) && !list.isEmpty()) {
648                            for (TrashEntry trashEntry : list) {
649                                    if ((companyId != trashEntry.getCompanyId())) {
650                                            list = null;
651    
652                                            break;
653                                    }
654                            }
655                    }
656    
657                    if (list == null) {
658                            StringBundler query = null;
659    
660                            if (orderByComparator != null) {
661                                    query = new StringBundler(3 +
662                                                    (orderByComparator.getOrderByFields().length * 3));
663                            }
664                            else {
665                                    query = new StringBundler(3);
666                            }
667    
668                            query.append(_SQL_SELECT_TRASHENTRY_WHERE);
669    
670                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
671    
672                            if (orderByComparator != null) {
673                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
674                                            orderByComparator);
675                            }
676                            else
677                             if (pagination) {
678                                    query.append(TrashEntryModelImpl.ORDER_BY_JPQL);
679                            }
680    
681                            String sql = query.toString();
682    
683                            Session session = null;
684    
685                            try {
686                                    session = openSession();
687    
688                                    Query q = session.createQuery(sql);
689    
690                                    QueryPos qPos = QueryPos.getInstance(q);
691    
692                                    qPos.add(companyId);
693    
694                                    if (!pagination) {
695                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
696                                                            start, end, false);
697    
698                                            Collections.sort(list);
699    
700                                            list = new UnmodifiableList<TrashEntry>(list);
701                                    }
702                                    else {
703                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
704                                                            start, end);
705                                    }
706    
707                                    cacheResult(list);
708    
709                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
710                            }
711                            catch (Exception e) {
712                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
713    
714                                    throw processException(e);
715                            }
716                            finally {
717                                    closeSession(session);
718                            }
719                    }
720    
721                    return list;
722            }
723    
724            /**
725             * Returns the first trash entry in the ordered set where companyId = &#63;.
726             *
727             * @param companyId the company ID
728             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
729             * @return the first matching trash entry
730             * @throws com.liferay.portlet.trash.NoSuchEntryException if a matching trash entry could not be found
731             * @throws SystemException if a system exception occurred
732             */
733            public TrashEntry findByCompanyId_First(long companyId,
734                    OrderByComparator orderByComparator)
735                    throws NoSuchEntryException, SystemException {
736                    TrashEntry trashEntry = fetchByCompanyId_First(companyId,
737                                    orderByComparator);
738    
739                    if (trashEntry != null) {
740                            return trashEntry;
741                    }
742    
743                    StringBundler msg = new StringBundler(4);
744    
745                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
746    
747                    msg.append("companyId=");
748                    msg.append(companyId);
749    
750                    msg.append(StringPool.CLOSE_CURLY_BRACE);
751    
752                    throw new NoSuchEntryException(msg.toString());
753            }
754    
755            /**
756             * Returns the first trash entry in the ordered set where companyId = &#63;.
757             *
758             * @param companyId the company ID
759             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
760             * @return the first matching trash entry, or <code>null</code> if a matching trash entry could not be found
761             * @throws SystemException if a system exception occurred
762             */
763            public TrashEntry fetchByCompanyId_First(long companyId,
764                    OrderByComparator orderByComparator) throws SystemException {
765                    List<TrashEntry> list = findByCompanyId(companyId, 0, 1,
766                                    orderByComparator);
767    
768                    if (!list.isEmpty()) {
769                            return list.get(0);
770                    }
771    
772                    return null;
773            }
774    
775            /**
776             * Returns the last trash entry in the ordered set where companyId = &#63;.
777             *
778             * @param companyId the company ID
779             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
780             * @return the last matching trash entry
781             * @throws com.liferay.portlet.trash.NoSuchEntryException if a matching trash entry could not be found
782             * @throws SystemException if a system exception occurred
783             */
784            public TrashEntry findByCompanyId_Last(long companyId,
785                    OrderByComparator orderByComparator)
786                    throws NoSuchEntryException, SystemException {
787                    TrashEntry trashEntry = fetchByCompanyId_Last(companyId,
788                                    orderByComparator);
789    
790                    if (trashEntry != null) {
791                            return trashEntry;
792                    }
793    
794                    StringBundler msg = new StringBundler(4);
795    
796                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
797    
798                    msg.append("companyId=");
799                    msg.append(companyId);
800    
801                    msg.append(StringPool.CLOSE_CURLY_BRACE);
802    
803                    throw new NoSuchEntryException(msg.toString());
804            }
805    
806            /**
807             * Returns the last trash entry in the ordered set where companyId = &#63;.
808             *
809             * @param companyId the company ID
810             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
811             * @return the last matching trash entry, or <code>null</code> if a matching trash entry could not be found
812             * @throws SystemException if a system exception occurred
813             */
814            public TrashEntry fetchByCompanyId_Last(long companyId,
815                    OrderByComparator orderByComparator) throws SystemException {
816                    int count = countByCompanyId(companyId);
817    
818                    List<TrashEntry> list = findByCompanyId(companyId, count - 1, count,
819                                    orderByComparator);
820    
821                    if (!list.isEmpty()) {
822                            return list.get(0);
823                    }
824    
825                    return null;
826            }
827    
828            /**
829             * Returns the trash entries before and after the current trash entry in the ordered set where companyId = &#63;.
830             *
831             * @param entryId the primary key of the current trash entry
832             * @param companyId the company ID
833             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
834             * @return the previous, current, and next trash entry
835             * @throws com.liferay.portlet.trash.NoSuchEntryException if a trash entry with the primary key could not be found
836             * @throws SystemException if a system exception occurred
837             */
838            public TrashEntry[] findByCompanyId_PrevAndNext(long entryId,
839                    long companyId, OrderByComparator orderByComparator)
840                    throws NoSuchEntryException, SystemException {
841                    TrashEntry trashEntry = findByPrimaryKey(entryId);
842    
843                    Session session = null;
844    
845                    try {
846                            session = openSession();
847    
848                            TrashEntry[] array = new TrashEntryImpl[3];
849    
850                            array[0] = getByCompanyId_PrevAndNext(session, trashEntry,
851                                            companyId, orderByComparator, true);
852    
853                            array[1] = trashEntry;
854    
855                            array[2] = getByCompanyId_PrevAndNext(session, trashEntry,
856                                            companyId, orderByComparator, false);
857    
858                            return array;
859                    }
860                    catch (Exception e) {
861                            throw processException(e);
862                    }
863                    finally {
864                            closeSession(session);
865                    }
866            }
867    
868            protected TrashEntry getByCompanyId_PrevAndNext(Session session,
869                    TrashEntry trashEntry, long companyId,
870                    OrderByComparator orderByComparator, boolean previous) {
871                    StringBundler query = null;
872    
873                    if (orderByComparator != null) {
874                            query = new StringBundler(6 +
875                                            (orderByComparator.getOrderByFields().length * 6));
876                    }
877                    else {
878                            query = new StringBundler(3);
879                    }
880    
881                    query.append(_SQL_SELECT_TRASHENTRY_WHERE);
882    
883                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
884    
885                    if (orderByComparator != null) {
886                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
887    
888                            if (orderByConditionFields.length > 0) {
889                                    query.append(WHERE_AND);
890                            }
891    
892                            for (int i = 0; i < orderByConditionFields.length; i++) {
893                                    query.append(_ORDER_BY_ENTITY_ALIAS);
894                                    query.append(orderByConditionFields[i]);
895    
896                                    if ((i + 1) < orderByConditionFields.length) {
897                                            if (orderByComparator.isAscending() ^ previous) {
898                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
899                                            }
900                                            else {
901                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
902                                            }
903                                    }
904                                    else {
905                                            if (orderByComparator.isAscending() ^ previous) {
906                                                    query.append(WHERE_GREATER_THAN);
907                                            }
908                                            else {
909                                                    query.append(WHERE_LESSER_THAN);
910                                            }
911                                    }
912                            }
913    
914                            query.append(ORDER_BY_CLAUSE);
915    
916                            String[] orderByFields = orderByComparator.getOrderByFields();
917    
918                            for (int i = 0; i < orderByFields.length; i++) {
919                                    query.append(_ORDER_BY_ENTITY_ALIAS);
920                                    query.append(orderByFields[i]);
921    
922                                    if ((i + 1) < orderByFields.length) {
923                                            if (orderByComparator.isAscending() ^ previous) {
924                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
925                                            }
926                                            else {
927                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
928                                            }
929                                    }
930                                    else {
931                                            if (orderByComparator.isAscending() ^ previous) {
932                                                    query.append(ORDER_BY_ASC);
933                                            }
934                                            else {
935                                                    query.append(ORDER_BY_DESC);
936                                            }
937                                    }
938                            }
939                    }
940                    else {
941                            query.append(TrashEntryModelImpl.ORDER_BY_JPQL);
942                    }
943    
944                    String sql = query.toString();
945    
946                    Query q = session.createQuery(sql);
947    
948                    q.setFirstResult(0);
949                    q.setMaxResults(2);
950    
951                    QueryPos qPos = QueryPos.getInstance(q);
952    
953                    qPos.add(companyId);
954    
955                    if (orderByComparator != null) {
956                            Object[] values = orderByComparator.getOrderByConditionValues(trashEntry);
957    
958                            for (Object value : values) {
959                                    qPos.add(value);
960                            }
961                    }
962    
963                    List<TrashEntry> list = q.list();
964    
965                    if (list.size() == 2) {
966                            return list.get(1);
967                    }
968                    else {
969                            return null;
970                    }
971            }
972    
973            /**
974             * Removes all the trash entries where companyId = &#63; from the database.
975             *
976             * @param companyId the company ID
977             * @throws SystemException if a system exception occurred
978             */
979            public void removeByCompanyId(long companyId) throws SystemException {
980                    for (TrashEntry trashEntry : findByCompanyId(companyId,
981                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
982                            remove(trashEntry);
983                    }
984            }
985    
986            /**
987             * Returns the number of trash entries where companyId = &#63;.
988             *
989             * @param companyId the company ID
990             * @return the number of matching trash entries
991             * @throws SystemException if a system exception occurred
992             */
993            public int countByCompanyId(long companyId) throws SystemException {
994                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
995    
996                    Object[] finderArgs = new Object[] { companyId };
997    
998                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
999                                    this);
1000    
1001                    if (count == null) {
1002                            StringBundler query = new StringBundler(2);
1003    
1004                            query.append(_SQL_COUNT_TRASHENTRY_WHERE);
1005    
1006                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1007    
1008                            String sql = query.toString();
1009    
1010                            Session session = null;
1011    
1012                            try {
1013                                    session = openSession();
1014    
1015                                    Query q = session.createQuery(sql);
1016    
1017                                    QueryPos qPos = QueryPos.getInstance(q);
1018    
1019                                    qPos.add(companyId);
1020    
1021                                    count = (Long)q.uniqueResult();
1022    
1023                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1024                            }
1025                            catch (Exception e) {
1026                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1027    
1028                                    throw processException(e);
1029                            }
1030                            finally {
1031                                    closeSession(session);
1032                            }
1033                    }
1034    
1035                    return count.intValue();
1036            }
1037    
1038            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "trashEntry.companyId = ?";
1039            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LTCD = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
1040                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
1041                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_LtCD",
1042                            new String[] {
1043                                    Long.class.getName(), Date.class.getName(),
1044                                    
1045                            Integer.class.getName(), Integer.class.getName(),
1046                                    OrderByComparator.class.getName()
1047                            });
1048            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LTCD = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
1049                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
1050                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_LtCD",
1051                            new String[] { Long.class.getName(), Date.class.getName() });
1052    
1053            /**
1054             * Returns all the trash entries where groupId = &#63; and createDate &lt; &#63;.
1055             *
1056             * @param groupId the group ID
1057             * @param createDate the create date
1058             * @return the matching trash entries
1059             * @throws SystemException if a system exception occurred
1060             */
1061            public List<TrashEntry> findByG_LtCD(long groupId, Date createDate)
1062                    throws SystemException {
1063                    return findByG_LtCD(groupId, createDate, QueryUtil.ALL_POS,
1064                            QueryUtil.ALL_POS, null);
1065            }
1066    
1067            /**
1068             * Returns a range of all the trash entries where groupId = &#63; and createDate &lt; &#63;.
1069             *
1070             * <p>
1071             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.trash.model.impl.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.
1072             * </p>
1073             *
1074             * @param groupId the group ID
1075             * @param createDate the create date
1076             * @param start the lower bound of the range of trash entries
1077             * @param end the upper bound of the range of trash entries (not inclusive)
1078             * @return the range of matching trash entries
1079             * @throws SystemException if a system exception occurred
1080             */
1081            public List<TrashEntry> findByG_LtCD(long groupId, Date createDate,
1082                    int start, int end) throws SystemException {
1083                    return findByG_LtCD(groupId, createDate, start, end, null);
1084            }
1085    
1086            /**
1087             * Returns an ordered range of all the trash entries where groupId = &#63; and createDate &lt; &#63;.
1088             *
1089             * <p>
1090             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.trash.model.impl.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.
1091             * </p>
1092             *
1093             * @param groupId the group ID
1094             * @param createDate the create date
1095             * @param start the lower bound of the range of trash entries
1096             * @param end the upper bound of the range of trash entries (not inclusive)
1097             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1098             * @return the ordered range of matching trash entries
1099             * @throws SystemException if a system exception occurred
1100             */
1101            public List<TrashEntry> findByG_LtCD(long groupId, Date createDate,
1102                    int start, int end, OrderByComparator orderByComparator)
1103                    throws SystemException {
1104                    boolean pagination = true;
1105                    FinderPath finderPath = null;
1106                    Object[] finderArgs = null;
1107    
1108                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LTCD;
1109                    finderArgs = new Object[] {
1110                                    groupId, createDate,
1111                                    
1112                                    start, end, orderByComparator
1113                            };
1114    
1115                    List<TrashEntry> list = (List<TrashEntry>)FinderCacheUtil.getResult(finderPath,
1116                                    finderArgs, this);
1117    
1118                    if ((list != null) && !list.isEmpty()) {
1119                            for (TrashEntry trashEntry : list) {
1120                                    if ((groupId != trashEntry.getGroupId()) ||
1121                                                    !Validator.equals(createDate, trashEntry.getCreateDate())) {
1122                                            list = null;
1123    
1124                                            break;
1125                                    }
1126                            }
1127                    }
1128    
1129                    if (list == null) {
1130                            StringBundler query = null;
1131    
1132                            if (orderByComparator != null) {
1133                                    query = new StringBundler(4 +
1134                                                    (orderByComparator.getOrderByFields().length * 3));
1135                            }
1136                            else {
1137                                    query = new StringBundler(4);
1138                            }
1139    
1140                            query.append(_SQL_SELECT_TRASHENTRY_WHERE);
1141    
1142                            query.append(_FINDER_COLUMN_G_LTCD_GROUPID_2);
1143    
1144                            boolean bindCreateDate = false;
1145    
1146                            if (createDate == null) {
1147                                    query.append(_FINDER_COLUMN_G_LTCD_CREATEDATE_1);
1148                            }
1149                            else {
1150                                    bindCreateDate = true;
1151    
1152                                    query.append(_FINDER_COLUMN_G_LTCD_CREATEDATE_2);
1153                            }
1154    
1155                            if (orderByComparator != null) {
1156                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1157                                            orderByComparator);
1158                            }
1159                            else
1160                             if (pagination) {
1161                                    query.append(TrashEntryModelImpl.ORDER_BY_JPQL);
1162                            }
1163    
1164                            String sql = query.toString();
1165    
1166                            Session session = null;
1167    
1168                            try {
1169                                    session = openSession();
1170    
1171                                    Query q = session.createQuery(sql);
1172    
1173                                    QueryPos qPos = QueryPos.getInstance(q);
1174    
1175                                    qPos.add(groupId);
1176    
1177                                    if (bindCreateDate) {
1178                                            qPos.add(CalendarUtil.getTimestamp(createDate));
1179                                    }
1180    
1181                                    if (!pagination) {
1182                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
1183                                                            start, end, false);
1184    
1185                                            Collections.sort(list);
1186    
1187                                            list = new UnmodifiableList<TrashEntry>(list);
1188                                    }
1189                                    else {
1190                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
1191                                                            start, end);
1192                                    }
1193    
1194                                    cacheResult(list);
1195    
1196                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1197                            }
1198                            catch (Exception e) {
1199                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1200    
1201                                    throw processException(e);
1202                            }
1203                            finally {
1204                                    closeSession(session);
1205                            }
1206                    }
1207    
1208                    return list;
1209            }
1210    
1211            /**
1212             * Returns the first trash entry in the ordered set where groupId = &#63; and createDate &lt; &#63;.
1213             *
1214             * @param groupId the group ID
1215             * @param createDate the create date
1216             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1217             * @return the first matching trash entry
1218             * @throws com.liferay.portlet.trash.NoSuchEntryException if a matching trash entry could not be found
1219             * @throws SystemException if a system exception occurred
1220             */
1221            public TrashEntry findByG_LtCD_First(long groupId, Date createDate,
1222                    OrderByComparator orderByComparator)
1223                    throws NoSuchEntryException, SystemException {
1224                    TrashEntry trashEntry = fetchByG_LtCD_First(groupId, createDate,
1225                                    orderByComparator);
1226    
1227                    if (trashEntry != null) {
1228                            return trashEntry;
1229                    }
1230    
1231                    StringBundler msg = new StringBundler(6);
1232    
1233                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1234    
1235                    msg.append("groupId=");
1236                    msg.append(groupId);
1237    
1238                    msg.append(", createDate=");
1239                    msg.append(createDate);
1240    
1241                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1242    
1243                    throw new NoSuchEntryException(msg.toString());
1244            }
1245    
1246            /**
1247             * Returns the first trash entry in the ordered set where groupId = &#63; and createDate &lt; &#63;.
1248             *
1249             * @param groupId the group ID
1250             * @param createDate the create date
1251             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1252             * @return the first matching trash entry, or <code>null</code> if a matching trash entry could not be found
1253             * @throws SystemException if a system exception occurred
1254             */
1255            public TrashEntry fetchByG_LtCD_First(long groupId, Date createDate,
1256                    OrderByComparator orderByComparator) throws SystemException {
1257                    List<TrashEntry> list = findByG_LtCD(groupId, createDate, 0, 1,
1258                                    orderByComparator);
1259    
1260                    if (!list.isEmpty()) {
1261                            return list.get(0);
1262                    }
1263    
1264                    return null;
1265            }
1266    
1267            /**
1268             * Returns the last trash entry in the ordered set where groupId = &#63; and createDate &lt; &#63;.
1269             *
1270             * @param groupId the group ID
1271             * @param createDate the create date
1272             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1273             * @return the last matching trash entry
1274             * @throws com.liferay.portlet.trash.NoSuchEntryException if a matching trash entry could not be found
1275             * @throws SystemException if a system exception occurred
1276             */
1277            public TrashEntry findByG_LtCD_Last(long groupId, Date createDate,
1278                    OrderByComparator orderByComparator)
1279                    throws NoSuchEntryException, SystemException {
1280                    TrashEntry trashEntry = fetchByG_LtCD_Last(groupId, createDate,
1281                                    orderByComparator);
1282    
1283                    if (trashEntry != null) {
1284                            return trashEntry;
1285                    }
1286    
1287                    StringBundler msg = new StringBundler(6);
1288    
1289                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1290    
1291                    msg.append("groupId=");
1292                    msg.append(groupId);
1293    
1294                    msg.append(", createDate=");
1295                    msg.append(createDate);
1296    
1297                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1298    
1299                    throw new NoSuchEntryException(msg.toString());
1300            }
1301    
1302            /**
1303             * Returns the last trash entry in the ordered set where groupId = &#63; and createDate &lt; &#63;.
1304             *
1305             * @param groupId the group ID
1306             * @param createDate the create date
1307             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1308             * @return the last matching trash entry, or <code>null</code> if a matching trash entry could not be found
1309             * @throws SystemException if a system exception occurred
1310             */
1311            public TrashEntry fetchByG_LtCD_Last(long groupId, Date createDate,
1312                    OrderByComparator orderByComparator) throws SystemException {
1313                    int count = countByG_LtCD(groupId, createDate);
1314    
1315                    List<TrashEntry> list = findByG_LtCD(groupId, createDate, count - 1,
1316                                    count, orderByComparator);
1317    
1318                    if (!list.isEmpty()) {
1319                            return list.get(0);
1320                    }
1321    
1322                    return null;
1323            }
1324    
1325            /**
1326             * Returns the trash entries before and after the current trash entry in the ordered set where groupId = &#63; and createDate &lt; &#63;.
1327             *
1328             * @param entryId the primary key of the current trash entry
1329             * @param groupId the group ID
1330             * @param createDate the create date
1331             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1332             * @return the previous, current, and next trash entry
1333             * @throws com.liferay.portlet.trash.NoSuchEntryException if a trash entry with the primary key could not be found
1334             * @throws SystemException if a system exception occurred
1335             */
1336            public TrashEntry[] findByG_LtCD_PrevAndNext(long entryId, long groupId,
1337                    Date createDate, OrderByComparator orderByComparator)
1338                    throws NoSuchEntryException, SystemException {
1339                    TrashEntry trashEntry = findByPrimaryKey(entryId);
1340    
1341                    Session session = null;
1342    
1343                    try {
1344                            session = openSession();
1345    
1346                            TrashEntry[] array = new TrashEntryImpl[3];
1347    
1348                            array[0] = getByG_LtCD_PrevAndNext(session, trashEntry, groupId,
1349                                            createDate, orderByComparator, true);
1350    
1351                            array[1] = trashEntry;
1352    
1353                            array[2] = getByG_LtCD_PrevAndNext(session, trashEntry, groupId,
1354                                            createDate, orderByComparator, false);
1355    
1356                            return array;
1357                    }
1358                    catch (Exception e) {
1359                            throw processException(e);
1360                    }
1361                    finally {
1362                            closeSession(session);
1363                    }
1364            }
1365    
1366            protected TrashEntry getByG_LtCD_PrevAndNext(Session session,
1367                    TrashEntry trashEntry, long groupId, Date createDate,
1368                    OrderByComparator orderByComparator, boolean previous) {
1369                    StringBundler query = null;
1370    
1371                    if (orderByComparator != null) {
1372                            query = new StringBundler(6 +
1373                                            (orderByComparator.getOrderByFields().length * 6));
1374                    }
1375                    else {
1376                            query = new StringBundler(3);
1377                    }
1378    
1379                    query.append(_SQL_SELECT_TRASHENTRY_WHERE);
1380    
1381                    query.append(_FINDER_COLUMN_G_LTCD_GROUPID_2);
1382    
1383                    boolean bindCreateDate = false;
1384    
1385                    if (createDate == null) {
1386                            query.append(_FINDER_COLUMN_G_LTCD_CREATEDATE_1);
1387                    }
1388                    else {
1389                            bindCreateDate = true;
1390    
1391                            query.append(_FINDER_COLUMN_G_LTCD_CREATEDATE_2);
1392                    }
1393    
1394                    if (orderByComparator != null) {
1395                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1396    
1397                            if (orderByConditionFields.length > 0) {
1398                                    query.append(WHERE_AND);
1399                            }
1400    
1401                            for (int i = 0; i < orderByConditionFields.length; i++) {
1402                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1403                                    query.append(orderByConditionFields[i]);
1404    
1405                                    if ((i + 1) < orderByConditionFields.length) {
1406                                            if (orderByComparator.isAscending() ^ previous) {
1407                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1408                                            }
1409                                            else {
1410                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1411                                            }
1412                                    }
1413                                    else {
1414                                            if (orderByComparator.isAscending() ^ previous) {
1415                                                    query.append(WHERE_GREATER_THAN);
1416                                            }
1417                                            else {
1418                                                    query.append(WHERE_LESSER_THAN);
1419                                            }
1420                                    }
1421                            }
1422    
1423                            query.append(ORDER_BY_CLAUSE);
1424    
1425                            String[] orderByFields = orderByComparator.getOrderByFields();
1426    
1427                            for (int i = 0; i < orderByFields.length; i++) {
1428                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1429                                    query.append(orderByFields[i]);
1430    
1431                                    if ((i + 1) < orderByFields.length) {
1432                                            if (orderByComparator.isAscending() ^ previous) {
1433                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1434                                            }
1435                                            else {
1436                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1437                                            }
1438                                    }
1439                                    else {
1440                                            if (orderByComparator.isAscending() ^ previous) {
1441                                                    query.append(ORDER_BY_ASC);
1442                                            }
1443                                            else {
1444                                                    query.append(ORDER_BY_DESC);
1445                                            }
1446                                    }
1447                            }
1448                    }
1449                    else {
1450                            query.append(TrashEntryModelImpl.ORDER_BY_JPQL);
1451                    }
1452    
1453                    String sql = query.toString();
1454    
1455                    Query q = session.createQuery(sql);
1456    
1457                    q.setFirstResult(0);
1458                    q.setMaxResults(2);
1459    
1460                    QueryPos qPos = QueryPos.getInstance(q);
1461    
1462                    qPos.add(groupId);
1463    
1464                    if (bindCreateDate) {
1465                            qPos.add(CalendarUtil.getTimestamp(createDate));
1466                    }
1467    
1468                    if (orderByComparator != null) {
1469                            Object[] values = orderByComparator.getOrderByConditionValues(trashEntry);
1470    
1471                            for (Object value : values) {
1472                                    qPos.add(value);
1473                            }
1474                    }
1475    
1476                    List<TrashEntry> list = q.list();
1477    
1478                    if (list.size() == 2) {
1479                            return list.get(1);
1480                    }
1481                    else {
1482                            return null;
1483                    }
1484            }
1485    
1486            /**
1487             * Removes all the trash entries where groupId = &#63; and createDate &lt; &#63; from the database.
1488             *
1489             * @param groupId the group ID
1490             * @param createDate the create date
1491             * @throws SystemException if a system exception occurred
1492             */
1493            public void removeByG_LtCD(long groupId, Date createDate)
1494                    throws SystemException {
1495                    for (TrashEntry trashEntry : findByG_LtCD(groupId, createDate,
1496                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1497                            remove(trashEntry);
1498                    }
1499            }
1500    
1501            /**
1502             * Returns the number of trash entries where groupId = &#63; and createDate &lt; &#63;.
1503             *
1504             * @param groupId the group ID
1505             * @param createDate the create date
1506             * @return the number of matching trash entries
1507             * @throws SystemException if a system exception occurred
1508             */
1509            public int countByG_LtCD(long groupId, Date createDate)
1510                    throws SystemException {
1511                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LTCD;
1512    
1513                    Object[] finderArgs = new Object[] { groupId, createDate };
1514    
1515                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1516                                    this);
1517    
1518                    if (count == null) {
1519                            StringBundler query = new StringBundler(3);
1520    
1521                            query.append(_SQL_COUNT_TRASHENTRY_WHERE);
1522    
1523                            query.append(_FINDER_COLUMN_G_LTCD_GROUPID_2);
1524    
1525                            boolean bindCreateDate = false;
1526    
1527                            if (createDate == null) {
1528                                    query.append(_FINDER_COLUMN_G_LTCD_CREATEDATE_1);
1529                            }
1530                            else {
1531                                    bindCreateDate = true;
1532    
1533                                    query.append(_FINDER_COLUMN_G_LTCD_CREATEDATE_2);
1534                            }
1535    
1536                            String sql = query.toString();
1537    
1538                            Session session = null;
1539    
1540                            try {
1541                                    session = openSession();
1542    
1543                                    Query q = session.createQuery(sql);
1544    
1545                                    QueryPos qPos = QueryPos.getInstance(q);
1546    
1547                                    qPos.add(groupId);
1548    
1549                                    if (bindCreateDate) {
1550                                            qPos.add(CalendarUtil.getTimestamp(createDate));
1551                                    }
1552    
1553                                    count = (Long)q.uniqueResult();
1554    
1555                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1556                            }
1557                            catch (Exception e) {
1558                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1559    
1560                                    throw processException(e);
1561                            }
1562                            finally {
1563                                    closeSession(session);
1564                            }
1565                    }
1566    
1567                    return count.intValue();
1568            }
1569    
1570            private static final String _FINDER_COLUMN_G_LTCD_GROUPID_2 = "trashEntry.groupId = ? AND ";
1571            private static final String _FINDER_COLUMN_G_LTCD_CREATEDATE_1 = "trashEntry.createDate < NULL";
1572            private static final String _FINDER_COLUMN_G_LTCD_CREATEDATE_2 = "trashEntry.createDate < ?";
1573            public static final FinderPath FINDER_PATH_FETCH_BY_C_C = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
1574                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
1575                            FINDER_CLASS_NAME_ENTITY, "fetchByC_C",
1576                            new String[] { Long.class.getName(), Long.class.getName() },
1577                            TrashEntryModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1578                            TrashEntryModelImpl.CLASSPK_COLUMN_BITMASK);
1579            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
1580                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
1581                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
1582                            new String[] { Long.class.getName(), Long.class.getName() });
1583    
1584            /**
1585             * Returns the trash entry where classNameId = &#63; and classPK = &#63; or throws a {@link com.liferay.portlet.trash.NoSuchEntryException} if it could not be found.
1586             *
1587             * @param classNameId the class name ID
1588             * @param classPK the class p k
1589             * @return the matching trash entry
1590             * @throws com.liferay.portlet.trash.NoSuchEntryException if a matching trash entry could not be found
1591             * @throws SystemException if a system exception occurred
1592             */
1593            public TrashEntry findByC_C(long classNameId, long classPK)
1594                    throws NoSuchEntryException, SystemException {
1595                    TrashEntry trashEntry = fetchByC_C(classNameId, classPK);
1596    
1597                    if (trashEntry == null) {
1598                            StringBundler msg = new StringBundler(6);
1599    
1600                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1601    
1602                            msg.append("classNameId=");
1603                            msg.append(classNameId);
1604    
1605                            msg.append(", classPK=");
1606                            msg.append(classPK);
1607    
1608                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1609    
1610                            if (_log.isWarnEnabled()) {
1611                                    _log.warn(msg.toString());
1612                            }
1613    
1614                            throw new NoSuchEntryException(msg.toString());
1615                    }
1616    
1617                    return trashEntry;
1618            }
1619    
1620            /**
1621             * 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.
1622             *
1623             * @param classNameId the class name ID
1624             * @param classPK the class p k
1625             * @return the matching trash entry, or <code>null</code> if a matching trash entry could not be found
1626             * @throws SystemException if a system exception occurred
1627             */
1628            public TrashEntry fetchByC_C(long classNameId, long classPK)
1629                    throws SystemException {
1630                    return fetchByC_C(classNameId, classPK, true);
1631            }
1632    
1633            /**
1634             * 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.
1635             *
1636             * @param classNameId the class name ID
1637             * @param classPK the class p k
1638             * @param retrieveFromCache whether to use the finder cache
1639             * @return the matching trash entry, or <code>null</code> if a matching trash entry could not be found
1640             * @throws SystemException if a system exception occurred
1641             */
1642            public TrashEntry fetchByC_C(long classNameId, long classPK,
1643                    boolean retrieveFromCache) throws SystemException {
1644                    Object[] finderArgs = new Object[] { classNameId, classPK };
1645    
1646                    Object result = null;
1647    
1648                    if (retrieveFromCache) {
1649                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C,
1650                                            finderArgs, this);
1651                    }
1652    
1653                    if (result instanceof TrashEntry) {
1654                            TrashEntry trashEntry = (TrashEntry)result;
1655    
1656                            if ((classNameId != trashEntry.getClassNameId()) ||
1657                                            (classPK != trashEntry.getClassPK())) {
1658                                    result = null;
1659                            }
1660                    }
1661    
1662                    if (result == null) {
1663                            StringBundler query = new StringBundler(4);
1664    
1665                            query.append(_SQL_SELECT_TRASHENTRY_WHERE);
1666    
1667                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1668    
1669                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1670    
1671                            String sql = query.toString();
1672    
1673                            Session session = null;
1674    
1675                            try {
1676                                    session = openSession();
1677    
1678                                    Query q = session.createQuery(sql);
1679    
1680                                    QueryPos qPos = QueryPos.getInstance(q);
1681    
1682                                    qPos.add(classNameId);
1683    
1684                                    qPos.add(classPK);
1685    
1686                                    List<TrashEntry> list = q.list();
1687    
1688                                    if (list.isEmpty()) {
1689                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
1690                                                    finderArgs, list);
1691                                    }
1692                                    else {
1693                                            TrashEntry trashEntry = list.get(0);
1694    
1695                                            result = trashEntry;
1696    
1697                                            cacheResult(trashEntry);
1698    
1699                                            if ((trashEntry.getClassNameId() != classNameId) ||
1700                                                            (trashEntry.getClassPK() != classPK)) {
1701                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
1702                                                            finderArgs, trashEntry);
1703                                            }
1704                                    }
1705                            }
1706                            catch (Exception e) {
1707                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
1708                                            finderArgs);
1709    
1710                                    throw processException(e);
1711                            }
1712                            finally {
1713                                    closeSession(session);
1714                            }
1715                    }
1716    
1717                    if (result instanceof List<?>) {
1718                            return null;
1719                    }
1720                    else {
1721                            return (TrashEntry)result;
1722                    }
1723            }
1724    
1725            /**
1726             * Removes the trash entry where classNameId = &#63; and classPK = &#63; from the database.
1727             *
1728             * @param classNameId the class name ID
1729             * @param classPK the class p k
1730             * @return the trash entry that was removed
1731             * @throws SystemException if a system exception occurred
1732             */
1733            public TrashEntry removeByC_C(long classNameId, long classPK)
1734                    throws NoSuchEntryException, SystemException {
1735                    TrashEntry trashEntry = findByC_C(classNameId, classPK);
1736    
1737                    return remove(trashEntry);
1738            }
1739    
1740            /**
1741             * Returns the number of trash entries where classNameId = &#63; and classPK = &#63;.
1742             *
1743             * @param classNameId the class name ID
1744             * @param classPK the class p k
1745             * @return the number of matching trash entries
1746             * @throws SystemException if a system exception occurred
1747             */
1748            public int countByC_C(long classNameId, long classPK)
1749                    throws SystemException {
1750                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
1751    
1752                    Object[] finderArgs = new Object[] { classNameId, classPK };
1753    
1754                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1755                                    this);
1756    
1757                    if (count == null) {
1758                            StringBundler query = new StringBundler(3);
1759    
1760                            query.append(_SQL_COUNT_TRASHENTRY_WHERE);
1761    
1762                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1763    
1764                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1765    
1766                            String sql = query.toString();
1767    
1768                            Session session = null;
1769    
1770                            try {
1771                                    session = openSession();
1772    
1773                                    Query q = session.createQuery(sql);
1774    
1775                                    QueryPos qPos = QueryPos.getInstance(q);
1776    
1777                                    qPos.add(classNameId);
1778    
1779                                    qPos.add(classPK);
1780    
1781                                    count = (Long)q.uniqueResult();
1782    
1783                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1784                            }
1785                            catch (Exception e) {
1786                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1787    
1788                                    throw processException(e);
1789                            }
1790                            finally {
1791                                    closeSession(session);
1792                            }
1793                    }
1794    
1795                    return count.intValue();
1796            }
1797    
1798            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "trashEntry.classNameId = ? AND ";
1799            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "trashEntry.classPK = ?";
1800    
1801            /**
1802             * Caches the trash entry in the entity cache if it is enabled.
1803             *
1804             * @param trashEntry the trash entry
1805             */
1806            public void cacheResult(TrashEntry trashEntry) {
1807                    EntityCacheUtil.putResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
1808                            TrashEntryImpl.class, trashEntry.getPrimaryKey(), trashEntry);
1809    
1810                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
1811                            new Object[] { trashEntry.getClassNameId(), trashEntry.getClassPK() },
1812                            trashEntry);
1813    
1814                    trashEntry.resetOriginalValues();
1815            }
1816    
1817            /**
1818             * Caches the trash entries in the entity cache if it is enabled.
1819             *
1820             * @param trashEntries the trash entries
1821             */
1822            public void cacheResult(List<TrashEntry> trashEntries) {
1823                    for (TrashEntry trashEntry : trashEntries) {
1824                            if (EntityCacheUtil.getResult(
1825                                                    TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
1826                                                    TrashEntryImpl.class, trashEntry.getPrimaryKey()) == null) {
1827                                    cacheResult(trashEntry);
1828                            }
1829                            else {
1830                                    trashEntry.resetOriginalValues();
1831                            }
1832                    }
1833            }
1834    
1835            /**
1836             * Clears the cache for all trash entries.
1837             *
1838             * <p>
1839             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1840             * </p>
1841             */
1842            @Override
1843            public void clearCache() {
1844                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1845                            CacheRegistryUtil.clear(TrashEntryImpl.class.getName());
1846                    }
1847    
1848                    EntityCacheUtil.clearCache(TrashEntryImpl.class.getName());
1849    
1850                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1851                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1852                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1853            }
1854    
1855            /**
1856             * Clears the cache for the trash entry.
1857             *
1858             * <p>
1859             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1860             * </p>
1861             */
1862            @Override
1863            public void clearCache(TrashEntry trashEntry) {
1864                    EntityCacheUtil.removeResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
1865                            TrashEntryImpl.class, trashEntry.getPrimaryKey());
1866    
1867                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1868                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1869    
1870                    clearUniqueFindersCache(trashEntry);
1871            }
1872    
1873            @Override
1874            public void clearCache(List<TrashEntry> trashEntries) {
1875                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1876                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1877    
1878                    for (TrashEntry trashEntry : trashEntries) {
1879                            EntityCacheUtil.removeResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
1880                                    TrashEntryImpl.class, trashEntry.getPrimaryKey());
1881    
1882                            clearUniqueFindersCache(trashEntry);
1883                    }
1884            }
1885    
1886            protected void cacheUniqueFindersCache(TrashEntry trashEntry) {
1887                    if (trashEntry.isNew()) {
1888                            Object[] args = new Object[] {
1889                                            trashEntry.getClassNameId(), trashEntry.getClassPK()
1890                                    };
1891    
1892                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, args,
1893                                    Long.valueOf(1));
1894                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C, args, trashEntry);
1895                    }
1896                    else {
1897                            TrashEntryModelImpl trashEntryModelImpl = (TrashEntryModelImpl)trashEntry;
1898    
1899                            if ((trashEntryModelImpl.getColumnBitmask() &
1900                                            FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
1901                                    Object[] args = new Object[] {
1902                                                    trashEntry.getClassNameId(), trashEntry.getClassPK()
1903                                            };
1904    
1905                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, args,
1906                                            Long.valueOf(1));
1907                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C, args,
1908                                            trashEntry);
1909                            }
1910                    }
1911            }
1912    
1913            protected void clearUniqueFindersCache(TrashEntry trashEntry) {
1914                    TrashEntryModelImpl trashEntryModelImpl = (TrashEntryModelImpl)trashEntry;
1915    
1916                    Object[] args = new Object[] {
1917                                    trashEntry.getClassNameId(), trashEntry.getClassPK()
1918                            };
1919    
1920                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1921                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
1922    
1923                    if ((trashEntryModelImpl.getColumnBitmask() &
1924                                    FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
1925                            args = new Object[] {
1926                                            trashEntryModelImpl.getOriginalClassNameId(),
1927                                            trashEntryModelImpl.getOriginalClassPK()
1928                                    };
1929    
1930                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1931                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
1932                    }
1933            }
1934    
1935            /**
1936             * Creates a new trash entry with the primary key. Does not add the trash entry to the database.
1937             *
1938             * @param entryId the primary key for the new trash entry
1939             * @return the new trash entry
1940             */
1941            public TrashEntry create(long entryId) {
1942                    TrashEntry trashEntry = new TrashEntryImpl();
1943    
1944                    trashEntry.setNew(true);
1945                    trashEntry.setPrimaryKey(entryId);
1946    
1947                    return trashEntry;
1948            }
1949    
1950            /**
1951             * Removes the trash entry with the primary key from the database. Also notifies the appropriate model listeners.
1952             *
1953             * @param entryId the primary key of the trash entry
1954             * @return the trash entry that was removed
1955             * @throws com.liferay.portlet.trash.NoSuchEntryException if a trash entry with the primary key could not be found
1956             * @throws SystemException if a system exception occurred
1957             */
1958            public TrashEntry remove(long entryId)
1959                    throws NoSuchEntryException, SystemException {
1960                    return remove((Serializable)entryId);
1961            }
1962    
1963            /**
1964             * Removes the trash entry with the primary key from the database. Also notifies the appropriate model listeners.
1965             *
1966             * @param primaryKey the primary key of the trash entry
1967             * @return the trash entry that was removed
1968             * @throws com.liferay.portlet.trash.NoSuchEntryException if a trash entry with the primary key could not be found
1969             * @throws SystemException if a system exception occurred
1970             */
1971            @Override
1972            public TrashEntry remove(Serializable primaryKey)
1973                    throws NoSuchEntryException, SystemException {
1974                    Session session = null;
1975    
1976                    try {
1977                            session = openSession();
1978    
1979                            TrashEntry trashEntry = (TrashEntry)session.get(TrashEntryImpl.class,
1980                                            primaryKey);
1981    
1982                            if (trashEntry == null) {
1983                                    if (_log.isWarnEnabled()) {
1984                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1985                                    }
1986    
1987                                    throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1988                                            primaryKey);
1989                            }
1990    
1991                            return remove(trashEntry);
1992                    }
1993                    catch (NoSuchEntryException nsee) {
1994                            throw nsee;
1995                    }
1996                    catch (Exception e) {
1997                            throw processException(e);
1998                    }
1999                    finally {
2000                            closeSession(session);
2001                    }
2002            }
2003    
2004            @Override
2005            protected TrashEntry removeImpl(TrashEntry trashEntry)
2006                    throws SystemException {
2007                    trashEntry = toUnwrappedModel(trashEntry);
2008    
2009                    Session session = null;
2010    
2011                    try {
2012                            session = openSession();
2013    
2014                            if (!session.contains(trashEntry)) {
2015                                    trashEntry = (TrashEntry)session.get(TrashEntryImpl.class,
2016                                                    trashEntry.getPrimaryKeyObj());
2017                            }
2018    
2019                            if (trashEntry != null) {
2020                                    session.delete(trashEntry);
2021                            }
2022                    }
2023                    catch (Exception e) {
2024                            throw processException(e);
2025                    }
2026                    finally {
2027                            closeSession(session);
2028                    }
2029    
2030                    if (trashEntry != null) {
2031                            clearCache(trashEntry);
2032                    }
2033    
2034                    return trashEntry;
2035            }
2036    
2037            @Override
2038            public TrashEntry updateImpl(
2039                    com.liferay.portlet.trash.model.TrashEntry trashEntry)
2040                    throws SystemException {
2041                    trashEntry = toUnwrappedModel(trashEntry);
2042    
2043                    boolean isNew = trashEntry.isNew();
2044    
2045                    TrashEntryModelImpl trashEntryModelImpl = (TrashEntryModelImpl)trashEntry;
2046    
2047                    Session session = null;
2048    
2049                    try {
2050                            session = openSession();
2051    
2052                            if (trashEntry.isNew()) {
2053                                    session.save(trashEntry);
2054    
2055                                    trashEntry.setNew(false);
2056                            }
2057                            else {
2058                                    session.merge(trashEntry);
2059                            }
2060                    }
2061                    catch (Exception e) {
2062                            throw processException(e);
2063                    }
2064                    finally {
2065                            closeSession(session);
2066                    }
2067    
2068                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2069    
2070                    if (isNew || !TrashEntryModelImpl.COLUMN_BITMASK_ENABLED) {
2071                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2072                    }
2073    
2074                    else {
2075                            if ((trashEntryModelImpl.getColumnBitmask() &
2076                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
2077                                    Object[] args = new Object[] {
2078                                                    trashEntryModelImpl.getOriginalGroupId()
2079                                            };
2080    
2081                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2082                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2083                                            args);
2084    
2085                                    args = new Object[] { trashEntryModelImpl.getGroupId() };
2086    
2087                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2088                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2089                                            args);
2090                            }
2091    
2092                            if ((trashEntryModelImpl.getColumnBitmask() &
2093                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
2094                                    Object[] args = new Object[] {
2095                                                    trashEntryModelImpl.getOriginalCompanyId()
2096                                            };
2097    
2098                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
2099                                            args);
2100                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
2101                                            args);
2102    
2103                                    args = new Object[] { trashEntryModelImpl.getCompanyId() };
2104    
2105                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
2106                                            args);
2107                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
2108                                            args);
2109                            }
2110                    }
2111    
2112                    EntityCacheUtil.putResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2113                            TrashEntryImpl.class, trashEntry.getPrimaryKey(), trashEntry);
2114    
2115                    clearUniqueFindersCache(trashEntry);
2116                    cacheUniqueFindersCache(trashEntry);
2117    
2118                    return trashEntry;
2119            }
2120    
2121            protected TrashEntry toUnwrappedModel(TrashEntry trashEntry) {
2122                    if (trashEntry instanceof TrashEntryImpl) {
2123                            return trashEntry;
2124                    }
2125    
2126                    TrashEntryImpl trashEntryImpl = new TrashEntryImpl();
2127    
2128                    trashEntryImpl.setNew(trashEntry.isNew());
2129                    trashEntryImpl.setPrimaryKey(trashEntry.getPrimaryKey());
2130    
2131                    trashEntryImpl.setEntryId(trashEntry.getEntryId());
2132                    trashEntryImpl.setGroupId(trashEntry.getGroupId());
2133                    trashEntryImpl.setCompanyId(trashEntry.getCompanyId());
2134                    trashEntryImpl.setUserId(trashEntry.getUserId());
2135                    trashEntryImpl.setUserName(trashEntry.getUserName());
2136                    trashEntryImpl.setCreateDate(trashEntry.getCreateDate());
2137                    trashEntryImpl.setClassNameId(trashEntry.getClassNameId());
2138                    trashEntryImpl.setClassPK(trashEntry.getClassPK());
2139                    trashEntryImpl.setTypeSettings(trashEntry.getTypeSettings());
2140                    trashEntryImpl.setStatus(trashEntry.getStatus());
2141    
2142                    return trashEntryImpl;
2143            }
2144    
2145            /**
2146             * Returns the trash entry with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2147             *
2148             * @param primaryKey the primary key of the trash entry
2149             * @return the trash entry
2150             * @throws com.liferay.portlet.trash.NoSuchEntryException if a trash entry with the primary key could not be found
2151             * @throws SystemException if a system exception occurred
2152             */
2153            @Override
2154            public TrashEntry findByPrimaryKey(Serializable primaryKey)
2155                    throws NoSuchEntryException, SystemException {
2156                    TrashEntry trashEntry = fetchByPrimaryKey(primaryKey);
2157    
2158                    if (trashEntry == null) {
2159                            if (_log.isWarnEnabled()) {
2160                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2161                            }
2162    
2163                            throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2164                                    primaryKey);
2165                    }
2166    
2167                    return trashEntry;
2168            }
2169    
2170            /**
2171             * Returns the trash entry with the primary key or throws a {@link com.liferay.portlet.trash.NoSuchEntryException} if it could not be found.
2172             *
2173             * @param entryId the primary key of the trash entry
2174             * @return the trash entry
2175             * @throws com.liferay.portlet.trash.NoSuchEntryException if a trash entry with the primary key could not be found
2176             * @throws SystemException if a system exception occurred
2177             */
2178            public TrashEntry findByPrimaryKey(long entryId)
2179                    throws NoSuchEntryException, SystemException {
2180                    return findByPrimaryKey((Serializable)entryId);
2181            }
2182    
2183            /**
2184             * Returns the trash entry with the primary key or returns <code>null</code> if it could not be found.
2185             *
2186             * @param primaryKey the primary key of the trash entry
2187             * @return the trash entry, or <code>null</code> if a trash entry with the primary key could not be found
2188             * @throws SystemException if a system exception occurred
2189             */
2190            @Override
2191            public TrashEntry fetchByPrimaryKey(Serializable primaryKey)
2192                    throws SystemException {
2193                    TrashEntry trashEntry = (TrashEntry)EntityCacheUtil.getResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2194                                    TrashEntryImpl.class, primaryKey);
2195    
2196                    if (trashEntry == _nullTrashEntry) {
2197                            return null;
2198                    }
2199    
2200                    if (trashEntry == null) {
2201                            Session session = null;
2202    
2203                            try {
2204                                    session = openSession();
2205    
2206                                    trashEntry = (TrashEntry)session.get(TrashEntryImpl.class,
2207                                                    primaryKey);
2208    
2209                                    if (trashEntry != null) {
2210                                            cacheResult(trashEntry);
2211                                    }
2212                                    else {
2213                                            EntityCacheUtil.putResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2214                                                    TrashEntryImpl.class, primaryKey, _nullTrashEntry);
2215                                    }
2216                            }
2217                            catch (Exception e) {
2218                                    EntityCacheUtil.removeResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2219                                            TrashEntryImpl.class, primaryKey);
2220    
2221                                    throw processException(e);
2222                            }
2223                            finally {
2224                                    closeSession(session);
2225                            }
2226                    }
2227    
2228                    return trashEntry;
2229            }
2230    
2231            /**
2232             * Returns the trash entry with the primary key or returns <code>null</code> if it could not be found.
2233             *
2234             * @param entryId the primary key of the trash entry
2235             * @return the trash entry, or <code>null</code> if a trash entry with the primary key could not be found
2236             * @throws SystemException if a system exception occurred
2237             */
2238            public TrashEntry fetchByPrimaryKey(long entryId) throws SystemException {
2239                    return fetchByPrimaryKey((Serializable)entryId);
2240            }
2241    
2242            /**
2243             * Returns all the trash entries.
2244             *
2245             * @return the trash entries
2246             * @throws SystemException if a system exception occurred
2247             */
2248            public List<TrashEntry> findAll() throws SystemException {
2249                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2250            }
2251    
2252            /**
2253             * Returns a range of all the trash entries.
2254             *
2255             * <p>
2256             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.trash.model.impl.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.
2257             * </p>
2258             *
2259             * @param start the lower bound of the range of trash entries
2260             * @param end the upper bound of the range of trash entries (not inclusive)
2261             * @return the range of trash entries
2262             * @throws SystemException if a system exception occurred
2263             */
2264            public List<TrashEntry> findAll(int start, int end)
2265                    throws SystemException {
2266                    return findAll(start, end, null);
2267            }
2268    
2269            /**
2270             * Returns an ordered range of all the trash entries.
2271             *
2272             * <p>
2273             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.trash.model.impl.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.
2274             * </p>
2275             *
2276             * @param start the lower bound of the range of trash entries
2277             * @param end the upper bound of the range of trash entries (not inclusive)
2278             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2279             * @return the ordered range of trash entries
2280             * @throws SystemException if a system exception occurred
2281             */
2282            public List<TrashEntry> findAll(int start, int end,
2283                    OrderByComparator orderByComparator) throws SystemException {
2284                    boolean pagination = true;
2285                    FinderPath finderPath = null;
2286                    Object[] finderArgs = null;
2287    
2288                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2289                                    (orderByComparator == null)) {
2290                            pagination = false;
2291                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2292                            finderArgs = FINDER_ARGS_EMPTY;
2293                    }
2294                    else {
2295                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2296                            finderArgs = new Object[] { start, end, orderByComparator };
2297                    }
2298    
2299                    List<TrashEntry> list = (List<TrashEntry>)FinderCacheUtil.getResult(finderPath,
2300                                    finderArgs, this);
2301    
2302                    if (list == null) {
2303                            StringBundler query = null;
2304                            String sql = null;
2305    
2306                            if (orderByComparator != null) {
2307                                    query = new StringBundler(2 +
2308                                                    (orderByComparator.getOrderByFields().length * 3));
2309    
2310                                    query.append(_SQL_SELECT_TRASHENTRY);
2311    
2312                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2313                                            orderByComparator);
2314    
2315                                    sql = query.toString();
2316                            }
2317                            else {
2318                                    sql = _SQL_SELECT_TRASHENTRY;
2319    
2320                                    if (pagination) {
2321                                            sql = sql.concat(TrashEntryModelImpl.ORDER_BY_JPQL);
2322                                    }
2323                            }
2324    
2325                            Session session = null;
2326    
2327                            try {
2328                                    session = openSession();
2329    
2330                                    Query q = session.createQuery(sql);
2331    
2332                                    if (!pagination) {
2333                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
2334                                                            start, end, false);
2335    
2336                                            Collections.sort(list);
2337    
2338                                            list = new UnmodifiableList<TrashEntry>(list);
2339                                    }
2340                                    else {
2341                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
2342                                                            start, end);
2343                                    }
2344    
2345                                    cacheResult(list);
2346    
2347                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2348                            }
2349                            catch (Exception e) {
2350                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2351    
2352                                    throw processException(e);
2353                            }
2354                            finally {
2355                                    closeSession(session);
2356                            }
2357                    }
2358    
2359                    return list;
2360            }
2361    
2362            /**
2363             * Removes all the trash entries from the database.
2364             *
2365             * @throws SystemException if a system exception occurred
2366             */
2367            public void removeAll() throws SystemException {
2368                    for (TrashEntry trashEntry : findAll()) {
2369                            remove(trashEntry);
2370                    }
2371            }
2372    
2373            /**
2374             * Returns the number of trash entries.
2375             *
2376             * @return the number of trash entries
2377             * @throws SystemException if a system exception occurred
2378             */
2379            public int countAll() throws SystemException {
2380                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2381                                    FINDER_ARGS_EMPTY, this);
2382    
2383                    if (count == null) {
2384                            Session session = null;
2385    
2386                            try {
2387                                    session = openSession();
2388    
2389                                    Query q = session.createQuery(_SQL_COUNT_TRASHENTRY);
2390    
2391                                    count = (Long)q.uniqueResult();
2392    
2393                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2394                                            FINDER_ARGS_EMPTY, count);
2395                            }
2396                            catch (Exception e) {
2397                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2398                                            FINDER_ARGS_EMPTY);
2399    
2400                                    throw processException(e);
2401                            }
2402                            finally {
2403                                    closeSession(session);
2404                            }
2405                    }
2406    
2407                    return count.intValue();
2408            }
2409    
2410            /**
2411             * Initializes the trash entry persistence.
2412             */
2413            public void afterPropertiesSet() {
2414                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2415                                            com.liferay.portal.util.PropsUtil.get(
2416                                                    "value.object.listener.com.liferay.portlet.trash.model.TrashEntry")));
2417    
2418                    if (listenerClassNames.length > 0) {
2419                            try {
2420                                    List<ModelListener<TrashEntry>> listenersList = new ArrayList<ModelListener<TrashEntry>>();
2421    
2422                                    for (String listenerClassName : listenerClassNames) {
2423                                            listenersList.add((ModelListener<TrashEntry>)InstanceFactory.newInstance(
2424                                                            listenerClassName));
2425                                    }
2426    
2427                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2428                            }
2429                            catch (Exception e) {
2430                                    _log.error(e);
2431                            }
2432                    }
2433            }
2434    
2435            public void destroy() {
2436                    EntityCacheUtil.removeCache(TrashEntryImpl.class.getName());
2437                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2438                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2439                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2440            }
2441    
2442            private static final String _SQL_SELECT_TRASHENTRY = "SELECT trashEntry FROM TrashEntry trashEntry";
2443            private static final String _SQL_SELECT_TRASHENTRY_WHERE = "SELECT trashEntry FROM TrashEntry trashEntry WHERE ";
2444            private static final String _SQL_COUNT_TRASHENTRY = "SELECT COUNT(trashEntry) FROM TrashEntry trashEntry";
2445            private static final String _SQL_COUNT_TRASHENTRY_WHERE = "SELECT COUNT(trashEntry) FROM TrashEntry trashEntry WHERE ";
2446            private static final String _ORDER_BY_ENTITY_ALIAS = "trashEntry.";
2447            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No TrashEntry exists with the primary key ";
2448            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No TrashEntry exists with the key {";
2449            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2450            private static Log _log = LogFactoryUtil.getLog(TrashEntryPersistenceImpl.class);
2451            private static TrashEntry _nullTrashEntry = new TrashEntryImpl() {
2452                            @Override
2453                            public Object clone() {
2454                                    return this;
2455                            }
2456    
2457                            @Override
2458                            public CacheModel<TrashEntry> toCacheModel() {
2459                                    return _nullTrashEntryCacheModel;
2460                            }
2461                    };
2462    
2463            private static CacheModel<TrashEntry> _nullTrashEntryCacheModel = new CacheModel<TrashEntry>() {
2464                            public TrashEntry toEntityModel() {
2465                                    return _nullTrashEntry;
2466                            }
2467                    };
2468    }