1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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.NoSuchPasswordTrackerException;
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.model.ModelListener;
44  import com.liferay.portal.model.PasswordTracker;
45  import com.liferay.portal.model.impl.PasswordTrackerImpl;
46  import com.liferay.portal.model.impl.PasswordTrackerModelImpl;
47  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
48  
49  import java.util.ArrayList;
50  import java.util.Collections;
51  import java.util.List;
52  
53  /**
54   * <a href="PasswordTrackerPersistenceImpl.java.html"><b><i>View Source</i></b></a>
55   *
56   * @author Brian Wing Shun Chan
57   *
58   */
59  public class PasswordTrackerPersistenceImpl extends BasePersistenceImpl
60      implements PasswordTrackerPersistence {
61      public static final String FINDER_CLASS_NAME_ENTITY = PasswordTrackerImpl.class.getName();
62      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
63          ".List";
64      public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
65              PasswordTrackerModelImpl.FINDER_CACHE_ENABLED,
66              FINDER_CLASS_NAME_LIST, "findByUserId",
67              new String[] { Long.class.getName() });
68      public static final FinderPath FINDER_PATH_FIND_BY_OBC_USERID = new FinderPath(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
69              PasswordTrackerModelImpl.FINDER_CACHE_ENABLED,
70              FINDER_CLASS_NAME_LIST, "findByUserId",
71              new String[] {
72                  Long.class.getName(),
73                  
74              "java.lang.Integer", "java.lang.Integer",
75                  "com.liferay.portal.kernel.util.OrderByComparator"
76              });
77      public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
78              PasswordTrackerModelImpl.FINDER_CACHE_ENABLED,
79              FINDER_CLASS_NAME_LIST, "countByUserId",
80              new String[] { Long.class.getName() });
81      public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
82              PasswordTrackerModelImpl.FINDER_CACHE_ENABLED,
83              FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
84      public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
85              PasswordTrackerModelImpl.FINDER_CACHE_ENABLED,
86              FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
87  
88      public void cacheResult(PasswordTracker passwordTracker) {
89          EntityCacheUtil.putResult(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
90              PasswordTrackerImpl.class, passwordTracker.getPrimaryKey(),
91              passwordTracker);
92      }
93  
94      public void cacheResult(List<PasswordTracker> passwordTrackers) {
95          for (PasswordTracker passwordTracker : passwordTrackers) {
96              if (EntityCacheUtil.getResult(
97                          PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
98                          PasswordTrackerImpl.class,
99                          passwordTracker.getPrimaryKey(), this) == null) {
100                 cacheResult(passwordTracker);
101             }
102         }
103     }
104 
105     public void clearCache() {
106         CacheRegistry.clear(PasswordTrackerImpl.class.getName());
107         EntityCacheUtil.clearCache(PasswordTrackerImpl.class.getName());
108         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
109         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
110     }
111 
112     public PasswordTracker create(long passwordTrackerId) {
113         PasswordTracker passwordTracker = new PasswordTrackerImpl();
114 
115         passwordTracker.setNew(true);
116         passwordTracker.setPrimaryKey(passwordTrackerId);
117 
118         return passwordTracker;
119     }
120 
121     public PasswordTracker remove(long passwordTrackerId)
122         throws NoSuchPasswordTrackerException, SystemException {
123         Session session = null;
124 
125         try {
126             session = openSession();
127 
128             PasswordTracker passwordTracker = (PasswordTracker)session.get(PasswordTrackerImpl.class,
129                     new Long(passwordTrackerId));
130 
131             if (passwordTracker == null) {
132                 if (_log.isWarnEnabled()) {
133                     _log.warn("No PasswordTracker exists with the primary key " +
134                         passwordTrackerId);
135                 }
136 
137                 throw new NoSuchPasswordTrackerException(
138                     "No PasswordTracker exists with the primary key " +
139                     passwordTrackerId);
140             }
141 
142             return remove(passwordTracker);
143         }
144         catch (NoSuchPasswordTrackerException nsee) {
145             throw nsee;
146         }
147         catch (Exception e) {
148             throw processException(e);
149         }
150         finally {
151             closeSession(session);
152         }
153     }
154 
155     public PasswordTracker remove(PasswordTracker passwordTracker)
156         throws SystemException {
157         for (ModelListener<PasswordTracker> listener : listeners) {
158             listener.onBeforeRemove(passwordTracker);
159         }
160 
161         passwordTracker = removeImpl(passwordTracker);
162 
163         for (ModelListener<PasswordTracker> listener : listeners) {
164             listener.onAfterRemove(passwordTracker);
165         }
166 
167         return passwordTracker;
168     }
169 
170     protected PasswordTracker removeImpl(PasswordTracker passwordTracker)
171         throws SystemException {
172         Session session = null;
173 
174         try {
175             session = openSession();
176 
177             if (passwordTracker.isCachedModel() ||
178                     BatchSessionUtil.isEnabled()) {
179                 Object staleObject = session.get(PasswordTrackerImpl.class,
180                         passwordTracker.getPrimaryKeyObj());
181 
182                 if (staleObject != null) {
183                     session.evict(staleObject);
184                 }
185             }
186 
187             session.delete(passwordTracker);
188 
189             session.flush();
190         }
191         catch (Exception e) {
192             throw processException(e);
193         }
194         finally {
195             closeSession(session);
196         }
197 
198         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
199 
200         EntityCacheUtil.removeResult(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
201             PasswordTrackerImpl.class, passwordTracker.getPrimaryKey());
202 
203         return passwordTracker;
204     }
205 
206     /**
207      * @deprecated Use <code>update(PasswordTracker passwordTracker, boolean merge)</code>.
208      */
209     public PasswordTracker update(PasswordTracker passwordTracker)
210         throws SystemException {
211         if (_log.isWarnEnabled()) {
212             _log.warn(
213                 "Using the deprecated update(PasswordTracker passwordTracker) method. Use update(PasswordTracker passwordTracker, boolean merge) instead.");
214         }
215 
216         return update(passwordTracker, false);
217     }
218 
219     /**
220      * Add, update, or merge, the entity. This method also calls the model
221      * listeners to trigger the proper events associated with adding, deleting,
222      * or updating an entity.
223      *
224      * @param        passwordTracker the entity to add, update, or merge
225      * @param        merge boolean value for whether to merge the entity. The
226      *                default value is false. Setting merge to true is more
227      *                expensive and should only be true when passwordTracker is
228      *                transient. See LEP-5473 for a detailed discussion of this
229      *                method.
230      * @return        true if the portlet can be displayed via Ajax
231      */
232     public PasswordTracker update(PasswordTracker passwordTracker, boolean merge)
233         throws SystemException {
234         boolean isNew = passwordTracker.isNew();
235 
236         for (ModelListener<PasswordTracker> listener : listeners) {
237             if (isNew) {
238                 listener.onBeforeCreate(passwordTracker);
239             }
240             else {
241                 listener.onBeforeUpdate(passwordTracker);
242             }
243         }
244 
245         passwordTracker = updateImpl(passwordTracker, merge);
246 
247         for (ModelListener<PasswordTracker> listener : listeners) {
248             if (isNew) {
249                 listener.onAfterCreate(passwordTracker);
250             }
251             else {
252                 listener.onAfterUpdate(passwordTracker);
253             }
254         }
255 
256         return passwordTracker;
257     }
258 
259     public PasswordTracker updateImpl(
260         com.liferay.portal.model.PasswordTracker passwordTracker, boolean merge)
261         throws SystemException {
262         Session session = null;
263 
264         try {
265             session = openSession();
266 
267             BatchSessionUtil.update(session, passwordTracker, merge);
268 
269             passwordTracker.setNew(false);
270         }
271         catch (Exception e) {
272             throw processException(e);
273         }
274         finally {
275             closeSession(session);
276         }
277 
278         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
279 
280         EntityCacheUtil.putResult(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
281             PasswordTrackerImpl.class, passwordTracker.getPrimaryKey(),
282             passwordTracker);
283 
284         return passwordTracker;
285     }
286 
287     public PasswordTracker findByPrimaryKey(long passwordTrackerId)
288         throws NoSuchPasswordTrackerException, SystemException {
289         PasswordTracker passwordTracker = fetchByPrimaryKey(passwordTrackerId);
290 
291         if (passwordTracker == null) {
292             if (_log.isWarnEnabled()) {
293                 _log.warn("No PasswordTracker exists with the primary key " +
294                     passwordTrackerId);
295             }
296 
297             throw new NoSuchPasswordTrackerException(
298                 "No PasswordTracker exists with the primary key " +
299                 passwordTrackerId);
300         }
301 
302         return passwordTracker;
303     }
304 
305     public PasswordTracker fetchByPrimaryKey(long passwordTrackerId)
306         throws SystemException {
307         PasswordTracker passwordTracker = (PasswordTracker)EntityCacheUtil.getResult(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
308                 PasswordTrackerImpl.class, passwordTrackerId, this);
309 
310         if (passwordTracker == null) {
311             Session session = null;
312 
313             try {
314                 session = openSession();
315 
316                 passwordTracker = (PasswordTracker)session.get(PasswordTrackerImpl.class,
317                         new Long(passwordTrackerId));
318             }
319             catch (Exception e) {
320                 throw processException(e);
321             }
322             finally {
323                 if (passwordTracker != null) {
324                     cacheResult(passwordTracker);
325                 }
326 
327                 closeSession(session);
328             }
329         }
330 
331         return passwordTracker;
332     }
333 
334     public List<PasswordTracker> findByUserId(long userId)
335         throws SystemException {
336         Object[] finderArgs = new Object[] { new Long(userId) };
337 
338         List<PasswordTracker> list = (List<PasswordTracker>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
339                 finderArgs, this);
340 
341         if (list == null) {
342             Session session = null;
343 
344             try {
345                 session = openSession();
346 
347                 StringBuilder query = new StringBuilder();
348 
349                 query.append(
350                     "SELECT passwordTracker FROM PasswordTracker passwordTracker WHERE ");
351 
352                 query.append("passwordTracker.userId = ?");
353 
354                 query.append(" ");
355 
356                 query.append("ORDER BY ");
357 
358                 query.append("passwordTracker.userId DESC, ");
359                 query.append("passwordTracker.createDate DESC");
360 
361                 Query q = session.createQuery(query.toString());
362 
363                 QueryPos qPos = QueryPos.getInstance(q);
364 
365                 qPos.add(userId);
366 
367                 list = q.list();
368             }
369             catch (Exception e) {
370                 throw processException(e);
371             }
372             finally {
373                 if (list == null) {
374                     list = new ArrayList<PasswordTracker>();
375                 }
376 
377                 cacheResult(list);
378 
379                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
380                     finderArgs, list);
381 
382                 closeSession(session);
383             }
384         }
385 
386         return list;
387     }
388 
389     public List<PasswordTracker> findByUserId(long userId, int start, int end)
390         throws SystemException {
391         return findByUserId(userId, start, end, null);
392     }
393 
394     public List<PasswordTracker> findByUserId(long userId, int start, int end,
395         OrderByComparator obc) throws SystemException {
396         Object[] finderArgs = new Object[] {
397                 new Long(userId),
398                 
399                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
400             };
401 
402         List<PasswordTracker> list = (List<PasswordTracker>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_USERID,
403                 finderArgs, this);
404 
405         if (list == null) {
406             Session session = null;
407 
408             try {
409                 session = openSession();
410 
411                 StringBuilder query = new StringBuilder();
412 
413                 query.append(
414                     "SELECT passwordTracker FROM PasswordTracker passwordTracker WHERE ");
415 
416                 query.append("passwordTracker.userId = ?");
417 
418                 query.append(" ");
419 
420                 if (obc != null) {
421                     query.append("ORDER BY ");
422 
423                     String[] orderByFields = obc.getOrderByFields();
424 
425                     for (int i = 0; i < orderByFields.length; i++) {
426                         query.append("passwordTracker.");
427                         query.append(orderByFields[i]);
428 
429                         if (obc.isAscending()) {
430                             query.append(" ASC");
431                         }
432                         else {
433                             query.append(" DESC");
434                         }
435 
436                         if ((i + 1) < orderByFields.length) {
437                             query.append(", ");
438                         }
439                     }
440                 }
441 
442                 else {
443                     query.append("ORDER BY ");
444 
445                     query.append("passwordTracker.userId DESC, ");
446                     query.append("passwordTracker.createDate DESC");
447                 }
448 
449                 Query q = session.createQuery(query.toString());
450 
451                 QueryPos qPos = QueryPos.getInstance(q);
452 
453                 qPos.add(userId);
454 
455                 list = (List<PasswordTracker>)QueryUtil.list(q, getDialect(),
456                         start, end);
457             }
458             catch (Exception e) {
459                 throw processException(e);
460             }
461             finally {
462                 if (list == null) {
463                     list = new ArrayList<PasswordTracker>();
464                 }
465 
466                 cacheResult(list);
467 
468                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_USERID,
469                     finderArgs, list);
470 
471                 closeSession(session);
472             }
473         }
474 
475         return list;
476     }
477 
478     public PasswordTracker findByUserId_First(long userId, OrderByComparator obc)
479         throws NoSuchPasswordTrackerException, SystemException {
480         List<PasswordTracker> list = findByUserId(userId, 0, 1, obc);
481 
482         if (list.isEmpty()) {
483             StringBuilder msg = new StringBuilder();
484 
485             msg.append("No PasswordTracker exists with the key {");
486 
487             msg.append("userId=" + userId);
488 
489             msg.append(StringPool.CLOSE_CURLY_BRACE);
490 
491             throw new NoSuchPasswordTrackerException(msg.toString());
492         }
493         else {
494             return list.get(0);
495         }
496     }
497 
498     public PasswordTracker findByUserId_Last(long userId, OrderByComparator obc)
499         throws NoSuchPasswordTrackerException, SystemException {
500         int count = countByUserId(userId);
501 
502         List<PasswordTracker> list = findByUserId(userId, count - 1, count, obc);
503 
504         if (list.isEmpty()) {
505             StringBuilder msg = new StringBuilder();
506 
507             msg.append("No PasswordTracker exists with the key {");
508 
509             msg.append("userId=" + userId);
510 
511             msg.append(StringPool.CLOSE_CURLY_BRACE);
512 
513             throw new NoSuchPasswordTrackerException(msg.toString());
514         }
515         else {
516             return list.get(0);
517         }
518     }
519 
520     public PasswordTracker[] findByUserId_PrevAndNext(long passwordTrackerId,
521         long userId, OrderByComparator obc)
522         throws NoSuchPasswordTrackerException, SystemException {
523         PasswordTracker passwordTracker = findByPrimaryKey(passwordTrackerId);
524 
525         int count = countByUserId(userId);
526 
527         Session session = null;
528 
529         try {
530             session = openSession();
531 
532             StringBuilder query = new StringBuilder();
533 
534             query.append(
535                 "SELECT passwordTracker FROM PasswordTracker passwordTracker WHERE ");
536 
537             query.append("passwordTracker.userId = ?");
538 
539             query.append(" ");
540 
541             if (obc != null) {
542                 query.append("ORDER BY ");
543 
544                 String[] orderByFields = obc.getOrderByFields();
545 
546                 for (int i = 0; i < orderByFields.length; i++) {
547                     query.append("passwordTracker.");
548                     query.append(orderByFields[i]);
549 
550                     if (obc.isAscending()) {
551                         query.append(" ASC");
552                     }
553                     else {
554                         query.append(" DESC");
555                     }
556 
557                     if ((i + 1) < orderByFields.length) {
558                         query.append(", ");
559                     }
560                 }
561             }
562 
563             else {
564                 query.append("ORDER BY ");
565 
566                 query.append("passwordTracker.userId DESC, ");
567                 query.append("passwordTracker.createDate DESC");
568             }
569 
570             Query q = session.createQuery(query.toString());
571 
572             QueryPos qPos = QueryPos.getInstance(q);
573 
574             qPos.add(userId);
575 
576             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
577                     passwordTracker);
578 
579             PasswordTracker[] array = new PasswordTrackerImpl[3];
580 
581             array[0] = (PasswordTracker)objArray[0];
582             array[1] = (PasswordTracker)objArray[1];
583             array[2] = (PasswordTracker)objArray[2];
584 
585             return array;
586         }
587         catch (Exception e) {
588             throw processException(e);
589         }
590         finally {
591             closeSession(session);
592         }
593     }
594 
595     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
596         throws SystemException {
597         Session session = null;
598 
599         try {
600             session = openSession();
601 
602             dynamicQuery.compile(session);
603 
604             return dynamicQuery.list();
605         }
606         catch (Exception e) {
607             throw processException(e);
608         }
609         finally {
610             closeSession(session);
611         }
612     }
613 
614     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
615         int start, int end) throws SystemException {
616         Session session = null;
617 
618         try {
619             session = openSession();
620 
621             dynamicQuery.setLimit(start, end);
622 
623             dynamicQuery.compile(session);
624 
625             return dynamicQuery.list();
626         }
627         catch (Exception e) {
628             throw processException(e);
629         }
630         finally {
631             closeSession(session);
632         }
633     }
634 
635     public List<PasswordTracker> findAll() throws SystemException {
636         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
637     }
638 
639     public List<PasswordTracker> findAll(int start, int end)
640         throws SystemException {
641         return findAll(start, end, null);
642     }
643 
644     public List<PasswordTracker> findAll(int start, int end,
645         OrderByComparator obc) throws SystemException {
646         Object[] finderArgs = new Object[] {
647                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
648             };
649 
650         List<PasswordTracker> list = (List<PasswordTracker>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
651                 finderArgs, this);
652 
653         if (list == null) {
654             Session session = null;
655 
656             try {
657                 session = openSession();
658 
659                 StringBuilder query = new StringBuilder();
660 
661                 query.append(
662                     "SELECT passwordTracker FROM PasswordTracker passwordTracker ");
663 
664                 if (obc != null) {
665                     query.append("ORDER BY ");
666 
667                     String[] orderByFields = obc.getOrderByFields();
668 
669                     for (int i = 0; i < orderByFields.length; i++) {
670                         query.append("passwordTracker.");
671                         query.append(orderByFields[i]);
672 
673                         if (obc.isAscending()) {
674                             query.append(" ASC");
675                         }
676                         else {
677                             query.append(" DESC");
678                         }
679 
680                         if ((i + 1) < orderByFields.length) {
681                             query.append(", ");
682                         }
683                     }
684                 }
685 
686                 else {
687                     query.append("ORDER BY ");
688 
689                     query.append("passwordTracker.userId DESC, ");
690                     query.append("passwordTracker.createDate DESC");
691                 }
692 
693                 Query q = session.createQuery(query.toString());
694 
695                 if (obc == null) {
696                     list = (List<PasswordTracker>)QueryUtil.list(q,
697                             getDialect(), start, end, false);
698 
699                     Collections.sort(list);
700                 }
701                 else {
702                     list = (List<PasswordTracker>)QueryUtil.list(q,
703                             getDialect(), start, end);
704                 }
705             }
706             catch (Exception e) {
707                 throw processException(e);
708             }
709             finally {
710                 if (list == null) {
711                     list = new ArrayList<PasswordTracker>();
712                 }
713 
714                 cacheResult(list);
715 
716                 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
717 
718                 closeSession(session);
719             }
720         }
721 
722         return list;
723     }
724 
725     public void removeByUserId(long userId) throws SystemException {
726         for (PasswordTracker passwordTracker : findByUserId(userId)) {
727             remove(passwordTracker);
728         }
729     }
730 
731     public void removeAll() throws SystemException {
732         for (PasswordTracker passwordTracker : findAll()) {
733             remove(passwordTracker);
734         }
735     }
736 
737     public int countByUserId(long userId) throws SystemException {
738         Object[] finderArgs = new Object[] { new Long(userId) };
739 
740         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
741                 finderArgs, this);
742 
743         if (count == null) {
744             Session session = null;
745 
746             try {
747                 session = openSession();
748 
749                 StringBuilder query = new StringBuilder();
750 
751                 query.append("SELECT COUNT(passwordTracker) ");
752                 query.append("FROM PasswordTracker passwordTracker WHERE ");
753 
754                 query.append("passwordTracker.userId = ?");
755 
756                 query.append(" ");
757 
758                 Query q = session.createQuery(query.toString());
759 
760                 QueryPos qPos = QueryPos.getInstance(q);
761 
762                 qPos.add(userId);
763 
764                 count = (Long)q.uniqueResult();
765             }
766             catch (Exception e) {
767                 throw processException(e);
768             }
769             finally {
770                 if (count == null) {
771                     count = Long.valueOf(0);
772                 }
773 
774                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
775                     finderArgs, count);
776 
777                 closeSession(session);
778             }
779         }
780 
781         return count.intValue();
782     }
783 
784     public int countAll() throws SystemException {
785         Object[] finderArgs = new Object[0];
786 
787         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
788                 finderArgs, this);
789 
790         if (count == null) {
791             Session session = null;
792 
793             try {
794                 session = openSession();
795 
796                 Query q = session.createQuery(
797                         "SELECT COUNT(passwordTracker) FROM PasswordTracker passwordTracker");
798 
799                 count = (Long)q.uniqueResult();
800             }
801             catch (Exception e) {
802                 throw processException(e);
803             }
804             finally {
805                 if (count == null) {
806                     count = Long.valueOf(0);
807                 }
808 
809                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
810                     count);
811 
812                 closeSession(session);
813             }
814         }
815 
816         return count.intValue();
817     }
818 
819     public void afterPropertiesSet() {
820         String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
821                     com.liferay.portal.util.PropsUtil.get(
822                         "value.object.listener.com.liferay.portal.model.PasswordTracker")));
823 
824         if (listenerClassNames.length > 0) {
825             try {
826                 List<ModelListener<PasswordTracker>> listenersList = new ArrayList<ModelListener<PasswordTracker>>();
827 
828                 for (String listenerClassName : listenerClassNames) {
829                     listenersList.add((ModelListener<PasswordTracker>)Class.forName(
830                             listenerClassName).newInstance());
831                 }
832 
833                 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
834             }
835             catch (Exception e) {
836                 _log.error(e);
837             }
838         }
839     }
840 
841     @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence.impl")
842     protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
843     @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence.impl")
844     protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
845     @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence.impl")
846     protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
847     @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence.impl")
848     protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
849     @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
850     protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
851     @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence.impl")
852     protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
853     @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence.impl")
854     protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
855     @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence.impl")
856     protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
857     @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
858     protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
859     @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
860     protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
861     @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence.impl")
862     protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
863     @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence.impl")
864     protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
865     @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence.impl")
866     protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
867     @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence.impl")
868     protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
869     @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence.impl")
870     protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
871     @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence.impl")
872     protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
873     @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence.impl")
874     protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
875     @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence.impl")
876     protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
877     @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence.impl")
878     protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
879     @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence.impl")
880     protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
881     @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence.impl")
882     protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
883     @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence.impl")
884     protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
885     @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence.impl")
886     protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
887     @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence.impl")
888     protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
889     @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence.impl")
890     protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
891     @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence.impl")
892     protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
893     @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence.impl")
894     protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
895     @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence.impl")
896     protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
897     @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence.impl")
898     protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
899     @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
900     protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
901     @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence.impl")
902     protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
903     @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence.impl")
904     protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
905     @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence.impl")
906     protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
907     @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence.impl")
908     protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
909     @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence.impl")
910     protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
911     @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence.impl")
912     protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
913     @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
914     protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
915     @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
916     protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
917     @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence.impl")
918     protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
919     @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence.impl")
920     protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
921     @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence.impl")
922     protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
923     @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence.impl")
924     protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
925     @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence.impl")
926     protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
927     @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence.impl")
928     protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
929     @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence.impl")
930     protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
931     private static Log _log = LogFactoryUtil.getLog(PasswordTrackerPersistenceImpl.class);
932 }