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         passwordTracker = toUnwrappedModel(passwordTracker);
180 
181         Session session = null;
182 
183         try {
184             session = openSession();
185 
186             if (passwordTracker.isCachedModel() ||
187                     BatchSessionUtil.isEnabled()) {
188                 Object staleObject = session.get(PasswordTrackerImpl.class,
189                         passwordTracker.getPrimaryKeyObj());
190 
191                 if (staleObject != null) {
192                     session.evict(staleObject);
193                 }
194             }
195 
196             session.delete(passwordTracker);
197 
198             session.flush();
199         }
200         catch (Exception e) {
201             throw processException(e);
202         }
203         finally {
204             closeSession(session);
205         }
206 
207         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
208 
209         EntityCacheUtil.removeResult(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
210             PasswordTrackerImpl.class, passwordTracker.getPrimaryKey());
211 
212         return passwordTracker;
213     }
214 
215     /**
216      * @deprecated Use {@link #update(PasswordTracker, boolean merge)}.
217      */
218     public PasswordTracker update(PasswordTracker passwordTracker)
219         throws SystemException {
220         if (_log.isWarnEnabled()) {
221             _log.warn(
222                 "Using the deprecated update(PasswordTracker passwordTracker) method. Use update(PasswordTracker passwordTracker, boolean merge) instead.");
223         }
224 
225         return update(passwordTracker, false);
226     }
227 
228     /**
229      * Add, update, or merge, the entity. This method also calls the model
230      * listeners to trigger the proper events associated with adding, deleting,
231      * or updating an entity.
232      *
233      * @param  passwordTracker the entity to add, update, or merge
234      * @param  merge boolean value for whether to merge the entity. The default
235      *         value is false. Setting merge to true is more expensive and
236      *         should only be true when passwordTracker is transient. See
237      *         LEP-5473 for a detailed discussion of this method.
238      * @return the entity that was added, updated, or merged
239      */
240     public PasswordTracker update(PasswordTracker passwordTracker, boolean merge)
241         throws SystemException {
242         boolean isNew = passwordTracker.isNew();
243 
244         for (ModelListener<PasswordTracker> listener : listeners) {
245             if (isNew) {
246                 listener.onBeforeCreate(passwordTracker);
247             }
248             else {
249                 listener.onBeforeUpdate(passwordTracker);
250             }
251         }
252 
253         passwordTracker = updateImpl(passwordTracker, merge);
254 
255         for (ModelListener<PasswordTracker> listener : listeners) {
256             if (isNew) {
257                 listener.onAfterCreate(passwordTracker);
258             }
259             else {
260                 listener.onAfterUpdate(passwordTracker);
261             }
262         }
263 
264         return passwordTracker;
265     }
266 
267     public PasswordTracker updateImpl(
268         com.liferay.portal.model.PasswordTracker passwordTracker, boolean merge)
269         throws SystemException {
270         passwordTracker = toUnwrappedModel(passwordTracker);
271 
272         Session session = null;
273 
274         try {
275             session = openSession();
276 
277             BatchSessionUtil.update(session, passwordTracker, merge);
278 
279             passwordTracker.setNew(false);
280         }
281         catch (Exception e) {
282             throw processException(e);
283         }
284         finally {
285             closeSession(session);
286         }
287 
288         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
289 
290         EntityCacheUtil.putResult(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
291             PasswordTrackerImpl.class, passwordTracker.getPrimaryKey(),
292             passwordTracker);
293 
294         return passwordTracker;
295     }
296 
297     protected PasswordTracker toUnwrappedModel(PasswordTracker passwordTracker) {
298         if (passwordTracker instanceof PasswordTrackerImpl) {
299             return passwordTracker;
300         }
301 
302         PasswordTrackerImpl passwordTrackerImpl = new PasswordTrackerImpl();
303 
304         passwordTrackerImpl.setNew(passwordTracker.isNew());
305         passwordTrackerImpl.setPrimaryKey(passwordTracker.getPrimaryKey());
306 
307         passwordTrackerImpl.setPasswordTrackerId(passwordTracker.getPasswordTrackerId());
308         passwordTrackerImpl.setUserId(passwordTracker.getUserId());
309         passwordTrackerImpl.setCreateDate(passwordTracker.getCreateDate());
310         passwordTrackerImpl.setPassword(passwordTracker.getPassword());
311 
312         return passwordTrackerImpl;
313     }
314 
315     public PasswordTracker findByPrimaryKey(long passwordTrackerId)
316         throws NoSuchPasswordTrackerException, SystemException {
317         PasswordTracker passwordTracker = fetchByPrimaryKey(passwordTrackerId);
318 
319         if (passwordTracker == null) {
320             if (_log.isWarnEnabled()) {
321                 _log.warn("No PasswordTracker exists with the primary key " +
322                     passwordTrackerId);
323             }
324 
325             throw new NoSuchPasswordTrackerException(
326                 "No PasswordTracker exists with the primary key " +
327                 passwordTrackerId);
328         }
329 
330         return passwordTracker;
331     }
332 
333     public PasswordTracker fetchByPrimaryKey(long passwordTrackerId)
334         throws SystemException {
335         PasswordTracker passwordTracker = (PasswordTracker)EntityCacheUtil.getResult(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
336                 PasswordTrackerImpl.class, passwordTrackerId, this);
337 
338         if (passwordTracker == null) {
339             Session session = null;
340 
341             try {
342                 session = openSession();
343 
344                 passwordTracker = (PasswordTracker)session.get(PasswordTrackerImpl.class,
345                         new Long(passwordTrackerId));
346             }
347             catch (Exception e) {
348                 throw processException(e);
349             }
350             finally {
351                 if (passwordTracker != null) {
352                     cacheResult(passwordTracker);
353                 }
354 
355                 closeSession(session);
356             }
357         }
358 
359         return passwordTracker;
360     }
361 
362     public List<PasswordTracker> findByUserId(long userId)
363         throws SystemException {
364         Object[] finderArgs = new Object[] { new Long(userId) };
365 
366         List<PasswordTracker> list = (List<PasswordTracker>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
367                 finderArgs, this);
368 
369         if (list == null) {
370             Session session = null;
371 
372             try {
373                 session = openSession();
374 
375                 StringBuilder query = new StringBuilder();
376 
377                 query.append(
378                     "SELECT passwordTracker FROM PasswordTracker passwordTracker WHERE ");
379 
380                 query.append("passwordTracker.userId = ?");
381 
382                 query.append(" ");
383 
384                 query.append("ORDER BY ");
385 
386                 query.append("passwordTracker.userId DESC, ");
387                 query.append("passwordTracker.createDate DESC");
388 
389                 Query q = session.createQuery(query.toString());
390 
391                 QueryPos qPos = QueryPos.getInstance(q);
392 
393                 qPos.add(userId);
394 
395                 list = q.list();
396             }
397             catch (Exception e) {
398                 throw processException(e);
399             }
400             finally {
401                 if (list == null) {
402                     list = new ArrayList<PasswordTracker>();
403                 }
404 
405                 cacheResult(list);
406 
407                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
408                     finderArgs, list);
409 
410                 closeSession(session);
411             }
412         }
413 
414         return list;
415     }
416 
417     public List<PasswordTracker> findByUserId(long userId, int start, int end)
418         throws SystemException {
419         return findByUserId(userId, start, end, null);
420     }
421 
422     public List<PasswordTracker> findByUserId(long userId, int start, int end,
423         OrderByComparator obc) throws SystemException {
424         Object[] finderArgs = new Object[] {
425                 new Long(userId),
426                 
427                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
428             };
429 
430         List<PasswordTracker> list = (List<PasswordTracker>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_USERID,
431                 finderArgs, this);
432 
433         if (list == null) {
434             Session session = null;
435 
436             try {
437                 session = openSession();
438 
439                 StringBuilder query = new StringBuilder();
440 
441                 query.append(
442                     "SELECT passwordTracker FROM PasswordTracker passwordTracker WHERE ");
443 
444                 query.append("passwordTracker.userId = ?");
445 
446                 query.append(" ");
447 
448                 if (obc != null) {
449                     query.append("ORDER BY ");
450 
451                     String[] orderByFields = obc.getOrderByFields();
452 
453                     for (int i = 0; i < orderByFields.length; i++) {
454                         query.append("passwordTracker.");
455                         query.append(orderByFields[i]);
456 
457                         if (obc.isAscending()) {
458                             query.append(" ASC");
459                         }
460                         else {
461                             query.append(" DESC");
462                         }
463 
464                         if ((i + 1) < orderByFields.length) {
465                             query.append(", ");
466                         }
467                     }
468                 }
469 
470                 else {
471                     query.append("ORDER BY ");
472 
473                     query.append("passwordTracker.userId DESC, ");
474                     query.append("passwordTracker.createDate DESC");
475                 }
476 
477                 Query q = session.createQuery(query.toString());
478 
479                 QueryPos qPos = QueryPos.getInstance(q);
480 
481                 qPos.add(userId);
482 
483                 list = (List<PasswordTracker>)QueryUtil.list(q, getDialect(),
484                         start, end);
485             }
486             catch (Exception e) {
487                 throw processException(e);
488             }
489             finally {
490                 if (list == null) {
491                     list = new ArrayList<PasswordTracker>();
492                 }
493 
494                 cacheResult(list);
495 
496                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_USERID,
497                     finderArgs, list);
498 
499                 closeSession(session);
500             }
501         }
502 
503         return list;
504     }
505 
506     public PasswordTracker findByUserId_First(long userId, OrderByComparator obc)
507         throws NoSuchPasswordTrackerException, SystemException {
508         List<PasswordTracker> list = findByUserId(userId, 0, 1, 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_Last(long userId, OrderByComparator obc)
527         throws NoSuchPasswordTrackerException, SystemException {
528         int count = countByUserId(userId);
529 
530         List<PasswordTracker> list = findByUserId(userId, count - 1, count, obc);
531 
532         if (list.isEmpty()) {
533             StringBuilder msg = new StringBuilder();
534 
535             msg.append("No PasswordTracker exists with the key {");
536 
537             msg.append("userId=" + userId);
538 
539             msg.append(StringPool.CLOSE_CURLY_BRACE);
540 
541             throw new NoSuchPasswordTrackerException(msg.toString());
542         }
543         else {
544             return list.get(0);
545         }
546     }
547 
548     public PasswordTracker[] findByUserId_PrevAndNext(long passwordTrackerId,
549         long userId, OrderByComparator obc)
550         throws NoSuchPasswordTrackerException, SystemException {
551         PasswordTracker passwordTracker = findByPrimaryKey(passwordTrackerId);
552 
553         int count = countByUserId(userId);
554 
555         Session session = null;
556 
557         try {
558             session = openSession();
559 
560             StringBuilder query = new StringBuilder();
561 
562             query.append(
563                 "SELECT passwordTracker FROM PasswordTracker passwordTracker WHERE ");
564 
565             query.append("passwordTracker.userId = ?");
566 
567             query.append(" ");
568 
569             if (obc != null) {
570                 query.append("ORDER BY ");
571 
572                 String[] orderByFields = obc.getOrderByFields();
573 
574                 for (int i = 0; i < orderByFields.length; i++) {
575                     query.append("passwordTracker.");
576                     query.append(orderByFields[i]);
577 
578                     if (obc.isAscending()) {
579                         query.append(" ASC");
580                     }
581                     else {
582                         query.append(" DESC");
583                     }
584 
585                     if ((i + 1) < orderByFields.length) {
586                         query.append(", ");
587                     }
588                 }
589             }
590 
591             else {
592                 query.append("ORDER BY ");
593 
594                 query.append("passwordTracker.userId DESC, ");
595                 query.append("passwordTracker.createDate DESC");
596             }
597 
598             Query q = session.createQuery(query.toString());
599 
600             QueryPos qPos = QueryPos.getInstance(q);
601 
602             qPos.add(userId);
603 
604             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
605                     passwordTracker);
606 
607             PasswordTracker[] array = new PasswordTrackerImpl[3];
608 
609             array[0] = (PasswordTracker)objArray[0];
610             array[1] = (PasswordTracker)objArray[1];
611             array[2] = (PasswordTracker)objArray[2];
612 
613             return array;
614         }
615         catch (Exception e) {
616             throw processException(e);
617         }
618         finally {
619             closeSession(session);
620         }
621     }
622 
623     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
624         throws SystemException {
625         Session session = null;
626 
627         try {
628             session = openSession();
629 
630             dynamicQuery.compile(session);
631 
632             return dynamicQuery.list();
633         }
634         catch (Exception e) {
635             throw processException(e);
636         }
637         finally {
638             closeSession(session);
639         }
640     }
641 
642     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
643         int start, int end) throws SystemException {
644         Session session = null;
645 
646         try {
647             session = openSession();
648 
649             dynamicQuery.setLimit(start, end);
650 
651             dynamicQuery.compile(session);
652 
653             return dynamicQuery.list();
654         }
655         catch (Exception e) {
656             throw processException(e);
657         }
658         finally {
659             closeSession(session);
660         }
661     }
662 
663     public List<PasswordTracker> findAll() throws SystemException {
664         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
665     }
666 
667     public List<PasswordTracker> findAll(int start, int end)
668         throws SystemException {
669         return findAll(start, end, null);
670     }
671 
672     public List<PasswordTracker> findAll(int start, int end,
673         OrderByComparator obc) throws SystemException {
674         Object[] finderArgs = new Object[] {
675                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
676             };
677 
678         List<PasswordTracker> list = (List<PasswordTracker>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
679                 finderArgs, this);
680 
681         if (list == null) {
682             Session session = null;
683 
684             try {
685                 session = openSession();
686 
687                 StringBuilder query = new StringBuilder();
688 
689                 query.append(
690                     "SELECT passwordTracker FROM PasswordTracker passwordTracker ");
691 
692                 if (obc != null) {
693                     query.append("ORDER BY ");
694 
695                     String[] orderByFields = obc.getOrderByFields();
696 
697                     for (int i = 0; i < orderByFields.length; i++) {
698                         query.append("passwordTracker.");
699                         query.append(orderByFields[i]);
700 
701                         if (obc.isAscending()) {
702                             query.append(" ASC");
703                         }
704                         else {
705                             query.append(" DESC");
706                         }
707 
708                         if ((i + 1) < orderByFields.length) {
709                             query.append(", ");
710                         }
711                     }
712                 }
713 
714                 else {
715                     query.append("ORDER BY ");
716 
717                     query.append("passwordTracker.userId DESC, ");
718                     query.append("passwordTracker.createDate DESC");
719                 }
720 
721                 Query q = session.createQuery(query.toString());
722 
723                 if (obc == null) {
724                     list = (List<PasswordTracker>)QueryUtil.list(q,
725                             getDialect(), start, end, false);
726 
727                     Collections.sort(list);
728                 }
729                 else {
730                     list = (List<PasswordTracker>)QueryUtil.list(q,
731                             getDialect(), start, end);
732                 }
733             }
734             catch (Exception e) {
735                 throw processException(e);
736             }
737             finally {
738                 if (list == null) {
739                     list = new ArrayList<PasswordTracker>();
740                 }
741 
742                 cacheResult(list);
743 
744                 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
745 
746                 closeSession(session);
747             }
748         }
749 
750         return list;
751     }
752 
753     public void removeByUserId(long userId) throws SystemException {
754         for (PasswordTracker passwordTracker : findByUserId(userId)) {
755             remove(passwordTracker);
756         }
757     }
758 
759     public void removeAll() throws SystemException {
760         for (PasswordTracker passwordTracker : findAll()) {
761             remove(passwordTracker);
762         }
763     }
764 
765     public int countByUserId(long userId) throws SystemException {
766         Object[] finderArgs = new Object[] { new Long(userId) };
767 
768         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
769                 finderArgs, this);
770 
771         if (count == null) {
772             Session session = null;
773 
774             try {
775                 session = openSession();
776 
777                 StringBuilder query = new StringBuilder();
778 
779                 query.append("SELECT COUNT(passwordTracker) ");
780                 query.append("FROM PasswordTracker passwordTracker WHERE ");
781 
782                 query.append("passwordTracker.userId = ?");
783 
784                 query.append(" ");
785 
786                 Query q = session.createQuery(query.toString());
787 
788                 QueryPos qPos = QueryPos.getInstance(q);
789 
790                 qPos.add(userId);
791 
792                 count = (Long)q.uniqueResult();
793             }
794             catch (Exception e) {
795                 throw processException(e);
796             }
797             finally {
798                 if (count == null) {
799                     count = Long.valueOf(0);
800                 }
801 
802                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
803                     finderArgs, count);
804 
805                 closeSession(session);
806             }
807         }
808 
809         return count.intValue();
810     }
811 
812     public int countAll() throws SystemException {
813         Object[] finderArgs = new Object[0];
814 
815         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
816                 finderArgs, this);
817 
818         if (count == null) {
819             Session session = null;
820 
821             try {
822                 session = openSession();
823 
824                 Query q = session.createQuery(
825                         "SELECT COUNT(passwordTracker) FROM PasswordTracker passwordTracker");
826 
827                 count = (Long)q.uniqueResult();
828             }
829             catch (Exception e) {
830                 throw processException(e);
831             }
832             finally {
833                 if (count == null) {
834                     count = Long.valueOf(0);
835                 }
836 
837                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
838                     count);
839 
840                 closeSession(session);
841             }
842         }
843 
844         return count.intValue();
845     }
846 
847     public void afterPropertiesSet() {
848         String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
849                     com.liferay.portal.util.PropsUtil.get(
850                         "value.object.listener.com.liferay.portal.model.PasswordTracker")));
851 
852         if (listenerClassNames.length > 0) {
853             try {
854                 List<ModelListener<PasswordTracker>> listenersList = new ArrayList<ModelListener<PasswordTracker>>();
855 
856                 for (String listenerClassName : listenerClassNames) {
857                     listenersList.add((ModelListener<PasswordTracker>)Class.forName(
858                             listenerClassName).newInstance());
859                 }
860 
861                 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
862             }
863             catch (Exception e) {
864                 _log.error(e);
865             }
866         }
867     }
868 
869     @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence.impl")
870     protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
871     @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence.impl")
872     protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
873     @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence.impl")
874     protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
875     @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence.impl")
876     protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
877     @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
878     protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
879     @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence.impl")
880     protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
881     @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence.impl")
882     protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
883     @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence.impl")
884     protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
885     @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
886     protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
887     @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
888     protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
889     @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence.impl")
890     protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
891     @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence.impl")
892     protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
893     @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence.impl")
894     protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
895     @BeanReference(name = "com.liferay.portal.service.persistence.LockPersistence.impl")
896     protected com.liferay.portal.service.persistence.LockPersistence lockPersistence;
897     @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence.impl")
898     protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
899     @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence.impl")
900     protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
901     @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence.impl")
902     protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
903     @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence.impl")
904     protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
905     @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence.impl")
906     protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
907     @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence.impl")
908     protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
909     @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence.impl")
910     protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
911     @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence.impl")
912     protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
913     @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence.impl")
914     protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
915     @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence.impl")
916     protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
917     @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence.impl")
918     protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
919     @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence.impl")
920     protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
921     @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence.impl")
922     protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
923     @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence.impl")
924     protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
925     @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence.impl")
926     protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
927     @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence.impl")
928     protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
929     @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
930     protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
931     @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence.impl")
932     protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
933     @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence.impl")
934     protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
935     @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence.impl")
936     protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
937     @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence.impl")
938     protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
939     @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence.impl")
940     protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
941     @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence.impl")
942     protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
943     @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
944     protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
945     @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
946     protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
947     @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence.impl")
948     protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
949     @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupGroupRolePersistence.impl")
950     protected com.liferay.portal.service.persistence.UserGroupGroupRolePersistence userGroupGroupRolePersistence;
951     @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence.impl")
952     protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
953     @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence.impl")
954     protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
955     @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence.impl")
956     protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
957     @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence.impl")
958     protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
959     @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence.impl")
960     protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
961     @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence.impl")
962     protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
963     private static Log _log = LogFactoryUtil.getLog(PasswordTrackerPersistenceImpl.class);
964 }