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