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