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