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.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     public PluginSetting remove(PluginSetting pluginSetting)
197         throws SystemException {
198         for (ModelListener<PluginSetting> listener : listeners) {
199             listener.onBeforeRemove(pluginSetting);
200         }
201 
202         pluginSetting = removeImpl(pluginSetting);
203 
204         for (ModelListener<PluginSetting> listener : listeners) {
205             listener.onAfterRemove(pluginSetting);
206         }
207 
208         return pluginSetting;
209     }
210 
211     protected PluginSetting removeImpl(PluginSetting pluginSetting)
212         throws SystemException {
213         pluginSetting = toUnwrappedModel(pluginSetting);
214 
215         Session session = null;
216 
217         try {
218             session = openSession();
219 
220             if (pluginSetting.isCachedModel() || BatchSessionUtil.isEnabled()) {
221                 Object staleObject = session.get(PluginSettingImpl.class,
222                         pluginSetting.getPrimaryKeyObj());
223 
224                 if (staleObject != null) {
225                     session.evict(staleObject);
226                 }
227             }
228 
229             session.delete(pluginSetting);
230 
231             session.flush();
232         }
233         catch (Exception e) {
234             throw processException(e);
235         }
236         finally {
237             closeSession(session);
238         }
239 
240         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
241 
242         PluginSettingModelImpl pluginSettingModelImpl = (PluginSettingModelImpl)pluginSetting;
243 
244         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_I_T,
245             new Object[] {
246                 new Long(pluginSettingModelImpl.getOriginalCompanyId()),
247                 
248             pluginSettingModelImpl.getOriginalPluginId(),
249                 
250             pluginSettingModelImpl.getOriginalPluginType()
251             });
252 
253         EntityCacheUtil.removeResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
254             PluginSettingImpl.class, pluginSetting.getPrimaryKey());
255 
256         return pluginSetting;
257     }
258 
259     public PluginSetting updateImpl(
260         com.liferay.portal.model.PluginSetting pluginSetting, boolean merge)
261         throws SystemException {
262         pluginSetting = toUnwrappedModel(pluginSetting);
263 
264         boolean isNew = pluginSetting.isNew();
265 
266         PluginSettingModelImpl pluginSettingModelImpl = (PluginSettingModelImpl)pluginSetting;
267 
268         Session session = null;
269 
270         try {
271             session = openSession();
272 
273             BatchSessionUtil.update(session, pluginSetting, merge);
274 
275             pluginSetting.setNew(false);
276         }
277         catch (Exception e) {
278             throw processException(e);
279         }
280         finally {
281             closeSession(session);
282         }
283 
284         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
285 
286         EntityCacheUtil.putResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
287             PluginSettingImpl.class, pluginSetting.getPrimaryKey(),
288             pluginSetting);
289 
290         if (!isNew &&
291                 ((pluginSetting.getCompanyId() != pluginSettingModelImpl.getOriginalCompanyId()) ||
292                 !Validator.equals(pluginSetting.getPluginId(),
293                     pluginSettingModelImpl.getOriginalPluginId()) ||
294                 !Validator.equals(pluginSetting.getPluginType(),
295                     pluginSettingModelImpl.getOriginalPluginType()))) {
296             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_I_T,
297                 new Object[] {
298                     new Long(pluginSettingModelImpl.getOriginalCompanyId()),
299                     
300                 pluginSettingModelImpl.getOriginalPluginId(),
301                     
302                 pluginSettingModelImpl.getOriginalPluginType()
303                 });
304         }
305 
306         if (isNew ||
307                 ((pluginSetting.getCompanyId() != pluginSettingModelImpl.getOriginalCompanyId()) ||
308                 !Validator.equals(pluginSetting.getPluginId(),
309                     pluginSettingModelImpl.getOriginalPluginId()) ||
310                 !Validator.equals(pluginSetting.getPluginType(),
311                     pluginSettingModelImpl.getOriginalPluginType()))) {
312             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_I_T,
313                 new Object[] {
314                     new Long(pluginSetting.getCompanyId()),
315                     
316                 pluginSetting.getPluginId(),
317                     
318                 pluginSetting.getPluginType()
319                 }, pluginSetting);
320         }
321 
322         return pluginSetting;
323     }
324 
325     protected PluginSetting toUnwrappedModel(PluginSetting pluginSetting) {
326         if (pluginSetting instanceof PluginSettingImpl) {
327             return pluginSetting;
328         }
329 
330         PluginSettingImpl pluginSettingImpl = new PluginSettingImpl();
331 
332         pluginSettingImpl.setNew(pluginSetting.isNew());
333         pluginSettingImpl.setPrimaryKey(pluginSetting.getPrimaryKey());
334 
335         pluginSettingImpl.setPluginSettingId(pluginSetting.getPluginSettingId());
336         pluginSettingImpl.setCompanyId(pluginSetting.getCompanyId());
337         pluginSettingImpl.setPluginId(pluginSetting.getPluginId());
338         pluginSettingImpl.setPluginType(pluginSetting.getPluginType());
339         pluginSettingImpl.setRoles(pluginSetting.getRoles());
340         pluginSettingImpl.setActive(pluginSetting.isActive());
341 
342         return pluginSettingImpl;
343     }
344 
345     public PluginSetting findByPrimaryKey(Serializable primaryKey)
346         throws NoSuchModelException, SystemException {
347         return findByPrimaryKey(((Long)primaryKey).longValue());
348     }
349 
350     public PluginSetting findByPrimaryKey(long pluginSettingId)
351         throws NoSuchPluginSettingException, SystemException {
352         PluginSetting pluginSetting = fetchByPrimaryKey(pluginSettingId);
353 
354         if (pluginSetting == null) {
355             if (_log.isWarnEnabled()) {
356                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + pluginSettingId);
357             }
358 
359             throw new NoSuchPluginSettingException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
360                 pluginSettingId);
361         }
362 
363         return pluginSetting;
364     }
365 
366     public PluginSetting fetchByPrimaryKey(Serializable primaryKey)
367         throws SystemException {
368         return fetchByPrimaryKey(((Long)primaryKey).longValue());
369     }
370 
371     public PluginSetting fetchByPrimaryKey(long pluginSettingId)
372         throws SystemException {
373         PluginSetting pluginSetting = (PluginSetting)EntityCacheUtil.getResult(PluginSettingModelImpl.ENTITY_CACHE_ENABLED,
374                 PluginSettingImpl.class, pluginSettingId, this);
375 
376         if (pluginSetting == null) {
377             Session session = null;
378 
379             try {
380                 session = openSession();
381 
382                 pluginSetting = (PluginSetting)session.get(PluginSettingImpl.class,
383                         new Long(pluginSettingId));
384             }
385             catch (Exception e) {
386                 throw processException(e);
387             }
388             finally {
389                 if (pluginSetting != null) {
390                     cacheResult(pluginSetting);
391                 }
392 
393                 closeSession(session);
394             }
395         }
396 
397         return pluginSetting;
398     }
399 
400     public List<PluginSetting> findByCompanyId(long companyId)
401         throws SystemException {
402         return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
403             null);
404     }
405 
406     public List<PluginSetting> findByCompanyId(long companyId, int start,
407         int end) throws SystemException {
408         return findByCompanyId(companyId, start, end, null);
409     }
410 
411     public List<PluginSetting> findByCompanyId(long companyId, int start,
412         int end, OrderByComparator orderByComparator) throws SystemException {
413         Object[] finderArgs = new Object[] {
414                 new Long(companyId),
415                 
416                 String.valueOf(start), String.valueOf(end),
417                 String.valueOf(orderByComparator)
418             };
419 
420         List<PluginSetting> list = (List<PluginSetting>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
421                 finderArgs, this);
422 
423         if (list == null) {
424             Session session = null;
425 
426             try {
427                 session = openSession();
428 
429                 StringBundler query = null;
430 
431                 if (orderByComparator != null) {
432                     query = new StringBundler(3 +
433                             (orderByComparator.getOrderByFields().length * 3));
434                 }
435                 else {
436                     query = new StringBundler(2);
437                 }
438 
439                 query.append(_SQL_SELECT_PLUGINSETTING_WHERE);
440 
441                 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
442 
443                 if (orderByComparator != null) {
444                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
445                         orderByComparator);
446                 }
447 
448                 String sql = query.toString();
449 
450                 Query q = session.createQuery(sql);
451 
452                 QueryPos qPos = QueryPos.getInstance(q);
453 
454                 qPos.add(companyId);
455 
456                 list = (List<PluginSetting>)QueryUtil.list(q, getDialect(),
457                         start, end);
458             }
459             catch (Exception e) {
460                 throw processException(e);
461             }
462             finally {
463                 if (list == null) {
464                     list = new ArrayList<PluginSetting>();
465                 }
466 
467                 cacheResult(list);
468 
469                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
470                     finderArgs, list);
471 
472                 closeSession(session);
473             }
474         }
475 
476         return list;
477     }
478 
479     public PluginSetting findByCompanyId_First(long companyId,
480         OrderByComparator orderByComparator)
481         throws NoSuchPluginSettingException, SystemException {
482         List<PluginSetting> list = findByCompanyId(companyId, 0, 1,
483                 orderByComparator);
484 
485         if (list.isEmpty()) {
486             StringBundler msg = new StringBundler(4);
487 
488             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
489 
490             msg.append("companyId=");
491             msg.append(companyId);
492 
493             msg.append(StringPool.CLOSE_CURLY_BRACE);
494 
495             throw new NoSuchPluginSettingException(msg.toString());
496         }
497         else {
498             return list.get(0);
499         }
500     }
501 
502     public PluginSetting findByCompanyId_Last(long companyId,
503         OrderByComparator orderByComparator)
504         throws NoSuchPluginSettingException, SystemException {
505         int count = countByCompanyId(companyId);
506 
507         List<PluginSetting> list = findByCompanyId(companyId, count - 1, count,
508                 orderByComparator);
509 
510         if (list.isEmpty()) {
511             StringBundler msg = new StringBundler(4);
512 
513             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
514 
515             msg.append("companyId=");
516             msg.append(companyId);
517 
518             msg.append(StringPool.CLOSE_CURLY_BRACE);
519 
520             throw new NoSuchPluginSettingException(msg.toString());
521         }
522         else {
523             return list.get(0);
524         }
525     }
526 
527     public PluginSetting[] findByCompanyId_PrevAndNext(long pluginSettingId,
528         long companyId, OrderByComparator orderByComparator)
529         throws NoSuchPluginSettingException, SystemException {
530         PluginSetting pluginSetting = findByPrimaryKey(pluginSettingId);
531 
532         Session session = null;
533 
534         try {
535             session = openSession();
536 
537             PluginSetting[] array = new PluginSettingImpl[3];
538 
539             array[0] = getByCompanyId_PrevAndNext(session, pluginSetting,
540                     companyId, orderByComparator, true);
541 
542             array[1] = pluginSetting;
543 
544             array[2] = getByCompanyId_PrevAndNext(session, pluginSetting,
545                     companyId, orderByComparator, false);
546 
547             return array;
548         }
549         catch (Exception e) {
550             throw processException(e);
551         }
552         finally {
553             closeSession(session);
554         }
555     }
556 
557     protected PluginSetting getByCompanyId_PrevAndNext(Session session,
558         PluginSetting pluginSetting, long companyId,
559         OrderByComparator orderByComparator, boolean previous) {
560         StringBundler query = null;
561 
562         if (orderByComparator != null) {
563             query = new StringBundler(6 +
564                     (orderByComparator.getOrderByFields().length * 6));
565         }
566         else {
567             query = new StringBundler(3);
568         }
569 
570         query.append(_SQL_SELECT_PLUGINSETTING_WHERE);
571 
572         query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
573 
574         if (orderByComparator != null) {
575             String[] orderByFields = orderByComparator.getOrderByFields();
576 
577             if (orderByFields.length > 0) {
578                 query.append(WHERE_AND);
579             }
580 
581             for (int i = 0; i < orderByFields.length; i++) {
582                 query.append(_ORDER_BY_ENTITY_ALIAS);
583                 query.append(orderByFields[i]);
584 
585                 if ((i + 1) < orderByFields.length) {
586                     if (orderByComparator.isAscending() ^ previous) {
587                         query.append(WHERE_GREATER_THAN_HAS_NEXT);
588                     }
589                     else {
590                         query.append(WHERE_LESSER_THAN_HAS_NEXT);
591                     }
592                 }
593                 else {
594                     if (orderByComparator.isAscending() ^ previous) {
595                         query.append(WHERE_GREATER_THAN);
596                     }
597                     else {
598                         query.append(WHERE_LESSER_THAN);
599                     }
600                 }
601             }
602 
603             query.append(ORDER_BY_CLAUSE);
604 
605             for (int i = 0; i < orderByFields.length; i++) {
606                 query.append(_ORDER_BY_ENTITY_ALIAS);
607                 query.append(orderByFields[i]);
608 
609                 if ((i + 1) < orderByFields.length) {
610                     if (orderByComparator.isAscending() ^ previous) {
611                         query.append(ORDER_BY_ASC_HAS_NEXT);
612                     }
613                     else {
614                         query.append(ORDER_BY_DESC_HAS_NEXT);
615                     }
616                 }
617                 else {
618                     if (orderByComparator.isAscending() ^ previous) {
619                         query.append(ORDER_BY_ASC);
620                     }
621                     else {
622                         query.append(ORDER_BY_DESC);
623                     }
624                 }
625             }
626         }
627 
628         String sql = query.toString();
629 
630         Query q = session.createQuery(sql);
631 
632         q.setFirstResult(0);
633         q.setMaxResults(2);
634 
635         QueryPos qPos = QueryPos.getInstance(q);
636 
637         qPos.add(companyId);
638 
639         if (orderByComparator != null) {
640             Object[] values = orderByComparator.getOrderByValues(pluginSetting);
641 
642             for (Object value : values) {
643                 qPos.add(value);
644             }
645         }
646 
647         List<PluginSetting> list = q.list();
648 
649         if (list.size() == 2) {
650             return list.get(1);
651         }
652         else {
653             return null;
654         }
655     }
656 
657     public PluginSetting findByC_I_T(long companyId, String pluginId,
658         String pluginType) throws NoSuchPluginSettingException, SystemException {
659         PluginSetting pluginSetting = fetchByC_I_T(companyId, pluginId,
660                 pluginType);
661 
662         if (pluginSetting == null) {
663             StringBundler msg = new StringBundler(8);
664 
665             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
666 
667             msg.append("companyId=");
668             msg.append(companyId);
669 
670             msg.append(", pluginId=");
671             msg.append(pluginId);
672 
673             msg.append(", pluginType=");
674             msg.append(pluginType);
675 
676             msg.append(StringPool.CLOSE_CURLY_BRACE);
677 
678             if (_log.isWarnEnabled()) {
679                 _log.warn(msg.toString());
680             }
681 
682             throw new NoSuchPluginSettingException(msg.toString());
683         }
684 
685         return pluginSetting;
686     }
687 
688     public PluginSetting fetchByC_I_T(long companyId, String pluginId,
689         String pluginType) throws SystemException {
690         return fetchByC_I_T(companyId, pluginId, pluginType, true);
691     }
692 
693     public PluginSetting fetchByC_I_T(long companyId, String pluginId,
694         String pluginType, boolean retrieveFromCache) throws SystemException {
695         Object[] finderArgs = new Object[] {
696                 new Long(companyId),
697                 
698                 pluginId,
699                 
700                 pluginType
701             };
702 
703         Object result = null;
704 
705         if (retrieveFromCache) {
706             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_I_T,
707                     finderArgs, this);
708         }
709 
710         if (result == null) {
711             Session session = null;
712 
713             try {
714                 session = openSession();
715 
716                 StringBundler query = new StringBundler(4);
717 
718                 query.append(_SQL_SELECT_PLUGINSETTING_WHERE);
719 
720                 query.append(_FINDER_COLUMN_C_I_T_COMPANYID_2);
721 
722                 if (pluginId == null) {
723                     query.append(_FINDER_COLUMN_C_I_T_PLUGINID_1);
724                 }
725                 else {
726                     if (pluginId.equals(StringPool.BLANK)) {
727                         query.append(_FINDER_COLUMN_C_I_T_PLUGINID_3);
728                     }
729                     else {
730                         query.append(_FINDER_COLUMN_C_I_T_PLUGINID_2);
731                     }
732                 }
733 
734                 if (pluginType == null) {
735                     query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_1);
736                 }
737                 else {
738                     if (pluginType.equals(StringPool.BLANK)) {
739                         query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_3);
740                     }
741                     else {
742                         query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_2);
743                     }
744                 }
745 
746                 String sql = query.toString();
747 
748                 Query q = session.createQuery(sql);
749 
750                 QueryPos qPos = QueryPos.getInstance(q);
751 
752                 qPos.add(companyId);
753 
754                 if (pluginId != null) {
755                     qPos.add(pluginId);
756                 }
757 
758                 if (pluginType != null) {
759                     qPos.add(pluginType);
760                 }
761 
762                 List<PluginSetting> list = q.list();
763 
764                 result = list;
765 
766                 PluginSetting pluginSetting = null;
767 
768                 if (list.isEmpty()) {
769                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_I_T,
770                         finderArgs, list);
771                 }
772                 else {
773                     pluginSetting = list.get(0);
774 
775                     cacheResult(pluginSetting);
776 
777                     if ((pluginSetting.getCompanyId() != companyId) ||
778                             (pluginSetting.getPluginId() == null) ||
779                             !pluginSetting.getPluginId().equals(pluginId) ||
780                             (pluginSetting.getPluginType() == null) ||
781                             !pluginSetting.getPluginType().equals(pluginType)) {
782                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_I_T,
783                             finderArgs, pluginSetting);
784                     }
785                 }
786 
787                 return pluginSetting;
788             }
789             catch (Exception e) {
790                 throw processException(e);
791             }
792             finally {
793                 if (result == null) {
794                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_I_T,
795                         finderArgs, new ArrayList<PluginSetting>());
796                 }
797 
798                 closeSession(session);
799             }
800         }
801         else {
802             if (result instanceof List<?>) {
803                 return null;
804             }
805             else {
806                 return (PluginSetting)result;
807             }
808         }
809     }
810 
811     public List<PluginSetting> findAll() throws SystemException {
812         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
813     }
814 
815     public List<PluginSetting> findAll(int start, int end)
816         throws SystemException {
817         return findAll(start, end, null);
818     }
819 
820     public List<PluginSetting> findAll(int start, int end,
821         OrderByComparator orderByComparator) throws SystemException {
822         Object[] finderArgs = new Object[] {
823                 String.valueOf(start), String.valueOf(end),
824                 String.valueOf(orderByComparator)
825             };
826 
827         List<PluginSetting> list = (List<PluginSetting>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
828                 finderArgs, this);
829 
830         if (list == null) {
831             Session session = null;
832 
833             try {
834                 session = openSession();
835 
836                 StringBundler query = null;
837                 String sql = null;
838 
839                 if (orderByComparator != null) {
840                     query = new StringBundler(2 +
841                             (orderByComparator.getOrderByFields().length * 3));
842 
843                     query.append(_SQL_SELECT_PLUGINSETTING);
844 
845                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
846                         orderByComparator);
847 
848                     sql = query.toString();
849                 }
850 
851                 sql = _SQL_SELECT_PLUGINSETTING;
852 
853                 Query q = session.createQuery(sql);
854 
855                 if (orderByComparator == null) {
856                     list = (List<PluginSetting>)QueryUtil.list(q, getDialect(),
857                             start, end, false);
858 
859                     Collections.sort(list);
860                 }
861                 else {
862                     list = (List<PluginSetting>)QueryUtil.list(q, getDialect(),
863                             start, end);
864                 }
865             }
866             catch (Exception e) {
867                 throw processException(e);
868             }
869             finally {
870                 if (list == null) {
871                     list = new ArrayList<PluginSetting>();
872                 }
873 
874                 cacheResult(list);
875 
876                 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
877 
878                 closeSession(session);
879             }
880         }
881 
882         return list;
883     }
884 
885     public void removeByCompanyId(long companyId) throws SystemException {
886         for (PluginSetting pluginSetting : findByCompanyId(companyId)) {
887             remove(pluginSetting);
888         }
889     }
890 
891     public void removeByC_I_T(long companyId, String pluginId, String pluginType)
892         throws NoSuchPluginSettingException, SystemException {
893         PluginSetting pluginSetting = findByC_I_T(companyId, pluginId,
894                 pluginType);
895 
896         remove(pluginSetting);
897     }
898 
899     public void removeAll() throws SystemException {
900         for (PluginSetting pluginSetting : findAll()) {
901             remove(pluginSetting);
902         }
903     }
904 
905     public int countByCompanyId(long companyId) throws SystemException {
906         Object[] finderArgs = new Object[] { new Long(companyId) };
907 
908         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
909                 finderArgs, this);
910 
911         if (count == null) {
912             Session session = null;
913 
914             try {
915                 session = openSession();
916 
917                 StringBundler query = new StringBundler(2);
918 
919                 query.append(_SQL_COUNT_PLUGINSETTING_WHERE);
920 
921                 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
922 
923                 String sql = query.toString();
924 
925                 Query q = session.createQuery(sql);
926 
927                 QueryPos qPos = QueryPos.getInstance(q);
928 
929                 qPos.add(companyId);
930 
931                 count = (Long)q.uniqueResult();
932             }
933             catch (Exception e) {
934                 throw processException(e);
935             }
936             finally {
937                 if (count == null) {
938                     count = Long.valueOf(0);
939                 }
940 
941                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
942                     finderArgs, count);
943 
944                 closeSession(session);
945             }
946         }
947 
948         return count.intValue();
949     }
950 
951     public int countByC_I_T(long companyId, String pluginId, String pluginType)
952         throws SystemException {
953         Object[] finderArgs = new Object[] {
954                 new Long(companyId),
955                 
956                 pluginId,
957                 
958                 pluginType
959             };
960 
961         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_I_T,
962                 finderArgs, this);
963 
964         if (count == null) {
965             Session session = null;
966 
967             try {
968                 session = openSession();
969 
970                 StringBundler query = new StringBundler(4);
971 
972                 query.append(_SQL_COUNT_PLUGINSETTING_WHERE);
973 
974                 query.append(_FINDER_COLUMN_C_I_T_COMPANYID_2);
975 
976                 if (pluginId == null) {
977                     query.append(_FINDER_COLUMN_C_I_T_PLUGINID_1);
978                 }
979                 else {
980                     if (pluginId.equals(StringPool.BLANK)) {
981                         query.append(_FINDER_COLUMN_C_I_T_PLUGINID_3);
982                     }
983                     else {
984                         query.append(_FINDER_COLUMN_C_I_T_PLUGINID_2);
985                     }
986                 }
987 
988                 if (pluginType == null) {
989                     query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_1);
990                 }
991                 else {
992                     if (pluginType.equals(StringPool.BLANK)) {
993                         query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_3);
994                     }
995                     else {
996                         query.append(_FINDER_COLUMN_C_I_T_PLUGINTYPE_2);
997                     }
998                 }
999 
1000                String sql = query.toString();
1001
1002                Query q = session.createQuery(sql);
1003
1004                QueryPos qPos = QueryPos.getInstance(q);
1005
1006                qPos.add(companyId);
1007
1008                if (pluginId != null) {
1009                    qPos.add(pluginId);
1010                }
1011
1012                if (pluginType != null) {
1013                    qPos.add(pluginType);
1014                }
1015
1016                count = (Long)q.uniqueResult();
1017            }
1018            catch (Exception e) {
1019                throw processException(e);
1020            }
1021            finally {
1022                if (count == null) {
1023                    count = Long.valueOf(0);
1024                }
1025
1026                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_I_T,
1027                    finderArgs, count);
1028
1029                closeSession(session);
1030            }
1031        }
1032
1033        return count.intValue();
1034    }
1035
1036    public int countAll() throws SystemException {
1037        Object[] finderArgs = new Object[0];
1038
1039        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1040                finderArgs, this);
1041
1042        if (count == null) {
1043            Session session = null;
1044
1045            try {
1046                session = openSession();
1047
1048                Query q = session.createQuery(_SQL_COUNT_PLUGINSETTING);
1049
1050                count = (Long)q.uniqueResult();
1051            }
1052            catch (Exception e) {
1053                throw processException(e);
1054            }
1055            finally {
1056                if (count == null) {
1057                    count = Long.valueOf(0);
1058                }
1059
1060                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1061                    count);
1062
1063                closeSession(session);
1064            }
1065        }
1066
1067        return count.intValue();
1068    }
1069
1070    public void afterPropertiesSet() {
1071        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1072                    com.liferay.portal.util.PropsUtil.get(
1073                        "value.object.listener.com.liferay.portal.model.PluginSetting")));
1074
1075        if (listenerClassNames.length > 0) {
1076            try {
1077                List<ModelListener<PluginSetting>> listenersList = new ArrayList<ModelListener<PluginSetting>>();
1078
1079                for (String listenerClassName : listenerClassNames) {
1080                    listenersList.add((ModelListener<PluginSetting>)InstanceFactory.newInstance(
1081                            listenerClassName));
1082                }
1083
1084                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1085            }
1086            catch (Exception e) {
1087                _log.error(e);
1088            }
1089        }
1090    }
1091
1092    @BeanReference(type = AccountPersistence.class)
1093    protected AccountPersistence accountPersistence;
1094    @BeanReference(type = AddressPersistence.class)
1095    protected AddressPersistence addressPersistence;
1096    @BeanReference(type = BrowserTrackerPersistence.class)
1097    protected BrowserTrackerPersistence browserTrackerPersistence;
1098    @BeanReference(type = ClassNamePersistence.class)
1099    protected ClassNamePersistence classNamePersistence;
1100    @BeanReference(type = CompanyPersistence.class)
1101    protected CompanyPersistence companyPersistence;
1102    @BeanReference(type = ContactPersistence.class)
1103    protected ContactPersistence contactPersistence;
1104    @BeanReference(type = CountryPersistence.class)
1105    protected CountryPersistence countryPersistence;
1106    @BeanReference(type = EmailAddressPersistence.class)
1107    protected EmailAddressPersistence emailAddressPersistence;
1108    @BeanReference(type = GroupPersistence.class)
1109    protected GroupPersistence groupPersistence;
1110    @BeanReference(type = ImagePersistence.class)
1111    protected ImagePersistence imagePersistence;
1112    @BeanReference(type = LayoutPersistence.class)
1113    protected LayoutPersistence layoutPersistence;
1114    @BeanReference(type = LayoutPrototypePersistence.class)
1115    protected LayoutPrototypePersistence layoutPrototypePersistence;
1116    @BeanReference(type = LayoutSetPersistence.class)
1117    protected LayoutSetPersistence layoutSetPersistence;
1118    @BeanReference(type = LayoutSetPrototypePersistence.class)
1119    protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1120    @BeanReference(type = ListTypePersistence.class)
1121    protected ListTypePersistence listTypePersistence;
1122    @BeanReference(type = LockPersistence.class)
1123    protected LockPersistence lockPersistence;
1124    @BeanReference(type = MembershipRequestPersistence.class)
1125    protected MembershipRequestPersistence membershipRequestPersistence;
1126    @BeanReference(type = OrganizationPersistence.class)
1127    protected OrganizationPersistence organizationPersistence;
1128    @BeanReference(type = OrgGroupPermissionPersistence.class)
1129    protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1130    @BeanReference(type = OrgGroupRolePersistence.class)
1131    protected OrgGroupRolePersistence orgGroupRolePersistence;
1132    @BeanReference(type = OrgLaborPersistence.class)
1133    protected OrgLaborPersistence orgLaborPersistence;
1134    @BeanReference(type = PasswordPolicyPersistence.class)
1135    protected PasswordPolicyPersistence passwordPolicyPersistence;
1136    @BeanReference(type = PasswordPolicyRelPersistence.class)
1137    protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1138    @BeanReference(type = PasswordTrackerPersistence.class)
1139    protected PasswordTrackerPersistence passwordTrackerPersistence;
1140    @BeanReference(type = PermissionPersistence.class)
1141    protected PermissionPersistence permissionPersistence;
1142    @BeanReference(type = PhonePersistence.class)
1143    protected PhonePersistence phonePersistence;
1144    @BeanReference(type = PluginSettingPersistence.class)
1145    protected PluginSettingPersistence pluginSettingPersistence;
1146    @BeanReference(type = PortletPersistence.class)
1147    protected PortletPersistence portletPersistence;
1148    @BeanReference(type = PortletItemPersistence.class)
1149    protected PortletItemPersistence portletItemPersistence;
1150    @BeanReference(type = PortletPreferencesPersistence.class)
1151    protected PortletPreferencesPersistence portletPreferencesPersistence;
1152    @BeanReference(type = RegionPersistence.class)
1153    protected RegionPersistence regionPersistence;
1154    @BeanReference(type = ReleasePersistence.class)
1155    protected ReleasePersistence releasePersistence;
1156    @BeanReference(type = ResourcePersistence.class)
1157    protected ResourcePersistence resourcePersistence;
1158    @BeanReference(type = ResourceActionPersistence.class)
1159    protected ResourceActionPersistence resourceActionPersistence;
1160    @BeanReference(type = ResourceCodePersistence.class)
1161    protected ResourceCodePersistence resourceCodePersistence;
1162    @BeanReference(type = ResourcePermissionPersistence.class)
1163    protected ResourcePermissionPersistence resourcePermissionPersistence;
1164    @BeanReference(type = RolePersistence.class)
1165    protected RolePersistence rolePersistence;
1166    @BeanReference(type = ServiceComponentPersistence.class)
1167    protected ServiceComponentPersistence serviceComponentPersistence;
1168    @BeanReference(type = ShardPersistence.class)
1169    protected ShardPersistence shardPersistence;
1170    @BeanReference(type = SubscriptionPersistence.class)
1171    protected SubscriptionPersistence subscriptionPersistence;
1172    @BeanReference(type = TicketPersistence.class)
1173    protected TicketPersistence ticketPersistence;
1174    @BeanReference(type = TeamPersistence.class)
1175    protected TeamPersistence teamPersistence;
1176    @BeanReference(type = UserPersistence.class)
1177    protected UserPersistence userPersistence;
1178    @BeanReference(type = UserGroupPersistence.class)
1179    protected UserGroupPersistence userGroupPersistence;
1180    @BeanReference(type = UserGroupGroupRolePersistence.class)
1181    protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1182    @BeanReference(type = UserGroupRolePersistence.class)
1183    protected UserGroupRolePersistence userGroupRolePersistence;
1184    @BeanReference(type = UserIdMapperPersistence.class)
1185    protected UserIdMapperPersistence userIdMapperPersistence;
1186    @BeanReference(type = UserTrackerPersistence.class)
1187    protected UserTrackerPersistence userTrackerPersistence;
1188    @BeanReference(type = UserTrackerPathPersistence.class)
1189    protected UserTrackerPathPersistence userTrackerPathPersistence;
1190    @BeanReference(type = WebDAVPropsPersistence.class)
1191    protected WebDAVPropsPersistence webDAVPropsPersistence;
1192    @BeanReference(type = WebsitePersistence.class)
1193    protected WebsitePersistence websitePersistence;
1194    @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1195    protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1196    @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1197    protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1198    private static final String _SQL_SELECT_PLUGINSETTING = "SELECT pluginSetting FROM PluginSetting pluginSetting";
1199    private static final String _SQL_SELECT_PLUGINSETTING_WHERE = "SELECT pluginSetting FROM PluginSetting pluginSetting WHERE ";
1200    private static final String _SQL_COUNT_PLUGINSETTING = "SELECT COUNT(pluginSetting) FROM PluginSetting pluginSetting";
1201    private static final String _SQL_COUNT_PLUGINSETTING_WHERE = "SELECT COUNT(pluginSetting) FROM PluginSetting pluginSetting WHERE ";
1202    private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "pluginSetting.companyId = ?";
1203    private static final String _FINDER_COLUMN_C_I_T_COMPANYID_2 = "pluginSetting.companyId = ? AND ";
1204    private static final String _FINDER_COLUMN_C_I_T_PLUGINID_1 = "pluginSetting.pluginId IS NULL AND ";
1205    private static final String _FINDER_COLUMN_C_I_T_PLUGINID_2 = "pluginSetting.pluginId = ? AND ";
1206    private static final String _FINDER_COLUMN_C_I_T_PLUGINID_3 = "(pluginSetting.pluginId IS NULL OR pluginSetting.pluginId = ?) AND ";
1207    private static final String _FINDER_COLUMN_C_I_T_PLUGINTYPE_1 = "pluginSetting.pluginType IS NULL";
1208    private static final String _FINDER_COLUMN_C_I_T_PLUGINTYPE_2 = "pluginSetting.pluginType = ?";
1209    private static final String _FINDER_COLUMN_C_I_T_PLUGINTYPE_3 = "(pluginSetting.pluginType IS NULL OR pluginSetting.pluginType = ?)";
1210    private static final String _ORDER_BY_ENTITY_ALIAS = "pluginSetting.";
1211    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PluginSetting exists with the primary key ";
1212    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PluginSetting exists with the key {";
1213    private static Log _log = LogFactoryUtil.getLog(PluginSettingPersistenceImpl.class);
1214}