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