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