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