001    /**
002     * Copyright (c) 2000-present 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.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderPath;
022    import com.liferay.portal.kernel.dao.orm.Query;
023    import com.liferay.portal.kernel.dao.orm.QueryPos;
024    import com.liferay.portal.kernel.dao.orm.QueryUtil;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.log.Log;
027    import com.liferay.portal.kernel.log.LogFactoryUtil;
028    import com.liferay.portal.kernel.util.OrderByComparator;
029    import com.liferay.portal.kernel.util.StringBundler;
030    import com.liferay.portal.kernel.util.StringPool;
031    import com.liferay.portal.model.CacheModel;
032    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
033    
034    import com.liferay.portlet.trash.NoSuchVersionException;
035    import com.liferay.portlet.trash.model.TrashVersion;
036    import com.liferay.portlet.trash.model.impl.TrashVersionImpl;
037    import com.liferay.portlet.trash.model.impl.TrashVersionModelImpl;
038    import com.liferay.portlet.trash.service.persistence.TrashVersionPersistence;
039    
040    import java.io.Serializable;
041    
042    import java.util.Collections;
043    import java.util.HashMap;
044    import java.util.HashSet;
045    import java.util.Iterator;
046    import java.util.List;
047    import java.util.Map;
048    import java.util.Set;
049    
050    /**
051     * The persistence implementation for the trash version service.
052     *
053     * <p>
054     * Caching information and settings can be found in <code>portal.properties</code>
055     * </p>
056     *
057     * @author Brian Wing Shun Chan
058     * @see TrashVersionPersistence
059     * @see com.liferay.portlet.trash.service.persistence.TrashVersionUtil
060     * @generated
061     */
062    @ProviderType
063    public class TrashVersionPersistenceImpl extends BasePersistenceImpl<TrashVersion>
064            implements TrashVersionPersistence {
065            /*
066             * NOTE FOR DEVELOPERS:
067             *
068             * Never modify or reference this class directly. Always use {@link TrashVersionUtil} to access the trash version persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
069             */
070            public static final String FINDER_CLASS_NAME_ENTITY = TrashVersionImpl.class.getName();
071            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072                    ".List1";
073            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074                    ".List2";
075            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
076                            TrashVersionModelImpl.FINDER_CACHE_ENABLED, TrashVersionImpl.class,
077                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
078            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
079                            TrashVersionModelImpl.FINDER_CACHE_ENABLED, TrashVersionImpl.class,
080                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
081            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
082                            TrashVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
083                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
084            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ENTRYID = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
085                            TrashVersionModelImpl.FINDER_CACHE_ENABLED, TrashVersionImpl.class,
086                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByEntryId",
087                            new String[] {
088                                    Long.class.getName(),
089                                    
090                            Integer.class.getName(), Integer.class.getName(),
091                                    OrderByComparator.class.getName()
092                            });
093            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID =
094                    new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
095                            TrashVersionModelImpl.FINDER_CACHE_ENABLED, TrashVersionImpl.class,
096                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByEntryId",
097                            new String[] { Long.class.getName() },
098                            TrashVersionModelImpl.ENTRYID_COLUMN_BITMASK);
099            public static final FinderPath FINDER_PATH_COUNT_BY_ENTRYID = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
100                            TrashVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
101                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByEntryId",
102                            new String[] { Long.class.getName() });
103    
104            /**
105             * Returns all the trash versions where entryId = &#63;.
106             *
107             * @param entryId the entry ID
108             * @return the matching trash versions
109             */
110            @Override
111            public List<TrashVersion> findByEntryId(long entryId) {
112                    return findByEntryId(entryId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
113            }
114    
115            /**
116             * Returns a range of all the trash versions where entryId = &#63;.
117             *
118             * <p>
119             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TrashVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
120             * </p>
121             *
122             * @param entryId the entry ID
123             * @param start the lower bound of the range of trash versions
124             * @param end the upper bound of the range of trash versions (not inclusive)
125             * @return the range of matching trash versions
126             */
127            @Override
128            public List<TrashVersion> findByEntryId(long entryId, int start, int end) {
129                    return findByEntryId(entryId, start, end, null);
130            }
131    
132            /**
133             * Returns an ordered range of all the trash versions where entryId = &#63;.
134             *
135             * <p>
136             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TrashVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
137             * </p>
138             *
139             * @param entryId the entry ID
140             * @param start the lower bound of the range of trash versions
141             * @param end the upper bound of the range of trash versions (not inclusive)
142             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
143             * @return the ordered range of matching trash versions
144             */
145            @Override
146            public List<TrashVersion> findByEntryId(long entryId, int start, int end,
147                    OrderByComparator<TrashVersion> orderByComparator) {
148                    boolean pagination = true;
149                    FinderPath finderPath = null;
150                    Object[] finderArgs = null;
151    
152                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
153                                    (orderByComparator == null)) {
154                            pagination = false;
155                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID;
156                            finderArgs = new Object[] { entryId };
157                    }
158                    else {
159                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ENTRYID;
160                            finderArgs = new Object[] { entryId, start, end, orderByComparator };
161                    }
162    
163                    List<TrashVersion> list = (List<TrashVersion>)FinderCacheUtil.getResult(finderPath,
164                                    finderArgs, this);
165    
166                    if ((list != null) && !list.isEmpty()) {
167                            for (TrashVersion trashVersion : list) {
168                                    if ((entryId != trashVersion.getEntryId())) {
169                                            list = null;
170    
171                                            break;
172                                    }
173                            }
174                    }
175    
176                    if (list == null) {
177                            StringBundler query = null;
178    
179                            if (orderByComparator != null) {
180                                    query = new StringBundler(3 +
181                                                    (orderByComparator.getOrderByFields().length * 3));
182                            }
183                            else {
184                                    query = new StringBundler(3);
185                            }
186    
187                            query.append(_SQL_SELECT_TRASHVERSION_WHERE);
188    
189                            query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
190    
191                            if (orderByComparator != null) {
192                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
193                                            orderByComparator);
194                            }
195                            else
196                             if (pagination) {
197                                    query.append(TrashVersionModelImpl.ORDER_BY_JPQL);
198                            }
199    
200                            String sql = query.toString();
201    
202                            Session session = null;
203    
204                            try {
205                                    session = openSession();
206    
207                                    Query q = session.createQuery(sql);
208    
209                                    QueryPos qPos = QueryPos.getInstance(q);
210    
211                                    qPos.add(entryId);
212    
213                                    if (!pagination) {
214                                            list = (List<TrashVersion>)QueryUtil.list(q, getDialect(),
215                                                            start, end, false);
216    
217                                            Collections.sort(list);
218    
219                                            list = Collections.unmodifiableList(list);
220                                    }
221                                    else {
222                                            list = (List<TrashVersion>)QueryUtil.list(q, getDialect(),
223                                                            start, end);
224                                    }
225    
226                                    cacheResult(list);
227    
228                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
229                            }
230                            catch (Exception e) {
231                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
232    
233                                    throw processException(e);
234                            }
235                            finally {
236                                    closeSession(session);
237                            }
238                    }
239    
240                    return list;
241            }
242    
243            /**
244             * Returns the first trash version in the ordered set where entryId = &#63;.
245             *
246             * @param entryId the entry ID
247             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
248             * @return the first matching trash version
249             * @throws NoSuchVersionException if a matching trash version could not be found
250             */
251            @Override
252            public TrashVersion findByEntryId_First(long entryId,
253                    OrderByComparator<TrashVersion> orderByComparator)
254                    throws NoSuchVersionException {
255                    TrashVersion trashVersion = fetchByEntryId_First(entryId,
256                                    orderByComparator);
257    
258                    if (trashVersion != null) {
259                            return trashVersion;
260                    }
261    
262                    StringBundler msg = new StringBundler(4);
263    
264                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
265    
266                    msg.append("entryId=");
267                    msg.append(entryId);
268    
269                    msg.append(StringPool.CLOSE_CURLY_BRACE);
270    
271                    throw new NoSuchVersionException(msg.toString());
272            }
273    
274            /**
275             * Returns the first trash version in the ordered set where entryId = &#63;.
276             *
277             * @param entryId the entry ID
278             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
279             * @return the first matching trash version, or <code>null</code> if a matching trash version could not be found
280             */
281            @Override
282            public TrashVersion fetchByEntryId_First(long entryId,
283                    OrderByComparator<TrashVersion> orderByComparator) {
284                    List<TrashVersion> list = findByEntryId(entryId, 0, 1, orderByComparator);
285    
286                    if (!list.isEmpty()) {
287                            return list.get(0);
288                    }
289    
290                    return null;
291            }
292    
293            /**
294             * Returns the last trash version in the ordered set where entryId = &#63;.
295             *
296             * @param entryId the entry ID
297             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
298             * @return the last matching trash version
299             * @throws NoSuchVersionException if a matching trash version could not be found
300             */
301            @Override
302            public TrashVersion findByEntryId_Last(long entryId,
303                    OrderByComparator<TrashVersion> orderByComparator)
304                    throws NoSuchVersionException {
305                    TrashVersion trashVersion = fetchByEntryId_Last(entryId,
306                                    orderByComparator);
307    
308                    if (trashVersion != null) {
309                            return trashVersion;
310                    }
311    
312                    StringBundler msg = new StringBundler(4);
313    
314                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
315    
316                    msg.append("entryId=");
317                    msg.append(entryId);
318    
319                    msg.append(StringPool.CLOSE_CURLY_BRACE);
320    
321                    throw new NoSuchVersionException(msg.toString());
322            }
323    
324            /**
325             * Returns the last trash version in the ordered set where entryId = &#63;.
326             *
327             * @param entryId the entry ID
328             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
329             * @return the last matching trash version, or <code>null</code> if a matching trash version could not be found
330             */
331            @Override
332            public TrashVersion fetchByEntryId_Last(long entryId,
333                    OrderByComparator<TrashVersion> orderByComparator) {
334                    int count = countByEntryId(entryId);
335    
336                    if (count == 0) {
337                            return null;
338                    }
339    
340                    List<TrashVersion> list = findByEntryId(entryId, count - 1, count,
341                                    orderByComparator);
342    
343                    if (!list.isEmpty()) {
344                            return list.get(0);
345                    }
346    
347                    return null;
348            }
349    
350            /**
351             * Returns the trash versions before and after the current trash version in the ordered set where entryId = &#63;.
352             *
353             * @param versionId the primary key of the current trash version
354             * @param entryId the entry ID
355             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
356             * @return the previous, current, and next trash version
357             * @throws NoSuchVersionException if a trash version with the primary key could not be found
358             */
359            @Override
360            public TrashVersion[] findByEntryId_PrevAndNext(long versionId,
361                    long entryId, OrderByComparator<TrashVersion> orderByComparator)
362                    throws NoSuchVersionException {
363                    TrashVersion trashVersion = findByPrimaryKey(versionId);
364    
365                    Session session = null;
366    
367                    try {
368                            session = openSession();
369    
370                            TrashVersion[] array = new TrashVersionImpl[3];
371    
372                            array[0] = getByEntryId_PrevAndNext(session, trashVersion, entryId,
373                                            orderByComparator, true);
374    
375                            array[1] = trashVersion;
376    
377                            array[2] = getByEntryId_PrevAndNext(session, trashVersion, entryId,
378                                            orderByComparator, false);
379    
380                            return array;
381                    }
382                    catch (Exception e) {
383                            throw processException(e);
384                    }
385                    finally {
386                            closeSession(session);
387                    }
388            }
389    
390            protected TrashVersion getByEntryId_PrevAndNext(Session session,
391                    TrashVersion trashVersion, long entryId,
392                    OrderByComparator<TrashVersion> orderByComparator, boolean previous) {
393                    StringBundler query = null;
394    
395                    if (orderByComparator != null) {
396                            query = new StringBundler(6 +
397                                            (orderByComparator.getOrderByFields().length * 6));
398                    }
399                    else {
400                            query = new StringBundler(3);
401                    }
402    
403                    query.append(_SQL_SELECT_TRASHVERSION_WHERE);
404    
405                    query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
406    
407                    if (orderByComparator != null) {
408                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
409    
410                            if (orderByConditionFields.length > 0) {
411                                    query.append(WHERE_AND);
412                            }
413    
414                            for (int i = 0; i < orderByConditionFields.length; i++) {
415                                    query.append(_ORDER_BY_ENTITY_ALIAS);
416                                    query.append(orderByConditionFields[i]);
417    
418                                    if ((i + 1) < orderByConditionFields.length) {
419                                            if (orderByComparator.isAscending() ^ previous) {
420                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
421                                            }
422                                            else {
423                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
424                                            }
425                                    }
426                                    else {
427                                            if (orderByComparator.isAscending() ^ previous) {
428                                                    query.append(WHERE_GREATER_THAN);
429                                            }
430                                            else {
431                                                    query.append(WHERE_LESSER_THAN);
432                                            }
433                                    }
434                            }
435    
436                            query.append(ORDER_BY_CLAUSE);
437    
438                            String[] orderByFields = orderByComparator.getOrderByFields();
439    
440                            for (int i = 0; i < orderByFields.length; i++) {
441                                    query.append(_ORDER_BY_ENTITY_ALIAS);
442                                    query.append(orderByFields[i]);
443    
444                                    if ((i + 1) < orderByFields.length) {
445                                            if (orderByComparator.isAscending() ^ previous) {
446                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
447                                            }
448                                            else {
449                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
450                                            }
451                                    }
452                                    else {
453                                            if (orderByComparator.isAscending() ^ previous) {
454                                                    query.append(ORDER_BY_ASC);
455                                            }
456                                            else {
457                                                    query.append(ORDER_BY_DESC);
458                                            }
459                                    }
460                            }
461                    }
462                    else {
463                            query.append(TrashVersionModelImpl.ORDER_BY_JPQL);
464                    }
465    
466                    String sql = query.toString();
467    
468                    Query q = session.createQuery(sql);
469    
470                    q.setFirstResult(0);
471                    q.setMaxResults(2);
472    
473                    QueryPos qPos = QueryPos.getInstance(q);
474    
475                    qPos.add(entryId);
476    
477                    if (orderByComparator != null) {
478                            Object[] values = orderByComparator.getOrderByConditionValues(trashVersion);
479    
480                            for (Object value : values) {
481                                    qPos.add(value);
482                            }
483                    }
484    
485                    List<TrashVersion> list = q.list();
486    
487                    if (list.size() == 2) {
488                            return list.get(1);
489                    }
490                    else {
491                            return null;
492                    }
493            }
494    
495            /**
496             * Removes all the trash versions where entryId = &#63; from the database.
497             *
498             * @param entryId the entry ID
499             */
500            @Override
501            public void removeByEntryId(long entryId) {
502                    for (TrashVersion trashVersion : findByEntryId(entryId,
503                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
504                            remove(trashVersion);
505                    }
506            }
507    
508            /**
509             * Returns the number of trash versions where entryId = &#63;.
510             *
511             * @param entryId the entry ID
512             * @return the number of matching trash versions
513             */
514            @Override
515            public int countByEntryId(long entryId) {
516                    FinderPath finderPath = FINDER_PATH_COUNT_BY_ENTRYID;
517    
518                    Object[] finderArgs = new Object[] { entryId };
519    
520                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
521                                    this);
522    
523                    if (count == null) {
524                            StringBundler query = new StringBundler(2);
525    
526                            query.append(_SQL_COUNT_TRASHVERSION_WHERE);
527    
528                            query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
529    
530                            String sql = query.toString();
531    
532                            Session session = null;
533    
534                            try {
535                                    session = openSession();
536    
537                                    Query q = session.createQuery(sql);
538    
539                                    QueryPos qPos = QueryPos.getInstance(q);
540    
541                                    qPos.add(entryId);
542    
543                                    count = (Long)q.uniqueResult();
544    
545                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
546                            }
547                            catch (Exception e) {
548                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
549    
550                                    throw processException(e);
551                            }
552                            finally {
553                                    closeSession(session);
554                            }
555                    }
556    
557                    return count.intValue();
558            }
559    
560            private static final String _FINDER_COLUMN_ENTRYID_ENTRYID_2 = "trashVersion.entryId = ?";
561            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_E_C = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
562                            TrashVersionModelImpl.FINDER_CACHE_ENABLED, TrashVersionImpl.class,
563                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByE_C",
564                            new String[] {
565                                    Long.class.getName(), Long.class.getName(),
566                                    
567                            Integer.class.getName(), Integer.class.getName(),
568                                    OrderByComparator.class.getName()
569                            });
570            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E_C = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
571                            TrashVersionModelImpl.FINDER_CACHE_ENABLED, TrashVersionImpl.class,
572                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByE_C",
573                            new String[] { Long.class.getName(), Long.class.getName() },
574                            TrashVersionModelImpl.ENTRYID_COLUMN_BITMASK |
575                            TrashVersionModelImpl.CLASSNAMEID_COLUMN_BITMASK);
576            public static final FinderPath FINDER_PATH_COUNT_BY_E_C = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
577                            TrashVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
578                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByE_C",
579                            new String[] { Long.class.getName(), Long.class.getName() });
580    
581            /**
582             * Returns all the trash versions where entryId = &#63; and classNameId = &#63;.
583             *
584             * @param entryId the entry ID
585             * @param classNameId the class name ID
586             * @return the matching trash versions
587             */
588            @Override
589            public List<TrashVersion> findByE_C(long entryId, long classNameId) {
590                    return findByE_C(entryId, classNameId, QueryUtil.ALL_POS,
591                            QueryUtil.ALL_POS, null);
592            }
593    
594            /**
595             * Returns a range of all the trash versions where entryId = &#63; and classNameId = &#63;.
596             *
597             * <p>
598             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TrashVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
599             * </p>
600             *
601             * @param entryId the entry ID
602             * @param classNameId the class name ID
603             * @param start the lower bound of the range of trash versions
604             * @param end the upper bound of the range of trash versions (not inclusive)
605             * @return the range of matching trash versions
606             */
607            @Override
608            public List<TrashVersion> findByE_C(long entryId, long classNameId,
609                    int start, int end) {
610                    return findByE_C(entryId, classNameId, start, end, null);
611            }
612    
613            /**
614             * Returns an ordered range of all the trash versions where entryId = &#63; and classNameId = &#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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TrashVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
618             * </p>
619             *
620             * @param entryId the entry ID
621             * @param classNameId the class name ID
622             * @param start the lower bound of the range of trash versions
623             * @param end the upper bound of the range of trash versions (not inclusive)
624             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
625             * @return the ordered range of matching trash versions
626             */
627            @Override
628            public List<TrashVersion> findByE_C(long entryId, long classNameId,
629                    int start, int end, OrderByComparator<TrashVersion> orderByComparator) {
630                    boolean pagination = true;
631                    FinderPath finderPath = null;
632                    Object[] finderArgs = null;
633    
634                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
635                                    (orderByComparator == null)) {
636                            pagination = false;
637                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E_C;
638                            finderArgs = new Object[] { entryId, classNameId };
639                    }
640                    else {
641                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_E_C;
642                            finderArgs = new Object[] {
643                                            entryId, classNameId,
644                                            
645                                            start, end, orderByComparator
646                                    };
647                    }
648    
649                    List<TrashVersion> list = (List<TrashVersion>)FinderCacheUtil.getResult(finderPath,
650                                    finderArgs, this);
651    
652                    if ((list != null) && !list.isEmpty()) {
653                            for (TrashVersion trashVersion : list) {
654                                    if ((entryId != trashVersion.getEntryId()) ||
655                                                    (classNameId != trashVersion.getClassNameId())) {
656                                            list = null;
657    
658                                            break;
659                                    }
660                            }
661                    }
662    
663                    if (list == null) {
664                            StringBundler query = null;
665    
666                            if (orderByComparator != null) {
667                                    query = new StringBundler(4 +
668                                                    (orderByComparator.getOrderByFields().length * 3));
669                            }
670                            else {
671                                    query = new StringBundler(4);
672                            }
673    
674                            query.append(_SQL_SELECT_TRASHVERSION_WHERE);
675    
676                            query.append(_FINDER_COLUMN_E_C_ENTRYID_2);
677    
678                            query.append(_FINDER_COLUMN_E_C_CLASSNAMEID_2);
679    
680                            if (orderByComparator != null) {
681                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
682                                            orderByComparator);
683                            }
684                            else
685                             if (pagination) {
686                                    query.append(TrashVersionModelImpl.ORDER_BY_JPQL);
687                            }
688    
689                            String sql = query.toString();
690    
691                            Session session = null;
692    
693                            try {
694                                    session = openSession();
695    
696                                    Query q = session.createQuery(sql);
697    
698                                    QueryPos qPos = QueryPos.getInstance(q);
699    
700                                    qPos.add(entryId);
701    
702                                    qPos.add(classNameId);
703    
704                                    if (!pagination) {
705                                            list = (List<TrashVersion>)QueryUtil.list(q, getDialect(),
706                                                            start, end, false);
707    
708                                            Collections.sort(list);
709    
710                                            list = Collections.unmodifiableList(list);
711                                    }
712                                    else {
713                                            list = (List<TrashVersion>)QueryUtil.list(q, getDialect(),
714                                                            start, end);
715                                    }
716    
717                                    cacheResult(list);
718    
719                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
720                            }
721                            catch (Exception e) {
722                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
723    
724                                    throw processException(e);
725                            }
726                            finally {
727                                    closeSession(session);
728                            }
729                    }
730    
731                    return list;
732            }
733    
734            /**
735             * Returns the first trash version in the ordered set where entryId = &#63; and classNameId = &#63;.
736             *
737             * @param entryId the entry ID
738             * @param classNameId the class name ID
739             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
740             * @return the first matching trash version
741             * @throws NoSuchVersionException if a matching trash version could not be found
742             */
743            @Override
744            public TrashVersion findByE_C_First(long entryId, long classNameId,
745                    OrderByComparator<TrashVersion> orderByComparator)
746                    throws NoSuchVersionException {
747                    TrashVersion trashVersion = fetchByE_C_First(entryId, classNameId,
748                                    orderByComparator);
749    
750                    if (trashVersion != null) {
751                            return trashVersion;
752                    }
753    
754                    StringBundler msg = new StringBundler(6);
755    
756                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
757    
758                    msg.append("entryId=");
759                    msg.append(entryId);
760    
761                    msg.append(", classNameId=");
762                    msg.append(classNameId);
763    
764                    msg.append(StringPool.CLOSE_CURLY_BRACE);
765    
766                    throw new NoSuchVersionException(msg.toString());
767            }
768    
769            /**
770             * Returns the first trash version in the ordered set where entryId = &#63; and classNameId = &#63;.
771             *
772             * @param entryId the entry ID
773             * @param classNameId the class name ID
774             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
775             * @return the first matching trash version, or <code>null</code> if a matching trash version could not be found
776             */
777            @Override
778            public TrashVersion fetchByE_C_First(long entryId, long classNameId,
779                    OrderByComparator<TrashVersion> orderByComparator) {
780                    List<TrashVersion> list = findByE_C(entryId, classNameId, 0, 1,
781                                    orderByComparator);
782    
783                    if (!list.isEmpty()) {
784                            return list.get(0);
785                    }
786    
787                    return null;
788            }
789    
790            /**
791             * Returns the last trash version in the ordered set where entryId = &#63; and classNameId = &#63;.
792             *
793             * @param entryId the entry ID
794             * @param classNameId the class name ID
795             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
796             * @return the last matching trash version
797             * @throws NoSuchVersionException if a matching trash version could not be found
798             */
799            @Override
800            public TrashVersion findByE_C_Last(long entryId, long classNameId,
801                    OrderByComparator<TrashVersion> orderByComparator)
802                    throws NoSuchVersionException {
803                    TrashVersion trashVersion = fetchByE_C_Last(entryId, classNameId,
804                                    orderByComparator);
805    
806                    if (trashVersion != null) {
807                            return trashVersion;
808                    }
809    
810                    StringBundler msg = new StringBundler(6);
811    
812                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
813    
814                    msg.append("entryId=");
815                    msg.append(entryId);
816    
817                    msg.append(", classNameId=");
818                    msg.append(classNameId);
819    
820                    msg.append(StringPool.CLOSE_CURLY_BRACE);
821    
822                    throw new NoSuchVersionException(msg.toString());
823            }
824    
825            /**
826             * Returns the last trash version in the ordered set where entryId = &#63; and classNameId = &#63;.
827             *
828             * @param entryId the entry ID
829             * @param classNameId the class name ID
830             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
831             * @return the last matching trash version, or <code>null</code> if a matching trash version could not be found
832             */
833            @Override
834            public TrashVersion fetchByE_C_Last(long entryId, long classNameId,
835                    OrderByComparator<TrashVersion> orderByComparator) {
836                    int count = countByE_C(entryId, classNameId);
837    
838                    if (count == 0) {
839                            return null;
840                    }
841    
842                    List<TrashVersion> list = findByE_C(entryId, classNameId, count - 1,
843                                    count, orderByComparator);
844    
845                    if (!list.isEmpty()) {
846                            return list.get(0);
847                    }
848    
849                    return null;
850            }
851    
852            /**
853             * Returns the trash versions before and after the current trash version in the ordered set where entryId = &#63; and classNameId = &#63;.
854             *
855             * @param versionId the primary key of the current trash version
856             * @param entryId the entry ID
857             * @param classNameId the class name ID
858             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
859             * @return the previous, current, and next trash version
860             * @throws NoSuchVersionException if a trash version with the primary key could not be found
861             */
862            @Override
863            public TrashVersion[] findByE_C_PrevAndNext(long versionId, long entryId,
864                    long classNameId, OrderByComparator<TrashVersion> orderByComparator)
865                    throws NoSuchVersionException {
866                    TrashVersion trashVersion = findByPrimaryKey(versionId);
867    
868                    Session session = null;
869    
870                    try {
871                            session = openSession();
872    
873                            TrashVersion[] array = new TrashVersionImpl[3];
874    
875                            array[0] = getByE_C_PrevAndNext(session, trashVersion, entryId,
876                                            classNameId, orderByComparator, true);
877    
878                            array[1] = trashVersion;
879    
880                            array[2] = getByE_C_PrevAndNext(session, trashVersion, entryId,
881                                            classNameId, orderByComparator, false);
882    
883                            return array;
884                    }
885                    catch (Exception e) {
886                            throw processException(e);
887                    }
888                    finally {
889                            closeSession(session);
890                    }
891            }
892    
893            protected TrashVersion getByE_C_PrevAndNext(Session session,
894                    TrashVersion trashVersion, long entryId, long classNameId,
895                    OrderByComparator<TrashVersion> orderByComparator, boolean previous) {
896                    StringBundler query = null;
897    
898                    if (orderByComparator != null) {
899                            query = new StringBundler(6 +
900                                            (orderByComparator.getOrderByFields().length * 6));
901                    }
902                    else {
903                            query = new StringBundler(3);
904                    }
905    
906                    query.append(_SQL_SELECT_TRASHVERSION_WHERE);
907    
908                    query.append(_FINDER_COLUMN_E_C_ENTRYID_2);
909    
910                    query.append(_FINDER_COLUMN_E_C_CLASSNAMEID_2);
911    
912                    if (orderByComparator != null) {
913                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
914    
915                            if (orderByConditionFields.length > 0) {
916                                    query.append(WHERE_AND);
917                            }
918    
919                            for (int i = 0; i < orderByConditionFields.length; i++) {
920                                    query.append(_ORDER_BY_ENTITY_ALIAS);
921                                    query.append(orderByConditionFields[i]);
922    
923                                    if ((i + 1) < orderByConditionFields.length) {
924                                            if (orderByComparator.isAscending() ^ previous) {
925                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
926                                            }
927                                            else {
928                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
929                                            }
930                                    }
931                                    else {
932                                            if (orderByComparator.isAscending() ^ previous) {
933                                                    query.append(WHERE_GREATER_THAN);
934                                            }
935                                            else {
936                                                    query.append(WHERE_LESSER_THAN);
937                                            }
938                                    }
939                            }
940    
941                            query.append(ORDER_BY_CLAUSE);
942    
943                            String[] orderByFields = orderByComparator.getOrderByFields();
944    
945                            for (int i = 0; i < orderByFields.length; i++) {
946                                    query.append(_ORDER_BY_ENTITY_ALIAS);
947                                    query.append(orderByFields[i]);
948    
949                                    if ((i + 1) < orderByFields.length) {
950                                            if (orderByComparator.isAscending() ^ previous) {
951                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
952                                            }
953                                            else {
954                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
955                                            }
956                                    }
957                                    else {
958                                            if (orderByComparator.isAscending() ^ previous) {
959                                                    query.append(ORDER_BY_ASC);
960                                            }
961                                            else {
962                                                    query.append(ORDER_BY_DESC);
963                                            }
964                                    }
965                            }
966                    }
967                    else {
968                            query.append(TrashVersionModelImpl.ORDER_BY_JPQL);
969                    }
970    
971                    String sql = query.toString();
972    
973                    Query q = session.createQuery(sql);
974    
975                    q.setFirstResult(0);
976                    q.setMaxResults(2);
977    
978                    QueryPos qPos = QueryPos.getInstance(q);
979    
980                    qPos.add(entryId);
981    
982                    qPos.add(classNameId);
983    
984                    if (orderByComparator != null) {
985                            Object[] values = orderByComparator.getOrderByConditionValues(trashVersion);
986    
987                            for (Object value : values) {
988                                    qPos.add(value);
989                            }
990                    }
991    
992                    List<TrashVersion> list = q.list();
993    
994                    if (list.size() == 2) {
995                            return list.get(1);
996                    }
997                    else {
998                            return null;
999                    }
1000            }
1001    
1002            /**
1003             * Removes all the trash versions where entryId = &#63; and classNameId = &#63; from the database.
1004             *
1005             * @param entryId the entry ID
1006             * @param classNameId the class name ID
1007             */
1008            @Override
1009            public void removeByE_C(long entryId, long classNameId) {
1010                    for (TrashVersion trashVersion : findByE_C(entryId, classNameId,
1011                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1012                            remove(trashVersion);
1013                    }
1014            }
1015    
1016            /**
1017             * Returns the number of trash versions where entryId = &#63; and classNameId = &#63;.
1018             *
1019             * @param entryId the entry ID
1020             * @param classNameId the class name ID
1021             * @return the number of matching trash versions
1022             */
1023            @Override
1024            public int countByE_C(long entryId, long classNameId) {
1025                    FinderPath finderPath = FINDER_PATH_COUNT_BY_E_C;
1026    
1027                    Object[] finderArgs = new Object[] { entryId, classNameId };
1028    
1029                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1030                                    this);
1031    
1032                    if (count == null) {
1033                            StringBundler query = new StringBundler(3);
1034    
1035                            query.append(_SQL_COUNT_TRASHVERSION_WHERE);
1036    
1037                            query.append(_FINDER_COLUMN_E_C_ENTRYID_2);
1038    
1039                            query.append(_FINDER_COLUMN_E_C_CLASSNAMEID_2);
1040    
1041                            String sql = query.toString();
1042    
1043                            Session session = null;
1044    
1045                            try {
1046                                    session = openSession();
1047    
1048                                    Query q = session.createQuery(sql);
1049    
1050                                    QueryPos qPos = QueryPos.getInstance(q);
1051    
1052                                    qPos.add(entryId);
1053    
1054                                    qPos.add(classNameId);
1055    
1056                                    count = (Long)q.uniqueResult();
1057    
1058                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1059                            }
1060                            catch (Exception e) {
1061                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1062    
1063                                    throw processException(e);
1064                            }
1065                            finally {
1066                                    closeSession(session);
1067                            }
1068                    }
1069    
1070                    return count.intValue();
1071            }
1072    
1073            private static final String _FINDER_COLUMN_E_C_ENTRYID_2 = "trashVersion.entryId = ? AND ";
1074            private static final String _FINDER_COLUMN_E_C_CLASSNAMEID_2 = "trashVersion.classNameId = ?";
1075            public static final FinderPath FINDER_PATH_FETCH_BY_C_C = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1076                            TrashVersionModelImpl.FINDER_CACHE_ENABLED, TrashVersionImpl.class,
1077                            FINDER_CLASS_NAME_ENTITY, "fetchByC_C",
1078                            new String[] { Long.class.getName(), Long.class.getName() },
1079                            TrashVersionModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1080                            TrashVersionModelImpl.CLASSPK_COLUMN_BITMASK);
1081            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1082                            TrashVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1083                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
1084                            new String[] { Long.class.getName(), Long.class.getName() });
1085    
1086            /**
1087             * Returns the trash version where classNameId = &#63; and classPK = &#63; or throws a {@link NoSuchVersionException} if it could not be found.
1088             *
1089             * @param classNameId the class name ID
1090             * @param classPK the class p k
1091             * @return the matching trash version
1092             * @throws NoSuchVersionException if a matching trash version could not be found
1093             */
1094            @Override
1095            public TrashVersion findByC_C(long classNameId, long classPK)
1096                    throws NoSuchVersionException {
1097                    TrashVersion trashVersion = fetchByC_C(classNameId, classPK);
1098    
1099                    if (trashVersion == null) {
1100                            StringBundler msg = new StringBundler(6);
1101    
1102                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1103    
1104                            msg.append("classNameId=");
1105                            msg.append(classNameId);
1106    
1107                            msg.append(", classPK=");
1108                            msg.append(classPK);
1109    
1110                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1111    
1112                            if (_log.isWarnEnabled()) {
1113                                    _log.warn(msg.toString());
1114                            }
1115    
1116                            throw new NoSuchVersionException(msg.toString());
1117                    }
1118    
1119                    return trashVersion;
1120            }
1121    
1122            /**
1123             * Returns the trash version where classNameId = &#63; and classPK = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1124             *
1125             * @param classNameId the class name ID
1126             * @param classPK the class p k
1127             * @return the matching trash version, or <code>null</code> if a matching trash version could not be found
1128             */
1129            @Override
1130            public TrashVersion fetchByC_C(long classNameId, long classPK) {
1131                    return fetchByC_C(classNameId, classPK, true);
1132            }
1133    
1134            /**
1135             * Returns the trash version where classNameId = &#63; and classPK = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1136             *
1137             * @param classNameId the class name ID
1138             * @param classPK the class p k
1139             * @param retrieveFromCache whether to use the finder cache
1140             * @return the matching trash version, or <code>null</code> if a matching trash version could not be found
1141             */
1142            @Override
1143            public TrashVersion fetchByC_C(long classNameId, long classPK,
1144                    boolean retrieveFromCache) {
1145                    Object[] finderArgs = new Object[] { classNameId, classPK };
1146    
1147                    Object result = null;
1148    
1149                    if (retrieveFromCache) {
1150                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C,
1151                                            finderArgs, this);
1152                    }
1153    
1154                    if (result instanceof TrashVersion) {
1155                            TrashVersion trashVersion = (TrashVersion)result;
1156    
1157                            if ((classNameId != trashVersion.getClassNameId()) ||
1158                                            (classPK != trashVersion.getClassPK())) {
1159                                    result = null;
1160                            }
1161                    }
1162    
1163                    if (result == null) {
1164                            StringBundler query = new StringBundler(4);
1165    
1166                            query.append(_SQL_SELECT_TRASHVERSION_WHERE);
1167    
1168                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1169    
1170                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1171    
1172                            String sql = query.toString();
1173    
1174                            Session session = null;
1175    
1176                            try {
1177                                    session = openSession();
1178    
1179                                    Query q = session.createQuery(sql);
1180    
1181                                    QueryPos qPos = QueryPos.getInstance(q);
1182    
1183                                    qPos.add(classNameId);
1184    
1185                                    qPos.add(classPK);
1186    
1187                                    List<TrashVersion> list = q.list();
1188    
1189                                    if (list.isEmpty()) {
1190                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
1191                                                    finderArgs, list);
1192                                    }
1193                                    else {
1194                                            TrashVersion trashVersion = list.get(0);
1195    
1196                                            result = trashVersion;
1197    
1198                                            cacheResult(trashVersion);
1199    
1200                                            if ((trashVersion.getClassNameId() != classNameId) ||
1201                                                            (trashVersion.getClassPK() != classPK)) {
1202                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
1203                                                            finderArgs, trashVersion);
1204                                            }
1205                                    }
1206                            }
1207                            catch (Exception e) {
1208                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
1209                                            finderArgs);
1210    
1211                                    throw processException(e);
1212                            }
1213                            finally {
1214                                    closeSession(session);
1215                            }
1216                    }
1217    
1218                    if (result instanceof List<?>) {
1219                            return null;
1220                    }
1221                    else {
1222                            return (TrashVersion)result;
1223                    }
1224            }
1225    
1226            /**
1227             * Removes the trash version where classNameId = &#63; and classPK = &#63; from the database.
1228             *
1229             * @param classNameId the class name ID
1230             * @param classPK the class p k
1231             * @return the trash version that was removed
1232             */
1233            @Override
1234            public TrashVersion removeByC_C(long classNameId, long classPK)
1235                    throws NoSuchVersionException {
1236                    TrashVersion trashVersion = findByC_C(classNameId, classPK);
1237    
1238                    return remove(trashVersion);
1239            }
1240    
1241            /**
1242             * Returns the number of trash versions where classNameId = &#63; and classPK = &#63;.
1243             *
1244             * @param classNameId the class name ID
1245             * @param classPK the class p k
1246             * @return the number of matching trash versions
1247             */
1248            @Override
1249            public int countByC_C(long classNameId, long classPK) {
1250                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
1251    
1252                    Object[] finderArgs = new Object[] { classNameId, classPK };
1253    
1254                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1255                                    this);
1256    
1257                    if (count == null) {
1258                            StringBundler query = new StringBundler(3);
1259    
1260                            query.append(_SQL_COUNT_TRASHVERSION_WHERE);
1261    
1262                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1263    
1264                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1265    
1266                            String sql = query.toString();
1267    
1268                            Session session = null;
1269    
1270                            try {
1271                                    session = openSession();
1272    
1273                                    Query q = session.createQuery(sql);
1274    
1275                                    QueryPos qPos = QueryPos.getInstance(q);
1276    
1277                                    qPos.add(classNameId);
1278    
1279                                    qPos.add(classPK);
1280    
1281                                    count = (Long)q.uniqueResult();
1282    
1283                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1284                            }
1285                            catch (Exception e) {
1286                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1287    
1288                                    throw processException(e);
1289                            }
1290                            finally {
1291                                    closeSession(session);
1292                            }
1293                    }
1294    
1295                    return count.intValue();
1296            }
1297    
1298            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "trashVersion.classNameId = ? AND ";
1299            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "trashVersion.classPK = ?";
1300    
1301            public TrashVersionPersistenceImpl() {
1302                    setModelClass(TrashVersion.class);
1303            }
1304    
1305            /**
1306             * Caches the trash version in the entity cache if it is enabled.
1307             *
1308             * @param trashVersion the trash version
1309             */
1310            @Override
1311            public void cacheResult(TrashVersion trashVersion) {
1312                    EntityCacheUtil.putResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1313                            TrashVersionImpl.class, trashVersion.getPrimaryKey(), trashVersion);
1314    
1315                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
1316                            new Object[] {
1317                                    trashVersion.getClassNameId(), trashVersion.getClassPK()
1318                            }, trashVersion);
1319    
1320                    trashVersion.resetOriginalValues();
1321            }
1322    
1323            /**
1324             * Caches the trash versions in the entity cache if it is enabled.
1325             *
1326             * @param trashVersions the trash versions
1327             */
1328            @Override
1329            public void cacheResult(List<TrashVersion> trashVersions) {
1330                    for (TrashVersion trashVersion : trashVersions) {
1331                            if (EntityCacheUtil.getResult(
1332                                                    TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1333                                                    TrashVersionImpl.class, trashVersion.getPrimaryKey()) == null) {
1334                                    cacheResult(trashVersion);
1335                            }
1336                            else {
1337                                    trashVersion.resetOriginalValues();
1338                            }
1339                    }
1340            }
1341    
1342            /**
1343             * Clears the cache for all trash versions.
1344             *
1345             * <p>
1346             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1347             * </p>
1348             */
1349            @Override
1350            public void clearCache() {
1351                    EntityCacheUtil.clearCache(TrashVersionImpl.class);
1352    
1353                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1354                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1355                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1356            }
1357    
1358            /**
1359             * Clears the cache for the trash version.
1360             *
1361             * <p>
1362             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1363             * </p>
1364             */
1365            @Override
1366            public void clearCache(TrashVersion trashVersion) {
1367                    EntityCacheUtil.removeResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1368                            TrashVersionImpl.class, trashVersion.getPrimaryKey());
1369    
1370                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1371                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1372    
1373                    clearUniqueFindersCache(trashVersion);
1374            }
1375    
1376            @Override
1377            public void clearCache(List<TrashVersion> trashVersions) {
1378                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1379                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1380    
1381                    for (TrashVersion trashVersion : trashVersions) {
1382                            EntityCacheUtil.removeResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1383                                    TrashVersionImpl.class, trashVersion.getPrimaryKey());
1384    
1385                            clearUniqueFindersCache(trashVersion);
1386                    }
1387            }
1388    
1389            protected void cacheUniqueFindersCache(TrashVersion trashVersion) {
1390                    if (trashVersion.isNew()) {
1391                            Object[] args = new Object[] {
1392                                            trashVersion.getClassNameId(), trashVersion.getClassPK()
1393                                    };
1394    
1395                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, args,
1396                                    Long.valueOf(1));
1397                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C, args,
1398                                    trashVersion);
1399                    }
1400                    else {
1401                            TrashVersionModelImpl trashVersionModelImpl = (TrashVersionModelImpl)trashVersion;
1402    
1403                            if ((trashVersionModelImpl.getColumnBitmask() &
1404                                            FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
1405                                    Object[] args = new Object[] {
1406                                                    trashVersion.getClassNameId(), trashVersion.getClassPK()
1407                                            };
1408    
1409                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, args,
1410                                            Long.valueOf(1));
1411                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C, args,
1412                                            trashVersion);
1413                            }
1414                    }
1415            }
1416    
1417            protected void clearUniqueFindersCache(TrashVersion trashVersion) {
1418                    TrashVersionModelImpl trashVersionModelImpl = (TrashVersionModelImpl)trashVersion;
1419    
1420                    Object[] args = new Object[] {
1421                                    trashVersion.getClassNameId(), trashVersion.getClassPK()
1422                            };
1423    
1424                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1425                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
1426    
1427                    if ((trashVersionModelImpl.getColumnBitmask() &
1428                                    FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
1429                            args = new Object[] {
1430                                            trashVersionModelImpl.getOriginalClassNameId(),
1431                                            trashVersionModelImpl.getOriginalClassPK()
1432                                    };
1433    
1434                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1435                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
1436                    }
1437            }
1438    
1439            /**
1440             * Creates a new trash version with the primary key. Does not add the trash version to the database.
1441             *
1442             * @param versionId the primary key for the new trash version
1443             * @return the new trash version
1444             */
1445            @Override
1446            public TrashVersion create(long versionId) {
1447                    TrashVersion trashVersion = new TrashVersionImpl();
1448    
1449                    trashVersion.setNew(true);
1450                    trashVersion.setPrimaryKey(versionId);
1451    
1452                    return trashVersion;
1453            }
1454    
1455            /**
1456             * Removes the trash version with the primary key from the database. Also notifies the appropriate model listeners.
1457             *
1458             * @param versionId the primary key of the trash version
1459             * @return the trash version that was removed
1460             * @throws NoSuchVersionException if a trash version with the primary key could not be found
1461             */
1462            @Override
1463            public TrashVersion remove(long versionId) throws NoSuchVersionException {
1464                    return remove((Serializable)versionId);
1465            }
1466    
1467            /**
1468             * Removes the trash version with the primary key from the database. Also notifies the appropriate model listeners.
1469             *
1470             * @param primaryKey the primary key of the trash version
1471             * @return the trash version that was removed
1472             * @throws NoSuchVersionException if a trash version with the primary key could not be found
1473             */
1474            @Override
1475            public TrashVersion remove(Serializable primaryKey)
1476                    throws NoSuchVersionException {
1477                    Session session = null;
1478    
1479                    try {
1480                            session = openSession();
1481    
1482                            TrashVersion trashVersion = (TrashVersion)session.get(TrashVersionImpl.class,
1483                                            primaryKey);
1484    
1485                            if (trashVersion == null) {
1486                                    if (_log.isWarnEnabled()) {
1487                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1488                                    }
1489    
1490                                    throw new NoSuchVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1491                                            primaryKey);
1492                            }
1493    
1494                            return remove(trashVersion);
1495                    }
1496                    catch (NoSuchVersionException nsee) {
1497                            throw nsee;
1498                    }
1499                    catch (Exception e) {
1500                            throw processException(e);
1501                    }
1502                    finally {
1503                            closeSession(session);
1504                    }
1505            }
1506    
1507            @Override
1508            protected TrashVersion removeImpl(TrashVersion trashVersion) {
1509                    trashVersion = toUnwrappedModel(trashVersion);
1510    
1511                    Session session = null;
1512    
1513                    try {
1514                            session = openSession();
1515    
1516                            if (!session.contains(trashVersion)) {
1517                                    trashVersion = (TrashVersion)session.get(TrashVersionImpl.class,
1518                                                    trashVersion.getPrimaryKeyObj());
1519                            }
1520    
1521                            if (trashVersion != null) {
1522                                    session.delete(trashVersion);
1523                            }
1524                    }
1525                    catch (Exception e) {
1526                            throw processException(e);
1527                    }
1528                    finally {
1529                            closeSession(session);
1530                    }
1531    
1532                    if (trashVersion != null) {
1533                            clearCache(trashVersion);
1534                    }
1535    
1536                    return trashVersion;
1537            }
1538    
1539            @Override
1540            public TrashVersion updateImpl(TrashVersion trashVersion) {
1541                    trashVersion = toUnwrappedModel(trashVersion);
1542    
1543                    boolean isNew = trashVersion.isNew();
1544    
1545                    TrashVersionModelImpl trashVersionModelImpl = (TrashVersionModelImpl)trashVersion;
1546    
1547                    Session session = null;
1548    
1549                    try {
1550                            session = openSession();
1551    
1552                            if (trashVersion.isNew()) {
1553                                    session.save(trashVersion);
1554    
1555                                    trashVersion.setNew(false);
1556                            }
1557                            else {
1558                                    session.merge(trashVersion);
1559                            }
1560                    }
1561                    catch (Exception e) {
1562                            throw processException(e);
1563                    }
1564                    finally {
1565                            closeSession(session);
1566                    }
1567    
1568                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1569    
1570                    if (isNew || !TrashVersionModelImpl.COLUMN_BITMASK_ENABLED) {
1571                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1572                    }
1573    
1574                    else {
1575                            if ((trashVersionModelImpl.getColumnBitmask() &
1576                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID.getColumnBitmask()) != 0) {
1577                                    Object[] args = new Object[] {
1578                                                    trashVersionModelImpl.getOriginalEntryId()
1579                                            };
1580    
1581                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ENTRYID, args);
1582                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID,
1583                                            args);
1584    
1585                                    args = new Object[] { trashVersionModelImpl.getEntryId() };
1586    
1587                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ENTRYID, args);
1588                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID,
1589                                            args);
1590                            }
1591    
1592                            if ((trashVersionModelImpl.getColumnBitmask() &
1593                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E_C.getColumnBitmask()) != 0) {
1594                                    Object[] args = new Object[] {
1595                                                    trashVersionModelImpl.getOriginalEntryId(),
1596                                                    trashVersionModelImpl.getOriginalClassNameId()
1597                                            };
1598    
1599                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_E_C, args);
1600                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E_C,
1601                                            args);
1602    
1603                                    args = new Object[] {
1604                                                    trashVersionModelImpl.getEntryId(),
1605                                                    trashVersionModelImpl.getClassNameId()
1606                                            };
1607    
1608                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_E_C, args);
1609                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E_C,
1610                                            args);
1611                            }
1612                    }
1613    
1614                    EntityCacheUtil.putResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1615                            TrashVersionImpl.class, trashVersion.getPrimaryKey(), trashVersion,
1616                            false);
1617    
1618                    clearUniqueFindersCache(trashVersion);
1619                    cacheUniqueFindersCache(trashVersion);
1620    
1621                    trashVersion.resetOriginalValues();
1622    
1623                    return trashVersion;
1624            }
1625    
1626            protected TrashVersion toUnwrappedModel(TrashVersion trashVersion) {
1627                    if (trashVersion instanceof TrashVersionImpl) {
1628                            return trashVersion;
1629                    }
1630    
1631                    TrashVersionImpl trashVersionImpl = new TrashVersionImpl();
1632    
1633                    trashVersionImpl.setNew(trashVersion.isNew());
1634                    trashVersionImpl.setPrimaryKey(trashVersion.getPrimaryKey());
1635    
1636                    trashVersionImpl.setVersionId(trashVersion.getVersionId());
1637                    trashVersionImpl.setEntryId(trashVersion.getEntryId());
1638                    trashVersionImpl.setClassNameId(trashVersion.getClassNameId());
1639                    trashVersionImpl.setClassPK(trashVersion.getClassPK());
1640                    trashVersionImpl.setTypeSettings(trashVersion.getTypeSettings());
1641                    trashVersionImpl.setStatus(trashVersion.getStatus());
1642    
1643                    return trashVersionImpl;
1644            }
1645    
1646            /**
1647             * Returns the trash version with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1648             *
1649             * @param primaryKey the primary key of the trash version
1650             * @return the trash version
1651             * @throws NoSuchVersionException if a trash version with the primary key could not be found
1652             */
1653            @Override
1654            public TrashVersion findByPrimaryKey(Serializable primaryKey)
1655                    throws NoSuchVersionException {
1656                    TrashVersion trashVersion = fetchByPrimaryKey(primaryKey);
1657    
1658                    if (trashVersion == null) {
1659                            if (_log.isWarnEnabled()) {
1660                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1661                            }
1662    
1663                            throw new NoSuchVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1664                                    primaryKey);
1665                    }
1666    
1667                    return trashVersion;
1668            }
1669    
1670            /**
1671             * Returns the trash version with the primary key or throws a {@link NoSuchVersionException} if it could not be found.
1672             *
1673             * @param versionId the primary key of the trash version
1674             * @return the trash version
1675             * @throws NoSuchVersionException if a trash version with the primary key could not be found
1676             */
1677            @Override
1678            public TrashVersion findByPrimaryKey(long versionId)
1679                    throws NoSuchVersionException {
1680                    return findByPrimaryKey((Serializable)versionId);
1681            }
1682    
1683            /**
1684             * Returns the trash version with the primary key or returns <code>null</code> if it could not be found.
1685             *
1686             * @param primaryKey the primary key of the trash version
1687             * @return the trash version, or <code>null</code> if a trash version with the primary key could not be found
1688             */
1689            @Override
1690            public TrashVersion fetchByPrimaryKey(Serializable primaryKey) {
1691                    TrashVersion trashVersion = (TrashVersion)EntityCacheUtil.getResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1692                                    TrashVersionImpl.class, primaryKey);
1693    
1694                    if (trashVersion == _nullTrashVersion) {
1695                            return null;
1696                    }
1697    
1698                    if (trashVersion == null) {
1699                            Session session = null;
1700    
1701                            try {
1702                                    session = openSession();
1703    
1704                                    trashVersion = (TrashVersion)session.get(TrashVersionImpl.class,
1705                                                    primaryKey);
1706    
1707                                    if (trashVersion != null) {
1708                                            cacheResult(trashVersion);
1709                                    }
1710                                    else {
1711                                            EntityCacheUtil.putResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1712                                                    TrashVersionImpl.class, primaryKey, _nullTrashVersion);
1713                                    }
1714                            }
1715                            catch (Exception e) {
1716                                    EntityCacheUtil.removeResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1717                                            TrashVersionImpl.class, primaryKey);
1718    
1719                                    throw processException(e);
1720                            }
1721                            finally {
1722                                    closeSession(session);
1723                            }
1724                    }
1725    
1726                    return trashVersion;
1727            }
1728    
1729            /**
1730             * Returns the trash version with the primary key or returns <code>null</code> if it could not be found.
1731             *
1732             * @param versionId the primary key of the trash version
1733             * @return the trash version, or <code>null</code> if a trash version with the primary key could not be found
1734             */
1735            @Override
1736            public TrashVersion fetchByPrimaryKey(long versionId) {
1737                    return fetchByPrimaryKey((Serializable)versionId);
1738            }
1739    
1740            @Override
1741            public Map<Serializable, TrashVersion> fetchByPrimaryKeys(
1742                    Set<Serializable> primaryKeys) {
1743                    if (primaryKeys.isEmpty()) {
1744                            return Collections.emptyMap();
1745                    }
1746    
1747                    Map<Serializable, TrashVersion> map = new HashMap<Serializable, TrashVersion>();
1748    
1749                    if (primaryKeys.size() == 1) {
1750                            Iterator<Serializable> iterator = primaryKeys.iterator();
1751    
1752                            Serializable primaryKey = iterator.next();
1753    
1754                            TrashVersion trashVersion = fetchByPrimaryKey(primaryKey);
1755    
1756                            if (trashVersion != null) {
1757                                    map.put(primaryKey, trashVersion);
1758                            }
1759    
1760                            return map;
1761                    }
1762    
1763                    Set<Serializable> uncachedPrimaryKeys = null;
1764    
1765                    for (Serializable primaryKey : primaryKeys) {
1766                            TrashVersion trashVersion = (TrashVersion)EntityCacheUtil.getResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1767                                            TrashVersionImpl.class, primaryKey);
1768    
1769                            if (trashVersion == null) {
1770                                    if (uncachedPrimaryKeys == null) {
1771                                            uncachedPrimaryKeys = new HashSet<Serializable>();
1772                                    }
1773    
1774                                    uncachedPrimaryKeys.add(primaryKey);
1775                            }
1776                            else {
1777                                    map.put(primaryKey, trashVersion);
1778                            }
1779                    }
1780    
1781                    if (uncachedPrimaryKeys == null) {
1782                            return map;
1783                    }
1784    
1785                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1786                                    1);
1787    
1788                    query.append(_SQL_SELECT_TRASHVERSION_WHERE_PKS_IN);
1789    
1790                    for (Serializable primaryKey : uncachedPrimaryKeys) {
1791                            query.append(String.valueOf(primaryKey));
1792    
1793                            query.append(StringPool.COMMA);
1794                    }
1795    
1796                    query.setIndex(query.index() - 1);
1797    
1798                    query.append(StringPool.CLOSE_PARENTHESIS);
1799    
1800                    String sql = query.toString();
1801    
1802                    Session session = null;
1803    
1804                    try {
1805                            session = openSession();
1806    
1807                            Query q = session.createQuery(sql);
1808    
1809                            for (TrashVersion trashVersion : (List<TrashVersion>)q.list()) {
1810                                    map.put(trashVersion.getPrimaryKeyObj(), trashVersion);
1811    
1812                                    cacheResult(trashVersion);
1813    
1814                                    uncachedPrimaryKeys.remove(trashVersion.getPrimaryKeyObj());
1815                            }
1816    
1817                            for (Serializable primaryKey : uncachedPrimaryKeys) {
1818                                    EntityCacheUtil.putResult(TrashVersionModelImpl.ENTITY_CACHE_ENABLED,
1819                                            TrashVersionImpl.class, primaryKey, _nullTrashVersion);
1820                            }
1821                    }
1822                    catch (Exception e) {
1823                            throw processException(e);
1824                    }
1825                    finally {
1826                            closeSession(session);
1827                    }
1828    
1829                    return map;
1830            }
1831    
1832            /**
1833             * Returns all the trash versions.
1834             *
1835             * @return the trash versions
1836             */
1837            @Override
1838            public List<TrashVersion> findAll() {
1839                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1840            }
1841    
1842            /**
1843             * Returns a range of all the trash versions.
1844             *
1845             * <p>
1846             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TrashVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1847             * </p>
1848             *
1849             * @param start the lower bound of the range of trash versions
1850             * @param end the upper bound of the range of trash versions (not inclusive)
1851             * @return the range of trash versions
1852             */
1853            @Override
1854            public List<TrashVersion> findAll(int start, int end) {
1855                    return findAll(start, end, null);
1856            }
1857    
1858            /**
1859             * Returns an ordered range of all the trash versions.
1860             *
1861             * <p>
1862             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TrashVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1863             * </p>
1864             *
1865             * @param start the lower bound of the range of trash versions
1866             * @param end the upper bound of the range of trash versions (not inclusive)
1867             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1868             * @return the ordered range of trash versions
1869             */
1870            @Override
1871            public List<TrashVersion> findAll(int start, int end,
1872                    OrderByComparator<TrashVersion> orderByComparator) {
1873                    boolean pagination = true;
1874                    FinderPath finderPath = null;
1875                    Object[] finderArgs = null;
1876    
1877                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1878                                    (orderByComparator == null)) {
1879                            pagination = false;
1880                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1881                            finderArgs = FINDER_ARGS_EMPTY;
1882                    }
1883                    else {
1884                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1885                            finderArgs = new Object[] { start, end, orderByComparator };
1886                    }
1887    
1888                    List<TrashVersion> list = (List<TrashVersion>)FinderCacheUtil.getResult(finderPath,
1889                                    finderArgs, this);
1890    
1891                    if (list == null) {
1892                            StringBundler query = null;
1893                            String sql = null;
1894    
1895                            if (orderByComparator != null) {
1896                                    query = new StringBundler(2 +
1897                                                    (orderByComparator.getOrderByFields().length * 3));
1898    
1899                                    query.append(_SQL_SELECT_TRASHVERSION);
1900    
1901                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1902                                            orderByComparator);
1903    
1904                                    sql = query.toString();
1905                            }
1906                            else {
1907                                    sql = _SQL_SELECT_TRASHVERSION;
1908    
1909                                    if (pagination) {
1910                                            sql = sql.concat(TrashVersionModelImpl.ORDER_BY_JPQL);
1911                                    }
1912                            }
1913    
1914                            Session session = null;
1915    
1916                            try {
1917                                    session = openSession();
1918    
1919                                    Query q = session.createQuery(sql);
1920    
1921                                    if (!pagination) {
1922                                            list = (List<TrashVersion>)QueryUtil.list(q, getDialect(),
1923                                                            start, end, false);
1924    
1925                                            Collections.sort(list);
1926    
1927                                            list = Collections.unmodifiableList(list);
1928                                    }
1929                                    else {
1930                                            list = (List<TrashVersion>)QueryUtil.list(q, getDialect(),
1931                                                            start, end);
1932                                    }
1933    
1934                                    cacheResult(list);
1935    
1936                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1937                            }
1938                            catch (Exception e) {
1939                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1940    
1941                                    throw processException(e);
1942                            }
1943                            finally {
1944                                    closeSession(session);
1945                            }
1946                    }
1947    
1948                    return list;
1949            }
1950    
1951            /**
1952             * Removes all the trash versions from the database.
1953             *
1954             */
1955            @Override
1956            public void removeAll() {
1957                    for (TrashVersion trashVersion : findAll()) {
1958                            remove(trashVersion);
1959                    }
1960            }
1961    
1962            /**
1963             * Returns the number of trash versions.
1964             *
1965             * @return the number of trash versions
1966             */
1967            @Override
1968            public int countAll() {
1969                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1970                                    FINDER_ARGS_EMPTY, this);
1971    
1972                    if (count == null) {
1973                            Session session = null;
1974    
1975                            try {
1976                                    session = openSession();
1977    
1978                                    Query q = session.createQuery(_SQL_COUNT_TRASHVERSION);
1979    
1980                                    count = (Long)q.uniqueResult();
1981    
1982                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1983                                            FINDER_ARGS_EMPTY, count);
1984                            }
1985                            catch (Exception e) {
1986                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1987                                            FINDER_ARGS_EMPTY);
1988    
1989                                    throw processException(e);
1990                            }
1991                            finally {
1992                                    closeSession(session);
1993                            }
1994                    }
1995    
1996                    return count.intValue();
1997            }
1998    
1999            /**
2000             * Initializes the trash version persistence.
2001             */
2002            public void afterPropertiesSet() {
2003            }
2004    
2005            public void destroy() {
2006                    EntityCacheUtil.removeCache(TrashVersionImpl.class.getName());
2007                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2008                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2009                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2010            }
2011    
2012            private static final String _SQL_SELECT_TRASHVERSION = "SELECT trashVersion FROM TrashVersion trashVersion";
2013            private static final String _SQL_SELECT_TRASHVERSION_WHERE_PKS_IN = "SELECT trashVersion FROM TrashVersion trashVersion WHERE versionId IN (";
2014            private static final String _SQL_SELECT_TRASHVERSION_WHERE = "SELECT trashVersion FROM TrashVersion trashVersion WHERE ";
2015            private static final String _SQL_COUNT_TRASHVERSION = "SELECT COUNT(trashVersion) FROM TrashVersion trashVersion";
2016            private static final String _SQL_COUNT_TRASHVERSION_WHERE = "SELECT COUNT(trashVersion) FROM TrashVersion trashVersion WHERE ";
2017            private static final String _ORDER_BY_ENTITY_ALIAS = "trashVersion.";
2018            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No TrashVersion exists with the primary key ";
2019            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No TrashVersion exists with the key {";
2020            private static final Log _log = LogFactoryUtil.getLog(TrashVersionPersistenceImpl.class);
2021            private static final TrashVersion _nullTrashVersion = new TrashVersionImpl() {
2022                            @Override
2023                            public Object clone() {
2024                                    return this;
2025                            }
2026    
2027                            @Override
2028                            public CacheModel<TrashVersion> toCacheModel() {
2029                                    return _nullTrashVersionCacheModel;
2030                            }
2031                    };
2032    
2033            private static final CacheModel<TrashVersion> _nullTrashVersionCacheModel = new CacheModel<TrashVersion>() {
2034                            @Override
2035                            public TrashVersion toEntityModel() {
2036                                    return _nullTrashVersion;
2037                            }
2038                    };
2039    }