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