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