1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.service.persistence;
16  
17  import com.liferay.portal.NoSuchModelException;
18  import com.liferay.portal.NoSuchPluginSettingException;
19  import com.liferay.portal.SystemException;
20  import com.liferay.portal.kernel.annotation.BeanReference;
21  import com.liferay.portal.kernel.cache.CacheRegistry;
22  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
23  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
24  import com.liferay.portal.kernel.dao.orm.FinderPath;
25  import com.liferay.portal.kernel.dao.orm.Query;
26  import com.liferay.portal.kernel.dao.orm.QueryPos;
27  import com.liferay.portal.kernel.dao.orm.QueryUtil;
28  import com.liferay.portal.kernel.dao.orm.Session;
29  import com.liferay.portal.kernel.log.Log;
30  import com.liferay.portal.kernel.log.LogFactoryUtil;
31  import com.liferay.portal.kernel.util.GetterUtil;
32  import com.liferay.portal.kernel.util.InstanceFactory;
33  import com.liferay.portal.kernel.util.OrderByComparator;
34  import com.liferay.portal.kernel.util.StringBundler;
35  import com.liferay.portal.kernel.util.StringPool;
36  import com.liferay.portal.kernel.util.StringUtil;
37  import com.liferay.portal.kernel.util.Validator;
38  import com.liferay.portal.model.ModelListener;
39  import com.liferay.portal.model.PluginSetting;
40  import com.liferay.portal.model.impl.PluginSettingImpl;
41  import com.liferay.portal.model.impl.PluginSettingModelImpl;
42  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
43  
44  import java.io.Serializable;
45  
46  import java.util.ArrayList;
47  import java.util.Collections;
48  import java.util.List;
49  
50  /**
51   * <a href="PluginSettingPersistenceImpl.java.html"><b><i>View Source</i></b></a>
52   *
53   * <p>
54   * ServiceBuilder generated this class. Modifications in this class will be
55   * overwritten the next time is generated.
56   * </p>
57   *
58   * @author    Brian Wing Shun Chan
59   * @see       PluginSettingPersistence
60   * @see       PluginSettingUtil
61   * @generated
62   */
63  public class PluginSettingPersistenceImpl extends BasePersistenceImpl<PluginSetting>
64      implements PluginSettingPersistence {
65      public static final String FINDER_CLASS_NAME_ENTITY = PluginSettingImpl.class.getName();
66      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
67          ".List";
68      public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
69              PluginSettingModelImpl.FINDER_CACHE_ENABLED,
70              FINDER_CLASS_NAME_LIST, "findByCompanyId",
71              new String[] {
72                  Long.class.getName(),
73                  
74              "java.lang.Integer", "java.lang.Integer",
75                  "com.liferay.portal.kernel.util.OrderByComparator"
76              });
77      public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
78              PluginSettingModelImpl.FINDER_CACHE_ENABLED,
79              FINDER_CLASS_NAME_LIST, "countByCompanyId",
80              new String[] { Long.class.getName() });
81      public static final FinderPath FINDER_PATH_FETCH_BY_C_I_T = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
82              PluginSettingModelImpl.FINDER_CACHE_ENABLED,
83              FINDER_CLASS_NAME_ENTITY, "fetchByC_I_T",
84              new String[] {
85                  Long.class.getName(), String.class.getName(),
86                  String.class.getName()
87              });
88      public static final FinderPath FINDER_PATH_COUNT_BY_C_I_T = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
89              PluginSettingModelImpl.FINDER_CACHE_ENABLED,
90              FINDER_CLASS_NAME_LIST, "countByC_I_T",
91              new String[] {
92                  Long.class.getName(), String.class.getName(),
93                  String.class.getName()
94              });
95      public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
96              PluginSettingModelImpl.FINDER_CACHE_ENABLED,
97              FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
98      public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
99              PluginSettingModelImpl.FINDER_CACHE_ENABLED,
100             FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
101 
102     public void cacheResult(PluginSetting pluginSetting) {
103         EntityCacheUtil.putResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
104             PluginSettingImpl.class, pluginSetting.getPrimaryKey(),
105             pluginSetting);
106 
107         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_I_T,
108             new Object[] {
109                 new Long(pluginSetting.getCompanyId()),
110                 
111             pluginSetting.getPluginId(),
112                 
113             pluginSetting.getPluginType()
114             }, pluginSetting);
115     }
116 
117     public void cacheResult(List<PluginSetting> pluginSettings) {
118         for (PluginSetting pluginSetting : pluginSettings) {
119             if (EntityCacheUtil.getResult(
120                         PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
121                         PluginSettingImpl.class, pluginSetting.getPrimaryKey(),
122                         this) == null) {
123                 cacheResult(pluginSetting);
124             }
125         }
126     }
127 
128     public void clearCache() {
129         CacheRegistry.clear(PluginSettingImpl.class.getName());
130         EntityCacheUtil.clearCache(PluginSettingImpl.class.getName());
131         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
132         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
133     }
134 
135     public void clearCache(PluginSetting pluginSetting) {
136         EntityCacheUtil.removeResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
137             PluginSettingImpl.class, pluginSetting.getPrimaryKey());
138 
139         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_I_T,
140             new Object[] {
141                 new Long(pluginSetting.getCompanyId()),
142                 
143             pluginSetting.getPluginId(),
144                 
145             pluginSetting.getPluginType()
146             });
147     }
148 
149     public PluginSetting create(long pluginSettingId) {
150         PluginSetting pluginSetting = new PluginSettingImpl();
151 
152         pluginSetting.setNew(true);
153         pluginSetting.setPrimaryKey(pluginSettingId);
154 
155         return pluginSetting;
156     }
157 
158     public PluginSetting remove(Serializable primaryKey)
159         throws NoSuchModelException, SystemException {
160         return remove(((Long)primaryKey).longValue());
161     }
162 
163     public PluginSetting remove(long pluginSettingId)
164         throws NoSuchPluginSettingException, SystemException {
165         Session session = null;
166 
167         try {
168             session = openSession();
169 
170             PluginSetting pluginSetting = (PluginSetting)session.get(PluginSettingImpl.class,
171                     new Long(pluginSettingId));
172 
173             if (pluginSetting == null) {
174                 if (_log.isWarnEnabled()) {
175                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
176                         pluginSettingId);
177                 }
178 
179                 throw new NoSuchPluginSettingException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
180                     pluginSettingId);
181             }
182 
183             return remove(pluginSetting);
184         }
185         catch (NoSuchPluginSettingException nsee) {
186             throw nsee;
187         }
188         catch (Exception e) {
189             throw processException(e);
190         }
191         finally {
192             closeSession(session);
193         }
194     }
195 
196     protected PluginSetting removeImpl(PluginSetting pluginSetting)
197         throws SystemException {
198         pluginSetting = toUnwrappedModel(pluginSetting);
199 
200         Session session = null;
201 
202         try {
203             session = openSession();
204 
205             BatchSessionUtil.delete(session, pluginSetting);
206         }
207         catch (Exception e) {
208             throw processException(e);
209         }
210         finally {
211             closeSession(session);
212         }
213 
214         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
215 
216         PluginSettingModelImpl pluginSettingModelImpl = (PluginSettingModelImpl)pluginSetting;
217 
218         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_I_T,
219             new Object[] {
220                 new Long(pluginSettingModelImpl.getOriginalCompanyId()),
221                 
222             pluginSettingModelImpl.getOriginalPluginId(),
223                 
224             pluginSettingModelImpl.getOriginalPluginType()
225             });
226 
227         EntityCacheUtil.removeResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
228             PluginSettingImpl.class, pluginSetting.getPrimaryKey());
229 
230         return pluginSetting;
231     }
232 
233     /**
234      * @deprecated Use {@link BasePersistence#update(com.liferay.portal.model.BaseModel, boolean)}.
235      */
236     public PluginSetting update(PluginSetting pluginSetting)
237         throws SystemException {
238         if (_log.isWarnEnabled()) {
239             _log.warn(
240                 "Using the deprecated update(PluginSetting pluginSetting) method. Use update(PluginSetting pluginSetting, boolean merge) instead.");
241         }
242 
243         return update(pluginSetting, false);
244     }
245 
246     public PluginSetting updateImpl(
247         com.liferay.portal.model.PluginSetting pluginSetting, boolean merge)
248         throws SystemException {
249         pluginSetting = toUnwrappedModel(pluginSetting);
250 
251         boolean isNew = pluginSetting.isNew();
252 
253         PluginSettingModelImpl pluginSettingModelImpl = (PluginSettingModelImpl)pluginSetting;
254 
255         Session session = null;
256 
257         try {
258             session = openSession();
259 
260             BatchSessionUtil.update(session, pluginSetting, merge);
261 
262             pluginSetting.setNew(false);
263         }
264         catch (Exception e) {
265             throw processException(e);
266         }
267         finally {
268             closeSession(session);
269         }
270 
271         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
272 
273         EntityCacheUtil.putResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
274             PluginSettingImpl.class, pluginSetting.getPrimaryKey(),
275             pluginSetting);
276 
277         if (!isNew &&
278                 ((pluginSetting.getCompanyId() != pluginSettingModelImpl.getOriginalCompanyId()) ||
279                 !Validator.equals(pluginSetting.getPluginId(),
280                     pluginSettingModelImpl.getOriginalPluginId()) ||
281                 !Validator.equals(pluginSetting.getPluginType(),
282                     pluginSettingModelImpl.getOriginalPluginType()))) {
283             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_I_T,
284                 new Object[] {
285                     new Long(pluginSettingModelImpl.getOriginalCompanyId()),
286                     
287                 pluginSettingModelImpl.getOriginalPluginId(),
288                     
289                 pluginSettingModelImpl.getOriginalPluginType()
290                 });
291         }
292 
293         if (isNew ||
294                 ((pluginSetting.getCompanyId() != pluginSettingModelImpl.getOriginalCompanyId()) ||
295                 !Validator.equals(pluginSetting.getPluginId(),
296                     pluginSettingModelImpl.getOriginalPluginId()) ||
297                 !Validator.equals(pluginSetting.getPluginType(),
298                     pluginSettingModelImpl.getOriginalPluginType()))) {
299             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_I_T,
300                 new Object[] {
301                     new Long(pluginSetting.getCompanyId()),
302                     
303                 pluginSetting.getPluginId(),
304                     
305                 pluginSetting.getPluginType()
306                 }, pluginSetting);
307         }
308 
309         return pluginSetting;
310     }
311 
312     protected PluginSetting toUnwrappedModel(PluginSetting pluginSetting) {
313         if (pluginSetting instanceof PluginSettingImpl) {
314             return pluginSetting;
315         }
316 
317         PluginSettingImpl pluginSettingImpl = new PluginSettingImpl();
318 
319         pluginSettingImpl.setNew(pluginSetting.isNew());
320         pluginSettingImpl.setPrimaryKey(pluginSetting.getPrimaryKey());
321 
322         pluginSettingImpl.setPluginSettingId(pluginSetting.getPluginSettingId());
323         pluginSettingImpl.setCompanyId(pluginSetting.getCompanyId());
324         pluginSettingImpl.setPluginId(pluginSetting.getPluginId());
325         pluginSettingImpl.setPluginType(pluginSetting.getPluginType());
326         pluginSettingImpl.setRoles(pluginSetting.getRoles());
327         pluginSettingImpl.setActive(pluginSetting.isActive());
328 
329         return pluginSettingImpl;
330     }
331 
332     public PluginSetting findByPrimaryKey(Serializable primaryKey)
333         throws NoSuchModelException, SystemException {
334         return findByPrimaryKey(((Long)primaryKey).longValue());
335     }
336 
337     public PluginSetting findByPrimaryKey(long pluginSettingId)
338         throws NoSuchPluginSettingException, SystemException {
339         PluginSetting pluginSetting = fetchByPrimaryKey(pluginSettingId);
340 
341         if (pluginSetting == null) {
342             if (_log.isWarnEnabled()) {
343                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + pluginSettingId);
344             }
345 
346             throw new NoSuchPluginSettingException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
347                 pluginSettingId);
348         }
349 
350         return pluginSetting;
351     }
352 
353     public PluginSetting fetchByPrimaryKey(Serializable primaryKey)
354         throws SystemException {
355         return fetchByPrimaryKey(((Long)primaryKey).longValue());
356     }
357 
358     public PluginSetting fetchByPrimaryKey(long pluginSettingId)
359         throws SystemException {
360         PluginSetting pluginSetting = (PluginSetting)EntityCacheUtil.getResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
361                 PluginSettingImpl.class, pluginSettingId, this);
362 
363         if (pluginSetting == null) {
364             Session session = null;
365 
366             try {
367                 session = openSession();
368 
369                 pluginSetting = (PluginSetting)session.get(PluginSettingImpl.class,
370                         new Long(pluginSettingId));
371             }
372             catch (Exception e) {
373                 throw processException(e);
374             }
375             finally {
376                 if (pluginSetting != null) {
377                     cacheResult(pluginSetting);
378                 }
379 
380                 closeSession(session);
381             }
382         }
383 
384         return pluginSetting;
385     }
386 
387     public List<PluginSetting> findByCompanyId(long companyId)
388         throws SystemException {
389         return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
390             null);
391     }
392 
393     public List<PluginSetting> findByCompanyId(long companyId, int start,
394         int end) throws SystemException {
395         return findByCompanyId(companyId, start, end, null);
396     }
397 
398     public List<PluginSetting> findByCompanyId(long companyId, int start,
399         int end, OrderByComparator orderByComparator) throws SystemException {
400         Object[] finderArgs = new Object[] {
401                 companyId,
402                 
403                 String.valueOf(start), String.valueOf(end),
404                 String.valueOf(orderByComparator)
405             };
406 
407         List<PluginSetting> list = (List<PluginSetting>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
408                 finderArgs, this);
409 
410         if (list == null) {
411             StringBundler query = null;
412 
413             if (orderByComparator != null) {
414                 query = new StringBundler(3 +
415                         (orderByComparator.getOrderByFields().length * 3));
416             }
417             else {
418                 query = new StringBundler(2);
419             }
420 
421             query.append(_SQL_SELECT_PLUGINSETTING_WHERE);
422 
423             query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
424 
425             if (orderByComparator != null) {
426                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
427                     orderByComparator);
428             }
429 
430             String sql = query.toString();
431 
432             Session session = null;
433 
434             try {
435                 session = openSession();
436 
437                 Query q = session.createQuery(sql);
438 
439                 QueryPos qPos = QueryPos.getInstance(q);
440 
441                 qPos.add(companyId);
442 
443                 list = (List<PluginSetting>)QueryUtil.list(q, getDialect(),
444                         start, end);
445             }
446             catch (Exception e) {
447                 throw processException(e);
448             }
449             finally {
450                 if (list == null) {
451                     list = new ArrayList<PluginSetting>();
452                 }
453 
454                 cacheResult(list);
455 
456                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
457                     finderArgs, list);
458 
459                 closeSession(session);
460             }
461         }
462 
463         return list;
464     }
465 
466     public PluginSetting findByCompanyId_First(long companyId,
467         OrderByComparator orderByComparator)
468         throws NoSuchPluginSettingException, SystemException {
469         List<PluginSetting> list = findByCompanyId(companyId, 0, 1,
470                 orderByComparator);
471 
472         if (list.isEmpty()) {
473             StringBundler msg = new StringBundler(4);
474 
475             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
476 
477             msg.append("companyId=");
478             msg.append(companyId);
479 
480             msg.append(StringPool.CLOSE_CURLY_BRACE);
481 
482             throw new NoSuchPluginSettingException(msg.toString());
483         }
484         else {
485             return list.get(0);
486         }
487     }
488 
489     public PluginSetting findByCompanyId_Last(long companyId,
490         OrderByComparator orderByComparator)
491         throws NoSuchPluginSettingException, SystemException {
492         int count = countByCompanyId(companyId);
493 
494         List<PluginSetting> list = findByCompanyId(companyId, count - 1, count,
495                 orderByComparator);
496 
497         if (list.isEmpty()) {
498             StringBundler msg = new StringBundler(4);
499 
500             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
501 
502             msg.append("companyId=");
503             msg.append(companyId);
504 
505             msg.append(StringPool.CLOSE_CURLY_BRACE);
506 
507             throw new NoSuchPluginSettingException(msg.toString());
508         }
509         else {
510             return list.get(0);
511         }
512     }
513 
514     public PluginSetting[] findByCompanyId_PrevAndNext(long pluginSettingId,
515         long companyId, OrderByComparator orderByComparator)
516         throws NoSuchPluginSettingException, SystemException {
517         PluginSetting pluginSetting = findByPrimaryKey(pluginSettingId);
518 
519         Session session = null;
520 
521         try {
522             session = openSession();
523 
524             PluginSetting[] array = new PluginSettingImpl[3];
525 
526             array[0] = getByCompanyId_PrevAndNext(session, pluginSetting,
527                     companyId, orderByComparator, true);
528 
529             array[1] = pluginSetting;
530 
531             array[2] = getByCompanyId_PrevAndNext(session, pluginSetting,
532                     companyId, orderByComparator, false);
533 
534             return array;
535         }
536         catch (Exception e) {
537             throw processException(e);
538         }
539         finally {
540             closeSession(session);
541         }
542     }
543 
544     protected PluginSetting getByCompanyId_PrevAndNext(Session session,
545         PluginSetting pluginSetting, long companyId,
546         OrderByComparator orderByComparator, boolean previous) {
547         StringBundler query = null;
548 
549         if (orderByComparator != null) {
550             query = new StringBundler(6 +
551                     (orderByComparator.getOrderByFields().length * 6));
552         }
553         else {
554             query = new StringBundler(3);
555         }
556 
557         query.append(_SQL_SELECT_PLUGINSETTING_WHERE);
558 
559         query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
560 
561         if (orderByComparator != null) {
562             String[] orderByFields = orderByComparator.getOrderByFields();
563 
564             if (orderByFields.length > 0) {
565                 query.append(WHERE_AND);
566             }
567 
568             for (int i = 0; i < orderByFields.length; i++) {
569                 query.append(_ORDER_BY_ENTITY_ALIAS);
570                 query.append(orderByFields[i]);
571 
572                 if ((i + 1) < orderByFields.length) {
573                     if (orderByComparator.isAscending() ^ previous) {
574                         query.append(WHERE_GREATER_THAN_HAS_NEXT);
575                     }
576                     else {
577                         query.append(WHERE_LESSER_THAN_HAS_NEXT);
578                     }
579                 }
580                 else {
581                     if (orderByComparator.isAscending() ^ previous) {
582                         query.append(WHERE_GREATER_THAN);
583                     }
584                     else {
585                         query.append(WHERE_LESSER_THAN);
586                     }
587                 }
588             }
589 
590             query.append(ORDER_BY_CLAUSE);
591 
592             for (int i = 0; i < orderByFields.length; i++) {
593                 query.append(_ORDER_BY_ENTITY_ALIAS);
594                 query.append(orderByFields[i]);
595 
596                 if ((i + 1) < orderByFields.length) {
597                     if (orderByComparator.isAscending() ^ previous) {
598                         query.append(ORDER_BY_ASC_HAS_NEXT);
599                     }
600                     else {
601                         query.append(ORDER_BY_DESC_HAS_NEXT);
602                     }
603                 }
604                 else {
605                     if (orderByComparator.isAscending() ^ previous) {
606                         query.append(ORDER_BY_ASC);
607                     }
608                     else {
609                         query.append(ORDER_BY_DESC);
610                     }
611                 }
612             }
613         }
614 
615         String sql = query.toString();
616 
617         Query q = session.createQuery(sql);
618 
619         q.setFirstResult(0);
620         q.setMaxResults(2);
621 
622         QueryPos qPos = QueryPos.getInstance(q);
623 
624         qPos.add(companyId);
625 
626         if (orderByComparator != null) {
627             Object[] values = orderByComparator.getOrderByValues(pluginSetting);
628 
629             for (Object value : values) {
630                 qPos.add(value);
631             }
632         }
633 
634         List<PluginSetting> list = q.list();
635 
636         if (list.size() == 2) {
637             return list.get(1);
638         }
639         else {
640             return null;
641         }
642     }
643 
644     public PluginSetting findByC_I_T(long companyId, String pluginId,
645         String pluginType) throws NoSuchPluginSettingException, SystemException {
646         PluginSetting pluginSetting = fetchByC_I_T(companyId, pluginId,
647                 pluginType);
648 
649         if (pluginSetting == null) {
650             StringBundler msg = new StringBundler(8);
651 
652             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
653 
654             msg.append("companyId=");
655             msg.append(companyId);
656 
657             msg.append(", pluginId=");
658             msg.append(pluginId);
659 
660             msg.append(", pluginType=");
661             msg.append(pluginType);
662 
663             msg.append(StringPool.CLOSE_CURLY_BRACE);
664 
665             if (_log.isWarnEnabled()) {
666                 _log.warn(msg.toString());
667             }
668 
669             throw new NoSuchPluginSettingException(msg.toString());
670         }
671 
672         return pluginSetting;
673     }
674 
675     public PluginSetting fetchByC_I_T(long companyId, String pluginId,
676         String pluginType) throws SystemException {
677         return fetchByC_I_T(companyId, pluginId, pluginType, true);
678     }
679 
680     public PluginSetting fetchByC_I_T(long companyId, String pluginId,
681         String pluginType, boolean retrieveFromCache) throws SystemException {
682         Object[] finderArgs = new Object[] { companyId, pluginId, pluginType };
683 
684         Object result = null;
685 
686         if (retrieveFromCache) {
687             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_I_T,
688                     finderArgs, this);
689         }
690 
691         if (result == null) {
692             StringBundler query = new StringBundler(4);
693 
694             query.append(_SQL_SELECT_PLUGINSETTING_WHERE);
695 
696             query.append(_FINDER_COLUMN_C_I_T_COMPANYID_2);
697 
698             if (pluginId == null) {
699                 query.append(_FINDER_COLUMN_C_I_T_PLUGINID_1);
700             }
701             else {
702                 if (pluginId.equals(StringPool.BLANK)) {
703                     query.append(_FINDER_COLUMN_C_I_T_PLUGINID_3);
704                 }
705                 else {
706                     query.append(_FINDER_COLUMN_C_I_T_PLUGINID_2);
707                 }
708             }
709 
710             if (pluginType == null) {
711                 query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_1);
712             }
713             else {
714                 if (pluginType.equals(StringPool.BLANK)) {
715                     query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_3);
716                 }
717                 else {
718                     query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_2);
719                 }
720             }
721 
722             String sql = query.toString();
723 
724             Session session = null;
725 
726             try {
727                 session = openSession();
728 
729                 Query q = session.createQuery(sql);
730 
731                 QueryPos qPos = QueryPos.getInstance(q);
732 
733                 qPos.add(companyId);
734 
735                 if (pluginId != null) {
736                     qPos.add(pluginId);
737                 }
738 
739                 if (pluginType != null) {
740                     qPos.add(pluginType);
741                 }
742 
743                 List<PluginSetting> list = q.list();
744 
745                 result = list;
746 
747                 PluginSetting pluginSetting = null;
748 
749                 if (list.isEmpty()) {
750                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_I_T,
751                         finderArgs, list);
752                 }
753                 else {
754                     pluginSetting = list.get(0);
755 
756                     cacheResult(pluginSetting);
757 
758                     if ((pluginSetting.getCompanyId() != companyId) ||
759                             (pluginSetting.getPluginId() == null) ||
760                             !pluginSetting.getPluginId().equals(pluginId) ||
761                             (pluginSetting.getPluginType() == null) ||
762                             !pluginSetting.getPluginType().equals(pluginType)) {
763                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_I_T,
764                             finderArgs, pluginSetting);
765                     }
766                 }
767 
768                 return pluginSetting;
769             }
770             catch (Exception e) {
771                 throw processException(e);
772             }
773             finally {
774                 if (result == null) {
775                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_I_T,
776                         finderArgs, new ArrayList<PluginSetting>());
777                 }
778 
779                 closeSession(session);
780             }
781         }
782         else {
783             if (result instanceof List<?>) {
784                 return null;
785             }
786             else {
787                 return (PluginSetting)result;
788             }
789         }
790     }
791 
792     public List<PluginSetting> findAll() throws SystemException {
793         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
794     }
795 
796     public List<PluginSetting> findAll(int start, int end)
797         throws SystemException {
798         return findAll(start, end, null);
799     }
800 
801     public List<PluginSetting> findAll(int start, int end,
802         OrderByComparator orderByComparator) throws SystemException {
803         Object[] finderArgs = new Object[] {
804                 String.valueOf(start), String.valueOf(end),
805                 String.valueOf(orderByComparator)
806             };
807 
808         List<PluginSetting> list = (List<PluginSetting>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
809                 finderArgs, this);
810 
811         if (list == null) {
812             StringBundler query = null;
813             String sql = null;
814 
815             if (orderByComparator != null) {
816                 query = new StringBundler(2 +
817                         (orderByComparator.getOrderByFields().length * 3));
818 
819                 query.append(_SQL_SELECT_PLUGINSETTING);
820 
821                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
822                     orderByComparator);
823 
824                 sql = query.toString();
825             }
826             else {
827                 sql = _SQL_SELECT_PLUGINSETTING;
828             }
829 
830             Session session = null;
831 
832             try {
833                 session = openSession();
834 
835                 Query q = session.createQuery(sql);
836 
837                 if (orderByComparator == null) {
838                     list = (List<PluginSetting>)QueryUtil.list(q, getDialect(),
839                             start, end, false);
840 
841                     Collections.sort(list);
842                 }
843                 else {
844                     list = (List<PluginSetting>)QueryUtil.list(q, getDialect(),
845                             start, end);
846                 }
847             }
848             catch (Exception e) {
849                 throw processException(e);
850             }
851             finally {
852                 if (list == null) {
853                     list = new ArrayList<PluginSetting>();
854                 }
855 
856                 cacheResult(list);
857 
858                 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
859 
860                 closeSession(session);
861             }
862         }
863 
864         return list;
865     }
866 
867     public void removeByCompanyId(long companyId) throws SystemException {
868         for (PluginSetting pluginSetting : findByCompanyId(companyId)) {
869             remove(pluginSetting);
870         }
871     }
872 
873     public void removeByC_I_T(long companyId, String pluginId, String pluginType)
874         throws NoSuchPluginSettingException, SystemException {
875         PluginSetting pluginSetting = findByC_I_T(companyId, pluginId,
876                 pluginType);
877 
878         remove(pluginSetting);
879     }
880 
881     public void removeAll() throws SystemException {
882         for (PluginSetting pluginSetting : findAll()) {
883             remove(pluginSetting);
884         }
885     }
886 
887     public int countByCompanyId(long companyId) throws SystemException {
888         Object[] finderArgs = new Object[] { companyId };
889 
890         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
891                 finderArgs, this);
892 
893         if (count == null) {
894             StringBundler query = new StringBundler(2);
895 
896             query.append(_SQL_COUNT_PLUGINSETTING_WHERE);
897 
898             query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
899 
900             String sql = query.toString();
901 
902             Session session = null;
903 
904             try {
905                 session = openSession();
906 
907                 Query q = session.createQuery(sql);
908 
909                 QueryPos qPos = QueryPos.getInstance(q);
910 
911                 qPos.add(companyId);
912 
913                 count = (Long)q.uniqueResult();
914             }
915             catch (Exception e) {
916                 throw processException(e);
917             }
918             finally {
919                 if (count == null) {
920                     count = Long.valueOf(0);
921                 }
922 
923                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
924                     finderArgs, count);
925 
926                 closeSession(session);
927             }
928         }
929 
930         return count.intValue();
931     }
932 
933     public int countByC_I_T(long companyId, String pluginId, String pluginType)
934         throws SystemException {
935         Object[] finderArgs = new Object[] { companyId, pluginId, pluginType };
936 
937         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_I_T,
938                 finderArgs, this);
939 
940         if (count == null) {
941             StringBundler query = new StringBundler(4);
942 
943             query.append(_SQL_COUNT_PLUGINSETTING_WHERE);
944 
945             query.append(_FINDER_COLUMN_C_I_T_COMPANYID_2);
946 
947             if (pluginId == null) {
948                 query.append(_FINDER_COLUMN_C_I_T_PLUGINID_1);
949             }
950             else {
951                 if (pluginId.equals(StringPool.BLANK)) {
952                     query.append(_FINDER_COLUMN_C_I_T_PLUGINID_3);
953                 }
954                 else {
955                     query.append(_FINDER_COLUMN_C_I_T_PLUGINID_2);
956                 }
957             }
958 
959             if (pluginType == null) {
960                 query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_1);
961             }
962             else {
963                 if (pluginType.equals(StringPool.BLANK)) {
964                     query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_3);
965                 }
966                 else {
967                     query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_2);
968                 }
969             }
970 
971             String sql = query.toString();
972 
973             Session session = null;
974 
975             try {
976                 session = openSession();
977 
978                 Query q = session.createQuery(sql);
979 
980                 QueryPos qPos = QueryPos.getInstance(q);
981 
982                 qPos.add(companyId);
983 
984                 if (pluginId != null) {
985                     qPos.add(pluginId);
986                 }
987 
988                 if (pluginType != null) {
989                     qPos.add(pluginType);
990                 }
991 
992                 count = (Long)q.uniqueResult();
993             }
994             catch (Exception e) {
995                 throw processException(e);
996             }
997             finally {
998                 if (count == null) {
999                     count = Long.valueOf(0);
1000                }
1001
1002                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_I_T,
1003                    finderArgs, count);
1004
1005                closeSession(session);
1006            }
1007        }
1008
1009        return count.intValue();
1010    }
1011
1012    public int countAll() throws SystemException {
1013        Object[] finderArgs = new Object[0];
1014
1015        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1016                finderArgs, this);
1017
1018        if (count == null) {
1019            Session session = null;
1020
1021            try {
1022                session = openSession();
1023
1024                Query q = session.createQuery(_SQL_COUNT_PLUGINSETTING);
1025
1026                count = (Long)q.uniqueResult();
1027            }
1028            catch (Exception e) {
1029                throw processException(e);
1030            }
1031            finally {
1032                if (count == null) {
1033                    count = Long.valueOf(0);
1034                }
1035
1036                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1037                    count);
1038
1039                closeSession(session);
1040            }
1041        }
1042
1043        return count.intValue();
1044    }
1045
1046    public void afterPropertiesSet() {
1047        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1048                    com.liferay.portal.util.PropsUtil.get(
1049                        "value.object.listener.com.liferay.portal.model.PluginSetting")));
1050
1051        if (listenerClassNames.length > 0) {
1052            try {
1053                List<ModelListener<PluginSetting>> listenersList = new ArrayList<ModelListener<PluginSetting>>();
1054
1055                for (String listenerClassName : listenerClassNames) {
1056                    listenersList.add((ModelListener<PluginSetting>)InstanceFactory.newInstance(
1057                            listenerClassName));
1058                }
1059
1060                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1061            }
1062            catch (Exception e) {
1063                _log.error(e);
1064            }
1065        }
1066    }
1067
1068    public void destroy() {
1069        EntityCacheUtil.removeCache(PluginSettingImpl.class.getName());
1070        FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1071        FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1072    }
1073
1074    @BeanReference(type = AccountPersistence.class)
1075    protected AccountPersistence accountPersistence;
1076    @BeanReference(type = AddressPersistence.class)
1077    protected AddressPersistence addressPersistence;
1078    @BeanReference(type = BrowserTrackerPersistence.class)
1079    protected BrowserTrackerPersistence browserTrackerPersistence;
1080    @BeanReference(type = ClassNamePersistence.class)
1081    protected ClassNamePersistence classNamePersistence;
1082    @BeanReference(type = CompanyPersistence.class)
1083    protected CompanyPersistence companyPersistence;
1084    @BeanReference(type = ContactPersistence.class)
1085    protected ContactPersistence contactPersistence;
1086    @BeanReference(type = CountryPersistence.class)
1087    protected CountryPersistence countryPersistence;
1088    @BeanReference(type = EmailAddressPersistence.class)
1089    protected EmailAddressPersistence emailAddressPersistence;
1090    @BeanReference(type = GroupPersistence.class)
1091    protected GroupPersistence groupPersistence;
1092    @BeanReference(type = ImagePersistence.class)
1093    protected ImagePersistence imagePersistence;
1094    @BeanReference(type = LayoutPersistence.class)
1095    protected LayoutPersistence layoutPersistence;
1096    @BeanReference(type = LayoutSetPersistence.class)
1097    protected LayoutSetPersistence layoutSetPersistence;
1098    @BeanReference(type = ListTypePersistence.class)
1099    protected ListTypePersistence listTypePersistence;
1100    @BeanReference(type = LockPersistence.class)
1101    protected LockPersistence lockPersistence;
1102    @BeanReference(type = MembershipRequestPersistence.class)
1103    protected MembershipRequestPersistence membershipRequestPersistence;
1104    @BeanReference(type = OrganizationPersistence.class)
1105    protected OrganizationPersistence organizationPersistence;
1106    @BeanReference(type = OrgGroupPermissionPersistence.class)
1107    protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1108    @BeanReference(type = OrgGroupRolePersistence.class)
1109    protected OrgGroupRolePersistence orgGroupRolePersistence;
1110    @BeanReference(type = OrgLaborPersistence.class)
1111    protected OrgLaborPersistence orgLaborPersistence;
1112    @BeanReference(type = PasswordPolicyPersistence.class)
1113    protected PasswordPolicyPersistence passwordPolicyPersistence;
1114    @BeanReference(type = PasswordPolicyRelPersistence.class)
1115    protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1116    @BeanReference(type = PasswordTrackerPersistence.class)
1117    protected PasswordTrackerPersistence passwordTrackerPersistence;
1118    @BeanReference(type = PermissionPersistence.class)
1119    protected PermissionPersistence permissionPersistence;
1120    @BeanReference(type = PhonePersistence.class)
1121    protected PhonePersistence phonePersistence;
1122    @BeanReference(type = PluginSettingPersistence.class)
1123    protected PluginSettingPersistence pluginSettingPersistence;
1124    @BeanReference(type = PortletPersistence.class)
1125    protected PortletPersistence portletPersistence;
1126    @BeanReference(type = PortletItemPersistence.class)
1127    protected PortletItemPersistence portletItemPersistence;
1128    @BeanReference(type = PortletPreferencesPersistence.class)
1129    protected PortletPreferencesPersistence portletPreferencesPersistence;
1130    @BeanReference(type = RegionPersistence.class)
1131    protected RegionPersistence regionPersistence;
1132    @BeanReference(type = ReleasePersistence.class)
1133    protected ReleasePersistence releasePersistence;
1134    @BeanReference(type = ResourcePersistence.class)
1135    protected ResourcePersistence resourcePersistence;
1136    @BeanReference(type = ResourceActionPersistence.class)
1137    protected ResourceActionPersistence resourceActionPersistence;
1138    @BeanReference(type = ResourceCodePersistence.class)
1139    protected ResourceCodePersistence resourceCodePersistence;
1140    @BeanReference(type = ResourcePermissionPersistence.class)
1141    protected ResourcePermissionPersistence resourcePermissionPersistence;
1142    @BeanReference(type = RolePersistence.class)
1143    protected RolePersistence rolePersistence;
1144    @BeanReference(type = ServiceComponentPersistence.class)
1145    protected ServiceComponentPersistence serviceComponentPersistence;
1146    @BeanReference(type = ShardPersistence.class)
1147    protected ShardPersistence shardPersistence;
1148    @BeanReference(type = SubscriptionPersistence.class)
1149    protected SubscriptionPersistence subscriptionPersistence;
1150    @BeanReference(type = UserPersistence.class)
1151    protected UserPersistence userPersistence;
1152    @BeanReference(type = UserGroupPersistence.class)
1153    protected UserGroupPersistence userGroupPersistence;
1154    @BeanReference(type = UserGroupGroupRolePersistence.class)
1155    protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1156    @BeanReference(type = UserGroupRolePersistence.class)
1157    protected UserGroupRolePersistence userGroupRolePersistence;
1158    @BeanReference(type = UserIdMapperPersistence.class)
1159    protected UserIdMapperPersistence userIdMapperPersistence;
1160    @BeanReference(type = UserTrackerPersistence.class)
1161    protected UserTrackerPersistence userTrackerPersistence;
1162    @BeanReference(type = UserTrackerPathPersistence.class)
1163    protected UserTrackerPathPersistence userTrackerPathPersistence;
1164    @BeanReference(type = WebDAVPropsPersistence.class)
1165    protected WebDAVPropsPersistence webDAVPropsPersistence;
1166    @BeanReference(type = WebsitePersistence.class)
1167    protected WebsitePersistence websitePersistence;
1168    private static final String _SQL_SELECT_PLUGINSETTING = "SELECT pluginSetting FROM PluginSetting pluginSetting";
1169    private static final String _SQL_SELECT_PLUGINSETTING_WHERE = "SELECT pluginSetting FROM PluginSetting pluginSetting WHERE ";
1170    private static final String _SQL_COUNT_PLUGINSETTING = "SELECT COUNT(pluginSetting) FROM PluginSetting pluginSetting";
1171    private static final String _SQL_COUNT_PLUGINSETTING_WHERE = "SELECT COUNT(pluginSetting) FROM PluginSetting pluginSetting WHERE ";
1172    private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "pluginSetting.companyId = ?";
1173    private static final String _FINDER_COLUMN_C_I_T_COMPANYID_2 = "pluginSetting.companyId = ? AND ";
1174    private static final String _FINDER_COLUMN_C_I_T_PLUGINID_1 = "pluginSetting.pluginId IS NULL AND ";
1175    private static final String _FINDER_COLUMN_C_I_T_PLUGINID_2 = "pluginSetting.pluginId = ? AND ";
1176    private static final String _FINDER_COLUMN_C_I_T_PLUGINID_3 = "(pluginSetting.pluginId IS NULL OR pluginSetting.pluginId = ?) AND ";
1177    private static final String _FINDER_COLUMN_C_I_T_PLUGINTYPE_1 = "pluginSetting.pluginType IS NULL";
1178    private static final String _FINDER_COLUMN_C_I_T_PLUGINTYPE_2 = "pluginSetting.pluginType = ?";
1179    private static final String _FINDER_COLUMN_C_I_T_PLUGINTYPE_3 = "(pluginSetting.pluginType IS NULL OR pluginSetting.pluginType = ?)";
1180    private static final String _ORDER_BY_ENTITY_ALIAS = "pluginSetting.";
1181    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PluginSetting exists with the primary key ";
1182    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PluginSetting exists with the key {";
1183    private static Log _log = LogFactoryUtil.getLog(PluginSettingPersistenceImpl.class);
1184}