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