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