001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.trash.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderPath;
022    import com.liferay.portal.kernel.dao.orm.Query;
023    import com.liferay.portal.kernel.dao.orm.QueryPos;
024    import com.liferay.portal.kernel.dao.orm.QueryUtil;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.log.Log;
027    import com.liferay.portal.kernel.log.LogFactoryUtil;
028    import com.liferay.portal.kernel.util.OrderByComparator;
029    import com.liferay.portal.kernel.util.StringBundler;
030    import com.liferay.portal.kernel.util.StringPool;
031    import com.liferay.portal.model.CacheModel;
032    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
033    
034    import com.liferay.portlet.trash.NoSuchEntryException;
035    import com.liferay.portlet.trash.model.TrashEntry;
036    import com.liferay.portlet.trash.model.impl.TrashEntryImpl;
037    import com.liferay.portlet.trash.model.impl.TrashEntryModelImpl;
038    import com.liferay.portlet.trash.service.persistence.TrashEntryPersistence;
039    
040    import java.io.Serializable;
041    
042    import java.sql.Timestamp;
043    
044    import java.util.Collections;
045    import java.util.Date;
046    import java.util.HashMap;
047    import java.util.HashSet;
048    import java.util.Iterator;
049    import java.util.List;
050    import java.util.Map;
051    import java.util.Set;
052    
053    /**
054     * The persistence implementation for the trash entry service.
055     *
056     * <p>
057     * Caching information and settings can be found in <code>portal.properties</code>
058     * </p>
059     *
060     * @author Brian Wing Shun Chan
061     * @see TrashEntryPersistence
062     * @see com.liferay.portlet.trash.service.persistence.TrashEntryUtil
063     * @generated
064     */
065    @ProviderType
066    public class TrashEntryPersistenceImpl extends BasePersistenceImpl<TrashEntry>
067            implements TrashEntryPersistence {
068            /*
069             * NOTE FOR DEVELOPERS:
070             *
071             * Never modify or reference this class directly. Always use {@link TrashEntryUtil} to access the trash entry persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
072             */
073            public static final String FINDER_CLASS_NAME_ENTITY = TrashEntryImpl.class.getName();
074            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075                    ".List1";
076            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077                    ".List2";
078            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
079                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
080                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
081            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
082                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
083                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
084            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
085                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
087            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
088                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
089                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
090                            new String[] {
091                                    Long.class.getName(),
092                                    
093                            Integer.class.getName(), Integer.class.getName(),
094                                    OrderByComparator.class.getName()
095                            });
096            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
097                    new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
098                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
099                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
100                            new String[] { Long.class.getName() },
101                            TrashEntryModelImpl.GROUPID_COLUMN_BITMASK |
102                            TrashEntryModelImpl.CREATEDATE_COLUMN_BITMASK);
103            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
104                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
105                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
106                            new String[] { Long.class.getName() });
107    
108            /**
109             * Returns all the trash entries where groupId = &#63;.
110             *
111             * @param groupId the group ID
112             * @return the matching trash entries
113             */
114            @Override
115            public List<TrashEntry> findByGroupId(long groupId) {
116                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
117            }
118    
119            /**
120             * Returns a range of all the trash entries where groupId = &#63;.
121             *
122             * <p>
123             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TrashEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
124             * </p>
125             *
126             * @param groupId the group ID
127             * @param start the lower bound of the range of trash entries
128             * @param end the upper bound of the range of trash entries (not inclusive)
129             * @return the range of matching trash entries
130             */
131            @Override
132            public List<TrashEntry> findByGroupId(long groupId, int start, int end) {
133                    return findByGroupId(groupId, start, end, null);
134            }
135    
136            /**
137             * Returns an ordered range of all the trash entries where groupId = &#63;.
138             *
139             * <p>
140             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TrashEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
141             * </p>
142             *
143             * @param groupId the group ID
144             * @param start the lower bound of the range of trash entries
145             * @param end the upper bound of the range of trash entries (not inclusive)
146             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
147             * @return the ordered range of matching trash entries
148             */
149            @Override
150            public List<TrashEntry> findByGroupId(long groupId, int start, int end,
151                    OrderByComparator<TrashEntry> orderByComparator) {
152                    boolean pagination = true;
153                    FinderPath finderPath = null;
154                    Object[] finderArgs = null;
155    
156                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
157                                    (orderByComparator == null)) {
158                            pagination = false;
159                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
160                            finderArgs = new Object[] { groupId };
161                    }
162                    else {
163                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
164                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
165                    }
166    
167                    List<TrashEntry> list = (List<TrashEntry>)FinderCacheUtil.getResult(finderPath,
168                                    finderArgs, this);
169    
170                    if ((list != null) && !list.isEmpty()) {
171                            for (TrashEntry trashEntry : list) {
172                                    if ((groupId != trashEntry.getGroupId())) {
173                                            list = null;
174    
175                                            break;
176                                    }
177                            }
178                    }
179    
180                    if (list == null) {
181                            StringBundler query = null;
182    
183                            if (orderByComparator != null) {
184                                    query = new StringBundler(3 +
185                                                    (orderByComparator.getOrderByFields().length * 3));
186                            }
187                            else {
188                                    query = new StringBundler(3);
189                            }
190    
191                            query.append(_SQL_SELECT_TRASHENTRY_WHERE);
192    
193                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
194    
195                            if (orderByComparator != null) {
196                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
197                                            orderByComparator);
198                            }
199                            else
200                             if (pagination) {
201                                    query.append(TrashEntryModelImpl.ORDER_BY_JPQL);
202                            }
203    
204                            String sql = query.toString();
205    
206                            Session session = null;
207    
208                            try {
209                                    session = openSession();
210    
211                                    Query q = session.createQuery(sql);
212    
213                                    QueryPos qPos = QueryPos.getInstance(q);
214    
215                                    qPos.add(groupId);
216    
217                                    if (!pagination) {
218                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
219                                                            start, end, false);
220    
221                                            Collections.sort(list);
222    
223                                            list = Collections.unmodifiableList(list);
224                                    }
225                                    else {
226                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
227                                                            start, end);
228                                    }
229    
230                                    cacheResult(list);
231    
232                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
233                            }
234                            catch (Exception e) {
235                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
236    
237                                    throw processException(e);
238                            }
239                            finally {
240                                    closeSession(session);
241                            }
242                    }
243    
244                    return list;
245            }
246    
247            /**
248             * Returns the first trash entry in the ordered set where groupId = &#63;.
249             *
250             * @param groupId the group ID
251             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
252             * @return the first matching trash entry
253             * @throws NoSuchEntryException if a matching trash entry could not be found
254             */
255            @Override
256            public TrashEntry findByGroupId_First(long groupId,
257                    OrderByComparator<TrashEntry> orderByComparator)
258                    throws NoSuchEntryException {
259                    TrashEntry trashEntry = fetchByGroupId_First(groupId, orderByComparator);
260    
261                    if (trashEntry != null) {
262                            return trashEntry;
263                    }
264    
265                    StringBundler msg = new StringBundler(4);
266    
267                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
268    
269                    msg.append("groupId=");
270                    msg.append(groupId);
271    
272                    msg.append(StringPool.CLOSE_CURLY_BRACE);
273    
274                    throw new NoSuchEntryException(msg.toString());
275            }
276    
277            /**
278             * Returns the first trash entry in the ordered set where groupId = &#63;.
279             *
280             * @param groupId the group ID
281             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
282             * @return the first matching trash entry, or <code>null</code> if a matching trash entry could not be found
283             */
284            @Override
285            public TrashEntry fetchByGroupId_First(long groupId,
286                    OrderByComparator<TrashEntry> orderByComparator) {
287                    List<TrashEntry> list = findByGroupId(groupId, 0, 1, orderByComparator);
288    
289                    if (!list.isEmpty()) {
290                            return list.get(0);
291                    }
292    
293                    return null;
294            }
295    
296            /**
297             * Returns the last trash entry in the ordered set where groupId = &#63;.
298             *
299             * @param groupId the group ID
300             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
301             * @return the last matching trash entry
302             * @throws NoSuchEntryException if a matching trash entry could not be found
303             */
304            @Override
305            public TrashEntry findByGroupId_Last(long groupId,
306                    OrderByComparator<TrashEntry> orderByComparator)
307                    throws NoSuchEntryException {
308                    TrashEntry trashEntry = fetchByGroupId_Last(groupId, orderByComparator);
309    
310                    if (trashEntry != null) {
311                            return trashEntry;
312                    }
313    
314                    StringBundler msg = new StringBundler(4);
315    
316                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
317    
318                    msg.append("groupId=");
319                    msg.append(groupId);
320    
321                    msg.append(StringPool.CLOSE_CURLY_BRACE);
322    
323                    throw new NoSuchEntryException(msg.toString());
324            }
325    
326            /**
327             * Returns the last trash entry in the ordered set where groupId = &#63;.
328             *
329             * @param groupId the group ID
330             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
331             * @return the last matching trash entry, or <code>null</code> if a matching trash entry could not be found
332             */
333            @Override
334            public TrashEntry fetchByGroupId_Last(long groupId,
335                    OrderByComparator<TrashEntry> orderByComparator) {
336                    int count = countByGroupId(groupId);
337    
338                    if (count == 0) {
339                            return null;
340                    }
341    
342                    List<TrashEntry> list = findByGroupId(groupId, count - 1, count,
343                                    orderByComparator);
344    
345                    if (!list.isEmpty()) {
346                            return list.get(0);
347                    }
348    
349                    return null;
350            }
351    
352            /**
353             * Returns the trash entries before and after the current trash entry in the ordered set where groupId = &#63;.
354             *
355             * @param entryId the primary key of the current trash entry
356             * @param groupId the group ID
357             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
358             * @return the previous, current, and next trash entry
359             * @throws NoSuchEntryException if a trash entry with the primary key could not be found
360             */
361            @Override
362            public TrashEntry[] findByGroupId_PrevAndNext(long entryId, long groupId,
363                    OrderByComparator<TrashEntry> orderByComparator)
364                    throws NoSuchEntryException {
365                    TrashEntry trashEntry = findByPrimaryKey(entryId);
366    
367                    Session session = null;
368    
369                    try {
370                            session = openSession();
371    
372                            TrashEntry[] array = new TrashEntryImpl[3];
373    
374                            array[0] = getByGroupId_PrevAndNext(session, trashEntry, groupId,
375                                            orderByComparator, true);
376    
377                            array[1] = trashEntry;
378    
379                            array[2] = getByGroupId_PrevAndNext(session, trashEntry, groupId,
380                                            orderByComparator, false);
381    
382                            return array;
383                    }
384                    catch (Exception e) {
385                            throw processException(e);
386                    }
387                    finally {
388                            closeSession(session);
389                    }
390            }
391    
392            protected TrashEntry getByGroupId_PrevAndNext(Session session,
393                    TrashEntry trashEntry, long groupId,
394                    OrderByComparator<TrashEntry> orderByComparator, boolean previous) {
395                    StringBundler query = null;
396    
397                    if (orderByComparator != null) {
398                            query = new StringBundler(6 +
399                                            (orderByComparator.getOrderByFields().length * 6));
400                    }
401                    else {
402                            query = new StringBundler(3);
403                    }
404    
405                    query.append(_SQL_SELECT_TRASHENTRY_WHERE);
406    
407                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
408    
409                    if (orderByComparator != null) {
410                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
411    
412                            if (orderByConditionFields.length > 0) {
413                                    query.append(WHERE_AND);
414                            }
415    
416                            for (int i = 0; i < orderByConditionFields.length; i++) {
417                                    query.append(_ORDER_BY_ENTITY_ALIAS);
418                                    query.append(orderByConditionFields[i]);
419    
420                                    if ((i + 1) < orderByConditionFields.length) {
421                                            if (orderByComparator.isAscending() ^ previous) {
422                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
423                                            }
424                                            else {
425                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
426                                            }
427                                    }
428                                    else {
429                                            if (orderByComparator.isAscending() ^ previous) {
430                                                    query.append(WHERE_GREATER_THAN);
431                                            }
432                                            else {
433                                                    query.append(WHERE_LESSER_THAN);
434                                            }
435                                    }
436                            }
437    
438                            query.append(ORDER_BY_CLAUSE);
439    
440                            String[] orderByFields = orderByComparator.getOrderByFields();
441    
442                            for (int i = 0; i < orderByFields.length; i++) {
443                                    query.append(_ORDER_BY_ENTITY_ALIAS);
444                                    query.append(orderByFields[i]);
445    
446                                    if ((i + 1) < orderByFields.length) {
447                                            if (orderByComparator.isAscending() ^ previous) {
448                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
449                                            }
450                                            else {
451                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
452                                            }
453                                    }
454                                    else {
455                                            if (orderByComparator.isAscending() ^ previous) {
456                                                    query.append(ORDER_BY_ASC);
457                                            }
458                                            else {
459                                                    query.append(ORDER_BY_DESC);
460                                            }
461                                    }
462                            }
463                    }
464                    else {
465                            query.append(TrashEntryModelImpl.ORDER_BY_JPQL);
466                    }
467    
468                    String sql = query.toString();
469    
470                    Query q = session.createQuery(sql);
471    
472                    q.setFirstResult(0);
473                    q.setMaxResults(2);
474    
475                    QueryPos qPos = QueryPos.getInstance(q);
476    
477                    qPos.add(groupId);
478    
479                    if (orderByComparator != null) {
480                            Object[] values = orderByComparator.getOrderByConditionValues(trashEntry);
481    
482                            for (Object value : values) {
483                                    qPos.add(value);
484                            }
485                    }
486    
487                    List<TrashEntry> list = q.list();
488    
489                    if (list.size() == 2) {
490                            return list.get(1);
491                    }
492                    else {
493                            return null;
494                    }
495            }
496    
497            /**
498             * Removes all the trash entries where groupId = &#63; from the database.
499             *
500             * @param groupId the group ID
501             */
502            @Override
503            public void removeByGroupId(long groupId) {
504                    for (TrashEntry trashEntry : findByGroupId(groupId, QueryUtil.ALL_POS,
505                                    QueryUtil.ALL_POS, null)) {
506                            remove(trashEntry);
507                    }
508            }
509    
510            /**
511             * Returns the number of trash entries where groupId = &#63;.
512             *
513             * @param groupId the group ID
514             * @return the number of matching trash entries
515             */
516            @Override
517            public int countByGroupId(long groupId) {
518                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
519    
520                    Object[] finderArgs = new Object[] { groupId };
521    
522                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
523                                    this);
524    
525                    if (count == null) {
526                            StringBundler query = new StringBundler(2);
527    
528                            query.append(_SQL_COUNT_TRASHENTRY_WHERE);
529    
530                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
531    
532                            String sql = query.toString();
533    
534                            Session session = null;
535    
536                            try {
537                                    session = openSession();
538    
539                                    Query q = session.createQuery(sql);
540    
541                                    QueryPos qPos = QueryPos.getInstance(q);
542    
543                                    qPos.add(groupId);
544    
545                                    count = (Long)q.uniqueResult();
546    
547                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
548                            }
549                            catch (Exception e) {
550                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
551    
552                                    throw processException(e);
553                            }
554                            finally {
555                                    closeSession(session);
556                            }
557                    }
558    
559                    return count.intValue();
560            }
561    
562            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "trashEntry.groupId = ?";
563            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
564                    new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
565                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
566                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
567                            new String[] {
568                                    Long.class.getName(),
569                                    
570                            Integer.class.getName(), Integer.class.getName(),
571                                    OrderByComparator.class.getName()
572                            });
573            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
574                    new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
575                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
576                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
577                            new String[] { Long.class.getName() },
578                            TrashEntryModelImpl.COMPANYID_COLUMN_BITMASK |
579                            TrashEntryModelImpl.CREATEDATE_COLUMN_BITMASK);
580            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
581                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
582                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
583                            new String[] { Long.class.getName() });
584    
585            /**
586             * Returns all the trash entries where companyId = &#63;.
587             *
588             * @param companyId the company ID
589             * @return the matching trash entries
590             */
591            @Override
592            public List<TrashEntry> findByCompanyId(long companyId) {
593                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
594                            null);
595            }
596    
597            /**
598             * Returns a range of all the trash entries where companyId = &#63;.
599             *
600             * <p>
601             * 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 TrashEntryModelImpl}. 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.
602             * </p>
603             *
604             * @param companyId the company ID
605             * @param start the lower bound of the range of trash entries
606             * @param end the upper bound of the range of trash entries (not inclusive)
607             * @return the range of matching trash entries
608             */
609            @Override
610            public List<TrashEntry> findByCompanyId(long companyId, int start, int end) {
611                    return findByCompanyId(companyId, start, end, null);
612            }
613    
614            /**
615             * Returns an ordered range of all the trash entries where companyId = &#63;.
616             *
617             * <p>
618             * 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 TrashEntryModelImpl}. 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.
619             * </p>
620             *
621             * @param companyId the company ID
622             * @param start the lower bound of the range of trash entries
623             * @param end the upper bound of the range of trash entries (not inclusive)
624             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
625             * @return the ordered range of matching trash entries
626             */
627            @Override
628            public List<TrashEntry> findByCompanyId(long companyId, int start, int end,
629                    OrderByComparator<TrashEntry> orderByComparator) {
630                    boolean pagination = true;
631                    FinderPath finderPath = null;
632                    Object[] finderArgs = null;
633    
634                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
635                                    (orderByComparator == null)) {
636                            pagination = false;
637                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
638                            finderArgs = new Object[] { companyId };
639                    }
640                    else {
641                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
642                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
643                    }
644    
645                    List<TrashEntry> list = (List<TrashEntry>)FinderCacheUtil.getResult(finderPath,
646                                    finderArgs, this);
647    
648                    if ((list != null) && !list.isEmpty()) {
649                            for (TrashEntry trashEntry : list) {
650                                    if ((companyId != trashEntry.getCompanyId())) {
651                                            list = null;
652    
653                                            break;
654                                    }
655                            }
656                    }
657    
658                    if (list == null) {
659                            StringBundler query = null;
660    
661                            if (orderByComparator != null) {
662                                    query = new StringBundler(3 +
663                                                    (orderByComparator.getOrderByFields().length * 3));
664                            }
665                            else {
666                                    query = new StringBundler(3);
667                            }
668    
669                            query.append(_SQL_SELECT_TRASHENTRY_WHERE);
670    
671                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
672    
673                            if (orderByComparator != null) {
674                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
675                                            orderByComparator);
676                            }
677                            else
678                             if (pagination) {
679                                    query.append(TrashEntryModelImpl.ORDER_BY_JPQL);
680                            }
681    
682                            String sql = query.toString();
683    
684                            Session session = null;
685    
686                            try {
687                                    session = openSession();
688    
689                                    Query q = session.createQuery(sql);
690    
691                                    QueryPos qPos = QueryPos.getInstance(q);
692    
693                                    qPos.add(companyId);
694    
695                                    if (!pagination) {
696                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
697                                                            start, end, false);
698    
699                                            Collections.sort(list);
700    
701                                            list = Collections.unmodifiableList(list);
702                                    }
703                                    else {
704                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
705                                                            start, end);
706                                    }
707    
708                                    cacheResult(list);
709    
710                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
711                            }
712                            catch (Exception e) {
713                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
714    
715                                    throw processException(e);
716                            }
717                            finally {
718                                    closeSession(session);
719                            }
720                    }
721    
722                    return list;
723            }
724    
725            /**
726             * Returns the first trash entry in the ordered set where companyId = &#63;.
727             *
728             * @param companyId the company ID
729             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
730             * @return the first matching trash entry
731             * @throws NoSuchEntryException if a matching trash entry could not be found
732             */
733            @Override
734            public TrashEntry findByCompanyId_First(long companyId,
735                    OrderByComparator<TrashEntry> orderByComparator)
736                    throws NoSuchEntryException {
737                    TrashEntry trashEntry = fetchByCompanyId_First(companyId,
738                                    orderByComparator);
739    
740                    if (trashEntry != null) {
741                            return trashEntry;
742                    }
743    
744                    StringBundler msg = new StringBundler(4);
745    
746                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
747    
748                    msg.append("companyId=");
749                    msg.append(companyId);
750    
751                    msg.append(StringPool.CLOSE_CURLY_BRACE);
752    
753                    throw new NoSuchEntryException(msg.toString());
754            }
755    
756            /**
757             * Returns the first trash entry in the ordered set where companyId = &#63;.
758             *
759             * @param companyId the company ID
760             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
761             * @return the first matching trash entry, or <code>null</code> if a matching trash entry could not be found
762             */
763            @Override
764            public TrashEntry fetchByCompanyId_First(long companyId,
765                    OrderByComparator<TrashEntry> orderByComparator) {
766                    List<TrashEntry> list = findByCompanyId(companyId, 0, 1,
767                                    orderByComparator);
768    
769                    if (!list.isEmpty()) {
770                            return list.get(0);
771                    }
772    
773                    return null;
774            }
775    
776            /**
777             * Returns the last trash entry in the ordered set where companyId = &#63;.
778             *
779             * @param companyId the company ID
780             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
781             * @return the last matching trash entry
782             * @throws NoSuchEntryException if a matching trash entry could not be found
783             */
784            @Override
785            public TrashEntry findByCompanyId_Last(long companyId,
786                    OrderByComparator<TrashEntry> orderByComparator)
787                    throws NoSuchEntryException {
788                    TrashEntry trashEntry = fetchByCompanyId_Last(companyId,
789                                    orderByComparator);
790    
791                    if (trashEntry != null) {
792                            return trashEntry;
793                    }
794    
795                    StringBundler msg = new StringBundler(4);
796    
797                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
798    
799                    msg.append("companyId=");
800                    msg.append(companyId);
801    
802                    msg.append(StringPool.CLOSE_CURLY_BRACE);
803    
804                    throw new NoSuchEntryException(msg.toString());
805            }
806    
807            /**
808             * Returns the last trash entry in the ordered set where companyId = &#63;.
809             *
810             * @param companyId the company ID
811             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
812             * @return the last matching trash entry, or <code>null</code> if a matching trash entry could not be found
813             */
814            @Override
815            public TrashEntry fetchByCompanyId_Last(long companyId,
816                    OrderByComparator<TrashEntry> orderByComparator) {
817                    int count = countByCompanyId(companyId);
818    
819                    if (count == 0) {
820                            return null;
821                    }
822    
823                    List<TrashEntry> list = findByCompanyId(companyId, count - 1, count,
824                                    orderByComparator);
825    
826                    if (!list.isEmpty()) {
827                            return list.get(0);
828                    }
829    
830                    return null;
831            }
832    
833            /**
834             * Returns the trash entries before and after the current trash entry in the ordered set where companyId = &#63;.
835             *
836             * @param entryId the primary key of the current trash entry
837             * @param companyId the company ID
838             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
839             * @return the previous, current, and next trash entry
840             * @throws NoSuchEntryException if a trash entry with the primary key could not be found
841             */
842            @Override
843            public TrashEntry[] findByCompanyId_PrevAndNext(long entryId,
844                    long companyId, OrderByComparator<TrashEntry> orderByComparator)
845                    throws NoSuchEntryException {
846                    TrashEntry trashEntry = findByPrimaryKey(entryId);
847    
848                    Session session = null;
849    
850                    try {
851                            session = openSession();
852    
853                            TrashEntry[] array = new TrashEntryImpl[3];
854    
855                            array[0] = getByCompanyId_PrevAndNext(session, trashEntry,
856                                            companyId, orderByComparator, true);
857    
858                            array[1] = trashEntry;
859    
860                            array[2] = getByCompanyId_PrevAndNext(session, trashEntry,
861                                            companyId, orderByComparator, false);
862    
863                            return array;
864                    }
865                    catch (Exception e) {
866                            throw processException(e);
867                    }
868                    finally {
869                            closeSession(session);
870                    }
871            }
872    
873            protected TrashEntry getByCompanyId_PrevAndNext(Session session,
874                    TrashEntry trashEntry, long companyId,
875                    OrderByComparator<TrashEntry> orderByComparator, boolean previous) {
876                    StringBundler query = null;
877    
878                    if (orderByComparator != null) {
879                            query = new StringBundler(6 +
880                                            (orderByComparator.getOrderByFields().length * 6));
881                    }
882                    else {
883                            query = new StringBundler(3);
884                    }
885    
886                    query.append(_SQL_SELECT_TRASHENTRY_WHERE);
887    
888                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
889    
890                    if (orderByComparator != null) {
891                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
892    
893                            if (orderByConditionFields.length > 0) {
894                                    query.append(WHERE_AND);
895                            }
896    
897                            for (int i = 0; i < orderByConditionFields.length; i++) {
898                                    query.append(_ORDER_BY_ENTITY_ALIAS);
899                                    query.append(orderByConditionFields[i]);
900    
901                                    if ((i + 1) < orderByConditionFields.length) {
902                                            if (orderByComparator.isAscending() ^ previous) {
903                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
904                                            }
905                                            else {
906                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
907                                            }
908                                    }
909                                    else {
910                                            if (orderByComparator.isAscending() ^ previous) {
911                                                    query.append(WHERE_GREATER_THAN);
912                                            }
913                                            else {
914                                                    query.append(WHERE_LESSER_THAN);
915                                            }
916                                    }
917                            }
918    
919                            query.append(ORDER_BY_CLAUSE);
920    
921                            String[] orderByFields = orderByComparator.getOrderByFields();
922    
923                            for (int i = 0; i < orderByFields.length; i++) {
924                                    query.append(_ORDER_BY_ENTITY_ALIAS);
925                                    query.append(orderByFields[i]);
926    
927                                    if ((i + 1) < orderByFields.length) {
928                                            if (orderByComparator.isAscending() ^ previous) {
929                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
930                                            }
931                                            else {
932                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
933                                            }
934                                    }
935                                    else {
936                                            if (orderByComparator.isAscending() ^ previous) {
937                                                    query.append(ORDER_BY_ASC);
938                                            }
939                                            else {
940                                                    query.append(ORDER_BY_DESC);
941                                            }
942                                    }
943                            }
944                    }
945                    else {
946                            query.append(TrashEntryModelImpl.ORDER_BY_JPQL);
947                    }
948    
949                    String sql = query.toString();
950    
951                    Query q = session.createQuery(sql);
952    
953                    q.setFirstResult(0);
954                    q.setMaxResults(2);
955    
956                    QueryPos qPos = QueryPos.getInstance(q);
957    
958                    qPos.add(companyId);
959    
960                    if (orderByComparator != null) {
961                            Object[] values = orderByComparator.getOrderByConditionValues(trashEntry);
962    
963                            for (Object value : values) {
964                                    qPos.add(value);
965                            }
966                    }
967    
968                    List<TrashEntry> list = q.list();
969    
970                    if (list.size() == 2) {
971                            return list.get(1);
972                    }
973                    else {
974                            return null;
975                    }
976            }
977    
978            /**
979             * Removes all the trash entries where companyId = &#63; from the database.
980             *
981             * @param companyId the company ID
982             */
983            @Override
984            public void removeByCompanyId(long companyId) {
985                    for (TrashEntry trashEntry : findByCompanyId(companyId,
986                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
987                            remove(trashEntry);
988                    }
989            }
990    
991            /**
992             * Returns the number of trash entries where companyId = &#63;.
993             *
994             * @param companyId the company ID
995             * @return the number of matching trash entries
996             */
997            @Override
998            public int countByCompanyId(long companyId) {
999                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
1000    
1001                    Object[] finderArgs = new Object[] { companyId };
1002    
1003                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1004                                    this);
1005    
1006                    if (count == null) {
1007                            StringBundler query = new StringBundler(2);
1008    
1009                            query.append(_SQL_COUNT_TRASHENTRY_WHERE);
1010    
1011                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1012    
1013                            String sql = query.toString();
1014    
1015                            Session session = null;
1016    
1017                            try {
1018                                    session = openSession();
1019    
1020                                    Query q = session.createQuery(sql);
1021    
1022                                    QueryPos qPos = QueryPos.getInstance(q);
1023    
1024                                    qPos.add(companyId);
1025    
1026                                    count = (Long)q.uniqueResult();
1027    
1028                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1029                            }
1030                            catch (Exception e) {
1031                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1032    
1033                                    throw processException(e);
1034                            }
1035                            finally {
1036                                    closeSession(session);
1037                            }
1038                    }
1039    
1040                    return count.intValue();
1041            }
1042    
1043            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "trashEntry.companyId = ?";
1044            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LTCD = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
1045                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
1046                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_LtCD",
1047                            new String[] {
1048                                    Long.class.getName(), Date.class.getName(),
1049                                    
1050                            Integer.class.getName(), Integer.class.getName(),
1051                                    OrderByComparator.class.getName()
1052                            });
1053            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LTCD = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
1054                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
1055                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_LtCD",
1056                            new String[] { Long.class.getName(), Date.class.getName() });
1057    
1058            /**
1059             * Returns all the trash entries where groupId = &#63; and createDate &lt; &#63;.
1060             *
1061             * @param groupId the group ID
1062             * @param createDate the create date
1063             * @return the matching trash entries
1064             */
1065            @Override
1066            public List<TrashEntry> findByG_LtCD(long groupId, Date createDate) {
1067                    return findByG_LtCD(groupId, createDate, QueryUtil.ALL_POS,
1068                            QueryUtil.ALL_POS, null);
1069            }
1070    
1071            /**
1072             * Returns a range of all the trash entries where groupId = &#63; and createDate &lt; &#63;.
1073             *
1074             * <p>
1075             * 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 TrashEntryModelImpl}. 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.
1076             * </p>
1077             *
1078             * @param groupId the group ID
1079             * @param createDate the create date
1080             * @param start the lower bound of the range of trash entries
1081             * @param end the upper bound of the range of trash entries (not inclusive)
1082             * @return the range of matching trash entries
1083             */
1084            @Override
1085            public List<TrashEntry> findByG_LtCD(long groupId, Date createDate,
1086                    int start, int end) {
1087                    return findByG_LtCD(groupId, createDate, start, end, null);
1088            }
1089    
1090            /**
1091             * Returns an ordered range of all the trash entries where groupId = &#63; and createDate &lt; &#63;.
1092             *
1093             * <p>
1094             * 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 TrashEntryModelImpl}. 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.
1095             * </p>
1096             *
1097             * @param groupId the group ID
1098             * @param createDate the create date
1099             * @param start the lower bound of the range of trash entries
1100             * @param end the upper bound of the range of trash entries (not inclusive)
1101             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1102             * @return the ordered range of matching trash entries
1103             */
1104            @Override
1105            public List<TrashEntry> findByG_LtCD(long groupId, Date createDate,
1106                    int start, int end, OrderByComparator<TrashEntry> orderByComparator) {
1107                    boolean pagination = true;
1108                    FinderPath finderPath = null;
1109                    Object[] finderArgs = null;
1110    
1111                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LTCD;
1112                    finderArgs = new Object[] {
1113                                    groupId, createDate,
1114                                    
1115                                    start, end, orderByComparator
1116                            };
1117    
1118                    List<TrashEntry> list = (List<TrashEntry>)FinderCacheUtil.getResult(finderPath,
1119                                    finderArgs, this);
1120    
1121                    if ((list != null) && !list.isEmpty()) {
1122                            for (TrashEntry trashEntry : list) {
1123                                    if ((groupId != trashEntry.getGroupId()) ||
1124                                                    (createDate.getTime() <= trashEntry.getCreateDate()
1125                                                                                                                               .getTime())) {
1126                                            list = null;
1127    
1128                                            break;
1129                                    }
1130                            }
1131                    }
1132    
1133                    if (list == null) {
1134                            StringBundler query = null;
1135    
1136                            if (orderByComparator != null) {
1137                                    query = new StringBundler(4 +
1138                                                    (orderByComparator.getOrderByFields().length * 3));
1139                            }
1140                            else {
1141                                    query = new StringBundler(4);
1142                            }
1143    
1144                            query.append(_SQL_SELECT_TRASHENTRY_WHERE);
1145    
1146                            query.append(_FINDER_COLUMN_G_LTCD_GROUPID_2);
1147    
1148                            boolean bindCreateDate = false;
1149    
1150                            if (createDate == null) {
1151                                    query.append(_FINDER_COLUMN_G_LTCD_CREATEDATE_1);
1152                            }
1153                            else {
1154                                    bindCreateDate = true;
1155    
1156                                    query.append(_FINDER_COLUMN_G_LTCD_CREATEDATE_2);
1157                            }
1158    
1159                            if (orderByComparator != null) {
1160                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1161                                            orderByComparator);
1162                            }
1163                            else
1164                             if (pagination) {
1165                                    query.append(TrashEntryModelImpl.ORDER_BY_JPQL);
1166                            }
1167    
1168                            String sql = query.toString();
1169    
1170                            Session session = null;
1171    
1172                            try {
1173                                    session = openSession();
1174    
1175                                    Query q = session.createQuery(sql);
1176    
1177                                    QueryPos qPos = QueryPos.getInstance(q);
1178    
1179                                    qPos.add(groupId);
1180    
1181                                    if (bindCreateDate) {
1182                                            qPos.add(new Timestamp(createDate.getTime()));
1183                                    }
1184    
1185                                    if (!pagination) {
1186                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
1187                                                            start, end, false);
1188    
1189                                            Collections.sort(list);
1190    
1191                                            list = Collections.unmodifiableList(list);
1192                                    }
1193                                    else {
1194                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
1195                                                            start, end);
1196                                    }
1197    
1198                                    cacheResult(list);
1199    
1200                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1201                            }
1202                            catch (Exception e) {
1203                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1204    
1205                                    throw processException(e);
1206                            }
1207                            finally {
1208                                    closeSession(session);
1209                            }
1210                    }
1211    
1212                    return list;
1213            }
1214    
1215            /**
1216             * Returns the first trash entry in the ordered set where groupId = &#63; and createDate &lt; &#63;.
1217             *
1218             * @param groupId the group ID
1219             * @param createDate the create date
1220             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1221             * @return the first matching trash entry
1222             * @throws NoSuchEntryException if a matching trash entry could not be found
1223             */
1224            @Override
1225            public TrashEntry findByG_LtCD_First(long groupId, Date createDate,
1226                    OrderByComparator<TrashEntry> orderByComparator)
1227                    throws NoSuchEntryException {
1228                    TrashEntry trashEntry = fetchByG_LtCD_First(groupId, createDate,
1229                                    orderByComparator);
1230    
1231                    if (trashEntry != null) {
1232                            return trashEntry;
1233                    }
1234    
1235                    StringBundler msg = new StringBundler(6);
1236    
1237                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1238    
1239                    msg.append("groupId=");
1240                    msg.append(groupId);
1241    
1242                    msg.append(", createDate=");
1243                    msg.append(createDate);
1244    
1245                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1246    
1247                    throw new NoSuchEntryException(msg.toString());
1248            }
1249    
1250            /**
1251             * Returns the first trash entry in the ordered set where groupId = &#63; and createDate &lt; &#63;.
1252             *
1253             * @param groupId the group ID
1254             * @param createDate the create date
1255             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1256             * @return the first matching trash entry, or <code>null</code> if a matching trash entry could not be found
1257             */
1258            @Override
1259            public TrashEntry fetchByG_LtCD_First(long groupId, Date createDate,
1260                    OrderByComparator<TrashEntry> orderByComparator) {
1261                    List<TrashEntry> list = findByG_LtCD(groupId, createDate, 0, 1,
1262                                    orderByComparator);
1263    
1264                    if (!list.isEmpty()) {
1265                            return list.get(0);
1266                    }
1267    
1268                    return null;
1269            }
1270    
1271            /**
1272             * Returns the last trash entry in the ordered set where groupId = &#63; and createDate &lt; &#63;.
1273             *
1274             * @param groupId the group ID
1275             * @param createDate the create date
1276             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1277             * @return the last matching trash entry
1278             * @throws NoSuchEntryException if a matching trash entry could not be found
1279             */
1280            @Override
1281            public TrashEntry findByG_LtCD_Last(long groupId, Date createDate,
1282                    OrderByComparator<TrashEntry> orderByComparator)
1283                    throws NoSuchEntryException {
1284                    TrashEntry trashEntry = fetchByG_LtCD_Last(groupId, createDate,
1285                                    orderByComparator);
1286    
1287                    if (trashEntry != null) {
1288                            return trashEntry;
1289                    }
1290    
1291                    StringBundler msg = new StringBundler(6);
1292    
1293                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1294    
1295                    msg.append("groupId=");
1296                    msg.append(groupId);
1297    
1298                    msg.append(", createDate=");
1299                    msg.append(createDate);
1300    
1301                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1302    
1303                    throw new NoSuchEntryException(msg.toString());
1304            }
1305    
1306            /**
1307             * Returns the last trash entry in the ordered set where groupId = &#63; and createDate &lt; &#63;.
1308             *
1309             * @param groupId the group ID
1310             * @param createDate the create date
1311             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1312             * @return the last matching trash entry, or <code>null</code> if a matching trash entry could not be found
1313             */
1314            @Override
1315            public TrashEntry fetchByG_LtCD_Last(long groupId, Date createDate,
1316                    OrderByComparator<TrashEntry> orderByComparator) {
1317                    int count = countByG_LtCD(groupId, createDate);
1318    
1319                    if (count == 0) {
1320                            return null;
1321                    }
1322    
1323                    List<TrashEntry> list = findByG_LtCD(groupId, createDate, count - 1,
1324                                    count, orderByComparator);
1325    
1326                    if (!list.isEmpty()) {
1327                            return list.get(0);
1328                    }
1329    
1330                    return null;
1331            }
1332    
1333            /**
1334             * Returns the trash entries before and after the current trash entry in the ordered set where groupId = &#63; and createDate &lt; &#63;.
1335             *
1336             * @param entryId the primary key of the current trash entry
1337             * @param groupId the group ID
1338             * @param createDate the create date
1339             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1340             * @return the previous, current, and next trash entry
1341             * @throws NoSuchEntryException if a trash entry with the primary key could not be found
1342             */
1343            @Override
1344            public TrashEntry[] findByG_LtCD_PrevAndNext(long entryId, long groupId,
1345                    Date createDate, OrderByComparator<TrashEntry> orderByComparator)
1346                    throws NoSuchEntryException {
1347                    TrashEntry trashEntry = findByPrimaryKey(entryId);
1348    
1349                    Session session = null;
1350    
1351                    try {
1352                            session = openSession();
1353    
1354                            TrashEntry[] array = new TrashEntryImpl[3];
1355    
1356                            array[0] = getByG_LtCD_PrevAndNext(session, trashEntry, groupId,
1357                                            createDate, orderByComparator, true);
1358    
1359                            array[1] = trashEntry;
1360    
1361                            array[2] = getByG_LtCD_PrevAndNext(session, trashEntry, groupId,
1362                                            createDate, orderByComparator, false);
1363    
1364                            return array;
1365                    }
1366                    catch (Exception e) {
1367                            throw processException(e);
1368                    }
1369                    finally {
1370                            closeSession(session);
1371                    }
1372            }
1373    
1374            protected TrashEntry getByG_LtCD_PrevAndNext(Session session,
1375                    TrashEntry trashEntry, long groupId, Date createDate,
1376                    OrderByComparator<TrashEntry> orderByComparator, boolean previous) {
1377                    StringBundler query = null;
1378    
1379                    if (orderByComparator != null) {
1380                            query = new StringBundler(6 +
1381                                            (orderByComparator.getOrderByFields().length * 6));
1382                    }
1383                    else {
1384                            query = new StringBundler(3);
1385                    }
1386    
1387                    query.append(_SQL_SELECT_TRASHENTRY_WHERE);
1388    
1389                    query.append(_FINDER_COLUMN_G_LTCD_GROUPID_2);
1390    
1391                    boolean bindCreateDate = false;
1392    
1393                    if (createDate == null) {
1394                            query.append(_FINDER_COLUMN_G_LTCD_CREATEDATE_1);
1395                    }
1396                    else {
1397                            bindCreateDate = true;
1398    
1399                            query.append(_FINDER_COLUMN_G_LTCD_CREATEDATE_2);
1400                    }
1401    
1402                    if (orderByComparator != null) {
1403                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1404    
1405                            if (orderByConditionFields.length > 0) {
1406                                    query.append(WHERE_AND);
1407                            }
1408    
1409                            for (int i = 0; i < orderByConditionFields.length; i++) {
1410                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1411                                    query.append(orderByConditionFields[i]);
1412    
1413                                    if ((i + 1) < orderByConditionFields.length) {
1414                                            if (orderByComparator.isAscending() ^ previous) {
1415                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1416                                            }
1417                                            else {
1418                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1419                                            }
1420                                    }
1421                                    else {
1422                                            if (orderByComparator.isAscending() ^ previous) {
1423                                                    query.append(WHERE_GREATER_THAN);
1424                                            }
1425                                            else {
1426                                                    query.append(WHERE_LESSER_THAN);
1427                                            }
1428                                    }
1429                            }
1430    
1431                            query.append(ORDER_BY_CLAUSE);
1432    
1433                            String[] orderByFields = orderByComparator.getOrderByFields();
1434    
1435                            for (int i = 0; i < orderByFields.length; i++) {
1436                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1437                                    query.append(orderByFields[i]);
1438    
1439                                    if ((i + 1) < orderByFields.length) {
1440                                            if (orderByComparator.isAscending() ^ previous) {
1441                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1442                                            }
1443                                            else {
1444                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1445                                            }
1446                                    }
1447                                    else {
1448                                            if (orderByComparator.isAscending() ^ previous) {
1449                                                    query.append(ORDER_BY_ASC);
1450                                            }
1451                                            else {
1452                                                    query.append(ORDER_BY_DESC);
1453                                            }
1454                                    }
1455                            }
1456                    }
1457                    else {
1458                            query.append(TrashEntryModelImpl.ORDER_BY_JPQL);
1459                    }
1460    
1461                    String sql = query.toString();
1462    
1463                    Query q = session.createQuery(sql);
1464    
1465                    q.setFirstResult(0);
1466                    q.setMaxResults(2);
1467    
1468                    QueryPos qPos = QueryPos.getInstance(q);
1469    
1470                    qPos.add(groupId);
1471    
1472                    if (bindCreateDate) {
1473                            qPos.add(new Timestamp(createDate.getTime()));
1474                    }
1475    
1476                    if (orderByComparator != null) {
1477                            Object[] values = orderByComparator.getOrderByConditionValues(trashEntry);
1478    
1479                            for (Object value : values) {
1480                                    qPos.add(value);
1481                            }
1482                    }
1483    
1484                    List<TrashEntry> list = q.list();
1485    
1486                    if (list.size() == 2) {
1487                            return list.get(1);
1488                    }
1489                    else {
1490                            return null;
1491                    }
1492            }
1493    
1494            /**
1495             * Removes all the trash entries where groupId = &#63; and createDate &lt; &#63; from the database.
1496             *
1497             * @param groupId the group ID
1498             * @param createDate the create date
1499             */
1500            @Override
1501            public void removeByG_LtCD(long groupId, Date createDate) {
1502                    for (TrashEntry trashEntry : findByG_LtCD(groupId, createDate,
1503                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1504                            remove(trashEntry);
1505                    }
1506            }
1507    
1508            /**
1509             * Returns the number of trash entries where groupId = &#63; and createDate &lt; &#63;.
1510             *
1511             * @param groupId the group ID
1512             * @param createDate the create date
1513             * @return the number of matching trash entries
1514             */
1515            @Override
1516            public int countByG_LtCD(long groupId, Date createDate) {
1517                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LTCD;
1518    
1519                    Object[] finderArgs = new Object[] { groupId, createDate };
1520    
1521                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1522                                    this);
1523    
1524                    if (count == null) {
1525                            StringBundler query = new StringBundler(3);
1526    
1527                            query.append(_SQL_COUNT_TRASHENTRY_WHERE);
1528    
1529                            query.append(_FINDER_COLUMN_G_LTCD_GROUPID_2);
1530    
1531                            boolean bindCreateDate = false;
1532    
1533                            if (createDate == null) {
1534                                    query.append(_FINDER_COLUMN_G_LTCD_CREATEDATE_1);
1535                            }
1536                            else {
1537                                    bindCreateDate = true;
1538    
1539                                    query.append(_FINDER_COLUMN_G_LTCD_CREATEDATE_2);
1540                            }
1541    
1542                            String sql = query.toString();
1543    
1544                            Session session = null;
1545    
1546                            try {
1547                                    session = openSession();
1548    
1549                                    Query q = session.createQuery(sql);
1550    
1551                                    QueryPos qPos = QueryPos.getInstance(q);
1552    
1553                                    qPos.add(groupId);
1554    
1555                                    if (bindCreateDate) {
1556                                            qPos.add(new Timestamp(createDate.getTime()));
1557                                    }
1558    
1559                                    count = (Long)q.uniqueResult();
1560    
1561                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1562                            }
1563                            catch (Exception e) {
1564                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1565    
1566                                    throw processException(e);
1567                            }
1568                            finally {
1569                                    closeSession(session);
1570                            }
1571                    }
1572    
1573                    return count.intValue();
1574            }
1575    
1576            private static final String _FINDER_COLUMN_G_LTCD_GROUPID_2 = "trashEntry.groupId = ? AND ";
1577            private static final String _FINDER_COLUMN_G_LTCD_CREATEDATE_1 = "trashEntry.createDate < NULL";
1578            private static final String _FINDER_COLUMN_G_LTCD_CREATEDATE_2 = "trashEntry.createDate < ?";
1579            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
1580                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
1581                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
1582                            new String[] {
1583                                    Long.class.getName(), Long.class.getName(),
1584                                    
1585                            Integer.class.getName(), Integer.class.getName(),
1586                                    OrderByComparator.class.getName()
1587                            });
1588            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
1589                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
1590                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
1591                            new String[] { Long.class.getName(), Long.class.getName() },
1592                            TrashEntryModelImpl.GROUPID_COLUMN_BITMASK |
1593                            TrashEntryModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1594                            TrashEntryModelImpl.CREATEDATE_COLUMN_BITMASK);
1595            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
1596                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
1597                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
1598                            new String[] { Long.class.getName(), Long.class.getName() });
1599    
1600            /**
1601             * Returns all the trash entries where groupId = &#63; and classNameId = &#63;.
1602             *
1603             * @param groupId the group ID
1604             * @param classNameId the class name ID
1605             * @return the matching trash entries
1606             */
1607            @Override
1608            public List<TrashEntry> findByG_C(long groupId, long classNameId) {
1609                    return findByG_C(groupId, classNameId, QueryUtil.ALL_POS,
1610                            QueryUtil.ALL_POS, null);
1611            }
1612    
1613            /**
1614             * Returns a range of all the trash entries where groupId = &#63; and classNameId = &#63;.
1615             *
1616             * <p>
1617             * 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 TrashEntryModelImpl}. 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.
1618             * </p>
1619             *
1620             * @param groupId the group ID
1621             * @param classNameId the class name ID
1622             * @param start the lower bound of the range of trash entries
1623             * @param end the upper bound of the range of trash entries (not inclusive)
1624             * @return the range of matching trash entries
1625             */
1626            @Override
1627            public List<TrashEntry> findByG_C(long groupId, long classNameId,
1628                    int start, int end) {
1629                    return findByG_C(groupId, classNameId, start, end, null);
1630            }
1631    
1632            /**
1633             * Returns an ordered range of all the trash entries where groupId = &#63; and classNameId = &#63;.
1634             *
1635             * <p>
1636             * 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 TrashEntryModelImpl}. 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.
1637             * </p>
1638             *
1639             * @param groupId the group ID
1640             * @param classNameId the class name ID
1641             * @param start the lower bound of the range of trash entries
1642             * @param end the upper bound of the range of trash entries (not inclusive)
1643             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1644             * @return the ordered range of matching trash entries
1645             */
1646            @Override
1647            public List<TrashEntry> findByG_C(long groupId, long classNameId,
1648                    int start, int end, OrderByComparator<TrashEntry> orderByComparator) {
1649                    boolean pagination = true;
1650                    FinderPath finderPath = null;
1651                    Object[] finderArgs = null;
1652    
1653                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1654                                    (orderByComparator == null)) {
1655                            pagination = false;
1656                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
1657                            finderArgs = new Object[] { groupId, classNameId };
1658                    }
1659                    else {
1660                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
1661                            finderArgs = new Object[] {
1662                                            groupId, classNameId,
1663                                            
1664                                            start, end, orderByComparator
1665                                    };
1666                    }
1667    
1668                    List<TrashEntry> list = (List<TrashEntry>)FinderCacheUtil.getResult(finderPath,
1669                                    finderArgs, this);
1670    
1671                    if ((list != null) && !list.isEmpty()) {
1672                            for (TrashEntry trashEntry : list) {
1673                                    if ((groupId != trashEntry.getGroupId()) ||
1674                                                    (classNameId != trashEntry.getClassNameId())) {
1675                                            list = null;
1676    
1677                                            break;
1678                                    }
1679                            }
1680                    }
1681    
1682                    if (list == null) {
1683                            StringBundler query = null;
1684    
1685                            if (orderByComparator != null) {
1686                                    query = new StringBundler(4 +
1687                                                    (orderByComparator.getOrderByFields().length * 3));
1688                            }
1689                            else {
1690                                    query = new StringBundler(4);
1691                            }
1692    
1693                            query.append(_SQL_SELECT_TRASHENTRY_WHERE);
1694    
1695                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1696    
1697                            query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
1698    
1699                            if (orderByComparator != null) {
1700                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1701                                            orderByComparator);
1702                            }
1703                            else
1704                             if (pagination) {
1705                                    query.append(TrashEntryModelImpl.ORDER_BY_JPQL);
1706                            }
1707    
1708                            String sql = query.toString();
1709    
1710                            Session session = null;
1711    
1712                            try {
1713                                    session = openSession();
1714    
1715                                    Query q = session.createQuery(sql);
1716    
1717                                    QueryPos qPos = QueryPos.getInstance(q);
1718    
1719                                    qPos.add(groupId);
1720    
1721                                    qPos.add(classNameId);
1722    
1723                                    if (!pagination) {
1724                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
1725                                                            start, end, false);
1726    
1727                                            Collections.sort(list);
1728    
1729                                            list = Collections.unmodifiableList(list);
1730                                    }
1731                                    else {
1732                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
1733                                                            start, end);
1734                                    }
1735    
1736                                    cacheResult(list);
1737    
1738                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1739                            }
1740                            catch (Exception e) {
1741                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1742    
1743                                    throw processException(e);
1744                            }
1745                            finally {
1746                                    closeSession(session);
1747                            }
1748                    }
1749    
1750                    return list;
1751            }
1752    
1753            /**
1754             * Returns the first trash entry in the ordered set where groupId = &#63; and classNameId = &#63;.
1755             *
1756             * @param groupId the group ID
1757             * @param classNameId the class name ID
1758             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1759             * @return the first matching trash entry
1760             * @throws NoSuchEntryException if a matching trash entry could not be found
1761             */
1762            @Override
1763            public TrashEntry findByG_C_First(long groupId, long classNameId,
1764                    OrderByComparator<TrashEntry> orderByComparator)
1765                    throws NoSuchEntryException {
1766                    TrashEntry trashEntry = fetchByG_C_First(groupId, classNameId,
1767                                    orderByComparator);
1768    
1769                    if (trashEntry != null) {
1770                            return trashEntry;
1771                    }
1772    
1773                    StringBundler msg = new StringBundler(6);
1774    
1775                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1776    
1777                    msg.append("groupId=");
1778                    msg.append(groupId);
1779    
1780                    msg.append(", classNameId=");
1781                    msg.append(classNameId);
1782    
1783                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1784    
1785                    throw new NoSuchEntryException(msg.toString());
1786            }
1787    
1788            /**
1789             * Returns the first trash entry in the ordered set where groupId = &#63; and classNameId = &#63;.
1790             *
1791             * @param groupId the group ID
1792             * @param classNameId the class name ID
1793             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1794             * @return the first matching trash entry, or <code>null</code> if a matching trash entry could not be found
1795             */
1796            @Override
1797            public TrashEntry fetchByG_C_First(long groupId, long classNameId,
1798                    OrderByComparator<TrashEntry> orderByComparator) {
1799                    List<TrashEntry> list = findByG_C(groupId, classNameId, 0, 1,
1800                                    orderByComparator);
1801    
1802                    if (!list.isEmpty()) {
1803                            return list.get(0);
1804                    }
1805    
1806                    return null;
1807            }
1808    
1809            /**
1810             * Returns the last trash entry in the ordered set where groupId = &#63; and classNameId = &#63;.
1811             *
1812             * @param groupId the group ID
1813             * @param classNameId the class name ID
1814             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1815             * @return the last matching trash entry
1816             * @throws NoSuchEntryException if a matching trash entry could not be found
1817             */
1818            @Override
1819            public TrashEntry findByG_C_Last(long groupId, long classNameId,
1820                    OrderByComparator<TrashEntry> orderByComparator)
1821                    throws NoSuchEntryException {
1822                    TrashEntry trashEntry = fetchByG_C_Last(groupId, classNameId,
1823                                    orderByComparator);
1824    
1825                    if (trashEntry != null) {
1826                            return trashEntry;
1827                    }
1828    
1829                    StringBundler msg = new StringBundler(6);
1830    
1831                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1832    
1833                    msg.append("groupId=");
1834                    msg.append(groupId);
1835    
1836                    msg.append(", classNameId=");
1837                    msg.append(classNameId);
1838    
1839                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1840    
1841                    throw new NoSuchEntryException(msg.toString());
1842            }
1843    
1844            /**
1845             * Returns the last trash entry in the ordered set where groupId = &#63; and classNameId = &#63;.
1846             *
1847             * @param groupId the group ID
1848             * @param classNameId the class name ID
1849             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1850             * @return the last matching trash entry, or <code>null</code> if a matching trash entry could not be found
1851             */
1852            @Override
1853            public TrashEntry fetchByG_C_Last(long groupId, long classNameId,
1854                    OrderByComparator<TrashEntry> orderByComparator) {
1855                    int count = countByG_C(groupId, classNameId);
1856    
1857                    if (count == 0) {
1858                            return null;
1859                    }
1860    
1861                    List<TrashEntry> list = findByG_C(groupId, classNameId, count - 1,
1862                                    count, orderByComparator);
1863    
1864                    if (!list.isEmpty()) {
1865                            return list.get(0);
1866                    }
1867    
1868                    return null;
1869            }
1870    
1871            /**
1872             * Returns the trash entries before and after the current trash entry in the ordered set where groupId = &#63; and classNameId = &#63;.
1873             *
1874             * @param entryId the primary key of the current trash entry
1875             * @param groupId the group ID
1876             * @param classNameId the class name ID
1877             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1878             * @return the previous, current, and next trash entry
1879             * @throws NoSuchEntryException if a trash entry with the primary key could not be found
1880             */
1881            @Override
1882            public TrashEntry[] findByG_C_PrevAndNext(long entryId, long groupId,
1883                    long classNameId, OrderByComparator<TrashEntry> orderByComparator)
1884                    throws NoSuchEntryException {
1885                    TrashEntry trashEntry = findByPrimaryKey(entryId);
1886    
1887                    Session session = null;
1888    
1889                    try {
1890                            session = openSession();
1891    
1892                            TrashEntry[] array = new TrashEntryImpl[3];
1893    
1894                            array[0] = getByG_C_PrevAndNext(session, trashEntry, groupId,
1895                                            classNameId, orderByComparator, true);
1896    
1897                            array[1] = trashEntry;
1898    
1899                            array[2] = getByG_C_PrevAndNext(session, trashEntry, groupId,
1900                                            classNameId, orderByComparator, false);
1901    
1902                            return array;
1903                    }
1904                    catch (Exception e) {
1905                            throw processException(e);
1906                    }
1907                    finally {
1908                            closeSession(session);
1909                    }
1910            }
1911    
1912            protected TrashEntry getByG_C_PrevAndNext(Session session,
1913                    TrashEntry trashEntry, long groupId, long classNameId,
1914                    OrderByComparator<TrashEntry> orderByComparator, boolean previous) {
1915                    StringBundler query = null;
1916    
1917                    if (orderByComparator != null) {
1918                            query = new StringBundler(6 +
1919                                            (orderByComparator.getOrderByFields().length * 6));
1920                    }
1921                    else {
1922                            query = new StringBundler(3);
1923                    }
1924    
1925                    query.append(_SQL_SELECT_TRASHENTRY_WHERE);
1926    
1927                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1928    
1929                    query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
1930    
1931                    if (orderByComparator != null) {
1932                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1933    
1934                            if (orderByConditionFields.length > 0) {
1935                                    query.append(WHERE_AND);
1936                            }
1937    
1938                            for (int i = 0; i < orderByConditionFields.length; i++) {
1939                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1940                                    query.append(orderByConditionFields[i]);
1941    
1942                                    if ((i + 1) < orderByConditionFields.length) {
1943                                            if (orderByComparator.isAscending() ^ previous) {
1944                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1945                                            }
1946                                            else {
1947                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1948                                            }
1949                                    }
1950                                    else {
1951                                            if (orderByComparator.isAscending() ^ previous) {
1952                                                    query.append(WHERE_GREATER_THAN);
1953                                            }
1954                                            else {
1955                                                    query.append(WHERE_LESSER_THAN);
1956                                            }
1957                                    }
1958                            }
1959    
1960                            query.append(ORDER_BY_CLAUSE);
1961    
1962                            String[] orderByFields = orderByComparator.getOrderByFields();
1963    
1964                            for (int i = 0; i < orderByFields.length; i++) {
1965                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1966                                    query.append(orderByFields[i]);
1967    
1968                                    if ((i + 1) < orderByFields.length) {
1969                                            if (orderByComparator.isAscending() ^ previous) {
1970                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1971                                            }
1972                                            else {
1973                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1974                                            }
1975                                    }
1976                                    else {
1977                                            if (orderByComparator.isAscending() ^ previous) {
1978                                                    query.append(ORDER_BY_ASC);
1979                                            }
1980                                            else {
1981                                                    query.append(ORDER_BY_DESC);
1982                                            }
1983                                    }
1984                            }
1985                    }
1986                    else {
1987                            query.append(TrashEntryModelImpl.ORDER_BY_JPQL);
1988                    }
1989    
1990                    String sql = query.toString();
1991    
1992                    Query q = session.createQuery(sql);
1993    
1994                    q.setFirstResult(0);
1995                    q.setMaxResults(2);
1996    
1997                    QueryPos qPos = QueryPos.getInstance(q);
1998    
1999                    qPos.add(groupId);
2000    
2001                    qPos.add(classNameId);
2002    
2003                    if (orderByComparator != null) {
2004                            Object[] values = orderByComparator.getOrderByConditionValues(trashEntry);
2005    
2006                            for (Object value : values) {
2007                                    qPos.add(value);
2008                            }
2009                    }
2010    
2011                    List<TrashEntry> list = q.list();
2012    
2013                    if (list.size() == 2) {
2014                            return list.get(1);
2015                    }
2016                    else {
2017                            return null;
2018                    }
2019            }
2020    
2021            /**
2022             * Removes all the trash entries where groupId = &#63; and classNameId = &#63; from the database.
2023             *
2024             * @param groupId the group ID
2025             * @param classNameId the class name ID
2026             */
2027            @Override
2028            public void removeByG_C(long groupId, long classNameId) {
2029                    for (TrashEntry trashEntry : findByG_C(groupId, classNameId,
2030                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2031                            remove(trashEntry);
2032                    }
2033            }
2034    
2035            /**
2036             * Returns the number of trash entries where groupId = &#63; and classNameId = &#63;.
2037             *
2038             * @param groupId the group ID
2039             * @param classNameId the class name ID
2040             * @return the number of matching trash entries
2041             */
2042            @Override
2043            public int countByG_C(long groupId, long classNameId) {
2044                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
2045    
2046                    Object[] finderArgs = new Object[] { groupId, classNameId };
2047    
2048                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2049                                    this);
2050    
2051                    if (count == null) {
2052                            StringBundler query = new StringBundler(3);
2053    
2054                            query.append(_SQL_COUNT_TRASHENTRY_WHERE);
2055    
2056                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2057    
2058                            query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
2059    
2060                            String sql = query.toString();
2061    
2062                            Session session = null;
2063    
2064                            try {
2065                                    session = openSession();
2066    
2067                                    Query q = session.createQuery(sql);
2068    
2069                                    QueryPos qPos = QueryPos.getInstance(q);
2070    
2071                                    qPos.add(groupId);
2072    
2073                                    qPos.add(classNameId);
2074    
2075                                    count = (Long)q.uniqueResult();
2076    
2077                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2078                            }
2079                            catch (Exception e) {
2080                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2081    
2082                                    throw processException(e);
2083                            }
2084                            finally {
2085                                    closeSession(session);
2086                            }
2087                    }
2088    
2089                    return count.intValue();
2090            }
2091    
2092            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "trashEntry.groupId = ? AND ";
2093            private static final String _FINDER_COLUMN_G_C_CLASSNAMEID_2 = "trashEntry.classNameId = ?";
2094            public static final FinderPath FINDER_PATH_FETCH_BY_C_C = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2095                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, TrashEntryImpl.class,
2096                            FINDER_CLASS_NAME_ENTITY, "fetchByC_C",
2097                            new String[] { Long.class.getName(), Long.class.getName() },
2098                            TrashEntryModelImpl.CLASSNAMEID_COLUMN_BITMASK |
2099                            TrashEntryModelImpl.CLASSPK_COLUMN_BITMASK);
2100            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2101                            TrashEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2102                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
2103                            new String[] { Long.class.getName(), Long.class.getName() });
2104    
2105            /**
2106             * Returns the trash entry where classNameId = &#63; and classPK = &#63; or throws a {@link NoSuchEntryException} if it could not be found.
2107             *
2108             * @param classNameId the class name ID
2109             * @param classPK the class p k
2110             * @return the matching trash entry
2111             * @throws NoSuchEntryException if a matching trash entry could not be found
2112             */
2113            @Override
2114            public TrashEntry findByC_C(long classNameId, long classPK)
2115                    throws NoSuchEntryException {
2116                    TrashEntry trashEntry = fetchByC_C(classNameId, classPK);
2117    
2118                    if (trashEntry == null) {
2119                            StringBundler msg = new StringBundler(6);
2120    
2121                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2122    
2123                            msg.append("classNameId=");
2124                            msg.append(classNameId);
2125    
2126                            msg.append(", classPK=");
2127                            msg.append(classPK);
2128    
2129                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2130    
2131                            if (_log.isWarnEnabled()) {
2132                                    _log.warn(msg.toString());
2133                            }
2134    
2135                            throw new NoSuchEntryException(msg.toString());
2136                    }
2137    
2138                    return trashEntry;
2139            }
2140    
2141            /**
2142             * Returns the trash entry where classNameId = &#63; and classPK = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2143             *
2144             * @param classNameId the class name ID
2145             * @param classPK the class p k
2146             * @return the matching trash entry, or <code>null</code> if a matching trash entry could not be found
2147             */
2148            @Override
2149            public TrashEntry fetchByC_C(long classNameId, long classPK) {
2150                    return fetchByC_C(classNameId, classPK, true);
2151            }
2152    
2153            /**
2154             * Returns the trash entry where classNameId = &#63; and classPK = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2155             *
2156             * @param classNameId the class name ID
2157             * @param classPK the class p k
2158             * @param retrieveFromCache whether to use the finder cache
2159             * @return the matching trash entry, or <code>null</code> if a matching trash entry could not be found
2160             */
2161            @Override
2162            public TrashEntry fetchByC_C(long classNameId, long classPK,
2163                    boolean retrieveFromCache) {
2164                    Object[] finderArgs = new Object[] { classNameId, classPK };
2165    
2166                    Object result = null;
2167    
2168                    if (retrieveFromCache) {
2169                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C,
2170                                            finderArgs, this);
2171                    }
2172    
2173                    if (result instanceof TrashEntry) {
2174                            TrashEntry trashEntry = (TrashEntry)result;
2175    
2176                            if ((classNameId != trashEntry.getClassNameId()) ||
2177                                            (classPK != trashEntry.getClassPK())) {
2178                                    result = null;
2179                            }
2180                    }
2181    
2182                    if (result == null) {
2183                            StringBundler query = new StringBundler(4);
2184    
2185                            query.append(_SQL_SELECT_TRASHENTRY_WHERE);
2186    
2187                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2188    
2189                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
2190    
2191                            String sql = query.toString();
2192    
2193                            Session session = null;
2194    
2195                            try {
2196                                    session = openSession();
2197    
2198                                    Query q = session.createQuery(sql);
2199    
2200                                    QueryPos qPos = QueryPos.getInstance(q);
2201    
2202                                    qPos.add(classNameId);
2203    
2204                                    qPos.add(classPK);
2205    
2206                                    List<TrashEntry> list = q.list();
2207    
2208                                    if (list.isEmpty()) {
2209                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
2210                                                    finderArgs, list);
2211                                    }
2212                                    else {
2213                                            TrashEntry trashEntry = list.get(0);
2214    
2215                                            result = trashEntry;
2216    
2217                                            cacheResult(trashEntry);
2218    
2219                                            if ((trashEntry.getClassNameId() != classNameId) ||
2220                                                            (trashEntry.getClassPK() != classPK)) {
2221                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
2222                                                            finderArgs, trashEntry);
2223                                            }
2224                                    }
2225                            }
2226                            catch (Exception e) {
2227                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
2228                                            finderArgs);
2229    
2230                                    throw processException(e);
2231                            }
2232                            finally {
2233                                    closeSession(session);
2234                            }
2235                    }
2236    
2237                    if (result instanceof List<?>) {
2238                            return null;
2239                    }
2240                    else {
2241                            return (TrashEntry)result;
2242                    }
2243            }
2244    
2245            /**
2246             * Removes the trash entry where classNameId = &#63; and classPK = &#63; from the database.
2247             *
2248             * @param classNameId the class name ID
2249             * @param classPK the class p k
2250             * @return the trash entry that was removed
2251             */
2252            @Override
2253            public TrashEntry removeByC_C(long classNameId, long classPK)
2254                    throws NoSuchEntryException {
2255                    TrashEntry trashEntry = findByC_C(classNameId, classPK);
2256    
2257                    return remove(trashEntry);
2258            }
2259    
2260            /**
2261             * Returns the number of trash entries where classNameId = &#63; and classPK = &#63;.
2262             *
2263             * @param classNameId the class name ID
2264             * @param classPK the class p k
2265             * @return the number of matching trash entries
2266             */
2267            @Override
2268            public int countByC_C(long classNameId, long classPK) {
2269                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
2270    
2271                    Object[] finderArgs = new Object[] { classNameId, classPK };
2272    
2273                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2274                                    this);
2275    
2276                    if (count == null) {
2277                            StringBundler query = new StringBundler(3);
2278    
2279                            query.append(_SQL_COUNT_TRASHENTRY_WHERE);
2280    
2281                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2282    
2283                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
2284    
2285                            String sql = query.toString();
2286    
2287                            Session session = null;
2288    
2289                            try {
2290                                    session = openSession();
2291    
2292                                    Query q = session.createQuery(sql);
2293    
2294                                    QueryPos qPos = QueryPos.getInstance(q);
2295    
2296                                    qPos.add(classNameId);
2297    
2298                                    qPos.add(classPK);
2299    
2300                                    count = (Long)q.uniqueResult();
2301    
2302                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2303                            }
2304                            catch (Exception e) {
2305                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2306    
2307                                    throw processException(e);
2308                            }
2309                            finally {
2310                                    closeSession(session);
2311                            }
2312                    }
2313    
2314                    return count.intValue();
2315            }
2316    
2317            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "trashEntry.classNameId = ? AND ";
2318            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "trashEntry.classPK = ?";
2319    
2320            public TrashEntryPersistenceImpl() {
2321                    setModelClass(TrashEntry.class);
2322            }
2323    
2324            /**
2325             * Caches the trash entry in the entity cache if it is enabled.
2326             *
2327             * @param trashEntry the trash entry
2328             */
2329            @Override
2330            public void cacheResult(TrashEntry trashEntry) {
2331                    EntityCacheUtil.putResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2332                            TrashEntryImpl.class, trashEntry.getPrimaryKey(), trashEntry);
2333    
2334                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
2335                            new Object[] { trashEntry.getClassNameId(), trashEntry.getClassPK() },
2336                            trashEntry);
2337    
2338                    trashEntry.resetOriginalValues();
2339            }
2340    
2341            /**
2342             * Caches the trash entries in the entity cache if it is enabled.
2343             *
2344             * @param trashEntries the trash entries
2345             */
2346            @Override
2347            public void cacheResult(List<TrashEntry> trashEntries) {
2348                    for (TrashEntry trashEntry : trashEntries) {
2349                            if (EntityCacheUtil.getResult(
2350                                                    TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2351                                                    TrashEntryImpl.class, trashEntry.getPrimaryKey()) == null) {
2352                                    cacheResult(trashEntry);
2353                            }
2354                            else {
2355                                    trashEntry.resetOriginalValues();
2356                            }
2357                    }
2358            }
2359    
2360            /**
2361             * Clears the cache for all trash entries.
2362             *
2363             * <p>
2364             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2365             * </p>
2366             */
2367            @Override
2368            public void clearCache() {
2369                    EntityCacheUtil.clearCache(TrashEntryImpl.class);
2370    
2371                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2372                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2373                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2374            }
2375    
2376            /**
2377             * Clears the cache for the trash entry.
2378             *
2379             * <p>
2380             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2381             * </p>
2382             */
2383            @Override
2384            public void clearCache(TrashEntry trashEntry) {
2385                    EntityCacheUtil.removeResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2386                            TrashEntryImpl.class, trashEntry.getPrimaryKey());
2387    
2388                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2389                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2390    
2391                    clearUniqueFindersCache(trashEntry);
2392            }
2393    
2394            @Override
2395            public void clearCache(List<TrashEntry> trashEntries) {
2396                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2397                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2398    
2399                    for (TrashEntry trashEntry : trashEntries) {
2400                            EntityCacheUtil.removeResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2401                                    TrashEntryImpl.class, trashEntry.getPrimaryKey());
2402    
2403                            clearUniqueFindersCache(trashEntry);
2404                    }
2405            }
2406    
2407            protected void cacheUniqueFindersCache(TrashEntry trashEntry) {
2408                    if (trashEntry.isNew()) {
2409                            Object[] args = new Object[] {
2410                                            trashEntry.getClassNameId(), trashEntry.getClassPK()
2411                                    };
2412    
2413                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, args,
2414                                    Long.valueOf(1));
2415                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C, args, trashEntry);
2416                    }
2417                    else {
2418                            TrashEntryModelImpl trashEntryModelImpl = (TrashEntryModelImpl)trashEntry;
2419    
2420                            if ((trashEntryModelImpl.getColumnBitmask() &
2421                                            FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
2422                                    Object[] args = new Object[] {
2423                                                    trashEntry.getClassNameId(), trashEntry.getClassPK()
2424                                            };
2425    
2426                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, args,
2427                                            Long.valueOf(1));
2428                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C, args,
2429                                            trashEntry);
2430                            }
2431                    }
2432            }
2433    
2434            protected void clearUniqueFindersCache(TrashEntry trashEntry) {
2435                    TrashEntryModelImpl trashEntryModelImpl = (TrashEntryModelImpl)trashEntry;
2436    
2437                    Object[] args = new Object[] {
2438                                    trashEntry.getClassNameId(), trashEntry.getClassPK()
2439                            };
2440    
2441                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
2442                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
2443    
2444                    if ((trashEntryModelImpl.getColumnBitmask() &
2445                                    FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
2446                            args = new Object[] {
2447                                            trashEntryModelImpl.getOriginalClassNameId(),
2448                                            trashEntryModelImpl.getOriginalClassPK()
2449                                    };
2450    
2451                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
2452                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
2453                    }
2454            }
2455    
2456            /**
2457             * Creates a new trash entry with the primary key. Does not add the trash entry to the database.
2458             *
2459             * @param entryId the primary key for the new trash entry
2460             * @return the new trash entry
2461             */
2462            @Override
2463            public TrashEntry create(long entryId) {
2464                    TrashEntry trashEntry = new TrashEntryImpl();
2465    
2466                    trashEntry.setNew(true);
2467                    trashEntry.setPrimaryKey(entryId);
2468    
2469                    return trashEntry;
2470            }
2471    
2472            /**
2473             * Removes the trash entry with the primary key from the database. Also notifies the appropriate model listeners.
2474             *
2475             * @param entryId the primary key of the trash entry
2476             * @return the trash entry that was removed
2477             * @throws NoSuchEntryException if a trash entry with the primary key could not be found
2478             */
2479            @Override
2480            public TrashEntry remove(long entryId) throws NoSuchEntryException {
2481                    return remove((Serializable)entryId);
2482            }
2483    
2484            /**
2485             * Removes the trash entry with the primary key from the database. Also notifies the appropriate model listeners.
2486             *
2487             * @param primaryKey the primary key of the trash entry
2488             * @return the trash entry that was removed
2489             * @throws NoSuchEntryException if a trash entry with the primary key could not be found
2490             */
2491            @Override
2492            public TrashEntry remove(Serializable primaryKey)
2493                    throws NoSuchEntryException {
2494                    Session session = null;
2495    
2496                    try {
2497                            session = openSession();
2498    
2499                            TrashEntry trashEntry = (TrashEntry)session.get(TrashEntryImpl.class,
2500                                            primaryKey);
2501    
2502                            if (trashEntry == null) {
2503                                    if (_log.isWarnEnabled()) {
2504                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2505                                    }
2506    
2507                                    throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2508                                            primaryKey);
2509                            }
2510    
2511                            return remove(trashEntry);
2512                    }
2513                    catch (NoSuchEntryException nsee) {
2514                            throw nsee;
2515                    }
2516                    catch (Exception e) {
2517                            throw processException(e);
2518                    }
2519                    finally {
2520                            closeSession(session);
2521                    }
2522            }
2523    
2524            @Override
2525            protected TrashEntry removeImpl(TrashEntry trashEntry) {
2526                    trashEntry = toUnwrappedModel(trashEntry);
2527    
2528                    Session session = null;
2529    
2530                    try {
2531                            session = openSession();
2532    
2533                            if (!session.contains(trashEntry)) {
2534                                    trashEntry = (TrashEntry)session.get(TrashEntryImpl.class,
2535                                                    trashEntry.getPrimaryKeyObj());
2536                            }
2537    
2538                            if (trashEntry != null) {
2539                                    session.delete(trashEntry);
2540                            }
2541                    }
2542                    catch (Exception e) {
2543                            throw processException(e);
2544                    }
2545                    finally {
2546                            closeSession(session);
2547                    }
2548    
2549                    if (trashEntry != null) {
2550                            clearCache(trashEntry);
2551                    }
2552    
2553                    return trashEntry;
2554            }
2555    
2556            @Override
2557            public TrashEntry updateImpl(TrashEntry trashEntry) {
2558                    trashEntry = toUnwrappedModel(trashEntry);
2559    
2560                    boolean isNew = trashEntry.isNew();
2561    
2562                    TrashEntryModelImpl trashEntryModelImpl = (TrashEntryModelImpl)trashEntry;
2563    
2564                    Session session = null;
2565    
2566                    try {
2567                            session = openSession();
2568    
2569                            if (trashEntry.isNew()) {
2570                                    session.save(trashEntry);
2571    
2572                                    trashEntry.setNew(false);
2573                            }
2574                            else {
2575                                    session.merge(trashEntry);
2576                            }
2577                    }
2578                    catch (Exception e) {
2579                            throw processException(e);
2580                    }
2581                    finally {
2582                            closeSession(session);
2583                    }
2584    
2585                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2586    
2587                    if (isNew || !TrashEntryModelImpl.COLUMN_BITMASK_ENABLED) {
2588                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2589                    }
2590    
2591                    else {
2592                            if ((trashEntryModelImpl.getColumnBitmask() &
2593                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
2594                                    Object[] args = new Object[] {
2595                                                    trashEntryModelImpl.getOriginalGroupId()
2596                                            };
2597    
2598                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2599                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2600                                            args);
2601    
2602                                    args = new Object[] { trashEntryModelImpl.getGroupId() };
2603    
2604                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2605                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2606                                            args);
2607                            }
2608    
2609                            if ((trashEntryModelImpl.getColumnBitmask() &
2610                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
2611                                    Object[] args = new Object[] {
2612                                                    trashEntryModelImpl.getOriginalCompanyId()
2613                                            };
2614    
2615                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
2616                                            args);
2617                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
2618                                            args);
2619    
2620                                    args = new Object[] { trashEntryModelImpl.getCompanyId() };
2621    
2622                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
2623                                            args);
2624                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
2625                                            args);
2626                            }
2627    
2628                            if ((trashEntryModelImpl.getColumnBitmask() &
2629                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
2630                                    Object[] args = new Object[] {
2631                                                    trashEntryModelImpl.getOriginalGroupId(),
2632                                                    trashEntryModelImpl.getOriginalClassNameId()
2633                                            };
2634    
2635                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
2636                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
2637                                            args);
2638    
2639                                    args = new Object[] {
2640                                                    trashEntryModelImpl.getGroupId(),
2641                                                    trashEntryModelImpl.getClassNameId()
2642                                            };
2643    
2644                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
2645                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
2646                                            args);
2647                            }
2648                    }
2649    
2650                    EntityCacheUtil.putResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2651                            TrashEntryImpl.class, trashEntry.getPrimaryKey(), trashEntry, false);
2652    
2653                    clearUniqueFindersCache(trashEntry);
2654                    cacheUniqueFindersCache(trashEntry);
2655    
2656                    trashEntry.resetOriginalValues();
2657    
2658                    return trashEntry;
2659            }
2660    
2661            protected TrashEntry toUnwrappedModel(TrashEntry trashEntry) {
2662                    if (trashEntry instanceof TrashEntryImpl) {
2663                            return trashEntry;
2664                    }
2665    
2666                    TrashEntryImpl trashEntryImpl = new TrashEntryImpl();
2667    
2668                    trashEntryImpl.setNew(trashEntry.isNew());
2669                    trashEntryImpl.setPrimaryKey(trashEntry.getPrimaryKey());
2670    
2671                    trashEntryImpl.setEntryId(trashEntry.getEntryId());
2672                    trashEntryImpl.setGroupId(trashEntry.getGroupId());
2673                    trashEntryImpl.setCompanyId(trashEntry.getCompanyId());
2674                    trashEntryImpl.setUserId(trashEntry.getUserId());
2675                    trashEntryImpl.setUserName(trashEntry.getUserName());
2676                    trashEntryImpl.setCreateDate(trashEntry.getCreateDate());
2677                    trashEntryImpl.setClassNameId(trashEntry.getClassNameId());
2678                    trashEntryImpl.setClassPK(trashEntry.getClassPK());
2679                    trashEntryImpl.setSystemEventSetKey(trashEntry.getSystemEventSetKey());
2680                    trashEntryImpl.setTypeSettings(trashEntry.getTypeSettings());
2681                    trashEntryImpl.setStatus(trashEntry.getStatus());
2682    
2683                    return trashEntryImpl;
2684            }
2685    
2686            /**
2687             * Returns the trash entry with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2688             *
2689             * @param primaryKey the primary key of the trash entry
2690             * @return the trash entry
2691             * @throws NoSuchEntryException if a trash entry with the primary key could not be found
2692             */
2693            @Override
2694            public TrashEntry findByPrimaryKey(Serializable primaryKey)
2695                    throws NoSuchEntryException {
2696                    TrashEntry trashEntry = fetchByPrimaryKey(primaryKey);
2697    
2698                    if (trashEntry == null) {
2699                            if (_log.isWarnEnabled()) {
2700                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2701                            }
2702    
2703                            throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2704                                    primaryKey);
2705                    }
2706    
2707                    return trashEntry;
2708            }
2709    
2710            /**
2711             * Returns the trash entry with the primary key or throws a {@link NoSuchEntryException} if it could not be found.
2712             *
2713             * @param entryId the primary key of the trash entry
2714             * @return the trash entry
2715             * @throws NoSuchEntryException if a trash entry with the primary key could not be found
2716             */
2717            @Override
2718            public TrashEntry findByPrimaryKey(long entryId)
2719                    throws NoSuchEntryException {
2720                    return findByPrimaryKey((Serializable)entryId);
2721            }
2722    
2723            /**
2724             * Returns the trash entry with the primary key or returns <code>null</code> if it could not be found.
2725             *
2726             * @param primaryKey the primary key of the trash entry
2727             * @return the trash entry, or <code>null</code> if a trash entry with the primary key could not be found
2728             */
2729            @Override
2730            public TrashEntry fetchByPrimaryKey(Serializable primaryKey) {
2731                    TrashEntry trashEntry = (TrashEntry)EntityCacheUtil.getResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2732                                    TrashEntryImpl.class, primaryKey);
2733    
2734                    if (trashEntry == _nullTrashEntry) {
2735                            return null;
2736                    }
2737    
2738                    if (trashEntry == null) {
2739                            Session session = null;
2740    
2741                            try {
2742                                    session = openSession();
2743    
2744                                    trashEntry = (TrashEntry)session.get(TrashEntryImpl.class,
2745                                                    primaryKey);
2746    
2747                                    if (trashEntry != null) {
2748                                            cacheResult(trashEntry);
2749                                    }
2750                                    else {
2751                                            EntityCacheUtil.putResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2752                                                    TrashEntryImpl.class, primaryKey, _nullTrashEntry);
2753                                    }
2754                            }
2755                            catch (Exception e) {
2756                                    EntityCacheUtil.removeResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2757                                            TrashEntryImpl.class, primaryKey);
2758    
2759                                    throw processException(e);
2760                            }
2761                            finally {
2762                                    closeSession(session);
2763                            }
2764                    }
2765    
2766                    return trashEntry;
2767            }
2768    
2769            /**
2770             * Returns the trash entry with the primary key or returns <code>null</code> if it could not be found.
2771             *
2772             * @param entryId the primary key of the trash entry
2773             * @return the trash entry, or <code>null</code> if a trash entry with the primary key could not be found
2774             */
2775            @Override
2776            public TrashEntry fetchByPrimaryKey(long entryId) {
2777                    return fetchByPrimaryKey((Serializable)entryId);
2778            }
2779    
2780            @Override
2781            public Map<Serializable, TrashEntry> fetchByPrimaryKeys(
2782                    Set<Serializable> primaryKeys) {
2783                    if (primaryKeys.isEmpty()) {
2784                            return Collections.emptyMap();
2785                    }
2786    
2787                    Map<Serializable, TrashEntry> map = new HashMap<Serializable, TrashEntry>();
2788    
2789                    if (primaryKeys.size() == 1) {
2790                            Iterator<Serializable> iterator = primaryKeys.iterator();
2791    
2792                            Serializable primaryKey = iterator.next();
2793    
2794                            TrashEntry trashEntry = fetchByPrimaryKey(primaryKey);
2795    
2796                            if (trashEntry != null) {
2797                                    map.put(primaryKey, trashEntry);
2798                            }
2799    
2800                            return map;
2801                    }
2802    
2803                    Set<Serializable> uncachedPrimaryKeys = null;
2804    
2805                    for (Serializable primaryKey : primaryKeys) {
2806                            TrashEntry trashEntry = (TrashEntry)EntityCacheUtil.getResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2807                                            TrashEntryImpl.class, primaryKey);
2808    
2809                            if (trashEntry == null) {
2810                                    if (uncachedPrimaryKeys == null) {
2811                                            uncachedPrimaryKeys = new HashSet<Serializable>();
2812                                    }
2813    
2814                                    uncachedPrimaryKeys.add(primaryKey);
2815                            }
2816                            else {
2817                                    map.put(primaryKey, trashEntry);
2818                            }
2819                    }
2820    
2821                    if (uncachedPrimaryKeys == null) {
2822                            return map;
2823                    }
2824    
2825                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
2826                                    1);
2827    
2828                    query.append(_SQL_SELECT_TRASHENTRY_WHERE_PKS_IN);
2829    
2830                    for (Serializable primaryKey : uncachedPrimaryKeys) {
2831                            query.append(String.valueOf(primaryKey));
2832    
2833                            query.append(StringPool.COMMA);
2834                    }
2835    
2836                    query.setIndex(query.index() - 1);
2837    
2838                    query.append(StringPool.CLOSE_PARENTHESIS);
2839    
2840                    String sql = query.toString();
2841    
2842                    Session session = null;
2843    
2844                    try {
2845                            session = openSession();
2846    
2847                            Query q = session.createQuery(sql);
2848    
2849                            for (TrashEntry trashEntry : (List<TrashEntry>)q.list()) {
2850                                    map.put(trashEntry.getPrimaryKeyObj(), trashEntry);
2851    
2852                                    cacheResult(trashEntry);
2853    
2854                                    uncachedPrimaryKeys.remove(trashEntry.getPrimaryKeyObj());
2855                            }
2856    
2857                            for (Serializable primaryKey : uncachedPrimaryKeys) {
2858                                    EntityCacheUtil.putResult(TrashEntryModelImpl.ENTITY_CACHE_ENABLED,
2859                                            TrashEntryImpl.class, primaryKey, _nullTrashEntry);
2860                            }
2861                    }
2862                    catch (Exception e) {
2863                            throw processException(e);
2864                    }
2865                    finally {
2866                            closeSession(session);
2867                    }
2868    
2869                    return map;
2870            }
2871    
2872            /**
2873             * Returns all the trash entries.
2874             *
2875             * @return the trash entries
2876             */
2877            @Override
2878            public List<TrashEntry> findAll() {
2879                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2880            }
2881    
2882            /**
2883             * Returns a range of all the trash entries.
2884             *
2885             * <p>
2886             * 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 TrashEntryModelImpl}. 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.
2887             * </p>
2888             *
2889             * @param start the lower bound of the range of trash entries
2890             * @param end the upper bound of the range of trash entries (not inclusive)
2891             * @return the range of trash entries
2892             */
2893            @Override
2894            public List<TrashEntry> findAll(int start, int end) {
2895                    return findAll(start, end, null);
2896            }
2897    
2898            /**
2899             * Returns an ordered range of all the trash entries.
2900             *
2901             * <p>
2902             * 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 TrashEntryModelImpl}. 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.
2903             * </p>
2904             *
2905             * @param start the lower bound of the range of trash entries
2906             * @param end the upper bound of the range of trash entries (not inclusive)
2907             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2908             * @return the ordered range of trash entries
2909             */
2910            @Override
2911            public List<TrashEntry> findAll(int start, int end,
2912                    OrderByComparator<TrashEntry> orderByComparator) {
2913                    boolean pagination = true;
2914                    FinderPath finderPath = null;
2915                    Object[] finderArgs = null;
2916    
2917                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2918                                    (orderByComparator == null)) {
2919                            pagination = false;
2920                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2921                            finderArgs = FINDER_ARGS_EMPTY;
2922                    }
2923                    else {
2924                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2925                            finderArgs = new Object[] { start, end, orderByComparator };
2926                    }
2927    
2928                    List<TrashEntry> list = (List<TrashEntry>)FinderCacheUtil.getResult(finderPath,
2929                                    finderArgs, this);
2930    
2931                    if (list == null) {
2932                            StringBundler query = null;
2933                            String sql = null;
2934    
2935                            if (orderByComparator != null) {
2936                                    query = new StringBundler(2 +
2937                                                    (orderByComparator.getOrderByFields().length * 3));
2938    
2939                                    query.append(_SQL_SELECT_TRASHENTRY);
2940    
2941                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2942                                            orderByComparator);
2943    
2944                                    sql = query.toString();
2945                            }
2946                            else {
2947                                    sql = _SQL_SELECT_TRASHENTRY;
2948    
2949                                    if (pagination) {
2950                                            sql = sql.concat(TrashEntryModelImpl.ORDER_BY_JPQL);
2951                                    }
2952                            }
2953    
2954                            Session session = null;
2955    
2956                            try {
2957                                    session = openSession();
2958    
2959                                    Query q = session.createQuery(sql);
2960    
2961                                    if (!pagination) {
2962                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
2963                                                            start, end, false);
2964    
2965                                            Collections.sort(list);
2966    
2967                                            list = Collections.unmodifiableList(list);
2968                                    }
2969                                    else {
2970                                            list = (List<TrashEntry>)QueryUtil.list(q, getDialect(),
2971                                                            start, end);
2972                                    }
2973    
2974                                    cacheResult(list);
2975    
2976                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2977                            }
2978                            catch (Exception e) {
2979                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2980    
2981                                    throw processException(e);
2982                            }
2983                            finally {
2984                                    closeSession(session);
2985                            }
2986                    }
2987    
2988                    return list;
2989            }
2990    
2991            /**
2992             * Removes all the trash entries from the database.
2993             *
2994             */
2995            @Override
2996            public void removeAll() {
2997                    for (TrashEntry trashEntry : findAll()) {
2998                            remove(trashEntry);
2999                    }
3000            }
3001    
3002            /**
3003             * Returns the number of trash entries.
3004             *
3005             * @return the number of trash entries
3006             */
3007            @Override
3008            public int countAll() {
3009                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3010                                    FINDER_ARGS_EMPTY, this);
3011    
3012                    if (count == null) {
3013                            Session session = null;
3014    
3015                            try {
3016                                    session = openSession();
3017    
3018                                    Query q = session.createQuery(_SQL_COUNT_TRASHENTRY);
3019    
3020                                    count = (Long)q.uniqueResult();
3021    
3022                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3023                                            FINDER_ARGS_EMPTY, count);
3024                            }
3025                            catch (Exception e) {
3026                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
3027                                            FINDER_ARGS_EMPTY);
3028    
3029                                    throw processException(e);
3030                            }
3031                            finally {
3032                                    closeSession(session);
3033                            }
3034                    }
3035    
3036                    return count.intValue();
3037            }
3038    
3039            /**
3040             * Initializes the trash entry persistence.
3041             */
3042            public void afterPropertiesSet() {
3043            }
3044    
3045            public void destroy() {
3046                    EntityCacheUtil.removeCache(TrashEntryImpl.class.getName());
3047                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3048                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3049                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3050            }
3051    
3052            private static final String _SQL_SELECT_TRASHENTRY = "SELECT trashEntry FROM TrashEntry trashEntry";
3053            private static final String _SQL_SELECT_TRASHENTRY_WHERE_PKS_IN = "SELECT trashEntry FROM TrashEntry trashEntry WHERE entryId IN (";
3054            private static final String _SQL_SELECT_TRASHENTRY_WHERE = "SELECT trashEntry FROM TrashEntry trashEntry WHERE ";
3055            private static final String _SQL_COUNT_TRASHENTRY = "SELECT COUNT(trashEntry) FROM TrashEntry trashEntry";
3056            private static final String _SQL_COUNT_TRASHENTRY_WHERE = "SELECT COUNT(trashEntry) FROM TrashEntry trashEntry WHERE ";
3057            private static final String _ORDER_BY_ENTITY_ALIAS = "trashEntry.";
3058            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No TrashEntry exists with the primary key ";
3059            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No TrashEntry exists with the key {";
3060            private static final Log _log = LogFactoryUtil.getLog(TrashEntryPersistenceImpl.class);
3061            private static final TrashEntry _nullTrashEntry = new TrashEntryImpl() {
3062                            @Override
3063                            public Object clone() {
3064                                    return this;
3065                            }
3066    
3067                            @Override
3068                            public CacheModel<TrashEntry> toCacheModel() {
3069                                    return _nullTrashEntryCacheModel;
3070                            }
3071                    };
3072    
3073            private static final CacheModel<TrashEntry> _nullTrashEntryCacheModel = new CacheModel<TrashEntry>() {
3074                            @Override
3075                            public TrashEntry toEntityModel() {
3076                                    return _nullTrashEntry;
3077                            }
3078                    };
3079    }