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