001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.NoSuchPortletItemException;
019    import com.liferay.portal.kernel.annotation.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.model.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     * @author    Brian Wing Shun Chan
052     * @see       PortletItemPersistence
053     * @see       PortletItemUtil
054     * @generated
055     */
056    public class PortletItemPersistenceImpl extends BasePersistenceImpl<PortletItem>
057            implements PortletItemPersistence {
058            public static final String FINDER_CLASS_NAME_ENTITY = PortletItemImpl.class.getName();
059            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
060                    ".List";
061            public static final FinderPath FINDER_PATH_FIND_BY_G_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
062                            PortletItemModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
063                            "findByG_C",
064                            new String[] {
065                                    Long.class.getName(), Long.class.getName(),
066                                    
067                            "java.lang.Integer", "java.lang.Integer",
068                                    "com.liferay.portal.kernel.util.OrderByComparator"
069                            });
070            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
071                            PortletItemModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
072                            "countByG_C",
073                            new String[] { Long.class.getName(), Long.class.getName() });
074            public static final FinderPath FINDER_PATH_FIND_BY_G_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
075                            PortletItemModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
076                            "findByG_P_C",
077                            new String[] {
078                                    Long.class.getName(), String.class.getName(),
079                                    Long.class.getName(),
080                                    
081                            "java.lang.Integer", "java.lang.Integer",
082                                    "com.liferay.portal.kernel.util.OrderByComparator"
083                            });
084            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
085                            PortletItemModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
086                            "countByG_P_C",
087                            new String[] {
088                                    Long.class.getName(), String.class.getName(),
089                                    Long.class.getName()
090                            });
091            public static final FinderPath FINDER_PATH_FETCH_BY_G_N_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
092                            PortletItemModelImpl.FINDER_CACHE_ENABLED,
093                            FINDER_CLASS_NAME_ENTITY, "fetchByG_N_P_C",
094                            new String[] {
095                                    Long.class.getName(), String.class.getName(),
096                                    String.class.getName(), Long.class.getName()
097                            });
098            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
099                            PortletItemModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
100                            "countByG_N_P_C",
101                            new String[] {
102                                    Long.class.getName(), String.class.getName(),
103                                    String.class.getName(), Long.class.getName()
104                            });
105            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
106                            PortletItemModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
107                            "findAll", new String[0]);
108            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
109                            PortletItemModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
110                            "countAll", new String[0]);
111    
112            public void cacheResult(PortletItem portletItem) {
113                    EntityCacheUtil.putResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
114                            PortletItemImpl.class, portletItem.getPrimaryKey(), portletItem);
115    
116                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
117                            new Object[] {
118                                    new Long(portletItem.getGroupId()),
119                                    
120                            portletItem.getName(),
121                                    
122                            portletItem.getPortletId(), new Long(portletItem.getClassNameId())
123                            }, portletItem);
124            }
125    
126            public void cacheResult(List<PortletItem> portletItems) {
127                    for (PortletItem portletItem : portletItems) {
128                            if (EntityCacheUtil.getResult(
129                                                    PortletItemModelImpl.ENTITY_CACHE_ENABLED,
130                                                    PortletItemImpl.class, portletItem.getPrimaryKey(), this) == null) {
131                                    cacheResult(portletItem);
132                            }
133                    }
134            }
135    
136            public void clearCache() {
137                    CacheRegistryUtil.clear(PortletItemImpl.class.getName());
138                    EntityCacheUtil.clearCache(PortletItemImpl.class.getName());
139                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
140                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
141            }
142    
143            public void clearCache(PortletItem portletItem) {
144                    EntityCacheUtil.removeResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
145                            PortletItemImpl.class, portletItem.getPrimaryKey());
146    
147                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N_P_C,
148                            new Object[] {
149                                    new Long(portletItem.getGroupId()),
150                                    
151                            portletItem.getName(),
152                                    
153                            portletItem.getPortletId(), new Long(portletItem.getClassNameId())
154                            });
155            }
156    
157            public PortletItem create(long portletItemId) {
158                    PortletItem portletItem = new PortletItemImpl();
159    
160                    portletItem.setNew(true);
161                    portletItem.setPrimaryKey(portletItemId);
162    
163                    return portletItem;
164            }
165    
166            public PortletItem remove(Serializable primaryKey)
167                    throws NoSuchModelException, SystemException {
168                    return remove(((Long)primaryKey).longValue());
169            }
170    
171            public PortletItem remove(long portletItemId)
172                    throws NoSuchPortletItemException, SystemException {
173                    Session session = null;
174    
175                    try {
176                            session = openSession();
177    
178                            PortletItem portletItem = (PortletItem)session.get(PortletItemImpl.class,
179                                            new Long(portletItemId));
180    
181                            if (portletItem == null) {
182                                    if (_log.isWarnEnabled()) {
183                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + portletItemId);
184                                    }
185    
186                                    throw new NoSuchPortletItemException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
187                                            portletItemId);
188                            }
189    
190                            return remove(portletItem);
191                    }
192                    catch (NoSuchPortletItemException nsee) {
193                            throw nsee;
194                    }
195                    catch (Exception e) {
196                            throw processException(e);
197                    }
198                    finally {
199                            closeSession(session);
200                    }
201            }
202    
203            protected PortletItem removeImpl(PortletItem portletItem)
204                    throws SystemException {
205                    portletItem = toUnwrappedModel(portletItem);
206    
207                    Session session = null;
208    
209                    try {
210                            session = openSession();
211    
212                            if (portletItem.isCachedModel() || BatchSessionUtil.isEnabled()) {
213                                    Object staleObject = session.get(PortletItemImpl.class,
214                                                    portletItem.getPrimaryKeyObj());
215    
216                                    if (staleObject != null) {
217                                            session.evict(staleObject);
218                                    }
219                            }
220    
221                            session.delete(portletItem);
222    
223                            session.flush();
224                    }
225                    catch (Exception e) {
226                            throw processException(e);
227                    }
228                    finally {
229                            closeSession(session);
230                    }
231    
232                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
233    
234                    PortletItemModelImpl portletItemModelImpl = (PortletItemModelImpl)portletItem;
235    
236                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N_P_C,
237                            new Object[] {
238                                    new Long(portletItemModelImpl.getOriginalGroupId()),
239                                    
240                            portletItemModelImpl.getOriginalName(),
241                                    
242                            portletItemModelImpl.getOriginalPortletId(),
243                                    new Long(portletItemModelImpl.getOriginalClassNameId())
244                            });
245    
246                    EntityCacheUtil.removeResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
247                            PortletItemImpl.class, portletItem.getPrimaryKey());
248    
249                    return portletItem;
250            }
251    
252            public PortletItem updateImpl(
253                    com.liferay.portal.model.PortletItem portletItem, boolean merge)
254                    throws SystemException {
255                    portletItem = toUnwrappedModel(portletItem);
256    
257                    boolean isNew = portletItem.isNew();
258    
259                    PortletItemModelImpl portletItemModelImpl = (PortletItemModelImpl)portletItem;
260    
261                    Session session = null;
262    
263                    try {
264                            session = openSession();
265    
266                            BatchSessionUtil.update(session, portletItem, merge);
267    
268                            portletItem.setNew(false);
269                    }
270                    catch (Exception e) {
271                            throw processException(e);
272                    }
273                    finally {
274                            closeSession(session);
275                    }
276    
277                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
278    
279                    EntityCacheUtil.putResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
280                            PortletItemImpl.class, portletItem.getPrimaryKey(), portletItem);
281    
282                    if (!isNew &&
283                                    ((portletItem.getGroupId() != portletItemModelImpl.getOriginalGroupId()) ||
284                                    !Validator.equals(portletItem.getName(),
285                                            portletItemModelImpl.getOriginalName()) ||
286                                    !Validator.equals(portletItem.getPortletId(),
287                                            portletItemModelImpl.getOriginalPortletId()) ||
288                                    (portletItem.getClassNameId() != portletItemModelImpl.getOriginalClassNameId()))) {
289                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N_P_C,
290                                    new Object[] {
291                                            new Long(portletItemModelImpl.getOriginalGroupId()),
292                                            
293                                    portletItemModelImpl.getOriginalName(),
294                                            
295                                    portletItemModelImpl.getOriginalPortletId(),
296                                            new Long(portletItemModelImpl.getOriginalClassNameId())
297                                    });
298                    }
299    
300                    if (isNew ||
301                                    ((portletItem.getGroupId() != portletItemModelImpl.getOriginalGroupId()) ||
302                                    !Validator.equals(portletItem.getName(),
303                                            portletItemModelImpl.getOriginalName()) ||
304                                    !Validator.equals(portletItem.getPortletId(),
305                                            portletItemModelImpl.getOriginalPortletId()) ||
306                                    (portletItem.getClassNameId() != portletItemModelImpl.getOriginalClassNameId()))) {
307                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
308                                    new Object[] {
309                                            new Long(portletItem.getGroupId()),
310                                            
311                                    portletItem.getName(),
312                                            
313                                    portletItem.getPortletId(),
314                                            new Long(portletItem.getClassNameId())
315                                    }, portletItem);
316                    }
317    
318                    return portletItem;
319            }
320    
321            protected PortletItem toUnwrappedModel(PortletItem portletItem) {
322                    if (portletItem instanceof PortletItemImpl) {
323                            return portletItem;
324                    }
325    
326                    PortletItemImpl portletItemImpl = new PortletItemImpl();
327    
328                    portletItemImpl.setNew(portletItem.isNew());
329                    portletItemImpl.setPrimaryKey(portletItem.getPrimaryKey());
330    
331                    portletItemImpl.setPortletItemId(portletItem.getPortletItemId());
332                    portletItemImpl.setGroupId(portletItem.getGroupId());
333                    portletItemImpl.setCompanyId(portletItem.getCompanyId());
334                    portletItemImpl.setUserId(portletItem.getUserId());
335                    portletItemImpl.setUserName(portletItem.getUserName());
336                    portletItemImpl.setCreateDate(portletItem.getCreateDate());
337                    portletItemImpl.setModifiedDate(portletItem.getModifiedDate());
338                    portletItemImpl.setName(portletItem.getName());
339                    portletItemImpl.setPortletId(portletItem.getPortletId());
340                    portletItemImpl.setClassNameId(portletItem.getClassNameId());
341    
342                    return portletItemImpl;
343            }
344    
345            public PortletItem findByPrimaryKey(Serializable primaryKey)
346                    throws NoSuchModelException, SystemException {
347                    return findByPrimaryKey(((Long)primaryKey).longValue());
348            }
349    
350            public PortletItem findByPrimaryKey(long portletItemId)
351                    throws NoSuchPortletItemException, SystemException {
352                    PortletItem portletItem = fetchByPrimaryKey(portletItemId);
353    
354                    if (portletItem == null) {
355                            if (_log.isWarnEnabled()) {
356                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + portletItemId);
357                            }
358    
359                            throw new NoSuchPortletItemException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
360                                    portletItemId);
361                    }
362    
363                    return portletItem;
364            }
365    
366            public PortletItem fetchByPrimaryKey(Serializable primaryKey)
367                    throws SystemException {
368                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
369            }
370    
371            public PortletItem fetchByPrimaryKey(long portletItemId)
372                    throws SystemException {
373                    PortletItem portletItem = (PortletItem)EntityCacheUtil.getResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
374                                    PortletItemImpl.class, portletItemId, this);
375    
376                    if (portletItem == null) {
377                            Session session = null;
378    
379                            try {
380                                    session = openSession();
381    
382                                    portletItem = (PortletItem)session.get(PortletItemImpl.class,
383                                                    new Long(portletItemId));
384                            }
385                            catch (Exception e) {
386                                    throw processException(e);
387                            }
388                            finally {
389                                    if (portletItem != null) {
390                                            cacheResult(portletItem);
391                                    }
392    
393                                    closeSession(session);
394                            }
395                    }
396    
397                    return portletItem;
398            }
399    
400            public List<PortletItem> findByG_C(long groupId, long classNameId)
401                    throws SystemException {
402                    return findByG_C(groupId, classNameId, QueryUtil.ALL_POS,
403                            QueryUtil.ALL_POS, null);
404            }
405    
406            public List<PortletItem> findByG_C(long groupId, long classNameId,
407                    int start, int end) throws SystemException {
408                    return findByG_C(groupId, classNameId, start, end, null);
409            }
410    
411            public List<PortletItem> findByG_C(long groupId, long classNameId,
412                    int start, int end, OrderByComparator orderByComparator)
413                    throws SystemException {
414                    Object[] finderArgs = new Object[] {
415                                    groupId, classNameId,
416                                    
417                                    String.valueOf(start), String.valueOf(end),
418                                    String.valueOf(orderByComparator)
419                            };
420    
421                    List<PortletItem> list = (List<PortletItem>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_C,
422                                    finderArgs, this);
423    
424                    if (list == null) {
425                            Session session = null;
426    
427                            try {
428                                    session = openSession();
429    
430                                    StringBundler query = null;
431    
432                                    if (orderByComparator != null) {
433                                            query = new StringBundler(4 +
434                                                            (orderByComparator.getOrderByFields().length * 3));
435                                    }
436                                    else {
437                                            query = new StringBundler(3);
438                                    }
439    
440                                    query.append(_SQL_SELECT_PORTLETITEM_WHERE);
441    
442                                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
443    
444                                    query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
445    
446                                    if (orderByComparator != null) {
447                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
448                                                    orderByComparator);
449                                    }
450    
451                                    String sql = query.toString();
452    
453                                    Query q = session.createQuery(sql);
454    
455                                    QueryPos qPos = QueryPos.getInstance(q);
456    
457                                    qPos.add(groupId);
458    
459                                    qPos.add(classNameId);
460    
461                                    list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
462                                                    start, end);
463                            }
464                            catch (Exception e) {
465                                    throw processException(e);
466                            }
467                            finally {
468                                    if (list == null) {
469                                            list = new ArrayList<PortletItem>();
470                                    }
471    
472                                    cacheResult(list);
473    
474                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_C, finderArgs,
475                                            list);
476    
477                                    closeSession(session);
478                            }
479                    }
480    
481                    return list;
482            }
483    
484            public PortletItem findByG_C_First(long groupId, long classNameId,
485                    OrderByComparator orderByComparator)
486                    throws NoSuchPortletItemException, SystemException {
487                    List<PortletItem> list = findByG_C(groupId, classNameId, 0, 1,
488                                    orderByComparator);
489    
490                    if (list.isEmpty()) {
491                            StringBundler msg = new StringBundler(6);
492    
493                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
494    
495                            msg.append("groupId=");
496                            msg.append(groupId);
497    
498                            msg.append(", classNameId=");
499                            msg.append(classNameId);
500    
501                            msg.append(StringPool.CLOSE_CURLY_BRACE);
502    
503                            throw new NoSuchPortletItemException(msg.toString());
504                    }
505                    else {
506                            return list.get(0);
507                    }
508            }
509    
510            public PortletItem findByG_C_Last(long groupId, long classNameId,
511                    OrderByComparator orderByComparator)
512                    throws NoSuchPortletItemException, SystemException {
513                    int count = countByG_C(groupId, classNameId);
514    
515                    List<PortletItem> list = findByG_C(groupId, classNameId, count - 1,
516                                    count, orderByComparator);
517    
518                    if (list.isEmpty()) {
519                            StringBundler msg = new StringBundler(6);
520    
521                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
522    
523                            msg.append("groupId=");
524                            msg.append(groupId);
525    
526                            msg.append(", classNameId=");
527                            msg.append(classNameId);
528    
529                            msg.append(StringPool.CLOSE_CURLY_BRACE);
530    
531                            throw new NoSuchPortletItemException(msg.toString());
532                    }
533                    else {
534                            return list.get(0);
535                    }
536            }
537    
538            public PortletItem[] findByG_C_PrevAndNext(long portletItemId,
539                    long groupId, long classNameId, OrderByComparator orderByComparator)
540                    throws NoSuchPortletItemException, SystemException {
541                    PortletItem portletItem = findByPrimaryKey(portletItemId);
542    
543                    Session session = null;
544    
545                    try {
546                            session = openSession();
547    
548                            PortletItem[] array = new PortletItemImpl[3];
549    
550                            array[0] = getByG_C_PrevAndNext(session, portletItem, groupId,
551                                            classNameId, orderByComparator, true);
552    
553                            array[1] = portletItem;
554    
555                            array[2] = getByG_C_PrevAndNext(session, portletItem, groupId,
556                                            classNameId, orderByComparator, false);
557    
558                            return array;
559                    }
560                    catch (Exception e) {
561                            throw processException(e);
562                    }
563                    finally {
564                            closeSession(session);
565                    }
566            }
567    
568            protected PortletItem getByG_C_PrevAndNext(Session session,
569                    PortletItem portletItem, long groupId, long classNameId,
570                    OrderByComparator orderByComparator, boolean previous) {
571                    StringBundler query = null;
572    
573                    if (orderByComparator != null) {
574                            query = new StringBundler(6 +
575                                            (orderByComparator.getOrderByFields().length * 6));
576                    }
577                    else {
578                            query = new StringBundler(3);
579                    }
580    
581                    query.append(_SQL_SELECT_PORTLETITEM_WHERE);
582    
583                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
584    
585                    query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
586    
587                    if (orderByComparator != null) {
588                            String[] orderByFields = orderByComparator.getOrderByFields();
589    
590                            if (orderByFields.length > 0) {
591                                    query.append(WHERE_AND);
592                            }
593    
594                            for (int i = 0; i < orderByFields.length; i++) {
595                                    query.append(_ORDER_BY_ENTITY_ALIAS);
596                                    query.append(orderByFields[i]);
597    
598                                    if ((i + 1) < orderByFields.length) {
599                                            if (orderByComparator.isAscending() ^ previous) {
600                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
601                                            }
602                                            else {
603                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
604                                            }
605                                    }
606                                    else {
607                                            if (orderByComparator.isAscending() ^ previous) {
608                                                    query.append(WHERE_GREATER_THAN);
609                                            }
610                                            else {
611                                                    query.append(WHERE_LESSER_THAN);
612                                            }
613                                    }
614                            }
615    
616                            query.append(ORDER_BY_CLAUSE);
617    
618                            for (int i = 0; i < orderByFields.length; i++) {
619                                    query.append(_ORDER_BY_ENTITY_ALIAS);
620                                    query.append(orderByFields[i]);
621    
622                                    if ((i + 1) < orderByFields.length) {
623                                            if (orderByComparator.isAscending() ^ previous) {
624                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
625                                            }
626                                            else {
627                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
628                                            }
629                                    }
630                                    else {
631                                            if (orderByComparator.isAscending() ^ previous) {
632                                                    query.append(ORDER_BY_ASC);
633                                            }
634                                            else {
635                                                    query.append(ORDER_BY_DESC);
636                                            }
637                                    }
638                            }
639                    }
640    
641                    String sql = query.toString();
642    
643                    Query q = session.createQuery(sql);
644    
645                    q.setFirstResult(0);
646                    q.setMaxResults(2);
647    
648                    QueryPos qPos = QueryPos.getInstance(q);
649    
650                    qPos.add(groupId);
651    
652                    qPos.add(classNameId);
653    
654                    if (orderByComparator != null) {
655                            Object[] values = orderByComparator.getOrderByValues(portletItem);
656    
657                            for (Object value : values) {
658                                    qPos.add(value);
659                            }
660                    }
661    
662                    List<PortletItem> list = q.list();
663    
664                    if (list.size() == 2) {
665                            return list.get(1);
666                    }
667                    else {
668                            return null;
669                    }
670            }
671    
672            public List<PortletItem> findByG_P_C(long groupId, String portletId,
673                    long classNameId) throws SystemException {
674                    return findByG_P_C(groupId, portletId, classNameId, QueryUtil.ALL_POS,
675                            QueryUtil.ALL_POS, null);
676            }
677    
678            public List<PortletItem> findByG_P_C(long groupId, String portletId,
679                    long classNameId, int start, int end) throws SystemException {
680                    return findByG_P_C(groupId, portletId, classNameId, start, end, null);
681            }
682    
683            public List<PortletItem> findByG_P_C(long groupId, String portletId,
684                    long classNameId, int start, int end,
685                    OrderByComparator orderByComparator) throws SystemException {
686                    Object[] finderArgs = new Object[] {
687                                    groupId, portletId, classNameId,
688                                    
689                                    String.valueOf(start), String.valueOf(end),
690                                    String.valueOf(orderByComparator)
691                            };
692    
693                    List<PortletItem> list = (List<PortletItem>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_P_C,
694                                    finderArgs, this);
695    
696                    if (list == null) {
697                            Session session = null;
698    
699                            try {
700                                    session = openSession();
701    
702                                    StringBundler query = null;
703    
704                                    if (orderByComparator != null) {
705                                            query = new StringBundler(5 +
706                                                            (orderByComparator.getOrderByFields().length * 3));
707                                    }
708                                    else {
709                                            query = new StringBundler(4);
710                                    }
711    
712                                    query.append(_SQL_SELECT_PORTLETITEM_WHERE);
713    
714                                    query.append(_FINDER_COLUMN_G_P_C_GROUPID_2);
715    
716                                    if (portletId == null) {
717                                            query.append(_FINDER_COLUMN_G_P_C_PORTLETID_1);
718                                    }
719                                    else {
720                                            if (portletId.equals(StringPool.BLANK)) {
721                                                    query.append(_FINDER_COLUMN_G_P_C_PORTLETID_3);
722                                            }
723                                            else {
724                                                    query.append(_FINDER_COLUMN_G_P_C_PORTLETID_2);
725                                            }
726                                    }
727    
728                                    query.append(_FINDER_COLUMN_G_P_C_CLASSNAMEID_2);
729    
730                                    if (orderByComparator != null) {
731                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
732                                                    orderByComparator);
733                                    }
734    
735                                    String sql = query.toString();
736    
737                                    Query q = session.createQuery(sql);
738    
739                                    QueryPos qPos = QueryPos.getInstance(q);
740    
741                                    qPos.add(groupId);
742    
743                                    if (portletId != null) {
744                                            qPos.add(portletId);
745                                    }
746    
747                                    qPos.add(classNameId);
748    
749                                    list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
750                                                    start, end);
751                            }
752                            catch (Exception e) {
753                                    throw processException(e);
754                            }
755                            finally {
756                                    if (list == null) {
757                                            list = new ArrayList<PortletItem>();
758                                    }
759    
760                                    cacheResult(list);
761    
762                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_P_C,
763                                            finderArgs, list);
764    
765                                    closeSession(session);
766                            }
767                    }
768    
769                    return list;
770            }
771    
772            public PortletItem findByG_P_C_First(long groupId, String portletId,
773                    long classNameId, OrderByComparator orderByComparator)
774                    throws NoSuchPortletItemException, SystemException {
775                    List<PortletItem> list = findByG_P_C(groupId, portletId, classNameId,
776                                    0, 1, orderByComparator);
777    
778                    if (list.isEmpty()) {
779                            StringBundler msg = new StringBundler(8);
780    
781                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
782    
783                            msg.append("groupId=");
784                            msg.append(groupId);
785    
786                            msg.append(", portletId=");
787                            msg.append(portletId);
788    
789                            msg.append(", classNameId=");
790                            msg.append(classNameId);
791    
792                            msg.append(StringPool.CLOSE_CURLY_BRACE);
793    
794                            throw new NoSuchPortletItemException(msg.toString());
795                    }
796                    else {
797                            return list.get(0);
798                    }
799            }
800    
801            public PortletItem findByG_P_C_Last(long groupId, String portletId,
802                    long classNameId, OrderByComparator orderByComparator)
803                    throws NoSuchPortletItemException, SystemException {
804                    int count = countByG_P_C(groupId, portletId, classNameId);
805    
806                    List<PortletItem> list = findByG_P_C(groupId, portletId, classNameId,
807                                    count - 1, count, orderByComparator);
808    
809                    if (list.isEmpty()) {
810                            StringBundler msg = new StringBundler(8);
811    
812                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
813    
814                            msg.append("groupId=");
815                            msg.append(groupId);
816    
817                            msg.append(", portletId=");
818                            msg.append(portletId);
819    
820                            msg.append(", classNameId=");
821                            msg.append(classNameId);
822    
823                            msg.append(StringPool.CLOSE_CURLY_BRACE);
824    
825                            throw new NoSuchPortletItemException(msg.toString());
826                    }
827                    else {
828                            return list.get(0);
829                    }
830            }
831    
832            public PortletItem[] findByG_P_C_PrevAndNext(long portletItemId,
833                    long groupId, String portletId, long classNameId,
834                    OrderByComparator orderByComparator)
835                    throws NoSuchPortletItemException, SystemException {
836                    PortletItem portletItem = findByPrimaryKey(portletItemId);
837    
838                    Session session = null;
839    
840                    try {
841                            session = openSession();
842    
843                            PortletItem[] array = new PortletItemImpl[3];
844    
845                            array[0] = getByG_P_C_PrevAndNext(session, portletItem, groupId,
846                                            portletId, classNameId, orderByComparator, true);
847    
848                            array[1] = portletItem;
849    
850                            array[2] = getByG_P_C_PrevAndNext(session, portletItem, groupId,
851                                            portletId, classNameId, orderByComparator, false);
852    
853                            return array;
854                    }
855                    catch (Exception e) {
856                            throw processException(e);
857                    }
858                    finally {
859                            closeSession(session);
860                    }
861            }
862    
863            protected PortletItem getByG_P_C_PrevAndNext(Session session,
864                    PortletItem portletItem, long groupId, String portletId,
865                    long classNameId, OrderByComparator orderByComparator, boolean previous) {
866                    StringBundler query = null;
867    
868                    if (orderByComparator != null) {
869                            query = new StringBundler(6 +
870                                            (orderByComparator.getOrderByFields().length * 6));
871                    }
872                    else {
873                            query = new StringBundler(3);
874                    }
875    
876                    query.append(_SQL_SELECT_PORTLETITEM_WHERE);
877    
878                    query.append(_FINDER_COLUMN_G_P_C_GROUPID_2);
879    
880                    if (portletId == null) {
881                            query.append(_FINDER_COLUMN_G_P_C_PORTLETID_1);
882                    }
883                    else {
884                            if (portletId.equals(StringPool.BLANK)) {
885                                    query.append(_FINDER_COLUMN_G_P_C_PORTLETID_3);
886                            }
887                            else {
888                                    query.append(_FINDER_COLUMN_G_P_C_PORTLETID_2);
889                            }
890                    }
891    
892                    query.append(_FINDER_COLUMN_G_P_C_CLASSNAMEID_2);
893    
894                    if (orderByComparator != null) {
895                            String[] orderByFields = orderByComparator.getOrderByFields();
896    
897                            if (orderByFields.length > 0) {
898                                    query.append(WHERE_AND);
899                            }
900    
901                            for (int i = 0; i < orderByFields.length; i++) {
902                                    query.append(_ORDER_BY_ENTITY_ALIAS);
903                                    query.append(orderByFields[i]);
904    
905                                    if ((i + 1) < orderByFields.length) {
906                                            if (orderByComparator.isAscending() ^ previous) {
907                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
908                                            }
909                                            else {
910                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
911                                            }
912                                    }
913                                    else {
914                                            if (orderByComparator.isAscending() ^ previous) {
915                                                    query.append(WHERE_GREATER_THAN);
916                                            }
917                                            else {
918                                                    query.append(WHERE_LESSER_THAN);
919                                            }
920                                    }
921                            }
922    
923                            query.append(ORDER_BY_CLAUSE);
924    
925                            for (int i = 0; i < orderByFields.length; i++) {
926                                    query.append(_ORDER_BY_ENTITY_ALIAS);
927                                    query.append(orderByFields[i]);
928    
929                                    if ((i + 1) < orderByFields.length) {
930                                            if (orderByComparator.isAscending() ^ previous) {
931                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
932                                            }
933                                            else {
934                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
935                                            }
936                                    }
937                                    else {
938                                            if (orderByComparator.isAscending() ^ previous) {
939                                                    query.append(ORDER_BY_ASC);
940                                            }
941                                            else {
942                                                    query.append(ORDER_BY_DESC);
943                                            }
944                                    }
945                            }
946                    }
947    
948                    String sql = query.toString();
949    
950                    Query q = session.createQuery(sql);
951    
952                    q.setFirstResult(0);
953                    q.setMaxResults(2);
954    
955                    QueryPos qPos = QueryPos.getInstance(q);
956    
957                    qPos.add(groupId);
958    
959                    if (portletId != null) {
960                            qPos.add(portletId);
961                    }
962    
963                    qPos.add(classNameId);
964    
965                    if (orderByComparator != null) {
966                            Object[] values = orderByComparator.getOrderByValues(portletItem);
967    
968                            for (Object value : values) {
969                                    qPos.add(value);
970                            }
971                    }
972    
973                    List<PortletItem> list = q.list();
974    
975                    if (list.size() == 2) {
976                            return list.get(1);
977                    }
978                    else {
979                            return null;
980                    }
981            }
982    
983            public PortletItem findByG_N_P_C(long groupId, String name,
984                    String portletId, long classNameId)
985                    throws NoSuchPortletItemException, SystemException {
986                    PortletItem portletItem = fetchByG_N_P_C(groupId, name, portletId,
987                                    classNameId);
988    
989                    if (portletItem == null) {
990                            StringBundler msg = new StringBundler(10);
991    
992                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
993    
994                            msg.append("groupId=");
995                            msg.append(groupId);
996    
997                            msg.append(", name=");
998                            msg.append(name);
999    
1000                            msg.append(", portletId=");
1001                            msg.append(portletId);
1002    
1003                            msg.append(", classNameId=");
1004                            msg.append(classNameId);
1005    
1006                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1007    
1008                            if (_log.isWarnEnabled()) {
1009                                    _log.warn(msg.toString());
1010                            }
1011    
1012                            throw new NoSuchPortletItemException(msg.toString());
1013                    }
1014    
1015                    return portletItem;
1016            }
1017    
1018            public PortletItem fetchByG_N_P_C(long groupId, String name,
1019                    String portletId, long classNameId) throws SystemException {
1020                    return fetchByG_N_P_C(groupId, name, portletId, classNameId, true);
1021            }
1022    
1023            public PortletItem fetchByG_N_P_C(long groupId, String name,
1024                    String portletId, long classNameId, boolean retrieveFromCache)
1025                    throws SystemException {
1026                    Object[] finderArgs = new Object[] { groupId, name, portletId, classNameId };
1027    
1028                    Object result = null;
1029    
1030                    if (retrieveFromCache) {
1031                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1032                                            finderArgs, this);
1033                    }
1034    
1035                    if (result == null) {
1036                            Session session = null;
1037    
1038                            try {
1039                                    session = openSession();
1040    
1041                                    StringBundler query = new StringBundler(5);
1042    
1043                                    query.append(_SQL_SELECT_PORTLETITEM_WHERE);
1044    
1045                                    query.append(_FINDER_COLUMN_G_N_P_C_GROUPID_2);
1046    
1047                                    if (name == null) {
1048                                            query.append(_FINDER_COLUMN_G_N_P_C_NAME_1);
1049                                    }
1050                                    else {
1051                                            if (name.equals(StringPool.BLANK)) {
1052                                                    query.append(_FINDER_COLUMN_G_N_P_C_NAME_3);
1053                                            }
1054                                            else {
1055                                                    query.append(_FINDER_COLUMN_G_N_P_C_NAME_2);
1056                                            }
1057                                    }
1058    
1059                                    if (portletId == null) {
1060                                            query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_1);
1061                                    }
1062                                    else {
1063                                            if (portletId.equals(StringPool.BLANK)) {
1064                                                    query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_3);
1065                                            }
1066                                            else {
1067                                                    query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_2);
1068                                            }
1069                                    }
1070    
1071                                    query.append(_FINDER_COLUMN_G_N_P_C_CLASSNAMEID_2);
1072    
1073                                    String sql = query.toString();
1074    
1075                                    Query q = session.createQuery(sql);
1076    
1077                                    QueryPos qPos = QueryPos.getInstance(q);
1078    
1079                                    qPos.add(groupId);
1080    
1081                                    if (name != null) {
1082                                            qPos.add(name);
1083                                    }
1084    
1085                                    if (portletId != null) {
1086                                            qPos.add(portletId);
1087                                    }
1088    
1089                                    qPos.add(classNameId);
1090    
1091                                    List<PortletItem> list = q.list();
1092    
1093                                    result = list;
1094    
1095                                    PortletItem portletItem = null;
1096    
1097                                    if (list.isEmpty()) {
1098                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1099                                                    finderArgs, list);
1100                                    }
1101                                    else {
1102                                            portletItem = list.get(0);
1103    
1104                                            cacheResult(portletItem);
1105    
1106                                            if ((portletItem.getGroupId() != groupId) ||
1107                                                            (portletItem.getName() == null) ||
1108                                                            !portletItem.getName().equals(name) ||
1109                                                            (portletItem.getPortletId() == null) ||
1110                                                            !portletItem.getPortletId().equals(portletId) ||
1111                                                            (portletItem.getClassNameId() != classNameId)) {
1112                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1113                                                            finderArgs, portletItem);
1114                                            }
1115                                    }
1116    
1117                                    return portletItem;
1118                            }
1119                            catch (Exception e) {
1120                                    throw processException(e);
1121                            }
1122                            finally {
1123                                    if (result == null) {
1124                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1125                                                    finderArgs, new ArrayList<PortletItem>());
1126                                    }
1127    
1128                                    closeSession(session);
1129                            }
1130                    }
1131                    else {
1132                            if (result instanceof List<?>) {
1133                                    return null;
1134                            }
1135                            else {
1136                                    return (PortletItem)result;
1137                            }
1138                    }
1139            }
1140    
1141            public List<PortletItem> findAll() throws SystemException {
1142                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1143            }
1144    
1145            public List<PortletItem> findAll(int start, int end)
1146                    throws SystemException {
1147                    return findAll(start, end, null);
1148            }
1149    
1150            public List<PortletItem> findAll(int start, int end,
1151                    OrderByComparator orderByComparator) throws SystemException {
1152                    Object[] finderArgs = new Object[] {
1153                                    String.valueOf(start), String.valueOf(end),
1154                                    String.valueOf(orderByComparator)
1155                            };
1156    
1157                    List<PortletItem> list = (List<PortletItem>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1158                                    finderArgs, this);
1159    
1160                    if (list == null) {
1161                            Session session = null;
1162    
1163                            try {
1164                                    session = openSession();
1165    
1166                                    StringBundler query = null;
1167                                    String sql = null;
1168    
1169                                    if (orderByComparator != null) {
1170                                            query = new StringBundler(2 +
1171                                                            (orderByComparator.getOrderByFields().length * 3));
1172    
1173                                            query.append(_SQL_SELECT_PORTLETITEM);
1174    
1175                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1176                                                    orderByComparator);
1177    
1178                                            sql = query.toString();
1179                                    }
1180                                    else {
1181                                            sql = _SQL_SELECT_PORTLETITEM;
1182                                    }
1183    
1184                                    Query q = session.createQuery(sql);
1185    
1186                                    if (orderByComparator == null) {
1187                                            list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
1188                                                            start, end, false);
1189    
1190                                            Collections.sort(list);
1191                                    }
1192                                    else {
1193                                            list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
1194                                                            start, end);
1195                                    }
1196                            }
1197                            catch (Exception e) {
1198                                    throw processException(e);
1199                            }
1200                            finally {
1201                                    if (list == null) {
1202                                            list = new ArrayList<PortletItem>();
1203                                    }
1204    
1205                                    cacheResult(list);
1206    
1207                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1208    
1209                                    closeSession(session);
1210                            }
1211                    }
1212    
1213                    return list;
1214            }
1215    
1216            public void removeByG_C(long groupId, long classNameId)
1217                    throws SystemException {
1218                    for (PortletItem portletItem : findByG_C(groupId, classNameId)) {
1219                            remove(portletItem);
1220                    }
1221            }
1222    
1223            public void removeByG_P_C(long groupId, String portletId, long classNameId)
1224                    throws SystemException {
1225                    for (PortletItem portletItem : findByG_P_C(groupId, portletId,
1226                                    classNameId)) {
1227                            remove(portletItem);
1228                    }
1229            }
1230    
1231            public void removeByG_N_P_C(long groupId, String name, String portletId,
1232                    long classNameId) throws NoSuchPortletItemException, SystemException {
1233                    PortletItem portletItem = findByG_N_P_C(groupId, name, portletId,
1234                                    classNameId);
1235    
1236                    remove(portletItem);
1237            }
1238    
1239            public void removeAll() throws SystemException {
1240                    for (PortletItem portletItem : findAll()) {
1241                            remove(portletItem);
1242                    }
1243            }
1244    
1245            public int countByG_C(long groupId, long classNameId)
1246                    throws SystemException {
1247                    Object[] finderArgs = new Object[] { groupId, classNameId };
1248    
1249                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C,
1250                                    finderArgs, this);
1251    
1252                    if (count == null) {
1253                            Session session = null;
1254    
1255                            try {
1256                                    session = openSession();
1257    
1258                                    StringBundler query = new StringBundler(3);
1259    
1260                                    query.append(_SQL_COUNT_PORTLETITEM_WHERE);
1261    
1262                                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1263    
1264                                    query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
1265    
1266                                    String sql = query.toString();
1267    
1268                                    Query q = session.createQuery(sql);
1269    
1270                                    QueryPos qPos = QueryPos.getInstance(q);
1271    
1272                                    qPos.add(groupId);
1273    
1274                                    qPos.add(classNameId);
1275    
1276                                    count = (Long)q.uniqueResult();
1277                            }
1278                            catch (Exception e) {
1279                                    throw processException(e);
1280                            }
1281                            finally {
1282                                    if (count == null) {
1283                                            count = Long.valueOf(0);
1284                                    }
1285    
1286                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C, finderArgs,
1287                                            count);
1288    
1289                                    closeSession(session);
1290                            }
1291                    }
1292    
1293                    return count.intValue();
1294            }
1295    
1296            public int countByG_P_C(long groupId, String portletId, long classNameId)
1297                    throws SystemException {
1298                    Object[] finderArgs = new Object[] { groupId, portletId, classNameId };
1299    
1300                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P_C,
1301                                    finderArgs, this);
1302    
1303                    if (count == null) {
1304                            Session session = null;
1305    
1306                            try {
1307                                    session = openSession();
1308    
1309                                    StringBundler query = new StringBundler(4);
1310    
1311                                    query.append(_SQL_COUNT_PORTLETITEM_WHERE);
1312    
1313                                    query.append(_FINDER_COLUMN_G_P_C_GROUPID_2);
1314    
1315                                    if (portletId == null) {
1316                                            query.append(_FINDER_COLUMN_G_P_C_PORTLETID_1);
1317                                    }
1318                                    else {
1319                                            if (portletId.equals(StringPool.BLANK)) {
1320                                                    query.append(_FINDER_COLUMN_G_P_C_PORTLETID_3);
1321                                            }
1322                                            else {
1323                                                    query.append(_FINDER_COLUMN_G_P_C_PORTLETID_2);
1324                                            }
1325                                    }
1326    
1327                                    query.append(_FINDER_COLUMN_G_P_C_CLASSNAMEID_2);
1328    
1329                                    String sql = query.toString();
1330    
1331                                    Query q = session.createQuery(sql);
1332    
1333                                    QueryPos qPos = QueryPos.getInstance(q);
1334    
1335                                    qPos.add(groupId);
1336    
1337                                    if (portletId != null) {
1338                                            qPos.add(portletId);
1339                                    }
1340    
1341                                    qPos.add(classNameId);
1342    
1343                                    count = (Long)q.uniqueResult();
1344                            }
1345                            catch (Exception e) {
1346                                    throw processException(e);
1347                            }
1348                            finally {
1349                                    if (count == null) {
1350                                            count = Long.valueOf(0);
1351                                    }
1352    
1353                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_C,
1354                                            finderArgs, count);
1355    
1356                                    closeSession(session);
1357                            }
1358                    }
1359    
1360                    return count.intValue();
1361            }
1362    
1363            public int countByG_N_P_C(long groupId, String name, String portletId,
1364                    long classNameId) throws SystemException {
1365                    Object[] finderArgs = new Object[] { groupId, name, portletId, classNameId };
1366    
1367                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_N_P_C,
1368                                    finderArgs, this);
1369    
1370                    if (count == null) {
1371                            Session session = null;
1372    
1373                            try {
1374                                    session = openSession();
1375    
1376                                    StringBundler query = new StringBundler(5);
1377    
1378                                    query.append(_SQL_COUNT_PORTLETITEM_WHERE);
1379    
1380                                    query.append(_FINDER_COLUMN_G_N_P_C_GROUPID_2);
1381    
1382                                    if (name == null) {
1383                                            query.append(_FINDER_COLUMN_G_N_P_C_NAME_1);
1384                                    }
1385                                    else {
1386                                            if (name.equals(StringPool.BLANK)) {
1387                                                    query.append(_FINDER_COLUMN_G_N_P_C_NAME_3);
1388                                            }
1389                                            else {
1390                                                    query.append(_FINDER_COLUMN_G_N_P_C_NAME_2);
1391                                            }
1392                                    }
1393    
1394                                    if (portletId == null) {
1395                                            query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_1);
1396                                    }
1397                                    else {
1398                                            if (portletId.equals(StringPool.BLANK)) {
1399                                                    query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_3);
1400                                            }
1401                                            else {
1402                                                    query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_2);
1403                                            }
1404                                    }
1405    
1406                                    query.append(_FINDER_COLUMN_G_N_P_C_CLASSNAMEID_2);
1407    
1408                                    String sql = query.toString();
1409    
1410                                    Query q = session.createQuery(sql);
1411    
1412                                    QueryPos qPos = QueryPos.getInstance(q);
1413    
1414                                    qPos.add(groupId);
1415    
1416                                    if (name != null) {
1417                                            qPos.add(name);
1418                                    }
1419    
1420                                    if (portletId != null) {
1421                                            qPos.add(portletId);
1422                                    }
1423    
1424                                    qPos.add(classNameId);
1425    
1426                                    count = (Long)q.uniqueResult();
1427                            }
1428                            catch (Exception e) {
1429                                    throw processException(e);
1430                            }
1431                            finally {
1432                                    if (count == null) {
1433                                            count = Long.valueOf(0);
1434                                    }
1435    
1436                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N_P_C,
1437                                            finderArgs, count);
1438    
1439                                    closeSession(session);
1440                            }
1441                    }
1442    
1443                    return count.intValue();
1444            }
1445    
1446            public int countAll() throws SystemException {
1447                    Object[] finderArgs = new Object[0];
1448    
1449                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1450                                    finderArgs, this);
1451    
1452                    if (count == null) {
1453                            Session session = null;
1454    
1455                            try {
1456                                    session = openSession();
1457    
1458                                    Query q = session.createQuery(_SQL_COUNT_PORTLETITEM);
1459    
1460                                    count = (Long)q.uniqueResult();
1461                            }
1462                            catch (Exception e) {
1463                                    throw processException(e);
1464                            }
1465                            finally {
1466                                    if (count == null) {
1467                                            count = Long.valueOf(0);
1468                                    }
1469    
1470                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1471                                            count);
1472    
1473                                    closeSession(session);
1474                            }
1475                    }
1476    
1477                    return count.intValue();
1478            }
1479    
1480            public void afterPropertiesSet() {
1481                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1482                                            com.liferay.portal.util.PropsUtil.get(
1483                                                    "value.object.listener.com.liferay.portal.model.PortletItem")));
1484    
1485                    if (listenerClassNames.length > 0) {
1486                            try {
1487                                    List<ModelListener<PortletItem>> listenersList = new ArrayList<ModelListener<PortletItem>>();
1488    
1489                                    for (String listenerClassName : listenerClassNames) {
1490                                            listenersList.add((ModelListener<PortletItem>)InstanceFactory.newInstance(
1491                                                            listenerClassName));
1492                                    }
1493    
1494                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1495                            }
1496                            catch (Exception e) {
1497                                    _log.error(e);
1498                            }
1499                    }
1500            }
1501    
1502            @BeanReference(type = AccountPersistence.class)
1503            protected AccountPersistence accountPersistence;
1504            @BeanReference(type = AddressPersistence.class)
1505            protected AddressPersistence addressPersistence;
1506            @BeanReference(type = BrowserTrackerPersistence.class)
1507            protected BrowserTrackerPersistence browserTrackerPersistence;
1508            @BeanReference(type = ClassNamePersistence.class)
1509            protected ClassNamePersistence classNamePersistence;
1510            @BeanReference(type = CompanyPersistence.class)
1511            protected CompanyPersistence companyPersistence;
1512            @BeanReference(type = ContactPersistence.class)
1513            protected ContactPersistence contactPersistence;
1514            @BeanReference(type = CountryPersistence.class)
1515            protected CountryPersistence countryPersistence;
1516            @BeanReference(type = EmailAddressPersistence.class)
1517            protected EmailAddressPersistence emailAddressPersistence;
1518            @BeanReference(type = GroupPersistence.class)
1519            protected GroupPersistence groupPersistence;
1520            @BeanReference(type = ImagePersistence.class)
1521            protected ImagePersistence imagePersistence;
1522            @BeanReference(type = LayoutPersistence.class)
1523            protected LayoutPersistence layoutPersistence;
1524            @BeanReference(type = LayoutPrototypePersistence.class)
1525            protected LayoutPrototypePersistence layoutPrototypePersistence;
1526            @BeanReference(type = LayoutSetPersistence.class)
1527            protected LayoutSetPersistence layoutSetPersistence;
1528            @BeanReference(type = LayoutSetPrototypePersistence.class)
1529            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1530            @BeanReference(type = ListTypePersistence.class)
1531            protected ListTypePersistence listTypePersistence;
1532            @BeanReference(type = LockPersistence.class)
1533            protected LockPersistence lockPersistence;
1534            @BeanReference(type = MembershipRequestPersistence.class)
1535            protected MembershipRequestPersistence membershipRequestPersistence;
1536            @BeanReference(type = OrganizationPersistence.class)
1537            protected OrganizationPersistence organizationPersistence;
1538            @BeanReference(type = OrgGroupPermissionPersistence.class)
1539            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1540            @BeanReference(type = OrgGroupRolePersistence.class)
1541            protected OrgGroupRolePersistence orgGroupRolePersistence;
1542            @BeanReference(type = OrgLaborPersistence.class)
1543            protected OrgLaborPersistence orgLaborPersistence;
1544            @BeanReference(type = PasswordPolicyPersistence.class)
1545            protected PasswordPolicyPersistence passwordPolicyPersistence;
1546            @BeanReference(type = PasswordPolicyRelPersistence.class)
1547            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1548            @BeanReference(type = PasswordTrackerPersistence.class)
1549            protected PasswordTrackerPersistence passwordTrackerPersistence;
1550            @BeanReference(type = PermissionPersistence.class)
1551            protected PermissionPersistence permissionPersistence;
1552            @BeanReference(type = PhonePersistence.class)
1553            protected PhonePersistence phonePersistence;
1554            @BeanReference(type = PluginSettingPersistence.class)
1555            protected PluginSettingPersistence pluginSettingPersistence;
1556            @BeanReference(type = PortletPersistence.class)
1557            protected PortletPersistence portletPersistence;
1558            @BeanReference(type = PortletItemPersistence.class)
1559            protected PortletItemPersistence portletItemPersistence;
1560            @BeanReference(type = PortletPreferencesPersistence.class)
1561            protected PortletPreferencesPersistence portletPreferencesPersistence;
1562            @BeanReference(type = RegionPersistence.class)
1563            protected RegionPersistence regionPersistence;
1564            @BeanReference(type = ReleasePersistence.class)
1565            protected ReleasePersistence releasePersistence;
1566            @BeanReference(type = ResourcePersistence.class)
1567            protected ResourcePersistence resourcePersistence;
1568            @BeanReference(type = ResourceActionPersistence.class)
1569            protected ResourceActionPersistence resourceActionPersistence;
1570            @BeanReference(type = ResourceCodePersistence.class)
1571            protected ResourceCodePersistence resourceCodePersistence;
1572            @BeanReference(type = ResourcePermissionPersistence.class)
1573            protected ResourcePermissionPersistence resourcePermissionPersistence;
1574            @BeanReference(type = RolePersistence.class)
1575            protected RolePersistence rolePersistence;
1576            @BeanReference(type = ServiceComponentPersistence.class)
1577            protected ServiceComponentPersistence serviceComponentPersistence;
1578            @BeanReference(type = ShardPersistence.class)
1579            protected ShardPersistence shardPersistence;
1580            @BeanReference(type = SubscriptionPersistence.class)
1581            protected SubscriptionPersistence subscriptionPersistence;
1582            @BeanReference(type = TicketPersistence.class)
1583            protected TicketPersistence ticketPersistence;
1584            @BeanReference(type = TeamPersistence.class)
1585            protected TeamPersistence teamPersistence;
1586            @BeanReference(type = UserPersistence.class)
1587            protected UserPersistence userPersistence;
1588            @BeanReference(type = UserGroupPersistence.class)
1589            protected UserGroupPersistence userGroupPersistence;
1590            @BeanReference(type = UserGroupGroupRolePersistence.class)
1591            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1592            @BeanReference(type = UserGroupRolePersistence.class)
1593            protected UserGroupRolePersistence userGroupRolePersistence;
1594            @BeanReference(type = UserIdMapperPersistence.class)
1595            protected UserIdMapperPersistence userIdMapperPersistence;
1596            @BeanReference(type = UserTrackerPersistence.class)
1597            protected UserTrackerPersistence userTrackerPersistence;
1598            @BeanReference(type = UserTrackerPathPersistence.class)
1599            protected UserTrackerPathPersistence userTrackerPathPersistence;
1600            @BeanReference(type = WebDAVPropsPersistence.class)
1601            protected WebDAVPropsPersistence webDAVPropsPersistence;
1602            @BeanReference(type = WebsitePersistence.class)
1603            protected WebsitePersistence websitePersistence;
1604            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1605            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1606            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1607            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1608            private static final String _SQL_SELECT_PORTLETITEM = "SELECT portletItem FROM PortletItem portletItem";
1609            private static final String _SQL_SELECT_PORTLETITEM_WHERE = "SELECT portletItem FROM PortletItem portletItem WHERE ";
1610            private static final String _SQL_COUNT_PORTLETITEM = "SELECT COUNT(portletItem) FROM PortletItem portletItem";
1611            private static final String _SQL_COUNT_PORTLETITEM_WHERE = "SELECT COUNT(portletItem) FROM PortletItem portletItem WHERE ";
1612            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "portletItem.groupId = ? AND ";
1613            private static final String _FINDER_COLUMN_G_C_CLASSNAMEID_2 = "portletItem.classNameId = ?";
1614            private static final String _FINDER_COLUMN_G_P_C_GROUPID_2 = "portletItem.groupId = ? AND ";
1615            private static final String _FINDER_COLUMN_G_P_C_PORTLETID_1 = "portletItem.portletId IS NULL AND ";
1616            private static final String _FINDER_COLUMN_G_P_C_PORTLETID_2 = "portletItem.portletId = ? AND ";
1617            private static final String _FINDER_COLUMN_G_P_C_PORTLETID_3 = "(portletItem.portletId IS NULL OR portletItem.portletId = ?) AND ";
1618            private static final String _FINDER_COLUMN_G_P_C_CLASSNAMEID_2 = "portletItem.classNameId = ?";
1619            private static final String _FINDER_COLUMN_G_N_P_C_GROUPID_2 = "portletItem.groupId = ? AND ";
1620            private static final String _FINDER_COLUMN_G_N_P_C_NAME_1 = "portletItem.name IS NULL AND ";
1621            private static final String _FINDER_COLUMN_G_N_P_C_NAME_2 = "lower(portletItem.name) = lower(?) AND ";
1622            private static final String _FINDER_COLUMN_G_N_P_C_NAME_3 = "(portletItem.name IS NULL OR lower(portletItem.name) = lower(?)) AND ";
1623            private static final String _FINDER_COLUMN_G_N_P_C_PORTLETID_1 = "portletItem.portletId IS NULL AND ";
1624            private static final String _FINDER_COLUMN_G_N_P_C_PORTLETID_2 = "portletItem.portletId = ? AND ";
1625            private static final String _FINDER_COLUMN_G_N_P_C_PORTLETID_3 = "(portletItem.portletId IS NULL OR portletItem.portletId = ?) AND ";
1626            private static final String _FINDER_COLUMN_G_N_P_C_CLASSNAMEID_2 = "portletItem.classNameId = ?";
1627            private static final String _ORDER_BY_ENTITY_ALIAS = "portletItem.";
1628            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PortletItem exists with the primary key ";
1629            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PortletItem exists with the key {";
1630            private static Log _log = LogFactoryUtil.getLog(PortletItemPersistenceImpl.class);
1631    }