001    /**
002     * Copyright (c) 2000-2012 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.NoSuchPasswordTrackerException;
018    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderPath;
022    import com.liferay.portal.kernel.dao.orm.Query;
023    import com.liferay.portal.kernel.dao.orm.QueryPos;
024    import com.liferay.portal.kernel.dao.orm.QueryUtil;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.exception.SystemException;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.GetterUtil;
030    import com.liferay.portal.kernel.util.InstanceFactory;
031    import com.liferay.portal.kernel.util.OrderByComparator;
032    import com.liferay.portal.kernel.util.StringBundler;
033    import com.liferay.portal.kernel.util.StringPool;
034    import com.liferay.portal.kernel.util.StringUtil;
035    import com.liferay.portal.kernel.util.UnmodifiableList;
036    import com.liferay.portal.model.CacheModel;
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     * Caching information and settings can be found in <code>portal.properties</code>
054     * </p>
055     *
056     * @author Brian Wing Shun Chan
057     * @see PasswordTrackerPersistence
058     * @see PasswordTrackerUtil
059     * @generated
060     */
061    public class PasswordTrackerPersistenceImpl extends BasePersistenceImpl<PasswordTracker>
062            implements PasswordTrackerPersistence {
063            /*
064             * NOTE FOR DEVELOPERS:
065             *
066             * 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.
067             */
068            public static final String FINDER_CLASS_NAME_ENTITY = PasswordTrackerImpl.class.getName();
069            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
070                    ".List1";
071            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072                    ".List2";
073            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
074                            PasswordTrackerModelImpl.FINDER_CACHE_ENABLED,
075                            PasswordTrackerImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
076                            "findAll", new String[0]);
077            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
078                            PasswordTrackerModelImpl.FINDER_CACHE_ENABLED,
079                            PasswordTrackerImpl.class,
080                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
081            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
082                            PasswordTrackerModelImpl.FINDER_CACHE_ENABLED, Long.class,
083                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
084            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
085                            PasswordTrackerModelImpl.FINDER_CACHE_ENABLED,
086                            PasswordTrackerImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
087                            "findByUserId",
088                            new String[] {
089                                    Long.class.getName(),
090                                    
091                            Integer.class.getName(), Integer.class.getName(),
092                                    OrderByComparator.class.getName()
093                            });
094            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
095                    new FinderPath(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
096                            PasswordTrackerModelImpl.FINDER_CACHE_ENABLED,
097                            PasswordTrackerImpl.class,
098                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
099                            new String[] { Long.class.getName() },
100                            PasswordTrackerModelImpl.USERID_COLUMN_BITMASK |
101                            PasswordTrackerModelImpl.CREATEDATE_COLUMN_BITMASK);
102            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
103                            PasswordTrackerModelImpl.FINDER_CACHE_ENABLED, Long.class,
104                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
105                            new String[] { Long.class.getName() });
106    
107            /**
108             * Returns all the password trackers where userId = &#63;.
109             *
110             * @param userId the user ID
111             * @return the matching password trackers
112             * @throws SystemException if a system exception occurred
113             */
114            public List<PasswordTracker> findByUserId(long userId)
115                    throws SystemException {
116                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
117            }
118    
119            /**
120             * Returns a range of all the password trackers where userId = &#63;.
121             *
122             * <p>
123             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.PasswordTrackerModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
124             * </p>
125             *
126             * @param userId the user ID
127             * @param start the lower bound of the range of password trackers
128             * @param end the upper bound of the range of password trackers (not inclusive)
129             * @return the range of matching password trackers
130             * @throws SystemException if a system exception occurred
131             */
132            public List<PasswordTracker> findByUserId(long userId, int start, int end)
133                    throws SystemException {
134                    return findByUserId(userId, start, end, null);
135            }
136    
137            /**
138             * Returns an ordered range of all the password trackers where userId = &#63;.
139             *
140             * <p>
141             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.PasswordTrackerModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
142             * </p>
143             *
144             * @param userId the user ID
145             * @param start the lower bound of the range of password trackers
146             * @param end the upper bound of the range of password trackers (not inclusive)
147             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
148             * @return the ordered range of matching password trackers
149             * @throws SystemException if a system exception occurred
150             */
151            public List<PasswordTracker> findByUserId(long userId, int start, int end,
152                    OrderByComparator orderByComparator) throws SystemException {
153                    boolean pagination = true;
154                    FinderPath finderPath = null;
155                    Object[] finderArgs = null;
156    
157                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
158                                    (orderByComparator == null)) {
159                            pagination = false;
160                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
161                            finderArgs = new Object[] { userId };
162                    }
163                    else {
164                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
165                            finderArgs = new Object[] { userId, start, end, orderByComparator };
166                    }
167    
168                    List<PasswordTracker> list = (List<PasswordTracker>)FinderCacheUtil.getResult(finderPath,
169                                    finderArgs, this);
170    
171                    if ((list != null) && !list.isEmpty()) {
172                            for (PasswordTracker passwordTracker : list) {
173                                    if ((userId != passwordTracker.getUserId())) {
174                                            list = null;
175    
176                                            break;
177                                    }
178                            }
179                    }
180    
181                    if (list == null) {
182                            StringBundler query = null;
183    
184                            if (orderByComparator != null) {
185                                    query = new StringBundler(3 +
186                                                    (orderByComparator.getOrderByFields().length * 3));
187                            }
188                            else {
189                                    query = new StringBundler(3);
190                            }
191    
192                            query.append(_SQL_SELECT_PASSWORDTRACKER_WHERE);
193    
194                            query.append(_FINDER_COLUMN_USERID_USERID_2);
195    
196                            if (orderByComparator != null) {
197                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
198                                            orderByComparator);
199                            }
200                            else
201                             if (pagination) {
202                                    query.append(PasswordTrackerModelImpl.ORDER_BY_JPQL);
203                            }
204    
205                            String sql = query.toString();
206    
207                            Session session = null;
208    
209                            try {
210                                    session = openSession();
211    
212                                    Query q = session.createQuery(sql);
213    
214                                    QueryPos qPos = QueryPos.getInstance(q);
215    
216                                    qPos.add(userId);
217    
218                                    if (!pagination) {
219                                            list = (List<PasswordTracker>)QueryUtil.list(q,
220                                                            getDialect(), start, end, false);
221    
222                                            Collections.sort(list);
223    
224                                            list = new UnmodifiableList<PasswordTracker>(list);
225                                    }
226                                    else {
227                                            list = (List<PasswordTracker>)QueryUtil.list(q,
228                                                            getDialect(), start, end);
229                                    }
230    
231                                    cacheResult(list);
232    
233                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
234                            }
235                            catch (Exception e) {
236                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
237    
238                                    throw processException(e);
239                            }
240                            finally {
241                                    closeSession(session);
242                            }
243                    }
244    
245                    return list;
246            }
247    
248            /**
249             * Returns the first password tracker in the ordered set where userId = &#63;.
250             *
251             * @param userId the user ID
252             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
253             * @return the first matching password tracker
254             * @throws com.liferay.portal.NoSuchPasswordTrackerException if a matching password tracker could not be found
255             * @throws SystemException if a system exception occurred
256             */
257            public PasswordTracker findByUserId_First(long userId,
258                    OrderByComparator orderByComparator)
259                    throws NoSuchPasswordTrackerException, SystemException {
260                    PasswordTracker passwordTracker = fetchByUserId_First(userId,
261                                    orderByComparator);
262    
263                    if (passwordTracker != null) {
264                            return passwordTracker;
265                    }
266    
267                    StringBundler msg = new StringBundler(4);
268    
269                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
270    
271                    msg.append("userId=");
272                    msg.append(userId);
273    
274                    msg.append(StringPool.CLOSE_CURLY_BRACE);
275    
276                    throw new NoSuchPasswordTrackerException(msg.toString());
277            }
278    
279            /**
280             * Returns the first password tracker in the ordered set where userId = &#63;.
281             *
282             * @param userId the user ID
283             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
284             * @return the first matching password tracker, or <code>null</code> if a matching password tracker could not be found
285             * @throws SystemException if a system exception occurred
286             */
287            public PasswordTracker fetchByUserId_First(long userId,
288                    OrderByComparator orderByComparator) throws SystemException {
289                    List<PasswordTracker> list = findByUserId(userId, 0, 1,
290                                    orderByComparator);
291    
292                    if (!list.isEmpty()) {
293                            return list.get(0);
294                    }
295    
296                    return null;
297            }
298    
299            /**
300             * Returns the last password tracker in the ordered set where userId = &#63;.
301             *
302             * @param userId the user ID
303             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
304             * @return the last matching password tracker
305             * @throws com.liferay.portal.NoSuchPasswordTrackerException if a matching password tracker could not be found
306             * @throws SystemException if a system exception occurred
307             */
308            public PasswordTracker findByUserId_Last(long userId,
309                    OrderByComparator orderByComparator)
310                    throws NoSuchPasswordTrackerException, SystemException {
311                    PasswordTracker passwordTracker = fetchByUserId_Last(userId,
312                                    orderByComparator);
313    
314                    if (passwordTracker != null) {
315                            return passwordTracker;
316                    }
317    
318                    StringBundler msg = new StringBundler(4);
319    
320                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
321    
322                    msg.append("userId=");
323                    msg.append(userId);
324    
325                    msg.append(StringPool.CLOSE_CURLY_BRACE);
326    
327                    throw new NoSuchPasswordTrackerException(msg.toString());
328            }
329    
330            /**
331             * Returns the last password tracker in the ordered set where userId = &#63;.
332             *
333             * @param userId the user ID
334             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
335             * @return the last matching password tracker, or <code>null</code> if a matching password tracker could not be found
336             * @throws SystemException if a system exception occurred
337             */
338            public PasswordTracker fetchByUserId_Last(long userId,
339                    OrderByComparator orderByComparator) throws SystemException {
340                    int count = countByUserId(userId);
341    
342                    List<PasswordTracker> list = findByUserId(userId, count - 1, count,
343                                    orderByComparator);
344    
345                    if (!list.isEmpty()) {
346                            return list.get(0);
347                    }
348    
349                    return null;
350            }
351    
352            /**
353             * Returns the password trackers before and after the current password tracker in the ordered set where userId = &#63;.
354             *
355             * @param passwordTrackerId the primary key of the current password tracker
356             * @param userId the user ID
357             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
358             * @return the previous, current, and next password tracker
359             * @throws com.liferay.portal.NoSuchPasswordTrackerException if a password tracker with the primary key could not be found
360             * @throws SystemException if a system exception occurred
361             */
362            public PasswordTracker[] findByUserId_PrevAndNext(long passwordTrackerId,
363                    long userId, OrderByComparator orderByComparator)
364                    throws NoSuchPasswordTrackerException, SystemException {
365                    PasswordTracker passwordTracker = findByPrimaryKey(passwordTrackerId);
366    
367                    Session session = null;
368    
369                    try {
370                            session = openSession();
371    
372                            PasswordTracker[] array = new PasswordTrackerImpl[3];
373    
374                            array[0] = getByUserId_PrevAndNext(session, passwordTracker,
375                                            userId, orderByComparator, true);
376    
377                            array[1] = passwordTracker;
378    
379                            array[2] = getByUserId_PrevAndNext(session, passwordTracker,
380                                            userId, orderByComparator, false);
381    
382                            return array;
383                    }
384                    catch (Exception e) {
385                            throw processException(e);
386                    }
387                    finally {
388                            closeSession(session);
389                    }
390            }
391    
392            protected PasswordTracker getByUserId_PrevAndNext(Session session,
393                    PasswordTracker passwordTracker, long userId,
394                    OrderByComparator orderByComparator, boolean previous) {
395                    StringBundler query = null;
396    
397                    if (orderByComparator != null) {
398                            query = new StringBundler(6 +
399                                            (orderByComparator.getOrderByFields().length * 6));
400                    }
401                    else {
402                            query = new StringBundler(3);
403                    }
404    
405                    query.append(_SQL_SELECT_PASSWORDTRACKER_WHERE);
406    
407                    query.append(_FINDER_COLUMN_USERID_USERID_2);
408    
409                    if (orderByComparator != null) {
410                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
411    
412                            if (orderByConditionFields.length > 0) {
413                                    query.append(WHERE_AND);
414                            }
415    
416                            for (int i = 0; i < orderByConditionFields.length; i++) {
417                                    query.append(_ORDER_BY_ENTITY_ALIAS);
418                                    query.append(orderByConditionFields[i]);
419    
420                                    if ((i + 1) < orderByConditionFields.length) {
421                                            if (orderByComparator.isAscending() ^ previous) {
422                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
423                                            }
424                                            else {
425                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
426                                            }
427                                    }
428                                    else {
429                                            if (orderByComparator.isAscending() ^ previous) {
430                                                    query.append(WHERE_GREATER_THAN);
431                                            }
432                                            else {
433                                                    query.append(WHERE_LESSER_THAN);
434                                            }
435                                    }
436                            }
437    
438                            query.append(ORDER_BY_CLAUSE);
439    
440                            String[] orderByFields = orderByComparator.getOrderByFields();
441    
442                            for (int i = 0; i < orderByFields.length; i++) {
443                                    query.append(_ORDER_BY_ENTITY_ALIAS);
444                                    query.append(orderByFields[i]);
445    
446                                    if ((i + 1) < orderByFields.length) {
447                                            if (orderByComparator.isAscending() ^ previous) {
448                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
449                                            }
450                                            else {
451                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
452                                            }
453                                    }
454                                    else {
455                                            if (orderByComparator.isAscending() ^ previous) {
456                                                    query.append(ORDER_BY_ASC);
457                                            }
458                                            else {
459                                                    query.append(ORDER_BY_DESC);
460                                            }
461                                    }
462                            }
463                    }
464                    else {
465                            query.append(PasswordTrackerModelImpl.ORDER_BY_JPQL);
466                    }
467    
468                    String sql = query.toString();
469    
470                    Query q = session.createQuery(sql);
471    
472                    q.setFirstResult(0);
473                    q.setMaxResults(2);
474    
475                    QueryPos qPos = QueryPos.getInstance(q);
476    
477                    qPos.add(userId);
478    
479                    if (orderByComparator != null) {
480                            Object[] values = orderByComparator.getOrderByConditionValues(passwordTracker);
481    
482                            for (Object value : values) {
483                                    qPos.add(value);
484                            }
485                    }
486    
487                    List<PasswordTracker> list = q.list();
488    
489                    if (list.size() == 2) {
490                            return list.get(1);
491                    }
492                    else {
493                            return null;
494                    }
495            }
496    
497            /**
498             * Removes all the password trackers where userId = &#63; from the database.
499             *
500             * @param userId the user ID
501             * @throws SystemException if a system exception occurred
502             */
503            public void removeByUserId(long userId) throws SystemException {
504                    for (PasswordTracker passwordTracker : findByUserId(userId,
505                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
506                            remove(passwordTracker);
507                    }
508            }
509    
510            /**
511             * Returns the number of password trackers where userId = &#63;.
512             *
513             * @param userId the user ID
514             * @return the number of matching password trackers
515             * @throws SystemException if a system exception occurred
516             */
517            public int countByUserId(long userId) throws SystemException {
518                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
519    
520                    Object[] finderArgs = new Object[] { userId };
521    
522                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
523                                    this);
524    
525                    if (count == null) {
526                            StringBundler query = new StringBundler(2);
527    
528                            query.append(_SQL_COUNT_PASSWORDTRACKER_WHERE);
529    
530                            query.append(_FINDER_COLUMN_USERID_USERID_2);
531    
532                            String sql = query.toString();
533    
534                            Session session = null;
535    
536                            try {
537                                    session = openSession();
538    
539                                    Query q = session.createQuery(sql);
540    
541                                    QueryPos qPos = QueryPos.getInstance(q);
542    
543                                    qPos.add(userId);
544    
545                                    count = (Long)q.uniqueResult();
546    
547                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
548                            }
549                            catch (Exception e) {
550                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
551    
552                                    throw processException(e);
553                            }
554                            finally {
555                                    closeSession(session);
556                            }
557                    }
558    
559                    return count.intValue();
560            }
561    
562            private static final String _FINDER_COLUMN_USERID_USERID_2 = "passwordTracker.userId = ?";
563    
564            /**
565             * Caches the password tracker in the entity cache if it is enabled.
566             *
567             * @param passwordTracker the password tracker
568             */
569            public void cacheResult(PasswordTracker passwordTracker) {
570                    EntityCacheUtil.putResult(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
571                            PasswordTrackerImpl.class, passwordTracker.getPrimaryKey(),
572                            passwordTracker);
573    
574                    passwordTracker.resetOriginalValues();
575            }
576    
577            /**
578             * Caches the password trackers in the entity cache if it is enabled.
579             *
580             * @param passwordTrackers the password trackers
581             */
582            public void cacheResult(List<PasswordTracker> passwordTrackers) {
583                    for (PasswordTracker passwordTracker : passwordTrackers) {
584                            if (EntityCacheUtil.getResult(
585                                                    PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
586                                                    PasswordTrackerImpl.class,
587                                                    passwordTracker.getPrimaryKey()) == null) {
588                                    cacheResult(passwordTracker);
589                            }
590                            else {
591                                    passwordTracker.resetOriginalValues();
592                            }
593                    }
594            }
595    
596            /**
597             * Clears the cache for all password trackers.
598             *
599             * <p>
600             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
601             * </p>
602             */
603            @Override
604            public void clearCache() {
605                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
606                            CacheRegistryUtil.clear(PasswordTrackerImpl.class.getName());
607                    }
608    
609                    EntityCacheUtil.clearCache(PasswordTrackerImpl.class.getName());
610    
611                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
612                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
613                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
614            }
615    
616            /**
617             * Clears the cache for the password tracker.
618             *
619             * <p>
620             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
621             * </p>
622             */
623            @Override
624            public void clearCache(PasswordTracker passwordTracker) {
625                    EntityCacheUtil.removeResult(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
626                            PasswordTrackerImpl.class, passwordTracker.getPrimaryKey());
627    
628                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
629                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
630            }
631    
632            @Override
633            public void clearCache(List<PasswordTracker> passwordTrackers) {
634                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
635                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
636    
637                    for (PasswordTracker passwordTracker : passwordTrackers) {
638                            EntityCacheUtil.removeResult(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
639                                    PasswordTrackerImpl.class, passwordTracker.getPrimaryKey());
640                    }
641            }
642    
643            /**
644             * Creates a new password tracker with the primary key. Does not add the password tracker to the database.
645             *
646             * @param passwordTrackerId the primary key for the new password tracker
647             * @return the new password tracker
648             */
649            public PasswordTracker create(long passwordTrackerId) {
650                    PasswordTracker passwordTracker = new PasswordTrackerImpl();
651    
652                    passwordTracker.setNew(true);
653                    passwordTracker.setPrimaryKey(passwordTrackerId);
654    
655                    return passwordTracker;
656            }
657    
658            /**
659             * Removes the password tracker with the primary key from the database. Also notifies the appropriate model listeners.
660             *
661             * @param passwordTrackerId the primary key of the password tracker
662             * @return the password tracker that was removed
663             * @throws com.liferay.portal.NoSuchPasswordTrackerException if a password tracker with the primary key could not be found
664             * @throws SystemException if a system exception occurred
665             */
666            public PasswordTracker remove(long passwordTrackerId)
667                    throws NoSuchPasswordTrackerException, SystemException {
668                    return remove((Serializable)passwordTrackerId);
669            }
670    
671            /**
672             * Removes the password tracker with the primary key from the database. Also notifies the appropriate model listeners.
673             *
674             * @param primaryKey the primary key of the password tracker
675             * @return the password tracker that was removed
676             * @throws com.liferay.portal.NoSuchPasswordTrackerException if a password tracker with the primary key could not be found
677             * @throws SystemException if a system exception occurred
678             */
679            @Override
680            public PasswordTracker remove(Serializable primaryKey)
681                    throws NoSuchPasswordTrackerException, SystemException {
682                    Session session = null;
683    
684                    try {
685                            session = openSession();
686    
687                            PasswordTracker passwordTracker = (PasswordTracker)session.get(PasswordTrackerImpl.class,
688                                            primaryKey);
689    
690                            if (passwordTracker == null) {
691                                    if (_log.isWarnEnabled()) {
692                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
693                                    }
694    
695                                    throw new NoSuchPasswordTrackerException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
696                                            primaryKey);
697                            }
698    
699                            return remove(passwordTracker);
700                    }
701                    catch (NoSuchPasswordTrackerException nsee) {
702                            throw nsee;
703                    }
704                    catch (Exception e) {
705                            throw processException(e);
706                    }
707                    finally {
708                            closeSession(session);
709                    }
710            }
711    
712            @Override
713            protected PasswordTracker removeImpl(PasswordTracker passwordTracker)
714                    throws SystemException {
715                    passwordTracker = toUnwrappedModel(passwordTracker);
716    
717                    Session session = null;
718    
719                    try {
720                            session = openSession();
721    
722                            if (!session.contains(passwordTracker)) {
723                                    passwordTracker = (PasswordTracker)session.get(PasswordTrackerImpl.class,
724                                                    passwordTracker.getPrimaryKeyObj());
725                            }
726    
727                            if (passwordTracker != null) {
728                                    session.delete(passwordTracker);
729                            }
730                    }
731                    catch (Exception e) {
732                            throw processException(e);
733                    }
734                    finally {
735                            closeSession(session);
736                    }
737    
738                    if (passwordTracker != null) {
739                            clearCache(passwordTracker);
740                    }
741    
742                    return passwordTracker;
743            }
744    
745            @Override
746            public PasswordTracker updateImpl(
747                    com.liferay.portal.model.PasswordTracker passwordTracker)
748                    throws SystemException {
749                    passwordTracker = toUnwrappedModel(passwordTracker);
750    
751                    boolean isNew = passwordTracker.isNew();
752    
753                    PasswordTrackerModelImpl passwordTrackerModelImpl = (PasswordTrackerModelImpl)passwordTracker;
754    
755                    Session session = null;
756    
757                    try {
758                            session = openSession();
759    
760                            if (passwordTracker.isNew()) {
761                                    session.save(passwordTracker);
762    
763                                    passwordTracker.setNew(false);
764                            }
765                            else {
766                                    session.merge(passwordTracker);
767                            }
768                    }
769                    catch (Exception e) {
770                            throw processException(e);
771                    }
772                    finally {
773                            closeSession(session);
774                    }
775    
776                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
777    
778                    if (isNew || !PasswordTrackerModelImpl.COLUMN_BITMASK_ENABLED) {
779                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
780                    }
781    
782                    else {
783                            if ((passwordTrackerModelImpl.getColumnBitmask() &
784                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
785                                    Object[] args = new Object[] {
786                                                    passwordTrackerModelImpl.getOriginalUserId()
787                                            };
788    
789                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
790                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
791                                            args);
792    
793                                    args = new Object[] { passwordTrackerModelImpl.getUserId() };
794    
795                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
796                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
797                                            args);
798                            }
799                    }
800    
801                    EntityCacheUtil.putResult(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
802                            PasswordTrackerImpl.class, passwordTracker.getPrimaryKey(),
803                            passwordTracker);
804    
805                    return passwordTracker;
806            }
807    
808            protected PasswordTracker toUnwrappedModel(PasswordTracker passwordTracker) {
809                    if (passwordTracker instanceof PasswordTrackerImpl) {
810                            return passwordTracker;
811                    }
812    
813                    PasswordTrackerImpl passwordTrackerImpl = new PasswordTrackerImpl();
814    
815                    passwordTrackerImpl.setNew(passwordTracker.isNew());
816                    passwordTrackerImpl.setPrimaryKey(passwordTracker.getPrimaryKey());
817    
818                    passwordTrackerImpl.setPasswordTrackerId(passwordTracker.getPasswordTrackerId());
819                    passwordTrackerImpl.setUserId(passwordTracker.getUserId());
820                    passwordTrackerImpl.setCreateDate(passwordTracker.getCreateDate());
821                    passwordTrackerImpl.setPassword(passwordTracker.getPassword());
822    
823                    return passwordTrackerImpl;
824            }
825    
826            /**
827             * Returns the password tracker with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
828             *
829             * @param primaryKey the primary key of the password tracker
830             * @return the password tracker
831             * @throws com.liferay.portal.NoSuchPasswordTrackerException if a password tracker with the primary key could not be found
832             * @throws SystemException if a system exception occurred
833             */
834            @Override
835            public PasswordTracker findByPrimaryKey(Serializable primaryKey)
836                    throws NoSuchPasswordTrackerException, SystemException {
837                    PasswordTracker passwordTracker = fetchByPrimaryKey(primaryKey);
838    
839                    if (passwordTracker == null) {
840                            if (_log.isWarnEnabled()) {
841                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
842                            }
843    
844                            throw new NoSuchPasswordTrackerException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
845                                    primaryKey);
846                    }
847    
848                    return passwordTracker;
849            }
850    
851            /**
852             * Returns the password tracker with the primary key or throws a {@link com.liferay.portal.NoSuchPasswordTrackerException} if it could not be found.
853             *
854             * @param passwordTrackerId the primary key of the password tracker
855             * @return the password tracker
856             * @throws com.liferay.portal.NoSuchPasswordTrackerException if a password tracker with the primary key could not be found
857             * @throws SystemException if a system exception occurred
858             */
859            public PasswordTracker findByPrimaryKey(long passwordTrackerId)
860                    throws NoSuchPasswordTrackerException, SystemException {
861                    return findByPrimaryKey((Serializable)passwordTrackerId);
862            }
863    
864            /**
865             * Returns the password tracker with the primary key or returns <code>null</code> if it could not be found.
866             *
867             * @param primaryKey the primary key of the password tracker
868             * @return the password tracker, or <code>null</code> if a password tracker with the primary key could not be found
869             * @throws SystemException if a system exception occurred
870             */
871            @Override
872            public PasswordTracker fetchByPrimaryKey(Serializable primaryKey)
873                    throws SystemException {
874                    PasswordTracker passwordTracker = (PasswordTracker)EntityCacheUtil.getResult(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
875                                    PasswordTrackerImpl.class, primaryKey);
876    
877                    if (passwordTracker == _nullPasswordTracker) {
878                            return null;
879                    }
880    
881                    if (passwordTracker == null) {
882                            Session session = null;
883    
884                            try {
885                                    session = openSession();
886    
887                                    passwordTracker = (PasswordTracker)session.get(PasswordTrackerImpl.class,
888                                                    primaryKey);
889    
890                                    if (passwordTracker != null) {
891                                            cacheResult(passwordTracker);
892                                    }
893                                    else {
894                                            EntityCacheUtil.putResult(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
895                                                    PasswordTrackerImpl.class, primaryKey,
896                                                    _nullPasswordTracker);
897                                    }
898                            }
899                            catch (Exception e) {
900                                    EntityCacheUtil.removeResult(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
901                                            PasswordTrackerImpl.class, primaryKey);
902    
903                                    throw processException(e);
904                            }
905                            finally {
906                                    closeSession(session);
907                            }
908                    }
909    
910                    return passwordTracker;
911            }
912    
913            /**
914             * Returns the password tracker with the primary key or returns <code>null</code> if it could not be found.
915             *
916             * @param passwordTrackerId the primary key of the password tracker
917             * @return the password tracker, or <code>null</code> if a password tracker with the primary key could not be found
918             * @throws SystemException if a system exception occurred
919             */
920            public PasswordTracker fetchByPrimaryKey(long passwordTrackerId)
921                    throws SystemException {
922                    return fetchByPrimaryKey((Serializable)passwordTrackerId);
923            }
924    
925            /**
926             * Returns all the password trackers.
927             *
928             * @return the password trackers
929             * @throws SystemException if a system exception occurred
930             */
931            public List<PasswordTracker> findAll() throws SystemException {
932                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
933            }
934    
935            /**
936             * Returns a range of all the password trackers.
937             *
938             * <p>
939             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.PasswordTrackerModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
940             * </p>
941             *
942             * @param start the lower bound of the range of password trackers
943             * @param end the upper bound of the range of password trackers (not inclusive)
944             * @return the range of password trackers
945             * @throws SystemException if a system exception occurred
946             */
947            public List<PasswordTracker> findAll(int start, int end)
948                    throws SystemException {
949                    return findAll(start, end, null);
950            }
951    
952            /**
953             * Returns an ordered range of all the password trackers.
954             *
955             * <p>
956             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.PasswordTrackerModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
957             * </p>
958             *
959             * @param start the lower bound of the range of password trackers
960             * @param end the upper bound of the range of password trackers (not inclusive)
961             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
962             * @return the ordered range of password trackers
963             * @throws SystemException if a system exception occurred
964             */
965            public List<PasswordTracker> findAll(int start, int end,
966                    OrderByComparator orderByComparator) throws SystemException {
967                    boolean pagination = true;
968                    FinderPath finderPath = null;
969                    Object[] finderArgs = null;
970    
971                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
972                                    (orderByComparator == null)) {
973                            pagination = false;
974                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
975                            finderArgs = FINDER_ARGS_EMPTY;
976                    }
977                    else {
978                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
979                            finderArgs = new Object[] { start, end, orderByComparator };
980                    }
981    
982                    List<PasswordTracker> list = (List<PasswordTracker>)FinderCacheUtil.getResult(finderPath,
983                                    finderArgs, this);
984    
985                    if (list == null) {
986                            StringBundler query = null;
987                            String sql = null;
988    
989                            if (orderByComparator != null) {
990                                    query = new StringBundler(2 +
991                                                    (orderByComparator.getOrderByFields().length * 3));
992    
993                                    query.append(_SQL_SELECT_PASSWORDTRACKER);
994    
995                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
996                                            orderByComparator);
997    
998                                    sql = query.toString();
999                            }
1000                            else {
1001                                    sql = _SQL_SELECT_PASSWORDTRACKER;
1002    
1003                                    if (pagination) {
1004                                            sql = sql.concat(PasswordTrackerModelImpl.ORDER_BY_JPQL);
1005                                    }
1006                            }
1007    
1008                            Session session = null;
1009    
1010                            try {
1011                                    session = openSession();
1012    
1013                                    Query q = session.createQuery(sql);
1014    
1015                                    if (!pagination) {
1016                                            list = (List<PasswordTracker>)QueryUtil.list(q,
1017                                                            getDialect(), start, end, false);
1018    
1019                                            Collections.sort(list);
1020    
1021                                            list = new UnmodifiableList<PasswordTracker>(list);
1022                                    }
1023                                    else {
1024                                            list = (List<PasswordTracker>)QueryUtil.list(q,
1025                                                            getDialect(), start, end);
1026                                    }
1027    
1028                                    cacheResult(list);
1029    
1030                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1031                            }
1032                            catch (Exception e) {
1033                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1034    
1035                                    throw processException(e);
1036                            }
1037                            finally {
1038                                    closeSession(session);
1039                            }
1040                    }
1041    
1042                    return list;
1043            }
1044    
1045            /**
1046             * Removes all the password trackers from the database.
1047             *
1048             * @throws SystemException if a system exception occurred
1049             */
1050            public void removeAll() throws SystemException {
1051                    for (PasswordTracker passwordTracker : findAll()) {
1052                            remove(passwordTracker);
1053                    }
1054            }
1055    
1056            /**
1057             * Returns the number of password trackers.
1058             *
1059             * @return the number of password trackers
1060             * @throws SystemException if a system exception occurred
1061             */
1062            public int countAll() throws SystemException {
1063                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1064                                    FINDER_ARGS_EMPTY, this);
1065    
1066                    if (count == null) {
1067                            Session session = null;
1068    
1069                            try {
1070                                    session = openSession();
1071    
1072                                    Query q = session.createQuery(_SQL_COUNT_PASSWORDTRACKER);
1073    
1074                                    count = (Long)q.uniqueResult();
1075    
1076                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1077                                            FINDER_ARGS_EMPTY, count);
1078                            }
1079                            catch (Exception e) {
1080                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1081                                            FINDER_ARGS_EMPTY);
1082    
1083                                    throw processException(e);
1084                            }
1085                            finally {
1086                                    closeSession(session);
1087                            }
1088                    }
1089    
1090                    return count.intValue();
1091            }
1092    
1093            /**
1094             * Initializes the password tracker persistence.
1095             */
1096            public void afterPropertiesSet() {
1097                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1098                                            com.liferay.portal.util.PropsUtil.get(
1099                                                    "value.object.listener.com.liferay.portal.model.PasswordTracker")));
1100    
1101                    if (listenerClassNames.length > 0) {
1102                            try {
1103                                    List<ModelListener<PasswordTracker>> listenersList = new ArrayList<ModelListener<PasswordTracker>>();
1104    
1105                                    for (String listenerClassName : listenerClassNames) {
1106                                            listenersList.add((ModelListener<PasswordTracker>)InstanceFactory.newInstance(
1107                                                            listenerClassName));
1108                                    }
1109    
1110                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1111                            }
1112                            catch (Exception e) {
1113                                    _log.error(e);
1114                            }
1115                    }
1116            }
1117    
1118            public void destroy() {
1119                    EntityCacheUtil.removeCache(PasswordTrackerImpl.class.getName());
1120                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1121                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1122                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1123            }
1124    
1125            private static final String _SQL_SELECT_PASSWORDTRACKER = "SELECT passwordTracker FROM PasswordTracker passwordTracker";
1126            private static final String _SQL_SELECT_PASSWORDTRACKER_WHERE = "SELECT passwordTracker FROM PasswordTracker passwordTracker WHERE ";
1127            private static final String _SQL_COUNT_PASSWORDTRACKER = "SELECT COUNT(passwordTracker) FROM PasswordTracker passwordTracker";
1128            private static final String _SQL_COUNT_PASSWORDTRACKER_WHERE = "SELECT COUNT(passwordTracker) FROM PasswordTracker passwordTracker WHERE ";
1129            private static final String _ORDER_BY_ENTITY_ALIAS = "passwordTracker.";
1130            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PasswordTracker exists with the primary key ";
1131            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PasswordTracker exists with the key {";
1132            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1133            private static Log _log = LogFactoryUtil.getLog(PasswordTrackerPersistenceImpl.class);
1134            private static PasswordTracker _nullPasswordTracker = new PasswordTrackerImpl() {
1135                            @Override
1136                            public Object clone() {
1137                                    return this;
1138                            }
1139    
1140                            @Override
1141                            public CacheModel<PasswordTracker> toCacheModel() {
1142                                    return _nullPasswordTrackerCacheModel;
1143                            }
1144                    };
1145    
1146            private static CacheModel<PasswordTracker> _nullPasswordTrackerCacheModel = new CacheModel<PasswordTracker>() {
1147                            public PasswordTracker toEntityModel() {
1148                                    return _nullPasswordTracker;
1149                            }
1150                    };
1151    }