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