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.model.CacheModel;
037    import com.liferay.portal.model.ModelListener;
038    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
039    
040    import com.liferay.portlet.trash.NoSuchEntryException;
041    import com.liferay.portlet.trash.model.TrashEntry;
042    import com.liferay.portlet.trash.model.impl.TrashEntryImpl;
043    import com.liferay.portlet.trash.model.impl.TrashEntryModelImpl;
044    
045    import java.io.Serializable;
046    
047    import java.util.ArrayList;
048    import java.util.Collections;
049    import java.util.Date;
050    import java.util.List;
051    
052    /**
053     * The persistence implementation for the trash entry service.
054     *
055     * <p>
056     * Caching information and settings can be found in <code>portal.properties</code>
057     * </p>
058     *
059     * @author Brian Wing Shun Chan
060     * @see TrashEntryPersistence
061     * @see TrashEntryUtil
062     * @generated
063     */
064    public class TrashEntryPersistenceImpl extends BasePersistenceImpl<TrashEntry>
065            implements TrashEntryPersistence {
066            /*
067             * NOTE FOR DEVELOPERS:
068             *
069             * 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.
070             */
071            public static final String FINDER_CLASS_NAME_ENTITY = TrashEntryImpl.class.getName();
072            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List1";
074            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075                    ".List2";
076            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
077                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
078                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
079            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
080                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
081                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
082            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
083                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
084                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
085            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
086                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
087                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
088                            new String[] {
089                                    Long.class.getName(),
090                                    
091                            Integer.class.getName(), Integer.class.getName(),
092                                    OrderByComparator.class.getName()
093                            });
094            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
095                    new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
096                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
097                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
098                            new String[] { Long.class.getName() },
099                            TrashEntryModelImpl.GROUPID_COLUMN_BITMASK |
100                            TrashEntryModelImpl.CREATEDATE_COLUMN_BITMASK);
101            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
102                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
103                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
104                            new String[] { Long.class.getName() });
105    
106            /**
107             * Returns all the trash entries where groupId = &#63;.
108             *
109             * @param groupId the group ID
110             * @return the matching trash entries
111             * @throws SystemException if a system exception occurred
112             */
113            @Override
114            public List<TrashEntry> findByGroupId(long groupId)
115                    throws SystemException {
116                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
117            }
118    
119            /**
120             * Returns a range of all the trash entries where groupId = &#63;.
121             *
122             * <p>
123             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.trash.model.impl.TrashEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
124             * </p>
125             *
126             * @param groupId the group ID
127             * @param start the lower bound of the range of trash entries
128             * @param end the upper bound of the range of trash entries (not inclusive)
129             * @return the range of matching trash entries
130             * @throws SystemException if a system exception occurred
131             */
132            @Override
133            public List<TrashEntry> findByGroupId(long groupId, int start, int end)
134                    throws SystemException {
135                    return findByGroupId(groupId, start, end, null);
136            }
137    
138            /**
139             * Returns an ordered range of all the trash entries where groupId = &#63;.
140             *
141             * <p>
142             * 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.
143             * </p>
144             *
145             * @param groupId the group ID
146             * @param start the lower bound of the range of trash entries
147             * @param end the upper bound of the range of trash entries (not inclusive)
148             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
149             * @return the ordered range of matching trash entries
150             * @throws SystemException if a system exception occurred
151             */
152            @Override
153            public List<TrashEntry> findByGroupId(long groupId, int start, int end,
154                    OrderByComparator orderByComparator) throws SystemException {
155                    boolean pagination = true;
156                    FinderPath finderPath = null;
157                    Object[] finderArgs = null;
158    
159                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
160                                    (orderByComparator == null)) {
161                            pagination = false;
162                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
163                            finderArgs = new Object[] { groupId };
164                    }
165                    else {
166                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
167                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
168                    }
169    
170                    List<TrashEntry> list = (List<TrashEntry>)FinderCacheUtil.getResult(finderPath,
171                                    finderArgs, this);
172    
173                    if ((list != null) && !list.isEmpty()) {
174                            for (TrashEntry trashEntry : list) {
175                                    if ((groupId != trashEntry.getGroupId())) {
176                                            list = null;
177    
178                                            break;
179                                    }
180                            }
181                    }
182    
183                    if (list == null) {
184                            StringBundler query = null;
185    
186                            if (orderByComparator != null) {
187                                    query = new StringBundler(3 +
188                                                    (orderByComparator.getOrderByFields().length * 3));
189                            }
190                            else {
191                                    query = new StringBundler(3);
192                            }
193    
194                            query.append(_SQL_SELECT_TRASHENTRY_WHERE);
195    
196                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
197    
198                            if (orderByComparator != null) {
199                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
200                                            orderByComparator);
201                            }
202                            else
203                             if (pagination) {
204                                    query.append(TrashEntryModelImpl.ORDER_BY_JPQL);
205                            }
206    
207                            String sql = query.toString();
208    
209                            Session session = null;
210    
211                            try {
212                                    session = openSession();
213    
214                                    Query q = session.createQuery(sql);
215    
216                                    QueryPos qPos = QueryPos.getInstance(q);
217    
218                                    qPos.add(groupId);
219    
220                                    if (!pagination) {
221                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
222                                                            start, end, false);
223    
224                                            Collections.sort(list);
225    
226                                            list = new UnmodifiableList<TrashEntry>(list);
227                                    }
228                                    else {
229                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
230                                                            start, end);
231                                    }
232    
233                                    cacheResult(list);
234    
235                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
236                            }
237                            catch (Exception e) {
238                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
239    
240                                    throw processException(e);
241                            }
242                            finally {
243                                    closeSession(session);
244                            }
245                    }
246    
247                    return list;
248            }
249    
250            /**
251             * Returns the first trash entry in the ordered set where groupId = &#63;.
252             *
253             * @param groupId the group ID
254             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
255             * @return the first matching trash entry
256             * @throws com.liferay.portlet.trash.NoSuchEntryException if a matching trash entry could not be found
257             * @throws SystemException if a system exception occurred
258             */
259            @Override
260            public TrashEntry findByGroupId_First(long groupId,
261                    OrderByComparator orderByComparator)
262                    throws NoSuchEntryException, SystemException {
263                    TrashEntry trashEntry = fetchByGroupId_First(groupId, orderByComparator);
264    
265                    if (trashEntry != null) {
266                            return trashEntry;
267                    }
268    
269                    StringBundler msg = new StringBundler(4);
270    
271                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
272    
273                    msg.append("groupId=");
274                    msg.append(groupId);
275    
276                    msg.append(StringPool.CLOSE_CURLY_BRACE);
277    
278                    throw new NoSuchEntryException(msg.toString());
279            }
280    
281            /**
282             * Returns the first trash entry in the ordered set where groupId = &#63;.
283             *
284             * @param groupId the group ID
285             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
286             * @return the first matching trash entry, or <code>null</code> if a matching trash entry could not be found
287             * @throws SystemException if a system exception occurred
288             */
289            @Override
290            public TrashEntry fetchByGroupId_First(long groupId,
291                    OrderByComparator orderByComparator) throws SystemException {
292                    List<TrashEntry> list = findByGroupId(groupId, 0, 1, orderByComparator);
293    
294                    if (!list.isEmpty()) {
295                            return list.get(0);
296                    }
297    
298                    return null;
299            }
300    
301            /**
302             * Returns the last trash entry in the ordered set where groupId = &#63;.
303             *
304             * @param groupId the group ID
305             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
306             * @return the last matching trash entry
307             * @throws com.liferay.portlet.trash.NoSuchEntryException if a matching trash entry could not be found
308             * @throws SystemException if a system exception occurred
309             */
310            @Override
311            public TrashEntry findByGroupId_Last(long groupId,
312                    OrderByComparator orderByComparator)
313                    throws NoSuchEntryException, SystemException {
314                    TrashEntry trashEntry = fetchByGroupId_Last(groupId, orderByComparator);
315    
316                    if (trashEntry != null) {
317                            return trashEntry;
318                    }
319    
320                    StringBundler msg = new StringBundler(4);
321    
322                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
323    
324                    msg.append("groupId=");
325                    msg.append(groupId);
326    
327                    msg.append(StringPool.CLOSE_CURLY_BRACE);
328    
329                    throw new NoSuchEntryException(msg.toString());
330            }
331    
332            /**
333             * Returns the last trash entry in the ordered set where groupId = &#63;.
334             *
335             * @param groupId the group ID
336             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
337             * @return the last matching trash entry, or <code>null</code> if a matching trash entry could not be found
338             * @throws SystemException if a system exception occurred
339             */
340            @Override
341            public TrashEntry fetchByGroupId_Last(long groupId,
342                    OrderByComparator orderByComparator) throws SystemException {
343                    int count = countByGroupId(groupId);
344    
345                    if (count == 0) {
346                            return null;
347                    }
348    
349                    List<TrashEntry> list = findByGroupId(groupId, count - 1, count,
350                                    orderByComparator);
351    
352                    if (!list.isEmpty()) {
353                            return list.get(0);
354                    }
355    
356                    return null;
357            }
358    
359            /**
360             * Returns the trash entries before and after the current trash entry in the ordered set where groupId = &#63;.
361             *
362             * @param entryId the primary key of the current trash entry
363             * @param groupId the group ID
364             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
365             * @return the previous, current, and next trash entry
366             * @throws com.liferay.portlet.trash.NoSuchEntryException if a trash entry with the primary key could not be found
367             * @throws SystemException if a system exception occurred
368             */
369            @Override
370            public TrashEntry[] findByGroupId_PrevAndNext(long entryId, long groupId,
371                    OrderByComparator orderByComparator)
372                    throws NoSuchEntryException, SystemException {
373                    TrashEntry trashEntry = findByPrimaryKey(entryId);
374    
375                    Session session = null;
376    
377                    try {
378                            session = openSession();
379    
380                            TrashEntry[] array = new TrashEntryImpl[3];
381    
382                            array[0] = getByGroupId_PrevAndNext(session, trashEntry, groupId,
383                                            orderByComparator, true);
384    
385                            array[1] = trashEntry;
386    
387                            array[2] = getByGroupId_PrevAndNext(session, trashEntry, groupId,
388                                            orderByComparator, false);
389    
390                            return array;
391                    }
392                    catch (Exception e) {
393                            throw processException(e);
394                    }
395                    finally {
396                            closeSession(session);
397                    }
398            }
399    
400            protected TrashEntry getByGroupId_PrevAndNext(Session session,
401                    TrashEntry trashEntry, long groupId,
402                    OrderByComparator orderByComparator, boolean previous) {
403                    StringBundler query = null;
404    
405                    if (orderByComparator != null) {
406                            query = new StringBundler(6 +
407                                            (orderByComparator.getOrderByFields().length * 6));
408                    }
409                    else {
410                            query = new StringBundler(3);
411                    }
412    
413                    query.append(_SQL_SELECT_TRASHENTRY_WHERE);
414    
415                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
416    
417                    if (orderByComparator != null) {
418                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
419    
420                            if (orderByConditionFields.length > 0) {
421                                    query.append(WHERE_AND);
422                            }
423    
424                            for (int i = 0; i < orderByConditionFields.length; i++) {
425                                    query.append(_ORDER_BY_ENTITY_ALIAS);
426                                    query.append(orderByConditionFields[i]);
427    
428                                    if ((i + 1) < orderByConditionFields.length) {
429                                            if (orderByComparator.isAscending() ^ previous) {
430                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
431                                            }
432                                            else {
433                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
434                                            }
435                                    }
436                                    else {
437                                            if (orderByComparator.isAscending() ^ previous) {
438                                                    query.append(WHERE_GREATER_THAN);
439                                            }
440                                            else {
441                                                    query.append(WHERE_LESSER_THAN);
442                                            }
443                                    }
444                            }
445    
446                            query.append(ORDER_BY_CLAUSE);
447    
448                            String[] orderByFields = orderByComparator.getOrderByFields();
449    
450                            for (int i = 0; i < orderByFields.length; i++) {
451                                    query.append(_ORDER_BY_ENTITY_ALIAS);
452                                    query.append(orderByFields[i]);
453    
454                                    if ((i + 1) < orderByFields.length) {
455                                            if (orderByComparator.isAscending() ^ previous) {
456                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
457                                            }
458                                            else {
459                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
460                                            }
461                                    }
462                                    else {
463                                            if (orderByComparator.isAscending() ^ previous) {
464                                                    query.append(ORDER_BY_ASC);
465                                            }
466                                            else {
467                                                    query.append(ORDER_BY_DESC);
468                                            }
469                                    }
470                            }
471                    }
472                    else {
473                            query.append(TrashEntryModelImpl.ORDER_BY_JPQL);
474                    }
475    
476                    String sql = query.toString();
477    
478                    Query q = session.createQuery(sql);
479    
480                    q.setFirstResult(0);
481                    q.setMaxResults(2);
482    
483                    QueryPos qPos = QueryPos.getInstance(q);
484    
485                    qPos.add(groupId);
486    
487                    if (orderByComparator != null) {
488                            Object[] values = orderByComparator.getOrderByConditionValues(trashEntry);
489    
490                            for (Object value : values) {
491                                    qPos.add(value);
492                            }
493                    }
494    
495                    List<TrashEntry> list = q.list();
496    
497                    if (list.size() == 2) {
498                            return list.get(1);
499                    }
500                    else {
501                            return null;
502                    }
503            }
504    
505            /**
506             * Removes all the trash entries where groupId = &#63; from the database.
507             *
508             * @param groupId the group ID
509             * @throws SystemException if a system exception occurred
510             */
511            @Override
512            public void removeByGroupId(long groupId) throws SystemException {
513                    for (TrashEntry trashEntry : findByGroupId(groupId, QueryUtil.ALL_POS,
514                                    QueryUtil.ALL_POS, null)) {
515                            remove(trashEntry);
516                    }
517            }
518    
519            /**
520             * Returns the number of trash entries where groupId = &#63;.
521             *
522             * @param groupId the group ID
523             * @return the number of matching trash entries
524             * @throws SystemException if a system exception occurred
525             */
526            @Override
527            public int countByGroupId(long groupId) throws SystemException {
528                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
529    
530                    Object[] finderArgs = new Object[] { groupId };
531    
532                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
533                                    this);
534    
535                    if (count == null) {
536                            StringBundler query = new StringBundler(2);
537    
538                            query.append(_SQL_COUNT_TRASHENTRY_WHERE);
539    
540                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
541    
542                            String sql = query.toString();
543    
544                            Session session = null;
545    
546                            try {
547                                    session = openSession();
548    
549                                    Query q = session.createQuery(sql);
550    
551                                    QueryPos qPos = QueryPos.getInstance(q);
552    
553                                    qPos.add(groupId);
554    
555                                    count = (Long)q.uniqueResult();
556    
557                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
558                            }
559                            catch (Exception e) {
560                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
561    
562                                    throw processException(e);
563                            }
564                            finally {
565                                    closeSession(session);
566                            }
567                    }
568    
569                    return count.intValue();
570            }
571    
572            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "trashEntry.groupId = ?";
573            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
574                    new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
575                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
576                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
577                            new String[] {
578                                    Long.class.getName(),
579                                    
580                            Integer.class.getName(), Integer.class.getName(),
581                                    OrderByComparator.class.getName()
582                            });
583            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
584                    new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
585                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
586                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
587                            new String[] { Long.class.getName() },
588                            TrashEntryModelImpl.COMPANYID_COLUMN_BITMASK |
589                            TrashEntryModelImpl.CREATEDATE_COLUMN_BITMASK);
590            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
591                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
592                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
593                            new String[] { Long.class.getName() });
594    
595            /**
596             * Returns all the trash entries where companyId = &#63;.
597             *
598             * @param companyId the company ID
599             * @return the matching trash entries
600             * @throws SystemException if a system exception occurred
601             */
602            @Override
603            public List<TrashEntry> findByCompanyId(long companyId)
604                    throws SystemException {
605                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
606                            null);
607            }
608    
609            /**
610             * Returns a range of all the trash entries where companyId = &#63;.
611             *
612             * <p>
613             * 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.
614             * </p>
615             *
616             * @param companyId the company ID
617             * @param start the lower bound of the range of trash entries
618             * @param end the upper bound of the range of trash entries (not inclusive)
619             * @return the range of matching trash entries
620             * @throws SystemException if a system exception occurred
621             */
622            @Override
623            public List<TrashEntry> findByCompanyId(long companyId, int start, int end)
624                    throws SystemException {
625                    return findByCompanyId(companyId, start, end, null);
626            }
627    
628            /**
629             * Returns an ordered range of all the trash entries where companyId = &#63;.
630             *
631             * <p>
632             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link 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.
633             * </p>
634             *
635             * @param companyId the company ID
636             * @param start the lower bound of the range of trash entries
637             * @param end the upper bound of the range of trash entries (not inclusive)
638             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
639             * @return the ordered range of matching trash entries
640             * @throws SystemException if a system exception occurred
641             */
642            @Override
643            public List<TrashEntry> findByCompanyId(long companyId, int start, int end,
644                    OrderByComparator orderByComparator) throws SystemException {
645                    boolean pagination = true;
646                    FinderPath finderPath = null;
647                    Object[] finderArgs = null;
648    
649                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
650                                    (orderByComparator == null)) {
651                            pagination = false;
652                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
653                            finderArgs = new Object[] { companyId };
654                    }
655                    else {
656                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
657                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
658                    }
659    
660                    List<TrashEntry> list = (List<TrashEntry>)FinderCacheUtil.getResult(finderPath,
661                                    finderArgs, this);
662    
663                    if ((list != null) && !list.isEmpty()) {
664                            for (TrashEntry trashEntry : list) {
665                                    if ((companyId != trashEntry.getCompanyId())) {
666                                            list = null;
667    
668                                            break;
669                                    }
670                            }
671                    }
672    
673                    if (list == null) {
674                            StringBundler query = null;
675    
676                            if (orderByComparator != null) {
677                                    query = new StringBundler(3 +
678                                                    (orderByComparator.getOrderByFields().length * 3));
679                            }
680                            else {
681                                    query = new StringBundler(3);
682                            }
683    
684                            query.append(_SQL_SELECT_TRASHENTRY_WHERE);
685    
686                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
687    
688                            if (orderByComparator != null) {
689                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
690                                            orderByComparator);
691                            }
692                            else
693                             if (pagination) {
694                                    query.append(TrashEntryModelImpl.ORDER_BY_JPQL);
695                            }
696    
697                            String sql = query.toString();
698    
699                            Session session = null;
700    
701                            try {
702                                    session = openSession();
703    
704                                    Query q = session.createQuery(sql);
705    
706                                    QueryPos qPos = QueryPos.getInstance(q);
707    
708                                    qPos.add(companyId);
709    
710                                    if (!pagination) {
711                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
712                                                            start, end, false);
713    
714                                            Collections.sort(list);
715    
716                                            list = new UnmodifiableList<TrashEntry>(list);
717                                    }
718                                    else {
719                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
720                                                            start, end);
721                                    }
722    
723                                    cacheResult(list);
724    
725                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
726                            }
727                            catch (Exception e) {
728                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
729    
730                                    throw processException(e);
731                            }
732                            finally {
733                                    closeSession(session);
734                            }
735                    }
736    
737                    return list;
738            }
739    
740            /**
741             * Returns the first trash entry in the ordered set where companyId = &#63;.
742             *
743             * @param companyId the company ID
744             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
745             * @return the first matching trash entry
746             * @throws com.liferay.portlet.trash.NoSuchEntryException if a matching trash entry could not be found
747             * @throws SystemException if a system exception occurred
748             */
749            @Override
750            public TrashEntry findByCompanyId_First(long companyId,
751                    OrderByComparator orderByComparator)
752                    throws NoSuchEntryException, SystemException {
753                    TrashEntry trashEntry = fetchByCompanyId_First(companyId,
754                                    orderByComparator);
755    
756                    if (trashEntry != null) {
757                            return trashEntry;
758                    }
759    
760                    StringBundler msg = new StringBundler(4);
761    
762                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
763    
764                    msg.append("companyId=");
765                    msg.append(companyId);
766    
767                    msg.append(StringPool.CLOSE_CURLY_BRACE);
768    
769                    throw new NoSuchEntryException(msg.toString());
770            }
771    
772            /**
773             * Returns the first trash entry in the ordered set where companyId = &#63;.
774             *
775             * @param companyId the company ID
776             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
777             * @return the first matching trash entry, or <code>null</code> if a matching trash entry could not be found
778             * @throws SystemException if a system exception occurred
779             */
780            @Override
781            public TrashEntry fetchByCompanyId_First(long companyId,
782                    OrderByComparator orderByComparator) throws SystemException {
783                    List<TrashEntry> list = findByCompanyId(companyId, 0, 1,
784                                    orderByComparator);
785    
786                    if (!list.isEmpty()) {
787                            return list.get(0);
788                    }
789    
790                    return null;
791            }
792    
793            /**
794             * Returns the last trash entry in the ordered set where companyId = &#63;.
795             *
796             * @param companyId the company ID
797             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
798             * @return the last matching trash entry
799             * @throws com.liferay.portlet.trash.NoSuchEntryException if a matching trash entry could not be found
800             * @throws SystemException if a system exception occurred
801             */
802            @Override
803            public TrashEntry findByCompanyId_Last(long companyId,
804                    OrderByComparator orderByComparator)
805                    throws NoSuchEntryException, SystemException {
806                    TrashEntry trashEntry = fetchByCompanyId_Last(companyId,
807                                    orderByComparator);
808    
809                    if (trashEntry != null) {
810                            return trashEntry;
811                    }
812    
813                    StringBundler msg = new StringBundler(4);
814    
815                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
816    
817                    msg.append("companyId=");
818                    msg.append(companyId);
819    
820                    msg.append(StringPool.CLOSE_CURLY_BRACE);
821    
822                    throw new NoSuchEntryException(msg.toString());
823            }
824    
825            /**
826             * Returns the last trash entry in the ordered set where companyId = &#63;.
827             *
828             * @param companyId the company ID
829             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
830             * @return the last matching trash entry, or <code>null</code> if a matching trash entry could not be found
831             * @throws SystemException if a system exception occurred
832             */
833            @Override
834            public TrashEntry fetchByCompanyId_Last(long companyId,
835                    OrderByComparator orderByComparator) throws SystemException {
836                    int count = countByCompanyId(companyId);
837    
838                    if (count == 0) {
839                            return null;
840                    }
841    
842                    List<TrashEntry> list = findByCompanyId(companyId, count - 1, count,
843                                    orderByComparator);
844    
845                    if (!list.isEmpty()) {
846                            return list.get(0);
847                    }
848    
849                    return null;
850            }
851    
852            /**
853             * Returns the trash entries before and after the current trash entry in the ordered set where companyId = &#63;.
854             *
855             * @param entryId the primary key of the current trash entry
856             * @param companyId the company ID
857             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
858             * @return the previous, current, and next trash entry
859             * @throws com.liferay.portlet.trash.NoSuchEntryException if a trash entry with the primary key could not be found
860             * @throws SystemException if a system exception occurred
861             */
862            @Override
863            public TrashEntry[] findByCompanyId_PrevAndNext(long entryId,
864                    long companyId, OrderByComparator orderByComparator)
865                    throws NoSuchEntryException, SystemException {
866                    TrashEntry trashEntry = findByPrimaryKey(entryId);
867    
868                    Session session = null;
869    
870                    try {
871                            session = openSession();
872    
873                            TrashEntry[] array = new TrashEntryImpl[3];
874    
875                            array[0] = getByCompanyId_PrevAndNext(session, trashEntry,
876                                            companyId, orderByComparator, true);
877    
878                            array[1] = trashEntry;
879    
880                            array[2] = getByCompanyId_PrevAndNext(session, trashEntry,
881                                            companyId, orderByComparator, false);
882    
883                            return array;
884                    }
885                    catch (Exception e) {
886                            throw processException(e);
887                    }
888                    finally {
889                            closeSession(session);
890                    }
891            }
892    
893            protected TrashEntry getByCompanyId_PrevAndNext(Session session,
894                    TrashEntry trashEntry, long companyId,
895                    OrderByComparator orderByComparator, boolean previous) {
896                    StringBundler query = null;
897    
898                    if (orderByComparator != null) {
899                            query = new StringBundler(6 +
900                                            (orderByComparator.getOrderByFields().length * 6));
901                    }
902                    else {
903                            query = new StringBundler(3);
904                    }
905    
906                    query.append(_SQL_SELECT_TRASHENTRY_WHERE);
907    
908                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
909    
910                    if (orderByComparator != null) {
911                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
912    
913                            if (orderByConditionFields.length > 0) {
914                                    query.append(WHERE_AND);
915                            }
916    
917                            for (int i = 0; i < orderByConditionFields.length; i++) {
918                                    query.append(_ORDER_BY_ENTITY_ALIAS);
919                                    query.append(orderByConditionFields[i]);
920    
921                                    if ((i + 1) < orderByConditionFields.length) {
922                                            if (orderByComparator.isAscending() ^ previous) {
923                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
924                                            }
925                                            else {
926                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
927                                            }
928                                    }
929                                    else {
930                                            if (orderByComparator.isAscending() ^ previous) {
931                                                    query.append(WHERE_GREATER_THAN);
932                                            }
933                                            else {
934                                                    query.append(WHERE_LESSER_THAN);
935                                            }
936                                    }
937                            }
938    
939                            query.append(ORDER_BY_CLAUSE);
940    
941                            String[] orderByFields = orderByComparator.getOrderByFields();
942    
943                            for (int i = 0; i < orderByFields.length; i++) {
944                                    query.append(_ORDER_BY_ENTITY_ALIAS);
945                                    query.append(orderByFields[i]);
946    
947                                    if ((i + 1) < orderByFields.length) {
948                                            if (orderByComparator.isAscending() ^ previous) {
949                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
950                                            }
951                                            else {
952                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
953                                            }
954                                    }
955                                    else {
956                                            if (orderByComparator.isAscending() ^ previous) {
957                                                    query.append(ORDER_BY_ASC);
958                                            }
959                                            else {
960                                                    query.append(ORDER_BY_DESC);
961                                            }
962                                    }
963                            }
964                    }
965                    else {
966                            query.append(TrashEntryModelImpl.ORDER_BY_JPQL);
967                    }
968    
969                    String sql = query.toString();
970    
971                    Query q = session.createQuery(sql);
972    
973                    q.setFirstResult(0);
974                    q.setMaxResults(2);
975    
976                    QueryPos qPos = QueryPos.getInstance(q);
977    
978                    qPos.add(companyId);
979    
980                    if (orderByComparator != null) {
981                            Object[] values = orderByComparator.getOrderByConditionValues(trashEntry);
982    
983                            for (Object value : values) {
984                                    qPos.add(value);
985                            }
986                    }
987    
988                    List<TrashEntry> list = q.list();
989    
990                    if (list.size() == 2) {
991                            return list.get(1);
992                    }
993                    else {
994                            return null;
995                    }
996            }
997    
998            /**
999             * Removes all the trash entries where companyId = &#63; from the database.
1000             *
1001             * @param companyId the company ID
1002             * @throws SystemException if a system exception occurred
1003             */
1004            @Override
1005            public void removeByCompanyId(long companyId) throws SystemException {
1006                    for (TrashEntry trashEntry : findByCompanyId(companyId,
1007                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1008                            remove(trashEntry);
1009                    }
1010            }
1011    
1012            /**
1013             * Returns the number of trash entries where companyId = &#63;.
1014             *
1015             * @param companyId the company ID
1016             * @return the number of matching trash entries
1017             * @throws SystemException if a system exception occurred
1018             */
1019            @Override
1020            public int countByCompanyId(long companyId) throws SystemException {
1021                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
1022    
1023                    Object[] finderArgs = new Object[] { companyId };
1024    
1025                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1026                                    this);
1027    
1028                    if (count == null) {
1029                            StringBundler query = new StringBundler(2);
1030    
1031                            query.append(_SQL_COUNT_TRASHENTRY_WHERE);
1032    
1033                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1034    
1035                            String sql = query.toString();
1036    
1037                            Session session = null;
1038    
1039                            try {
1040                                    session = openSession();
1041    
1042                                    Query q = session.createQuery(sql);
1043    
1044                                    QueryPos qPos = QueryPos.getInstance(q);
1045    
1046                                    qPos.add(companyId);
1047    
1048                                    count = (Long)q.uniqueResult();
1049    
1050                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1051                            }
1052                            catch (Exception e) {
1053                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1054    
1055                                    throw processException(e);
1056                            }
1057                            finally {
1058                                    closeSession(session);
1059                            }
1060                    }
1061    
1062                    return count.intValue();
1063            }
1064    
1065            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "trashEntry.companyId = ?";
1066            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LTCD = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
1067                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
1068                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_LtCD",
1069                            new String[] {
1070                                    Long.class.getName(), Date.class.getName(),
1071                                    
1072                            Integer.class.getName(), Integer.class.getName(),
1073                                    OrderByComparator.class.getName()
1074                            });
1075            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LTCD = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
1076                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
1077                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_LtCD",
1078                            new String[] { Long.class.getName(), Date.class.getName() });
1079    
1080            /**
1081             * Returns all the trash entries where groupId = &#63; and createDate &lt; &#63;.
1082             *
1083             * @param groupId the group ID
1084             * @param createDate the create date
1085             * @return the matching trash entries
1086             * @throws SystemException if a system exception occurred
1087             */
1088            @Override
1089            public List<TrashEntry> findByG_LtCD(long groupId, Date createDate)
1090                    throws SystemException {
1091                    return findByG_LtCD(groupId, createDate, QueryUtil.ALL_POS,
1092                            QueryUtil.ALL_POS, null);
1093            }
1094    
1095            /**
1096             * Returns a range of all the trash entries where groupId = &#63; and createDate &lt; &#63;.
1097             *
1098             * <p>
1099             * 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.
1100             * </p>
1101             *
1102             * @param groupId the group ID
1103             * @param createDate the create date
1104             * @param start the lower bound of the range of trash entries
1105             * @param end the upper bound of the range of trash entries (not inclusive)
1106             * @return the range of matching trash entries
1107             * @throws SystemException if a system exception occurred
1108             */
1109            @Override
1110            public List<TrashEntry> findByG_LtCD(long groupId, Date createDate,
1111                    int start, int end) throws SystemException {
1112                    return findByG_LtCD(groupId, createDate, start, end, null);
1113            }
1114    
1115            /**
1116             * Returns an ordered range of all the trash entries where groupId = &#63; and createDate &lt; &#63;.
1117             *
1118             * <p>
1119             * 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.
1120             * </p>
1121             *
1122             * @param groupId the group ID
1123             * @param createDate the create date
1124             * @param start the lower bound of the range of trash entries
1125             * @param end the upper bound of the range of trash entries (not inclusive)
1126             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1127             * @return the ordered range of matching trash entries
1128             * @throws SystemException if a system exception occurred
1129             */
1130            @Override
1131            public List<TrashEntry> findByG_LtCD(long groupId, Date createDate,
1132                    int start, int end, OrderByComparator orderByComparator)
1133                    throws SystemException {
1134                    boolean pagination = true;
1135                    FinderPath finderPath = null;
1136                    Object[] finderArgs = null;
1137    
1138                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LTCD;
1139                    finderArgs = new Object[] {
1140                                    groupId, createDate,
1141                                    
1142                                    start, end, orderByComparator
1143                            };
1144    
1145                    List<TrashEntry> list = (List<TrashEntry>)FinderCacheUtil.getResult(finderPath,
1146                                    finderArgs, this);
1147    
1148                    if ((list != null) && !list.isEmpty()) {
1149                            for (TrashEntry trashEntry : list) {
1150                                    if ((groupId != trashEntry.getGroupId()) ||
1151                                                    (createDate.getTime() <= trashEntry.getCreateDate()
1152                                                                                                                               .getTime())) {
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.setSystemEventSetKey(trashEntry.getSystemEventSetKey());
2745                    trashEntryImpl.setTypeSettings(trashEntry.getTypeSettings());
2746                    trashEntryImpl.setStatus(trashEntry.getStatus());
2747    
2748                    return trashEntryImpl;
2749            }
2750    
2751            /**
2752             * Returns the trash entry with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2753             *
2754             * @param primaryKey the primary key of the trash entry
2755             * @return the trash entry
2756             * @throws com.liferay.portlet.trash.NoSuchEntryException if a trash entry with the primary key could not be found
2757             * @throws SystemException if a system exception occurred
2758             */
2759            @Override
2760            public TrashEntry findByPrimaryKey(Serializable primaryKey)
2761                    throws NoSuchEntryException, SystemException {
2762                    TrashEntry trashEntry = fetchByPrimaryKey(primaryKey);
2763    
2764                    if (trashEntry == null) {
2765                            if (_log.isWarnEnabled()) {
2766                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2767                            }
2768    
2769                            throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2770                                    primaryKey);
2771                    }
2772    
2773                    return trashEntry;
2774            }
2775    
2776            /**
2777             * Returns the trash entry with the primary key or throws a {@link com.liferay.portlet.trash.NoSuchEntryException} if it could not be found.
2778             *
2779             * @param entryId the primary key of the trash entry
2780             * @return the trash entry
2781             * @throws com.liferay.portlet.trash.NoSuchEntryException if a trash entry with the primary key could not be found
2782             * @throws SystemException if a system exception occurred
2783             */
2784            @Override
2785            public TrashEntry findByPrimaryKey(long entryId)
2786                    throws NoSuchEntryException, SystemException {
2787                    return findByPrimaryKey((Serializable)entryId);
2788            }
2789    
2790            /**
2791             * Returns the trash entry with the primary key or returns <code>null</code> if it could not be found.
2792             *
2793             * @param primaryKey the primary key of the trash entry
2794             * @return the trash entry, or <code>null</code> if a trash entry with the primary key could not be found
2795             * @throws SystemException if a system exception occurred
2796             */
2797            @Override
2798            public TrashEntry fetchByPrimaryKey(Serializable primaryKey)
2799                    throws SystemException {
2800                    TrashEntry trashEntry = (TrashEntry)EntityCacheUtil.getResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2801                                    TrashEntryImpl.class, primaryKey);
2802    
2803                    if (trashEntry == _nullTrashEntry) {
2804                            return null;
2805                    }
2806    
2807                    if (trashEntry == null) {
2808                            Session session = null;
2809    
2810                            try {
2811                                    session = openSession();
2812    
2813                                    trashEntry = (TrashEntry)session.get(TrashEntryImpl.class,
2814                                                    primaryKey);
2815    
2816                                    if (trashEntry != null) {
2817                                            cacheResult(trashEntry);
2818                                    }
2819                                    else {
2820                                            EntityCacheUtil.putResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2821                                                    TrashEntryImpl.class, primaryKey, _nullTrashEntry);
2822                                    }
2823                            }
2824                            catch (Exception e) {
2825                                    EntityCacheUtil.removeResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2826                                            TrashEntryImpl.class, primaryKey);
2827    
2828                                    throw processException(e);
2829                            }
2830                            finally {
2831                                    closeSession(session);
2832                            }
2833                    }
2834    
2835                    return trashEntry;
2836            }
2837    
2838            /**
2839             * Returns the trash entry with the primary key or returns <code>null</code> if it could not be found.
2840             *
2841             * @param entryId the primary key of the trash entry
2842             * @return the trash entry, or <code>null</code> if a trash entry with the primary key could not be found
2843             * @throws SystemException if a system exception occurred
2844             */
2845            @Override
2846            public TrashEntry fetchByPrimaryKey(long entryId) throws SystemException {
2847                    return fetchByPrimaryKey((Serializable)entryId);
2848            }
2849    
2850            /**
2851             * Returns all the trash entries.
2852             *
2853             * @return the trash entries
2854             * @throws SystemException if a system exception occurred
2855             */
2856            @Override
2857            public List<TrashEntry> findAll() throws SystemException {
2858                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2859            }
2860    
2861            /**
2862             * Returns a range of all the trash entries.
2863             *
2864             * <p>
2865             * 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.
2866             * </p>
2867             *
2868             * @param start the lower bound of the range of trash entries
2869             * @param end the upper bound of the range of trash entries (not inclusive)
2870             * @return the range of trash entries
2871             * @throws SystemException if a system exception occurred
2872             */
2873            @Override
2874            public List<TrashEntry> findAll(int start, int end)
2875                    throws SystemException {
2876                    return findAll(start, end, null);
2877            }
2878    
2879            /**
2880             * Returns an ordered range of all the trash entries.
2881             *
2882             * <p>
2883             * 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.
2884             * </p>
2885             *
2886             * @param start the lower bound of the range of trash entries
2887             * @param end the upper bound of the range of trash entries (not inclusive)
2888             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2889             * @return the ordered range of trash entries
2890             * @throws SystemException if a system exception occurred
2891             */
2892            @Override
2893            public List<TrashEntry> findAll(int start, int end,
2894                    OrderByComparator orderByComparator) throws SystemException {
2895                    boolean pagination = true;
2896                    FinderPath finderPath = null;
2897                    Object[] finderArgs = null;
2898    
2899                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2900                                    (orderByComparator == null)) {
2901                            pagination = false;
2902                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2903                            finderArgs = FINDER_ARGS_EMPTY;
2904                    }
2905                    else {
2906                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2907                            finderArgs = new Object[] { start, end, orderByComparator };
2908                    }
2909    
2910                    List<TrashEntry> list = (List<TrashEntry>)FinderCacheUtil.getResult(finderPath,
2911                                    finderArgs, this);
2912    
2913                    if (list == null) {
2914                            StringBundler query = null;
2915                            String sql = null;
2916    
2917                            if (orderByComparator != null) {
2918                                    query = new StringBundler(2 +
2919                                                    (orderByComparator.getOrderByFields().length * 3));
2920    
2921                                    query.append(_SQL_SELECT_TRASHENTRY);
2922    
2923                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2924                                            orderByComparator);
2925    
2926                                    sql = query.toString();
2927                            }
2928                            else {
2929                                    sql = _SQL_SELECT_TRASHENTRY;
2930    
2931                                    if (pagination) {
2932                                            sql = sql.concat(TrashEntryModelImpl.ORDER_BY_JPQL);
2933                                    }
2934                            }
2935    
2936                            Session session = null;
2937    
2938                            try {
2939                                    session = openSession();
2940    
2941                                    Query q = session.createQuery(sql);
2942    
2943                                    if (!pagination) {
2944                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
2945                                                            start, end, false);
2946    
2947                                            Collections.sort(list);
2948    
2949                                            list = new UnmodifiableList<TrashEntry>(list);
2950                                    }
2951                                    else {
2952                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
2953                                                            start, end);
2954                                    }
2955    
2956                                    cacheResult(list);
2957    
2958                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2959                            }
2960                            catch (Exception e) {
2961                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2962    
2963                                    throw processException(e);
2964                            }
2965                            finally {
2966                                    closeSession(session);
2967                            }
2968                    }
2969    
2970                    return list;
2971            }
2972    
2973            /**
2974             * Removes all the trash entries from the database.
2975             *
2976             * @throws SystemException if a system exception occurred
2977             */
2978            @Override
2979            public void removeAll() throws SystemException {
2980                    for (TrashEntry trashEntry : findAll()) {
2981                            remove(trashEntry);
2982                    }
2983            }
2984    
2985            /**
2986             * Returns the number of trash entries.
2987             *
2988             * @return the number of trash entries
2989             * @throws SystemException if a system exception occurred
2990             */
2991            @Override
2992            public int countAll() throws SystemException {
2993                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2994                                    FINDER_ARGS_EMPTY, this);
2995    
2996                    if (count == null) {
2997                            Session session = null;
2998    
2999                            try {
3000                                    session = openSession();
3001    
3002                                    Query q = session.createQuery(_SQL_COUNT_TRASHENTRY);
3003    
3004                                    count = (Long)q.uniqueResult();
3005    
3006                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3007                                            FINDER_ARGS_EMPTY, count);
3008                            }
3009                            catch (Exception e) {
3010                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
3011                                            FINDER_ARGS_EMPTY);
3012    
3013                                    throw processException(e);
3014                            }
3015                            finally {
3016                                    closeSession(session);
3017                            }
3018                    }
3019    
3020                    return count.intValue();
3021            }
3022    
3023            /**
3024             * Initializes the trash entry persistence.
3025             */
3026            public void afterPropertiesSet() {
3027                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3028                                            com.liferay.portal.util.PropsUtil.get(
3029                                                    "value.object.listener.com.liferay.portlet.trash.model.TrashEntry")));
3030    
3031                    if (listenerClassNames.length > 0) {
3032                            try {
3033                                    List<ModelListener<TrashEntry>> listenersList = new ArrayList<ModelListener<TrashEntry>>();
3034    
3035                                    for (String listenerClassName : listenerClassNames) {
3036                                            listenersList.add((ModelListener<TrashEntry>)InstanceFactory.newInstance(
3037                                                            getClassLoader(), listenerClassName));
3038                                    }
3039    
3040                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3041                            }
3042                            catch (Exception e) {
3043                                    _log.error(e);
3044                            }
3045                    }
3046            }
3047    
3048            public void destroy() {
3049                    EntityCacheUtil.removeCache(TrashEntryImpl.class.getName());
3050                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3051                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3052                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3053            }
3054    
3055            private static final String _SQL_SELECT_TRASHENTRY = "SELECT trashEntry FROM TrashEntry trashEntry";
3056            private static final String _SQL_SELECT_TRASHENTRY_WHERE = "SELECT trashEntry FROM TrashEntry trashEntry WHERE ";
3057            private static final String _SQL_COUNT_TRASHENTRY = "SELECT COUNT(trashEntry) FROM TrashEntry trashEntry";
3058            private static final String _SQL_COUNT_TRASHENTRY_WHERE = "SELECT COUNT(trashEntry) FROM TrashEntry trashEntry WHERE ";
3059            private static final String _ORDER_BY_ENTITY_ALIAS = "trashEntry.";
3060            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No TrashEntry exists with the primary key ";
3061            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No TrashEntry exists with the key {";
3062            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3063            private static Log _log = LogFactoryUtil.getLog(TrashEntryPersistenceImpl.class);
3064            private static TrashEntry _nullTrashEntry = new TrashEntryImpl() {
3065                            @Override
3066                            public Object clone() {
3067                                    return this;
3068                            }
3069    
3070                            @Override
3071                            public CacheModel<TrashEntry> toCacheModel() {
3072                                    return _nullTrashEntryCacheModel;
3073                            }
3074                    };
3075    
3076            private static CacheModel<TrashEntry> _nullTrashEntryCacheModel = new CacheModel<TrashEntry>() {
3077                            @Override
3078                            public TrashEntry toEntityModel() {
3079                                    return _nullTrashEntry;
3080                            }
3081                    };
3082    }