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