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