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