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