001    /**
002     * Copyright (c) 2000-2013 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.journal.service.persistence;
016    
017    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderPath;
021    import com.liferay.portal.kernel.dao.orm.Query;
022    import com.liferay.portal.kernel.dao.orm.QueryPos;
023    import com.liferay.portal.kernel.dao.orm.QueryUtil;
024    import com.liferay.portal.kernel.dao.orm.Session;
025    import com.liferay.portal.kernel.exception.SystemException;
026    import com.liferay.portal.kernel.log.Log;
027    import com.liferay.portal.kernel.log.LogFactoryUtil;
028    import com.liferay.portal.kernel.util.GetterUtil;
029    import com.liferay.portal.kernel.util.InstanceFactory;
030    import com.liferay.portal.kernel.util.OrderByComparator;
031    import com.liferay.portal.kernel.util.StringBundler;
032    import com.liferay.portal.kernel.util.StringPool;
033    import com.liferay.portal.kernel.util.StringUtil;
034    import com.liferay.portal.kernel.util.UnmodifiableList;
035    import com.liferay.portal.kernel.util.Validator;
036    import com.liferay.portal.model.CacheModel;
037    import com.liferay.portal.model.ModelListener;
038    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
039    
040    import com.liferay.portlet.journal.NoSuchContentSearchException;
041    import com.liferay.portlet.journal.model.JournalContentSearch;
042    import com.liferay.portlet.journal.model.impl.JournalContentSearchImpl;
043    import com.liferay.portlet.journal.model.impl.JournalContentSearchModelImpl;
044    
045    import java.io.Serializable;
046    
047    import java.util.ArrayList;
048    import java.util.Collections;
049    import java.util.List;
050    
051    /**
052     * The persistence implementation for the journal content search service.
053     *
054     * <p>
055     * Caching information and settings can be found in <code>portal.properties</code>
056     * </p>
057     *
058     * @author Brian Wing Shun Chan
059     * @see JournalContentSearchPersistence
060     * @see JournalContentSearchUtil
061     * @generated
062     */
063    public class JournalContentSearchPersistenceImpl extends BasePersistenceImpl<JournalContentSearch>
064            implements JournalContentSearchPersistence {
065            /*
066             * NOTE FOR DEVELOPERS:
067             *
068             * Never modify or reference this class directly. Always use {@link JournalContentSearchUtil} to access the journal content search persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
069             */
070            public static final String FINDER_CLASS_NAME_ENTITY = JournalContentSearchImpl.class.getName();
071            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072                    ".List1";
073            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074                    ".List2";
075            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
076                            JournalContentSearchModelImpl.FINDER_CACHE_ENABLED,
077                            JournalContentSearchImpl.class,
078                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
079            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
080                            JournalContentSearchModelImpl.FINDER_CACHE_ENABLED,
081                            JournalContentSearchImpl.class,
082                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
083            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
084                            JournalContentSearchModelImpl.FINDER_CACHE_ENABLED, Long.class,
085                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
086            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_PORTLETID =
087                    new FinderPath(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
088                            JournalContentSearchModelImpl.FINDER_CACHE_ENABLED,
089                            JournalContentSearchImpl.class,
090                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByPortletId",
091                            new String[] {
092                                    String.class.getName(),
093                                    
094                            Integer.class.getName(), Integer.class.getName(),
095                                    OrderByComparator.class.getName()
096                            });
097            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PORTLETID =
098                    new FinderPath(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
099                            JournalContentSearchModelImpl.FINDER_CACHE_ENABLED,
100                            JournalContentSearchImpl.class,
101                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByPortletId",
102                            new String[] { String.class.getName() },
103                            JournalContentSearchModelImpl.PORTLETID_COLUMN_BITMASK);
104            public static final FinderPath FINDER_PATH_COUNT_BY_PORTLETID = new FinderPath(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
105                            JournalContentSearchModelImpl.FINDER_CACHE_ENABLED, Long.class,
106                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByPortletId",
107                            new String[] { String.class.getName() });
108    
109            /**
110             * Returns all the journal content searchs where portletId = &#63;.
111             *
112             * @param portletId the portlet ID
113             * @return the matching journal content searchs
114             * @throws SystemException if a system exception occurred
115             */
116            @Override
117            public List<JournalContentSearch> findByPortletId(String portletId)
118                    throws SystemException {
119                    return findByPortletId(portletId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
120                            null);
121            }
122    
123            /**
124             * Returns a range of all the journal content searchs where portletId = &#63;.
125             *
126             * <p>
127             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalContentSearchModelImpl}. 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.
128             * </p>
129             *
130             * @param portletId the portlet ID
131             * @param start the lower bound of the range of journal content searchs
132             * @param end the upper bound of the range of journal content searchs (not inclusive)
133             * @return the range of matching journal content searchs
134             * @throws SystemException if a system exception occurred
135             */
136            @Override
137            public List<JournalContentSearch> findByPortletId(String portletId,
138                    int start, int end) throws SystemException {
139                    return findByPortletId(portletId, start, end, null);
140            }
141    
142            /**
143             * Returns an ordered range of all the journal content searchs where portletId = &#63;.
144             *
145             * <p>
146             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalContentSearchModelImpl}. 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.
147             * </p>
148             *
149             * @param portletId the portlet ID
150             * @param start the lower bound of the range of journal content searchs
151             * @param end the upper bound of the range of journal content searchs (not inclusive)
152             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
153             * @return the ordered range of matching journal content searchs
154             * @throws SystemException if a system exception occurred
155             */
156            @Override
157            public List<JournalContentSearch> findByPortletId(String portletId,
158                    int start, int end, OrderByComparator orderByComparator)
159                    throws SystemException {
160                    boolean pagination = true;
161                    FinderPath finderPath = null;
162                    Object[] finderArgs = null;
163    
164                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
165                                    (orderByComparator == null)) {
166                            pagination = false;
167                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PORTLETID;
168                            finderArgs = new Object[] { portletId };
169                    }
170                    else {
171                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_PORTLETID;
172                            finderArgs = new Object[] { portletId, start, end, orderByComparator };
173                    }
174    
175                    List<JournalContentSearch> list = (List<JournalContentSearch>)FinderCacheUtil.getResult(finderPath,
176                                    finderArgs, this);
177    
178                    if ((list != null) && !list.isEmpty()) {
179                            for (JournalContentSearch journalContentSearch : list) {
180                                    if (!Validator.equals(portletId,
181                                                            journalContentSearch.getPortletId())) {
182                                            list = null;
183    
184                                            break;
185                                    }
186                            }
187                    }
188    
189                    if (list == null) {
190                            StringBundler query = null;
191    
192                            if (orderByComparator != null) {
193                                    query = new StringBundler(3 +
194                                                    (orderByComparator.getOrderByFields().length * 3));
195                            }
196                            else {
197                                    query = new StringBundler(3);
198                            }
199    
200                            query.append(_SQL_SELECT_JOURNALCONTENTSEARCH_WHERE);
201    
202                            boolean bindPortletId = false;
203    
204                            if (portletId == null) {
205                                    query.append(_FINDER_COLUMN_PORTLETID_PORTLETID_1);
206                            }
207                            else if (portletId.equals(StringPool.BLANK)) {
208                                    query.append(_FINDER_COLUMN_PORTLETID_PORTLETID_3);
209                            }
210                            else {
211                                    bindPortletId = true;
212    
213                                    query.append(_FINDER_COLUMN_PORTLETID_PORTLETID_2);
214                            }
215    
216                            if (orderByComparator != null) {
217                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
218                                            orderByComparator);
219                            }
220                            else
221                             if (pagination) {
222                                    query.append(JournalContentSearchModelImpl.ORDER_BY_JPQL);
223                            }
224    
225                            String sql = query.toString();
226    
227                            Session session = null;
228    
229                            try {
230                                    session = openSession();
231    
232                                    Query q = session.createQuery(sql);
233    
234                                    QueryPos qPos = QueryPos.getInstance(q);
235    
236                                    if (bindPortletId) {
237                                            qPos.add(portletId);
238                                    }
239    
240                                    if (!pagination) {
241                                            list = (List<JournalContentSearch>)QueryUtil.list(q,
242                                                            getDialect(), start, end, false);
243    
244                                            Collections.sort(list);
245    
246                                            list = new UnmodifiableList<JournalContentSearch>(list);
247                                    }
248                                    else {
249                                            list = (List<JournalContentSearch>)QueryUtil.list(q,
250                                                            getDialect(), start, end);
251                                    }
252    
253                                    cacheResult(list);
254    
255                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
256                            }
257                            catch (Exception e) {
258                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
259    
260                                    throw processException(e);
261                            }
262                            finally {
263                                    closeSession(session);
264                            }
265                    }
266    
267                    return list;
268            }
269    
270            /**
271             * Returns the first journal content search in the ordered set where portletId = &#63;.
272             *
273             * @param portletId the portlet ID
274             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
275             * @return the first matching journal content search
276             * @throws com.liferay.portlet.journal.NoSuchContentSearchException if a matching journal content search could not be found
277             * @throws SystemException if a system exception occurred
278             */
279            @Override
280            public JournalContentSearch findByPortletId_First(String portletId,
281                    OrderByComparator orderByComparator)
282                    throws NoSuchContentSearchException, SystemException {
283                    JournalContentSearch journalContentSearch = fetchByPortletId_First(portletId,
284                                    orderByComparator);
285    
286                    if (journalContentSearch != null) {
287                            return journalContentSearch;
288                    }
289    
290                    StringBundler msg = new StringBundler(4);
291    
292                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
293    
294                    msg.append("portletId=");
295                    msg.append(portletId);
296    
297                    msg.append(StringPool.CLOSE_CURLY_BRACE);
298    
299                    throw new NoSuchContentSearchException(msg.toString());
300            }
301    
302            /**
303             * Returns the first journal content search in the ordered set where portletId = &#63;.
304             *
305             * @param portletId the portlet ID
306             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
307             * @return the first matching journal content search, or <code>null</code> if a matching journal content search could not be found
308             * @throws SystemException if a system exception occurred
309             */
310            @Override
311            public JournalContentSearch fetchByPortletId_First(String portletId,
312                    OrderByComparator orderByComparator) throws SystemException {
313                    List<JournalContentSearch> list = findByPortletId(portletId, 0, 1,
314                                    orderByComparator);
315    
316                    if (!list.isEmpty()) {
317                            return list.get(0);
318                    }
319    
320                    return null;
321            }
322    
323            /**
324             * Returns the last journal content search in the ordered set where portletId = &#63;.
325             *
326             * @param portletId the portlet ID
327             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
328             * @return the last matching journal content search
329             * @throws com.liferay.portlet.journal.NoSuchContentSearchException if a matching journal content search could not be found
330             * @throws SystemException if a system exception occurred
331             */
332            @Override
333            public JournalContentSearch findByPortletId_Last(String portletId,
334                    OrderByComparator orderByComparator)
335                    throws NoSuchContentSearchException, SystemException {
336                    JournalContentSearch journalContentSearch = fetchByPortletId_Last(portletId,
337                                    orderByComparator);
338    
339                    if (journalContentSearch != null) {
340                            return journalContentSearch;
341                    }
342    
343                    StringBundler msg = new StringBundler(4);
344    
345                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
346    
347                    msg.append("portletId=");
348                    msg.append(portletId);
349    
350                    msg.append(StringPool.CLOSE_CURLY_BRACE);
351    
352                    throw new NoSuchContentSearchException(msg.toString());
353            }
354    
355            /**
356             * Returns the last journal content search in the ordered set where portletId = &#63;.
357             *
358             * @param portletId the portlet ID
359             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
360             * @return the last matching journal content search, or <code>null</code> if a matching journal content search could not be found
361             * @throws SystemException if a system exception occurred
362             */
363            @Override
364            public JournalContentSearch fetchByPortletId_Last(String portletId,
365                    OrderByComparator orderByComparator) throws SystemException {
366                    int count = countByPortletId(portletId);
367    
368                    if (count == 0) {
369                            return null;
370                    }
371    
372                    List<JournalContentSearch> list = findByPortletId(portletId, count - 1,
373                                    count, orderByComparator);
374    
375                    if (!list.isEmpty()) {
376                            return list.get(0);
377                    }
378    
379                    return null;
380            }
381    
382            /**
383             * Returns the journal content searchs before and after the current journal content search in the ordered set where portletId = &#63;.
384             *
385             * @param contentSearchId the primary key of the current journal content search
386             * @param portletId the portlet ID
387             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
388             * @return the previous, current, and next journal content search
389             * @throws com.liferay.portlet.journal.NoSuchContentSearchException if a journal content search with the primary key could not be found
390             * @throws SystemException if a system exception occurred
391             */
392            @Override
393            public JournalContentSearch[] findByPortletId_PrevAndNext(
394                    long contentSearchId, String portletId,
395                    OrderByComparator orderByComparator)
396                    throws NoSuchContentSearchException, SystemException {
397                    JournalContentSearch journalContentSearch = findByPrimaryKey(contentSearchId);
398    
399                    Session session = null;
400    
401                    try {
402                            session = openSession();
403    
404                            JournalContentSearch[] array = new JournalContentSearchImpl[3];
405    
406                            array[0] = getByPortletId_PrevAndNext(session,
407                                            journalContentSearch, portletId, orderByComparator, true);
408    
409                            array[1] = journalContentSearch;
410    
411                            array[2] = getByPortletId_PrevAndNext(session,
412                                            journalContentSearch, portletId, orderByComparator, false);
413    
414                            return array;
415                    }
416                    catch (Exception e) {
417                            throw processException(e);
418                    }
419                    finally {
420                            closeSession(session);
421                    }
422            }
423    
424            protected JournalContentSearch getByPortletId_PrevAndNext(Session session,
425                    JournalContentSearch journalContentSearch, String portletId,
426                    OrderByComparator orderByComparator, boolean previous) {
427                    StringBundler query = null;
428    
429                    if (orderByComparator != null) {
430                            query = new StringBundler(6 +
431                                            (orderByComparator.getOrderByFields().length * 6));
432                    }
433                    else {
434                            query = new StringBundler(3);
435                    }
436    
437                    query.append(_SQL_SELECT_JOURNALCONTENTSEARCH_WHERE);
438    
439                    boolean bindPortletId = false;
440    
441                    if (portletId == null) {
442                            query.append(_FINDER_COLUMN_PORTLETID_PORTLETID_1);
443                    }
444                    else if (portletId.equals(StringPool.BLANK)) {
445                            query.append(_FINDER_COLUMN_PORTLETID_PORTLETID_3);
446                    }
447                    else {
448                            bindPortletId = true;
449    
450                            query.append(_FINDER_COLUMN_PORTLETID_PORTLETID_2);
451                    }
452    
453                    if (orderByComparator != null) {
454                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
455    
456                            if (orderByConditionFields.length > 0) {
457                                    query.append(WHERE_AND);
458                            }
459    
460                            for (int i = 0; i < orderByConditionFields.length; i++) {
461                                    query.append(_ORDER_BY_ENTITY_ALIAS);
462                                    query.append(orderByConditionFields[i]);
463    
464                                    if ((i + 1) < orderByConditionFields.length) {
465                                            if (orderByComparator.isAscending() ^ previous) {
466                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
467                                            }
468                                            else {
469                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
470                                            }
471                                    }
472                                    else {
473                                            if (orderByComparator.isAscending() ^ previous) {
474                                                    query.append(WHERE_GREATER_THAN);
475                                            }
476                                            else {
477                                                    query.append(WHERE_LESSER_THAN);
478                                            }
479                                    }
480                            }
481    
482                            query.append(ORDER_BY_CLAUSE);
483    
484                            String[] orderByFields = orderByComparator.getOrderByFields();
485    
486                            for (int i = 0; i < orderByFields.length; i++) {
487                                    query.append(_ORDER_BY_ENTITY_ALIAS);
488                                    query.append(orderByFields[i]);
489    
490                                    if ((i + 1) < orderByFields.length) {
491                                            if (orderByComparator.isAscending() ^ previous) {
492                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
493                                            }
494                                            else {
495                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
496                                            }
497                                    }
498                                    else {
499                                            if (orderByComparator.isAscending() ^ previous) {
500                                                    query.append(ORDER_BY_ASC);
501                                            }
502                                            else {
503                                                    query.append(ORDER_BY_DESC);
504                                            }
505                                    }
506                            }
507                    }
508                    else {
509                            query.append(JournalContentSearchModelImpl.ORDER_BY_JPQL);
510                    }
511    
512                    String sql = query.toString();
513    
514                    Query q = session.createQuery(sql);
515    
516                    q.setFirstResult(0);
517                    q.setMaxResults(2);
518    
519                    QueryPos qPos = QueryPos.getInstance(q);
520    
521                    if (bindPortletId) {
522                            qPos.add(portletId);
523                    }
524    
525                    if (orderByComparator != null) {
526                            Object[] values = orderByComparator.getOrderByConditionValues(journalContentSearch);
527    
528                            for (Object value : values) {
529                                    qPos.add(value);
530                            }
531                    }
532    
533                    List<JournalContentSearch> list = q.list();
534    
535                    if (list.size() == 2) {
536                            return list.get(1);
537                    }
538                    else {
539                            return null;
540                    }
541            }
542    
543            /**
544             * Removes all the journal content searchs where portletId = &#63; from the database.
545             *
546             * @param portletId the portlet ID
547             * @throws SystemException if a system exception occurred
548             */
549            @Override
550            public void removeByPortletId(String portletId) throws SystemException {
551                    for (JournalContentSearch journalContentSearch : findByPortletId(
552                                    portletId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
553                            remove(journalContentSearch);
554                    }
555            }
556    
557            /**
558             * Returns the number of journal content searchs where portletId = &#63;.
559             *
560             * @param portletId the portlet ID
561             * @return the number of matching journal content searchs
562             * @throws SystemException if a system exception occurred
563             */
564            @Override
565            public int countByPortletId(String portletId) throws SystemException {
566                    FinderPath finderPath = FINDER_PATH_COUNT_BY_PORTLETID;
567    
568                    Object[] finderArgs = new Object[] { portletId };
569    
570                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
571                                    this);
572    
573                    if (count == null) {
574                            StringBundler query = new StringBundler(2);
575    
576                            query.append(_SQL_COUNT_JOURNALCONTENTSEARCH_WHERE);
577    
578                            boolean bindPortletId = false;
579    
580                            if (portletId == null) {
581                                    query.append(_FINDER_COLUMN_PORTLETID_PORTLETID_1);
582                            }
583                            else if (portletId.equals(StringPool.BLANK)) {
584                                    query.append(_FINDER_COLUMN_PORTLETID_PORTLETID_3);
585                            }
586                            else {
587                                    bindPortletId = true;
588    
589                                    query.append(_FINDER_COLUMN_PORTLETID_PORTLETID_2);
590                            }
591    
592                            String sql = query.toString();
593    
594                            Session session = null;
595    
596                            try {
597                                    session = openSession();
598    
599                                    Query q = session.createQuery(sql);
600    
601                                    QueryPos qPos = QueryPos.getInstance(q);
602    
603                                    if (bindPortletId) {
604                                            qPos.add(portletId);
605                                    }
606    
607                                    count = (Long)q.uniqueResult();
608    
609                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
610                            }
611                            catch (Exception e) {
612                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
613    
614                                    throw processException(e);
615                            }
616                            finally {
617                                    closeSession(session);
618                            }
619                    }
620    
621                    return count.intValue();
622            }
623    
624            private static final String _FINDER_COLUMN_PORTLETID_PORTLETID_1 = "journalContentSearch.portletId IS NULL";
625            private static final String _FINDER_COLUMN_PORTLETID_PORTLETID_2 = "journalContentSearch.portletId = ?";
626            private static final String _FINDER_COLUMN_PORTLETID_PORTLETID_3 = "(journalContentSearch.portletId IS NULL OR journalContentSearch.portletId = '')";
627            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ARTICLEID =
628                    new FinderPath(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
629                            JournalContentSearchModelImpl.FINDER_CACHE_ENABLED,
630                            JournalContentSearchImpl.class,
631                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByArticleId",
632                            new String[] {
633                                    String.class.getName(),
634                                    
635                            Integer.class.getName(), Integer.class.getName(),
636                                    OrderByComparator.class.getName()
637                            });
638            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ARTICLEID =
639                    new FinderPath(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
640                            JournalContentSearchModelImpl.FINDER_CACHE_ENABLED,
641                            JournalContentSearchImpl.class,
642                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByArticleId",
643                            new String[] { String.class.getName() },
644                            JournalContentSearchModelImpl.ARTICLEID_COLUMN_BITMASK);
645            public static final FinderPath FINDER_PATH_COUNT_BY_ARTICLEID = new FinderPath(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
646                            JournalContentSearchModelImpl.FINDER_CACHE_ENABLED, Long.class,
647                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByArticleId",
648                            new String[] { String.class.getName() });
649    
650            /**
651             * Returns all the journal content searchs where articleId = &#63;.
652             *
653             * @param articleId the article ID
654             * @return the matching journal content searchs
655             * @throws SystemException if a system exception occurred
656             */
657            @Override
658            public List<JournalContentSearch> findByArticleId(String articleId)
659                    throws SystemException {
660                    return findByArticleId(articleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
661                            null);
662            }
663    
664            /**
665             * Returns a range of all the journal content searchs where articleId = &#63;.
666             *
667             * <p>
668             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalContentSearchModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
669             * </p>
670             *
671             * @param articleId the article ID
672             * @param start the lower bound of the range of journal content searchs
673             * @param end the upper bound of the range of journal content searchs (not inclusive)
674             * @return the range of matching journal content searchs
675             * @throws SystemException if a system exception occurred
676             */
677            @Override
678            public List<JournalContentSearch> findByArticleId(String articleId,
679                    int start, int end) throws SystemException {
680                    return findByArticleId(articleId, start, end, null);
681            }
682    
683            /**
684             * Returns an ordered range of all the journal content searchs where articleId = &#63;.
685             *
686             * <p>
687             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalContentSearchModelImpl}. 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.
688             * </p>
689             *
690             * @param articleId the article ID
691             * @param start the lower bound of the range of journal content searchs
692             * @param end the upper bound of the range of journal content searchs (not inclusive)
693             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
694             * @return the ordered range of matching journal content searchs
695             * @throws SystemException if a system exception occurred
696             */
697            @Override
698            public List<JournalContentSearch> findByArticleId(String articleId,
699                    int start, int end, OrderByComparator orderByComparator)
700                    throws SystemException {
701                    boolean pagination = true;
702                    FinderPath finderPath = null;
703                    Object[] finderArgs = null;
704    
705                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
706                                    (orderByComparator == null)) {
707                            pagination = false;
708                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ARTICLEID;
709                            finderArgs = new Object[] { articleId };
710                    }
711                    else {
712                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ARTICLEID;
713                            finderArgs = new Object[] { articleId, start, end, orderByComparator };
714                    }
715    
716                    List<JournalContentSearch> list = (List<JournalContentSearch>)FinderCacheUtil.getResult(finderPath,
717                                    finderArgs, this);
718    
719                    if ((list != null) && !list.isEmpty()) {
720                            for (JournalContentSearch journalContentSearch : list) {
721                                    if (!Validator.equals(articleId,
722                                                            journalContentSearch.getArticleId())) {
723                                            list = null;
724    
725                                            break;
726                                    }
727                            }
728                    }
729    
730                    if (list == null) {
731                            StringBundler query = null;
732    
733                            if (orderByComparator != null) {
734                                    query = new StringBundler(3 +
735                                                    (orderByComparator.getOrderByFields().length * 3));
736                            }
737                            else {
738                                    query = new StringBundler(3);
739                            }
740    
741                            query.append(_SQL_SELECT_JOURNALCONTENTSEARCH_WHERE);
742    
743                            boolean bindArticleId = false;
744    
745                            if (articleId == null) {
746                                    query.append(_FINDER_COLUMN_ARTICLEID_ARTICLEID_1);
747                            }
748                            else if (articleId.equals(StringPool.BLANK)) {
749                                    query.append(_FINDER_COLUMN_ARTICLEID_ARTICLEID_3);
750                            }
751                            else {
752                                    bindArticleId = true;
753    
754                                    query.append(_FINDER_COLUMN_ARTICLEID_ARTICLEID_2);
755                            }
756    
757                            if (orderByComparator != null) {
758                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
759                                            orderByComparator);
760                            }
761                            else
762                             if (pagination) {
763                                    query.append(JournalContentSearchModelImpl.ORDER_BY_JPQL);
764                            }
765    
766                            String sql = query.toString();
767    
768                            Session session = null;
769    
770                            try {
771                                    session = openSession();
772    
773                                    Query q = session.createQuery(sql);
774    
775                                    QueryPos qPos = QueryPos.getInstance(q);
776    
777                                    if (bindArticleId) {
778                                            qPos.add(articleId);
779                                    }
780    
781                                    if (!pagination) {
782                                            list = (List<JournalContentSearch>)QueryUtil.list(q,
783                                                            getDialect(), start, end, false);
784    
785                                            Collections.sort(list);
786    
787                                            list = new UnmodifiableList<JournalContentSearch>(list);
788                                    }
789                                    else {
790                                            list = (List<JournalContentSearch>)QueryUtil.list(q,
791                                                            getDialect(), start, end);
792                                    }
793    
794                                    cacheResult(list);
795    
796                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
797                            }
798                            catch (Exception e) {
799                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
800    
801                                    throw processException(e);
802                            }
803                            finally {
804                                    closeSession(session);
805                            }
806                    }
807    
808                    return list;
809            }
810    
811            /**
812             * Returns the first journal content search in the ordered set where articleId = &#63;.
813             *
814             * @param articleId the article ID
815             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
816             * @return the first matching journal content search
817             * @throws com.liferay.portlet.journal.NoSuchContentSearchException if a matching journal content search could not be found
818             * @throws SystemException if a system exception occurred
819             */
820            @Override
821            public JournalContentSearch findByArticleId_First(String articleId,
822                    OrderByComparator orderByComparator)
823                    throws NoSuchContentSearchException, SystemException {
824                    JournalContentSearch journalContentSearch = fetchByArticleId_First(articleId,
825                                    orderByComparator);
826    
827                    if (journalContentSearch != null) {
828                            return journalContentSearch;
829                    }
830    
831                    StringBundler msg = new StringBundler(4);
832    
833                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
834    
835                    msg.append("articleId=");
836                    msg.append(articleId);
837    
838                    msg.append(StringPool.CLOSE_CURLY_BRACE);
839    
840                    throw new NoSuchContentSearchException(msg.toString());
841            }
842    
843            /**
844             * Returns the first journal content search in the ordered set where articleId = &#63;.
845             *
846             * @param articleId the article ID
847             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
848             * @return the first matching journal content search, or <code>null</code> if a matching journal content search could not be found
849             * @throws SystemException if a system exception occurred
850             */
851            @Override
852            public JournalContentSearch fetchByArticleId_First(String articleId,
853                    OrderByComparator orderByComparator) throws SystemException {
854                    List<JournalContentSearch> list = findByArticleId(articleId, 0, 1,
855                                    orderByComparator);
856    
857                    if (!list.isEmpty()) {
858                            return list.get(0);
859                    }
860    
861                    return null;
862            }
863    
864            /**
865             * Returns the last journal content search in the ordered set where articleId = &#63;.
866             *
867             * @param articleId the article ID
868             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
869             * @return the last matching journal content search
870             * @throws com.liferay.portlet.journal.NoSuchContentSearchException if a matching journal content search could not be found
871             * @throws SystemException if a system exception occurred
872             */
873            @Override
874            public JournalContentSearch findByArticleId_Last(String articleId,
875                    OrderByComparator orderByComparator)
876                    throws NoSuchContentSearchException, SystemException {
877                    JournalContentSearch journalContentSearch = fetchByArticleId_Last(articleId,
878                                    orderByComparator);
879    
880                    if (journalContentSearch != null) {
881                            return journalContentSearch;
882                    }
883    
884                    StringBundler msg = new StringBundler(4);
885    
886                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
887    
888                    msg.append("articleId=");
889                    msg.append(articleId);
890    
891                    msg.append(StringPool.CLOSE_CURLY_BRACE);
892    
893                    throw new NoSuchContentSearchException(msg.toString());
894            }
895    
896            /**
897             * Returns the last journal content search in the ordered set where articleId = &#63;.
898             *
899             * @param articleId the article ID
900             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
901             * @return the last matching journal content search, or <code>null</code> if a matching journal content search could not be found
902             * @throws SystemException if a system exception occurred
903             */
904            @Override
905            public JournalContentSearch fetchByArticleId_Last(String articleId,
906                    OrderByComparator orderByComparator) throws SystemException {
907                    int count = countByArticleId(articleId);
908    
909                    if (count == 0) {
910                            return null;
911                    }
912    
913                    List<JournalContentSearch> list = findByArticleId(articleId, count - 1,
914                                    count, orderByComparator);
915    
916                    if (!list.isEmpty()) {
917                            return list.get(0);
918                    }
919    
920                    return null;
921            }
922    
923            /**
924             * Returns the journal content searchs before and after the current journal content search in the ordered set where articleId = &#63;.
925             *
926             * @param contentSearchId the primary key of the current journal content search
927             * @param articleId the article ID
928             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
929             * @return the previous, current, and next journal content search
930             * @throws com.liferay.portlet.journal.NoSuchContentSearchException if a journal content search with the primary key could not be found
931             * @throws SystemException if a system exception occurred
932             */
933            @Override
934            public JournalContentSearch[] findByArticleId_PrevAndNext(
935                    long contentSearchId, String articleId,
936                    OrderByComparator orderByComparator)
937                    throws NoSuchContentSearchException, SystemException {
938                    JournalContentSearch journalContentSearch = findByPrimaryKey(contentSearchId);
939    
940                    Session session = null;
941    
942                    try {
943                            session = openSession();
944    
945                            JournalContentSearch[] array = new JournalContentSearchImpl[3];
946    
947                            array[0] = getByArticleId_PrevAndNext(session,
948                                            journalContentSearch, articleId, orderByComparator, true);
949    
950                            array[1] = journalContentSearch;
951    
952                            array[2] = getByArticleId_PrevAndNext(session,
953                                            journalContentSearch, articleId, orderByComparator, false);
954    
955                            return array;
956                    }
957                    catch (Exception e) {
958                            throw processException(e);
959                    }
960                    finally {
961                            closeSession(session);
962                    }
963            }
964    
965            protected JournalContentSearch getByArticleId_PrevAndNext(Session session,
966                    JournalContentSearch journalContentSearch, String articleId,
967                    OrderByComparator orderByComparator, boolean previous) {
968                    StringBundler query = null;
969    
970                    if (orderByComparator != null) {
971                            query = new StringBundler(6 +
972                                            (orderByComparator.getOrderByFields().length * 6));
973                    }
974                    else {
975                            query = new StringBundler(3);
976                    }
977    
978                    query.append(_SQL_SELECT_JOURNALCONTENTSEARCH_WHERE);
979    
980                    boolean bindArticleId = false;
981    
982                    if (articleId == null) {
983                            query.append(_FINDER_COLUMN_ARTICLEID_ARTICLEID_1);
984                    }
985                    else if (articleId.equals(StringPool.BLANK)) {
986                            query.append(_FINDER_COLUMN_ARTICLEID_ARTICLEID_3);
987                    }
988                    else {
989                            bindArticleId = true;
990    
991                            query.append(_FINDER_COLUMN_ARTICLEID_ARTICLEID_2);
992                    }
993    
994                    if (orderByComparator != null) {
995                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
996    
997                            if (orderByConditionFields.length > 0) {
998                                    query.append(WHERE_AND);
999                            }
1000    
1001                            for (int i = 0; i < orderByConditionFields.length; i++) {
1002                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1003                                    query.append(orderByConditionFields[i]);
1004    
1005                                    if ((i + 1) < orderByConditionFields.length) {
1006                                            if (orderByComparator.isAscending() ^ previous) {
1007                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1008                                            }
1009                                            else {
1010                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1011                                            }
1012                                    }
1013                                    else {
1014                                            if (orderByComparator.isAscending() ^ previous) {
1015                                                    query.append(WHERE_GREATER_THAN);
1016                                            }
1017                                            else {
1018                                                    query.append(WHERE_LESSER_THAN);
1019                                            }
1020                                    }
1021                            }
1022    
1023                            query.append(ORDER_BY_CLAUSE);
1024    
1025                            String[] orderByFields = orderByComparator.getOrderByFields();
1026    
1027                            for (int i = 0; i < orderByFields.length; i++) {
1028                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1029                                    query.append(orderByFields[i]);
1030    
1031                                    if ((i + 1) < orderByFields.length) {
1032                                            if (orderByComparator.isAscending() ^ previous) {
1033                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1034                                            }
1035                                            else {
1036                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1037                                            }
1038                                    }
1039                                    else {
1040                                            if (orderByComparator.isAscending() ^ previous) {
1041                                                    query.append(ORDER_BY_ASC);
1042                                            }
1043                                            else {
1044                                                    query.append(ORDER_BY_DESC);
1045                                            }
1046                                    }
1047                            }
1048                    }
1049                    else {
1050                            query.append(JournalContentSearchModelImpl.ORDER_BY_JPQL);
1051                    }
1052    
1053                    String sql = query.toString();
1054    
1055                    Query q = session.createQuery(sql);
1056    
1057                    q.setFirstResult(0);
1058                    q.setMaxResults(2);
1059    
1060                    QueryPos qPos = QueryPos.getInstance(q);
1061    
1062                    if (bindArticleId) {
1063                            qPos.add(articleId);
1064                    }
1065    
1066                    if (orderByComparator != null) {
1067                            Object[] values = orderByComparator.getOrderByConditionValues(journalContentSearch);
1068    
1069                            for (Object value : values) {
1070                                    qPos.add(value);
1071                            }
1072                    }
1073    
1074                    List<JournalContentSearch> list = q.list();
1075    
1076                    if (list.size() == 2) {
1077                            return list.get(1);
1078                    }
1079                    else {
1080                            return null;
1081                    }
1082            }
1083    
1084            /**
1085             * Removes all the journal content searchs where articleId = &#63; from the database.
1086             *
1087             * @param articleId the article ID
1088             * @throws SystemException if a system exception occurred
1089             */
1090            @Override
1091            public void removeByArticleId(String articleId) throws SystemException {
1092                    for (JournalContentSearch journalContentSearch : findByArticleId(
1093                                    articleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1094                            remove(journalContentSearch);
1095                    }
1096            }
1097    
1098            /**
1099             * Returns the number of journal content searchs where articleId = &#63;.
1100             *
1101             * @param articleId the article ID
1102             * @return the number of matching journal content searchs
1103             * @throws SystemException if a system exception occurred
1104             */
1105            @Override
1106            public int countByArticleId(String articleId) throws SystemException {
1107                    FinderPath finderPath = FINDER_PATH_COUNT_BY_ARTICLEID;
1108    
1109                    Object[] finderArgs = new Object[] { articleId };
1110    
1111                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1112                                    this);
1113    
1114                    if (count == null) {
1115                            StringBundler query = new StringBundler(2);
1116    
1117                            query.append(_SQL_COUNT_JOURNALCONTENTSEARCH_WHERE);
1118    
1119                            boolean bindArticleId = false;
1120    
1121                            if (articleId == null) {
1122                                    query.append(_FINDER_COLUMN_ARTICLEID_ARTICLEID_1);
1123                            }
1124                            else if (articleId.equals(StringPool.BLANK)) {
1125                                    query.append(_FINDER_COLUMN_ARTICLEID_ARTICLEID_3);
1126                            }
1127                            else {
1128                                    bindArticleId = true;
1129    
1130                                    query.append(_FINDER_COLUMN_ARTICLEID_ARTICLEID_2);
1131                            }
1132    
1133                            String sql = query.toString();
1134    
1135                            Session session = null;
1136    
1137                            try {
1138                                    session = openSession();
1139    
1140                                    Query q = session.createQuery(sql);
1141    
1142                                    QueryPos qPos = QueryPos.getInstance(q);
1143    
1144                                    if (bindArticleId) {
1145                                            qPos.add(articleId);
1146                                    }
1147    
1148                                    count = (Long)q.uniqueResult();
1149    
1150                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1151                            }
1152                            catch (Exception e) {
1153                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1154    
1155                                    throw processException(e);
1156                            }
1157                            finally {
1158                                    closeSession(session);
1159                            }
1160                    }
1161    
1162                    return count.intValue();
1163            }
1164    
1165            private static final String _FINDER_COLUMN_ARTICLEID_ARTICLEID_1 = "journalContentSearch.articleId IS NULL";
1166            private static final String _FINDER_COLUMN_ARTICLEID_ARTICLEID_2 = "journalContentSearch.articleId = ?";
1167            private static final String _FINDER_COLUMN_ARTICLEID_ARTICLEID_3 = "(journalContentSearch.articleId IS NULL OR journalContentSearch.articleId = '')";
1168            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P = new FinderPath(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
1169                            JournalContentSearchModelImpl.FINDER_CACHE_ENABLED,
1170                            JournalContentSearchImpl.class,
1171                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P",
1172                            new String[] {
1173                                    Long.class.getName(), Boolean.class.getName(),
1174                                    
1175                            Integer.class.getName(), Integer.class.getName(),
1176                                    OrderByComparator.class.getName()
1177                            });
1178            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P = new FinderPath(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
1179                            JournalContentSearchModelImpl.FINDER_CACHE_ENABLED,
1180                            JournalContentSearchImpl.class,
1181                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P",
1182                            new String[] { Long.class.getName(), Boolean.class.getName() },
1183                            JournalContentSearchModelImpl.GROUPID_COLUMN_BITMASK |
1184                            JournalContentSearchModelImpl.PRIVATELAYOUT_COLUMN_BITMASK);
1185            public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
1186                            JournalContentSearchModelImpl.FINDER_CACHE_ENABLED, Long.class,
1187                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P",
1188                            new String[] { Long.class.getName(), Boolean.class.getName() });
1189    
1190            /**
1191             * Returns all the journal content searchs where groupId = &#63; and privateLayout = &#63;.
1192             *
1193             * @param groupId the group ID
1194             * @param privateLayout the private layout
1195             * @return the matching journal content searchs
1196             * @throws SystemException if a system exception occurred
1197             */
1198            @Override
1199            public List<JournalContentSearch> findByG_P(long groupId,
1200                    boolean privateLayout) throws SystemException {
1201                    return findByG_P(groupId, privateLayout, QueryUtil.ALL_POS,
1202                            QueryUtil.ALL_POS, null);
1203            }
1204    
1205            /**
1206             * Returns a range of all the journal content searchs where groupId = &#63; and privateLayout = &#63;.
1207             *
1208             * <p>
1209             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalContentSearchModelImpl}. 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.
1210             * </p>
1211             *
1212             * @param groupId the group ID
1213             * @param privateLayout the private layout
1214             * @param start the lower bound of the range of journal content searchs
1215             * @param end the upper bound of the range of journal content searchs (not inclusive)
1216             * @return the range of matching journal content searchs
1217             * @throws SystemException if a system exception occurred
1218             */
1219            @Override
1220            public List<JournalContentSearch> findByG_P(long groupId,
1221                    boolean privateLayout, int start, int end) throws SystemException {
1222                    return findByG_P(groupId, privateLayout, start, end, null);
1223            }
1224    
1225            /**
1226             * Returns an ordered range of all the journal content searchs where groupId = &#63; and privateLayout = &#63;.
1227             *
1228             * <p>
1229             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalContentSearchModelImpl}. 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.
1230             * </p>
1231             *
1232             * @param groupId the group ID
1233             * @param privateLayout the private layout
1234             * @param start the lower bound of the range of journal content searchs
1235             * @param end the upper bound of the range of journal content searchs (not inclusive)
1236             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1237             * @return the ordered range of matching journal content searchs
1238             * @throws SystemException if a system exception occurred
1239             */
1240            @Override
1241            public List<JournalContentSearch> findByG_P(long groupId,
1242                    boolean privateLayout, int start, int end,
1243                    OrderByComparator orderByComparator) throws SystemException {
1244                    boolean pagination = true;
1245                    FinderPath finderPath = null;
1246                    Object[] finderArgs = null;
1247    
1248                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1249                                    (orderByComparator == null)) {
1250                            pagination = false;
1251                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P;
1252                            finderArgs = new Object[] { groupId, privateLayout };
1253                    }
1254                    else {
1255                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P;
1256                            finderArgs = new Object[] {
1257                                            groupId, privateLayout,
1258                                            
1259                                            start, end, orderByComparator
1260                                    };
1261                    }
1262    
1263                    List<JournalContentSearch> list = (List<JournalContentSearch>)FinderCacheUtil.getResult(finderPath,
1264                                    finderArgs, this);
1265    
1266                    if ((list != null) && !list.isEmpty()) {
1267                            for (JournalContentSearch journalContentSearch : list) {
1268                                    if ((groupId != journalContentSearch.getGroupId()) ||
1269                                                    (privateLayout != journalContentSearch.getPrivateLayout())) {
1270                                            list = null;
1271    
1272                                            break;
1273                                    }
1274                            }
1275                    }
1276    
1277                    if (list == null) {
1278                            StringBundler query = null;
1279    
1280                            if (orderByComparator != null) {
1281                                    query = new StringBundler(4 +
1282                                                    (orderByComparator.getOrderByFields().length * 3));
1283                            }
1284                            else {
1285                                    query = new StringBundler(4);
1286                            }
1287    
1288                            query.append(_SQL_SELECT_JOURNALCONTENTSEARCH_WHERE);
1289    
1290                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1291    
1292                            query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
1293    
1294                            if (orderByComparator != null) {
1295                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1296                                            orderByComparator);
1297                            }
1298                            else
1299                             if (pagination) {
1300                                    query.append(JournalContentSearchModelImpl.ORDER_BY_JPQL);
1301                            }
1302    
1303                            String sql = query.toString();
1304    
1305                            Session session = null;
1306    
1307                            try {
1308                                    session = openSession();
1309    
1310                                    Query q = session.createQuery(sql);
1311    
1312                                    QueryPos qPos = QueryPos.getInstance(q);
1313    
1314                                    qPos.add(groupId);
1315    
1316                                    qPos.add(privateLayout);
1317    
1318                                    if (!pagination) {
1319                                            list = (List<JournalContentSearch>)QueryUtil.list(q,
1320                                                            getDialect(), start, end, false);
1321    
1322                                            Collections.sort(list);
1323    
1324                                            list = new UnmodifiableList<JournalContentSearch>(list);
1325                                    }
1326                                    else {
1327                                            list = (List<JournalContentSearch>)QueryUtil.list(q,
1328                                                            getDialect(), start, end);
1329                                    }
1330    
1331                                    cacheResult(list);
1332    
1333                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1334                            }
1335                            catch (Exception e) {
1336                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1337    
1338                                    throw processException(e);
1339                            }
1340                            finally {
1341                                    closeSession(session);
1342                            }
1343                    }
1344    
1345                    return list;
1346            }
1347    
1348            /**
1349             * Returns the first journal content search in the ordered set where groupId = &#63; and privateLayout = &#63;.
1350             *
1351             * @param groupId the group ID
1352             * @param privateLayout the private layout
1353             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1354             * @return the first matching journal content search
1355             * @throws com.liferay.portlet.journal.NoSuchContentSearchException if a matching journal content search could not be found
1356             * @throws SystemException if a system exception occurred
1357             */
1358            @Override
1359            public JournalContentSearch findByG_P_First(long groupId,
1360                    boolean privateLayout, OrderByComparator orderByComparator)
1361                    throws NoSuchContentSearchException, SystemException {
1362                    JournalContentSearch journalContentSearch = fetchByG_P_First(groupId,
1363                                    privateLayout, orderByComparator);
1364    
1365                    if (journalContentSearch != null) {
1366                            return journalContentSearch;
1367                    }
1368    
1369                    StringBundler msg = new StringBundler(6);
1370    
1371                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1372    
1373                    msg.append("groupId=");
1374                    msg.append(groupId);
1375    
1376                    msg.append(", privateLayout=");
1377                    msg.append(privateLayout);
1378    
1379                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1380    
1381                    throw new NoSuchContentSearchException(msg.toString());
1382            }
1383    
1384            /**
1385             * Returns the first journal content search in the ordered set where groupId = &#63; and privateLayout = &#63;.
1386             *
1387             * @param groupId the group ID
1388             * @param privateLayout the private layout
1389             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1390             * @return the first matching journal content search, or <code>null</code> if a matching journal content search could not be found
1391             * @throws SystemException if a system exception occurred
1392             */
1393            @Override
1394            public JournalContentSearch fetchByG_P_First(long groupId,
1395                    boolean privateLayout, OrderByComparator orderByComparator)
1396                    throws SystemException {
1397                    List<JournalContentSearch> list = findByG_P(groupId, privateLayout, 0,
1398                                    1, orderByComparator);
1399    
1400                    if (!list.isEmpty()) {
1401                            return list.get(0);
1402                    }
1403    
1404                    return null;
1405            }
1406    
1407            /**
1408             * Returns the last journal content search in the ordered set where groupId = &#63; and privateLayout = &#63;.
1409             *
1410             * @param groupId the group ID
1411             * @param privateLayout the private layout
1412             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1413             * @return the last matching journal content search
1414             * @throws com.liferay.portlet.journal.NoSuchContentSearchException if a matching journal content search could not be found
1415             * @throws SystemException if a system exception occurred
1416             */
1417            @Override
1418            public JournalContentSearch findByG_P_Last(long groupId,
1419                    boolean privateLayout, OrderByComparator orderByComparator)
1420                    throws NoSuchContentSearchException, SystemException {
1421                    JournalContentSearch journalContentSearch = fetchByG_P_Last(groupId,
1422                                    privateLayout, orderByComparator);
1423    
1424                    if (journalContentSearch != null) {
1425                            return journalContentSearch;
1426                    }
1427    
1428                    StringBundler msg = new StringBundler(6);
1429    
1430                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1431    
1432                    msg.append("groupId=");
1433                    msg.append(groupId);
1434    
1435                    msg.append(", privateLayout=");
1436                    msg.append(privateLayout);
1437    
1438                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1439    
1440                    throw new NoSuchContentSearchException(msg.toString());
1441            }
1442    
1443            /**
1444             * Returns the last journal content search in the ordered set where groupId = &#63; and privateLayout = &#63;.
1445             *
1446             * @param groupId the group ID
1447             * @param privateLayout the private layout
1448             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1449             * @return the last matching journal content search, or <code>null</code> if a matching journal content search could not be found
1450             * @throws SystemException if a system exception occurred
1451             */
1452            @Override
1453            public JournalContentSearch fetchByG_P_Last(long groupId,
1454                    boolean privateLayout, OrderByComparator orderByComparator)
1455                    throws SystemException {
1456                    int count = countByG_P(groupId, privateLayout);
1457    
1458                    if (count == 0) {
1459                            return null;
1460                    }
1461    
1462                    List<JournalContentSearch> list = findByG_P(groupId, privateLayout,
1463                                    count - 1, count, orderByComparator);
1464    
1465                    if (!list.isEmpty()) {
1466                            return list.get(0);
1467                    }
1468    
1469                    return null;
1470            }
1471    
1472            /**
1473             * Returns the journal content searchs before and after the current journal content search in the ordered set where groupId = &#63; and privateLayout = &#63;.
1474             *
1475             * @param contentSearchId the primary key of the current journal content search
1476             * @param groupId the group ID
1477             * @param privateLayout the private layout
1478             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1479             * @return the previous, current, and next journal content search
1480             * @throws com.liferay.portlet.journal.NoSuchContentSearchException if a journal content search with the primary key could not be found
1481             * @throws SystemException if a system exception occurred
1482             */
1483            @Override
1484            public JournalContentSearch[] findByG_P_PrevAndNext(long contentSearchId,
1485                    long groupId, boolean privateLayout, OrderByComparator orderByComparator)
1486                    throws NoSuchContentSearchException, SystemException {
1487                    JournalContentSearch journalContentSearch = findByPrimaryKey(contentSearchId);
1488    
1489                    Session session = null;
1490    
1491                    try {
1492                            session = openSession();
1493    
1494                            JournalContentSearch[] array = new JournalContentSearchImpl[3];
1495    
1496                            array[0] = getByG_P_PrevAndNext(session, journalContentSearch,
1497                                            groupId, privateLayout, orderByComparator, true);
1498    
1499                            array[1] = journalContentSearch;
1500    
1501                            array[2] = getByG_P_PrevAndNext(session, journalContentSearch,
1502                                            groupId, privateLayout, orderByComparator, false);
1503    
1504                            return array;
1505                    }
1506                    catch (Exception e) {
1507                            throw processException(e);
1508                    }
1509                    finally {
1510                            closeSession(session);
1511                    }
1512            }
1513    
1514            protected JournalContentSearch getByG_P_PrevAndNext(Session session,
1515                    JournalContentSearch journalContentSearch, long groupId,
1516                    boolean privateLayout, OrderByComparator orderByComparator,
1517                    boolean previous) {
1518                    StringBundler query = null;
1519    
1520                    if (orderByComparator != null) {
1521                            query = new StringBundler(6 +
1522                                            (orderByComparator.getOrderByFields().length * 6));
1523                    }
1524                    else {
1525                            query = new StringBundler(3);
1526                    }
1527    
1528                    query.append(_SQL_SELECT_JOURNALCONTENTSEARCH_WHERE);
1529    
1530                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1531    
1532                    query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
1533    
1534                    if (orderByComparator != null) {
1535                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1536    
1537                            if (orderByConditionFields.length > 0) {
1538                                    query.append(WHERE_AND);
1539                            }
1540    
1541                            for (int i = 0; i < orderByConditionFields.length; i++) {
1542                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1543                                    query.append(orderByConditionFields[i]);
1544    
1545                                    if ((i + 1) < orderByConditionFields.length) {
1546                                            if (orderByComparator.isAscending() ^ previous) {
1547                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1548                                            }
1549                                            else {
1550                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1551                                            }
1552                                    }
1553                                    else {
1554                                            if (orderByComparator.isAscending() ^ previous) {
1555                                                    query.append(WHERE_GREATER_THAN);
1556                                            }
1557                                            else {
1558                                                    query.append(WHERE_LESSER_THAN);
1559                                            }
1560                                    }
1561                            }
1562    
1563                            query.append(ORDER_BY_CLAUSE);
1564    
1565                            String[] orderByFields = orderByComparator.getOrderByFields();
1566    
1567                            for (int i = 0; i < orderByFields.length; i++) {
1568                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1569                                    query.append(orderByFields[i]);
1570    
1571                                    if ((i + 1) < orderByFields.length) {
1572                                            if (orderByComparator.isAscending() ^ previous) {
1573                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1574                                            }
1575                                            else {
1576                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1577                                            }
1578                                    }
1579                                    else {
1580                                            if (orderByComparator.isAscending() ^ previous) {
1581                                                    query.append(ORDER_BY_ASC);
1582                                            }
1583                                            else {
1584                                                    query.append(ORDER_BY_DESC);
1585                                            }
1586                                    }
1587                            }
1588                    }
1589                    else {
1590                            query.append(JournalContentSearchModelImpl.ORDER_BY_JPQL);
1591                    }
1592    
1593                    String sql = query.toString();
1594    
1595                    Query q = session.createQuery(sql);
1596    
1597                    q.setFirstResult(0);
1598                    q.setMaxResults(2);
1599    
1600                    QueryPos qPos = QueryPos.getInstance(q);
1601    
1602                    qPos.add(groupId);
1603    
1604                    qPos.add(privateLayout);
1605    
1606                    if (orderByComparator != null) {
1607                            Object[] values = orderByComparator.getOrderByConditionValues(journalContentSearch);
1608    
1609                            for (Object value : values) {
1610                                    qPos.add(value);
1611                            }
1612                    }
1613    
1614                    List<JournalContentSearch> list = q.list();
1615    
1616                    if (list.size() == 2) {
1617                            return list.get(1);
1618                    }
1619                    else {
1620                            return null;
1621                    }
1622            }
1623    
1624            /**
1625             * Removes all the journal content searchs where groupId = &#63; and privateLayout = &#63; from the database.
1626             *
1627             * @param groupId the group ID
1628             * @param privateLayout the private layout
1629             * @throws SystemException if a system exception occurred
1630             */
1631            @Override
1632            public void removeByG_P(long groupId, boolean privateLayout)
1633                    throws SystemException {
1634                    for (JournalContentSearch journalContentSearch : findByG_P(groupId,
1635                                    privateLayout, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1636                            remove(journalContentSearch);
1637                    }
1638            }
1639    
1640            /**
1641             * Returns the number of journal content searchs where groupId = &#63; and privateLayout = &#63;.
1642             *
1643             * @param groupId the group ID
1644             * @param privateLayout the private layout
1645             * @return the number of matching journal content searchs
1646             * @throws SystemException if a system exception occurred
1647             */
1648            @Override
1649            public int countByG_P(long groupId, boolean privateLayout)
1650                    throws SystemException {
1651                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P;
1652    
1653                    Object[] finderArgs = new Object[] { groupId, privateLayout };
1654    
1655                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1656                                    this);
1657    
1658                    if (count == null) {
1659                            StringBundler query = new StringBundler(3);
1660    
1661                            query.append(_SQL_COUNT_JOURNALCONTENTSEARCH_WHERE);
1662    
1663                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1664    
1665                            query.append(_FINDER_COLUMN_G_P_PRIVATELAYOUT_2);
1666    
1667                            String sql = query.toString();
1668    
1669                            Session session = null;
1670    
1671                            try {
1672                                    session = openSession();
1673    
1674                                    Query q = session.createQuery(sql);
1675    
1676                                    QueryPos qPos = QueryPos.getInstance(q);
1677    
1678                                    qPos.add(groupId);
1679    
1680                                    qPos.add(privateLayout);
1681    
1682                                    count = (Long)q.uniqueResult();
1683    
1684                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1685                            }
1686                            catch (Exception e) {
1687                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1688    
1689                                    throw processException(e);
1690                            }
1691                            finally {
1692                                    closeSession(session);
1693                            }
1694                    }
1695    
1696                    return count.intValue();
1697            }
1698    
1699            private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "journalContentSearch.groupId = ? AND ";
1700            private static final String _FINDER_COLUMN_G_P_PRIVATELAYOUT_2 = "journalContentSearch.privateLayout = ?";
1701            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_A = new FinderPath(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
1702                            JournalContentSearchModelImpl.FINDER_CACHE_ENABLED,
1703                            JournalContentSearchImpl.class,
1704                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_A",
1705                            new String[] {
1706                                    Long.class.getName(), String.class.getName(),
1707                                    
1708                            Integer.class.getName(), Integer.class.getName(),
1709                                    OrderByComparator.class.getName()
1710                            });
1711            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A = new FinderPath(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
1712                            JournalContentSearchModelImpl.FINDER_CACHE_ENABLED,
1713                            JournalContentSearchImpl.class,
1714                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_A",
1715                            new String[] { Long.class.getName(), String.class.getName() },
1716                            JournalContentSearchModelImpl.GROUPID_COLUMN_BITMASK |
1717                            JournalContentSearchModelImpl.ARTICLEID_COLUMN_BITMASK);
1718            public static final FinderPath FINDER_PATH_COUNT_BY_G_A = new FinderPath(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
1719                            JournalContentSearchModelImpl.FINDER_CACHE_ENABLED, Long.class,
1720                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_A",
1721                            new String[] { Long.class.getName(), String.class.getName() });
1722    
1723            /**
1724             * Returns all the journal content searchs where groupId = &#63; and articleId = &#63;.
1725             *
1726             * @param groupId the group ID
1727             * @param articleId the article ID
1728             * @return the matching journal content searchs
1729             * @throws SystemException if a system exception occurred
1730             */
1731            @Override
1732            public List<JournalContentSearch> findByG_A(long groupId, String articleId)
1733                    throws SystemException {
1734                    return findByG_A(groupId, articleId, QueryUtil.ALL_POS,
1735                            QueryUtil.ALL_POS, null);
1736            }
1737    
1738            /**
1739             * Returns a range of all the journal content searchs where groupId = &#63; and articleId = &#63;.
1740             *
1741             * <p>
1742             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalContentSearchModelImpl}. 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.
1743             * </p>
1744             *
1745             * @param groupId the group ID
1746             * @param articleId the article ID
1747             * @param start the lower bound of the range of journal content searchs
1748             * @param end the upper bound of the range of journal content searchs (not inclusive)
1749             * @return the range of matching journal content searchs
1750             * @throws SystemException if a system exception occurred
1751             */
1752            @Override
1753            public List<JournalContentSearch> findByG_A(long groupId, String articleId,
1754                    int start, int end) throws SystemException {
1755                    return findByG_A(groupId, articleId, start, end, null);
1756            }
1757    
1758            /**
1759             * Returns an ordered range of all the journal content searchs where groupId = &#63; and articleId = &#63;.
1760             *
1761             * <p>
1762             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalContentSearchModelImpl}. 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.
1763             * </p>
1764             *
1765             * @param groupId the group ID
1766             * @param articleId the article ID
1767             * @param start the lower bound of the range of journal content searchs
1768             * @param end the upper bound of the range of journal content searchs (not inclusive)
1769             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1770             * @return the ordered range of matching journal content searchs
1771             * @throws SystemException if a system exception occurred
1772             */
1773            @Override
1774            public List<JournalContentSearch> findByG_A(long groupId, String articleId,
1775                    int start, int end, OrderByComparator orderByComparator)
1776                    throws SystemException {
1777                    boolean pagination = true;
1778                    FinderPath finderPath = null;
1779                    Object[] finderArgs = null;
1780    
1781                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1782                                    (orderByComparator == null)) {
1783                            pagination = false;
1784                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A;
1785                            finderArgs = new Object[] { groupId, articleId };
1786                    }
1787                    else {
1788                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_A;
1789                            finderArgs = new Object[] {
1790                                            groupId, articleId,
1791                                            
1792                                            start, end, orderByComparator
1793                                    };
1794                    }
1795    
1796                    List<JournalContentSearch> list = (List<JournalContentSearch>)FinderCacheUtil.getResult(finderPath,
1797                                    finderArgs, this);
1798    
1799                    if ((list != null) && !list.isEmpty()) {
1800                            for (JournalContentSearch journalContentSearch : list) {
1801                                    if ((groupId != journalContentSearch.getGroupId()) ||
1802                                                    !Validator.equals(articleId,
1803                                                            journalContentSearch.getArticleId())) {
1804                                            list = null;
1805    
1806                                            break;
1807                                    }
1808                            }
1809                    }
1810    
1811                    if (list == null) {
1812                            StringBundler query = null;
1813    
1814                            if (orderByComparator != null) {
1815                                    query = new StringBundler(4 +
1816                                                    (orderByComparator.getOrderByFields().length * 3));
1817                            }
1818                            else {
1819                                    query = new StringBundler(4);
1820                            }
1821    
1822                            query.append(_SQL_SELECT_JOURNALCONTENTSEARCH_WHERE);
1823    
1824                            query.append(_FINDER_COLUMN_G_A_GROUPID_2);
1825    
1826                            boolean bindArticleId = false;
1827    
1828                            if (articleId == null) {
1829                                    query.append(_FINDER_COLUMN_G_A_ARTICLEID_1);
1830                            }
1831                            else if (articleId.equals(StringPool.BLANK)) {
1832                                    query.append(_FINDER_COLUMN_G_A_ARTICLEID_3);
1833                            }
1834                            else {
1835                                    bindArticleId = true;
1836    
1837                                    query.append(_FINDER_COLUMN_G_A_ARTICLEID_2);
1838                            }
1839    
1840                            if (orderByComparator != null) {
1841                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1842                                            orderByComparator);
1843                            }
1844                            else
1845                             if (pagination) {
1846                                    query.append(JournalContentSearchModelImpl.ORDER_BY_JPQL);
1847                            }
1848    
1849                            String sql = query.toString();
1850    
1851                            Session session = null;
1852    
1853                            try {
1854                                    session = openSession();
1855    
1856                                    Query q = session.createQuery(sql);
1857    
1858                                    QueryPos qPos = QueryPos.getInstance(q);
1859    
1860                                    qPos.add(groupId);
1861    
1862                                    if (bindArticleId) {
1863                                            qPos.add(articleId);
1864                                    }
1865    
1866                                    if (!pagination) {
1867                                            list = (List<JournalContentSearch>)QueryUtil.list(q,
1868                                                            getDialect(), start, end, false);
1869    
1870                                            Collections.sort(list);
1871    
1872                                            list = new UnmodifiableList<JournalContentSearch>(list);
1873                                    }
1874                                    else {
1875                                            list = (List<JournalContentSearch>)QueryUtil.list(q,
1876                                                            getDialect(), start, end);
1877                                    }
1878    
1879                                    cacheResult(list);
1880    
1881                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1882                            }
1883                            catch (Exception e) {
1884                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1885    
1886                                    throw processException(e);
1887                            }
1888                            finally {
1889                                    closeSession(session);
1890                            }
1891                    }
1892    
1893                    return list;
1894            }
1895    
1896            /**
1897             * Returns the first journal content search in the ordered set where groupId = &#63; and articleId = &#63;.
1898             *
1899             * @param groupId the group ID
1900             * @param articleId the article ID
1901             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1902             * @return the first matching journal content search
1903             * @throws com.liferay.portlet.journal.NoSuchContentSearchException if a matching journal content search could not be found
1904             * @throws SystemException if a system exception occurred
1905             */
1906            @Override
1907            public JournalContentSearch findByG_A_First(long groupId, String articleId,
1908                    OrderByComparator orderByComparator)
1909                    throws NoSuchContentSearchException, SystemException {
1910                    JournalContentSearch journalContentSearch = fetchByG_A_First(groupId,
1911                                    articleId, orderByComparator);
1912    
1913                    if (journalContentSearch != null) {
1914                            return journalContentSearch;
1915                    }
1916    
1917                    StringBundler msg = new StringBundler(6);
1918    
1919                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1920    
1921                    msg.append("groupId=");
1922                    msg.append(groupId);
1923    
1924                    msg.append(", articleId=");
1925                    msg.append(articleId);
1926    
1927                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1928    
1929                    throw new NoSuchContentSearchException(msg.toString());
1930            }
1931    
1932            /**
1933             * Returns the first journal content search in the ordered set where groupId = &#63; and articleId = &#63;.
1934             *
1935             * @param groupId the group ID
1936             * @param articleId the article ID
1937             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1938             * @return the first matching journal content search, or <code>null</code> if a matching journal content search could not be found
1939             * @throws SystemException if a system exception occurred
1940             */
1941            @Override
1942            public JournalContentSearch fetchByG_A_First(long groupId,
1943                    String articleId, OrderByComparator orderByComparator)
1944                    throws SystemException {
1945                    List<JournalContentSearch> list = findByG_A(groupId, articleId, 0, 1,
1946                                    orderByComparator);
1947    
1948                    if (!list.isEmpty()) {
1949                            return list.get(0);
1950                    }
1951    
1952                    return null;
1953            }
1954    
1955            /**
1956             * Returns the last journal content search in the ordered set where groupId = &#63; and articleId = &#63;.
1957             *
1958             * @param groupId the group ID
1959             * @param articleId the article ID
1960             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1961             * @return the last matching journal content search
1962             * @throws com.liferay.portlet.journal.NoSuchContentSearchException if a matching journal content search could not be found
1963             * @throws SystemException if a system exception occurred
1964             */
1965            @Override
1966            public JournalContentSearch findByG_A_Last(long groupId, String articleId,
1967                    OrderByComparator orderByComparator)
1968                    throws NoSuchContentSearchException, SystemException {
1969                    JournalContentSearch journalContentSearch = fetchByG_A_Last(groupId,
1970                                    articleId, orderByComparator);
1971    
1972                    if (journalContentSearch != null) {
1973                            return journalContentSearch;
1974                    }
1975    
1976                    StringBundler msg = new StringBundler(6);
1977    
1978                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1979    
1980                    msg.append("groupId=");
1981                    msg.append(groupId);
1982    
1983                    msg.append(", articleId=");
1984                    msg.append(articleId);
1985    
1986                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1987    
1988                    throw new NoSuchContentSearchException(msg.toString());
1989            }
1990    
1991            /**
1992             * Returns the last journal content search in the ordered set where groupId = &#63; and articleId = &#63;.
1993             *
1994             * @param groupId the group ID
1995             * @param articleId the article ID
1996             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1997             * @return the last matching journal content search, or <code>null</code> if a matching journal content search could not be found
1998             * @throws SystemException if a system exception occurred
1999             */
2000            @Override
2001            public JournalContentSearch fetchByG_A_Last(long groupId, String articleId,
2002                    OrderByComparator orderByComparator) throws SystemException {
2003                    int count = countByG_A(groupId, articleId);
2004    
2005                    if (count == 0) {
2006                            return null;
2007                    }
2008    
2009                    List<JournalContentSearch> list = findByG_A(groupId, articleId,
2010                                    count - 1, count, orderByComparator);
2011    
2012                    if (!list.isEmpty()) {
2013                            return list.get(0);
2014                    }
2015    
2016                    return null;
2017            }
2018    
2019            /**
2020             * Returns the journal content searchs before and after the current journal content search in the ordered set where groupId = &#63; and articleId = &#63;.
2021             *
2022             * @param contentSearchId the primary key of the current journal content search
2023             * @param groupId the group ID
2024             * @param articleId the article ID
2025             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2026             * @return the previous, current, and next journal content search
2027             * @throws com.liferay.portlet.journal.NoSuchContentSearchException if a journal content search with the primary key could not be found
2028             * @throws SystemException if a system exception occurred
2029             */
2030            @Override
2031            public JournalContentSearch[] findByG_A_PrevAndNext(long contentSearchId,
2032                    long groupId, String articleId, OrderByComparator orderByComparator)
2033                    throws NoSuchContentSearchException, SystemException {
2034                    JournalContentSearch journalContentSearch = findByPrimaryKey(contentSearchId);
2035    
2036                    Session session = null;
2037    
2038                    try {
2039                            session = openSession();
2040    
2041                            JournalContentSearch[] array = new JournalContentSearchImpl[3];
2042    
2043                            array[0] = getByG_A_PrevAndNext(session, journalContentSearch,
2044                                            groupId, articleId, orderByComparator, true);
2045    
2046                            array[1] = journalContentSearch;
2047    
2048                            array[2] = getByG_A_PrevAndNext(session, journalContentSearch,
2049                                            groupId, articleId, orderByComparator, false);
2050    
2051                            return array;
2052                    }
2053                    catch (Exception e) {
2054                            throw processException(e);
2055                    }
2056                    finally {
2057                            closeSession(session);
2058                    }
2059            }
2060    
2061            protected JournalContentSearch getByG_A_PrevAndNext(Session session,
2062                    JournalContentSearch journalContentSearch, long groupId,
2063                    String articleId, OrderByComparator orderByComparator, boolean previous) {
2064                    StringBundler query = null;
2065    
2066                    if (orderByComparator != null) {
2067                            query = new StringBundler(6 +
2068                                            (orderByComparator.getOrderByFields().length * 6));
2069                    }
2070                    else {
2071                            query = new StringBundler(3);
2072                    }
2073    
2074                    query.append(_SQL_SELECT_JOURNALCONTENTSEARCH_WHERE);
2075    
2076                    query.append(_FINDER_COLUMN_G_A_GROUPID_2);
2077    
2078                    boolean bindArticleId = false;
2079    
2080                    if (articleId == null) {
2081                            query.append(_FINDER_COLUMN_G_A_ARTICLEID_1);
2082                    }
2083                    else if (articleId.equals(StringPool.BLANK)) {
2084                            query.append(_FINDER_COLUMN_G_A_ARTICLEID_3);
2085                    }
2086                    else {
2087                            bindArticleId = true;
2088    
2089                            query.append(_FINDER_COLUMN_G_A_ARTICLEID_2);
2090                    }
2091    
2092                    if (orderByComparator != null) {
2093                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2094    
2095                            if (orderByConditionFields.length > 0) {
2096                                    query.append(WHERE_AND);
2097                            }
2098    
2099                            for (int i = 0; i < orderByConditionFields.length; i++) {
2100                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2101                                    query.append(orderByConditionFields[i]);
2102    
2103                                    if ((i + 1) < orderByConditionFields.length) {
2104                                            if (orderByComparator.isAscending() ^ previous) {
2105                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2106                                            }
2107                                            else {
2108                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2109                                            }
2110                                    }
2111                                    else {
2112                                            if (orderByComparator.isAscending() ^ previous) {
2113                                                    query.append(WHERE_GREATER_THAN);
2114                                            }
2115                                            else {
2116                                                    query.append(WHERE_LESSER_THAN);
2117                                            }
2118                                    }
2119                            }
2120    
2121                            query.append(ORDER_BY_CLAUSE);
2122    
2123                            String[] orderByFields = orderByComparator.getOrderByFields();
2124    
2125                            for (int i = 0; i < orderByFields.length; i++) {
2126                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2127                                    query.append(orderByFields[i]);
2128    
2129                                    if ((i + 1) < orderByFields.length) {
2130                                            if (orderByComparator.isAscending() ^ previous) {
2131                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2132                                            }
2133                                            else {
2134                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2135                                            }
2136                                    }
2137                                    else {
2138                                            if (orderByComparator.isAscending() ^ previous) {
2139                                                    query.append(ORDER_BY_ASC);
2140                                            }
2141                                            else {
2142                                                    query.append(ORDER_BY_DESC);
2143                                            }
2144                                    }
2145                            }
2146                    }
2147                    else {
2148                            query.append(JournalContentSearchModelImpl.ORDER_BY_JPQL);
2149                    }
2150    
2151                    String sql = query.toString();
2152    
2153                    Query q = session.createQuery(sql);
2154    
2155                    q.setFirstResult(0);
2156                    q.setMaxResults(2);
2157    
2158                    QueryPos qPos = QueryPos.getInstance(q);
2159    
2160                    qPos.add(groupId);
2161    
2162                    if (bindArticleId) {
2163                            qPos.add(articleId);
2164                    }
2165    
2166                    if (orderByComparator != null) {
2167                            Object[] values = orderByComparator.getOrderByConditionValues(journalContentSearch);
2168    
2169                            for (Object value : values) {
2170                                    qPos.add(value);
2171                            }
2172                    }
2173    
2174                    List<JournalContentSearch> list = q.list();
2175    
2176                    if (list.size() == 2) {
2177                            return list.get(1);
2178                    }
2179                    else {
2180                            return null;
2181                    }
2182            }
2183    
2184            /**
2185             * Removes all the journal content searchs where groupId = &#63; and articleId = &#63; from the database.
2186             *
2187             * @param groupId the group ID
2188             * @param articleId the article ID
2189             * @throws SystemException if a system exception occurred
2190             */
2191            @Override
2192            public void removeByG_A(long groupId, String articleId)
2193                    throws SystemException {
2194                    for (JournalContentSearch journalContentSearch : findByG_A(groupId,
2195                                    articleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2196                            remove(journalContentSearch);
2197                    }
2198            }
2199    
2200            /**
2201             * Returns the number of journal content searchs where groupId = &#63; and articleId = &#63;.
2202             *
2203             * @param groupId the group ID
2204             * @param articleId the article ID
2205             * @return the number of matching journal content searchs
2206             * @throws SystemException if a system exception occurred
2207             */
2208            @Override
2209            public int countByG_A(long groupId, String articleId)
2210                    throws SystemException {
2211                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_A;
2212    
2213                    Object[] finderArgs = new Object[] { groupId, articleId };
2214    
2215                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2216                                    this);
2217    
2218                    if (count == null) {
2219                            StringBundler query = new StringBundler(3);
2220    
2221                            query.append(_SQL_COUNT_JOURNALCONTENTSEARCH_WHERE);
2222    
2223                            query.append(_FINDER_COLUMN_G_A_GROUPID_2);
2224    
2225                            boolean bindArticleId = false;
2226    
2227                            if (articleId == null) {
2228                                    query.append(_FINDER_COLUMN_G_A_ARTICLEID_1);
2229                            }
2230                            else if (articleId.equals(StringPool.BLANK)) {
2231                                    query.append(_FINDER_COLUMN_G_A_ARTICLEID_3);
2232                            }
2233                            else {
2234                                    bindArticleId = true;
2235    
2236                                    query.append(_FINDER_COLUMN_G_A_ARTICLEID_2);
2237                            }
2238    
2239                            String sql = query.toString();
2240    
2241                            Session session = null;
2242    
2243                            try {
2244                                    session = openSession();
2245    
2246                                    Query q = session.createQuery(sql);
2247    
2248                                    QueryPos qPos = QueryPos.getInstance(q);
2249    
2250                                    qPos.add(groupId);
2251    
2252                                    if (bindArticleId) {
2253                                            qPos.add(articleId);
2254                                    }
2255    
2256                                    count = (Long)q.uniqueResult();
2257    
2258                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2259                            }
2260                            catch (Exception e) {
2261                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2262    
2263                                    throw processException(e);
2264                            }
2265                            finally {
2266                                    closeSession(session);
2267                            }
2268                    }
2269    
2270                    return count.intValue();
2271            }
2272    
2273            private static final String _FINDER_COLUMN_G_A_GROUPID_2 = "journalContentSearch.groupId = ? AND ";
2274            private static final String _FINDER_COLUMN_G_A_ARTICLEID_1 = "journalContentSearch.articleId IS NULL";
2275            private static final String _FINDER_COLUMN_G_A_ARTICLEID_2 = "journalContentSearch.articleId = ?";
2276            private static final String _FINDER_COLUMN_G_A_ARTICLEID_3 = "(journalContentSearch.articleId IS NULL OR journalContentSearch.articleId = '')";
2277            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_L = new FinderPath(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
2278                            JournalContentSearchModelImpl.FINDER_CACHE_ENABLED,
2279                            JournalContentSearchImpl.class,
2280                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P_L",
2281                            new String[] {
2282                                    Long.class.getName(), Boolean.class.getName(),
2283                                    Long.class.getName(),
2284                                    
2285                            Integer.class.getName(), Integer.class.getName(),
2286                                    OrderByComparator.class.getName()
2287                            });
2288            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_L = new FinderPath(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
2289                            JournalContentSearchModelImpl.FINDER_CACHE_ENABLED,
2290                            JournalContentSearchImpl.class,
2291                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P_L",
2292                            new String[] {
2293                                    Long.class.getName(), Boolean.class.getName(),
2294                                    Long.class.getName()
2295                            },
2296                            JournalContentSearchModelImpl.GROUPID_COLUMN_BITMASK |
2297                            JournalContentSearchModelImpl.PRIVATELAYOUT_COLUMN_BITMASK |
2298                            JournalContentSearchModelImpl.LAYOUTID_COLUMN_BITMASK);
2299            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_L = new FinderPath(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
2300                            JournalContentSearchModelImpl.FINDER_CACHE_ENABLED, Long.class,
2301                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_L",
2302                            new String[] {
2303                                    Long.class.getName(), Boolean.class.getName(),
2304                                    Long.class.getName()
2305                            });
2306    
2307            /**
2308             * Returns all the journal content searchs where groupId = &#63; and privateLayout = &#63; and layoutId = &#63;.
2309             *
2310             * @param groupId the group ID
2311             * @param privateLayout the private layout
2312             * @param layoutId the layout ID
2313             * @return the matching journal content searchs
2314             * @throws SystemException if a system exception occurred
2315             */
2316            @Override
2317            public List<JournalContentSearch> findByG_P_L(long groupId,
2318                    boolean privateLayout, long layoutId) throws SystemException {
2319                    return findByG_P_L(groupId, privateLayout, layoutId, QueryUtil.ALL_POS,
2320                            QueryUtil.ALL_POS, null);
2321            }
2322    
2323            /**
2324             * Returns a range of all the journal content searchs where groupId = &#63; and privateLayout = &#63; and layoutId = &#63;.
2325             *
2326             * <p>
2327             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalContentSearchModelImpl}. 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.
2328             * </p>
2329             *
2330             * @param groupId the group ID
2331             * @param privateLayout the private layout
2332             * @param layoutId the layout ID
2333             * @param start the lower bound of the range of journal content searchs
2334             * @param end the upper bound of the range of journal content searchs (not inclusive)
2335             * @return the range of matching journal content searchs
2336             * @throws SystemException if a system exception occurred
2337             */
2338            @Override
2339            public List<JournalContentSearch> findByG_P_L(long groupId,
2340                    boolean privateLayout, long layoutId, int start, int end)
2341                    throws SystemException {
2342                    return findByG_P_L(groupId, privateLayout, layoutId, start, end, null);
2343            }
2344    
2345            /**
2346             * Returns an ordered range of all the journal content searchs where groupId = &#63; and privateLayout = &#63; and layoutId = &#63;.
2347             *
2348             * <p>
2349             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalContentSearchModelImpl}. 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.
2350             * </p>
2351             *
2352             * @param groupId the group ID
2353             * @param privateLayout the private layout
2354             * @param layoutId the layout ID
2355             * @param start the lower bound of the range of journal content searchs
2356             * @param end the upper bound of the range of journal content searchs (not inclusive)
2357             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2358             * @return the ordered range of matching journal content searchs
2359             * @throws SystemException if a system exception occurred
2360             */
2361            @Override
2362            public List<JournalContentSearch> findByG_P_L(long groupId,
2363                    boolean privateLayout, long layoutId, int start, int end,
2364                    OrderByComparator orderByComparator) throws SystemException {
2365                    boolean pagination = true;
2366                    FinderPath finderPath = null;
2367                    Object[] finderArgs = null;
2368    
2369                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2370                                    (orderByComparator == null)) {
2371                            pagination = false;
2372                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_L;
2373                            finderArgs = new Object[] { groupId, privateLayout, layoutId };
2374                    }
2375                    else {
2376                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_L;
2377                            finderArgs = new Object[] {
2378                                            groupId, privateLayout, layoutId,
2379                                            
2380                                            start, end, orderByComparator
2381                                    };
2382                    }
2383    
2384                    List<JournalContentSearch> list = (List<JournalContentSearch>)FinderCacheUtil.getResult(finderPath,
2385                                    finderArgs, this);
2386    
2387                    if ((list != null) && !list.isEmpty()) {
2388                            for (JournalContentSearch journalContentSearch : list) {
2389                                    if ((groupId != journalContentSearch.getGroupId()) ||
2390                                                    (privateLayout != journalContentSearch.getPrivateLayout()) ||
2391                                                    (layoutId != journalContentSearch.getLayoutId())) {
2392                                            list = null;
2393    
2394                                            break;
2395                                    }
2396                            }
2397                    }
2398    
2399                    if (list == null) {
2400                            StringBundler query = null;
2401    
2402                            if (orderByComparator != null) {
2403                                    query = new StringBundler(5 +
2404                                                    (orderByComparator.getOrderByFields().length * 3));
2405                            }
2406                            else {
2407                                    query = new StringBundler(5);
2408                            }
2409    
2410                            query.append(_SQL_SELECT_JOURNALCONTENTSEARCH_WHERE);
2411    
2412                            query.append(_FINDER_COLUMN_G_P_L_GROUPID_2);
2413    
2414                            query.append(_FINDER_COLUMN_G_P_L_PRIVATELAYOUT_2);
2415    
2416                            query.append(_FINDER_COLUMN_G_P_L_LAYOUTID_2);
2417    
2418                            if (orderByComparator != null) {
2419                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2420                                            orderByComparator);
2421                            }
2422                            else
2423                             if (pagination) {
2424                                    query.append(JournalContentSearchModelImpl.ORDER_BY_JPQL);
2425                            }
2426    
2427                            String sql = query.toString();
2428    
2429                            Session session = null;
2430    
2431                            try {
2432                                    session = openSession();
2433    
2434                                    Query q = session.createQuery(sql);
2435    
2436                                    QueryPos qPos = QueryPos.getInstance(q);
2437    
2438                                    qPos.add(groupId);
2439    
2440                                    qPos.add(privateLayout);
2441    
2442                                    qPos.add(layoutId);
2443    
2444                                    if (!pagination) {
2445                                            list = (List<JournalContentSearch>)QueryUtil.list(q,
2446                                                            getDialect(), start, end, false);
2447    
2448                                            Collections.sort(list);
2449    
2450                                            list = new UnmodifiableList<JournalContentSearch>(list);
2451                                    }
2452                                    else {
2453                                            list = (List<JournalContentSearch>)QueryUtil.list(q,
2454                                                            getDialect(), start, end);
2455                                    }
2456    
2457                                    cacheResult(list);
2458    
2459                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2460                            }
2461                            catch (Exception e) {
2462                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2463    
2464                                    throw processException(e);
2465                            }
2466                            finally {
2467                                    closeSession(session);
2468                            }
2469                    }
2470    
2471                    return list;
2472            }
2473    
2474            /**
2475             * Returns the first journal content search in the ordered set where groupId = &#63; and privateLayout = &#63; and layoutId = &#63;.
2476             *
2477             * @param groupId the group ID
2478             * @param privateLayout the private layout
2479             * @param layoutId the layout ID
2480             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2481             * @return the first matching journal content search
2482             * @throws com.liferay.portlet.journal.NoSuchContentSearchException if a matching journal content search could not be found
2483             * @throws SystemException if a system exception occurred
2484             */
2485            @Override
2486            public JournalContentSearch findByG_P_L_First(long groupId,
2487                    boolean privateLayout, long layoutId,
2488                    OrderByComparator orderByComparator)
2489                    throws NoSuchContentSearchException, SystemException {
2490                    JournalContentSearch journalContentSearch = fetchByG_P_L_First(groupId,
2491                                    privateLayout, layoutId, orderByComparator);
2492    
2493                    if (journalContentSearch != null) {
2494                            return journalContentSearch;
2495                    }
2496    
2497                    StringBundler msg = new StringBundler(8);
2498    
2499                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2500    
2501                    msg.append("groupId=");
2502                    msg.append(groupId);
2503    
2504                    msg.append(", privateLayout=");
2505                    msg.append(privateLayout);
2506    
2507                    msg.append(", layoutId=");
2508                    msg.append(layoutId);
2509    
2510                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2511    
2512                    throw new NoSuchContentSearchException(msg.toString());
2513            }
2514    
2515            /**
2516             * Returns the first journal content search in the ordered set where groupId = &#63; and privateLayout = &#63; and layoutId = &#63;.
2517             *
2518             * @param groupId the group ID
2519             * @param privateLayout the private layout
2520             * @param layoutId the layout ID
2521             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2522             * @return the first matching journal content search, or <code>null</code> if a matching journal content search could not be found
2523             * @throws SystemException if a system exception occurred
2524             */
2525            @Override
2526            public JournalContentSearch fetchByG_P_L_First(long groupId,
2527                    boolean privateLayout, long layoutId,
2528                    OrderByComparator orderByComparator) throws SystemException {
2529                    List<JournalContentSearch> list = findByG_P_L(groupId, privateLayout,
2530                                    layoutId, 0, 1, orderByComparator);
2531    
2532                    if (!list.isEmpty()) {
2533                            return list.get(0);
2534                    }
2535    
2536                    return null;
2537            }
2538    
2539            /**
2540             * Returns the last journal content search in the ordered set where groupId = &#63; and privateLayout = &#63; and layoutId = &#63;.
2541             *
2542             * @param groupId the group ID
2543             * @param privateLayout the private layout
2544             * @param layoutId the layout ID
2545             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2546             * @return the last matching journal content search
2547             * @throws com.liferay.portlet.journal.NoSuchContentSearchException if a matching journal content search could not be found
2548             * @throws SystemException if a system exception occurred
2549             */
2550            @Override
2551            public JournalContentSearch findByG_P_L_Last(long groupId,
2552                    boolean privateLayout, long layoutId,
2553                    OrderByComparator orderByComparator)
2554                    throws NoSuchContentSearchException, SystemException {
2555                    JournalContentSearch journalContentSearch = fetchByG_P_L_Last(groupId,
2556                                    privateLayout, layoutId, orderByComparator);
2557    
2558                    if (journalContentSearch != null) {
2559                            return journalContentSearch;
2560                    }
2561    
2562                    StringBundler msg = new StringBundler(8);
2563    
2564                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2565    
2566                    msg.append("groupId=");
2567                    msg.append(groupId);
2568    
2569                    msg.append(", privateLayout=");
2570                    msg.append(privateLayout);
2571    
2572                    msg.append(", layoutId=");
2573                    msg.append(layoutId);
2574    
2575                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2576    
2577                    throw new NoSuchContentSearchException(msg.toString());
2578            }
2579    
2580            /**
2581             * Returns the last journal content search in the ordered set where groupId = &#63; and privateLayout = &#63; and layoutId = &#63;.
2582             *
2583             * @param groupId the group ID
2584             * @param privateLayout the private layout
2585             * @param layoutId the layout ID
2586             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2587             * @return the last matching journal content search, or <code>null</code> if a matching journal content search could not be found
2588             * @throws SystemException if a system exception occurred
2589             */
2590            @Override
2591            public JournalContentSearch fetchByG_P_L_Last(long groupId,
2592                    boolean privateLayout, long layoutId,
2593                    OrderByComparator orderByComparator) throws SystemException {
2594                    int count = countByG_P_L(groupId, privateLayout, layoutId);
2595    
2596                    if (count == 0) {
2597                            return null;
2598                    }
2599    
2600                    List<JournalContentSearch> list = findByG_P_L(groupId, privateLayout,
2601                                    layoutId, count - 1, count, orderByComparator);
2602    
2603                    if (!list.isEmpty()) {
2604                            return list.get(0);
2605                    }
2606    
2607                    return null;
2608            }
2609    
2610            /**
2611             * Returns the journal content searchs before and after the current journal content search in the ordered set where groupId = &#63; and privateLayout = &#63; and layoutId = &#63;.
2612             *
2613             * @param contentSearchId the primary key of the current journal content search
2614             * @param groupId the group ID
2615             * @param privateLayout the private layout
2616             * @param layoutId the layout ID
2617             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2618             * @return the previous, current, and next journal content search
2619             * @throws com.liferay.portlet.journal.NoSuchContentSearchException if a journal content search with the primary key could not be found
2620             * @throws SystemException if a system exception occurred
2621             */
2622            @Override
2623            public JournalContentSearch[] findByG_P_L_PrevAndNext(
2624                    long contentSearchId, long groupId, boolean privateLayout,
2625                    long layoutId, OrderByComparator orderByComparator)
2626                    throws NoSuchContentSearchException, SystemException {
2627                    JournalContentSearch journalContentSearch = findByPrimaryKey(contentSearchId);
2628    
2629                    Session session = null;
2630    
2631                    try {
2632                            session = openSession();
2633    
2634                            JournalContentSearch[] array = new JournalContentSearchImpl[3];
2635    
2636                            array[0] = getByG_P_L_PrevAndNext(session, journalContentSearch,
2637                                            groupId, privateLayout, layoutId, orderByComparator, true);
2638    
2639                            array[1] = journalContentSearch;
2640    
2641                            array[2] = getByG_P_L_PrevAndNext(session, journalContentSearch,
2642                                            groupId, privateLayout, layoutId, orderByComparator, false);
2643    
2644                            return array;
2645                    }
2646                    catch (Exception e) {
2647                            throw processException(e);
2648                    }
2649                    finally {
2650                            closeSession(session);
2651                    }
2652            }
2653    
2654            protected JournalContentSearch getByG_P_L_PrevAndNext(Session session,
2655                    JournalContentSearch journalContentSearch, long groupId,
2656                    boolean privateLayout, long layoutId,
2657                    OrderByComparator orderByComparator, boolean previous) {
2658                    StringBundler query = null;
2659    
2660                    if (orderByComparator != null) {
2661                            query = new StringBundler(6 +
2662                                            (orderByComparator.getOrderByFields().length * 6));
2663                    }
2664                    else {
2665                            query = new StringBundler(3);
2666                    }
2667    
2668                    query.append(_SQL_SELECT_JOURNALCONTENTSEARCH_WHERE);
2669    
2670                    query.append(_FINDER_COLUMN_G_P_L_GROUPID_2);
2671    
2672                    query.append(_FINDER_COLUMN_G_P_L_PRIVATELAYOUT_2);
2673    
2674                    query.append(_FINDER_COLUMN_G_P_L_LAYOUTID_2);
2675    
2676                    if (orderByComparator != null) {
2677                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2678    
2679                            if (orderByConditionFields.length > 0) {
2680                                    query.append(WHERE_AND);
2681                            }
2682    
2683                            for (int i = 0; i < orderByConditionFields.length; i++) {
2684                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2685                                    query.append(orderByConditionFields[i]);
2686    
2687                                    if ((i + 1) < orderByConditionFields.length) {
2688                                            if (orderByComparator.isAscending() ^ previous) {
2689                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2690                                            }
2691                                            else {
2692                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2693                                            }
2694                                    }
2695                                    else {
2696                                            if (orderByComparator.isAscending() ^ previous) {
2697                                                    query.append(WHERE_GREATER_THAN);
2698                                            }
2699                                            else {
2700                                                    query.append(WHERE_LESSER_THAN);
2701                                            }
2702                                    }
2703                            }
2704    
2705                            query.append(ORDER_BY_CLAUSE);
2706    
2707                            String[] orderByFields = orderByComparator.getOrderByFields();
2708    
2709                            for (int i = 0; i < orderByFields.length; i++) {
2710                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2711                                    query.append(orderByFields[i]);
2712    
2713                                    if ((i + 1) < orderByFields.length) {
2714                                            if (orderByComparator.isAscending() ^ previous) {
2715                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2716                                            }
2717                                            else {
2718                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2719                                            }
2720                                    }
2721                                    else {
2722                                            if (orderByComparator.isAscending() ^ previous) {
2723                                                    query.append(ORDER_BY_ASC);
2724                                            }
2725                                            else {
2726                                                    query.append(ORDER_BY_DESC);
2727                                            }
2728                                    }
2729                            }
2730                    }
2731                    else {
2732                            query.append(JournalContentSearchModelImpl.ORDER_BY_JPQL);
2733                    }
2734    
2735                    String sql = query.toString();
2736    
2737                    Query q = session.createQuery(sql);
2738    
2739                    q.setFirstResult(0);
2740                    q.setMaxResults(2);
2741    
2742                    QueryPos qPos = QueryPos.getInstance(q);
2743    
2744                    qPos.add(groupId);
2745    
2746                    qPos.add(privateLayout);
2747    
2748                    qPos.add(layoutId);
2749    
2750                    if (orderByComparator != null) {
2751                            Object[] values = orderByComparator.getOrderByConditionValues(journalContentSearch);
2752    
2753                            for (Object value : values) {
2754                                    qPos.add(value);
2755                            }
2756                    }
2757    
2758                    List<JournalContentSearch> list = q.list();
2759    
2760                    if (list.size() == 2) {
2761                            return list.get(1);
2762                    }
2763                    else {
2764                            return null;
2765                    }
2766            }
2767    
2768            /**
2769             * Removes all the journal content searchs where groupId = &#63; and privateLayout = &#63; and layoutId = &#63; from the database.
2770             *
2771             * @param groupId the group ID
2772             * @param privateLayout the private layout
2773             * @param layoutId the layout ID
2774             * @throws SystemException if a system exception occurred
2775             */
2776            @Override
2777            public void removeByG_P_L(long groupId, boolean privateLayout, long layoutId)
2778                    throws SystemException {
2779                    for (JournalContentSearch journalContentSearch : findByG_P_L(groupId,
2780                                    privateLayout, layoutId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2781                                    null)) {
2782                            remove(journalContentSearch);
2783                    }
2784            }
2785    
2786            /**
2787             * Returns the number of journal content searchs where groupId = &#63; and privateLayout = &#63; and layoutId = &#63;.
2788             *
2789             * @param groupId the group ID
2790             * @param privateLayout the private layout
2791             * @param layoutId the layout ID
2792             * @return the number of matching journal content searchs
2793             * @throws SystemException if a system exception occurred
2794             */
2795            @Override
2796            public int countByG_P_L(long groupId, boolean privateLayout, long layoutId)
2797                    throws SystemException {
2798                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_L;
2799    
2800                    Object[] finderArgs = new Object[] { groupId, privateLayout, layoutId };
2801    
2802                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2803                                    this);
2804    
2805                    if (count == null) {
2806                            StringBundler query = new StringBundler(4);
2807    
2808                            query.append(_SQL_COUNT_JOURNALCONTENTSEARCH_WHERE);
2809    
2810                            query.append(_FINDER_COLUMN_G_P_L_GROUPID_2);
2811    
2812                            query.append(_FINDER_COLUMN_G_P_L_PRIVATELAYOUT_2);
2813    
2814                            query.append(_FINDER_COLUMN_G_P_L_LAYOUTID_2);
2815    
2816                            String sql = query.toString();
2817    
2818                            Session session = null;
2819    
2820                            try {
2821                                    session = openSession();
2822    
2823                                    Query q = session.createQuery(sql);
2824    
2825                                    QueryPos qPos = QueryPos.getInstance(q);
2826    
2827                                    qPos.add(groupId);
2828    
2829                                    qPos.add(privateLayout);
2830    
2831                                    qPos.add(layoutId);
2832    
2833                                    count = (Long)q.uniqueResult();
2834    
2835                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2836                            }
2837                            catch (Exception e) {
2838                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2839    
2840                                    throw processException(e);
2841                            }
2842                            finally {
2843                                    closeSession(session);
2844                            }
2845                    }
2846    
2847                    return count.intValue();
2848            }
2849    
2850            private static final String _FINDER_COLUMN_G_P_L_GROUPID_2 = "journalContentSearch.groupId = ? AND ";
2851            private static final String _FINDER_COLUMN_G_P_L_PRIVATELAYOUT_2 = "journalContentSearch.privateLayout = ? AND ";
2852            private static final String _FINDER_COLUMN_G_P_L_LAYOUTID_2 = "journalContentSearch.layoutId = ?";
2853            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_A = new FinderPath(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
2854                            JournalContentSearchModelImpl.FINDER_CACHE_ENABLED,
2855                            JournalContentSearchImpl.class,
2856                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P_A",
2857                            new String[] {
2858                                    Long.class.getName(), Boolean.class.getName(),
2859                                    String.class.getName(),
2860                                    
2861                            Integer.class.getName(), Integer.class.getName(),
2862                                    OrderByComparator.class.getName()
2863                            });
2864            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_A = new FinderPath(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
2865                            JournalContentSearchModelImpl.FINDER_CACHE_ENABLED,
2866                            JournalContentSearchImpl.class,
2867                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P_A",
2868                            new String[] {
2869                                    Long.class.getName(), Boolean.class.getName(),
2870                                    String.class.getName()
2871                            },
2872                            JournalContentSearchModelImpl.GROUPID_COLUMN_BITMASK |
2873                            JournalContentSearchModelImpl.PRIVATELAYOUT_COLUMN_BITMASK |
2874                            JournalContentSearchModelImpl.ARTICLEID_COLUMN_BITMASK);
2875            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_A = new FinderPath(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
2876                            JournalContentSearchModelImpl.FINDER_CACHE_ENABLED, Long.class,
2877                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_A",
2878                            new String[] {
2879                                    Long.class.getName(), Boolean.class.getName(),
2880                                    String.class.getName()
2881                            });
2882    
2883            /**
2884             * Returns all the journal content searchs where groupId = &#63; and privateLayout = &#63; and articleId = &#63;.
2885             *
2886             * @param groupId the group ID
2887             * @param privateLayout the private layout
2888             * @param articleId the article ID
2889             * @return the matching journal content searchs
2890             * @throws SystemException if a system exception occurred
2891             */
2892            @Override
2893            public List<JournalContentSearch> findByG_P_A(long groupId,
2894                    boolean privateLayout, String articleId) throws SystemException {
2895                    return findByG_P_A(groupId, privateLayout, articleId,
2896                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2897            }
2898    
2899            /**
2900             * Returns a range of all the journal content searchs where groupId = &#63; and privateLayout = &#63; and articleId = &#63;.
2901             *
2902             * <p>
2903             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalContentSearchModelImpl}. 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.
2904             * </p>
2905             *
2906             * @param groupId the group ID
2907             * @param privateLayout the private layout
2908             * @param articleId the article ID
2909             * @param start the lower bound of the range of journal content searchs
2910             * @param end the upper bound of the range of journal content searchs (not inclusive)
2911             * @return the range of matching journal content searchs
2912             * @throws SystemException if a system exception occurred
2913             */
2914            @Override
2915            public List<JournalContentSearch> findByG_P_A(long groupId,
2916                    boolean privateLayout, String articleId, int start, int end)
2917                    throws SystemException {
2918                    return findByG_P_A(groupId, privateLayout, articleId, start, end, null);
2919            }
2920    
2921            /**
2922             * Returns an ordered range of all the journal content searchs where groupId = &#63; and privateLayout = &#63; and articleId = &#63;.
2923             *
2924             * <p>
2925             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalContentSearchModelImpl}. 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.
2926             * </p>
2927             *
2928             * @param groupId the group ID
2929             * @param privateLayout the private layout
2930             * @param articleId the article ID
2931             * @param start the lower bound of the range of journal content searchs
2932             * @param end the upper bound of the range of journal content searchs (not inclusive)
2933             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2934             * @return the ordered range of matching journal content searchs
2935             * @throws SystemException if a system exception occurred
2936             */
2937            @Override
2938            public List<JournalContentSearch> findByG_P_A(long groupId,
2939                    boolean privateLayout, String articleId, int start, int end,
2940                    OrderByComparator orderByComparator) throws SystemException {
2941                    boolean pagination = true;
2942                    FinderPath finderPath = null;
2943                    Object[] finderArgs = null;
2944    
2945                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2946                                    (orderByComparator == null)) {
2947                            pagination = false;
2948                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_A;
2949                            finderArgs = new Object[] { groupId, privateLayout, articleId };
2950                    }
2951                    else {
2952                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_A;
2953                            finderArgs = new Object[] {
2954                                            groupId, privateLayout, articleId,
2955                                            
2956                                            start, end, orderByComparator
2957                                    };
2958                    }
2959    
2960                    List<JournalContentSearch> list = (List<JournalContentSearch>)FinderCacheUtil.getResult(finderPath,
2961                                    finderArgs, this);
2962    
2963                    if ((list != null) && !list.isEmpty()) {
2964                            for (JournalContentSearch journalContentSearch : list) {
2965                                    if ((groupId != journalContentSearch.getGroupId()) ||
2966                                                    (privateLayout != journalContentSearch.getPrivateLayout()) ||
2967                                                    !Validator.equals(articleId,
2968                                                            journalContentSearch.getArticleId())) {
2969                                            list = null;
2970    
2971                                            break;
2972                                    }
2973                            }
2974                    }
2975    
2976                    if (list == null) {
2977                            StringBundler query = null;
2978    
2979                            if (orderByComparator != null) {
2980                                    query = new StringBundler(5 +
2981                                                    (orderByComparator.getOrderByFields().length * 3));
2982                            }
2983                            else {
2984                                    query = new StringBundler(5);
2985                            }
2986    
2987                            query.append(_SQL_SELECT_JOURNALCONTENTSEARCH_WHERE);
2988    
2989                            query.append(_FINDER_COLUMN_G_P_A_GROUPID_2);
2990    
2991                            query.append(_FINDER_COLUMN_G_P_A_PRIVATELAYOUT_2);
2992    
2993                            boolean bindArticleId = false;
2994    
2995                            if (articleId == null) {
2996                                    query.append(_FINDER_COLUMN_G_P_A_ARTICLEID_1);
2997                            }
2998                            else if (articleId.equals(StringPool.BLANK)) {
2999                                    query.append(_FINDER_COLUMN_G_P_A_ARTICLEID_3);
3000                            }
3001                            else {
3002                                    bindArticleId = true;
3003    
3004                                    query.append(_FINDER_COLUMN_G_P_A_ARTICLEID_2);
3005                            }
3006    
3007                            if (orderByComparator != null) {
3008                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3009                                            orderByComparator);
3010                            }
3011                            else
3012                             if (pagination) {
3013                                    query.append(JournalContentSearchModelImpl.ORDER_BY_JPQL);
3014                            }
3015    
3016                            String sql = query.toString();
3017    
3018                            Session session = null;
3019    
3020                            try {
3021                                    session = openSession();
3022    
3023                                    Query q = session.createQuery(sql);
3024    
3025                                    QueryPos qPos = QueryPos.getInstance(q);
3026    
3027                                    qPos.add(groupId);
3028    
3029                                    qPos.add(privateLayout);
3030    
3031                                    if (bindArticleId) {
3032                                            qPos.add(articleId);
3033                                    }
3034    
3035                                    if (!pagination) {
3036                                            list = (List<JournalContentSearch>)QueryUtil.list(q,
3037                                                            getDialect(), start, end, false);
3038    
3039                                            Collections.sort(list);
3040    
3041                                            list = new UnmodifiableList<JournalContentSearch>(list);
3042                                    }
3043                                    else {
3044                                            list = (List<JournalContentSearch>)QueryUtil.list(q,
3045                                                            getDialect(), start, end);
3046                                    }
3047    
3048                                    cacheResult(list);
3049    
3050                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3051                            }
3052                            catch (Exception e) {
3053                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3054    
3055                                    throw processException(e);
3056                            }
3057                            finally {
3058                                    closeSession(session);
3059                            }
3060                    }
3061    
3062                    return list;
3063            }
3064    
3065            /**
3066             * Returns the first journal content search in the ordered set where groupId = &#63; and privateLayout = &#63; and articleId = &#63;.
3067             *
3068             * @param groupId the group ID
3069             * @param privateLayout the private layout
3070             * @param articleId the article ID
3071             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3072             * @return the first matching journal content search
3073             * @throws com.liferay.portlet.journal.NoSuchContentSearchException if a matching journal content search could not be found
3074             * @throws SystemException if a system exception occurred
3075             */
3076            @Override
3077            public JournalContentSearch findByG_P_A_First(long groupId,
3078                    boolean privateLayout, String articleId,
3079                    OrderByComparator orderByComparator)
3080                    throws NoSuchContentSearchException, SystemException {
3081                    JournalContentSearch journalContentSearch = fetchByG_P_A_First(groupId,
3082                                    privateLayout, articleId, orderByComparator);
3083    
3084                    if (journalContentSearch != null) {
3085                            return journalContentSearch;
3086                    }
3087    
3088                    StringBundler msg = new StringBundler(8);
3089    
3090                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3091    
3092                    msg.append("groupId=");
3093                    msg.append(groupId);
3094    
3095                    msg.append(", privateLayout=");
3096                    msg.append(privateLayout);
3097    
3098                    msg.append(", articleId=");
3099                    msg.append(articleId);
3100    
3101                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3102    
3103                    throw new NoSuchContentSearchException(msg.toString());
3104            }
3105    
3106            /**
3107             * Returns the first journal content search in the ordered set where groupId = &#63; and privateLayout = &#63; and articleId = &#63;.
3108             *
3109             * @param groupId the group ID
3110             * @param privateLayout the private layout
3111             * @param articleId the article ID
3112             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3113             * @return the first matching journal content search, or <code>null</code> if a matching journal content search could not be found
3114             * @throws SystemException if a system exception occurred
3115             */
3116            @Override
3117            public JournalContentSearch fetchByG_P_A_First(long groupId,
3118                    boolean privateLayout, String articleId,
3119                    OrderByComparator orderByComparator) throws SystemException {
3120                    List<JournalContentSearch> list = findByG_P_A(groupId, privateLayout,
3121                                    articleId, 0, 1, orderByComparator);
3122    
3123                    if (!list.isEmpty()) {
3124                            return list.get(0);
3125                    }
3126    
3127                    return null;
3128            }
3129    
3130            /**
3131             * Returns the last journal content search in the ordered set where groupId = &#63; and privateLayout = &#63; and articleId = &#63;.
3132             *
3133             * @param groupId the group ID
3134             * @param privateLayout the private layout
3135             * @param articleId the article ID
3136             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3137             * @return the last matching journal content search
3138             * @throws com.liferay.portlet.journal.NoSuchContentSearchException if a matching journal content search could not be found
3139             * @throws SystemException if a system exception occurred
3140             */
3141            @Override
3142            public JournalContentSearch findByG_P_A_Last(long groupId,
3143                    boolean privateLayout, String articleId,
3144                    OrderByComparator orderByComparator)
3145                    throws NoSuchContentSearchException, SystemException {
3146                    JournalContentSearch journalContentSearch = fetchByG_P_A_Last(groupId,
3147                                    privateLayout, articleId, orderByComparator);
3148    
3149                    if (journalContentSearch != null) {
3150                            return journalContentSearch;
3151                    }
3152    
3153                    StringBundler msg = new StringBundler(8);
3154    
3155                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3156    
3157                    msg.append("groupId=");
3158                    msg.append(groupId);
3159    
3160                    msg.append(", privateLayout=");
3161                    msg.append(privateLayout);
3162    
3163                    msg.append(", articleId=");
3164                    msg.append(articleId);
3165    
3166                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3167    
3168                    throw new NoSuchContentSearchException(msg.toString());
3169            }
3170    
3171            /**
3172             * Returns the last journal content search in the ordered set where groupId = &#63; and privateLayout = &#63; and articleId = &#63;.
3173             *
3174             * @param groupId the group ID
3175             * @param privateLayout the private layout
3176             * @param articleId the article ID
3177             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3178             * @return the last matching journal content search, or <code>null</code> if a matching journal content search could not be found
3179             * @throws SystemException if a system exception occurred
3180             */
3181            @Override
3182            public JournalContentSearch fetchByG_P_A_Last(long groupId,
3183                    boolean privateLayout, String articleId,
3184                    OrderByComparator orderByComparator) throws SystemException {
3185                    int count = countByG_P_A(groupId, privateLayout, articleId);
3186    
3187                    if (count == 0) {
3188                            return null;
3189                    }
3190    
3191                    List<JournalContentSearch> list = findByG_P_A(groupId, privateLayout,
3192                                    articleId, count - 1, count, orderByComparator);
3193    
3194                    if (!list.isEmpty()) {
3195                            return list.get(0);
3196                    }
3197    
3198                    return null;
3199            }
3200    
3201            /**
3202             * Returns the journal content searchs before and after the current journal content search in the ordered set where groupId = &#63; and privateLayout = &#63; and articleId = &#63;.
3203             *
3204             * @param contentSearchId the primary key of the current journal content search
3205             * @param groupId the group ID
3206             * @param privateLayout the private layout
3207             * @param articleId the article ID
3208             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3209             * @return the previous, current, and next journal content search
3210             * @throws com.liferay.portlet.journal.NoSuchContentSearchException if a journal content search with the primary key could not be found
3211             * @throws SystemException if a system exception occurred
3212             */
3213            @Override
3214            public JournalContentSearch[] findByG_P_A_PrevAndNext(
3215                    long contentSearchId, long groupId, boolean privateLayout,
3216                    String articleId, OrderByComparator orderByComparator)
3217                    throws NoSuchContentSearchException, SystemException {
3218                    JournalContentSearch journalContentSearch = findByPrimaryKey(contentSearchId);
3219    
3220                    Session session = null;
3221    
3222                    try {
3223                            session = openSession();
3224    
3225                            JournalContentSearch[] array = new JournalContentSearchImpl[3];
3226    
3227                            array[0] = getByG_P_A_PrevAndNext(session, journalContentSearch,
3228                                            groupId, privateLayout, articleId, orderByComparator, true);
3229    
3230                            array[1] = journalContentSearch;
3231    
3232                            array[2] = getByG_P_A_PrevAndNext(session, journalContentSearch,
3233                                            groupId, privateLayout, articleId, orderByComparator, false);
3234    
3235                            return array;
3236                    }
3237                    catch (Exception e) {
3238                            throw processException(e);
3239                    }
3240                    finally {
3241                            closeSession(session);
3242                    }
3243            }
3244    
3245            protected JournalContentSearch getByG_P_A_PrevAndNext(Session session,
3246                    JournalContentSearch journalContentSearch, long groupId,
3247                    boolean privateLayout, String articleId,
3248                    OrderByComparator orderByComparator, boolean previous) {
3249                    StringBundler query = null;
3250    
3251                    if (orderByComparator != null) {
3252                            query = new StringBundler(6 +
3253                                            (orderByComparator.getOrderByFields().length * 6));
3254                    }
3255                    else {
3256                            query = new StringBundler(3);
3257                    }
3258    
3259                    query.append(_SQL_SELECT_JOURNALCONTENTSEARCH_WHERE);
3260    
3261                    query.append(_FINDER_COLUMN_G_P_A_GROUPID_2);
3262    
3263                    query.append(_FINDER_COLUMN_G_P_A_PRIVATELAYOUT_2);
3264    
3265                    boolean bindArticleId = false;
3266    
3267                    if (articleId == null) {
3268                            query.append(_FINDER_COLUMN_G_P_A_ARTICLEID_1);
3269                    }
3270                    else if (articleId.equals(StringPool.BLANK)) {
3271                            query.append(_FINDER_COLUMN_G_P_A_ARTICLEID_3);
3272                    }
3273                    else {
3274                            bindArticleId = true;
3275    
3276                            query.append(_FINDER_COLUMN_G_P_A_ARTICLEID_2);
3277                    }
3278    
3279                    if (orderByComparator != null) {
3280                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3281    
3282                            if (orderByConditionFields.length > 0) {
3283                                    query.append(WHERE_AND);
3284                            }
3285    
3286                            for (int i = 0; i < orderByConditionFields.length; i++) {
3287                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3288                                    query.append(orderByConditionFields[i]);
3289    
3290                                    if ((i + 1) < orderByConditionFields.length) {
3291                                            if (orderByComparator.isAscending() ^ previous) {
3292                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3293                                            }
3294                                            else {
3295                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3296                                            }
3297                                    }
3298                                    else {
3299                                            if (orderByComparator.isAscending() ^ previous) {
3300                                                    query.append(WHERE_GREATER_THAN);
3301                                            }
3302                                            else {
3303                                                    query.append(WHERE_LESSER_THAN);
3304                                            }
3305                                    }
3306                            }
3307    
3308                            query.append(ORDER_BY_CLAUSE);
3309    
3310                            String[] orderByFields = orderByComparator.getOrderByFields();
3311    
3312                            for (int i = 0; i < orderByFields.length; i++) {
3313                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3314                                    query.append(orderByFields[i]);
3315    
3316                                    if ((i + 1) < orderByFields.length) {
3317                                            if (orderByComparator.isAscending() ^ previous) {
3318                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3319                                            }
3320                                            else {
3321                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3322                                            }
3323                                    }
3324                                    else {
3325                                            if (orderByComparator.isAscending() ^ previous) {
3326                                                    query.append(ORDER_BY_ASC);
3327                                            }
3328                                            else {
3329                                                    query.append(ORDER_BY_DESC);
3330                                            }
3331                                    }
3332                            }
3333                    }
3334                    else {
3335                            query.append(JournalContentSearchModelImpl.ORDER_BY_JPQL);
3336                    }
3337    
3338                    String sql = query.toString();
3339    
3340                    Query q = session.createQuery(sql);
3341    
3342                    q.setFirstResult(0);
3343                    q.setMaxResults(2);
3344    
3345                    QueryPos qPos = QueryPos.getInstance(q);
3346    
3347                    qPos.add(groupId);
3348    
3349                    qPos.add(privateLayout);
3350    
3351                    if (bindArticleId) {
3352                            qPos.add(articleId);
3353                    }
3354    
3355                    if (orderByComparator != null) {
3356                            Object[] values = orderByComparator.getOrderByConditionValues(journalContentSearch);
3357    
3358                            for (Object value : values) {
3359                                    qPos.add(value);
3360                            }
3361                    }
3362    
3363                    List<JournalContentSearch> list = q.list();
3364    
3365                    if (list.size() == 2) {
3366                            return list.get(1);
3367                    }
3368                    else {
3369                            return null;
3370                    }
3371            }
3372    
3373            /**
3374             * Removes all the journal content searchs where groupId = &#63; and privateLayout = &#63; and articleId = &#63; from the database.
3375             *
3376             * @param groupId the group ID
3377             * @param privateLayout the private layout
3378             * @param articleId the article ID
3379             * @throws SystemException if a system exception occurred
3380             */
3381            @Override
3382            public void removeByG_P_A(long groupId, boolean privateLayout,
3383                    String articleId) throws SystemException {
3384                    for (JournalContentSearch journalContentSearch : findByG_P_A(groupId,
3385                                    privateLayout, articleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3386                                    null)) {
3387                            remove(journalContentSearch);
3388                    }
3389            }
3390    
3391            /**
3392             * Returns the number of journal content searchs where groupId = &#63; and privateLayout = &#63; and articleId = &#63;.
3393             *
3394             * @param groupId the group ID
3395             * @param privateLayout the private layout
3396             * @param articleId the article ID
3397             * @return the number of matching journal content searchs
3398             * @throws SystemException if a system exception occurred
3399             */
3400            @Override
3401            public int countByG_P_A(long groupId, boolean privateLayout,
3402                    String articleId) throws SystemException {
3403                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_A;
3404    
3405                    Object[] finderArgs = new Object[] { groupId, privateLayout, articleId };
3406    
3407                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3408                                    this);
3409    
3410                    if (count == null) {
3411                            StringBundler query = new StringBundler(4);
3412    
3413                            query.append(_SQL_COUNT_JOURNALCONTENTSEARCH_WHERE);
3414    
3415                            query.append(_FINDER_COLUMN_G_P_A_GROUPID_2);
3416    
3417                            query.append(_FINDER_COLUMN_G_P_A_PRIVATELAYOUT_2);
3418    
3419                            boolean bindArticleId = false;
3420    
3421                            if (articleId == null) {
3422                                    query.append(_FINDER_COLUMN_G_P_A_ARTICLEID_1);
3423                            }
3424                            else if (articleId.equals(StringPool.BLANK)) {
3425                                    query.append(_FINDER_COLUMN_G_P_A_ARTICLEID_3);
3426                            }
3427                            else {
3428                                    bindArticleId = true;
3429    
3430                                    query.append(_FINDER_COLUMN_G_P_A_ARTICLEID_2);
3431                            }
3432    
3433                            String sql = query.toString();
3434    
3435                            Session session = null;
3436    
3437                            try {
3438                                    session = openSession();
3439    
3440                                    Query q = session.createQuery(sql);
3441    
3442                                    QueryPos qPos = QueryPos.getInstance(q);
3443    
3444                                    qPos.add(groupId);
3445    
3446                                    qPos.add(privateLayout);
3447    
3448                                    if (bindArticleId) {
3449                                            qPos.add(articleId);
3450                                    }
3451    
3452                                    count = (Long)q.uniqueResult();
3453    
3454                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3455                            }
3456                            catch (Exception e) {
3457                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3458    
3459                                    throw processException(e);
3460                            }
3461                            finally {
3462                                    closeSession(session);
3463                            }
3464                    }
3465    
3466                    return count.intValue();
3467            }
3468    
3469            private static final String _FINDER_COLUMN_G_P_A_GROUPID_2 = "journalContentSearch.groupId = ? AND ";
3470            private static final String _FINDER_COLUMN_G_P_A_PRIVATELAYOUT_2 = "journalContentSearch.privateLayout = ? AND ";
3471            private static final String _FINDER_COLUMN_G_P_A_ARTICLEID_1 = "journalContentSearch.articleId IS NULL";
3472            private static final String _FINDER_COLUMN_G_P_A_ARTICLEID_2 = "journalContentSearch.articleId = ?";
3473            private static final String _FINDER_COLUMN_G_P_A_ARTICLEID_3 = "(journalContentSearch.articleId IS NULL OR journalContentSearch.articleId = '')";
3474            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_L_P = new FinderPath(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
3475                            JournalContentSearchModelImpl.FINDER_CACHE_ENABLED,
3476                            JournalContentSearchImpl.class,
3477                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P_L_P",
3478                            new String[] {
3479                                    Long.class.getName(), Boolean.class.getName(),
3480                                    Long.class.getName(), String.class.getName(),
3481                                    
3482                            Integer.class.getName(), Integer.class.getName(),
3483                                    OrderByComparator.class.getName()
3484                            });
3485            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_L_P =
3486                    new FinderPath(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
3487                            JournalContentSearchModelImpl.FINDER_CACHE_ENABLED,
3488                            JournalContentSearchImpl.class,
3489                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P_L_P",
3490                            new String[] {
3491                                    Long.class.getName(), Boolean.class.getName(),
3492                                    Long.class.getName(), String.class.getName()
3493                            },
3494                            JournalContentSearchModelImpl.GROUPID_COLUMN_BITMASK |
3495                            JournalContentSearchModelImpl.PRIVATELAYOUT_COLUMN_BITMASK |
3496                            JournalContentSearchModelImpl.LAYOUTID_COLUMN_BITMASK |
3497                            JournalContentSearchModelImpl.PORTLETID_COLUMN_BITMASK);
3498            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_L_P = new FinderPath(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
3499                            JournalContentSearchModelImpl.FINDER_CACHE_ENABLED, Long.class,
3500                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_L_P",
3501                            new String[] {
3502                                    Long.class.getName(), Boolean.class.getName(),
3503                                    Long.class.getName(), String.class.getName()
3504                            });
3505    
3506            /**
3507             * Returns all the journal content searchs where groupId = &#63; and privateLayout = &#63; and layoutId = &#63; and portletId = &#63;.
3508             *
3509             * @param groupId the group ID
3510             * @param privateLayout the private layout
3511             * @param layoutId the layout ID
3512             * @param portletId the portlet ID
3513             * @return the matching journal content searchs
3514             * @throws SystemException if a system exception occurred
3515             */
3516            @Override
3517            public List<JournalContentSearch> findByG_P_L_P(long groupId,
3518                    boolean privateLayout, long layoutId, String portletId)
3519                    throws SystemException {
3520                    return findByG_P_L_P(groupId, privateLayout, layoutId, portletId,
3521                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3522            }
3523    
3524            /**
3525             * Returns a range of all the journal content searchs where groupId = &#63; and privateLayout = &#63; and layoutId = &#63; and portletId = &#63;.
3526             *
3527             * <p>
3528             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalContentSearchModelImpl}. 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.
3529             * </p>
3530             *
3531             * @param groupId the group ID
3532             * @param privateLayout the private layout
3533             * @param layoutId the layout ID
3534             * @param portletId the portlet ID
3535             * @param start the lower bound of the range of journal content searchs
3536             * @param end the upper bound of the range of journal content searchs (not inclusive)
3537             * @return the range of matching journal content searchs
3538             * @throws SystemException if a system exception occurred
3539             */
3540            @Override
3541            public List<JournalContentSearch> findByG_P_L_P(long groupId,
3542                    boolean privateLayout, long layoutId, String portletId, int start,
3543                    int end) throws SystemException {
3544                    return findByG_P_L_P(groupId, privateLayout, layoutId, portletId,
3545                            start, end, null);
3546            }
3547    
3548            /**
3549             * Returns an ordered range of all the journal content searchs where groupId = &#63; and privateLayout = &#63; and layoutId = &#63; and portletId = &#63;.
3550             *
3551             * <p>
3552             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalContentSearchModelImpl}. 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.
3553             * </p>
3554             *
3555             * @param groupId the group ID
3556             * @param privateLayout the private layout
3557             * @param layoutId the layout ID
3558             * @param portletId the portlet ID
3559             * @param start the lower bound of the range of journal content searchs
3560             * @param end the upper bound of the range of journal content searchs (not inclusive)
3561             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3562             * @return the ordered range of matching journal content searchs
3563             * @throws SystemException if a system exception occurred
3564             */
3565            @Override
3566            public List<JournalContentSearch> findByG_P_L_P(long groupId,
3567                    boolean privateLayout, long layoutId, String portletId, int start,
3568                    int end, OrderByComparator orderByComparator) throws SystemException {
3569                    boolean pagination = true;
3570                    FinderPath finderPath = null;
3571                    Object[] finderArgs = null;
3572    
3573                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3574                                    (orderByComparator == null)) {
3575                            pagination = false;
3576                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_L_P;
3577                            finderArgs = new Object[] {
3578                                            groupId, privateLayout, layoutId, portletId
3579                                    };
3580                    }
3581                    else {
3582                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_L_P;
3583                            finderArgs = new Object[] {
3584                                            groupId, privateLayout, layoutId, portletId,
3585                                            
3586                                            start, end, orderByComparator
3587                                    };
3588                    }
3589    
3590                    List<JournalContentSearch> list = (List<JournalContentSearch>)FinderCacheUtil.getResult(finderPath,
3591                                    finderArgs, this);
3592    
3593                    if ((list != null) && !list.isEmpty()) {
3594                            for (JournalContentSearch journalContentSearch : list) {
3595                                    if ((groupId != journalContentSearch.getGroupId()) ||
3596                                                    (privateLayout != journalContentSearch.getPrivateLayout()) ||
3597                                                    (layoutId != journalContentSearch.getLayoutId()) ||
3598                                                    !Validator.equals(portletId,
3599                                                            journalContentSearch.getPortletId())) {
3600                                            list = null;
3601    
3602                                            break;
3603                                    }
3604                            }
3605                    }
3606    
3607                    if (list == null) {
3608                            StringBundler query = null;
3609    
3610                            if (orderByComparator != null) {
3611                                    query = new StringBundler(6 +
3612                                                    (orderByComparator.getOrderByFields().length * 3));
3613                            }
3614                            else {
3615                                    query = new StringBundler(6);
3616                            }
3617    
3618                            query.append(_SQL_SELECT_JOURNALCONTENTSEARCH_WHERE);
3619    
3620                            query.append(_FINDER_COLUMN_G_P_L_P_GROUPID_2);
3621    
3622                            query.append(_FINDER_COLUMN_G_P_L_P_PRIVATELAYOUT_2);
3623    
3624                            query.append(_FINDER_COLUMN_G_P_L_P_LAYOUTID_2);
3625    
3626                            boolean bindPortletId = false;
3627    
3628                            if (portletId == null) {
3629                                    query.append(_FINDER_COLUMN_G_P_L_P_PORTLETID_1);
3630                            }
3631                            else if (portletId.equals(StringPool.BLANK)) {
3632                                    query.append(_FINDER_COLUMN_G_P_L_P_PORTLETID_3);
3633                            }
3634                            else {
3635                                    bindPortletId = true;
3636    
3637                                    query.append(_FINDER_COLUMN_G_P_L_P_PORTLETID_2);
3638                            }
3639    
3640                            if (orderByComparator != null) {
3641                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3642                                            orderByComparator);
3643                            }
3644                            else
3645                             if (pagination) {
3646                                    query.append(JournalContentSearchModelImpl.ORDER_BY_JPQL);
3647                            }
3648    
3649                            String sql = query.toString();
3650    
3651                            Session session = null;
3652    
3653                            try {
3654                                    session = openSession();
3655    
3656                                    Query q = session.createQuery(sql);
3657    
3658                                    QueryPos qPos = QueryPos.getInstance(q);
3659    
3660                                    qPos.add(groupId);
3661    
3662                                    qPos.add(privateLayout);
3663    
3664                                    qPos.add(layoutId);
3665    
3666                                    if (bindPortletId) {
3667                                            qPos.add(portletId);
3668                                    }
3669    
3670                                    if (!pagination) {
3671                                            list = (List<JournalContentSearch>)QueryUtil.list(q,
3672                                                            getDialect(), start, end, false);
3673    
3674                                            Collections.sort(list);
3675    
3676                                            list = new UnmodifiableList<JournalContentSearch>(list);
3677                                    }
3678                                    else {
3679                                            list = (List<JournalContentSearch>)QueryUtil.list(q,
3680                                                            getDialect(), start, end);
3681                                    }
3682    
3683                                    cacheResult(list);
3684    
3685                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3686                            }
3687                            catch (Exception e) {
3688                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3689    
3690                                    throw processException(e);
3691                            }
3692                            finally {
3693                                    closeSession(session);
3694                            }
3695                    }
3696    
3697                    return list;
3698            }
3699    
3700            /**
3701             * Returns the first journal content search in the ordered set where groupId = &#63; and privateLayout = &#63; and layoutId = &#63; and portletId = &#63;.
3702             *
3703             * @param groupId the group ID
3704             * @param privateLayout the private layout
3705             * @param layoutId the layout ID
3706             * @param portletId the portlet ID
3707             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3708             * @return the first matching journal content search
3709             * @throws com.liferay.portlet.journal.NoSuchContentSearchException if a matching journal content search could not be found
3710             * @throws SystemException if a system exception occurred
3711             */
3712            @Override
3713            public JournalContentSearch findByG_P_L_P_First(long groupId,
3714                    boolean privateLayout, long layoutId, String portletId,
3715                    OrderByComparator orderByComparator)
3716                    throws NoSuchContentSearchException, SystemException {
3717                    JournalContentSearch journalContentSearch = fetchByG_P_L_P_First(groupId,
3718                                    privateLayout, layoutId, portletId, orderByComparator);
3719    
3720                    if (journalContentSearch != null) {
3721                            return journalContentSearch;
3722                    }
3723    
3724                    StringBundler msg = new StringBundler(10);
3725    
3726                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3727    
3728                    msg.append("groupId=");
3729                    msg.append(groupId);
3730    
3731                    msg.append(", privateLayout=");
3732                    msg.append(privateLayout);
3733    
3734                    msg.append(", layoutId=");
3735                    msg.append(layoutId);
3736    
3737                    msg.append(", portletId=");
3738                    msg.append(portletId);
3739    
3740                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3741    
3742                    throw new NoSuchContentSearchException(msg.toString());
3743            }
3744    
3745            /**
3746             * Returns the first journal content search in the ordered set where groupId = &#63; and privateLayout = &#63; and layoutId = &#63; and portletId = &#63;.
3747             *
3748             * @param groupId the group ID
3749             * @param privateLayout the private layout
3750             * @param layoutId the layout ID
3751             * @param portletId the portlet ID
3752             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3753             * @return the first matching journal content search, or <code>null</code> if a matching journal content search could not be found
3754             * @throws SystemException if a system exception occurred
3755             */
3756            @Override
3757            public JournalContentSearch fetchByG_P_L_P_First(long groupId,
3758                    boolean privateLayout, long layoutId, String portletId,
3759                    OrderByComparator orderByComparator) throws SystemException {
3760                    List<JournalContentSearch> list = findByG_P_L_P(groupId, privateLayout,
3761                                    layoutId, portletId, 0, 1, orderByComparator);
3762    
3763                    if (!list.isEmpty()) {
3764                            return list.get(0);
3765                    }
3766    
3767                    return null;
3768            }
3769    
3770            /**
3771             * Returns the last journal content search in the ordered set where groupId = &#63; and privateLayout = &#63; and layoutId = &#63; and portletId = &#63;.
3772             *
3773             * @param groupId the group ID
3774             * @param privateLayout the private layout
3775             * @param layoutId the layout ID
3776             * @param portletId the portlet ID
3777             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3778             * @return the last matching journal content search
3779             * @throws com.liferay.portlet.journal.NoSuchContentSearchException if a matching journal content search could not be found
3780             * @throws SystemException if a system exception occurred
3781             */
3782            @Override
3783            public JournalContentSearch findByG_P_L_P_Last(long groupId,
3784                    boolean privateLayout, long layoutId, String portletId,
3785                    OrderByComparator orderByComparator)
3786                    throws NoSuchContentSearchException, SystemException {
3787                    JournalContentSearch journalContentSearch = fetchByG_P_L_P_Last(groupId,
3788                                    privateLayout, layoutId, portletId, orderByComparator);
3789    
3790                    if (journalContentSearch != null) {
3791                            return journalContentSearch;
3792                    }
3793    
3794                    StringBundler msg = new StringBundler(10);
3795    
3796                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3797    
3798                    msg.append("groupId=");
3799                    msg.append(groupId);
3800    
3801                    msg.append(", privateLayout=");
3802                    msg.append(privateLayout);
3803    
3804                    msg.append(", layoutId=");
3805                    msg.append(layoutId);
3806    
3807                    msg.append(", portletId=");
3808                    msg.append(portletId);
3809    
3810                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3811    
3812                    throw new NoSuchContentSearchException(msg.toString());
3813            }
3814    
3815            /**
3816             * Returns the last journal content search in the ordered set where groupId = &#63; and privateLayout = &#63; and layoutId = &#63; and portletId = &#63;.
3817             *
3818             * @param groupId the group ID
3819             * @param privateLayout the private layout
3820             * @param layoutId the layout ID
3821             * @param portletId the portlet ID
3822             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3823             * @return the last matching journal content search, or <code>null</code> if a matching journal content search could not be found
3824             * @throws SystemException if a system exception occurred
3825             */
3826            @Override
3827            public JournalContentSearch fetchByG_P_L_P_Last(long groupId,
3828                    boolean privateLayout, long layoutId, String portletId,
3829                    OrderByComparator orderByComparator) throws SystemException {
3830                    int count = countByG_P_L_P(groupId, privateLayout, layoutId, portletId);
3831    
3832                    if (count == 0) {
3833                            return null;
3834                    }
3835    
3836                    List<JournalContentSearch> list = findByG_P_L_P(groupId, privateLayout,
3837                                    layoutId, portletId, count - 1, count, orderByComparator);
3838    
3839                    if (!list.isEmpty()) {
3840                            return list.get(0);
3841                    }
3842    
3843                    return null;
3844            }
3845    
3846            /**
3847             * Returns the journal content searchs before and after the current journal content search in the ordered set where groupId = &#63; and privateLayout = &#63; and layoutId = &#63; and portletId = &#63;.
3848             *
3849             * @param contentSearchId the primary key of the current journal content search
3850             * @param groupId the group ID
3851             * @param privateLayout the private layout
3852             * @param layoutId the layout ID
3853             * @param portletId the portlet ID
3854             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3855             * @return the previous, current, and next journal content search
3856             * @throws com.liferay.portlet.journal.NoSuchContentSearchException if a journal content search with the primary key could not be found
3857             * @throws SystemException if a system exception occurred
3858             */
3859            @Override
3860            public JournalContentSearch[] findByG_P_L_P_PrevAndNext(
3861                    long contentSearchId, long groupId, boolean privateLayout,
3862                    long layoutId, String portletId, OrderByComparator orderByComparator)
3863                    throws NoSuchContentSearchException, SystemException {
3864                    JournalContentSearch journalContentSearch = findByPrimaryKey(contentSearchId);
3865    
3866                    Session session = null;
3867    
3868                    try {
3869                            session = openSession();
3870    
3871                            JournalContentSearch[] array = new JournalContentSearchImpl[3];
3872    
3873                            array[0] = getByG_P_L_P_PrevAndNext(session, journalContentSearch,
3874                                            groupId, privateLayout, layoutId, portletId,
3875                                            orderByComparator, true);
3876    
3877                            array[1] = journalContentSearch;
3878    
3879                            array[2] = getByG_P_L_P_PrevAndNext(session, journalContentSearch,
3880                                            groupId, privateLayout, layoutId, portletId,
3881                                            orderByComparator, false);
3882    
3883                            return array;
3884                    }
3885                    catch (Exception e) {
3886                            throw processException(e);
3887                    }
3888                    finally {
3889                            closeSession(session);
3890                    }
3891            }
3892    
3893            protected JournalContentSearch getByG_P_L_P_PrevAndNext(Session session,
3894                    JournalContentSearch journalContentSearch, long groupId,
3895                    boolean privateLayout, long layoutId, String portletId,
3896                    OrderByComparator orderByComparator, boolean previous) {
3897                    StringBundler query = null;
3898    
3899                    if (orderByComparator != null) {
3900                            query = new StringBundler(6 +
3901                                            (orderByComparator.getOrderByFields().length * 6));
3902                    }
3903                    else {
3904                            query = new StringBundler(3);
3905                    }
3906    
3907                    query.append(_SQL_SELECT_JOURNALCONTENTSEARCH_WHERE);
3908    
3909                    query.append(_FINDER_COLUMN_G_P_L_P_GROUPID_2);
3910    
3911                    query.append(_FINDER_COLUMN_G_P_L_P_PRIVATELAYOUT_2);
3912    
3913                    query.append(_FINDER_COLUMN_G_P_L_P_LAYOUTID_2);
3914    
3915                    boolean bindPortletId = false;
3916    
3917                    if (portletId == null) {
3918                            query.append(_FINDER_COLUMN_G_P_L_P_PORTLETID_1);
3919                    }
3920                    else if (portletId.equals(StringPool.BLANK)) {
3921                            query.append(_FINDER_COLUMN_G_P_L_P_PORTLETID_3);
3922                    }
3923                    else {
3924                            bindPortletId = true;
3925    
3926                            query.append(_FINDER_COLUMN_G_P_L_P_PORTLETID_2);
3927                    }
3928    
3929                    if (orderByComparator != null) {
3930                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3931    
3932                            if (orderByConditionFields.length > 0) {
3933                                    query.append(WHERE_AND);
3934                            }
3935    
3936                            for (int i = 0; i < orderByConditionFields.length; i++) {
3937                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3938                                    query.append(orderByConditionFields[i]);
3939    
3940                                    if ((i + 1) < orderByConditionFields.length) {
3941                                            if (orderByComparator.isAscending() ^ previous) {
3942                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3943                                            }
3944                                            else {
3945                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3946                                            }
3947                                    }
3948                                    else {
3949                                            if (orderByComparator.isAscending() ^ previous) {
3950                                                    query.append(WHERE_GREATER_THAN);
3951                                            }
3952                                            else {
3953                                                    query.append(WHERE_LESSER_THAN);
3954                                            }
3955                                    }
3956                            }
3957    
3958                            query.append(ORDER_BY_CLAUSE);
3959    
3960                            String[] orderByFields = orderByComparator.getOrderByFields();
3961    
3962                            for (int i = 0; i < orderByFields.length; i++) {
3963                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3964                                    query.append(orderByFields[i]);
3965    
3966                                    if ((i + 1) < orderByFields.length) {
3967                                            if (orderByComparator.isAscending() ^ previous) {
3968                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3969                                            }
3970                                            else {
3971                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3972                                            }
3973                                    }
3974                                    else {
3975                                            if (orderByComparator.isAscending() ^ previous) {
3976                                                    query.append(ORDER_BY_ASC);
3977                                            }
3978                                            else {
3979                                                    query.append(ORDER_BY_DESC);
3980                                            }
3981                                    }
3982                            }
3983                    }
3984                    else {
3985                            query.append(JournalContentSearchModelImpl.ORDER_BY_JPQL);
3986                    }
3987    
3988                    String sql = query.toString();
3989    
3990                    Query q = session.createQuery(sql);
3991    
3992                    q.setFirstResult(0);
3993                    q.setMaxResults(2);
3994    
3995                    QueryPos qPos = QueryPos.getInstance(q);
3996    
3997                    qPos.add(groupId);
3998    
3999                    qPos.add(privateLayout);
4000    
4001                    qPos.add(layoutId);
4002    
4003                    if (bindPortletId) {
4004                            qPos.add(portletId);
4005                    }
4006    
4007                    if (orderByComparator != null) {
4008                            Object[] values = orderByComparator.getOrderByConditionValues(journalContentSearch);
4009    
4010                            for (Object value : values) {
4011                                    qPos.add(value);
4012                            }
4013                    }
4014    
4015                    List<JournalContentSearch> list = q.list();
4016    
4017                    if (list.size() == 2) {
4018                            return list.get(1);
4019                    }
4020                    else {
4021                            return null;
4022                    }
4023            }
4024    
4025            /**
4026             * Removes all the journal content searchs where groupId = &#63; and privateLayout = &#63; and layoutId = &#63; and portletId = &#63; from the database.
4027             *
4028             * @param groupId the group ID
4029             * @param privateLayout the private layout
4030             * @param layoutId the layout ID
4031             * @param portletId the portlet ID
4032             * @throws SystemException if a system exception occurred
4033             */
4034            @Override
4035            public void removeByG_P_L_P(long groupId, boolean privateLayout,
4036                    long layoutId, String portletId) throws SystemException {
4037                    for (JournalContentSearch journalContentSearch : findByG_P_L_P(
4038                                    groupId, privateLayout, layoutId, portletId, QueryUtil.ALL_POS,
4039                                    QueryUtil.ALL_POS, null)) {
4040                            remove(journalContentSearch);
4041                    }
4042            }
4043    
4044            /**
4045             * Returns the number of journal content searchs where groupId = &#63; and privateLayout = &#63; and layoutId = &#63; and portletId = &#63;.
4046             *
4047             * @param groupId the group ID
4048             * @param privateLayout the private layout
4049             * @param layoutId the layout ID
4050             * @param portletId the portlet ID
4051             * @return the number of matching journal content searchs
4052             * @throws SystemException if a system exception occurred
4053             */
4054            @Override
4055            public int countByG_P_L_P(long groupId, boolean privateLayout,
4056                    long layoutId, String portletId) throws SystemException {
4057                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_L_P;
4058    
4059                    Object[] finderArgs = new Object[] {
4060                                    groupId, privateLayout, layoutId, portletId
4061                            };
4062    
4063                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4064                                    this);
4065    
4066                    if (count == null) {
4067                            StringBundler query = new StringBundler(5);
4068    
4069                            query.append(_SQL_COUNT_JOURNALCONTENTSEARCH_WHERE);
4070    
4071                            query.append(_FINDER_COLUMN_G_P_L_P_GROUPID_2);
4072    
4073                            query.append(_FINDER_COLUMN_G_P_L_P_PRIVATELAYOUT_2);
4074    
4075                            query.append(_FINDER_COLUMN_G_P_L_P_LAYOUTID_2);
4076    
4077                            boolean bindPortletId = false;
4078    
4079                            if (portletId == null) {
4080                                    query.append(_FINDER_COLUMN_G_P_L_P_PORTLETID_1);
4081                            }
4082                            else if (portletId.equals(StringPool.BLANK)) {
4083                                    query.append(_FINDER_COLUMN_G_P_L_P_PORTLETID_3);
4084                            }
4085                            else {
4086                                    bindPortletId = true;
4087    
4088                                    query.append(_FINDER_COLUMN_G_P_L_P_PORTLETID_2);
4089                            }
4090    
4091                            String sql = query.toString();
4092    
4093                            Session session = null;
4094    
4095                            try {
4096                                    session = openSession();
4097    
4098                                    Query q = session.createQuery(sql);
4099    
4100                                    QueryPos qPos = QueryPos.getInstance(q);
4101    
4102                                    qPos.add(groupId);
4103    
4104                                    qPos.add(privateLayout);
4105    
4106                                    qPos.add(layoutId);
4107    
4108                                    if (bindPortletId) {
4109                                            qPos.add(portletId);
4110                                    }
4111    
4112                                    count = (Long)q.uniqueResult();
4113    
4114                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4115                            }
4116                            catch (Exception e) {
4117                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4118    
4119                                    throw processException(e);
4120                            }
4121                            finally {
4122                                    closeSession(session);
4123                            }
4124                    }
4125    
4126                    return count.intValue();
4127            }
4128    
4129            private static final String _FINDER_COLUMN_G_P_L_P_GROUPID_2 = "journalContentSearch.groupId = ? AND ";
4130            private static final String _FINDER_COLUMN_G_P_L_P_PRIVATELAYOUT_2 = "journalContentSearch.privateLayout = ? AND ";
4131            private static final String _FINDER_COLUMN_G_P_L_P_LAYOUTID_2 = "journalContentSearch.layoutId = ? AND ";
4132            private static final String _FINDER_COLUMN_G_P_L_P_PORTLETID_1 = "journalContentSearch.portletId IS NULL";
4133            private static final String _FINDER_COLUMN_G_P_L_P_PORTLETID_2 = "journalContentSearch.portletId = ?";
4134            private static final String _FINDER_COLUMN_G_P_L_P_PORTLETID_3 = "(journalContentSearch.portletId IS NULL OR journalContentSearch.portletId = '')";
4135            public static final FinderPath FINDER_PATH_FETCH_BY_G_P_L_P_A = new FinderPath(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
4136                            JournalContentSearchModelImpl.FINDER_CACHE_ENABLED,
4137                            JournalContentSearchImpl.class, FINDER_CLASS_NAME_ENTITY,
4138                            "fetchByG_P_L_P_A",
4139                            new String[] {
4140                                    Long.class.getName(), Boolean.class.getName(),
4141                                    Long.class.getName(), String.class.getName(),
4142                                    String.class.getName()
4143                            },
4144                            JournalContentSearchModelImpl.GROUPID_COLUMN_BITMASK |
4145                            JournalContentSearchModelImpl.PRIVATELAYOUT_COLUMN_BITMASK |
4146                            JournalContentSearchModelImpl.LAYOUTID_COLUMN_BITMASK |
4147                            JournalContentSearchModelImpl.PORTLETID_COLUMN_BITMASK |
4148                            JournalContentSearchModelImpl.ARTICLEID_COLUMN_BITMASK);
4149            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_L_P_A = new FinderPath(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
4150                            JournalContentSearchModelImpl.FINDER_CACHE_ENABLED, Long.class,
4151                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_L_P_A",
4152                            new String[] {
4153                                    Long.class.getName(), Boolean.class.getName(),
4154                                    Long.class.getName(), String.class.getName(),
4155                                    String.class.getName()
4156                            });
4157    
4158            /**
4159             * Returns the journal content search where groupId = &#63; and privateLayout = &#63; and layoutId = &#63; and portletId = &#63; and articleId = &#63; or throws a {@link com.liferay.portlet.journal.NoSuchContentSearchException} if it could not be found.
4160             *
4161             * @param groupId the group ID
4162             * @param privateLayout the private layout
4163             * @param layoutId the layout ID
4164             * @param portletId the portlet ID
4165             * @param articleId the article ID
4166             * @return the matching journal content search
4167             * @throws com.liferay.portlet.journal.NoSuchContentSearchException if a matching journal content search could not be found
4168             * @throws SystemException if a system exception occurred
4169             */
4170            @Override
4171            public JournalContentSearch findByG_P_L_P_A(long groupId,
4172                    boolean privateLayout, long layoutId, String portletId, String articleId)
4173                    throws NoSuchContentSearchException, SystemException {
4174                    JournalContentSearch journalContentSearch = fetchByG_P_L_P_A(groupId,
4175                                    privateLayout, layoutId, portletId, articleId);
4176    
4177                    if (journalContentSearch == null) {
4178                            StringBundler msg = new StringBundler(12);
4179    
4180                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4181    
4182                            msg.append("groupId=");
4183                            msg.append(groupId);
4184    
4185                            msg.append(", privateLayout=");
4186                            msg.append(privateLayout);
4187    
4188                            msg.append(", layoutId=");
4189                            msg.append(layoutId);
4190    
4191                            msg.append(", portletId=");
4192                            msg.append(portletId);
4193    
4194                            msg.append(", articleId=");
4195                            msg.append(articleId);
4196    
4197                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4198    
4199                            if (_log.isWarnEnabled()) {
4200                                    _log.warn(msg.toString());
4201                            }
4202    
4203                            throw new NoSuchContentSearchException(msg.toString());
4204                    }
4205    
4206                    return journalContentSearch;
4207            }
4208    
4209            /**
4210             * Returns the journal content search where groupId = &#63; and privateLayout = &#63; and layoutId = &#63; and portletId = &#63; and articleId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
4211             *
4212             * @param groupId the group ID
4213             * @param privateLayout the private layout
4214             * @param layoutId the layout ID
4215             * @param portletId the portlet ID
4216             * @param articleId the article ID
4217             * @return the matching journal content search, or <code>null</code> if a matching journal content search could not be found
4218             * @throws SystemException if a system exception occurred
4219             */
4220            @Override
4221            public JournalContentSearch fetchByG_P_L_P_A(long groupId,
4222                    boolean privateLayout, long layoutId, String portletId, String articleId)
4223                    throws SystemException {
4224                    return fetchByG_P_L_P_A(groupId, privateLayout, layoutId, portletId,
4225                            articleId, true);
4226            }
4227    
4228            /**
4229             * Returns the journal content search where groupId = &#63; and privateLayout = &#63; and layoutId = &#63; and portletId = &#63; and articleId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
4230             *
4231             * @param groupId the group ID
4232             * @param privateLayout the private layout
4233             * @param layoutId the layout ID
4234             * @param portletId the portlet ID
4235             * @param articleId the article ID
4236             * @param retrieveFromCache whether to use the finder cache
4237             * @return the matching journal content search, or <code>null</code> if a matching journal content search could not be found
4238             * @throws SystemException if a system exception occurred
4239             */
4240            @Override
4241            public JournalContentSearch fetchByG_P_L_P_A(long groupId,
4242                    boolean privateLayout, long layoutId, String portletId,
4243                    String articleId, boolean retrieveFromCache) throws SystemException {
4244                    Object[] finderArgs = new Object[] {
4245                                    groupId, privateLayout, layoutId, portletId, articleId
4246                            };
4247    
4248                    Object result = null;
4249    
4250                    if (retrieveFromCache) {
4251                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_P_L_P_A,
4252                                            finderArgs, this);
4253                    }
4254    
4255                    if (result instanceof JournalContentSearch) {
4256                            JournalContentSearch journalContentSearch = (JournalContentSearch)result;
4257    
4258                            if ((groupId != journalContentSearch.getGroupId()) ||
4259                                            (privateLayout != journalContentSearch.getPrivateLayout()) ||
4260                                            (layoutId != journalContentSearch.getLayoutId()) ||
4261                                            !Validator.equals(portletId,
4262                                                    journalContentSearch.getPortletId()) ||
4263                                            !Validator.equals(articleId,
4264                                                    journalContentSearch.getArticleId())) {
4265                                    result = null;
4266                            }
4267                    }
4268    
4269                    if (result == null) {
4270                            StringBundler query = new StringBundler(7);
4271    
4272                            query.append(_SQL_SELECT_JOURNALCONTENTSEARCH_WHERE);
4273    
4274                            query.append(_FINDER_COLUMN_G_P_L_P_A_GROUPID_2);
4275    
4276                            query.append(_FINDER_COLUMN_G_P_L_P_A_PRIVATELAYOUT_2);
4277    
4278                            query.append(_FINDER_COLUMN_G_P_L_P_A_LAYOUTID_2);
4279    
4280                            boolean bindPortletId = false;
4281    
4282                            if (portletId == null) {
4283                                    query.append(_FINDER_COLUMN_G_P_L_P_A_PORTLETID_1);
4284                            }
4285                            else if (portletId.equals(StringPool.BLANK)) {
4286                                    query.append(_FINDER_COLUMN_G_P_L_P_A_PORTLETID_3);
4287                            }
4288                            else {
4289                                    bindPortletId = true;
4290    
4291                                    query.append(_FINDER_COLUMN_G_P_L_P_A_PORTLETID_2);
4292                            }
4293    
4294                            boolean bindArticleId = false;
4295    
4296                            if (articleId == null) {
4297                                    query.append(_FINDER_COLUMN_G_P_L_P_A_ARTICLEID_1);
4298                            }
4299                            else if (articleId.equals(StringPool.BLANK)) {
4300                                    query.append(_FINDER_COLUMN_G_P_L_P_A_ARTICLEID_3);
4301                            }
4302                            else {
4303                                    bindArticleId = true;
4304    
4305                                    query.append(_FINDER_COLUMN_G_P_L_P_A_ARTICLEID_2);
4306                            }
4307    
4308                            String sql = query.toString();
4309    
4310                            Session session = null;
4311    
4312                            try {
4313                                    session = openSession();
4314    
4315                                    Query q = session.createQuery(sql);
4316    
4317                                    QueryPos qPos = QueryPos.getInstance(q);
4318    
4319                                    qPos.add(groupId);
4320    
4321                                    qPos.add(privateLayout);
4322    
4323                                    qPos.add(layoutId);
4324    
4325                                    if (bindPortletId) {
4326                                            qPos.add(portletId);
4327                                    }
4328    
4329                                    if (bindArticleId) {
4330                                            qPos.add(articleId);
4331                                    }
4332    
4333                                    List<JournalContentSearch> list = q.list();
4334    
4335                                    if (list.isEmpty()) {
4336                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_L_P_A,
4337                                                    finderArgs, list);
4338                                    }
4339                                    else {
4340                                            JournalContentSearch journalContentSearch = list.get(0);
4341    
4342                                            result = journalContentSearch;
4343    
4344                                            cacheResult(journalContentSearch);
4345    
4346                                            if ((journalContentSearch.getGroupId() != groupId) ||
4347                                                            (journalContentSearch.getPrivateLayout() != privateLayout) ||
4348                                                            (journalContentSearch.getLayoutId() != layoutId) ||
4349                                                            (journalContentSearch.getPortletId() == null) ||
4350                                                            !journalContentSearch.getPortletId()
4351                                                                                                             .equals(portletId) ||
4352                                                            (journalContentSearch.getArticleId() == null) ||
4353                                                            !journalContentSearch.getArticleId()
4354                                                                                                             .equals(articleId)) {
4355                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_L_P_A,
4356                                                            finderArgs, journalContentSearch);
4357                                            }
4358                                    }
4359                            }
4360                            catch (Exception e) {
4361                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_L_P_A,
4362                                            finderArgs);
4363    
4364                                    throw processException(e);
4365                            }
4366                            finally {
4367                                    closeSession(session);
4368                            }
4369                    }
4370    
4371                    if (result instanceof List<?>) {
4372                            return null;
4373                    }
4374                    else {
4375                            return (JournalContentSearch)result;
4376                    }
4377            }
4378    
4379            /**
4380             * Removes the journal content search where groupId = &#63; and privateLayout = &#63; and layoutId = &#63; and portletId = &#63; and articleId = &#63; from the database.
4381             *
4382             * @param groupId the group ID
4383             * @param privateLayout the private layout
4384             * @param layoutId the layout ID
4385             * @param portletId the portlet ID
4386             * @param articleId the article ID
4387             * @return the journal content search that was removed
4388             * @throws SystemException if a system exception occurred
4389             */
4390            @Override
4391            public JournalContentSearch removeByG_P_L_P_A(long groupId,
4392                    boolean privateLayout, long layoutId, String portletId, String articleId)
4393                    throws NoSuchContentSearchException, SystemException {
4394                    JournalContentSearch journalContentSearch = findByG_P_L_P_A(groupId,
4395                                    privateLayout, layoutId, portletId, articleId);
4396    
4397                    return remove(journalContentSearch);
4398            }
4399    
4400            /**
4401             * Returns the number of journal content searchs where groupId = &#63; and privateLayout = &#63; and layoutId = &#63; and portletId = &#63; and articleId = &#63;.
4402             *
4403             * @param groupId the group ID
4404             * @param privateLayout the private layout
4405             * @param layoutId the layout ID
4406             * @param portletId the portlet ID
4407             * @param articleId the article ID
4408             * @return the number of matching journal content searchs
4409             * @throws SystemException if a system exception occurred
4410             */
4411            @Override
4412            public int countByG_P_L_P_A(long groupId, boolean privateLayout,
4413                    long layoutId, String portletId, String articleId)
4414                    throws SystemException {
4415                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_L_P_A;
4416    
4417                    Object[] finderArgs = new Object[] {
4418                                    groupId, privateLayout, layoutId, portletId, articleId
4419                            };
4420    
4421                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4422                                    this);
4423    
4424                    if (count == null) {
4425                            StringBundler query = new StringBundler(6);
4426    
4427                            query.append(_SQL_COUNT_JOURNALCONTENTSEARCH_WHERE);
4428    
4429                            query.append(_FINDER_COLUMN_G_P_L_P_A_GROUPID_2);
4430    
4431                            query.append(_FINDER_COLUMN_G_P_L_P_A_PRIVATELAYOUT_2);
4432    
4433                            query.append(_FINDER_COLUMN_G_P_L_P_A_LAYOUTID_2);
4434    
4435                            boolean bindPortletId = false;
4436    
4437                            if (portletId == null) {
4438                                    query.append(_FINDER_COLUMN_G_P_L_P_A_PORTLETID_1);
4439                            }
4440                            else if (portletId.equals(StringPool.BLANK)) {
4441                                    query.append(_FINDER_COLUMN_G_P_L_P_A_PORTLETID_3);
4442                            }
4443                            else {
4444                                    bindPortletId = true;
4445    
4446                                    query.append(_FINDER_COLUMN_G_P_L_P_A_PORTLETID_2);
4447                            }
4448    
4449                            boolean bindArticleId = false;
4450    
4451                            if (articleId == null) {
4452                                    query.append(_FINDER_COLUMN_G_P_L_P_A_ARTICLEID_1);
4453                            }
4454                            else if (articleId.equals(StringPool.BLANK)) {
4455                                    query.append(_FINDER_COLUMN_G_P_L_P_A_ARTICLEID_3);
4456                            }
4457                            else {
4458                                    bindArticleId = true;
4459    
4460                                    query.append(_FINDER_COLUMN_G_P_L_P_A_ARTICLEID_2);
4461                            }
4462    
4463                            String sql = query.toString();
4464    
4465                            Session session = null;
4466    
4467                            try {
4468                                    session = openSession();
4469    
4470                                    Query q = session.createQuery(sql);
4471    
4472                                    QueryPos qPos = QueryPos.getInstance(q);
4473    
4474                                    qPos.add(groupId);
4475    
4476                                    qPos.add(privateLayout);
4477    
4478                                    qPos.add(layoutId);
4479    
4480                                    if (bindPortletId) {
4481                                            qPos.add(portletId);
4482                                    }
4483    
4484                                    if (bindArticleId) {
4485                                            qPos.add(articleId);
4486                                    }
4487    
4488                                    count = (Long)q.uniqueResult();
4489    
4490                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4491                            }
4492                            catch (Exception e) {
4493                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4494    
4495                                    throw processException(e);
4496                            }
4497                            finally {
4498                                    closeSession(session);
4499                            }
4500                    }
4501    
4502                    return count.intValue();
4503            }
4504    
4505            private static final String _FINDER_COLUMN_G_P_L_P_A_GROUPID_2 = "journalContentSearch.groupId = ? AND ";
4506            private static final String _FINDER_COLUMN_G_P_L_P_A_PRIVATELAYOUT_2 = "journalContentSearch.privateLayout = ? AND ";
4507            private static final String _FINDER_COLUMN_G_P_L_P_A_LAYOUTID_2 = "journalContentSearch.layoutId = ? AND ";
4508            private static final String _FINDER_COLUMN_G_P_L_P_A_PORTLETID_1 = "journalContentSearch.portletId IS NULL AND ";
4509            private static final String _FINDER_COLUMN_G_P_L_P_A_PORTLETID_2 = "journalContentSearch.portletId = ? AND ";
4510            private static final String _FINDER_COLUMN_G_P_L_P_A_PORTLETID_3 = "(journalContentSearch.portletId IS NULL OR journalContentSearch.portletId = '') AND ";
4511            private static final String _FINDER_COLUMN_G_P_L_P_A_ARTICLEID_1 = "journalContentSearch.articleId IS NULL";
4512            private static final String _FINDER_COLUMN_G_P_L_P_A_ARTICLEID_2 = "journalContentSearch.articleId = ?";
4513            private static final String _FINDER_COLUMN_G_P_L_P_A_ARTICLEID_3 = "(journalContentSearch.articleId IS NULL OR journalContentSearch.articleId = '')";
4514    
4515            public JournalContentSearchPersistenceImpl() {
4516                    setModelClass(JournalContentSearch.class);
4517            }
4518    
4519            /**
4520             * Caches the journal content search in the entity cache if it is enabled.
4521             *
4522             * @param journalContentSearch the journal content search
4523             */
4524            @Override
4525            public void cacheResult(JournalContentSearch journalContentSearch) {
4526                    EntityCacheUtil.putResult(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
4527                            JournalContentSearchImpl.class,
4528                            journalContentSearch.getPrimaryKey(), journalContentSearch);
4529    
4530                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_L_P_A,
4531                            new Object[] {
4532                                    journalContentSearch.getGroupId(),
4533                                    journalContentSearch.getPrivateLayout(),
4534                                    journalContentSearch.getLayoutId(),
4535                                    journalContentSearch.getPortletId(),
4536                                    journalContentSearch.getArticleId()
4537                            }, journalContentSearch);
4538    
4539                    journalContentSearch.resetOriginalValues();
4540            }
4541    
4542            /**
4543             * Caches the journal content searchs in the entity cache if it is enabled.
4544             *
4545             * @param journalContentSearchs the journal content searchs
4546             */
4547            @Override
4548            public void cacheResult(List<JournalContentSearch> journalContentSearchs) {
4549                    for (JournalContentSearch journalContentSearch : journalContentSearchs) {
4550                            if (EntityCacheUtil.getResult(
4551                                                    JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
4552                                                    JournalContentSearchImpl.class,
4553                                                    journalContentSearch.getPrimaryKey()) == null) {
4554                                    cacheResult(journalContentSearch);
4555                            }
4556                            else {
4557                                    journalContentSearch.resetOriginalValues();
4558                            }
4559                    }
4560            }
4561    
4562            /**
4563             * Clears the cache for all journal content searchs.
4564             *
4565             * <p>
4566             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
4567             * </p>
4568             */
4569            @Override
4570            public void clearCache() {
4571                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
4572                            CacheRegistryUtil.clear(JournalContentSearchImpl.class.getName());
4573                    }
4574    
4575                    EntityCacheUtil.clearCache(JournalContentSearchImpl.class.getName());
4576    
4577                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
4578                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4579                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4580            }
4581    
4582            /**
4583             * Clears the cache for the journal content search.
4584             *
4585             * <p>
4586             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
4587             * </p>
4588             */
4589            @Override
4590            public void clearCache(JournalContentSearch journalContentSearch) {
4591                    EntityCacheUtil.removeResult(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
4592                            JournalContentSearchImpl.class, journalContentSearch.getPrimaryKey());
4593    
4594                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4595                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4596    
4597                    clearUniqueFindersCache(journalContentSearch);
4598            }
4599    
4600            @Override
4601            public void clearCache(List<JournalContentSearch> journalContentSearchs) {
4602                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4603                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4604    
4605                    for (JournalContentSearch journalContentSearch : journalContentSearchs) {
4606                            EntityCacheUtil.removeResult(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
4607                                    JournalContentSearchImpl.class,
4608                                    journalContentSearch.getPrimaryKey());
4609    
4610                            clearUniqueFindersCache(journalContentSearch);
4611                    }
4612            }
4613    
4614            protected void cacheUniqueFindersCache(
4615                    JournalContentSearch journalContentSearch) {
4616                    if (journalContentSearch.isNew()) {
4617                            Object[] args = new Object[] {
4618                                            journalContentSearch.getGroupId(),
4619                                            journalContentSearch.getPrivateLayout(),
4620                                            journalContentSearch.getLayoutId(),
4621                                            journalContentSearch.getPortletId(),
4622                                            journalContentSearch.getArticleId()
4623                                    };
4624    
4625                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_L_P_A, args,
4626                                    Long.valueOf(1));
4627                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_L_P_A, args,
4628                                    journalContentSearch);
4629                    }
4630                    else {
4631                            JournalContentSearchModelImpl journalContentSearchModelImpl = (JournalContentSearchModelImpl)journalContentSearch;
4632    
4633                            if ((journalContentSearchModelImpl.getColumnBitmask() &
4634                                            FINDER_PATH_FETCH_BY_G_P_L_P_A.getColumnBitmask()) != 0) {
4635                                    Object[] args = new Object[] {
4636                                                    journalContentSearch.getGroupId(),
4637                                                    journalContentSearch.getPrivateLayout(),
4638                                                    journalContentSearch.getLayoutId(),
4639                                                    journalContentSearch.getPortletId(),
4640                                                    journalContentSearch.getArticleId()
4641                                            };
4642    
4643                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_L_P_A, args,
4644                                            Long.valueOf(1));
4645                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_L_P_A, args,
4646                                            journalContentSearch);
4647                            }
4648                    }
4649            }
4650    
4651            protected void clearUniqueFindersCache(
4652                    JournalContentSearch journalContentSearch) {
4653                    JournalContentSearchModelImpl journalContentSearchModelImpl = (JournalContentSearchModelImpl)journalContentSearch;
4654    
4655                    Object[] args = new Object[] {
4656                                    journalContentSearch.getGroupId(),
4657                                    journalContentSearch.getPrivateLayout(),
4658                                    journalContentSearch.getLayoutId(),
4659                                    journalContentSearch.getPortletId(),
4660                                    journalContentSearch.getArticleId()
4661                            };
4662    
4663                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_L_P_A, args);
4664                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_L_P_A, args);
4665    
4666                    if ((journalContentSearchModelImpl.getColumnBitmask() &
4667                                    FINDER_PATH_FETCH_BY_G_P_L_P_A.getColumnBitmask()) != 0) {
4668                            args = new Object[] {
4669                                            journalContentSearchModelImpl.getOriginalGroupId(),
4670                                            journalContentSearchModelImpl.getOriginalPrivateLayout(),
4671                                            journalContentSearchModelImpl.getOriginalLayoutId(),
4672                                            journalContentSearchModelImpl.getOriginalPortletId(),
4673                                            journalContentSearchModelImpl.getOriginalArticleId()
4674                                    };
4675    
4676                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_L_P_A, args);
4677                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_L_P_A, args);
4678                    }
4679            }
4680    
4681            /**
4682             * Creates a new journal content search with the primary key. Does not add the journal content search to the database.
4683             *
4684             * @param contentSearchId the primary key for the new journal content search
4685             * @return the new journal content search
4686             */
4687            @Override
4688            public JournalContentSearch create(long contentSearchId) {
4689                    JournalContentSearch journalContentSearch = new JournalContentSearchImpl();
4690    
4691                    journalContentSearch.setNew(true);
4692                    journalContentSearch.setPrimaryKey(contentSearchId);
4693    
4694                    return journalContentSearch;
4695            }
4696    
4697            /**
4698             * Removes the journal content search with the primary key from the database. Also notifies the appropriate model listeners.
4699             *
4700             * @param contentSearchId the primary key of the journal content search
4701             * @return the journal content search that was removed
4702             * @throws com.liferay.portlet.journal.NoSuchContentSearchException if a journal content search with the primary key could not be found
4703             * @throws SystemException if a system exception occurred
4704             */
4705            @Override
4706            public JournalContentSearch remove(long contentSearchId)
4707                    throws NoSuchContentSearchException, SystemException {
4708                    return remove((Serializable)contentSearchId);
4709            }
4710    
4711            /**
4712             * Removes the journal content search with the primary key from the database. Also notifies the appropriate model listeners.
4713             *
4714             * @param primaryKey the primary key of the journal content search
4715             * @return the journal content search that was removed
4716             * @throws com.liferay.portlet.journal.NoSuchContentSearchException if a journal content search with the primary key could not be found
4717             * @throws SystemException if a system exception occurred
4718             */
4719            @Override
4720            public JournalContentSearch remove(Serializable primaryKey)
4721                    throws NoSuchContentSearchException, SystemException {
4722                    Session session = null;
4723    
4724                    try {
4725                            session = openSession();
4726    
4727                            JournalContentSearch journalContentSearch = (JournalContentSearch)session.get(JournalContentSearchImpl.class,
4728                                            primaryKey);
4729    
4730                            if (journalContentSearch == null) {
4731                                    if (_log.isWarnEnabled()) {
4732                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4733                                    }
4734    
4735                                    throw new NoSuchContentSearchException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4736                                            primaryKey);
4737                            }
4738    
4739                            return remove(journalContentSearch);
4740                    }
4741                    catch (NoSuchContentSearchException nsee) {
4742                            throw nsee;
4743                    }
4744                    catch (Exception e) {
4745                            throw processException(e);
4746                    }
4747                    finally {
4748                            closeSession(session);
4749                    }
4750            }
4751    
4752            @Override
4753            protected JournalContentSearch removeImpl(
4754                    JournalContentSearch journalContentSearch) throws SystemException {
4755                    journalContentSearch = toUnwrappedModel(journalContentSearch);
4756    
4757                    Session session = null;
4758    
4759                    try {
4760                            session = openSession();
4761    
4762                            if (!session.contains(journalContentSearch)) {
4763                                    journalContentSearch = (JournalContentSearch)session.get(JournalContentSearchImpl.class,
4764                                                    journalContentSearch.getPrimaryKeyObj());
4765                            }
4766    
4767                            if (journalContentSearch != null) {
4768                                    session.delete(journalContentSearch);
4769                            }
4770                    }
4771                    catch (Exception e) {
4772                            throw processException(e);
4773                    }
4774                    finally {
4775                            closeSession(session);
4776                    }
4777    
4778                    if (journalContentSearch != null) {
4779                            clearCache(journalContentSearch);
4780                    }
4781    
4782                    return journalContentSearch;
4783            }
4784    
4785            @Override
4786            public JournalContentSearch updateImpl(
4787                    com.liferay.portlet.journal.model.JournalContentSearch journalContentSearch)
4788                    throws SystemException {
4789                    journalContentSearch = toUnwrappedModel(journalContentSearch);
4790    
4791                    boolean isNew = journalContentSearch.isNew();
4792    
4793                    JournalContentSearchModelImpl journalContentSearchModelImpl = (JournalContentSearchModelImpl)journalContentSearch;
4794    
4795                    Session session = null;
4796    
4797                    try {
4798                            session = openSession();
4799    
4800                            if (journalContentSearch.isNew()) {
4801                                    session.save(journalContentSearch);
4802    
4803                                    journalContentSearch.setNew(false);
4804                            }
4805                            else {
4806                                    session.merge(journalContentSearch);
4807                            }
4808                    }
4809                    catch (Exception e) {
4810                            throw processException(e);
4811                    }
4812                    finally {
4813                            closeSession(session);
4814                    }
4815    
4816                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4817    
4818                    if (isNew || !JournalContentSearchModelImpl.COLUMN_BITMASK_ENABLED) {
4819                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4820                    }
4821    
4822                    else {
4823                            if ((journalContentSearchModelImpl.getColumnBitmask() &
4824                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PORTLETID.getColumnBitmask()) != 0) {
4825                                    Object[] args = new Object[] {
4826                                                    journalContentSearchModelImpl.getOriginalPortletId()
4827                                            };
4828    
4829                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_PORTLETID,
4830                                            args);
4831                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PORTLETID,
4832                                            args);
4833    
4834                                    args = new Object[] { journalContentSearchModelImpl.getPortletId() };
4835    
4836                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_PORTLETID,
4837                                            args);
4838                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PORTLETID,
4839                                            args);
4840                            }
4841    
4842                            if ((journalContentSearchModelImpl.getColumnBitmask() &
4843                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ARTICLEID.getColumnBitmask()) != 0) {
4844                                    Object[] args = new Object[] {
4845                                                    journalContentSearchModelImpl.getOriginalArticleId()
4846                                            };
4847    
4848                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ARTICLEID,
4849                                            args);
4850                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ARTICLEID,
4851                                            args);
4852    
4853                                    args = new Object[] { journalContentSearchModelImpl.getArticleId() };
4854    
4855                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ARTICLEID,
4856                                            args);
4857                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ARTICLEID,
4858                                            args);
4859                            }
4860    
4861                            if ((journalContentSearchModelImpl.getColumnBitmask() &
4862                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P.getColumnBitmask()) != 0) {
4863                                    Object[] args = new Object[] {
4864                                                    journalContentSearchModelImpl.getOriginalGroupId(),
4865                                                    journalContentSearchModelImpl.getOriginalPrivateLayout()
4866                                            };
4867    
4868                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
4869                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
4870                                            args);
4871    
4872                                    args = new Object[] {
4873                                                    journalContentSearchModelImpl.getGroupId(),
4874                                                    journalContentSearchModelImpl.getPrivateLayout()
4875                                            };
4876    
4877                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
4878                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
4879                                            args);
4880                            }
4881    
4882                            if ((journalContentSearchModelImpl.getColumnBitmask() &
4883                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A.getColumnBitmask()) != 0) {
4884                                    Object[] args = new Object[] {
4885                                                    journalContentSearchModelImpl.getOriginalGroupId(),
4886                                                    journalContentSearchModelImpl.getOriginalArticleId()
4887                                            };
4888    
4889                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_A, args);
4890                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A,
4891                                            args);
4892    
4893                                    args = new Object[] {
4894                                                    journalContentSearchModelImpl.getGroupId(),
4895                                                    journalContentSearchModelImpl.getArticleId()
4896                                            };
4897    
4898                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_A, args);
4899                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A,
4900                                            args);
4901                            }
4902    
4903                            if ((journalContentSearchModelImpl.getColumnBitmask() &
4904                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_L.getColumnBitmask()) != 0) {
4905                                    Object[] args = new Object[] {
4906                                                    journalContentSearchModelImpl.getOriginalGroupId(),
4907                                                    journalContentSearchModelImpl.getOriginalPrivateLayout(),
4908                                                    journalContentSearchModelImpl.getOriginalLayoutId()
4909                                            };
4910    
4911                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_L, args);
4912                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_L,
4913                                            args);
4914    
4915                                    args = new Object[] {
4916                                                    journalContentSearchModelImpl.getGroupId(),
4917                                                    journalContentSearchModelImpl.getPrivateLayout(),
4918                                                    journalContentSearchModelImpl.getLayoutId()
4919                                            };
4920    
4921                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_L, args);
4922                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_L,
4923                                            args);
4924                            }
4925    
4926                            if ((journalContentSearchModelImpl.getColumnBitmask() &
4927                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_A.getColumnBitmask()) != 0) {
4928                                    Object[] args = new Object[] {
4929                                                    journalContentSearchModelImpl.getOriginalGroupId(),
4930                                                    journalContentSearchModelImpl.getOriginalPrivateLayout(),
4931                                                    journalContentSearchModelImpl.getOriginalArticleId()
4932                                            };
4933    
4934                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_A, args);
4935                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_A,
4936                                            args);
4937    
4938                                    args = new Object[] {
4939                                                    journalContentSearchModelImpl.getGroupId(),
4940                                                    journalContentSearchModelImpl.getPrivateLayout(),
4941                                                    journalContentSearchModelImpl.getArticleId()
4942                                            };
4943    
4944                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_A, args);
4945                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_A,
4946                                            args);
4947                            }
4948    
4949                            if ((journalContentSearchModelImpl.getColumnBitmask() &
4950                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_L_P.getColumnBitmask()) != 0) {
4951                                    Object[] args = new Object[] {
4952                                                    journalContentSearchModelImpl.getOriginalGroupId(),
4953                                                    journalContentSearchModelImpl.getOriginalPrivateLayout(),
4954                                                    journalContentSearchModelImpl.getOriginalLayoutId(),
4955                                                    journalContentSearchModelImpl.getOriginalPortletId()
4956                                            };
4957    
4958                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_L_P, args);
4959                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_L_P,
4960                                            args);
4961    
4962                                    args = new Object[] {
4963                                                    journalContentSearchModelImpl.getGroupId(),
4964                                                    journalContentSearchModelImpl.getPrivateLayout(),
4965                                                    journalContentSearchModelImpl.getLayoutId(),
4966                                                    journalContentSearchModelImpl.getPortletId()
4967                                            };
4968    
4969                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_L_P, args);
4970                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_L_P,
4971                                            args);
4972                            }
4973                    }
4974    
4975                    EntityCacheUtil.putResult(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
4976                            JournalContentSearchImpl.class,
4977                            journalContentSearch.getPrimaryKey(), journalContentSearch);
4978    
4979                    clearUniqueFindersCache(journalContentSearch);
4980                    cacheUniqueFindersCache(journalContentSearch);
4981    
4982                    return journalContentSearch;
4983            }
4984    
4985            protected JournalContentSearch toUnwrappedModel(
4986                    JournalContentSearch journalContentSearch) {
4987                    if (journalContentSearch instanceof JournalContentSearchImpl) {
4988                            return journalContentSearch;
4989                    }
4990    
4991                    JournalContentSearchImpl journalContentSearchImpl = new JournalContentSearchImpl();
4992    
4993                    journalContentSearchImpl.setNew(journalContentSearch.isNew());
4994                    journalContentSearchImpl.setPrimaryKey(journalContentSearch.getPrimaryKey());
4995    
4996                    journalContentSearchImpl.setContentSearchId(journalContentSearch.getContentSearchId());
4997                    journalContentSearchImpl.setGroupId(journalContentSearch.getGroupId());
4998                    journalContentSearchImpl.setCompanyId(journalContentSearch.getCompanyId());
4999                    journalContentSearchImpl.setPrivateLayout(journalContentSearch.isPrivateLayout());
5000                    journalContentSearchImpl.setLayoutId(journalContentSearch.getLayoutId());
5001                    journalContentSearchImpl.setPortletId(journalContentSearch.getPortletId());
5002                    journalContentSearchImpl.setArticleId(journalContentSearch.getArticleId());
5003    
5004                    return journalContentSearchImpl;
5005            }
5006    
5007            /**
5008             * Returns the journal content search with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
5009             *
5010             * @param primaryKey the primary key of the journal content search
5011             * @return the journal content search
5012             * @throws com.liferay.portlet.journal.NoSuchContentSearchException if a journal content search with the primary key could not be found
5013             * @throws SystemException if a system exception occurred
5014             */
5015            @Override
5016            public JournalContentSearch findByPrimaryKey(Serializable primaryKey)
5017                    throws NoSuchContentSearchException, SystemException {
5018                    JournalContentSearch journalContentSearch = fetchByPrimaryKey(primaryKey);
5019    
5020                    if (journalContentSearch == null) {
5021                            if (_log.isWarnEnabled()) {
5022                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
5023                            }
5024    
5025                            throw new NoSuchContentSearchException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
5026                                    primaryKey);
5027                    }
5028    
5029                    return journalContentSearch;
5030            }
5031    
5032            /**
5033             * Returns the journal content search with the primary key or throws a {@link com.liferay.portlet.journal.NoSuchContentSearchException} if it could not be found.
5034             *
5035             * @param contentSearchId the primary key of the journal content search
5036             * @return the journal content search
5037             * @throws com.liferay.portlet.journal.NoSuchContentSearchException if a journal content search with the primary key could not be found
5038             * @throws SystemException if a system exception occurred
5039             */
5040            @Override
5041            public JournalContentSearch findByPrimaryKey(long contentSearchId)
5042                    throws NoSuchContentSearchException, SystemException {
5043                    return findByPrimaryKey((Serializable)contentSearchId);
5044            }
5045    
5046            /**
5047             * Returns the journal content search with the primary key or returns <code>null</code> if it could not be found.
5048             *
5049             * @param primaryKey the primary key of the journal content search
5050             * @return the journal content search, or <code>null</code> if a journal content search with the primary key could not be found
5051             * @throws SystemException if a system exception occurred
5052             */
5053            @Override
5054            public JournalContentSearch fetchByPrimaryKey(Serializable primaryKey)
5055                    throws SystemException {
5056                    JournalContentSearch journalContentSearch = (JournalContentSearch)EntityCacheUtil.getResult(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
5057                                    JournalContentSearchImpl.class, primaryKey);
5058    
5059                    if (journalContentSearch == _nullJournalContentSearch) {
5060                            return null;
5061                    }
5062    
5063                    if (journalContentSearch == null) {
5064                            Session session = null;
5065    
5066                            try {
5067                                    session = openSession();
5068    
5069                                    journalContentSearch = (JournalContentSearch)session.get(JournalContentSearchImpl.class,
5070                                                    primaryKey);
5071    
5072                                    if (journalContentSearch != null) {
5073                                            cacheResult(journalContentSearch);
5074                                    }
5075                                    else {
5076                                            EntityCacheUtil.putResult(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
5077                                                    JournalContentSearchImpl.class, primaryKey,
5078                                                    _nullJournalContentSearch);
5079                                    }
5080                            }
5081                            catch (Exception e) {
5082                                    EntityCacheUtil.removeResult(JournalContentSearchModelImpl.ENTITY_CACHE_ENABLED,
5083                                            JournalContentSearchImpl.class, primaryKey);
5084    
5085                                    throw processException(e);
5086                            }
5087                            finally {
5088                                    closeSession(session);
5089                            }
5090                    }
5091    
5092                    return journalContentSearch;
5093            }
5094    
5095            /**
5096             * Returns the journal content search with the primary key or returns <code>null</code> if it could not be found.
5097             *
5098             * @param contentSearchId the primary key of the journal content search
5099             * @return the journal content search, or <code>null</code> if a journal content search with the primary key could not be found
5100             * @throws SystemException if a system exception occurred
5101             */
5102            @Override
5103            public JournalContentSearch fetchByPrimaryKey(long contentSearchId)
5104                    throws SystemException {
5105                    return fetchByPrimaryKey((Serializable)contentSearchId);
5106            }
5107    
5108            /**
5109             * Returns all the journal content searchs.
5110             *
5111             * @return the journal content searchs
5112             * @throws SystemException if a system exception occurred
5113             */
5114            @Override
5115            public List<JournalContentSearch> findAll() throws SystemException {
5116                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5117            }
5118    
5119            /**
5120             * Returns a range of all the journal content searchs.
5121             *
5122             * <p>
5123             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalContentSearchModelImpl}. 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.
5124             * </p>
5125             *
5126             * @param start the lower bound of the range of journal content searchs
5127             * @param end the upper bound of the range of journal content searchs (not inclusive)
5128             * @return the range of journal content searchs
5129             * @throws SystemException if a system exception occurred
5130             */
5131            @Override
5132            public List<JournalContentSearch> findAll(int start, int end)
5133                    throws SystemException {
5134                    return findAll(start, end, null);
5135            }
5136    
5137            /**
5138             * Returns an ordered range of all the journal content searchs.
5139             *
5140             * <p>
5141             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalContentSearchModelImpl}. 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.
5142             * </p>
5143             *
5144             * @param start the lower bound of the range of journal content searchs
5145             * @param end the upper bound of the range of journal content searchs (not inclusive)
5146             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5147             * @return the ordered range of journal content searchs
5148             * @throws SystemException if a system exception occurred
5149             */
5150            @Override
5151            public List<JournalContentSearch> findAll(int start, int end,
5152                    OrderByComparator orderByComparator) throws SystemException {
5153                    boolean pagination = true;
5154                    FinderPath finderPath = null;
5155                    Object[] finderArgs = null;
5156    
5157                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5158                                    (orderByComparator == null)) {
5159                            pagination = false;
5160                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
5161                            finderArgs = FINDER_ARGS_EMPTY;
5162                    }
5163                    else {
5164                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
5165                            finderArgs = new Object[] { start, end, orderByComparator };
5166                    }
5167    
5168                    List<JournalContentSearch> list = (List<JournalContentSearch>)FinderCacheUtil.getResult(finderPath,
5169                                    finderArgs, this);
5170    
5171                    if (list == null) {
5172                            StringBundler query = null;
5173                            String sql = null;
5174    
5175                            if (orderByComparator != null) {
5176                                    query = new StringBundler(2 +
5177                                                    (orderByComparator.getOrderByFields().length * 3));
5178    
5179                                    query.append(_SQL_SELECT_JOURNALCONTENTSEARCH);
5180    
5181                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5182                                            orderByComparator);
5183    
5184                                    sql = query.toString();
5185                            }
5186                            else {
5187                                    sql = _SQL_SELECT_JOURNALCONTENTSEARCH;
5188    
5189                                    if (pagination) {
5190                                            sql = sql.concat(JournalContentSearchModelImpl.ORDER_BY_JPQL);
5191                                    }
5192                            }
5193    
5194                            Session session = null;
5195    
5196                            try {
5197                                    session = openSession();
5198    
5199                                    Query q = session.createQuery(sql);
5200    
5201                                    if (!pagination) {
5202                                            list = (List<JournalContentSearch>)QueryUtil.list(q,
5203                                                            getDialect(), start, end, false);
5204    
5205                                            Collections.sort(list);
5206    
5207                                            list = new UnmodifiableList<JournalContentSearch>(list);
5208                                    }
5209                                    else {
5210                                            list = (List<JournalContentSearch>)QueryUtil.list(q,
5211                                                            getDialect(), start, end);
5212                                    }
5213    
5214                                    cacheResult(list);
5215    
5216                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5217                            }
5218                            catch (Exception e) {
5219                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5220    
5221                                    throw processException(e);
5222                            }
5223                            finally {
5224                                    closeSession(session);
5225                            }
5226                    }
5227    
5228                    return list;
5229            }
5230    
5231            /**
5232             * Removes all the journal content searchs from the database.
5233             *
5234             * @throws SystemException if a system exception occurred
5235             */
5236            @Override
5237            public void removeAll() throws SystemException {
5238                    for (JournalContentSearch journalContentSearch : findAll()) {
5239                            remove(journalContentSearch);
5240                    }
5241            }
5242    
5243            /**
5244             * Returns the number of journal content searchs.
5245             *
5246             * @return the number of journal content searchs
5247             * @throws SystemException if a system exception occurred
5248             */
5249            @Override
5250            public int countAll() throws SystemException {
5251                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
5252                                    FINDER_ARGS_EMPTY, this);
5253    
5254                    if (count == null) {
5255                            Session session = null;
5256    
5257                            try {
5258                                    session = openSession();
5259    
5260                                    Query q = session.createQuery(_SQL_COUNT_JOURNALCONTENTSEARCH);
5261    
5262                                    count = (Long)q.uniqueResult();
5263    
5264                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
5265                                            FINDER_ARGS_EMPTY, count);
5266                            }
5267                            catch (Exception e) {
5268                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
5269                                            FINDER_ARGS_EMPTY);
5270    
5271                                    throw processException(e);
5272                            }
5273                            finally {
5274                                    closeSession(session);
5275                            }
5276                    }
5277    
5278                    return count.intValue();
5279            }
5280    
5281            /**
5282             * Initializes the journal content search persistence.
5283             */
5284            public void afterPropertiesSet() {
5285                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
5286                                            com.liferay.portal.util.PropsUtil.get(
5287                                                    "value.object.listener.com.liferay.portlet.journal.model.JournalContentSearch")));
5288    
5289                    if (listenerClassNames.length > 0) {
5290                            try {
5291                                    List<ModelListener<JournalContentSearch>> listenersList = new ArrayList<ModelListener<JournalContentSearch>>();
5292    
5293                                    for (String listenerClassName : listenerClassNames) {
5294                                            listenersList.add((ModelListener<JournalContentSearch>)InstanceFactory.newInstance(
5295                                                            getClassLoader(), listenerClassName));
5296                                    }
5297    
5298                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
5299                            }
5300                            catch (Exception e) {
5301                                    _log.error(e);
5302                            }
5303                    }
5304            }
5305    
5306            public void destroy() {
5307                    EntityCacheUtil.removeCache(JournalContentSearchImpl.class.getName());
5308                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
5309                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5310                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5311            }
5312    
5313            private static final String _SQL_SELECT_JOURNALCONTENTSEARCH = "SELECT journalContentSearch FROM JournalContentSearch journalContentSearch";
5314            private static final String _SQL_SELECT_JOURNALCONTENTSEARCH_WHERE = "SELECT journalContentSearch FROM JournalContentSearch journalContentSearch WHERE ";
5315            private static final String _SQL_COUNT_JOURNALCONTENTSEARCH = "SELECT COUNT(journalContentSearch) FROM JournalContentSearch journalContentSearch";
5316            private static final String _SQL_COUNT_JOURNALCONTENTSEARCH_WHERE = "SELECT COUNT(journalContentSearch) FROM JournalContentSearch journalContentSearch WHERE ";
5317            private static final String _ORDER_BY_ENTITY_ALIAS = "journalContentSearch.";
5318            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No JournalContentSearch exists with the primary key ";
5319            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No JournalContentSearch exists with the key {";
5320            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
5321            private static Log _log = LogFactoryUtil.getLog(JournalContentSearchPersistenceImpl.class);
5322            private static JournalContentSearch _nullJournalContentSearch = new JournalContentSearchImpl() {
5323                            @Override
5324                            public Object clone() {
5325                                    return this;
5326                            }
5327    
5328                            @Override
5329                            public CacheModel<JournalContentSearch> toCacheModel() {
5330                                    return _nullJournalContentSearchCacheModel;
5331                            }
5332                    };
5333    
5334            private static CacheModel<JournalContentSearch> _nullJournalContentSearchCacheModel =
5335                    new CacheModel<JournalContentSearch>() {
5336                            @Override
5337                            public JournalContentSearch toEntityModel() {
5338                                    return _nullJournalContentSearch;
5339                            }
5340                    };
5341    }