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.portlet.polls.service.persistence;
24  
25  import com.liferay.portal.SystemException;
26  import com.liferay.portal.kernel.annotation.BeanReference;
27  import com.liferay.portal.kernel.cache.CacheRegistry;
28  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
29  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
30  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
31  import com.liferay.portal.kernel.dao.orm.FinderPath;
32  import com.liferay.portal.kernel.dao.orm.Query;
33  import com.liferay.portal.kernel.dao.orm.QueryPos;
34  import com.liferay.portal.kernel.dao.orm.QueryUtil;
35  import com.liferay.portal.kernel.dao.orm.Session;
36  import com.liferay.portal.kernel.log.Log;
37  import com.liferay.portal.kernel.log.LogFactoryUtil;
38  import com.liferay.portal.kernel.util.GetterUtil;
39  import com.liferay.portal.kernel.util.OrderByComparator;
40  import com.liferay.portal.kernel.util.StringPool;
41  import com.liferay.portal.kernel.util.StringUtil;
42  import com.liferay.portal.kernel.util.Validator;
43  import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
44  import com.liferay.portal.model.ModelListener;
45  import com.liferay.portal.service.persistence.BatchSessionUtil;
46  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
47  
48  import com.liferay.portlet.polls.NoSuchQuestionException;
49  import com.liferay.portlet.polls.model.PollsQuestion;
50  import com.liferay.portlet.polls.model.impl.PollsQuestionImpl;
51  import com.liferay.portlet.polls.model.impl.PollsQuestionModelImpl;
52  
53  import java.util.ArrayList;
54  import java.util.Collections;
55  import java.util.List;
56  
57  /**
58   * <a href="PollsQuestionPersistenceImpl.java.html"><b><i>View Source</i></b></a>
59   *
60   * <p>
61   * ServiceBuilder generated this class. Modifications in this class will be
62   * overwritten the next time is generated.
63   * </p>
64   *
65   * @author    Brian Wing Shun Chan
66   * @see       PollsQuestionPersistence
67   * @see       PollsQuestionUtil
68   * @generated
69   */
70  public class PollsQuestionPersistenceImpl extends BasePersistenceImpl
71      implements PollsQuestionPersistence {
72      public static final String FINDER_CLASS_NAME_ENTITY = PollsQuestionImpl.class.getName();
73      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
74          ".List";
75      public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
76              PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
77              FINDER_CLASS_NAME_LIST, "findByUuid",
78              new String[] { String.class.getName() });
79      public static final FinderPath FINDER_PATH_FIND_BY_OBC_UUID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
80              PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
81              FINDER_CLASS_NAME_LIST, "findByUuid",
82              new String[] {
83                  String.class.getName(),
84                  
85              "java.lang.Integer", "java.lang.Integer",
86                  "com.liferay.portal.kernel.util.OrderByComparator"
87              });
88      public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
89              PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
90              FINDER_CLASS_NAME_LIST, "countByUuid",
91              new String[] { String.class.getName() });
92      public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
93              PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
94              FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
95              new String[] { String.class.getName(), Long.class.getName() });
96      public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
97              PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
98              FINDER_CLASS_NAME_LIST, "countByUUID_G",
99              new String[] { String.class.getName(), Long.class.getName() });
100     public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
101             PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
102             FINDER_CLASS_NAME_LIST, "findByGroupId",
103             new String[] { Long.class.getName() });
104     public static final FinderPath FINDER_PATH_FIND_BY_OBC_GROUPID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
105             PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
106             FINDER_CLASS_NAME_LIST, "findByGroupId",
107             new String[] {
108                 Long.class.getName(),
109                 
110             "java.lang.Integer", "java.lang.Integer",
111                 "com.liferay.portal.kernel.util.OrderByComparator"
112             });
113     public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
114             PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
115             FINDER_CLASS_NAME_LIST, "countByGroupId",
116             new String[] { Long.class.getName() });
117     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
118             PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
119             FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
120     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
121             PollsQuestionModelImpl.FINDER_CACHE_ENABLED,
122             FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
123 
124     public void cacheResult(PollsQuestion pollsQuestion) {
125         EntityCacheUtil.putResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
126             PollsQuestionImpl.class, pollsQuestion.getPrimaryKey(),
127             pollsQuestion);
128 
129         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
130             new Object[] {
131                 pollsQuestion.getUuid(), new Long(pollsQuestion.getGroupId())
132             }, pollsQuestion);
133     }
134 
135     public void cacheResult(List<PollsQuestion> pollsQuestions) {
136         for (PollsQuestion pollsQuestion : pollsQuestions) {
137             if (EntityCacheUtil.getResult(
138                         PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
139                         PollsQuestionImpl.class, pollsQuestion.getPrimaryKey(),
140                         this) == null) {
141                 cacheResult(pollsQuestion);
142             }
143         }
144     }
145 
146     public void clearCache() {
147         CacheRegistry.clear(PollsQuestionImpl.class.getName());
148         EntityCacheUtil.clearCache(PollsQuestionImpl.class.getName());
149         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
150         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
151     }
152 
153     public PollsQuestion create(long questionId) {
154         PollsQuestion pollsQuestion = new PollsQuestionImpl();
155 
156         pollsQuestion.setNew(true);
157         pollsQuestion.setPrimaryKey(questionId);
158 
159         String uuid = PortalUUIDUtil.generate();
160 
161         pollsQuestion.setUuid(uuid);
162 
163         return pollsQuestion;
164     }
165 
166     public PollsQuestion remove(long questionId)
167         throws NoSuchQuestionException, SystemException {
168         Session session = null;
169 
170         try {
171             session = openSession();
172 
173             PollsQuestion pollsQuestion = (PollsQuestion)session.get(PollsQuestionImpl.class,
174                     new Long(questionId));
175 
176             if (pollsQuestion == null) {
177                 if (_log.isWarnEnabled()) {
178                     _log.warn("No PollsQuestion exists with the primary key " +
179                         questionId);
180                 }
181 
182                 throw new NoSuchQuestionException(
183                     "No PollsQuestion exists with the primary key " +
184                     questionId);
185             }
186 
187             return remove(pollsQuestion);
188         }
189         catch (NoSuchQuestionException nsee) {
190             throw nsee;
191         }
192         catch (Exception e) {
193             throw processException(e);
194         }
195         finally {
196             closeSession(session);
197         }
198     }
199 
200     public PollsQuestion remove(PollsQuestion pollsQuestion)
201         throws SystemException {
202         for (ModelListener<PollsQuestion> listener : listeners) {
203             listener.onBeforeRemove(pollsQuestion);
204         }
205 
206         pollsQuestion = removeImpl(pollsQuestion);
207 
208         for (ModelListener<PollsQuestion> listener : listeners) {
209             listener.onAfterRemove(pollsQuestion);
210         }
211 
212         return pollsQuestion;
213     }
214 
215     protected PollsQuestion removeImpl(PollsQuestion pollsQuestion)
216         throws SystemException {
217         Session session = null;
218 
219         try {
220             session = openSession();
221 
222             if (pollsQuestion.isCachedModel() || BatchSessionUtil.isEnabled()) {
223                 Object staleObject = session.get(PollsQuestionImpl.class,
224                         pollsQuestion.getPrimaryKeyObj());
225 
226                 if (staleObject != null) {
227                     session.evict(staleObject);
228                 }
229             }
230 
231             session.delete(pollsQuestion);
232 
233             session.flush();
234         }
235         catch (Exception e) {
236             throw processException(e);
237         }
238         finally {
239             closeSession(session);
240         }
241 
242         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
243 
244         PollsQuestionModelImpl pollsQuestionModelImpl = (PollsQuestionModelImpl)pollsQuestion;
245 
246         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
247             new Object[] {
248                 pollsQuestionModelImpl.getOriginalUuid(),
249                 new Long(pollsQuestionModelImpl.getOriginalGroupId())
250             });
251 
252         EntityCacheUtil.removeResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
253             PollsQuestionImpl.class, pollsQuestion.getPrimaryKey());
254 
255         return pollsQuestion;
256     }
257 
258     /**
259      * @deprecated Use {@link #update(PollsQuestion, boolean merge)}.
260      */
261     public PollsQuestion update(PollsQuestion pollsQuestion)
262         throws SystemException {
263         if (_log.isWarnEnabled()) {
264             _log.warn(
265                 "Using the deprecated update(PollsQuestion pollsQuestion) method. Use update(PollsQuestion pollsQuestion, boolean merge) instead.");
266         }
267 
268         return update(pollsQuestion, false);
269     }
270 
271     /**
272      * Add, update, or merge, the entity. This method also calls the model
273      * listeners to trigger the proper events associated with adding, deleting,
274      * or updating an entity.
275      *
276      * @param  pollsQuestion the entity to add, update, or merge
277      * @param  merge boolean value for whether to merge the entity. The default
278      *         value is false. Setting merge to true is more expensive and
279      *         should only be true when pollsQuestion is transient. See
280      *         LEP-5473 for a detailed discussion of this method.
281      * @return the entity that was added, updated, or merged
282      */
283     public PollsQuestion update(PollsQuestion pollsQuestion, boolean merge)
284         throws SystemException {
285         boolean isNew = pollsQuestion.isNew();
286 
287         for (ModelListener<PollsQuestion> listener : listeners) {
288             if (isNew) {
289                 listener.onBeforeCreate(pollsQuestion);
290             }
291             else {
292                 listener.onBeforeUpdate(pollsQuestion);
293             }
294         }
295 
296         pollsQuestion = updateImpl(pollsQuestion, merge);
297 
298         for (ModelListener<PollsQuestion> listener : listeners) {
299             if (isNew) {
300                 listener.onAfterCreate(pollsQuestion);
301             }
302             else {
303                 listener.onAfterUpdate(pollsQuestion);
304             }
305         }
306 
307         return pollsQuestion;
308     }
309 
310     public PollsQuestion updateImpl(
311         com.liferay.portlet.polls.model.PollsQuestion pollsQuestion,
312         boolean merge) throws SystemException {
313         boolean isNew = pollsQuestion.isNew();
314 
315         PollsQuestionModelImpl pollsQuestionModelImpl = (PollsQuestionModelImpl)pollsQuestion;
316 
317         if (Validator.isNull(pollsQuestion.getUuid())) {
318             String uuid = PortalUUIDUtil.generate();
319 
320             pollsQuestion.setUuid(uuid);
321         }
322 
323         Session session = null;
324 
325         try {
326             session = openSession();
327 
328             BatchSessionUtil.update(session, pollsQuestion, merge);
329 
330             pollsQuestion.setNew(false);
331         }
332         catch (Exception e) {
333             throw processException(e);
334         }
335         finally {
336             closeSession(session);
337         }
338 
339         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
340 
341         EntityCacheUtil.putResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
342             PollsQuestionImpl.class, pollsQuestion.getPrimaryKey(),
343             pollsQuestion);
344 
345         if (!isNew &&
346                 (!Validator.equals(pollsQuestion.getUuid(),
347                     pollsQuestionModelImpl.getOriginalUuid()) ||
348                 (pollsQuestion.getGroupId() != pollsQuestionModelImpl.getOriginalGroupId()))) {
349             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
350                 new Object[] {
351                     pollsQuestionModelImpl.getOriginalUuid(),
352                     new Long(pollsQuestionModelImpl.getOriginalGroupId())
353                 });
354         }
355 
356         if (isNew ||
357                 (!Validator.equals(pollsQuestion.getUuid(),
358                     pollsQuestionModelImpl.getOriginalUuid()) ||
359                 (pollsQuestion.getGroupId() != pollsQuestionModelImpl.getOriginalGroupId()))) {
360             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
361                 new Object[] {
362                     pollsQuestion.getUuid(),
363                     new Long(pollsQuestion.getGroupId())
364                 }, pollsQuestion);
365         }
366 
367         return pollsQuestion;
368     }
369 
370     public PollsQuestion findByPrimaryKey(long questionId)
371         throws NoSuchQuestionException, SystemException {
372         PollsQuestion pollsQuestion = fetchByPrimaryKey(questionId);
373 
374         if (pollsQuestion == null) {
375             if (_log.isWarnEnabled()) {
376                 _log.warn("No PollsQuestion exists with the primary key " +
377                     questionId);
378             }
379 
380             throw new NoSuchQuestionException(
381                 "No PollsQuestion exists with the primary key " + questionId);
382         }
383 
384         return pollsQuestion;
385     }
386 
387     public PollsQuestion fetchByPrimaryKey(long questionId)
388         throws SystemException {
389         PollsQuestion pollsQuestion = (PollsQuestion)EntityCacheUtil.getResult(PollsQuestionModelImpl.ENTITY_CACHE_ENABLED,
390                 PollsQuestionImpl.class, questionId, this);
391 
392         if (pollsQuestion == null) {
393             Session session = null;
394 
395             try {
396                 session = openSession();
397 
398                 pollsQuestion = (PollsQuestion)session.get(PollsQuestionImpl.class,
399                         new Long(questionId));
400             }
401             catch (Exception e) {
402                 throw processException(e);
403             }
404             finally {
405                 if (pollsQuestion != null) {
406                     cacheResult(pollsQuestion);
407                 }
408 
409                 closeSession(session);
410             }
411         }
412 
413         return pollsQuestion;
414     }
415 
416     public List<PollsQuestion> findByUuid(String uuid)
417         throws SystemException {
418         Object[] finderArgs = new Object[] { uuid };
419 
420         List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
421                 finderArgs, this);
422 
423         if (list == null) {
424             Session session = null;
425 
426             try {
427                 session = openSession();
428 
429                 StringBuilder query = new StringBuilder();
430 
431                 query.append(
432                     "SELECT pollsQuestion FROM PollsQuestion pollsQuestion WHERE ");
433 
434                 if (uuid == null) {
435                     query.append("pollsQuestion.uuid IS NULL");
436                 }
437                 else {
438                     query.append("pollsQuestion.uuid = ?");
439                 }
440 
441                 query.append(" ");
442 
443                 query.append("ORDER BY ");
444 
445                 query.append("pollsQuestion.createDate DESC");
446 
447                 Query q = session.createQuery(query.toString());
448 
449                 QueryPos qPos = QueryPos.getInstance(q);
450 
451                 if (uuid != null) {
452                     qPos.add(uuid);
453                 }
454 
455                 list = q.list();
456             }
457             catch (Exception e) {
458                 throw processException(e);
459             }
460             finally {
461                 if (list == null) {
462                     list = new ArrayList<PollsQuestion>();
463                 }
464 
465                 cacheResult(list);
466 
467                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
468                     list);
469 
470                 closeSession(session);
471             }
472         }
473 
474         return list;
475     }
476 
477     public List<PollsQuestion> findByUuid(String uuid, int start, int end)
478         throws SystemException {
479         return findByUuid(uuid, start, end, null);
480     }
481 
482     public List<PollsQuestion> findByUuid(String uuid, int start, int end,
483         OrderByComparator obc) throws SystemException {
484         Object[] finderArgs = new Object[] {
485                 uuid,
486                 
487                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
488             };
489 
490         List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_UUID,
491                 finderArgs, this);
492 
493         if (list == null) {
494             Session session = null;
495 
496             try {
497                 session = openSession();
498 
499                 StringBuilder query = new StringBuilder();
500 
501                 query.append(
502                     "SELECT pollsQuestion FROM PollsQuestion pollsQuestion WHERE ");
503 
504                 if (uuid == null) {
505                     query.append("pollsQuestion.uuid IS NULL");
506                 }
507                 else {
508                     query.append("pollsQuestion.uuid = ?");
509                 }
510 
511                 query.append(" ");
512 
513                 if (obc != null) {
514                     query.append("ORDER BY ");
515 
516                     String[] orderByFields = obc.getOrderByFields();
517 
518                     for (int i = 0; i < orderByFields.length; i++) {
519                         query.append("pollsQuestion.");
520                         query.append(orderByFields[i]);
521 
522                         if (obc.isAscending()) {
523                             query.append(" ASC");
524                         }
525                         else {
526                             query.append(" DESC");
527                         }
528 
529                         if ((i + 1) < orderByFields.length) {
530                             query.append(", ");
531                         }
532                     }
533                 }
534 
535                 else {
536                     query.append("ORDER BY ");
537 
538                     query.append("pollsQuestion.createDate DESC");
539                 }
540 
541                 Query q = session.createQuery(query.toString());
542 
543                 QueryPos qPos = QueryPos.getInstance(q);
544 
545                 if (uuid != null) {
546                     qPos.add(uuid);
547                 }
548 
549                 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
550                         start, end);
551             }
552             catch (Exception e) {
553                 throw processException(e);
554             }
555             finally {
556                 if (list == null) {
557                     list = new ArrayList<PollsQuestion>();
558                 }
559 
560                 cacheResult(list);
561 
562                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_UUID,
563                     finderArgs, list);
564 
565                 closeSession(session);
566             }
567         }
568 
569         return list;
570     }
571 
572     public PollsQuestion findByUuid_First(String uuid, OrderByComparator obc)
573         throws NoSuchQuestionException, SystemException {
574         List<PollsQuestion> list = findByUuid(uuid, 0, 1, obc);
575 
576         if (list.isEmpty()) {
577             StringBuilder msg = new StringBuilder();
578 
579             msg.append("No PollsQuestion exists with the key {");
580 
581             msg.append("uuid=" + uuid);
582 
583             msg.append(StringPool.CLOSE_CURLY_BRACE);
584 
585             throw new NoSuchQuestionException(msg.toString());
586         }
587         else {
588             return list.get(0);
589         }
590     }
591 
592     public PollsQuestion findByUuid_Last(String uuid, OrderByComparator obc)
593         throws NoSuchQuestionException, SystemException {
594         int count = countByUuid(uuid);
595 
596         List<PollsQuestion> list = findByUuid(uuid, count - 1, count, obc);
597 
598         if (list.isEmpty()) {
599             StringBuilder msg = new StringBuilder();
600 
601             msg.append("No PollsQuestion exists with the key {");
602 
603             msg.append("uuid=" + uuid);
604 
605             msg.append(StringPool.CLOSE_CURLY_BRACE);
606 
607             throw new NoSuchQuestionException(msg.toString());
608         }
609         else {
610             return list.get(0);
611         }
612     }
613 
614     public PollsQuestion[] findByUuid_PrevAndNext(long questionId, String uuid,
615         OrderByComparator obc) throws NoSuchQuestionException, SystemException {
616         PollsQuestion pollsQuestion = findByPrimaryKey(questionId);
617 
618         int count = countByUuid(uuid);
619 
620         Session session = null;
621 
622         try {
623             session = openSession();
624 
625             StringBuilder query = new StringBuilder();
626 
627             query.append(
628                 "SELECT pollsQuestion FROM PollsQuestion pollsQuestion WHERE ");
629 
630             if (uuid == null) {
631                 query.append("pollsQuestion.uuid IS NULL");
632             }
633             else {
634                 query.append("pollsQuestion.uuid = ?");
635             }
636 
637             query.append(" ");
638 
639             if (obc != null) {
640                 query.append("ORDER BY ");
641 
642                 String[] orderByFields = obc.getOrderByFields();
643 
644                 for (int i = 0; i < orderByFields.length; i++) {
645                     query.append("pollsQuestion.");
646                     query.append(orderByFields[i]);
647 
648                     if (obc.isAscending()) {
649                         query.append(" ASC");
650                     }
651                     else {
652                         query.append(" DESC");
653                     }
654 
655                     if ((i + 1) < orderByFields.length) {
656                         query.append(", ");
657                     }
658                 }
659             }
660 
661             else {
662                 query.append("ORDER BY ");
663 
664                 query.append("pollsQuestion.createDate DESC");
665             }
666 
667             Query q = session.createQuery(query.toString());
668 
669             QueryPos qPos = QueryPos.getInstance(q);
670 
671             if (uuid != null) {
672                 qPos.add(uuid);
673             }
674 
675             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
676                     pollsQuestion);
677 
678             PollsQuestion[] array = new PollsQuestionImpl[3];
679 
680             array[0] = (PollsQuestion)objArray[0];
681             array[1] = (PollsQuestion)objArray[1];
682             array[2] = (PollsQuestion)objArray[2];
683 
684             return array;
685         }
686         catch (Exception e) {
687             throw processException(e);
688         }
689         finally {
690             closeSession(session);
691         }
692     }
693 
694     public PollsQuestion findByUUID_G(String uuid, long groupId)
695         throws NoSuchQuestionException, SystemException {
696         PollsQuestion pollsQuestion = fetchByUUID_G(uuid, groupId);
697 
698         if (pollsQuestion == null) {
699             StringBuilder msg = new StringBuilder();
700 
701             msg.append("No PollsQuestion exists with the key {");
702 
703             msg.append("uuid=" + uuid);
704 
705             msg.append(", ");
706             msg.append("groupId=" + groupId);
707 
708             msg.append(StringPool.CLOSE_CURLY_BRACE);
709 
710             if (_log.isWarnEnabled()) {
711                 _log.warn(msg.toString());
712             }
713 
714             throw new NoSuchQuestionException(msg.toString());
715         }
716 
717         return pollsQuestion;
718     }
719 
720     public PollsQuestion fetchByUUID_G(String uuid, long groupId)
721         throws SystemException {
722         return fetchByUUID_G(uuid, groupId, true);
723     }
724 
725     public PollsQuestion fetchByUUID_G(String uuid, long groupId,
726         boolean retrieveFromCache) throws SystemException {
727         Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
728 
729         Object result = null;
730 
731         if (retrieveFromCache) {
732             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
733                     finderArgs, this);
734         }
735 
736         if (result == null) {
737             Session session = null;
738 
739             try {
740                 session = openSession();
741 
742                 StringBuilder query = new StringBuilder();
743 
744                 query.append(
745                     "SELECT pollsQuestion FROM PollsQuestion pollsQuestion WHERE ");
746 
747                 if (uuid == null) {
748                     query.append("pollsQuestion.uuid IS NULL");
749                 }
750                 else {
751                     query.append("pollsQuestion.uuid = ?");
752                 }
753 
754                 query.append(" AND ");
755 
756                 query.append("pollsQuestion.groupId = ?");
757 
758                 query.append(" ");
759 
760                 query.append("ORDER BY ");
761 
762                 query.append("pollsQuestion.createDate DESC");
763 
764                 Query q = session.createQuery(query.toString());
765 
766                 QueryPos qPos = QueryPos.getInstance(q);
767 
768                 if (uuid != null) {
769                     qPos.add(uuid);
770                 }
771 
772                 qPos.add(groupId);
773 
774                 List<PollsQuestion> list = q.list();
775 
776                 result = list;
777 
778                 PollsQuestion pollsQuestion = null;
779 
780                 if (list.isEmpty()) {
781                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
782                         finderArgs, list);
783                 }
784                 else {
785                     pollsQuestion = list.get(0);
786 
787                     cacheResult(pollsQuestion);
788 
789                     if ((pollsQuestion.getUuid() == null) ||
790                             !pollsQuestion.getUuid().equals(uuid) ||
791                             (pollsQuestion.getGroupId() != groupId)) {
792                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
793                             finderArgs, pollsQuestion);
794                     }
795                 }
796 
797                 return pollsQuestion;
798             }
799             catch (Exception e) {
800                 throw processException(e);
801             }
802             finally {
803                 if (result == null) {
804                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
805                         finderArgs, new ArrayList<PollsQuestion>());
806                 }
807 
808                 closeSession(session);
809             }
810         }
811         else {
812             if (result instanceof List<?>) {
813                 return null;
814             }
815             else {
816                 return (PollsQuestion)result;
817             }
818         }
819     }
820 
821     public List<PollsQuestion> findByGroupId(long groupId)
822         throws SystemException {
823         Object[] finderArgs = new Object[] { new Long(groupId) };
824 
825         List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
826                 finderArgs, this);
827 
828         if (list == null) {
829             Session session = null;
830 
831             try {
832                 session = openSession();
833 
834                 StringBuilder query = new StringBuilder();
835 
836                 query.append(
837                     "SELECT pollsQuestion FROM PollsQuestion pollsQuestion WHERE ");
838 
839                 query.append("pollsQuestion.groupId = ?");
840 
841                 query.append(" ");
842 
843                 query.append("ORDER BY ");
844 
845                 query.append("pollsQuestion.createDate DESC");
846 
847                 Query q = session.createQuery(query.toString());
848 
849                 QueryPos qPos = QueryPos.getInstance(q);
850 
851                 qPos.add(groupId);
852 
853                 list = q.list();
854             }
855             catch (Exception e) {
856                 throw processException(e);
857             }
858             finally {
859                 if (list == null) {
860                     list = new ArrayList<PollsQuestion>();
861                 }
862 
863                 cacheResult(list);
864 
865                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
866                     finderArgs, list);
867 
868                 closeSession(session);
869             }
870         }
871 
872         return list;
873     }
874 
875     public List<PollsQuestion> findByGroupId(long groupId, int start, int end)
876         throws SystemException {
877         return findByGroupId(groupId, start, end, null);
878     }
879 
880     public List<PollsQuestion> findByGroupId(long groupId, int start, int end,
881         OrderByComparator obc) throws SystemException {
882         Object[] finderArgs = new Object[] {
883                 new Long(groupId),
884                 
885                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
886             };
887 
888         List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
889                 finderArgs, this);
890 
891         if (list == null) {
892             Session session = null;
893 
894             try {
895                 session = openSession();
896 
897                 StringBuilder query = new StringBuilder();
898 
899                 query.append(
900                     "SELECT pollsQuestion FROM PollsQuestion pollsQuestion WHERE ");
901 
902                 query.append("pollsQuestion.groupId = ?");
903 
904                 query.append(" ");
905 
906                 if (obc != null) {
907                     query.append("ORDER BY ");
908 
909                     String[] orderByFields = obc.getOrderByFields();
910 
911                     for (int i = 0; i < orderByFields.length; i++) {
912                         query.append("pollsQuestion.");
913                         query.append(orderByFields[i]);
914 
915                         if (obc.isAscending()) {
916                             query.append(" ASC");
917                         }
918                         else {
919                             query.append(" DESC");
920                         }
921 
922                         if ((i + 1) < orderByFields.length) {
923                             query.append(", ");
924                         }
925                     }
926                 }
927 
928                 else {
929                     query.append("ORDER BY ");
930 
931                     query.append("pollsQuestion.createDate DESC");
932                 }
933 
934                 Query q = session.createQuery(query.toString());
935 
936                 QueryPos qPos = QueryPos.getInstance(q);
937 
938                 qPos.add(groupId);
939 
940                 list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
941                         start, end);
942             }
943             catch (Exception e) {
944                 throw processException(e);
945             }
946             finally {
947                 if (list == null) {
948                     list = new ArrayList<PollsQuestion>();
949                 }
950 
951                 cacheResult(list);
952 
953                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
954                     finderArgs, list);
955 
956                 closeSession(session);
957             }
958         }
959 
960         return list;
961     }
962 
963     public PollsQuestion findByGroupId_First(long groupId, OrderByComparator obc)
964         throws NoSuchQuestionException, SystemException {
965         List<PollsQuestion> list = findByGroupId(groupId, 0, 1, obc);
966 
967         if (list.isEmpty()) {
968             StringBuilder msg = new StringBuilder();
969 
970             msg.append("No PollsQuestion exists with the key {");
971 
972             msg.append("groupId=" + groupId);
973 
974             msg.append(StringPool.CLOSE_CURLY_BRACE);
975 
976             throw new NoSuchQuestionException(msg.toString());
977         }
978         else {
979             return list.get(0);
980         }
981     }
982 
983     public PollsQuestion findByGroupId_Last(long groupId, OrderByComparator obc)
984         throws NoSuchQuestionException, SystemException {
985         int count = countByGroupId(groupId);
986 
987         List<PollsQuestion> list = findByGroupId(groupId, count - 1, count, obc);
988 
989         if (list.isEmpty()) {
990             StringBuilder msg = new StringBuilder();
991 
992             msg.append("No PollsQuestion exists with the key {");
993 
994             msg.append("groupId=" + groupId);
995 
996             msg.append(StringPool.CLOSE_CURLY_BRACE);
997 
998             throw new NoSuchQuestionException(msg.toString());
999         }
1000        else {
1001            return list.get(0);
1002        }
1003    }
1004
1005    public PollsQuestion[] findByGroupId_PrevAndNext(long questionId,
1006        long groupId, OrderByComparator obc)
1007        throws NoSuchQuestionException, SystemException {
1008        PollsQuestion pollsQuestion = findByPrimaryKey(questionId);
1009
1010        int count = countByGroupId(groupId);
1011
1012        Session session = null;
1013
1014        try {
1015            session = openSession();
1016
1017            StringBuilder query = new StringBuilder();
1018
1019            query.append(
1020                "SELECT pollsQuestion FROM PollsQuestion pollsQuestion WHERE ");
1021
1022            query.append("pollsQuestion.groupId = ?");
1023
1024            query.append(" ");
1025
1026            if (obc != null) {
1027                query.append("ORDER BY ");
1028
1029                String[] orderByFields = obc.getOrderByFields();
1030
1031                for (int i = 0; i < orderByFields.length; i++) {
1032                    query.append("pollsQuestion.");
1033                    query.append(orderByFields[i]);
1034
1035                    if (obc.isAscending()) {
1036                        query.append(" ASC");
1037                    }
1038                    else {
1039                        query.append(" DESC");
1040                    }
1041
1042                    if ((i + 1) < orderByFields.length) {
1043                        query.append(", ");
1044                    }
1045                }
1046            }
1047
1048            else {
1049                query.append("ORDER BY ");
1050
1051                query.append("pollsQuestion.createDate DESC");
1052            }
1053
1054            Query q = session.createQuery(query.toString());
1055
1056            QueryPos qPos = QueryPos.getInstance(q);
1057
1058            qPos.add(groupId);
1059
1060            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1061                    pollsQuestion);
1062
1063            PollsQuestion[] array = new PollsQuestionImpl[3];
1064
1065            array[0] = (PollsQuestion)objArray[0];
1066            array[1] = (PollsQuestion)objArray[1];
1067            array[2] = (PollsQuestion)objArray[2];
1068
1069            return array;
1070        }
1071        catch (Exception e) {
1072            throw processException(e);
1073        }
1074        finally {
1075            closeSession(session);
1076        }
1077    }
1078
1079    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1080        throws SystemException {
1081        Session session = null;
1082
1083        try {
1084            session = openSession();
1085
1086            dynamicQuery.compile(session);
1087
1088            return dynamicQuery.list();
1089        }
1090        catch (Exception e) {
1091            throw processException(e);
1092        }
1093        finally {
1094            closeSession(session);
1095        }
1096    }
1097
1098    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1099        int start, int end) throws SystemException {
1100        Session session = null;
1101
1102        try {
1103            session = openSession();
1104
1105            dynamicQuery.setLimit(start, end);
1106
1107            dynamicQuery.compile(session);
1108
1109            return dynamicQuery.list();
1110        }
1111        catch (Exception e) {
1112            throw processException(e);
1113        }
1114        finally {
1115            closeSession(session);
1116        }
1117    }
1118
1119    public List<PollsQuestion> findAll() throws SystemException {
1120        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1121    }
1122
1123    public List<PollsQuestion> findAll(int start, int end)
1124        throws SystemException {
1125        return findAll(start, end, null);
1126    }
1127
1128    public List<PollsQuestion> findAll(int start, int end, OrderByComparator obc)
1129        throws SystemException {
1130        Object[] finderArgs = new Object[] {
1131                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1132            };
1133
1134        List<PollsQuestion> list = (List<PollsQuestion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1135                finderArgs, this);
1136
1137        if (list == null) {
1138            Session session = null;
1139
1140            try {
1141                session = openSession();
1142
1143                StringBuilder query = new StringBuilder();
1144
1145                query.append(
1146                    "SELECT pollsQuestion FROM PollsQuestion pollsQuestion ");
1147
1148                if (obc != null) {
1149                    query.append("ORDER BY ");
1150
1151                    String[] orderByFields = obc.getOrderByFields();
1152
1153                    for (int i = 0; i < orderByFields.length; i++) {
1154                        query.append("pollsQuestion.");
1155                        query.append(orderByFields[i]);
1156
1157                        if (obc.isAscending()) {
1158                            query.append(" ASC");
1159                        }
1160                        else {
1161                            query.append(" DESC");
1162                        }
1163
1164                        if ((i + 1) < orderByFields.length) {
1165                            query.append(", ");
1166                        }
1167                    }
1168                }
1169
1170                else {
1171                    query.append("ORDER BY ");
1172
1173                    query.append("pollsQuestion.createDate DESC");
1174                }
1175
1176                Query q = session.createQuery(query.toString());
1177
1178                if (obc == null) {
1179                    list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
1180                            start, end, false);
1181
1182                    Collections.sort(list);
1183                }
1184                else {
1185                    list = (List<PollsQuestion>)QueryUtil.list(q, getDialect(),
1186                            start, end);
1187                }
1188            }
1189            catch (Exception e) {
1190                throw processException(e);
1191            }
1192            finally {
1193                if (list == null) {
1194                    list = new ArrayList<PollsQuestion>();
1195                }
1196
1197                cacheResult(list);
1198
1199                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1200
1201                closeSession(session);
1202            }
1203        }
1204
1205        return list;
1206    }
1207
1208    public void removeByUuid(String uuid) throws SystemException {
1209        for (PollsQuestion pollsQuestion : findByUuid(uuid)) {
1210            remove(pollsQuestion);
1211        }
1212    }
1213
1214    public void removeByUUID_G(String uuid, long groupId)
1215        throws NoSuchQuestionException, SystemException {
1216        PollsQuestion pollsQuestion = findByUUID_G(uuid, groupId);
1217
1218        remove(pollsQuestion);
1219    }
1220
1221    public void removeByGroupId(long groupId) throws SystemException {
1222        for (PollsQuestion pollsQuestion : findByGroupId(groupId)) {
1223            remove(pollsQuestion);
1224        }
1225    }
1226
1227    public void removeAll() throws SystemException {
1228        for (PollsQuestion pollsQuestion : findAll()) {
1229            remove(pollsQuestion);
1230        }
1231    }
1232
1233    public int countByUuid(String uuid) throws SystemException {
1234        Object[] finderArgs = new Object[] { uuid };
1235
1236        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1237                finderArgs, this);
1238
1239        if (count == null) {
1240            Session session = null;
1241
1242            try {
1243                session = openSession();
1244
1245                StringBuilder query = new StringBuilder();
1246
1247                query.append("SELECT COUNT(pollsQuestion) ");
1248                query.append("FROM PollsQuestion pollsQuestion WHERE ");
1249
1250                if (uuid == null) {
1251                    query.append("pollsQuestion.uuid IS NULL");
1252                }
1253                else {
1254                    query.append("pollsQuestion.uuid = ?");
1255                }
1256
1257                query.append(" ");
1258
1259                Query q = session.createQuery(query.toString());
1260
1261                QueryPos qPos = QueryPos.getInstance(q);
1262
1263                if (uuid != null) {
1264                    qPos.add(uuid);
1265                }
1266
1267                count = (Long)q.uniqueResult();
1268            }
1269            catch (Exception e) {
1270                throw processException(e);
1271            }
1272            finally {
1273                if (count == null) {
1274                    count = Long.valueOf(0);
1275                }
1276
1277                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1278                    finderArgs, count);
1279
1280                closeSession(session);
1281            }
1282        }
1283
1284        return count.intValue();
1285    }
1286
1287    public int countByUUID_G(String uuid, long groupId)
1288        throws SystemException {
1289        Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
1290
1291        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
1292                finderArgs, this);
1293
1294        if (count == null) {
1295            Session session = null;
1296
1297            try {
1298                session = openSession();
1299
1300                StringBuilder query = new StringBuilder();
1301
1302                query.append("SELECT COUNT(pollsQuestion) ");
1303                query.append("FROM PollsQuestion pollsQuestion WHERE ");
1304
1305                if (uuid == null) {
1306                    query.append("pollsQuestion.uuid IS NULL");
1307                }
1308                else {
1309                    query.append("pollsQuestion.uuid = ?");
1310                }
1311
1312                query.append(" AND ");
1313
1314                query.append("pollsQuestion.groupId = ?");
1315
1316                query.append(" ");
1317
1318                Query q = session.createQuery(query.toString());
1319
1320                QueryPos qPos = QueryPos.getInstance(q);
1321
1322                if (uuid != null) {
1323                    qPos.add(uuid);
1324                }
1325
1326                qPos.add(groupId);
1327
1328                count = (Long)q.uniqueResult();
1329            }
1330            catch (Exception e) {
1331                throw processException(e);
1332            }
1333            finally {
1334                if (count == null) {
1335                    count = Long.valueOf(0);
1336                }
1337
1338                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
1339                    finderArgs, count);
1340
1341                closeSession(session);
1342            }
1343        }
1344
1345        return count.intValue();
1346    }
1347
1348    public int countByGroupId(long groupId) throws SystemException {
1349        Object[] finderArgs = new Object[] { new Long(groupId) };
1350
1351        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1352                finderArgs, this);
1353
1354        if (count == null) {
1355            Session session = null;
1356
1357            try {
1358                session = openSession();
1359
1360                StringBuilder query = new StringBuilder();
1361
1362                query.append("SELECT COUNT(pollsQuestion) ");
1363                query.append("FROM PollsQuestion pollsQuestion WHERE ");
1364
1365                query.append("pollsQuestion.groupId = ?");
1366
1367                query.append(" ");
1368
1369                Query q = session.createQuery(query.toString());
1370
1371                QueryPos qPos = QueryPos.getInstance(q);
1372
1373                qPos.add(groupId);
1374
1375                count = (Long)q.uniqueResult();
1376            }
1377            catch (Exception e) {
1378                throw processException(e);
1379            }
1380            finally {
1381                if (count == null) {
1382                    count = Long.valueOf(0);
1383                }
1384
1385                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1386                    finderArgs, count);
1387
1388                closeSession(session);
1389            }
1390        }
1391
1392        return count.intValue();
1393    }
1394
1395    public int countAll() throws SystemException {
1396        Object[] finderArgs = new Object[0];
1397
1398        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1399                finderArgs, this);
1400
1401        if (count == null) {
1402            Session session = null;
1403
1404            try {
1405                session = openSession();
1406
1407                Query q = session.createQuery(
1408                        "SELECT COUNT(pollsQuestion) FROM PollsQuestion pollsQuestion");
1409
1410                count = (Long)q.uniqueResult();
1411            }
1412            catch (Exception e) {
1413                throw processException(e);
1414            }
1415            finally {
1416                if (count == null) {
1417                    count = Long.valueOf(0);
1418                }
1419
1420                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1421                    count);
1422
1423                closeSession(session);
1424            }
1425        }
1426
1427        return count.intValue();
1428    }
1429
1430    public void afterPropertiesSet() {
1431        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1432                    com.liferay.portal.util.PropsUtil.get(
1433                        "value.object.listener.com.liferay.portlet.polls.model.PollsQuestion")));
1434
1435        if (listenerClassNames.length > 0) {
1436            try {
1437                List<ModelListener<PollsQuestion>> listenersList = new ArrayList<ModelListener<PollsQuestion>>();
1438
1439                for (String listenerClassName : listenerClassNames) {
1440                    listenersList.add((ModelListener<PollsQuestion>)Class.forName(
1441                            listenerClassName).newInstance());
1442                }
1443
1444                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1445            }
1446            catch (Exception e) {
1447                _log.error(e);
1448            }
1449        }
1450    }
1451
1452    @BeanReference(name = "com.liferay.portlet.polls.service.persistence.PollsChoicePersistence.impl")
1453    protected com.liferay.portlet.polls.service.persistence.PollsChoicePersistence pollsChoicePersistence;
1454    @BeanReference(name = "com.liferay.portlet.polls.service.persistence.PollsQuestionPersistence.impl")
1455    protected com.liferay.portlet.polls.service.persistence.PollsQuestionPersistence pollsQuestionPersistence;
1456    @BeanReference(name = "com.liferay.portlet.polls.service.persistence.PollsVotePersistence.impl")
1457    protected com.liferay.portlet.polls.service.persistence.PollsVotePersistence pollsVotePersistence;
1458    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
1459    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1460    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1461    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1462    private static Log _log = LogFactoryUtil.getLog(PollsQuestionPersistenceImpl.class);
1463}