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