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