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