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