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