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