001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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                            Session session = null;
429    
430                            try {
431                                    session = openSession();
432    
433                                    StringBundler query = null;
434    
435                                    if (orderByComparator != null) {
436                                            query = new StringBundler(3 +
437                                                            (orderByComparator.getOrderByFields().length * 3));
438                                    }
439                                    else {
440                                            query = new StringBundler(3);
441                                    }
442    
443                                    query.append(_SQL_SELECT_PASSWORDTRACKER_WHERE);
444    
445                                    query.append(_FINDER_COLUMN_USERID_USERID_2);
446    
447                                    if (orderByComparator != null) {
448                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
449                                                    orderByComparator);
450                                    }
451    
452                                    else {
453                                            query.append(PasswordTrackerModelImpl.ORDER_BY_JPQL);
454                                    }
455    
456                                    String sql = query.toString();
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                                            list = new ArrayList<PasswordTracker>();
473                                    }
474    
475                                    cacheResult(list);
476    
477                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
478                                            finderArgs, list);
479    
480                                    closeSession(session);
481                            }
482                    }
483    
484                    return list;
485            }
486    
487            /**
488             * Finds the first password tracker in the ordered set where userId = &#63;.
489             *
490             * <p>
491             * 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.
492             * </p>
493             *
494             * @param userId the user id to search with
495             * @param orderByComparator the comparator to order the set by
496             * @return the first matching password tracker
497             * @throws com.liferay.portal.NoSuchPasswordTrackerException if a matching password tracker could not be found
498             * @throws SystemException if a system exception occurred
499             */
500            public PasswordTracker findByUserId_First(long userId,
501                    OrderByComparator orderByComparator)
502                    throws NoSuchPasswordTrackerException, SystemException {
503                    List<PasswordTracker> list = findByUserId(userId, 0, 1,
504                                    orderByComparator);
505    
506                    if (list.isEmpty()) {
507                            StringBundler msg = new StringBundler(4);
508    
509                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
510    
511                            msg.append("userId=");
512                            msg.append(userId);
513    
514                            msg.append(StringPool.CLOSE_CURLY_BRACE);
515    
516                            throw new NoSuchPasswordTrackerException(msg.toString());
517                    }
518                    else {
519                            return list.get(0);
520                    }
521            }
522    
523            /**
524             * Finds the last password tracker in the ordered set where userId = &#63;.
525             *
526             * <p>
527             * 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.
528             * </p>
529             *
530             * @param userId the user id to search with
531             * @param orderByComparator the comparator to order the set by
532             * @return the last matching password tracker
533             * @throws com.liferay.portal.NoSuchPasswordTrackerException if a matching password tracker could not be found
534             * @throws SystemException if a system exception occurred
535             */
536            public PasswordTracker findByUserId_Last(long userId,
537                    OrderByComparator orderByComparator)
538                    throws NoSuchPasswordTrackerException, SystemException {
539                    int count = countByUserId(userId);
540    
541                    List<PasswordTracker> list = findByUserId(userId, count - 1, count,
542                                    orderByComparator);
543    
544                    if (list.isEmpty()) {
545                            StringBundler msg = new StringBundler(4);
546    
547                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
548    
549                            msg.append("userId=");
550                            msg.append(userId);
551    
552                            msg.append(StringPool.CLOSE_CURLY_BRACE);
553    
554                            throw new NoSuchPasswordTrackerException(msg.toString());
555                    }
556                    else {
557                            return list.get(0);
558                    }
559            }
560    
561            /**
562             * Finds the password trackers before and after the current password tracker in the ordered set where userId = &#63;.
563             *
564             * <p>
565             * 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.
566             * </p>
567             *
568             * @param passwordTrackerId the primary key of the current password tracker
569             * @param userId the user id to search with
570             * @param orderByComparator the comparator to order the set by
571             * @return the previous, current, and next password tracker
572             * @throws com.liferay.portal.NoSuchPasswordTrackerException if a password tracker with the primary key could not be found
573             * @throws SystemException if a system exception occurred
574             */
575            public PasswordTracker[] findByUserId_PrevAndNext(long passwordTrackerId,
576                    long userId, OrderByComparator orderByComparator)
577                    throws NoSuchPasswordTrackerException, SystemException {
578                    PasswordTracker passwordTracker = findByPrimaryKey(passwordTrackerId);
579    
580                    Session session = null;
581    
582                    try {
583                            session = openSession();
584    
585                            PasswordTracker[] array = new PasswordTrackerImpl[3];
586    
587                            array[0] = getByUserId_PrevAndNext(session, passwordTracker,
588                                            userId, orderByComparator, true);
589    
590                            array[1] = passwordTracker;
591    
592                            array[2] = getByUserId_PrevAndNext(session, passwordTracker,
593                                            userId, orderByComparator, false);
594    
595                            return array;
596                    }
597                    catch (Exception e) {
598                            throw processException(e);
599                    }
600                    finally {
601                            closeSession(session);
602                    }
603            }
604    
605            protected PasswordTracker getByUserId_PrevAndNext(Session session,
606                    PasswordTracker passwordTracker, long userId,
607                    OrderByComparator orderByComparator, boolean previous) {
608                    StringBundler query = null;
609    
610                    if (orderByComparator != null) {
611                            query = new StringBundler(6 +
612                                            (orderByComparator.getOrderByFields().length * 6));
613                    }
614                    else {
615                            query = new StringBundler(3);
616                    }
617    
618                    query.append(_SQL_SELECT_PASSWORDTRACKER_WHERE);
619    
620                    query.append(_FINDER_COLUMN_USERID_USERID_2);
621    
622                    if (orderByComparator != null) {
623                            String[] orderByFields = orderByComparator.getOrderByFields();
624    
625                            if (orderByFields.length > 0) {
626                                    query.append(WHERE_AND);
627                            }
628    
629                            for (int i = 0; i < orderByFields.length; i++) {
630                                    query.append(_ORDER_BY_ENTITY_ALIAS);
631                                    query.append(orderByFields[i]);
632    
633                                    if ((i + 1) < orderByFields.length) {
634                                            if (orderByComparator.isAscending() ^ previous) {
635                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
636                                            }
637                                            else {
638                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
639                                            }
640                                    }
641                                    else {
642                                            if (orderByComparator.isAscending() ^ previous) {
643                                                    query.append(WHERE_GREATER_THAN);
644                                            }
645                                            else {
646                                                    query.append(WHERE_LESSER_THAN);
647                                            }
648                                    }
649                            }
650    
651                            query.append(ORDER_BY_CLAUSE);
652    
653                            for (int i = 0; i < orderByFields.length; i++) {
654                                    query.append(_ORDER_BY_ENTITY_ALIAS);
655                                    query.append(orderByFields[i]);
656    
657                                    if ((i + 1) < orderByFields.length) {
658                                            if (orderByComparator.isAscending() ^ previous) {
659                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
660                                            }
661                                            else {
662                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
663                                            }
664                                    }
665                                    else {
666                                            if (orderByComparator.isAscending() ^ previous) {
667                                                    query.append(ORDER_BY_ASC);
668                                            }
669                                            else {
670                                                    query.append(ORDER_BY_DESC);
671                                            }
672                                    }
673                            }
674                    }
675    
676                    else {
677                            query.append(PasswordTrackerModelImpl.ORDER_BY_JPQL);
678                    }
679    
680                    String sql = query.toString();
681    
682                    Query q = session.createQuery(sql);
683    
684                    q.setFirstResult(0);
685                    q.setMaxResults(2);
686    
687                    QueryPos qPos = QueryPos.getInstance(q);
688    
689                    qPos.add(userId);
690    
691                    if (orderByComparator != null) {
692                            Object[] values = orderByComparator.getOrderByValues(passwordTracker);
693    
694                            for (Object value : values) {
695                                    qPos.add(value);
696                            }
697                    }
698    
699                    List<PasswordTracker> list = q.list();
700    
701                    if (list.size() == 2) {
702                            return list.get(1);
703                    }
704                    else {
705                            return null;
706                    }
707            }
708    
709            /**
710             * Finds all the password trackers.
711             *
712             * @return the password trackers
713             * @throws SystemException if a system exception occurred
714             */
715            public List<PasswordTracker> findAll() throws SystemException {
716                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
717            }
718    
719            /**
720             * Finds a range of all the password trackers.
721             *
722             * <p>
723             * 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.
724             * </p>
725             *
726             * @param start the lower bound of the range of password trackers to return
727             * @param end the upper bound of the range of password trackers to return (not inclusive)
728             * @return the range of password trackers
729             * @throws SystemException if a system exception occurred
730             */
731            public List<PasswordTracker> findAll(int start, int end)
732                    throws SystemException {
733                    return findAll(start, end, null);
734            }
735    
736            /**
737             * Finds an ordered range of all the password trackers.
738             *
739             * <p>
740             * 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.
741             * </p>
742             *
743             * @param start the lower bound of the range of password trackers to return
744             * @param end the upper bound of the range of password trackers to return (not inclusive)
745             * @param orderByComparator the comparator to order the results by
746             * @return the ordered range of password trackers
747             * @throws SystemException if a system exception occurred
748             */
749            public List<PasswordTracker> findAll(int start, int end,
750                    OrderByComparator orderByComparator) throws SystemException {
751                    Object[] finderArgs = new Object[] {
752                                    String.valueOf(start), String.valueOf(end),
753                                    String.valueOf(orderByComparator)
754                            };
755    
756                    List<PasswordTracker> list = (List<PasswordTracker>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
757                                    finderArgs, this);
758    
759                    if (list == null) {
760                            Session session = null;
761    
762                            try {
763                                    session = openSession();
764    
765                                    StringBundler query = null;
766                                    String sql = null;
767    
768                                    if (orderByComparator != null) {
769                                            query = new StringBundler(2 +
770                                                            (orderByComparator.getOrderByFields().length * 3));
771    
772                                            query.append(_SQL_SELECT_PASSWORDTRACKER);
773    
774                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
775                                                    orderByComparator);
776    
777                                            sql = query.toString();
778                                    }
779                                    else {
780                                            sql = _SQL_SELECT_PASSWORDTRACKER.concat(PasswordTrackerModelImpl.ORDER_BY_JPQL);
781                                    }
782    
783                                    Query q = session.createQuery(sql);
784    
785                                    if (orderByComparator == null) {
786                                            list = (List<PasswordTracker>)QueryUtil.list(q,
787                                                            getDialect(), start, end, false);
788    
789                                            Collections.sort(list);
790                                    }
791                                    else {
792                                            list = (List<PasswordTracker>)QueryUtil.list(q,
793                                                            getDialect(), start, end);
794                                    }
795                            }
796                            catch (Exception e) {
797                                    throw processException(e);
798                            }
799                            finally {
800                                    if (list == null) {
801                                            list = new ArrayList<PasswordTracker>();
802                                    }
803    
804                                    cacheResult(list);
805    
806                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
807    
808                                    closeSession(session);
809                            }
810                    }
811    
812                    return list;
813            }
814    
815            /**
816             * Removes all the password trackers where userId = &#63; from the database.
817             *
818             * @param userId the user id to search with
819             * @throws SystemException if a system exception occurred
820             */
821            public void removeByUserId(long userId) throws SystemException {
822                    for (PasswordTracker passwordTracker : findByUserId(userId)) {
823                            remove(passwordTracker);
824                    }
825            }
826    
827            /**
828             * Removes all the password trackers from the database.
829             *
830             * @throws SystemException if a system exception occurred
831             */
832            public void removeAll() throws SystemException {
833                    for (PasswordTracker passwordTracker : findAll()) {
834                            remove(passwordTracker);
835                    }
836            }
837    
838            /**
839             * Counts all the password trackers where userId = &#63;.
840             *
841             * @param userId the user id to search with
842             * @return the number of matching password trackers
843             * @throws SystemException if a system exception occurred
844             */
845            public int countByUserId(long userId) throws SystemException {
846                    Object[] finderArgs = new Object[] { userId };
847    
848                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
849                                    finderArgs, this);
850    
851                    if (count == null) {
852                            Session session = null;
853    
854                            try {
855                                    session = openSession();
856    
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                                    Query q = session.createQuery(sql);
866    
867                                    QueryPos qPos = QueryPos.getInstance(q);
868    
869                                    qPos.add(userId);
870    
871                                    count = (Long)q.uniqueResult();
872                            }
873                            catch (Exception e) {
874                                    throw processException(e);
875                            }
876                            finally {
877                                    if (count == null) {
878                                            count = Long.valueOf(0);
879                                    }
880    
881                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
882                                            finderArgs, count);
883    
884                                    closeSession(session);
885                            }
886                    }
887    
888                    return count.intValue();
889            }
890    
891            /**
892             * Counts all the password trackers.
893             *
894             * @return the number of password trackers
895             * @throws SystemException if a system exception occurred
896             */
897            public int countAll() throws SystemException {
898                    Object[] finderArgs = new Object[0];
899    
900                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
901                                    finderArgs, this);
902    
903                    if (count == null) {
904                            Session session = null;
905    
906                            try {
907                                    session = openSession();
908    
909                                    Query q = session.createQuery(_SQL_COUNT_PASSWORDTRACKER);
910    
911                                    count = (Long)q.uniqueResult();
912                            }
913                            catch (Exception e) {
914                                    throw processException(e);
915                            }
916                            finally {
917                                    if (count == null) {
918                                            count = Long.valueOf(0);
919                                    }
920    
921                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
922                                            count);
923    
924                                    closeSession(session);
925                            }
926                    }
927    
928                    return count.intValue();
929            }
930    
931            /**
932             * Initializes the password tracker persistence.
933             */
934            public void afterPropertiesSet() {
935                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
936                                            com.liferay.portal.util.PropsUtil.get(
937                                                    "value.object.listener.com.liferay.portal.model.PasswordTracker")));
938    
939                    if (listenerClassNames.length > 0) {
940                            try {
941                                    List<ModelListener<PasswordTracker>> listenersList = new ArrayList<ModelListener<PasswordTracker>>();
942    
943                                    for (String listenerClassName : listenerClassNames) {
944                                            listenersList.add((ModelListener<PasswordTracker>)InstanceFactory.newInstance(
945                                                            listenerClassName));
946                                    }
947    
948                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
949                            }
950                            catch (Exception e) {
951                                    _log.error(e);
952                            }
953                    }
954            }
955    
956            public void destroy() {
957                    EntityCacheUtil.removeCache(PasswordTrackerImpl.class.getName());
958                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
959                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
960            }
961    
962            @BeanReference(type = AccountPersistence.class)
963            protected AccountPersistence accountPersistence;
964            @BeanReference(type = AddressPersistence.class)
965            protected AddressPersistence addressPersistence;
966            @BeanReference(type = BrowserTrackerPersistence.class)
967            protected BrowserTrackerPersistence browserTrackerPersistence;
968            @BeanReference(type = ClassNamePersistence.class)
969            protected ClassNamePersistence classNamePersistence;
970            @BeanReference(type = ClusterGroupPersistence.class)
971            protected ClusterGroupPersistence clusterGroupPersistence;
972            @BeanReference(type = CompanyPersistence.class)
973            protected CompanyPersistence companyPersistence;
974            @BeanReference(type = ContactPersistence.class)
975            protected ContactPersistence contactPersistence;
976            @BeanReference(type = CountryPersistence.class)
977            protected CountryPersistence countryPersistence;
978            @BeanReference(type = EmailAddressPersistence.class)
979            protected EmailAddressPersistence emailAddressPersistence;
980            @BeanReference(type = GroupPersistence.class)
981            protected GroupPersistence groupPersistence;
982            @BeanReference(type = ImagePersistence.class)
983            protected ImagePersistence imagePersistence;
984            @BeanReference(type = LayoutPersistence.class)
985            protected LayoutPersistence layoutPersistence;
986            @BeanReference(type = LayoutPrototypePersistence.class)
987            protected LayoutPrototypePersistence layoutPrototypePersistence;
988            @BeanReference(type = LayoutSetPersistence.class)
989            protected LayoutSetPersistence layoutSetPersistence;
990            @BeanReference(type = LayoutSetPrototypePersistence.class)
991            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
992            @BeanReference(type = ListTypePersistence.class)
993            protected ListTypePersistence listTypePersistence;
994            @BeanReference(type = LockPersistence.class)
995            protected LockPersistence lockPersistence;
996            @BeanReference(type = MembershipRequestPersistence.class)
997            protected MembershipRequestPersistence membershipRequestPersistence;
998            @BeanReference(type = OrganizationPersistence.class)
999            protected OrganizationPersistence organizationPersistence;
1000            @BeanReference(type = OrgGroupPermissionPersistence.class)
1001            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1002            @BeanReference(type = OrgGroupRolePersistence.class)
1003            protected OrgGroupRolePersistence orgGroupRolePersistence;
1004            @BeanReference(type = OrgLaborPersistence.class)
1005            protected OrgLaborPersistence orgLaborPersistence;
1006            @BeanReference(type = PasswordPolicyPersistence.class)
1007            protected PasswordPolicyPersistence passwordPolicyPersistence;
1008            @BeanReference(type = PasswordPolicyRelPersistence.class)
1009            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1010            @BeanReference(type = PasswordTrackerPersistence.class)
1011            protected PasswordTrackerPersistence passwordTrackerPersistence;
1012            @BeanReference(type = PermissionPersistence.class)
1013            protected PermissionPersistence permissionPersistence;
1014            @BeanReference(type = PhonePersistence.class)
1015            protected PhonePersistence phonePersistence;
1016            @BeanReference(type = PluginSettingPersistence.class)
1017            protected PluginSettingPersistence pluginSettingPersistence;
1018            @BeanReference(type = PortletPersistence.class)
1019            protected PortletPersistence portletPersistence;
1020            @BeanReference(type = PortletItemPersistence.class)
1021            protected PortletItemPersistence portletItemPersistence;
1022            @BeanReference(type = PortletPreferencesPersistence.class)
1023            protected PortletPreferencesPersistence portletPreferencesPersistence;
1024            @BeanReference(type = RegionPersistence.class)
1025            protected RegionPersistence regionPersistence;
1026            @BeanReference(type = ReleasePersistence.class)
1027            protected ReleasePersistence releasePersistence;
1028            @BeanReference(type = ResourcePersistence.class)
1029            protected ResourcePersistence resourcePersistence;
1030            @BeanReference(type = ResourceActionPersistence.class)
1031            protected ResourceActionPersistence resourceActionPersistence;
1032            @BeanReference(type = ResourceCodePersistence.class)
1033            protected ResourceCodePersistence resourceCodePersistence;
1034            @BeanReference(type = ResourcePermissionPersistence.class)
1035            protected ResourcePermissionPersistence resourcePermissionPersistence;
1036            @BeanReference(type = RolePersistence.class)
1037            protected RolePersistence rolePersistence;
1038            @BeanReference(type = ServiceComponentPersistence.class)
1039            protected ServiceComponentPersistence serviceComponentPersistence;
1040            @BeanReference(type = ShardPersistence.class)
1041            protected ShardPersistence shardPersistence;
1042            @BeanReference(type = SubscriptionPersistence.class)
1043            protected SubscriptionPersistence subscriptionPersistence;
1044            @BeanReference(type = TicketPersistence.class)
1045            protected TicketPersistence ticketPersistence;
1046            @BeanReference(type = TeamPersistence.class)
1047            protected TeamPersistence teamPersistence;
1048            @BeanReference(type = UserPersistence.class)
1049            protected UserPersistence userPersistence;
1050            @BeanReference(type = UserGroupPersistence.class)
1051            protected UserGroupPersistence userGroupPersistence;
1052            @BeanReference(type = UserGroupGroupRolePersistence.class)
1053            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1054            @BeanReference(type = UserGroupRolePersistence.class)
1055            protected UserGroupRolePersistence userGroupRolePersistence;
1056            @BeanReference(type = UserIdMapperPersistence.class)
1057            protected UserIdMapperPersistence userIdMapperPersistence;
1058            @BeanReference(type = UserTrackerPersistence.class)
1059            protected UserTrackerPersistence userTrackerPersistence;
1060            @BeanReference(type = UserTrackerPathPersistence.class)
1061            protected UserTrackerPathPersistence userTrackerPathPersistence;
1062            @BeanReference(type = WebDAVPropsPersistence.class)
1063            protected WebDAVPropsPersistence webDAVPropsPersistence;
1064            @BeanReference(type = WebsitePersistence.class)
1065            protected WebsitePersistence websitePersistence;
1066            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1067            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1068            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1069            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1070            private static final String _SQL_SELECT_PASSWORDTRACKER = "SELECT passwordTracker FROM PasswordTracker passwordTracker";
1071            private static final String _SQL_SELECT_PASSWORDTRACKER_WHERE = "SELECT passwordTracker FROM PasswordTracker passwordTracker WHERE ";
1072            private static final String _SQL_COUNT_PASSWORDTRACKER = "SELECT COUNT(passwordTracker) FROM PasswordTracker passwordTracker";
1073            private static final String _SQL_COUNT_PASSWORDTRACKER_WHERE = "SELECT COUNT(passwordTracker) FROM PasswordTracker passwordTracker WHERE ";
1074            private static final String _FINDER_COLUMN_USERID_USERID_2 = "passwordTracker.userId = ?";
1075            private static final String _ORDER_BY_ENTITY_ALIAS = "passwordTracker.";
1076            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PasswordTracker exists with the primary key ";
1077            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PasswordTracker exists with the key {";
1078            private static Log _log = LogFactoryUtil.getLog(PasswordTrackerPersistenceImpl.class);
1079    }