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