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