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