001    /**
002     * Copyright (c) 2000-2011 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 implementation for the password tracker service.
051     *
052     * <p>
053     * Never modify or reference this class directly. Always use {@link PasswordTrackerUtil} to access the password tracker persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate 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. Does not add the password tracker to the database.
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                            BatchSessionUtil.delete(session, passwordTracker);
222                    }
223                    catch (Exception e) {
224                            throw processException(e);
225                    }
226                    finally {
227                            closeSession(session);
228                    }
229    
230                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
231    
232                    EntityCacheUtil.removeResult(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
233                            PasswordTrackerImpl.class, passwordTracker.getPrimaryKey());
234    
235                    return passwordTracker;
236            }
237    
238            public PasswordTracker updateImpl(
239                    com.liferay.portal.model.PasswordTracker passwordTracker, boolean merge)
240                    throws SystemException {
241                    passwordTracker = toUnwrappedModel(passwordTracker);
242    
243                    Session session = null;
244    
245                    try {
246                            session = openSession();
247    
248                            BatchSessionUtil.update(session, passwordTracker, merge);
249    
250                            passwordTracker.setNew(false);
251                    }
252                    catch (Exception e) {
253                            throw processException(e);
254                    }
255                    finally {
256                            closeSession(session);
257                    }
258    
259                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
260    
261                    EntityCacheUtil.putResult(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
262                            PasswordTrackerImpl.class, passwordTracker.getPrimaryKey(),
263                            passwordTracker);
264    
265                    return passwordTracker;
266            }
267    
268            protected PasswordTracker toUnwrappedModel(PasswordTracker passwordTracker) {
269                    if (passwordTracker instanceof PasswordTrackerImpl) {
270                            return passwordTracker;
271                    }
272    
273                    PasswordTrackerImpl passwordTrackerImpl = new PasswordTrackerImpl();
274    
275                    passwordTrackerImpl.setNew(passwordTracker.isNew());
276                    passwordTrackerImpl.setPrimaryKey(passwordTracker.getPrimaryKey());
277    
278                    passwordTrackerImpl.setPasswordTrackerId(passwordTracker.getPasswordTrackerId());
279                    passwordTrackerImpl.setUserId(passwordTracker.getUserId());
280                    passwordTrackerImpl.setCreateDate(passwordTracker.getCreateDate());
281                    passwordTrackerImpl.setPassword(passwordTracker.getPassword());
282    
283                    return passwordTrackerImpl;
284            }
285    
286            /**
287             * Finds the password tracker with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
288             *
289             * @param primaryKey the primary key of the password tracker to find
290             * @return the password tracker
291             * @throws com.liferay.portal.NoSuchModelException if a password tracker with the primary key could not be found
292             * @throws SystemException if a system exception occurred
293             */
294            public PasswordTracker findByPrimaryKey(Serializable primaryKey)
295                    throws NoSuchModelException, SystemException {
296                    return findByPrimaryKey(((Long)primaryKey).longValue());
297            }
298    
299            /**
300             * Finds the password tracker with the primary key or throws a {@link com.liferay.portal.NoSuchPasswordTrackerException} if it could not be found.
301             *
302             * @param passwordTrackerId the primary key of the password tracker to find
303             * @return the password tracker
304             * @throws com.liferay.portal.NoSuchPasswordTrackerException if a password tracker with the primary key could not be found
305             * @throws SystemException if a system exception occurred
306             */
307            public PasswordTracker findByPrimaryKey(long passwordTrackerId)
308                    throws NoSuchPasswordTrackerException, SystemException {
309                    PasswordTracker passwordTracker = fetchByPrimaryKey(passwordTrackerId);
310    
311                    if (passwordTracker == null) {
312                            if (_log.isWarnEnabled()) {
313                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + passwordTrackerId);
314                            }
315    
316                            throw new NoSuchPasswordTrackerException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
317                                    passwordTrackerId);
318                    }
319    
320                    return passwordTracker;
321            }
322    
323            /**
324             * Finds the password tracker with the primary key or returns <code>null</code> if it could not be found.
325             *
326             * @param primaryKey the primary key of the password tracker to find
327             * @return the password tracker, or <code>null</code> if a password tracker with the primary key could not be found
328             * @throws SystemException if a system exception occurred
329             */
330            public PasswordTracker fetchByPrimaryKey(Serializable primaryKey)
331                    throws SystemException {
332                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
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 passwordTrackerId 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(long passwordTrackerId)
343                    throws SystemException {
344                    PasswordTracker passwordTracker = (PasswordTracker)EntityCacheUtil.getResult(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
345                                    PasswordTrackerImpl.class, passwordTrackerId, this);
346    
347                    if (passwordTracker == null) {
348                            Session session = null;
349    
350                            try {
351                                    session = openSession();
352    
353                                    passwordTracker = (PasswordTracker)session.get(PasswordTrackerImpl.class,
354                                                    new Long(passwordTrackerId));
355                            }
356                            catch (Exception e) {
357                                    throw processException(e);
358                            }
359                            finally {
360                                    if (passwordTracker != null) {
361                                            cacheResult(passwordTracker);
362                                    }
363    
364                                    closeSession(session);
365                            }
366                    }
367    
368                    return passwordTracker;
369            }
370    
371            /**
372             * Finds all the password trackers where userId = &#63;.
373             *
374             * @param userId the user id to search with
375             * @return the matching password trackers
376             * @throws SystemException if a system exception occurred
377             */
378            public List<PasswordTracker> findByUserId(long userId)
379                    throws SystemException {
380                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
381            }
382    
383            /**
384             * Finds a range of all the password trackers where userId = &#63;.
385             *
386             * <p>
387             * 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.
388             * </p>
389             *
390             * @param userId the user id to search with
391             * @param start the lower bound of the range of password trackers to return
392             * @param end the upper bound of the range of password trackers to return (not inclusive)
393             * @return the range of matching password trackers
394             * @throws SystemException if a system exception occurred
395             */
396            public List<PasswordTracker> findByUserId(long userId, int start, int end)
397                    throws SystemException {
398                    return findByUserId(userId, start, end, null);
399            }
400    
401            /**
402             * Finds an ordered range of all the password trackers where userId = &#63;.
403             *
404             * <p>
405             * 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.
406             * </p>
407             *
408             * @param userId the user id to search with
409             * @param start the lower bound of the range of password trackers to return
410             * @param end the upper bound of the range of password trackers to return (not inclusive)
411             * @param orderByComparator the comparator to order the results by
412             * @return the ordered range of matching password trackers
413             * @throws SystemException if a system exception occurred
414             */
415            public List<PasswordTracker> findByUserId(long userId, int start, int end,
416                    OrderByComparator orderByComparator) throws SystemException {
417                    Object[] finderArgs = new Object[] {
418                                    userId,
419                                    
420                                    String.valueOf(start), String.valueOf(end),
421                                    String.valueOf(orderByComparator)
422                            };
423    
424                    List<PasswordTracker> list = (List<PasswordTracker>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
425                                    finderArgs, this);
426    
427                    if (list == null) {
428                            StringBundler query = null;
429    
430                            if (orderByComparator != null) {
431                                    query = new StringBundler(3 +
432                                                    (orderByComparator.getOrderByFields().length * 3));
433                            }
434                            else {
435                                    query = new StringBundler(3);
436                            }
437    
438                            query.append(_SQL_SELECT_PASSWORDTRACKER_WHERE);
439    
440                            query.append(_FINDER_COLUMN_USERID_USERID_2);
441    
442                            if (orderByComparator != null) {
443                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
444                                            orderByComparator);
445                            }
446    
447                            else {
448                                    query.append(PasswordTrackerModelImpl.ORDER_BY_JPQL);
449                            }
450    
451                            String sql = query.toString();
452    
453                            Session session = null;
454    
455                            try {
456                                    session = openSession();
457    
458                                    Query q = session.createQuery(sql);
459    
460                                    QueryPos qPos = QueryPos.getInstance(q);
461    
462                                    qPos.add(userId);
463    
464                                    list = (List<PasswordTracker>)QueryUtil.list(q, getDialect(),
465                                                    start, end);
466                            }
467                            catch (Exception e) {
468                                    throw processException(e);
469                            }
470                            finally {
471                                    if (list == null) {
472                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_USERID,
473                                                    finderArgs);
474                                    }
475                                    else {
476                                            cacheResult(list);
477    
478                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
479                                                    finderArgs, list);
480                                    }
481    
482                                    closeSession(session);
483                            }
484                    }
485    
486                    return list;
487            }
488    
489            /**
490             * Finds the first password tracker in the ordered set where userId = &#63;.
491             *
492             * <p>
493             * 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.
494             * </p>
495             *
496             * @param userId the user id to search with
497             * @param orderByComparator the comparator to order the set by
498             * @return the first matching password tracker
499             * @throws com.liferay.portal.NoSuchPasswordTrackerException if a matching password tracker could not be found
500             * @throws SystemException if a system exception occurred
501             */
502            public PasswordTracker findByUserId_First(long userId,
503                    OrderByComparator orderByComparator)
504                    throws NoSuchPasswordTrackerException, SystemException {
505                    List<PasswordTracker> list = findByUserId(userId, 0, 1,
506                                    orderByComparator);
507    
508                    if (list.isEmpty()) {
509                            StringBundler msg = new StringBundler(4);
510    
511                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
512    
513                            msg.append("userId=");
514                            msg.append(userId);
515    
516                            msg.append(StringPool.CLOSE_CURLY_BRACE);
517    
518                            throw new NoSuchPasswordTrackerException(msg.toString());
519                    }
520                    else {
521                            return list.get(0);
522                    }
523            }
524    
525            /**
526             * Finds the last password tracker in the ordered set where userId = &#63;.
527             *
528             * <p>
529             * 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.
530             * </p>
531             *
532             * @param userId the user id to search with
533             * @param orderByComparator the comparator to order the set by
534             * @return the last matching password tracker
535             * @throws com.liferay.portal.NoSuchPasswordTrackerException if a matching password tracker could not be found
536             * @throws SystemException if a system exception occurred
537             */
538            public PasswordTracker findByUserId_Last(long userId,
539                    OrderByComparator orderByComparator)
540                    throws NoSuchPasswordTrackerException, SystemException {
541                    int count = countByUserId(userId);
542    
543                    List<PasswordTracker> list = findByUserId(userId, count - 1, count,
544                                    orderByComparator);
545    
546                    if (list.isEmpty()) {
547                            StringBundler msg = new StringBundler(4);
548    
549                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
550    
551                            msg.append("userId=");
552                            msg.append(userId);
553    
554                            msg.append(StringPool.CLOSE_CURLY_BRACE);
555    
556                            throw new NoSuchPasswordTrackerException(msg.toString());
557                    }
558                    else {
559                            return list.get(0);
560                    }
561            }
562    
563            /**
564             * Finds the password trackers before and after the current password tracker in the ordered set where userId = &#63;.
565             *
566             * <p>
567             * 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.
568             * </p>
569             *
570             * @param passwordTrackerId the primary key of the current password tracker
571             * @param userId the user id to search with
572             * @param orderByComparator the comparator to order the set by
573             * @return the previous, current, and next password tracker
574             * @throws com.liferay.portal.NoSuchPasswordTrackerException if a password tracker with the primary key could not be found
575             * @throws SystemException if a system exception occurred
576             */
577            public PasswordTracker[] findByUserId_PrevAndNext(long passwordTrackerId,
578                    long userId, OrderByComparator orderByComparator)
579                    throws NoSuchPasswordTrackerException, SystemException {
580                    PasswordTracker passwordTracker = findByPrimaryKey(passwordTrackerId);
581    
582                    Session session = null;
583    
584                    try {
585                            session = openSession();
586    
587                            PasswordTracker[] array = new PasswordTrackerImpl[3];
588    
589                            array[0] = getByUserId_PrevAndNext(session, passwordTracker,
590                                            userId, orderByComparator, true);
591    
592                            array[1] = passwordTracker;
593    
594                            array[2] = getByUserId_PrevAndNext(session, passwordTracker,
595                                            userId, orderByComparator, false);
596    
597                            return array;
598                    }
599                    catch (Exception e) {
600                            throw processException(e);
601                    }
602                    finally {
603                            closeSession(session);
604                    }
605            }
606    
607            protected PasswordTracker getByUserId_PrevAndNext(Session session,
608                    PasswordTracker passwordTracker, long userId,
609                    OrderByComparator orderByComparator, boolean previous) {
610                    StringBundler query = null;
611    
612                    if (orderByComparator != null) {
613                            query = new StringBundler(6 +
614                                            (orderByComparator.getOrderByFields().length * 6));
615                    }
616                    else {
617                            query = new StringBundler(3);
618                    }
619    
620                    query.append(_SQL_SELECT_PASSWORDTRACKER_WHERE);
621    
622                    query.append(_FINDER_COLUMN_USERID_USERID_2);
623    
624                    if (orderByComparator != null) {
625                            String[] orderByFields = orderByComparator.getOrderByFields();
626    
627                            if (orderByFields.length > 0) {
628                                    query.append(WHERE_AND);
629                            }
630    
631                            for (int i = 0; i < orderByFields.length; i++) {
632                                    query.append(_ORDER_BY_ENTITY_ALIAS);
633                                    query.append(orderByFields[i]);
634    
635                                    if ((i + 1) < orderByFields.length) {
636                                            if (orderByComparator.isAscending() ^ previous) {
637                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
638                                            }
639                                            else {
640                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
641                                            }
642                                    }
643                                    else {
644                                            if (orderByComparator.isAscending() ^ previous) {
645                                                    query.append(WHERE_GREATER_THAN);
646                                            }
647                                            else {
648                                                    query.append(WHERE_LESSER_THAN);
649                                            }
650                                    }
651                            }
652    
653                            query.append(ORDER_BY_CLAUSE);
654    
655                            for (int i = 0; i < orderByFields.length; i++) {
656                                    query.append(_ORDER_BY_ENTITY_ALIAS);
657                                    query.append(orderByFields[i]);
658    
659                                    if ((i + 1) < orderByFields.length) {
660                                            if (orderByComparator.isAscending() ^ previous) {
661                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
662                                            }
663                                            else {
664                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
665                                            }
666                                    }
667                                    else {
668                                            if (orderByComparator.isAscending() ^ previous) {
669                                                    query.append(ORDER_BY_ASC);
670                                            }
671                                            else {
672                                                    query.append(ORDER_BY_DESC);
673                                            }
674                                    }
675                            }
676                    }
677    
678                    else {
679                            query.append(PasswordTrackerModelImpl.ORDER_BY_JPQL);
680                    }
681    
682                    String sql = query.toString();
683    
684                    Query q = session.createQuery(sql);
685    
686                    q.setFirstResult(0);
687                    q.setMaxResults(2);
688    
689                    QueryPos qPos = QueryPos.getInstance(q);
690    
691                    qPos.add(userId);
692    
693                    if (orderByComparator != null) {
694                            Object[] values = orderByComparator.getOrderByValues(passwordTracker);
695    
696                            for (Object value : values) {
697                                    qPos.add(value);
698                            }
699                    }
700    
701                    List<PasswordTracker> list = q.list();
702    
703                    if (list.size() == 2) {
704                            return list.get(1);
705                    }
706                    else {
707                            return null;
708                    }
709            }
710    
711            /**
712             * Finds all the password trackers.
713             *
714             * @return the password trackers
715             * @throws SystemException if a system exception occurred
716             */
717            public List<PasswordTracker> findAll() throws SystemException {
718                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
719            }
720    
721            /**
722             * Finds a range of all the password trackers.
723             *
724             * <p>
725             * 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.
726             * </p>
727             *
728             * @param start the lower bound of the range of password trackers to return
729             * @param end the upper bound of the range of password trackers to return (not inclusive)
730             * @return the range of password trackers
731             * @throws SystemException if a system exception occurred
732             */
733            public List<PasswordTracker> findAll(int start, int end)
734                    throws SystemException {
735                    return findAll(start, end, null);
736            }
737    
738            /**
739             * Finds an ordered range of all the password trackers.
740             *
741             * <p>
742             * 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.
743             * </p>
744             *
745             * @param start the lower bound of the range of password trackers to return
746             * @param end the upper bound of the range of password trackers to return (not inclusive)
747             * @param orderByComparator the comparator to order the results by
748             * @return the ordered range of password trackers
749             * @throws SystemException if a system exception occurred
750             */
751            public List<PasswordTracker> findAll(int start, int end,
752                    OrderByComparator orderByComparator) throws SystemException {
753                    Object[] finderArgs = new Object[] {
754                                    String.valueOf(start), String.valueOf(end),
755                                    String.valueOf(orderByComparator)
756                            };
757    
758                    List<PasswordTracker> list = (List<PasswordTracker>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
759                                    finderArgs, this);
760    
761                    if (list == null) {
762                            StringBundler query = null;
763                            String sql = null;
764    
765                            if (orderByComparator != null) {
766                                    query = new StringBundler(2 +
767                                                    (orderByComparator.getOrderByFields().length * 3));
768    
769                                    query.append(_SQL_SELECT_PASSWORDTRACKER);
770    
771                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
772                                            orderByComparator);
773    
774                                    sql = query.toString();
775                            }
776                            else {
777                                    sql = _SQL_SELECT_PASSWORDTRACKER.concat(PasswordTrackerModelImpl.ORDER_BY_JPQL);
778                            }
779    
780                            Session session = null;
781    
782                            try {
783                                    session = openSession();
784    
785                                    Query q = session.createQuery(sql);
786    
787                                    if (orderByComparator == null) {
788                                            list = (List<PasswordTracker>)QueryUtil.list(q,
789                                                            getDialect(), start, end, false);
790    
791                                            Collections.sort(list);
792                                    }
793                                    else {
794                                            list = (List<PasswordTracker>)QueryUtil.list(q,
795                                                            getDialect(), start, end);
796                                    }
797                            }
798                            catch (Exception e) {
799                                    throw processException(e);
800                            }
801                            finally {
802                                    if (list == null) {
803                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
804                                                    finderArgs);
805                                    }
806                                    else {
807                                            cacheResult(list);
808    
809                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
810                                                    list);
811                                    }
812    
813                                    closeSession(session);
814                            }
815                    }
816    
817                    return list;
818            }
819    
820            /**
821             * Removes all the password trackers where userId = &#63; from the database.
822             *
823             * @param userId the user id to search with
824             * @throws SystemException if a system exception occurred
825             */
826            public void removeByUserId(long userId) throws SystemException {
827                    for (PasswordTracker passwordTracker : findByUserId(userId)) {
828                            remove(passwordTracker);
829                    }
830            }
831    
832            /**
833             * Removes all the password trackers from the database.
834             *
835             * @throws SystemException if a system exception occurred
836             */
837            public void removeAll() throws SystemException {
838                    for (PasswordTracker passwordTracker : findAll()) {
839                            remove(passwordTracker);
840                    }
841            }
842    
843            /**
844             * Counts all the password trackers where userId = &#63;.
845             *
846             * @param userId the user id to search with
847             * @return the number of matching password trackers
848             * @throws SystemException if a system exception occurred
849             */
850            public int countByUserId(long userId) throws SystemException {
851                    Object[] finderArgs = new Object[] { userId };
852    
853                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
854                                    finderArgs, this);
855    
856                    if (count == null) {
857                            StringBundler query = new StringBundler(2);
858    
859                            query.append(_SQL_COUNT_PASSWORDTRACKER_WHERE);
860    
861                            query.append(_FINDER_COLUMN_USERID_USERID_2);
862    
863                            String sql = query.toString();
864    
865                            Session session = null;
866    
867                            try {
868                                    session = openSession();
869    
870                                    Query q = session.createQuery(sql);
871    
872                                    QueryPos qPos = QueryPos.getInstance(q);
873    
874                                    qPos.add(userId);
875    
876                                    count = (Long)q.uniqueResult();
877                            }
878                            catch (Exception e) {
879                                    throw processException(e);
880                            }
881                            finally {
882                                    if (count == null) {
883                                            count = Long.valueOf(0);
884                                    }
885    
886                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
887                                            finderArgs, count);
888    
889                                    closeSession(session);
890                            }
891                    }
892    
893                    return count.intValue();
894            }
895    
896            /**
897             * Counts all the password trackers.
898             *
899             * @return the number of password trackers
900             * @throws SystemException if a system exception occurred
901             */
902            public int countAll() throws SystemException {
903                    Object[] finderArgs = new Object[0];
904    
905                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
906                                    finderArgs, this);
907    
908                    if (count == null) {
909                            Session session = null;
910    
911                            try {
912                                    session = openSession();
913    
914                                    Query q = session.createQuery(_SQL_COUNT_PASSWORDTRACKER);
915    
916                                    count = (Long)q.uniqueResult();
917                            }
918                            catch (Exception e) {
919                                    throw processException(e);
920                            }
921                            finally {
922                                    if (count == null) {
923                                            count = Long.valueOf(0);
924                                    }
925    
926                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
927                                            count);
928    
929                                    closeSession(session);
930                            }
931                    }
932    
933                    return count.intValue();
934            }
935    
936            /**
937             * Initializes the password tracker persistence.
938             */
939            public void afterPropertiesSet() {
940                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
941                                            com.liferay.portal.util.PropsUtil.get(
942                                                    "value.object.listener.com.liferay.portal.model.PasswordTracker")));
943    
944                    if (listenerClassNames.length > 0) {
945                            try {
946                                    List<ModelListener<PasswordTracker>> listenersList = new ArrayList<ModelListener<PasswordTracker>>();
947    
948                                    for (String listenerClassName : listenerClassNames) {
949                                            listenersList.add((ModelListener<PasswordTracker>)InstanceFactory.newInstance(
950                                                            listenerClassName));
951                                    }
952    
953                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
954                            }
955                            catch (Exception e) {
956                                    _log.error(e);
957                            }
958                    }
959            }
960    
961            public void destroy() {
962                    EntityCacheUtil.removeCache(PasswordTrackerImpl.class.getName());
963                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
964                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
965            }
966    
967            @BeanReference(type = AccountPersistence.class)
968            protected AccountPersistence accountPersistence;
969            @BeanReference(type = AddressPersistence.class)
970            protected AddressPersistence addressPersistence;
971            @BeanReference(type = BrowserTrackerPersistence.class)
972            protected BrowserTrackerPersistence browserTrackerPersistence;
973            @BeanReference(type = ClassNamePersistence.class)
974            protected ClassNamePersistence classNamePersistence;
975            @BeanReference(type = ClusterGroupPersistence.class)
976            protected ClusterGroupPersistence clusterGroupPersistence;
977            @BeanReference(type = CompanyPersistence.class)
978            protected CompanyPersistence companyPersistence;
979            @BeanReference(type = ContactPersistence.class)
980            protected ContactPersistence contactPersistence;
981            @BeanReference(type = CountryPersistence.class)
982            protected CountryPersistence countryPersistence;
983            @BeanReference(type = EmailAddressPersistence.class)
984            protected EmailAddressPersistence emailAddressPersistence;
985            @BeanReference(type = GroupPersistence.class)
986            protected GroupPersistence groupPersistence;
987            @BeanReference(type = ImagePersistence.class)
988            protected ImagePersistence imagePersistence;
989            @BeanReference(type = LayoutPersistence.class)
990            protected LayoutPersistence layoutPersistence;
991            @BeanReference(type = LayoutPrototypePersistence.class)
992            protected LayoutPrototypePersistence layoutPrototypePersistence;
993            @BeanReference(type = LayoutSetPersistence.class)
994            protected LayoutSetPersistence layoutSetPersistence;
995            @BeanReference(type = LayoutSetPrototypePersistence.class)
996            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
997            @BeanReference(type = ListTypePersistence.class)
998            protected ListTypePersistence listTypePersistence;
999            @BeanReference(type = LockPersistence.class)
1000            protected LockPersistence lockPersistence;
1001            @BeanReference(type = MembershipRequestPersistence.class)
1002            protected MembershipRequestPersistence membershipRequestPersistence;
1003            @BeanReference(type = OrganizationPersistence.class)
1004            protected OrganizationPersistence organizationPersistence;
1005            @BeanReference(type = OrgGroupPermissionPersistence.class)
1006            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1007            @BeanReference(type = OrgGroupRolePersistence.class)
1008            protected OrgGroupRolePersistence orgGroupRolePersistence;
1009            @BeanReference(type = OrgLaborPersistence.class)
1010            protected OrgLaborPersistence orgLaborPersistence;
1011            @BeanReference(type = PasswordPolicyPersistence.class)
1012            protected PasswordPolicyPersistence passwordPolicyPersistence;
1013            @BeanReference(type = PasswordPolicyRelPersistence.class)
1014            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1015            @BeanReference(type = PasswordTrackerPersistence.class)
1016            protected PasswordTrackerPersistence passwordTrackerPersistence;
1017            @BeanReference(type = PermissionPersistence.class)
1018            protected PermissionPersistence permissionPersistence;
1019            @BeanReference(type = PhonePersistence.class)
1020            protected PhonePersistence phonePersistence;
1021            @BeanReference(type = PluginSettingPersistence.class)
1022            protected PluginSettingPersistence pluginSettingPersistence;
1023            @BeanReference(type = PortletPersistence.class)
1024            protected PortletPersistence portletPersistence;
1025            @BeanReference(type = PortletItemPersistence.class)
1026            protected PortletItemPersistence portletItemPersistence;
1027            @BeanReference(type = PortletPreferencesPersistence.class)
1028            protected PortletPreferencesPersistence portletPreferencesPersistence;
1029            @BeanReference(type = RegionPersistence.class)
1030            protected RegionPersistence regionPersistence;
1031            @BeanReference(type = ReleasePersistence.class)
1032            protected ReleasePersistence releasePersistence;
1033            @BeanReference(type = ResourcePersistence.class)
1034            protected ResourcePersistence resourcePersistence;
1035            @BeanReference(type = ResourceActionPersistence.class)
1036            protected ResourceActionPersistence resourceActionPersistence;
1037            @BeanReference(type = ResourceCodePersistence.class)
1038            protected ResourceCodePersistence resourceCodePersistence;
1039            @BeanReference(type = ResourcePermissionPersistence.class)
1040            protected ResourcePermissionPersistence resourcePermissionPersistence;
1041            @BeanReference(type = RolePersistence.class)
1042            protected RolePersistence rolePersistence;
1043            @BeanReference(type = ServiceComponentPersistence.class)
1044            protected ServiceComponentPersistence serviceComponentPersistence;
1045            @BeanReference(type = ShardPersistence.class)
1046            protected ShardPersistence shardPersistence;
1047            @BeanReference(type = SubscriptionPersistence.class)
1048            protected SubscriptionPersistence subscriptionPersistence;
1049            @BeanReference(type = TicketPersistence.class)
1050            protected TicketPersistence ticketPersistence;
1051            @BeanReference(type = TeamPersistence.class)
1052            protected TeamPersistence teamPersistence;
1053            @BeanReference(type = UserPersistence.class)
1054            protected UserPersistence userPersistence;
1055            @BeanReference(type = UserGroupPersistence.class)
1056            protected UserGroupPersistence userGroupPersistence;
1057            @BeanReference(type = UserGroupGroupRolePersistence.class)
1058            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1059            @BeanReference(type = UserGroupRolePersistence.class)
1060            protected UserGroupRolePersistence userGroupRolePersistence;
1061            @BeanReference(type = UserIdMapperPersistence.class)
1062            protected UserIdMapperPersistence userIdMapperPersistence;
1063            @BeanReference(type = UserTrackerPersistence.class)
1064            protected UserTrackerPersistence userTrackerPersistence;
1065            @BeanReference(type = UserTrackerPathPersistence.class)
1066            protected UserTrackerPathPersistence userTrackerPathPersistence;
1067            @BeanReference(type = WebDAVPropsPersistence.class)
1068            protected WebDAVPropsPersistence webDAVPropsPersistence;
1069            @BeanReference(type = WebsitePersistence.class)
1070            protected WebsitePersistence websitePersistence;
1071            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1072            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1073            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1074            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1075            private static final String _SQL_SELECT_PASSWORDTRACKER = "SELECT passwordTracker FROM PasswordTracker passwordTracker";
1076            private static final String _SQL_SELECT_PASSWORDTRACKER_WHERE = "SELECT passwordTracker FROM PasswordTracker passwordTracker WHERE ";
1077            private static final String _SQL_COUNT_PASSWORDTRACKER = "SELECT COUNT(passwordTracker) FROM PasswordTracker passwordTracker";
1078            private static final String _SQL_COUNT_PASSWORDTRACKER_WHERE = "SELECT COUNT(passwordTracker) FROM PasswordTracker passwordTracker WHERE ";
1079            private static final String _FINDER_COLUMN_USERID_USERID_2 = "passwordTracker.userId = ?";
1080            private static final String _ORDER_BY_ENTITY_ALIAS = "passwordTracker.";
1081            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PasswordTracker exists with the primary key ";
1082            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PasswordTracker exists with the key {";
1083            private static Log _log = LogFactoryUtil.getLog(PasswordTrackerPersistenceImpl.class);
1084    }