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