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