001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.NoSuchPasswordTrackerException;
019    import com.liferay.portal.kernel.annotation.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.model.ModelListener;
038    import com.liferay.portal.model.PasswordTracker;
039    import com.liferay.portal.model.impl.PasswordTrackerImpl;
040    import com.liferay.portal.model.impl.PasswordTrackerModelImpl;
041    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042    
043    import java.io.Serializable;
044    
045    import java.util.ArrayList;
046    import java.util.Collections;
047    import java.util.List;
048    
049    /**
050     * The persistence for the password tracker service.
051     *
052     * <p>
053     * Never modify this class directly. Modify <code>service.xml</code> and rerun ServiceBuilder to regnerate this class.
054     * </p>
055     *
056     * <p>
057     * Caching information and settings can be found in <code>portal.properties</code>
058     * </p>
059     *
060     * @author Brian Wing Shun Chan
061     * @see PasswordTrackerPersistence
062     * @see PasswordTrackerUtil
063     * @generated
064     */
065    public class PasswordTrackerPersistenceImpl extends BasePersistenceImpl<PasswordTracker>
066            implements PasswordTrackerPersistence {
067            public static final String FINDER_CLASS_NAME_ENTITY = PasswordTrackerImpl.class.getName();
068            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
069                    ".List";
070            public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
071                            PasswordTrackerModelImpl.FINDER_CACHE_ENABLED,
072                            FINDER_CLASS_NAME_LIST, "findByUserId",
073                            new String[] {
074                                    Long.class.getName(),
075                                    
076                            "java.lang.Integer", "java.lang.Integer",
077                                    "com.liferay.portal.kernel.util.OrderByComparator"
078                            });
079            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
080                            PasswordTrackerModelImpl.FINDER_CACHE_ENABLED,
081                            FINDER_CLASS_NAME_LIST, "countByUserId",
082                            new String[] { Long.class.getName() });
083            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
084                            PasswordTrackerModelImpl.FINDER_CACHE_ENABLED,
085                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
086            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
087                            PasswordTrackerModelImpl.FINDER_CACHE_ENABLED,
088                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
089    
090            /**
091             * Caches the password tracker in the entity cache if it is enabled.
092             *
093             * @param passwordTracker the password tracker to cache
094             */
095            public void cacheResult(PasswordTracker passwordTracker) {
096                    EntityCacheUtil.putResult(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
097                            PasswordTrackerImpl.class, passwordTracker.getPrimaryKey(),
098                            passwordTracker);
099            }
100    
101            /**
102             * Caches the password trackers in the entity cache if it is enabled.
103             *
104             * @param passwordTrackers the password trackers to cache
105             */
106            public void cacheResult(List<PasswordTracker> passwordTrackers) {
107                    for (PasswordTracker passwordTracker : passwordTrackers) {
108                            if (EntityCacheUtil.getResult(
109                                                    PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
110                                                    PasswordTrackerImpl.class,
111                                                    passwordTracker.getPrimaryKey(), this) == null) {
112                                    cacheResult(passwordTracker);
113                            }
114                    }
115            }
116    
117            /**
118             * Clears the cache for all password trackers.
119             *
120             * <p>
121             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
122             * </p>
123             */
124            public void clearCache() {
125                    CacheRegistryUtil.clear(PasswordTrackerImpl.class.getName());
126                    EntityCacheUtil.clearCache(PasswordTrackerImpl.class.getName());
127                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
128                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
129            }
130    
131            /**
132             * Clears the cache for the password tracker.
133             *
134             * <p>
135             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
136             * </p>
137             */
138            public void clearCache(PasswordTracker passwordTracker) {
139                    EntityCacheUtil.removeResult(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
140                            PasswordTrackerImpl.class, passwordTracker.getPrimaryKey());
141            }
142    
143            /**
144             * Creates a new password tracker with the primary key.
145             *
146             * @param passwordTrackerId the primary key for the new password tracker
147             * @return the new password tracker
148             */
149            public PasswordTracker create(long passwordTrackerId) {
150                    PasswordTracker passwordTracker = new PasswordTrackerImpl();
151    
152                    passwordTracker.setNew(true);
153                    passwordTracker.setPrimaryKey(passwordTrackerId);
154    
155                    return passwordTracker;
156            }
157    
158            /**
159             * Removes the password tracker with the primary key from the database. Also notifies the appropriate model listeners.
160             *
161             * @param primaryKey the primary key of the password tracker to remove
162             * @return the password tracker that was removed
163             * @throws com.liferay.portal.NoSuchModelException if a password tracker with the primary key could not be found
164             * @throws SystemException if a system exception occurred
165             */
166            public PasswordTracker remove(Serializable primaryKey)
167                    throws NoSuchModelException, SystemException {
168                    return remove(((Long)primaryKey).longValue());
169            }
170    
171            /**
172             * Removes the password tracker with the primary key from the database. Also notifies the appropriate model listeners.
173             *
174             * @param passwordTrackerId the primary key of the password tracker to remove
175             * @return the password tracker that was removed
176             * @throws com.liferay.portal.NoSuchPasswordTrackerException if a password tracker with the primary key could not be found
177             * @throws SystemException if a system exception occurred
178             */
179            public PasswordTracker remove(long passwordTrackerId)
180                    throws NoSuchPasswordTrackerException, SystemException {
181                    Session session = null;
182    
183                    try {
184                            session = openSession();
185    
186                            PasswordTracker passwordTracker = (PasswordTracker)session.get(PasswordTrackerImpl.class,
187                                            new Long(passwordTrackerId));
188    
189                            if (passwordTracker == null) {
190                                    if (_log.isWarnEnabled()) {
191                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
192                                                    passwordTrackerId);
193                                    }
194    
195                                    throw new NoSuchPasswordTrackerException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
196                                            passwordTrackerId);
197                            }
198    
199                            return remove(passwordTracker);
200                    }
201                    catch (NoSuchPasswordTrackerException nsee) {
202                            throw nsee;
203                    }
204                    catch (Exception e) {
205                            throw processException(e);
206                    }
207                    finally {
208                            closeSession(session);
209                    }
210            }
211    
212            protected PasswordTracker removeImpl(PasswordTracker passwordTracker)
213                    throws SystemException {
214                    passwordTracker = toUnwrappedModel(passwordTracker);
215    
216                    Session session = null;
217    
218                    try {
219                            session = openSession();
220    
221                            if (passwordTracker.isCachedModel() ||
222                                            BatchSessionUtil.isEnabled()) {
223                                    Object staleObject = session.get(PasswordTrackerImpl.class,
224                                                    passwordTracker.getPrimaryKeyObj());
225    
226                                    if (staleObject != null) {
227                                            session.evict(staleObject);
228                                    }
229                            }
230    
231                            session.delete(passwordTracker);
232    
233                            session.flush();
234                    }
235                    catch (Exception e) {
236                            throw processException(e);
237                    }
238                    finally {
239                            closeSession(session);
240                    }
241    
242                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
243    
244                    EntityCacheUtil.removeResult(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
245                            PasswordTrackerImpl.class, passwordTracker.getPrimaryKey());
246    
247                    return passwordTracker;
248            }
249    
250            public PasswordTracker updateImpl(
251                    com.liferay.portal.model.PasswordTracker passwordTracker, boolean merge)
252                    throws SystemException {
253                    passwordTracker = toUnwrappedModel(passwordTracker);
254    
255                    Session session = null;
256    
257                    try {
258                            session = openSession();
259    
260                            BatchSessionUtil.update(session, passwordTracker, merge);
261    
262                            passwordTracker.setNew(false);
263                    }
264                    catch (Exception e) {
265                            throw processException(e);
266                    }
267                    finally {
268                            closeSession(session);
269                    }
270    
271                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
272    
273                    EntityCacheUtil.putResult(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
274                            PasswordTrackerImpl.class, passwordTracker.getPrimaryKey(),
275                            passwordTracker);
276    
277                    return passwordTracker;
278            }
279    
280            protected PasswordTracker toUnwrappedModel(PasswordTracker passwordTracker) {
281                    if (passwordTracker instanceof PasswordTrackerImpl) {
282                            return passwordTracker;
283                    }
284    
285                    PasswordTrackerImpl passwordTrackerImpl = new PasswordTrackerImpl();
286    
287                    passwordTrackerImpl.setNew(passwordTracker.isNew());
288                    passwordTrackerImpl.setPrimaryKey(passwordTracker.getPrimaryKey());
289    
290                    passwordTrackerImpl.setPasswordTrackerId(passwordTracker.getPasswordTrackerId());
291                    passwordTrackerImpl.setUserId(passwordTracker.getUserId());
292                    passwordTrackerImpl.setCreateDate(passwordTracker.getCreateDate());
293                    passwordTrackerImpl.setPassword(passwordTracker.getPassword());
294    
295                    return passwordTrackerImpl;
296            }
297    
298            /**
299             * Finds the password tracker with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
300             *
301             * @param primaryKey the primary key of the password tracker to find
302             * @return the password tracker
303             * @throws com.liferay.portal.NoSuchModelException if a password tracker with the primary key could not be found
304             * @throws SystemException if a system exception occurred
305             */
306            public PasswordTracker findByPrimaryKey(Serializable primaryKey)
307                    throws NoSuchModelException, SystemException {
308                    return findByPrimaryKey(((Long)primaryKey).longValue());
309            }
310    
311            /**
312             * Finds the password tracker with the primary key or throws a {@link com.liferay.portal.NoSuchPasswordTrackerException} if it could not be found.
313             *
314             * @param passwordTrackerId the primary key of the password tracker to find
315             * @return the password tracker
316             * @throws com.liferay.portal.NoSuchPasswordTrackerException if a password tracker with the primary key could not be found
317             * @throws SystemException if a system exception occurred
318             */
319            public PasswordTracker findByPrimaryKey(long passwordTrackerId)
320                    throws NoSuchPasswordTrackerException, SystemException {
321                    PasswordTracker passwordTracker = fetchByPrimaryKey(passwordTrackerId);
322    
323                    if (passwordTracker == null) {
324                            if (_log.isWarnEnabled()) {
325                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + passwordTrackerId);
326                            }
327    
328                            throw new NoSuchPasswordTrackerException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
329                                    passwordTrackerId);
330                    }
331    
332                    return passwordTracker;
333            }
334    
335            /**
336             * Finds the password tracker with the primary key or returns <code>null</code> if it could not be found.
337             *
338             * @param primaryKey the primary key of the password tracker to find
339             * @return the password tracker, or <code>null</code> if a password tracker with the primary key could not be found
340             * @throws SystemException if a system exception occurred
341             */
342            public PasswordTracker fetchByPrimaryKey(Serializable primaryKey)
343                    throws SystemException {
344                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
345            }
346    
347            /**
348             * Finds the password tracker with the primary key or returns <code>null</code> if it could not be found.
349             *
350             * @param passwordTrackerId the primary key of the password tracker to find
351             * @return the password tracker, or <code>null</code> if a password tracker with the primary key could not be found
352             * @throws SystemException if a system exception occurred
353             */
354            public PasswordTracker fetchByPrimaryKey(long passwordTrackerId)
355                    throws SystemException {
356                    PasswordTracker passwordTracker = (PasswordTracker)EntityCacheUtil.getResult(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
357                                    PasswordTrackerImpl.class, passwordTrackerId, this);
358    
359                    if (passwordTracker == null) {
360                            Session session = null;
361    
362                            try {
363                                    session = openSession();
364    
365                                    passwordTracker = (PasswordTracker)session.get(PasswordTrackerImpl.class,
366                                                    new Long(passwordTrackerId));
367                            }
368                            catch (Exception e) {
369                                    throw processException(e);
370                            }
371                            finally {
372                                    if (passwordTracker != null) {
373                                            cacheResult(passwordTracker);
374                                    }
375    
376                                    closeSession(session);
377                            }
378                    }
379    
380                    return passwordTracker;
381            }
382    
383            /**
384             * Finds all the password trackers where userId = &#63;.
385             *
386             * @param userId the user id to search with
387             * @return the matching password trackers
388             * @throws SystemException if a system exception occurred
389             */
390            public List<PasswordTracker> findByUserId(long userId)
391                    throws SystemException {
392                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
393            }
394    
395            /**
396             * Finds a range of all the password trackers where userId = &#63;.
397             *
398             * <p>
399             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
400             * </p>
401             *
402             * @param userId the user id to search with
403             * @param start the lower bound of the range of password trackers to return
404             * @param end the upper bound of the range of password trackers to return (not inclusive)
405             * @return the range of matching password trackers
406             * @throws SystemException if a system exception occurred
407             */
408            public List<PasswordTracker> findByUserId(long userId, int start, int end)
409                    throws SystemException {
410                    return findByUserId(userId, start, end, null);
411            }
412    
413            /**
414             * Finds an ordered range of all the password trackers where userId = &#63;.
415             *
416             * <p>
417             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
418             * </p>
419             *
420             * @param userId the user id to search with
421             * @param start the lower bound of the range of password trackers to return
422             * @param end the upper bound of the range of password trackers to return (not inclusive)
423             * @param orderByComparator the comparator to order the results by
424             * @return the ordered range of matching password trackers
425             * @throws SystemException if a system exception occurred
426             */
427            public List<PasswordTracker> findByUserId(long userId, int start, int end,
428                    OrderByComparator orderByComparator) throws SystemException {
429                    Object[] finderArgs = new Object[] {
430                                    userId,
431                                    
432                                    String.valueOf(start), String.valueOf(end),
433                                    String.valueOf(orderByComparator)
434                            };
435    
436                    List<PasswordTracker> list = (List<PasswordTracker>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
437                                    finderArgs, this);
438    
439                    if (list == null) {
440                            Session session = null;
441    
442                            try {
443                                    session = openSession();
444    
445                                    StringBundler query = null;
446    
447                                    if (orderByComparator != null) {
448                                            query = new StringBundler(3 +
449                                                            (orderByComparator.getOrderByFields().length * 3));
450                                    }
451                                    else {
452                                            query = new StringBundler(3);
453                                    }
454    
455                                    query.append(_SQL_SELECT_PASSWORDTRACKER_WHERE);
456    
457                                    query.append(_FINDER_COLUMN_USERID_USERID_2);
458    
459                                    if (orderByComparator != null) {
460                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
461                                                    orderByComparator);
462                                    }
463    
464                                    else {
465                                            query.append(PasswordTrackerModelImpl.ORDER_BY_JPQL);
466                                    }
467    
468                                    String sql = query.toString();
469    
470                                    Query q = session.createQuery(sql);
471    
472                                    QueryPos qPos = QueryPos.getInstance(q);
473    
474                                    qPos.add(userId);
475    
476                                    list = (List<PasswordTracker>)QueryUtil.list(q, getDialect(),
477                                                    start, end);
478                            }
479                            catch (Exception e) {
480                                    throw processException(e);
481                            }
482                            finally {
483                                    if (list == null) {
484                                            list = new ArrayList<PasswordTracker>();
485                                    }
486    
487                                    cacheResult(list);
488    
489                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
490                                            finderArgs, list);
491    
492                                    closeSession(session);
493                            }
494                    }
495    
496                    return list;
497            }
498    
499            /**
500             * Finds the first password tracker in the ordered set where userId = &#63;.
501             *
502             * <p>
503             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
504             * </p>
505             *
506             * @param userId the user id to search with
507             * @param orderByComparator the comparator to order the set by
508             * @return the first matching password tracker
509             * @throws com.liferay.portal.NoSuchPasswordTrackerException if a matching password tracker could not be found
510             * @throws SystemException if a system exception occurred
511             */
512            public PasswordTracker findByUserId_First(long userId,
513                    OrderByComparator orderByComparator)
514                    throws NoSuchPasswordTrackerException, SystemException {
515                    List<PasswordTracker> list = findByUserId(userId, 0, 1,
516                                    orderByComparator);
517    
518                    if (list.isEmpty()) {
519                            StringBundler msg = new StringBundler(4);
520    
521                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
522    
523                            msg.append("userId=");
524                            msg.append(userId);
525    
526                            msg.append(StringPool.CLOSE_CURLY_BRACE);
527    
528                            throw new NoSuchPasswordTrackerException(msg.toString());
529                    }
530                    else {
531                            return list.get(0);
532                    }
533            }
534    
535            /**
536             * Finds the last password tracker in the ordered set where userId = &#63;.
537             *
538             * <p>
539             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
540             * </p>
541             *
542             * @param userId the user id to search with
543             * @param orderByComparator the comparator to order the set by
544             * @return the last matching password tracker
545             * @throws com.liferay.portal.NoSuchPasswordTrackerException if a matching password tracker could not be found
546             * @throws SystemException if a system exception occurred
547             */
548            public PasswordTracker findByUserId_Last(long userId,
549                    OrderByComparator orderByComparator)
550                    throws NoSuchPasswordTrackerException, SystemException {
551                    int count = countByUserId(userId);
552    
553                    List<PasswordTracker> list = findByUserId(userId, count - 1, count,
554                                    orderByComparator);
555    
556                    if (list.isEmpty()) {
557                            StringBundler msg = new StringBundler(4);
558    
559                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
560    
561                            msg.append("userId=");
562                            msg.append(userId);
563    
564                            msg.append(StringPool.CLOSE_CURLY_BRACE);
565    
566                            throw new NoSuchPasswordTrackerException(msg.toString());
567                    }
568                    else {
569                            return list.get(0);
570                    }
571            }
572    
573            /**
574             * Finds the password trackers before and after the current password tracker in the ordered set where userId = &#63;.
575             *
576             * <p>
577             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
578             * </p>
579             *
580             * @param passwordTrackerId the primary key of the current password tracker
581             * @param userId the user id to search with
582             * @param orderByComparator the comparator to order the set by
583             * @return the previous, current, and next password tracker
584             * @throws com.liferay.portal.NoSuchPasswordTrackerException if a password tracker with the primary key could not be found
585             * @throws SystemException if a system exception occurred
586             */
587            public PasswordTracker[] findByUserId_PrevAndNext(long passwordTrackerId,
588                    long userId, OrderByComparator orderByComparator)
589                    throws NoSuchPasswordTrackerException, SystemException {
590                    PasswordTracker passwordTracker = findByPrimaryKey(passwordTrackerId);
591    
592                    Session session = null;
593    
594                    try {
595                            session = openSession();
596    
597                            PasswordTracker[] array = new PasswordTrackerImpl[3];
598    
599                            array[0] = getByUserId_PrevAndNext(session, passwordTracker,
600                                            userId, orderByComparator, true);
601    
602                            array[1] = passwordTracker;
603    
604                            array[2] = getByUserId_PrevAndNext(session, passwordTracker,
605                                            userId, orderByComparator, false);
606    
607                            return array;
608                    }
609                    catch (Exception e) {
610                            throw processException(e);
611                    }
612                    finally {
613                            closeSession(session);
614                    }
615            }
616    
617            protected PasswordTracker getByUserId_PrevAndNext(Session session,
618                    PasswordTracker passwordTracker, long userId,
619                    OrderByComparator orderByComparator, boolean previous) {
620                    StringBundler query = null;
621    
622                    if (orderByComparator != null) {
623                            query = new StringBundler(6 +
624                                            (orderByComparator.getOrderByFields().length * 6));
625                    }
626                    else {
627                            query = new StringBundler(3);
628                    }
629    
630                    query.append(_SQL_SELECT_PASSWORDTRACKER_WHERE);
631    
632                    query.append(_FINDER_COLUMN_USERID_USERID_2);
633    
634                    if (orderByComparator != null) {
635                            String[] orderByFields = orderByComparator.getOrderByFields();
636    
637                            if (orderByFields.length > 0) {
638                                    query.append(WHERE_AND);
639                            }
640    
641                            for (int i = 0; i < orderByFields.length; i++) {
642                                    query.append(_ORDER_BY_ENTITY_ALIAS);
643                                    query.append(orderByFields[i]);
644    
645                                    if ((i + 1) < orderByFields.length) {
646                                            if (orderByComparator.isAscending() ^ previous) {
647                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
648                                            }
649                                            else {
650                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
651                                            }
652                                    }
653                                    else {
654                                            if (orderByComparator.isAscending() ^ previous) {
655                                                    query.append(WHERE_GREATER_THAN);
656                                            }
657                                            else {
658                                                    query.append(WHERE_LESSER_THAN);
659                                            }
660                                    }
661                            }
662    
663                            query.append(ORDER_BY_CLAUSE);
664    
665                            for (int i = 0; i < orderByFields.length; i++) {
666                                    query.append(_ORDER_BY_ENTITY_ALIAS);
667                                    query.append(orderByFields[i]);
668    
669                                    if ((i + 1) < orderByFields.length) {
670                                            if (orderByComparator.isAscending() ^ previous) {
671                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
672                                            }
673                                            else {
674                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
675                                            }
676                                    }
677                                    else {
678                                            if (orderByComparator.isAscending() ^ previous) {
679                                                    query.append(ORDER_BY_ASC);
680                                            }
681                                            else {
682                                                    query.append(ORDER_BY_DESC);
683                                            }
684                                    }
685                            }
686                    }
687    
688                    else {
689                            query.append(PasswordTrackerModelImpl.ORDER_BY_JPQL);
690                    }
691    
692                    String sql = query.toString();
693    
694                    Query q = session.createQuery(sql);
695    
696                    q.setFirstResult(0);
697                    q.setMaxResults(2);
698    
699                    QueryPos qPos = QueryPos.getInstance(q);
700    
701                    qPos.add(userId);
702    
703                    if (orderByComparator != null) {
704                            Object[] values = orderByComparator.getOrderByValues(passwordTracker);
705    
706                            for (Object value : values) {
707                                    qPos.add(value);
708                            }
709                    }
710    
711                    List<PasswordTracker> list = q.list();
712    
713                    if (list.size() == 2) {
714                            return list.get(1);
715                    }
716                    else {
717                            return null;
718                    }
719            }
720    
721            /**
722             * Finds all the password trackers.
723             *
724             * @return the password trackers
725             * @throws SystemException if a system exception occurred
726             */
727            public List<PasswordTracker> findAll() throws SystemException {
728                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
729            }
730    
731            /**
732             * Finds a range of all the password trackers.
733             *
734             * <p>
735             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
736             * </p>
737             *
738             * @param start the lower bound of the range of password trackers to return
739             * @param end the upper bound of the range of password trackers to return (not inclusive)
740             * @return the range of password trackers
741             * @throws SystemException if a system exception occurred
742             */
743            public List<PasswordTracker> findAll(int start, int end)
744                    throws SystemException {
745                    return findAll(start, end, null);
746            }
747    
748            /**
749             * Finds an ordered range of all the password trackers.
750             *
751             * <p>
752             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
753             * </p>
754             *
755             * @param start the lower bound of the range of password trackers to return
756             * @param end the upper bound of the range of password trackers to return (not inclusive)
757             * @param orderByComparator the comparator to order the results by
758             * @return the ordered range of password trackers
759             * @throws SystemException if a system exception occurred
760             */
761            public List<PasswordTracker> findAll(int start, int end,
762                    OrderByComparator orderByComparator) throws SystemException {
763                    Object[] finderArgs = new Object[] {
764                                    String.valueOf(start), String.valueOf(end),
765                                    String.valueOf(orderByComparator)
766                            };
767    
768                    List<PasswordTracker> list = (List<PasswordTracker>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
769                                    finderArgs, this);
770    
771                    if (list == null) {
772                            Session session = null;
773    
774                            try {
775                                    session = openSession();
776    
777                                    StringBundler query = null;
778                                    String sql = null;
779    
780                                    if (orderByComparator != null) {
781                                            query = new StringBundler(2 +
782                                                            (orderByComparator.getOrderByFields().length * 3));
783    
784                                            query.append(_SQL_SELECT_PASSWORDTRACKER);
785    
786                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
787                                                    orderByComparator);
788    
789                                            sql = query.toString();
790                                    }
791                                    else {
792                                            sql = _SQL_SELECT_PASSWORDTRACKER.concat(PasswordTrackerModelImpl.ORDER_BY_JPQL);
793                                    }
794    
795                                    Query q = session.createQuery(sql);
796    
797                                    if (orderByComparator == null) {
798                                            list = (List<PasswordTracker>)QueryUtil.list(q,
799                                                            getDialect(), start, end, false);
800    
801                                            Collections.sort(list);
802                                    }
803                                    else {
804                                            list = (List<PasswordTracker>)QueryUtil.list(q,
805                                                            getDialect(), start, end);
806                                    }
807                            }
808                            catch (Exception e) {
809                                    throw processException(e);
810                            }
811                            finally {
812                                    if (list == null) {
813                                            list = new ArrayList<PasswordTracker>();
814                                    }
815    
816                                    cacheResult(list);
817    
818                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
819    
820                                    closeSession(session);
821                            }
822                    }
823    
824                    return list;
825            }
826    
827            /**
828             * Removes all the password trackers where userId = &#63; from the database.
829             *
830             * @param userId the user id to search with
831             * @throws SystemException if a system exception occurred
832             */
833            public void removeByUserId(long userId) throws SystemException {
834                    for (PasswordTracker passwordTracker : findByUserId(userId)) {
835                            remove(passwordTracker);
836                    }
837            }
838    
839            /**
840             * Removes all the password trackers from the database.
841             *
842             * @throws SystemException if a system exception occurred
843             */
844            public void removeAll() throws SystemException {
845                    for (PasswordTracker passwordTracker : findAll()) {
846                            remove(passwordTracker);
847                    }
848            }
849    
850            /**
851             * Counts all the password trackers where userId = &#63;.
852             *
853             * @param userId the user id to search with
854             * @return the number of matching password trackers
855             * @throws SystemException if a system exception occurred
856             */
857            public int countByUserId(long userId) throws SystemException {
858                    Object[] finderArgs = new Object[] { userId };
859    
860                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
861                                    finderArgs, this);
862    
863                    if (count == null) {
864                            Session session = null;
865    
866                            try {
867                                    session = openSession();
868    
869                                    StringBundler query = new StringBundler(2);
870    
871                                    query.append(_SQL_COUNT_PASSWORDTRACKER_WHERE);
872    
873                                    query.append(_FINDER_COLUMN_USERID_USERID_2);
874    
875                                    String sql = query.toString();
876    
877                                    Query q = session.createQuery(sql);
878    
879                                    QueryPos qPos = QueryPos.getInstance(q);
880    
881                                    qPos.add(userId);
882    
883                                    count = (Long)q.uniqueResult();
884                            }
885                            catch (Exception e) {
886                                    throw processException(e);
887                            }
888                            finally {
889                                    if (count == null) {
890                                            count = Long.valueOf(0);
891                                    }
892    
893                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
894                                            finderArgs, count);
895    
896                                    closeSession(session);
897                            }
898                    }
899    
900                    return count.intValue();
901            }
902    
903            /**
904             * Counts all the password trackers.
905             *
906             * @return the number of password trackers
907             * @throws SystemException if a system exception occurred
908             */
909            public int countAll() throws SystemException {
910                    Object[] finderArgs = new Object[0];
911    
912                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
913                                    finderArgs, this);
914    
915                    if (count == null) {
916                            Session session = null;
917    
918                            try {
919                                    session = openSession();
920    
921                                    Query q = session.createQuery(_SQL_COUNT_PASSWORDTRACKER);
922    
923                                    count = (Long)q.uniqueResult();
924                            }
925                            catch (Exception e) {
926                                    throw processException(e);
927                            }
928                            finally {
929                                    if (count == null) {
930                                            count = Long.valueOf(0);
931                                    }
932    
933                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
934                                            count);
935    
936                                    closeSession(session);
937                            }
938                    }
939    
940                    return count.intValue();
941            }
942    
943            /**
944             * Initializes the password tracker persistence.
945             */
946            public void afterPropertiesSet() {
947                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
948                                            com.liferay.portal.util.PropsUtil.get(
949                                                    "value.object.listener.com.liferay.portal.model.PasswordTracker")));
950    
951                    if (listenerClassNames.length > 0) {
952                            try {
953                                    List<ModelListener<PasswordTracker>> listenersList = new ArrayList<ModelListener<PasswordTracker>>();
954    
955                                    for (String listenerClassName : listenerClassNames) {
956                                            listenersList.add((ModelListener<PasswordTracker>)InstanceFactory.newInstance(
957                                                            listenerClassName));
958                                    }
959    
960                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
961                            }
962                            catch (Exception e) {
963                                    _log.error(e);
964                            }
965                    }
966            }
967    
968            @BeanReference(type = AccountPersistence.class)
969            protected AccountPersistence accountPersistence;
970            @BeanReference(type = AddressPersistence.class)
971            protected AddressPersistence addressPersistence;
972            @BeanReference(type = BrowserTrackerPersistence.class)
973            protected BrowserTrackerPersistence browserTrackerPersistence;
974            @BeanReference(type = ClassNamePersistence.class)
975            protected ClassNamePersistence classNamePersistence;
976            @BeanReference(type = CompanyPersistence.class)
977            protected CompanyPersistence companyPersistence;
978            @BeanReference(type = ContactPersistence.class)
979            protected ContactPersistence contactPersistence;
980            @BeanReference(type = CountryPersistence.class)
981            protected CountryPersistence countryPersistence;
982            @BeanReference(type = EmailAddressPersistence.class)
983            protected EmailAddressPersistence emailAddressPersistence;
984            @BeanReference(type = GroupPersistence.class)
985            protected GroupPersistence groupPersistence;
986            @BeanReference(type = ImagePersistence.class)
987            protected ImagePersistence imagePersistence;
988            @BeanReference(type = LayoutPersistence.class)
989            protected LayoutPersistence layoutPersistence;
990            @BeanReference(type = LayoutPrototypePersistence.class)
991            protected LayoutPrototypePersistence layoutPrototypePersistence;
992            @BeanReference(type = LayoutSetPersistence.class)
993            protected LayoutSetPersistence layoutSetPersistence;
994            @BeanReference(type = LayoutSetPrototypePersistence.class)
995            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
996            @BeanReference(type = ListTypePersistence.class)
997            protected ListTypePersistence listTypePersistence;
998            @BeanReference(type = LockPersistence.class)
999            protected LockPersistence lockPersistence;
1000            @BeanReference(type = MembershipRequestPersistence.class)
1001            protected MembershipRequestPersistence membershipRequestPersistence;
1002            @BeanReference(type = OrganizationPersistence.class)
1003            protected OrganizationPersistence organizationPersistence;
1004            @BeanReference(type = OrgGroupPermissionPersistence.class)
1005            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1006            @BeanReference(type = OrgGroupRolePersistence.class)
1007            protected OrgGroupRolePersistence orgGroupRolePersistence;
1008            @BeanReference(type = OrgLaborPersistence.class)
1009            protected OrgLaborPersistence orgLaborPersistence;
1010            @BeanReference(type = PasswordPolicyPersistence.class)
1011            protected PasswordPolicyPersistence passwordPolicyPersistence;
1012            @BeanReference(type = PasswordPolicyRelPersistence.class)
1013            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1014            @BeanReference(type = PasswordTrackerPersistence.class)
1015            protected PasswordTrackerPersistence passwordTrackerPersistence;
1016            @BeanReference(type = PermissionPersistence.class)
1017            protected PermissionPersistence permissionPersistence;
1018            @BeanReference(type = PhonePersistence.class)
1019            protected PhonePersistence phonePersistence;
1020            @BeanReference(type = PluginSettingPersistence.class)
1021            protected PluginSettingPersistence pluginSettingPersistence;
1022            @BeanReference(type = PortletPersistence.class)
1023            protected PortletPersistence portletPersistence;
1024            @BeanReference(type = PortletItemPersistence.class)
1025            protected PortletItemPersistence portletItemPersistence;
1026            @BeanReference(type = PortletPreferencesPersistence.class)
1027            protected PortletPreferencesPersistence portletPreferencesPersistence;
1028            @BeanReference(type = RegionPersistence.class)
1029            protected RegionPersistence regionPersistence;
1030            @BeanReference(type = ReleasePersistence.class)
1031            protected ReleasePersistence releasePersistence;
1032            @BeanReference(type = ResourcePersistence.class)
1033            protected ResourcePersistence resourcePersistence;
1034            @BeanReference(type = ResourceActionPersistence.class)
1035            protected ResourceActionPersistence resourceActionPersistence;
1036            @BeanReference(type = ResourceCodePersistence.class)
1037            protected ResourceCodePersistence resourceCodePersistence;
1038            @BeanReference(type = ResourcePermissionPersistence.class)
1039            protected ResourcePermissionPersistence resourcePermissionPersistence;
1040            @BeanReference(type = RolePersistence.class)
1041            protected RolePersistence rolePersistence;
1042            @BeanReference(type = ServiceComponentPersistence.class)
1043            protected ServiceComponentPersistence serviceComponentPersistence;
1044            @BeanReference(type = ShardPersistence.class)
1045            protected ShardPersistence shardPersistence;
1046            @BeanReference(type = SubscriptionPersistence.class)
1047            protected SubscriptionPersistence subscriptionPersistence;
1048            @BeanReference(type = TicketPersistence.class)
1049            protected TicketPersistence ticketPersistence;
1050            @BeanReference(type = TeamPersistence.class)
1051            protected TeamPersistence teamPersistence;
1052            @BeanReference(type = UserPersistence.class)
1053            protected UserPersistence userPersistence;
1054            @BeanReference(type = UserGroupPersistence.class)
1055            protected UserGroupPersistence userGroupPersistence;
1056            @BeanReference(type = UserGroupGroupRolePersistence.class)
1057            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1058            @BeanReference(type = UserGroupRolePersistence.class)
1059            protected UserGroupRolePersistence userGroupRolePersistence;
1060            @BeanReference(type = UserIdMapperPersistence.class)
1061            protected UserIdMapperPersistence userIdMapperPersistence;
1062            @BeanReference(type = UserTrackerPersistence.class)
1063            protected UserTrackerPersistence userTrackerPersistence;
1064            @BeanReference(type = UserTrackerPathPersistence.class)
1065            protected UserTrackerPathPersistence userTrackerPathPersistence;
1066            @BeanReference(type = WebDAVPropsPersistence.class)
1067            protected WebDAVPropsPersistence webDAVPropsPersistence;
1068            @BeanReference(type = WebsitePersistence.class)
1069            protected WebsitePersistence websitePersistence;
1070            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1071            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1072            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1073            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1074            private static final String _SQL_SELECT_PASSWORDTRACKER = "SELECT passwordTracker FROM PasswordTracker passwordTracker";
1075            private static final String _SQL_SELECT_PASSWORDTRACKER_WHERE = "SELECT passwordTracker FROM PasswordTracker passwordTracker WHERE ";
1076            private static final String _SQL_COUNT_PASSWORDTRACKER = "SELECT COUNT(passwordTracker) FROM PasswordTracker passwordTracker";
1077            private static final String _SQL_COUNT_PASSWORDTRACKER_WHERE = "SELECT COUNT(passwordTracker) FROM PasswordTracker passwordTracker WHERE ";
1078            private static final String _FINDER_COLUMN_USERID_USERID_2 = "passwordTracker.userId = ?";
1079            private static final String _ORDER_BY_ENTITY_ALIAS = "passwordTracker.";
1080            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PasswordTracker exists with the primary key ";
1081            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PasswordTracker exists with the key {";
1082            private static Log _log = LogFactoryUtil.getLog(PasswordTrackerPersistenceImpl.class);
1083    }