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