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