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