001    /**
002     * Copyright (c) 2000-2012 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.NoSuchPreferencesException;
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.PortalPreferences;
040    import com.liferay.portal.model.impl.PortalPreferencesImpl;
041    import com.liferay.portal.model.impl.PortalPreferencesModelImpl;
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 portal preferences 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 PortalPreferencesPersistence
059     * @see PortalPreferencesUtil
060     * @generated
061     */
062    public class PortalPreferencesPersistenceImpl extends BasePersistenceImpl<PortalPreferences>
063            implements PortalPreferencesPersistence {
064            /*
065             * NOTE FOR DEVELOPERS:
066             *
067             * Never modify or reference this class directly. Always use {@link PortalPreferencesUtil} to access the portal preferences persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
068             */
069            public static final String FINDER_CLASS_NAME_ENTITY = PortalPreferencesImpl.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_FETCH_BY_O_O = new FinderPath(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
075                            PortalPreferencesModelImpl.FINDER_CACHE_ENABLED,
076                            PortalPreferencesImpl.class, FINDER_CLASS_NAME_ENTITY,
077                            "fetchByO_O",
078                            new String[] { Long.class.getName(), Integer.class.getName() },
079                            PortalPreferencesModelImpl.OWNERID_COLUMN_BITMASK |
080                            PortalPreferencesModelImpl.OWNERTYPE_COLUMN_BITMASK);
081            public static final FinderPath FINDER_PATH_COUNT_BY_O_O = new FinderPath(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
082                            PortalPreferencesModelImpl.FINDER_CACHE_ENABLED, Long.class,
083                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByO_O",
084                            new String[] { Long.class.getName(), Integer.class.getName() });
085            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
086                            PortalPreferencesModelImpl.FINDER_CACHE_ENABLED,
087                            PortalPreferencesImpl.class,
088                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
089            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
090                            PortalPreferencesModelImpl.FINDER_CACHE_ENABLED,
091                            PortalPreferencesImpl.class,
092                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
093            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
094                            PortalPreferencesModelImpl.FINDER_CACHE_ENABLED, Long.class,
095                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
096    
097            /**
098             * Caches the portal preferences in the entity cache if it is enabled.
099             *
100             * @param portalPreferences the portal preferences
101             */
102            public void cacheResult(PortalPreferences portalPreferences) {
103                    EntityCacheUtil.putResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
104                            PortalPreferencesImpl.class, portalPreferences.getPrimaryKey(),
105                            portalPreferences);
106    
107                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O,
108                            new Object[] {
109                                    Long.valueOf(portalPreferences.getOwnerId()),
110                                    Integer.valueOf(portalPreferences.getOwnerType())
111                            }, portalPreferences);
112    
113                    portalPreferences.resetOriginalValues();
114            }
115    
116            /**
117             * Caches the portal preferenceses in the entity cache if it is enabled.
118             *
119             * @param portalPreferenceses the portal preferenceses
120             */
121            public void cacheResult(List<PortalPreferences> portalPreferenceses) {
122                    for (PortalPreferences portalPreferences : portalPreferenceses) {
123                            if (EntityCacheUtil.getResult(
124                                                    PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
125                                                    PortalPreferencesImpl.class,
126                                                    portalPreferences.getPrimaryKey()) == null) {
127                                    cacheResult(portalPreferences);
128                            }
129                            else {
130                                    portalPreferences.resetOriginalValues();
131                            }
132                    }
133            }
134    
135            /**
136             * Clears the cache for all portal preferenceses.
137             *
138             * <p>
139             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
140             * </p>
141             */
142            @Override
143            public void clearCache() {
144                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
145                            CacheRegistryUtil.clear(PortalPreferencesImpl.class.getName());
146                    }
147    
148                    EntityCacheUtil.clearCache(PortalPreferencesImpl.class.getName());
149    
150                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
151                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
152                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
153            }
154    
155            /**
156             * Clears the cache for the portal preferences.
157             *
158             * <p>
159             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
160             * </p>
161             */
162            @Override
163            public void clearCache(PortalPreferences portalPreferences) {
164                    EntityCacheUtil.removeResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
165                            PortalPreferencesImpl.class, portalPreferences.getPrimaryKey());
166    
167                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
168                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
169    
170                    clearUniqueFindersCache(portalPreferences);
171            }
172    
173            @Override
174            public void clearCache(List<PortalPreferences> portalPreferenceses) {
175                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
176                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
177    
178                    for (PortalPreferences portalPreferences : portalPreferenceses) {
179                            EntityCacheUtil.removeResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
180                                    PortalPreferencesImpl.class, portalPreferences.getPrimaryKey());
181    
182                            clearUniqueFindersCache(portalPreferences);
183                    }
184            }
185    
186            protected void clearUniqueFindersCache(PortalPreferences portalPreferences) {
187                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_O_O,
188                            new Object[] {
189                                    Long.valueOf(portalPreferences.getOwnerId()),
190                                    Integer.valueOf(portalPreferences.getOwnerType())
191                            });
192            }
193    
194            /**
195             * Creates a new portal preferences with the primary key. Does not add the portal preferences to the database.
196             *
197             * @param portalPreferencesId the primary key for the new portal preferences
198             * @return the new portal preferences
199             */
200            public PortalPreferences create(long portalPreferencesId) {
201                    PortalPreferences portalPreferences = new PortalPreferencesImpl();
202    
203                    portalPreferences.setNew(true);
204                    portalPreferences.setPrimaryKey(portalPreferencesId);
205    
206                    return portalPreferences;
207            }
208    
209            /**
210             * Removes the portal preferences with the primary key from the database. Also notifies the appropriate model listeners.
211             *
212             * @param portalPreferencesId the primary key of the portal preferences
213             * @return the portal preferences that was removed
214             * @throws com.liferay.portal.NoSuchPreferencesException if a portal preferences with the primary key could not be found
215             * @throws SystemException if a system exception occurred
216             */
217            public PortalPreferences remove(long portalPreferencesId)
218                    throws NoSuchPreferencesException, SystemException {
219                    return remove(Long.valueOf(portalPreferencesId));
220            }
221    
222            /**
223             * Removes the portal preferences with the primary key from the database. Also notifies the appropriate model listeners.
224             *
225             * @param primaryKey the primary key of the portal preferences
226             * @return the portal preferences that was removed
227             * @throws com.liferay.portal.NoSuchPreferencesException if a portal preferences with the primary key could not be found
228             * @throws SystemException if a system exception occurred
229             */
230            @Override
231            public PortalPreferences remove(Serializable primaryKey)
232                    throws NoSuchPreferencesException, SystemException {
233                    Session session = null;
234    
235                    try {
236                            session = openSession();
237    
238                            PortalPreferences portalPreferences = (PortalPreferences)session.get(PortalPreferencesImpl.class,
239                                            primaryKey);
240    
241                            if (portalPreferences == null) {
242                                    if (_log.isWarnEnabled()) {
243                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
244                                    }
245    
246                                    throw new NoSuchPreferencesException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
247                                            primaryKey);
248                            }
249    
250                            return remove(portalPreferences);
251                    }
252                    catch (NoSuchPreferencesException nsee) {
253                            throw nsee;
254                    }
255                    catch (Exception e) {
256                            throw processException(e);
257                    }
258                    finally {
259                            closeSession(session);
260                    }
261            }
262    
263            @Override
264            protected PortalPreferences removeImpl(PortalPreferences portalPreferences)
265                    throws SystemException {
266                    portalPreferences = toUnwrappedModel(portalPreferences);
267    
268                    Session session = null;
269    
270                    try {
271                            session = openSession();
272    
273                            BatchSessionUtil.delete(session, portalPreferences);
274                    }
275                    catch (Exception e) {
276                            throw processException(e);
277                    }
278                    finally {
279                            closeSession(session);
280                    }
281    
282                    clearCache(portalPreferences);
283    
284                    return portalPreferences;
285            }
286    
287            @Override
288            public PortalPreferences updateImpl(
289                    com.liferay.portal.model.PortalPreferences portalPreferences,
290                    boolean merge) throws SystemException {
291                    portalPreferences = toUnwrappedModel(portalPreferences);
292    
293                    boolean isNew = portalPreferences.isNew();
294    
295                    PortalPreferencesModelImpl portalPreferencesModelImpl = (PortalPreferencesModelImpl)portalPreferences;
296    
297                    Session session = null;
298    
299                    try {
300                            session = openSession();
301    
302                            BatchSessionUtil.update(session, portalPreferences, merge);
303    
304                            portalPreferences.setNew(false);
305                    }
306                    catch (Exception e) {
307                            throw processException(e);
308                    }
309                    finally {
310                            closeSession(session);
311                    }
312    
313                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
314    
315                    if (isNew || !PortalPreferencesModelImpl.COLUMN_BITMASK_ENABLED) {
316                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
317                    }
318    
319                    EntityCacheUtil.putResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
320                            PortalPreferencesImpl.class, portalPreferences.getPrimaryKey(),
321                            portalPreferences);
322    
323                    if (isNew) {
324                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O,
325                                    new Object[] {
326                                            Long.valueOf(portalPreferences.getOwnerId()),
327                                            Integer.valueOf(portalPreferences.getOwnerType())
328                                    }, portalPreferences);
329                    }
330                    else {
331                            if ((portalPreferencesModelImpl.getColumnBitmask() &
332                                            FINDER_PATH_FETCH_BY_O_O.getColumnBitmask()) != 0) {
333                                    Object[] args = new Object[] {
334                                                    Long.valueOf(portalPreferencesModelImpl.getOriginalOwnerId()),
335                                                    Integer.valueOf(portalPreferencesModelImpl.getOriginalOwnerType())
336                                            };
337    
338                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_O_O, args);
339                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_O_O, args);
340    
341                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O,
342                                            new Object[] {
343                                                    Long.valueOf(portalPreferences.getOwnerId()),
344                                                    Integer.valueOf(portalPreferences.getOwnerType())
345                                            }, portalPreferences);
346                            }
347                    }
348    
349                    return portalPreferences;
350            }
351    
352            protected PortalPreferences toUnwrappedModel(
353                    PortalPreferences portalPreferences) {
354                    if (portalPreferences instanceof PortalPreferencesImpl) {
355                            return portalPreferences;
356                    }
357    
358                    PortalPreferencesImpl portalPreferencesImpl = new PortalPreferencesImpl();
359    
360                    portalPreferencesImpl.setNew(portalPreferences.isNew());
361                    portalPreferencesImpl.setPrimaryKey(portalPreferences.getPrimaryKey());
362    
363                    portalPreferencesImpl.setPortalPreferencesId(portalPreferences.getPortalPreferencesId());
364                    portalPreferencesImpl.setOwnerId(portalPreferences.getOwnerId());
365                    portalPreferencesImpl.setOwnerType(portalPreferences.getOwnerType());
366                    portalPreferencesImpl.setPreferences(portalPreferences.getPreferences());
367    
368                    return portalPreferencesImpl;
369            }
370    
371            /**
372             * Returns the portal preferences with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
373             *
374             * @param primaryKey the primary key of the portal preferences
375             * @return the portal preferences
376             * @throws com.liferay.portal.NoSuchModelException if a portal preferences with the primary key could not be found
377             * @throws SystemException if a system exception occurred
378             */
379            @Override
380            public PortalPreferences findByPrimaryKey(Serializable primaryKey)
381                    throws NoSuchModelException, SystemException {
382                    return findByPrimaryKey(((Long)primaryKey).longValue());
383            }
384    
385            /**
386             * Returns the portal preferences with the primary key or throws a {@link com.liferay.portal.NoSuchPreferencesException} if it could not be found.
387             *
388             * @param portalPreferencesId the primary key of the portal preferences
389             * @return the portal preferences
390             * @throws com.liferay.portal.NoSuchPreferencesException if a portal preferences with the primary key could not be found
391             * @throws SystemException if a system exception occurred
392             */
393            public PortalPreferences findByPrimaryKey(long portalPreferencesId)
394                    throws NoSuchPreferencesException, SystemException {
395                    PortalPreferences portalPreferences = fetchByPrimaryKey(portalPreferencesId);
396    
397                    if (portalPreferences == null) {
398                            if (_log.isWarnEnabled()) {
399                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
400                                            portalPreferencesId);
401                            }
402    
403                            throw new NoSuchPreferencesException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
404                                    portalPreferencesId);
405                    }
406    
407                    return portalPreferences;
408            }
409    
410            /**
411             * Returns the portal preferences with the primary key or returns <code>null</code> if it could not be found.
412             *
413             * @param primaryKey the primary key of the portal preferences
414             * @return the portal preferences, or <code>null</code> if a portal preferences with the primary key could not be found
415             * @throws SystemException if a system exception occurred
416             */
417            @Override
418            public PortalPreferences fetchByPrimaryKey(Serializable primaryKey)
419                    throws SystemException {
420                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
421            }
422    
423            /**
424             * Returns the portal preferences with the primary key or returns <code>null</code> if it could not be found.
425             *
426             * @param portalPreferencesId the primary key of the portal preferences
427             * @return the portal preferences, or <code>null</code> if a portal preferences with the primary key could not be found
428             * @throws SystemException if a system exception occurred
429             */
430            public PortalPreferences fetchByPrimaryKey(long portalPreferencesId)
431                    throws SystemException {
432                    PortalPreferences portalPreferences = (PortalPreferences)EntityCacheUtil.getResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
433                                    PortalPreferencesImpl.class, portalPreferencesId);
434    
435                    if (portalPreferences == _nullPortalPreferences) {
436                            return null;
437                    }
438    
439                    if (portalPreferences == null) {
440                            Session session = null;
441    
442                            boolean hasException = false;
443    
444                            try {
445                                    session = openSession();
446    
447                                    portalPreferences = (PortalPreferences)session.get(PortalPreferencesImpl.class,
448                                                    Long.valueOf(portalPreferencesId));
449                            }
450                            catch (Exception e) {
451                                    hasException = true;
452    
453                                    throw processException(e);
454                            }
455                            finally {
456                                    if (portalPreferences != null) {
457                                            cacheResult(portalPreferences);
458                                    }
459                                    else if (!hasException) {
460                                            EntityCacheUtil.putResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
461                                                    PortalPreferencesImpl.class, portalPreferencesId,
462                                                    _nullPortalPreferences);
463                                    }
464    
465                                    closeSession(session);
466                            }
467                    }
468    
469                    return portalPreferences;
470            }
471    
472            /**
473             * Returns the portal preferences where ownerId = &#63; and ownerType = &#63; or throws a {@link com.liferay.portal.NoSuchPreferencesException} if it could not be found.
474             *
475             * @param ownerId the owner ID
476             * @param ownerType the owner type
477             * @return the matching portal preferences
478             * @throws com.liferay.portal.NoSuchPreferencesException if a matching portal preferences could not be found
479             * @throws SystemException if a system exception occurred
480             */
481            public PortalPreferences findByO_O(long ownerId, int ownerType)
482                    throws NoSuchPreferencesException, SystemException {
483                    PortalPreferences portalPreferences = fetchByO_O(ownerId, ownerType);
484    
485                    if (portalPreferences == null) {
486                            StringBundler msg = new StringBundler(6);
487    
488                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
489    
490                            msg.append("ownerId=");
491                            msg.append(ownerId);
492    
493                            msg.append(", ownerType=");
494                            msg.append(ownerType);
495    
496                            msg.append(StringPool.CLOSE_CURLY_BRACE);
497    
498                            if (_log.isWarnEnabled()) {
499                                    _log.warn(msg.toString());
500                            }
501    
502                            throw new NoSuchPreferencesException(msg.toString());
503                    }
504    
505                    return portalPreferences;
506            }
507    
508            /**
509             * Returns the portal preferences where ownerId = &#63; and ownerType = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
510             *
511             * @param ownerId the owner ID
512             * @param ownerType the owner type
513             * @return the matching portal preferences, or <code>null</code> if a matching portal preferences could not be found
514             * @throws SystemException if a system exception occurred
515             */
516            public PortalPreferences fetchByO_O(long ownerId, int ownerType)
517                    throws SystemException {
518                    return fetchByO_O(ownerId, ownerType, true);
519            }
520    
521            /**
522             * Returns the portal preferences where ownerId = &#63; and ownerType = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
523             *
524             * @param ownerId the owner ID
525             * @param ownerType the owner type
526             * @param retrieveFromCache whether to use the finder cache
527             * @return the matching portal preferences, or <code>null</code> if a matching portal preferences could not be found
528             * @throws SystemException if a system exception occurred
529             */
530            public PortalPreferences fetchByO_O(long ownerId, int ownerType,
531                    boolean retrieveFromCache) throws SystemException {
532                    Object[] finderArgs = new Object[] { ownerId, ownerType };
533    
534                    Object result = null;
535    
536                    if (retrieveFromCache) {
537                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_O_O,
538                                            finderArgs, this);
539                    }
540    
541                    if (result == null) {
542                            StringBundler query = new StringBundler(3);
543    
544                            query.append(_SQL_SELECT_PORTALPREFERENCES_WHERE);
545    
546                            query.append(_FINDER_COLUMN_O_O_OWNERID_2);
547    
548                            query.append(_FINDER_COLUMN_O_O_OWNERTYPE_2);
549    
550                            String sql = query.toString();
551    
552                            Session session = null;
553    
554                            try {
555                                    session = openSession();
556    
557                                    Query q = session.createQuery(sql);
558    
559                                    QueryPos qPos = QueryPos.getInstance(q);
560    
561                                    qPos.add(ownerId);
562    
563                                    qPos.add(ownerType);
564    
565                                    List<PortalPreferences> list = q.list();
566    
567                                    result = list;
568    
569                                    PortalPreferences portalPreferences = null;
570    
571                                    if (list.isEmpty()) {
572                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O,
573                                                    finderArgs, list);
574                                    }
575                                    else {
576                                            portalPreferences = list.get(0);
577    
578                                            cacheResult(portalPreferences);
579    
580                                            if ((portalPreferences.getOwnerId() != ownerId) ||
581                                                            (portalPreferences.getOwnerType() != ownerType)) {
582                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O,
583                                                            finderArgs, portalPreferences);
584                                            }
585                                    }
586    
587                                    return portalPreferences;
588                            }
589                            catch (Exception e) {
590                                    throw processException(e);
591                            }
592                            finally {
593                                    if (result == null) {
594                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_O_O,
595                                                    finderArgs);
596                                    }
597    
598                                    closeSession(session);
599                            }
600                    }
601                    else {
602                            if (result instanceof List<?>) {
603                                    return null;
604                            }
605                            else {
606                                    return (PortalPreferences)result;
607                            }
608                    }
609            }
610    
611            /**
612             * Returns all the portal preferenceses.
613             *
614             * @return the portal preferenceses
615             * @throws SystemException if a system exception occurred
616             */
617            public List<PortalPreferences> findAll() throws SystemException {
618                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
619            }
620    
621            /**
622             * Returns a range of all the portal preferenceses.
623             *
624             * <p>
625             * 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.
626             * </p>
627             *
628             * @param start the lower bound of the range of portal preferenceses
629             * @param end the upper bound of the range of portal preferenceses (not inclusive)
630             * @return the range of portal preferenceses
631             * @throws SystemException if a system exception occurred
632             */
633            public List<PortalPreferences> findAll(int start, int end)
634                    throws SystemException {
635                    return findAll(start, end, null);
636            }
637    
638            /**
639             * Returns an ordered range of all the portal preferenceses.
640             *
641             * <p>
642             * 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.
643             * </p>
644             *
645             * @param start the lower bound of the range of portal preferenceses
646             * @param end the upper bound of the range of portal preferenceses (not inclusive)
647             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
648             * @return the ordered range of portal preferenceses
649             * @throws SystemException if a system exception occurred
650             */
651            public List<PortalPreferences> findAll(int start, int end,
652                    OrderByComparator orderByComparator) throws SystemException {
653                    FinderPath finderPath = null;
654                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
655    
656                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
657                                    (orderByComparator == null)) {
658                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
659                            finderArgs = FINDER_ARGS_EMPTY;
660                    }
661                    else {
662                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
663                            finderArgs = new Object[] { start, end, orderByComparator };
664                    }
665    
666                    List<PortalPreferences> list = (List<PortalPreferences>)FinderCacheUtil.getResult(finderPath,
667                                    finderArgs, this);
668    
669                    if (list == null) {
670                            StringBundler query = null;
671                            String sql = null;
672    
673                            if (orderByComparator != null) {
674                                    query = new StringBundler(2 +
675                                                    (orderByComparator.getOrderByFields().length * 3));
676    
677                                    query.append(_SQL_SELECT_PORTALPREFERENCES);
678    
679                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
680                                            orderByComparator);
681    
682                                    sql = query.toString();
683                            }
684                            else {
685                                    sql = _SQL_SELECT_PORTALPREFERENCES;
686                            }
687    
688                            Session session = null;
689    
690                            try {
691                                    session = openSession();
692    
693                                    Query q = session.createQuery(sql);
694    
695                                    if (orderByComparator == null) {
696                                            list = (List<PortalPreferences>)QueryUtil.list(q,
697                                                            getDialect(), start, end, false);
698    
699                                            Collections.sort(list);
700                                    }
701                                    else {
702                                            list = (List<PortalPreferences>)QueryUtil.list(q,
703                                                            getDialect(), start, end);
704                                    }
705                            }
706                            catch (Exception e) {
707                                    throw processException(e);
708                            }
709                            finally {
710                                    if (list == null) {
711                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
712                                    }
713                                    else {
714                                            cacheResult(list);
715    
716                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
717                                    }
718    
719                                    closeSession(session);
720                            }
721                    }
722    
723                    return list;
724            }
725    
726            /**
727             * Removes the portal preferences where ownerId = &#63; and ownerType = &#63; from the database.
728             *
729             * @param ownerId the owner ID
730             * @param ownerType the owner type
731             * @throws SystemException if a system exception occurred
732             */
733            public void removeByO_O(long ownerId, int ownerType)
734                    throws NoSuchPreferencesException, SystemException {
735                    PortalPreferences portalPreferences = findByO_O(ownerId, ownerType);
736    
737                    remove(portalPreferences);
738            }
739    
740            /**
741             * Removes all the portal preferenceses from the database.
742             *
743             * @throws SystemException if a system exception occurred
744             */
745            public void removeAll() throws SystemException {
746                    for (PortalPreferences portalPreferences : findAll()) {
747                            remove(portalPreferences);
748                    }
749            }
750    
751            /**
752             * Returns the number of portal preferenceses where ownerId = &#63; and ownerType = &#63;.
753             *
754             * @param ownerId the owner ID
755             * @param ownerType the owner type
756             * @return the number of matching portal preferenceses
757             * @throws SystemException if a system exception occurred
758             */
759            public int countByO_O(long ownerId, int ownerType)
760                    throws SystemException {
761                    Object[] finderArgs = new Object[] { ownerId, ownerType };
762    
763                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_O_O,
764                                    finderArgs, this);
765    
766                    if (count == null) {
767                            StringBundler query = new StringBundler(3);
768    
769                            query.append(_SQL_COUNT_PORTALPREFERENCES_WHERE);
770    
771                            query.append(_FINDER_COLUMN_O_O_OWNERID_2);
772    
773                            query.append(_FINDER_COLUMN_O_O_OWNERTYPE_2);
774    
775                            String sql = query.toString();
776    
777                            Session session = null;
778    
779                            try {
780                                    session = openSession();
781    
782                                    Query q = session.createQuery(sql);
783    
784                                    QueryPos qPos = QueryPos.getInstance(q);
785    
786                                    qPos.add(ownerId);
787    
788                                    qPos.add(ownerType);
789    
790                                    count = (Long)q.uniqueResult();
791                            }
792                            catch (Exception e) {
793                                    throw processException(e);
794                            }
795                            finally {
796                                    if (count == null) {
797                                            count = Long.valueOf(0);
798                                    }
799    
800                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_O_O, finderArgs,
801                                            count);
802    
803                                    closeSession(session);
804                            }
805                    }
806    
807                    return count.intValue();
808            }
809    
810            /**
811             * Returns the number of portal preferenceses.
812             *
813             * @return the number of portal preferenceses
814             * @throws SystemException if a system exception occurred
815             */
816            public int countAll() throws SystemException {
817                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
818                                    FINDER_ARGS_EMPTY, this);
819    
820                    if (count == null) {
821                            Session session = null;
822    
823                            try {
824                                    session = openSession();
825    
826                                    Query q = session.createQuery(_SQL_COUNT_PORTALPREFERENCES);
827    
828                                    count = (Long)q.uniqueResult();
829                            }
830                            catch (Exception e) {
831                                    throw processException(e);
832                            }
833                            finally {
834                                    if (count == null) {
835                                            count = Long.valueOf(0);
836                                    }
837    
838                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
839                                            FINDER_ARGS_EMPTY, count);
840    
841                                    closeSession(session);
842                            }
843                    }
844    
845                    return count.intValue();
846            }
847    
848            /**
849             * Initializes the portal preferences persistence.
850             */
851            public void afterPropertiesSet() {
852                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
853                                            com.liferay.portal.util.PropsUtil.get(
854                                                    "value.object.listener.com.liferay.portal.model.PortalPreferences")));
855    
856                    if (listenerClassNames.length > 0) {
857                            try {
858                                    List<ModelListener<PortalPreferences>> listenersList = new ArrayList<ModelListener<PortalPreferences>>();
859    
860                                    for (String listenerClassName : listenerClassNames) {
861                                            listenersList.add((ModelListener<PortalPreferences>)InstanceFactory.newInstance(
862                                                            listenerClassName));
863                                    }
864    
865                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
866                            }
867                            catch (Exception e) {
868                                    _log.error(e);
869                            }
870                    }
871            }
872    
873            public void destroy() {
874                    EntityCacheUtil.removeCache(PortalPreferencesImpl.class.getName());
875                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
876                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
877            }
878    
879            @BeanReference(type = AccountPersistence.class)
880            protected AccountPersistence accountPersistence;
881            @BeanReference(type = AddressPersistence.class)
882            protected AddressPersistence addressPersistence;
883            @BeanReference(type = BrowserTrackerPersistence.class)
884            protected BrowserTrackerPersistence browserTrackerPersistence;
885            @BeanReference(type = ClassNamePersistence.class)
886            protected ClassNamePersistence classNamePersistence;
887            @BeanReference(type = ClusterGroupPersistence.class)
888            protected ClusterGroupPersistence clusterGroupPersistence;
889            @BeanReference(type = CompanyPersistence.class)
890            protected CompanyPersistence companyPersistence;
891            @BeanReference(type = ContactPersistence.class)
892            protected ContactPersistence contactPersistence;
893            @BeanReference(type = CountryPersistence.class)
894            protected CountryPersistence countryPersistence;
895            @BeanReference(type = EmailAddressPersistence.class)
896            protected EmailAddressPersistence emailAddressPersistence;
897            @BeanReference(type = GroupPersistence.class)
898            protected GroupPersistence groupPersistence;
899            @BeanReference(type = ImagePersistence.class)
900            protected ImagePersistence imagePersistence;
901            @BeanReference(type = LayoutPersistence.class)
902            protected LayoutPersistence layoutPersistence;
903            @BeanReference(type = LayoutBranchPersistence.class)
904            protected LayoutBranchPersistence layoutBranchPersistence;
905            @BeanReference(type = LayoutPrototypePersistence.class)
906            protected LayoutPrototypePersistence layoutPrototypePersistence;
907            @BeanReference(type = LayoutRevisionPersistence.class)
908            protected LayoutRevisionPersistence layoutRevisionPersistence;
909            @BeanReference(type = LayoutSetPersistence.class)
910            protected LayoutSetPersistence layoutSetPersistence;
911            @BeanReference(type = LayoutSetBranchPersistence.class)
912            protected LayoutSetBranchPersistence layoutSetBranchPersistence;
913            @BeanReference(type = LayoutSetPrototypePersistence.class)
914            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
915            @BeanReference(type = ListTypePersistence.class)
916            protected ListTypePersistence listTypePersistence;
917            @BeanReference(type = LockPersistence.class)
918            protected LockPersistence lockPersistence;
919            @BeanReference(type = MembershipRequestPersistence.class)
920            protected MembershipRequestPersistence membershipRequestPersistence;
921            @BeanReference(type = OrganizationPersistence.class)
922            protected OrganizationPersistence organizationPersistence;
923            @BeanReference(type = OrgGroupPermissionPersistence.class)
924            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
925            @BeanReference(type = OrgGroupRolePersistence.class)
926            protected OrgGroupRolePersistence orgGroupRolePersistence;
927            @BeanReference(type = OrgLaborPersistence.class)
928            protected OrgLaborPersistence orgLaborPersistence;
929            @BeanReference(type = PasswordPolicyPersistence.class)
930            protected PasswordPolicyPersistence passwordPolicyPersistence;
931            @BeanReference(type = PasswordPolicyRelPersistence.class)
932            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
933            @BeanReference(type = PasswordTrackerPersistence.class)
934            protected PasswordTrackerPersistence passwordTrackerPersistence;
935            @BeanReference(type = PermissionPersistence.class)
936            protected PermissionPersistence permissionPersistence;
937            @BeanReference(type = PhonePersistence.class)
938            protected PhonePersistence phonePersistence;
939            @BeanReference(type = PluginSettingPersistence.class)
940            protected PluginSettingPersistence pluginSettingPersistence;
941            @BeanReference(type = PortalPreferencesPersistence.class)
942            protected PortalPreferencesPersistence portalPreferencesPersistence;
943            @BeanReference(type = PortletPersistence.class)
944            protected PortletPersistence portletPersistence;
945            @BeanReference(type = PortletItemPersistence.class)
946            protected PortletItemPersistence portletItemPersistence;
947            @BeanReference(type = PortletPreferencesPersistence.class)
948            protected PortletPreferencesPersistence portletPreferencesPersistence;
949            @BeanReference(type = RegionPersistence.class)
950            protected RegionPersistence regionPersistence;
951            @BeanReference(type = ReleasePersistence.class)
952            protected ReleasePersistence releasePersistence;
953            @BeanReference(type = RepositoryPersistence.class)
954            protected RepositoryPersistence repositoryPersistence;
955            @BeanReference(type = RepositoryEntryPersistence.class)
956            protected RepositoryEntryPersistence repositoryEntryPersistence;
957            @BeanReference(type = ResourcePersistence.class)
958            protected ResourcePersistence resourcePersistence;
959            @BeanReference(type = ResourceActionPersistence.class)
960            protected ResourceActionPersistence resourceActionPersistence;
961            @BeanReference(type = ResourceBlockPersistence.class)
962            protected ResourceBlockPersistence resourceBlockPersistence;
963            @BeanReference(type = ResourceBlockPermissionPersistence.class)
964            protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
965            @BeanReference(type = ResourceCodePersistence.class)
966            protected ResourceCodePersistence resourceCodePersistence;
967            @BeanReference(type = ResourcePermissionPersistence.class)
968            protected ResourcePermissionPersistence resourcePermissionPersistence;
969            @BeanReference(type = ResourceTypePermissionPersistence.class)
970            protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
971            @BeanReference(type = RolePersistence.class)
972            protected RolePersistence rolePersistence;
973            @BeanReference(type = ServiceComponentPersistence.class)
974            protected ServiceComponentPersistence serviceComponentPersistence;
975            @BeanReference(type = ShardPersistence.class)
976            protected ShardPersistence shardPersistence;
977            @BeanReference(type = SubscriptionPersistence.class)
978            protected SubscriptionPersistence subscriptionPersistence;
979            @BeanReference(type = TeamPersistence.class)
980            protected TeamPersistence teamPersistence;
981            @BeanReference(type = TicketPersistence.class)
982            protected TicketPersistence ticketPersistence;
983            @BeanReference(type = UserPersistence.class)
984            protected UserPersistence userPersistence;
985            @BeanReference(type = UserGroupPersistence.class)
986            protected UserGroupPersistence userGroupPersistence;
987            @BeanReference(type = UserGroupGroupRolePersistence.class)
988            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
989            @BeanReference(type = UserGroupRolePersistence.class)
990            protected UserGroupRolePersistence userGroupRolePersistence;
991            @BeanReference(type = UserIdMapperPersistence.class)
992            protected UserIdMapperPersistence userIdMapperPersistence;
993            @BeanReference(type = UserNotificationEventPersistence.class)
994            protected UserNotificationEventPersistence userNotificationEventPersistence;
995            @BeanReference(type = UserTrackerPersistence.class)
996            protected UserTrackerPersistence userTrackerPersistence;
997            @BeanReference(type = UserTrackerPathPersistence.class)
998            protected UserTrackerPathPersistence userTrackerPathPersistence;
999            @BeanReference(type = VirtualHostPersistence.class)
1000            protected VirtualHostPersistence virtualHostPersistence;
1001            @BeanReference(type = WebDAVPropsPersistence.class)
1002            protected WebDAVPropsPersistence webDAVPropsPersistence;
1003            @BeanReference(type = WebsitePersistence.class)
1004            protected WebsitePersistence websitePersistence;
1005            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1006            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1007            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1008            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1009            private static final String _SQL_SELECT_PORTALPREFERENCES = "SELECT portalPreferences FROM PortalPreferences portalPreferences";
1010            private static final String _SQL_SELECT_PORTALPREFERENCES_WHERE = "SELECT portalPreferences FROM PortalPreferences portalPreferences WHERE ";
1011            private static final String _SQL_COUNT_PORTALPREFERENCES = "SELECT COUNT(portalPreferences) FROM PortalPreferences portalPreferences";
1012            private static final String _SQL_COUNT_PORTALPREFERENCES_WHERE = "SELECT COUNT(portalPreferences) FROM PortalPreferences portalPreferences WHERE ";
1013            private static final String _FINDER_COLUMN_O_O_OWNERID_2 = "portalPreferences.ownerId = ? AND ";
1014            private static final String _FINDER_COLUMN_O_O_OWNERTYPE_2 = "portalPreferences.ownerType = ?";
1015            private static final String _ORDER_BY_ENTITY_ALIAS = "portalPreferences.";
1016            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PortalPreferences exists with the primary key ";
1017            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PortalPreferences exists with the key {";
1018            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1019            private static Log _log = LogFactoryUtil.getLog(PortalPreferencesPersistenceImpl.class);
1020            private static PortalPreferences _nullPortalPreferences = new PortalPreferencesImpl() {
1021                            @Override
1022                            public Object clone() {
1023                                    return this;
1024                            }
1025    
1026                            @Override
1027                            public CacheModel<PortalPreferences> toCacheModel() {
1028                                    return _nullPortalPreferencesCacheModel;
1029                            }
1030                    };
1031    
1032            private static CacheModel<PortalPreferences> _nullPortalPreferencesCacheModel =
1033                    new CacheModel<PortalPreferences>() {
1034                            public PortalPreferences toEntityModel() {
1035                                    return _nullPortalPreferences;
1036                            }
1037                    };
1038    }