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