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