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