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