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.model.CacheModel;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.model.PluginSetting;
040    import com.liferay.portal.model.impl.PluginSettingImpl;
041    import com.liferay.portal.model.impl.PluginSettingModelImpl;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import java.io.Serializable;
045    
046    import java.util.ArrayList;
047    import java.util.Collections;
048    import java.util.List;
049    
050    /**
051     * The persistence implementation for the plugin setting service.
052     *
053     * <p>
054     * Caching information and settings can be found in <code>portal.properties</code>
055     * </p>
056     *
057     * @author Brian Wing Shun Chan
058     * @see PluginSettingPersistence
059     * @see PluginSettingUtil
060     * @generated
061     */
062    public class PluginSettingPersistenceImpl extends BasePersistenceImpl<PluginSetting>
063            implements PluginSettingPersistence {
064            /*
065             * NOTE FOR DEVELOPERS:
066             *
067             * 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.
068             */
069            public static final String FINDER_CLASS_NAME_ENTITY = PluginSettingImpl.class.getName();
070            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071                    ".List1";
072            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List2";
074            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
075                    new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
076                            PluginSettingModelImpl.FINDER_CACHE_ENABLED,
077                            PluginSettingImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
078                            "findByCompanyId",
079                            new String[] {
080                                    Long.class.getName(),
081                                    
082                            "java.lang.Integer", "java.lang.Integer",
083                                    "com.liferay.portal.kernel.util.OrderByComparator"
084                            });
085            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
086                    new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
087                            PluginSettingModelImpl.FINDER_CACHE_ENABLED,
088                            PluginSettingImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
089                            "findByCompanyId", new String[] { Long.class.getName() },
090                            PluginSettingModelImpl.COMPANYID_COLUMN_BITMASK);
091            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
092                            PluginSettingModelImpl.FINDER_CACHE_ENABLED, Long.class,
093                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
094                            new String[] { Long.class.getName() });
095            public static final FinderPath FINDER_PATH_FETCH_BY_C_I_T = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
096                            PluginSettingModelImpl.FINDER_CACHE_ENABLED,
097                            PluginSettingImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByC_I_T",
098                            new String[] {
099                                    Long.class.getName(), String.class.getName(),
100                                    String.class.getName()
101                            },
102                            PluginSettingModelImpl.COMPANYID_COLUMN_BITMASK |
103                            PluginSettingModelImpl.PLUGINID_COLUMN_BITMASK |
104                            PluginSettingModelImpl.PLUGINTYPE_COLUMN_BITMASK);
105            public static final FinderPath FINDER_PATH_COUNT_BY_C_I_T = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
106                            PluginSettingModelImpl.FINDER_CACHE_ENABLED, Long.class,
107                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_I_T",
108                            new String[] {
109                                    Long.class.getName(), String.class.getName(),
110                                    String.class.getName()
111                            });
112            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
113                            PluginSettingModelImpl.FINDER_CACHE_ENABLED,
114                            PluginSettingImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
115                            "findAll", new String[0]);
116            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
117                            PluginSettingModelImpl.FINDER_CACHE_ENABLED,
118                            PluginSettingImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
119                            "findAll", new String[0]);
120            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
121                            PluginSettingModelImpl.FINDER_CACHE_ENABLED, Long.class,
122                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
123    
124            /**
125             * Caches the plugin setting in the entity cache if it is enabled.
126             *
127             * @param pluginSetting the plugin setting
128             */
129            public void cacheResult(PluginSetting pluginSetting) {
130                    EntityCacheUtil.putResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
131                            PluginSettingImpl.class, pluginSetting.getPrimaryKey(),
132                            pluginSetting);
133    
134                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_I_T,
135                            new Object[] {
136                                    Long.valueOf(pluginSetting.getCompanyId()),
137                                    
138                            pluginSetting.getPluginId(),
139                                    
140                            pluginSetting.getPluginType()
141                            }, pluginSetting);
142    
143                    pluginSetting.resetOriginalValues();
144            }
145    
146            /**
147             * Caches the plugin settings in the entity cache if it is enabled.
148             *
149             * @param pluginSettings the plugin settings
150             */
151            public void cacheResult(List<PluginSetting> pluginSettings) {
152                    for (PluginSetting pluginSetting : pluginSettings) {
153                            if (EntityCacheUtil.getResult(
154                                                    PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
155                                                    PluginSettingImpl.class, pluginSetting.getPrimaryKey()) == null) {
156                                    cacheResult(pluginSetting);
157                            }
158                            else {
159                                    pluginSetting.resetOriginalValues();
160                            }
161                    }
162            }
163    
164            /**
165             * Clears the cache for all plugin settings.
166             *
167             * <p>
168             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
169             * </p>
170             */
171            @Override
172            public void clearCache() {
173                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
174                            CacheRegistryUtil.clear(PluginSettingImpl.class.getName());
175                    }
176    
177                    EntityCacheUtil.clearCache(PluginSettingImpl.class.getName());
178    
179                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
180                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
181                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
182            }
183    
184            /**
185             * Clears the cache for the plugin setting.
186             *
187             * <p>
188             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
189             * </p>
190             */
191            @Override
192            public void clearCache(PluginSetting pluginSetting) {
193                    EntityCacheUtil.removeResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
194                            PluginSettingImpl.class, pluginSetting.getPrimaryKey());
195    
196                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
197                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
198    
199                    clearUniqueFindersCache(pluginSetting);
200            }
201    
202            @Override
203            public void clearCache(List<PluginSetting> pluginSettings) {
204                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
205                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
206    
207                    for (PluginSetting pluginSetting : pluginSettings) {
208                            EntityCacheUtil.removeResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
209                                    PluginSettingImpl.class, pluginSetting.getPrimaryKey());
210    
211                            clearUniqueFindersCache(pluginSetting);
212                    }
213            }
214    
215            protected void clearUniqueFindersCache(PluginSetting pluginSetting) {
216                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_I_T,
217                            new Object[] {
218                                    Long.valueOf(pluginSetting.getCompanyId()),
219                                    
220                            pluginSetting.getPluginId(),
221                                    
222                            pluginSetting.getPluginType()
223                            });
224            }
225    
226            /**
227             * Creates a new plugin setting with the primary key. Does not add the plugin setting to the database.
228             *
229             * @param pluginSettingId the primary key for the new plugin setting
230             * @return the new plugin setting
231             */
232            public PluginSetting create(long pluginSettingId) {
233                    PluginSetting pluginSetting = new PluginSettingImpl();
234    
235                    pluginSetting.setNew(true);
236                    pluginSetting.setPrimaryKey(pluginSettingId);
237    
238                    return pluginSetting;
239            }
240    
241            /**
242             * Removes the plugin setting with the primary key from the database. Also notifies the appropriate model listeners.
243             *
244             * @param pluginSettingId the primary key of the plugin setting
245             * @return the plugin setting that was removed
246             * @throws com.liferay.portal.NoSuchPluginSettingException if a plugin setting with the primary key could not be found
247             * @throws SystemException if a system exception occurred
248             */
249            public PluginSetting remove(long pluginSettingId)
250                    throws NoSuchPluginSettingException, SystemException {
251                    return remove(Long.valueOf(pluginSettingId));
252            }
253    
254            /**
255             * Removes the plugin setting with the primary key from the database. Also notifies the appropriate model listeners.
256             *
257             * @param primaryKey the primary key of the plugin setting
258             * @return the plugin setting that was removed
259             * @throws com.liferay.portal.NoSuchPluginSettingException if a plugin setting with the primary key could not be found
260             * @throws SystemException if a system exception occurred
261             */
262            @Override
263            public PluginSetting remove(Serializable primaryKey)
264                    throws NoSuchPluginSettingException, SystemException {
265                    Session session = null;
266    
267                    try {
268                            session = openSession();
269    
270                            PluginSetting pluginSetting = (PluginSetting)session.get(PluginSettingImpl.class,
271                                            primaryKey);
272    
273                            if (pluginSetting == null) {
274                                    if (_log.isWarnEnabled()) {
275                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
276                                    }
277    
278                                    throw new NoSuchPluginSettingException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
279                                            primaryKey);
280                            }
281    
282                            return remove(pluginSetting);
283                    }
284                    catch (NoSuchPluginSettingException nsee) {
285                            throw nsee;
286                    }
287                    catch (Exception e) {
288                            throw processException(e);
289                    }
290                    finally {
291                            closeSession(session);
292                    }
293            }
294    
295            @Override
296            protected PluginSetting removeImpl(PluginSetting pluginSetting)
297                    throws SystemException {
298                    pluginSetting = toUnwrappedModel(pluginSetting);
299    
300                    Session session = null;
301    
302                    try {
303                            session = openSession();
304    
305                            BatchSessionUtil.delete(session, pluginSetting);
306                    }
307                    catch (Exception e) {
308                            throw processException(e);
309                    }
310                    finally {
311                            closeSession(session);
312                    }
313    
314                    clearCache(pluginSetting);
315    
316                    return pluginSetting;
317            }
318    
319            @Override
320            public PluginSetting updateImpl(
321                    com.liferay.portal.model.PluginSetting pluginSetting, boolean merge)
322                    throws SystemException {
323                    pluginSetting = toUnwrappedModel(pluginSetting);
324    
325                    boolean isNew = pluginSetting.isNew();
326    
327                    PluginSettingModelImpl pluginSettingModelImpl = (PluginSettingModelImpl)pluginSetting;
328    
329                    Session session = null;
330    
331                    try {
332                            session = openSession();
333    
334                            BatchSessionUtil.update(session, pluginSetting, merge);
335    
336                            pluginSetting.setNew(false);
337                    }
338                    catch (Exception e) {
339                            throw processException(e);
340                    }
341                    finally {
342                            closeSession(session);
343                    }
344    
345                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
346    
347                    if (isNew || !PluginSettingModelImpl.COLUMN_BITMASK_ENABLED) {
348                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
349                    }
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) {
600                            StringBundler query = null;
601    
602                            if (orderByComparator != null) {
603                                    query = new StringBundler(3 +
604                                                    (orderByComparator.getOrderByFields().length * 3));
605                            }
606                            else {
607                                    query = new StringBundler(2);
608                            }
609    
610                            query.append(_SQL_SELECT_PLUGINSETTING_WHERE);
611    
612                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
613    
614                            if (orderByComparator != null) {
615                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
616                                            orderByComparator);
617                            }
618    
619                            String sql = query.toString();
620    
621                            Session session = null;
622    
623                            try {
624                                    session = openSession();
625    
626                                    Query q = session.createQuery(sql);
627    
628                                    QueryPos qPos = QueryPos.getInstance(q);
629    
630                                    qPos.add(companyId);
631    
632                                    list = (List<PluginSetting>)QueryUtil.list(q, getDialect(),
633                                                    start, end);
634                            }
635                            catch (Exception e) {
636                                    throw processException(e);
637                            }
638                            finally {
639                                    if (list == null) {
640                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
641                                    }
642                                    else {
643                                            cacheResult(list);
644    
645                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
646                                    }
647    
648                                    closeSession(session);
649                            }
650                    }
651    
652                    return list;
653            }
654    
655            /**
656             * Returns the first plugin setting in the ordered set where companyId = &#63;.
657             *
658             * <p>
659             * 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.
660             * </p>
661             *
662             * @param companyId the company ID
663             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
664             * @return the first matching plugin setting
665             * @throws com.liferay.portal.NoSuchPluginSettingException if a matching plugin setting could not be found
666             * @throws SystemException if a system exception occurred
667             */
668            public PluginSetting findByCompanyId_First(long companyId,
669                    OrderByComparator orderByComparator)
670                    throws NoSuchPluginSettingException, SystemException {
671                    List<PluginSetting> list = findByCompanyId(companyId, 0, 1,
672                                    orderByComparator);
673    
674                    if (list.isEmpty()) {
675                            StringBundler msg = new StringBundler(4);
676    
677                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
678    
679                            msg.append("companyId=");
680                            msg.append(companyId);
681    
682                            msg.append(StringPool.CLOSE_CURLY_BRACE);
683    
684                            throw new NoSuchPluginSettingException(msg.toString());
685                    }
686                    else {
687                            return list.get(0);
688                    }
689            }
690    
691            /**
692             * Returns the last plugin setting in the ordered set where companyId = &#63;.
693             *
694             * <p>
695             * 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.
696             * </p>
697             *
698             * @param companyId the company ID
699             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
700             * @return the last matching plugin setting
701             * @throws com.liferay.portal.NoSuchPluginSettingException if a matching plugin setting could not be found
702             * @throws SystemException if a system exception occurred
703             */
704            public PluginSetting findByCompanyId_Last(long companyId,
705                    OrderByComparator orderByComparator)
706                    throws NoSuchPluginSettingException, SystemException {
707                    int count = countByCompanyId(companyId);
708    
709                    List<PluginSetting> list = findByCompanyId(companyId, count - 1, count,
710                                    orderByComparator);
711    
712                    if (list.isEmpty()) {
713                            StringBundler msg = new StringBundler(4);
714    
715                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
716    
717                            msg.append("companyId=");
718                            msg.append(companyId);
719    
720                            msg.append(StringPool.CLOSE_CURLY_BRACE);
721    
722                            throw new NoSuchPluginSettingException(msg.toString());
723                    }
724                    else {
725                            return list.get(0);
726                    }
727            }
728    
729            /**
730             * Returns the plugin settings before and after the current plugin setting in the ordered set where companyId = &#63;.
731             *
732             * <p>
733             * 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.
734             * </p>
735             *
736             * @param pluginSettingId the primary key of the current plugin setting
737             * @param companyId the company ID
738             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
739             * @return the previous, current, and next plugin setting
740             * @throws com.liferay.portal.NoSuchPluginSettingException if a plugin setting with the primary key could not be found
741             * @throws SystemException if a system exception occurred
742             */
743            public PluginSetting[] findByCompanyId_PrevAndNext(long pluginSettingId,
744                    long companyId, OrderByComparator orderByComparator)
745                    throws NoSuchPluginSettingException, SystemException {
746                    PluginSetting pluginSetting = findByPrimaryKey(pluginSettingId);
747    
748                    Session session = null;
749    
750                    try {
751                            session = openSession();
752    
753                            PluginSetting[] array = new PluginSettingImpl[3];
754    
755                            array[0] = getByCompanyId_PrevAndNext(session, pluginSetting,
756                                            companyId, orderByComparator, true);
757    
758                            array[1] = pluginSetting;
759    
760                            array[2] = getByCompanyId_PrevAndNext(session, pluginSetting,
761                                            companyId, orderByComparator, false);
762    
763                            return array;
764                    }
765                    catch (Exception e) {
766                            throw processException(e);
767                    }
768                    finally {
769                            closeSession(session);
770                    }
771            }
772    
773            protected PluginSetting getByCompanyId_PrevAndNext(Session session,
774                    PluginSetting pluginSetting, long companyId,
775                    OrderByComparator orderByComparator, boolean previous) {
776                    StringBundler query = null;
777    
778                    if (orderByComparator != null) {
779                            query = new StringBundler(6 +
780                                            (orderByComparator.getOrderByFields().length * 6));
781                    }
782                    else {
783                            query = new StringBundler(3);
784                    }
785    
786                    query.append(_SQL_SELECT_PLUGINSETTING_WHERE);
787    
788                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
789    
790                    if (orderByComparator != null) {
791                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
792    
793                            if (orderByConditionFields.length > 0) {
794                                    query.append(WHERE_AND);
795                            }
796    
797                            for (int i = 0; i < orderByConditionFields.length; i++) {
798                                    query.append(_ORDER_BY_ENTITY_ALIAS);
799                                    query.append(orderByConditionFields[i]);
800    
801                                    if ((i + 1) < orderByConditionFields.length) {
802                                            if (orderByComparator.isAscending() ^ previous) {
803                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
804                                            }
805                                            else {
806                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
807                                            }
808                                    }
809                                    else {
810                                            if (orderByComparator.isAscending() ^ previous) {
811                                                    query.append(WHERE_GREATER_THAN);
812                                            }
813                                            else {
814                                                    query.append(WHERE_LESSER_THAN);
815                                            }
816                                    }
817                            }
818    
819                            query.append(ORDER_BY_CLAUSE);
820    
821                            String[] orderByFields = orderByComparator.getOrderByFields();
822    
823                            for (int i = 0; i < orderByFields.length; i++) {
824                                    query.append(_ORDER_BY_ENTITY_ALIAS);
825                                    query.append(orderByFields[i]);
826    
827                                    if ((i + 1) < orderByFields.length) {
828                                            if (orderByComparator.isAscending() ^ previous) {
829                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
830                                            }
831                                            else {
832                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
833                                            }
834                                    }
835                                    else {
836                                            if (orderByComparator.isAscending() ^ previous) {
837                                                    query.append(ORDER_BY_ASC);
838                                            }
839                                            else {
840                                                    query.append(ORDER_BY_DESC);
841                                            }
842                                    }
843                            }
844                    }
845    
846                    String sql = query.toString();
847    
848                    Query q = session.createQuery(sql);
849    
850                    q.setFirstResult(0);
851                    q.setMaxResults(2);
852    
853                    QueryPos qPos = QueryPos.getInstance(q);
854    
855                    qPos.add(companyId);
856    
857                    if (orderByComparator != null) {
858                            Object[] values = orderByComparator.getOrderByConditionValues(pluginSetting);
859    
860                            for (Object value : values) {
861                                    qPos.add(value);
862                            }
863                    }
864    
865                    List<PluginSetting> list = q.list();
866    
867                    if (list.size() == 2) {
868                            return list.get(1);
869                    }
870                    else {
871                            return null;
872                    }
873            }
874    
875            /**
876             * 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.
877             *
878             * @param companyId the company ID
879             * @param pluginId the plugin ID
880             * @param pluginType the plugin type
881             * @return the matching plugin setting
882             * @throws com.liferay.portal.NoSuchPluginSettingException if a matching plugin setting could not be found
883             * @throws SystemException if a system exception occurred
884             */
885            public PluginSetting findByC_I_T(long companyId, String pluginId,
886                    String pluginType) throws NoSuchPluginSettingException, SystemException {
887                    PluginSetting pluginSetting = fetchByC_I_T(companyId, pluginId,
888                                    pluginType);
889    
890                    if (pluginSetting == null) {
891                            StringBundler msg = new StringBundler(8);
892    
893                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
894    
895                            msg.append("companyId=");
896                            msg.append(companyId);
897    
898                            msg.append(", pluginId=");
899                            msg.append(pluginId);
900    
901                            msg.append(", pluginType=");
902                            msg.append(pluginType);
903    
904                            msg.append(StringPool.CLOSE_CURLY_BRACE);
905    
906                            if (_log.isWarnEnabled()) {
907                                    _log.warn(msg.toString());
908                            }
909    
910                            throw new NoSuchPluginSettingException(msg.toString());
911                    }
912    
913                    return pluginSetting;
914            }
915    
916            /**
917             * 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.
918             *
919             * @param companyId the company ID
920             * @param pluginId the plugin ID
921             * @param pluginType the plugin type
922             * @return the matching plugin setting, or <code>null</code> if a matching plugin setting could not be found
923             * @throws SystemException if a system exception occurred
924             */
925            public PluginSetting fetchByC_I_T(long companyId, String pluginId,
926                    String pluginType) throws SystemException {
927                    return fetchByC_I_T(companyId, pluginId, pluginType, true);
928            }
929    
930            /**
931             * 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.
932             *
933             * @param companyId the company ID
934             * @param pluginId the plugin ID
935             * @param pluginType the plugin type
936             * @param retrieveFromCache whether to use the finder cache
937             * @return the matching plugin setting, or <code>null</code> if a matching plugin setting could not be found
938             * @throws SystemException if a system exception occurred
939             */
940            public PluginSetting fetchByC_I_T(long companyId, String pluginId,
941                    String pluginType, boolean retrieveFromCache) throws SystemException {
942                    Object[] finderArgs = new Object[] { companyId, pluginId, pluginType };
943    
944                    Object result = null;
945    
946                    if (retrieveFromCache) {
947                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_I_T,
948                                            finderArgs, this);
949                    }
950    
951                    if (result == null) {
952                            StringBundler query = new StringBundler(4);
953    
954                            query.append(_SQL_SELECT_PLUGINSETTING_WHERE);
955    
956                            query.append(_FINDER_COLUMN_C_I_T_COMPANYID_2);
957    
958                            if (pluginId == null) {
959                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINID_1);
960                            }
961                            else {
962                                    if (pluginId.equals(StringPool.BLANK)) {
963                                            query.append(_FINDER_COLUMN_C_I_T_PLUGINID_3);
964                                    }
965                                    else {
966                                            query.append(_FINDER_COLUMN_C_I_T_PLUGINID_2);
967                                    }
968                            }
969    
970                            if (pluginType == null) {
971                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_1);
972                            }
973                            else {
974                                    if (pluginType.equals(StringPool.BLANK)) {
975                                            query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_3);
976                                    }
977                                    else {
978                                            query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_2);
979                                    }
980                            }
981    
982                            String sql = query.toString();
983    
984                            Session session = null;
985    
986                            try {
987                                    session = openSession();
988    
989                                    Query q = session.createQuery(sql);
990    
991                                    QueryPos qPos = QueryPos.getInstance(q);
992    
993                                    qPos.add(companyId);
994    
995                                    if (pluginId != null) {
996                                            qPos.add(pluginId);
997                                    }
998    
999                                    if (pluginType != null) {
1000                                            qPos.add(pluginType);
1001                                    }
1002    
1003                                    List<PluginSetting> list = q.list();
1004    
1005                                    result = list;
1006    
1007                                    PluginSetting pluginSetting = null;
1008    
1009                                    if (list.isEmpty()) {
1010                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_I_T,
1011                                                    finderArgs, list);
1012                                    }
1013                                    else {
1014                                            pluginSetting = list.get(0);
1015    
1016                                            cacheResult(pluginSetting);
1017    
1018                                            if ((pluginSetting.getCompanyId() != companyId) ||
1019                                                            (pluginSetting.getPluginId() == null) ||
1020                                                            !pluginSetting.getPluginId().equals(pluginId) ||
1021                                                            (pluginSetting.getPluginType() == null) ||
1022                                                            !pluginSetting.getPluginType().equals(pluginType)) {
1023                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_I_T,
1024                                                            finderArgs, pluginSetting);
1025                                            }
1026                                    }
1027    
1028                                    return pluginSetting;
1029                            }
1030                            catch (Exception e) {
1031                                    throw processException(e);
1032                            }
1033                            finally {
1034                                    if (result == null) {
1035                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_I_T,
1036                                                    finderArgs);
1037                                    }
1038    
1039                                    closeSession(session);
1040                            }
1041                    }
1042                    else {
1043                            if (result instanceof List<?>) {
1044                                    return null;
1045                            }
1046                            else {
1047                                    return (PluginSetting)result;
1048                            }
1049                    }
1050            }
1051    
1052            /**
1053             * Returns all the plugin settings.
1054             *
1055             * @return the plugin settings
1056             * @throws SystemException if a system exception occurred
1057             */
1058            public List<PluginSetting> findAll() throws SystemException {
1059                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1060            }
1061    
1062            /**
1063             * Returns a range of all the plugin settings.
1064             *
1065             * <p>
1066             * 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.
1067             * </p>
1068             *
1069             * @param start the lower bound of the range of plugin settings
1070             * @param end the upper bound of the range of plugin settings (not inclusive)
1071             * @return the range of plugin settings
1072             * @throws SystemException if a system exception occurred
1073             */
1074            public List<PluginSetting> findAll(int start, int end)
1075                    throws SystemException {
1076                    return findAll(start, end, null);
1077            }
1078    
1079            /**
1080             * Returns an ordered range of all the plugin settings.
1081             *
1082             * <p>
1083             * 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.
1084             * </p>
1085             *
1086             * @param start the lower bound of the range of plugin settings
1087             * @param end the upper bound of the range of plugin settings (not inclusive)
1088             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1089             * @return the ordered range of plugin settings
1090             * @throws SystemException if a system exception occurred
1091             */
1092            public List<PluginSetting> findAll(int start, int end,
1093                    OrderByComparator orderByComparator) throws SystemException {
1094                    FinderPath finderPath = null;
1095                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1096    
1097                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1098                                    (orderByComparator == null)) {
1099                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1100                            finderArgs = FINDER_ARGS_EMPTY;
1101                    }
1102                    else {
1103                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1104                            finderArgs = new Object[] { start, end, orderByComparator };
1105                    }
1106    
1107                    List<PluginSetting> list = (List<PluginSetting>)FinderCacheUtil.getResult(finderPath,
1108                                    finderArgs, this);
1109    
1110                    if (list == null) {
1111                            StringBundler query = null;
1112                            String sql = null;
1113    
1114                            if (orderByComparator != null) {
1115                                    query = new StringBundler(2 +
1116                                                    (orderByComparator.getOrderByFields().length * 3));
1117    
1118                                    query.append(_SQL_SELECT_PLUGINSETTING);
1119    
1120                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1121                                            orderByComparator);
1122    
1123                                    sql = query.toString();
1124                            }
1125                            else {
1126                                    sql = _SQL_SELECT_PLUGINSETTING;
1127                            }
1128    
1129                            Session session = null;
1130    
1131                            try {
1132                                    session = openSession();
1133    
1134                                    Query q = session.createQuery(sql);
1135    
1136                                    if (orderByComparator == null) {
1137                                            list = (List<PluginSetting>)QueryUtil.list(q, getDialect(),
1138                                                            start, end, false);
1139    
1140                                            Collections.sort(list);
1141                                    }
1142                                    else {
1143                                            list = (List<PluginSetting>)QueryUtil.list(q, getDialect(),
1144                                                            start, end);
1145                                    }
1146                            }
1147                            catch (Exception e) {
1148                                    throw processException(e);
1149                            }
1150                            finally {
1151                                    if (list == null) {
1152                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1153                                    }
1154                                    else {
1155                                            cacheResult(list);
1156    
1157                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1158                                    }
1159    
1160                                    closeSession(session);
1161                            }
1162                    }
1163    
1164                    return list;
1165            }
1166    
1167            /**
1168             * Removes all the plugin settings where companyId = &#63; from the database.
1169             *
1170             * @param companyId the company ID
1171             * @throws SystemException if a system exception occurred
1172             */
1173            public void removeByCompanyId(long companyId) throws SystemException {
1174                    for (PluginSetting pluginSetting : findByCompanyId(companyId)) {
1175                            remove(pluginSetting);
1176                    }
1177            }
1178    
1179            /**
1180             * Removes the plugin setting where companyId = &#63; and pluginId = &#63; and pluginType = &#63; from the database.
1181             *
1182             * @param companyId the company ID
1183             * @param pluginId the plugin ID
1184             * @param pluginType the plugin type
1185             * @throws SystemException if a system exception occurred
1186             */
1187            public void removeByC_I_T(long companyId, String pluginId, String pluginType)
1188                    throws NoSuchPluginSettingException, SystemException {
1189                    PluginSetting pluginSetting = findByC_I_T(companyId, pluginId,
1190                                    pluginType);
1191    
1192                    remove(pluginSetting);
1193            }
1194    
1195            /**
1196             * Removes all the plugin settings from the database.
1197             *
1198             * @throws SystemException if a system exception occurred
1199             */
1200            public void removeAll() throws SystemException {
1201                    for (PluginSetting pluginSetting : findAll()) {
1202                            remove(pluginSetting);
1203                    }
1204            }
1205    
1206            /**
1207             * Returns the number of plugin settings where companyId = &#63;.
1208             *
1209             * @param companyId the company ID
1210             * @return the number of matching plugin settings
1211             * @throws SystemException if a system exception occurred
1212             */
1213            public int countByCompanyId(long companyId) throws SystemException {
1214                    Object[] finderArgs = new Object[] { companyId };
1215    
1216                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1217                                    finderArgs, this);
1218    
1219                    if (count == null) {
1220                            StringBundler query = new StringBundler(2);
1221    
1222                            query.append(_SQL_COUNT_PLUGINSETTING_WHERE);
1223    
1224                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1225    
1226                            String sql = query.toString();
1227    
1228                            Session session = null;
1229    
1230                            try {
1231                                    session = openSession();
1232    
1233                                    Query q = session.createQuery(sql);
1234    
1235                                    QueryPos qPos = QueryPos.getInstance(q);
1236    
1237                                    qPos.add(companyId);
1238    
1239                                    count = (Long)q.uniqueResult();
1240                            }
1241                            catch (Exception e) {
1242                                    throw processException(e);
1243                            }
1244                            finally {
1245                                    if (count == null) {
1246                                            count = Long.valueOf(0);
1247                                    }
1248    
1249                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1250                                            finderArgs, count);
1251    
1252                                    closeSession(session);
1253                            }
1254                    }
1255    
1256                    return count.intValue();
1257            }
1258    
1259            /**
1260             * Returns the number of plugin settings where companyId = &#63; and pluginId = &#63; and pluginType = &#63;.
1261             *
1262             * @param companyId the company ID
1263             * @param pluginId the plugin ID
1264             * @param pluginType the plugin type
1265             * @return the number of matching plugin settings
1266             * @throws SystemException if a system exception occurred
1267             */
1268            public int countByC_I_T(long companyId, String pluginId, String pluginType)
1269                    throws SystemException {
1270                    Object[] finderArgs = new Object[] { companyId, pluginId, pluginType };
1271    
1272                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_I_T,
1273                                    finderArgs, this);
1274    
1275                    if (count == null) {
1276                            StringBundler query = new StringBundler(4);
1277    
1278                            query.append(_SQL_COUNT_PLUGINSETTING_WHERE);
1279    
1280                            query.append(_FINDER_COLUMN_C_I_T_COMPANYID_2);
1281    
1282                            if (pluginId == null) {
1283                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINID_1);
1284                            }
1285                            else {
1286                                    if (pluginId.equals(StringPool.BLANK)) {
1287                                            query.append(_FINDER_COLUMN_C_I_T_PLUGINID_3);
1288                                    }
1289                                    else {
1290                                            query.append(_FINDER_COLUMN_C_I_T_PLUGINID_2);
1291                                    }
1292                            }
1293    
1294                            if (pluginType == null) {
1295                                    query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_1);
1296                            }
1297                            else {
1298                                    if (pluginType.equals(StringPool.BLANK)) {
1299                                            query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_3);
1300                                    }
1301                                    else {
1302                                            query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_2);
1303                                    }
1304                            }
1305    
1306                            String sql = query.toString();
1307    
1308                            Session session = null;
1309    
1310                            try {
1311                                    session = openSession();
1312    
1313                                    Query q = session.createQuery(sql);
1314    
1315                                    QueryPos qPos = QueryPos.getInstance(q);
1316    
1317                                    qPos.add(companyId);
1318    
1319                                    if (pluginId != null) {
1320                                            qPos.add(pluginId);
1321                                    }
1322    
1323                                    if (pluginType != null) {
1324                                            qPos.add(pluginType);
1325                                    }
1326    
1327                                    count = (Long)q.uniqueResult();
1328                            }
1329                            catch (Exception e) {
1330                                    throw processException(e);
1331                            }
1332                            finally {
1333                                    if (count == null) {
1334                                            count = Long.valueOf(0);
1335                                    }
1336    
1337                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_I_T,
1338                                            finderArgs, count);
1339    
1340                                    closeSession(session);
1341                            }
1342                    }
1343    
1344                    return count.intValue();
1345            }
1346    
1347            /**
1348             * Returns the number of plugin settings.
1349             *
1350             * @return the number of plugin settings
1351             * @throws SystemException if a system exception occurred
1352             */
1353            public int countAll() throws SystemException {
1354                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1355                                    FINDER_ARGS_EMPTY, this);
1356    
1357                    if (count == null) {
1358                            Session session = null;
1359    
1360                            try {
1361                                    session = openSession();
1362    
1363                                    Query q = session.createQuery(_SQL_COUNT_PLUGINSETTING);
1364    
1365                                    count = (Long)q.uniqueResult();
1366                            }
1367                            catch (Exception e) {
1368                                    throw processException(e);
1369                            }
1370                            finally {
1371                                    if (count == null) {
1372                                            count = Long.valueOf(0);
1373                                    }
1374    
1375                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1376                                            FINDER_ARGS_EMPTY, count);
1377    
1378                                    closeSession(session);
1379                            }
1380                    }
1381    
1382                    return count.intValue();
1383            }
1384    
1385            /**
1386             * Initializes the plugin setting persistence.
1387             */
1388            public void afterPropertiesSet() {
1389                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1390                                            com.liferay.portal.util.PropsUtil.get(
1391                                                    "value.object.listener.com.liferay.portal.model.PluginSetting")));
1392    
1393                    if (listenerClassNames.length > 0) {
1394                            try {
1395                                    List<ModelListener<PluginSetting>> listenersList = new ArrayList<ModelListener<PluginSetting>>();
1396    
1397                                    for (String listenerClassName : listenerClassNames) {
1398                                            listenersList.add((ModelListener<PluginSetting>)InstanceFactory.newInstance(
1399                                                            listenerClassName));
1400                                    }
1401    
1402                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1403                            }
1404                            catch (Exception e) {
1405                                    _log.error(e);
1406                            }
1407                    }
1408            }
1409    
1410            public void destroy() {
1411                    EntityCacheUtil.removeCache(PluginSettingImpl.class.getName());
1412                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1413                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1414            }
1415    
1416            @BeanReference(type = AccountPersistence.class)
1417            protected AccountPersistence accountPersistence;
1418            @BeanReference(type = AddressPersistence.class)
1419            protected AddressPersistence addressPersistence;
1420            @BeanReference(type = BrowserTrackerPersistence.class)
1421            protected BrowserTrackerPersistence browserTrackerPersistence;
1422            @BeanReference(type = ClassNamePersistence.class)
1423            protected ClassNamePersistence classNamePersistence;
1424            @BeanReference(type = ClusterGroupPersistence.class)
1425            protected ClusterGroupPersistence clusterGroupPersistence;
1426            @BeanReference(type = CompanyPersistence.class)
1427            protected CompanyPersistence companyPersistence;
1428            @BeanReference(type = ContactPersistence.class)
1429            protected ContactPersistence contactPersistence;
1430            @BeanReference(type = CountryPersistence.class)
1431            protected CountryPersistence countryPersistence;
1432            @BeanReference(type = EmailAddressPersistence.class)
1433            protected EmailAddressPersistence emailAddressPersistence;
1434            @BeanReference(type = GroupPersistence.class)
1435            protected GroupPersistence groupPersistence;
1436            @BeanReference(type = ImagePersistence.class)
1437            protected ImagePersistence imagePersistence;
1438            @BeanReference(type = LayoutPersistence.class)
1439            protected LayoutPersistence layoutPersistence;
1440            @BeanReference(type = LayoutBranchPersistence.class)
1441            protected LayoutBranchPersistence layoutBranchPersistence;
1442            @BeanReference(type = LayoutPrototypePersistence.class)
1443            protected LayoutPrototypePersistence layoutPrototypePersistence;
1444            @BeanReference(type = LayoutRevisionPersistence.class)
1445            protected LayoutRevisionPersistence layoutRevisionPersistence;
1446            @BeanReference(type = LayoutSetPersistence.class)
1447            protected LayoutSetPersistence layoutSetPersistence;
1448            @BeanReference(type = LayoutSetBranchPersistence.class)
1449            protected LayoutSetBranchPersistence layoutSetBranchPersistence;
1450            @BeanReference(type = LayoutSetPrototypePersistence.class)
1451            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1452            @BeanReference(type = ListTypePersistence.class)
1453            protected ListTypePersistence listTypePersistence;
1454            @BeanReference(type = LockPersistence.class)
1455            protected LockPersistence lockPersistence;
1456            @BeanReference(type = MembershipRequestPersistence.class)
1457            protected MembershipRequestPersistence membershipRequestPersistence;
1458            @BeanReference(type = OrganizationPersistence.class)
1459            protected OrganizationPersistence organizationPersistence;
1460            @BeanReference(type = OrgGroupPermissionPersistence.class)
1461            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1462            @BeanReference(type = OrgGroupRolePersistence.class)
1463            protected OrgGroupRolePersistence orgGroupRolePersistence;
1464            @BeanReference(type = OrgLaborPersistence.class)
1465            protected OrgLaborPersistence orgLaborPersistence;
1466            @BeanReference(type = PasswordPolicyPersistence.class)
1467            protected PasswordPolicyPersistence passwordPolicyPersistence;
1468            @BeanReference(type = PasswordPolicyRelPersistence.class)
1469            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1470            @BeanReference(type = PasswordTrackerPersistence.class)
1471            protected PasswordTrackerPersistence passwordTrackerPersistence;
1472            @BeanReference(type = PermissionPersistence.class)
1473            protected PermissionPersistence permissionPersistence;
1474            @BeanReference(type = PhonePersistence.class)
1475            protected PhonePersistence phonePersistence;
1476            @BeanReference(type = PluginSettingPersistence.class)
1477            protected PluginSettingPersistence pluginSettingPersistence;
1478            @BeanReference(type = PortalPreferencesPersistence.class)
1479            protected PortalPreferencesPersistence portalPreferencesPersistence;
1480            @BeanReference(type = PortletPersistence.class)
1481            protected PortletPersistence portletPersistence;
1482            @BeanReference(type = PortletItemPersistence.class)
1483            protected PortletItemPersistence portletItemPersistence;
1484            @BeanReference(type = PortletPreferencesPersistence.class)
1485            protected PortletPreferencesPersistence portletPreferencesPersistence;
1486            @BeanReference(type = RegionPersistence.class)
1487            protected RegionPersistence regionPersistence;
1488            @BeanReference(type = ReleasePersistence.class)
1489            protected ReleasePersistence releasePersistence;
1490            @BeanReference(type = RepositoryPersistence.class)
1491            protected RepositoryPersistence repositoryPersistence;
1492            @BeanReference(type = RepositoryEntryPersistence.class)
1493            protected RepositoryEntryPersistence repositoryEntryPersistence;
1494            @BeanReference(type = ResourcePersistence.class)
1495            protected ResourcePersistence resourcePersistence;
1496            @BeanReference(type = ResourceActionPersistence.class)
1497            protected ResourceActionPersistence resourceActionPersistence;
1498            @BeanReference(type = ResourceBlockPersistence.class)
1499            protected ResourceBlockPersistence resourceBlockPersistence;
1500            @BeanReference(type = ResourceBlockPermissionPersistence.class)
1501            protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
1502            @BeanReference(type = ResourceCodePersistence.class)
1503            protected ResourceCodePersistence resourceCodePersistence;
1504            @BeanReference(type = ResourcePermissionPersistence.class)
1505            protected ResourcePermissionPersistence resourcePermissionPersistence;
1506            @BeanReference(type = ResourceTypePermissionPersistence.class)
1507            protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
1508            @BeanReference(type = RolePersistence.class)
1509            protected RolePersistence rolePersistence;
1510            @BeanReference(type = ServiceComponentPersistence.class)
1511            protected ServiceComponentPersistence serviceComponentPersistence;
1512            @BeanReference(type = ShardPersistence.class)
1513            protected ShardPersistence shardPersistence;
1514            @BeanReference(type = SubscriptionPersistence.class)
1515            protected SubscriptionPersistence subscriptionPersistence;
1516            @BeanReference(type = TeamPersistence.class)
1517            protected TeamPersistence teamPersistence;
1518            @BeanReference(type = TicketPersistence.class)
1519            protected TicketPersistence ticketPersistence;
1520            @BeanReference(type = UserPersistence.class)
1521            protected UserPersistence userPersistence;
1522            @BeanReference(type = UserGroupPersistence.class)
1523            protected UserGroupPersistence userGroupPersistence;
1524            @BeanReference(type = UserGroupGroupRolePersistence.class)
1525            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1526            @BeanReference(type = UserGroupRolePersistence.class)
1527            protected UserGroupRolePersistence userGroupRolePersistence;
1528            @BeanReference(type = UserIdMapperPersistence.class)
1529            protected UserIdMapperPersistence userIdMapperPersistence;
1530            @BeanReference(type = UserNotificationEventPersistence.class)
1531            protected UserNotificationEventPersistence userNotificationEventPersistence;
1532            @BeanReference(type = UserTrackerPersistence.class)
1533            protected UserTrackerPersistence userTrackerPersistence;
1534            @BeanReference(type = UserTrackerPathPersistence.class)
1535            protected UserTrackerPathPersistence userTrackerPathPersistence;
1536            @BeanReference(type = VirtualHostPersistence.class)
1537            protected VirtualHostPersistence virtualHostPersistence;
1538            @BeanReference(type = WebDAVPropsPersistence.class)
1539            protected WebDAVPropsPersistence webDAVPropsPersistence;
1540            @BeanReference(type = WebsitePersistence.class)
1541            protected WebsitePersistence websitePersistence;
1542            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1543            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1544            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1545            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1546            private static final String _SQL_SELECT_PLUGINSETTING = "SELECT pluginSetting FROM PluginSetting pluginSetting";
1547            private static final String _SQL_SELECT_PLUGINSETTING_WHERE = "SELECT pluginSetting FROM PluginSetting pluginSetting WHERE ";
1548            private static final String _SQL_COUNT_PLUGINSETTING = "SELECT COUNT(pluginSetting) FROM PluginSetting pluginSetting";
1549            private static final String _SQL_COUNT_PLUGINSETTING_WHERE = "SELECT COUNT(pluginSetting) FROM PluginSetting pluginSetting WHERE ";
1550            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "pluginSetting.companyId = ?";
1551            private static final String _FINDER_COLUMN_C_I_T_COMPANYID_2 = "pluginSetting.companyId = ? AND ";
1552            private static final String _FINDER_COLUMN_C_I_T_PLUGINID_1 = "pluginSetting.pluginId IS NULL AND ";
1553            private static final String _FINDER_COLUMN_C_I_T_PLUGINID_2 = "pluginSetting.pluginId = ? AND ";
1554            private static final String _FINDER_COLUMN_C_I_T_PLUGINID_3 = "(pluginSetting.pluginId IS NULL OR pluginSetting.pluginId = ?) AND ";
1555            private static final String _FINDER_COLUMN_C_I_T_PLUGINTYPE_1 = "pluginSetting.pluginType IS NULL";
1556            private static final String _FINDER_COLUMN_C_I_T_PLUGINTYPE_2 = "pluginSetting.pluginType = ?";
1557            private static final String _FINDER_COLUMN_C_I_T_PLUGINTYPE_3 = "(pluginSetting.pluginType IS NULL OR pluginSetting.pluginType = ?)";
1558            private static final String _ORDER_BY_ENTITY_ALIAS = "pluginSetting.";
1559            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PluginSetting exists with the primary key ";
1560            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PluginSetting exists with the key {";
1561            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1562            private static Log _log = LogFactoryUtil.getLog(PluginSettingPersistenceImpl.class);
1563            private static PluginSetting _nullPluginSetting = new PluginSettingImpl() {
1564                            @Override
1565                            public Object clone() {
1566                                    return this;
1567                            }
1568    
1569                            @Override
1570                            public CacheModel<PluginSetting> toCacheModel() {
1571                                    return _nullPluginSettingCacheModel;
1572                            }
1573                    };
1574    
1575            private static CacheModel<PluginSetting> _nullPluginSettingCacheModel = new CacheModel<PluginSetting>() {
1576                            public PluginSetting toEntityModel() {
1577                                    return _nullPluginSetting;
1578                            }
1579                    };
1580    }