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            public PasswordTrackerPersistenceImpl() {
581                    setModelClass(PasswordTracker.class);
582            }
583    
584            /**
585             * Caches the password tracker in the entity cache if it is enabled.
586             *
587             * @param passwordTracker the password tracker
588             */
589            @Override
590            public void cacheResult(PasswordTracker passwordTracker) {
591                    EntityCacheUtil.putResult(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
592                            PasswordTrackerImpl.class, passwordTracker.getPrimaryKey(),
593                            passwordTracker);
594    
595                    passwordTracker.resetOriginalValues();
596            }
597    
598            /**
599             * Caches the password trackers in the entity cache if it is enabled.
600             *
601             * @param passwordTrackers the password trackers
602             */
603            @Override
604            public void cacheResult(List<PasswordTracker> passwordTrackers) {
605                    for (PasswordTracker passwordTracker : passwordTrackers) {
606                            if (EntityCacheUtil.getResult(
607                                                    PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
608                                                    PasswordTrackerImpl.class,
609                                                    passwordTracker.getPrimaryKey()) == null) {
610                                    cacheResult(passwordTracker);
611                            }
612                            else {
613                                    passwordTracker.resetOriginalValues();
614                            }
615                    }
616            }
617    
618            /**
619             * Clears the cache for all password trackers.
620             *
621             * <p>
622             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
623             * </p>
624             */
625            @Override
626            public void clearCache() {
627                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
628                            CacheRegistryUtil.clear(PasswordTrackerImpl.class.getName());
629                    }
630    
631                    EntityCacheUtil.clearCache(PasswordTrackerImpl.class.getName());
632    
633                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
634                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
635                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
636            }
637    
638            /**
639             * Clears the cache for the password tracker.
640             *
641             * <p>
642             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
643             * </p>
644             */
645            @Override
646            public void clearCache(PasswordTracker passwordTracker) {
647                    EntityCacheUtil.removeResult(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
648                            PasswordTrackerImpl.class, passwordTracker.getPrimaryKey());
649    
650                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
651                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
652            }
653    
654            @Override
655            public void clearCache(List<PasswordTracker> passwordTrackers) {
656                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
657                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
658    
659                    for (PasswordTracker passwordTracker : passwordTrackers) {
660                            EntityCacheUtil.removeResult(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
661                                    PasswordTrackerImpl.class, passwordTracker.getPrimaryKey());
662                    }
663            }
664    
665            /**
666             * Creates a new password tracker with the primary key. Does not add the password tracker to the database.
667             *
668             * @param passwordTrackerId the primary key for the new password tracker
669             * @return the new password tracker
670             */
671            @Override
672            public PasswordTracker create(long passwordTrackerId) {
673                    PasswordTracker passwordTracker = new PasswordTrackerImpl();
674    
675                    passwordTracker.setNew(true);
676                    passwordTracker.setPrimaryKey(passwordTrackerId);
677    
678                    return passwordTracker;
679            }
680    
681            /**
682             * Removes the password tracker with the primary key from the database. Also notifies the appropriate model listeners.
683             *
684             * @param passwordTrackerId the primary key of the password tracker
685             * @return the password tracker that was removed
686             * @throws com.liferay.portal.NoSuchPasswordTrackerException if a password tracker with the primary key could not be found
687             * @throws SystemException if a system exception occurred
688             */
689            @Override
690            public PasswordTracker remove(long passwordTrackerId)
691                    throws NoSuchPasswordTrackerException, SystemException {
692                    return remove((Serializable)passwordTrackerId);
693            }
694    
695            /**
696             * Removes the password tracker with the primary key from the database. Also notifies the appropriate model listeners.
697             *
698             * @param primaryKey the primary key of the password tracker
699             * @return the password tracker that was removed
700             * @throws com.liferay.portal.NoSuchPasswordTrackerException if a password tracker with the primary key could not be found
701             * @throws SystemException if a system exception occurred
702             */
703            @Override
704            public PasswordTracker remove(Serializable primaryKey)
705                    throws NoSuchPasswordTrackerException, SystemException {
706                    Session session = null;
707    
708                    try {
709                            session = openSession();
710    
711                            PasswordTracker passwordTracker = (PasswordTracker)session.get(PasswordTrackerImpl.class,
712                                            primaryKey);
713    
714                            if (passwordTracker == null) {
715                                    if (_log.isWarnEnabled()) {
716                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
717                                    }
718    
719                                    throw new NoSuchPasswordTrackerException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
720                                            primaryKey);
721                            }
722    
723                            return remove(passwordTracker);
724                    }
725                    catch (NoSuchPasswordTrackerException nsee) {
726                            throw nsee;
727                    }
728                    catch (Exception e) {
729                            throw processException(e);
730                    }
731                    finally {
732                            closeSession(session);
733                    }
734            }
735    
736            @Override
737            protected PasswordTracker removeImpl(PasswordTracker passwordTracker)
738                    throws SystemException {
739                    passwordTracker = toUnwrappedModel(passwordTracker);
740    
741                    Session session = null;
742    
743                    try {
744                            session = openSession();
745    
746                            if (!session.contains(passwordTracker)) {
747                                    passwordTracker = (PasswordTracker)session.get(PasswordTrackerImpl.class,
748                                                    passwordTracker.getPrimaryKeyObj());
749                            }
750    
751                            if (passwordTracker != null) {
752                                    session.delete(passwordTracker);
753                            }
754                    }
755                    catch (Exception e) {
756                            throw processException(e);
757                    }
758                    finally {
759                            closeSession(session);
760                    }
761    
762                    if (passwordTracker != null) {
763                            clearCache(passwordTracker);
764                    }
765    
766                    return passwordTracker;
767            }
768    
769            @Override
770            public PasswordTracker updateImpl(
771                    com.liferay.portal.model.PasswordTracker passwordTracker)
772                    throws SystemException {
773                    passwordTracker = toUnwrappedModel(passwordTracker);
774    
775                    boolean isNew = passwordTracker.isNew();
776    
777                    PasswordTrackerModelImpl passwordTrackerModelImpl = (PasswordTrackerModelImpl)passwordTracker;
778    
779                    Session session = null;
780    
781                    try {
782                            session = openSession();
783    
784                            if (passwordTracker.isNew()) {
785                                    session.save(passwordTracker);
786    
787                                    passwordTracker.setNew(false);
788                            }
789                            else {
790                                    session.merge(passwordTracker);
791                            }
792                    }
793                    catch (Exception e) {
794                            throw processException(e);
795                    }
796                    finally {
797                            closeSession(session);
798                    }
799    
800                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
801    
802                    if (isNew || !PasswordTrackerModelImpl.COLUMN_BITMASK_ENABLED) {
803                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
804                    }
805    
806                    else {
807                            if ((passwordTrackerModelImpl.getColumnBitmask() &
808                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
809                                    Object[] args = new Object[] {
810                                                    passwordTrackerModelImpl.getOriginalUserId()
811                                            };
812    
813                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
814                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
815                                            args);
816    
817                                    args = new Object[] { passwordTrackerModelImpl.getUserId() };
818    
819                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
820                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
821                                            args);
822                            }
823                    }
824    
825                    EntityCacheUtil.putResult(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
826                            PasswordTrackerImpl.class, passwordTracker.getPrimaryKey(),
827                            passwordTracker);
828    
829                    return passwordTracker;
830            }
831    
832            protected PasswordTracker toUnwrappedModel(PasswordTracker passwordTracker) {
833                    if (passwordTracker instanceof PasswordTrackerImpl) {
834                            return passwordTracker;
835                    }
836    
837                    PasswordTrackerImpl passwordTrackerImpl = new PasswordTrackerImpl();
838    
839                    passwordTrackerImpl.setNew(passwordTracker.isNew());
840                    passwordTrackerImpl.setPrimaryKey(passwordTracker.getPrimaryKey());
841    
842                    passwordTrackerImpl.setPasswordTrackerId(passwordTracker.getPasswordTrackerId());
843                    passwordTrackerImpl.setUserId(passwordTracker.getUserId());
844                    passwordTrackerImpl.setCreateDate(passwordTracker.getCreateDate());
845                    passwordTrackerImpl.setPassword(passwordTracker.getPassword());
846    
847                    return passwordTrackerImpl;
848            }
849    
850            /**
851             * Returns the password tracker with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
852             *
853             * @param primaryKey the primary key of the password tracker
854             * @return the password tracker
855             * @throws com.liferay.portal.NoSuchPasswordTrackerException if a password tracker with the primary key could not be found
856             * @throws SystemException if a system exception occurred
857             */
858            @Override
859            public PasswordTracker findByPrimaryKey(Serializable primaryKey)
860                    throws NoSuchPasswordTrackerException, SystemException {
861                    PasswordTracker passwordTracker = fetchByPrimaryKey(primaryKey);
862    
863                    if (passwordTracker == null) {
864                            if (_log.isWarnEnabled()) {
865                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
866                            }
867    
868                            throw new NoSuchPasswordTrackerException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
869                                    primaryKey);
870                    }
871    
872                    return passwordTracker;
873            }
874    
875            /**
876             * Returns the password tracker with the primary key or throws a {@link com.liferay.portal.NoSuchPasswordTrackerException} if it could not be found.
877             *
878             * @param passwordTrackerId the primary key of the password tracker
879             * @return the password tracker
880             * @throws com.liferay.portal.NoSuchPasswordTrackerException if a password tracker with the primary key could not be found
881             * @throws SystemException if a system exception occurred
882             */
883            @Override
884            public PasswordTracker findByPrimaryKey(long passwordTrackerId)
885                    throws NoSuchPasswordTrackerException, SystemException {
886                    return findByPrimaryKey((Serializable)passwordTrackerId);
887            }
888    
889            /**
890             * Returns the password tracker with the primary key or returns <code>null</code> if it could not be found.
891             *
892             * @param primaryKey the primary key of the password tracker
893             * @return the password tracker, or <code>null</code> if a password tracker with the primary key could not be found
894             * @throws SystemException if a system exception occurred
895             */
896            @Override
897            public PasswordTracker fetchByPrimaryKey(Serializable primaryKey)
898                    throws SystemException {
899                    PasswordTracker passwordTracker = (PasswordTracker)EntityCacheUtil.getResult(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
900                                    PasswordTrackerImpl.class, primaryKey);
901    
902                    if (passwordTracker == _nullPasswordTracker) {
903                            return null;
904                    }
905    
906                    if (passwordTracker == null) {
907                            Session session = null;
908    
909                            try {
910                                    session = openSession();
911    
912                                    passwordTracker = (PasswordTracker)session.get(PasswordTrackerImpl.class,
913                                                    primaryKey);
914    
915                                    if (passwordTracker != null) {
916                                            cacheResult(passwordTracker);
917                                    }
918                                    else {
919                                            EntityCacheUtil.putResult(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
920                                                    PasswordTrackerImpl.class, primaryKey,
921                                                    _nullPasswordTracker);
922                                    }
923                            }
924                            catch (Exception e) {
925                                    EntityCacheUtil.removeResult(PasswordTrackerModelImpl.ENTITY_CACHE_ENABLED,
926                                            PasswordTrackerImpl.class, primaryKey);
927    
928                                    throw processException(e);
929                            }
930                            finally {
931                                    closeSession(session);
932                            }
933                    }
934    
935                    return passwordTracker;
936            }
937    
938            /**
939             * Returns the password tracker with the primary key or returns <code>null</code> if it could not be found.
940             *
941             * @param passwordTrackerId the primary key of the password tracker
942             * @return the password tracker, or <code>null</code> if a password tracker with the primary key could not be found
943             * @throws SystemException if a system exception occurred
944             */
945            @Override
946            public PasswordTracker fetchByPrimaryKey(long passwordTrackerId)
947                    throws SystemException {
948                    return fetchByPrimaryKey((Serializable)passwordTrackerId);
949            }
950    
951            /**
952             * Returns all the password trackers.
953             *
954             * @return the password trackers
955             * @throws SystemException if a system exception occurred
956             */
957            @Override
958            public List<PasswordTracker> findAll() throws SystemException {
959                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
960            }
961    
962            /**
963             * Returns a range of all the password trackers.
964             *
965             * <p>
966             * 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.
967             * </p>
968             *
969             * @param start the lower bound of the range of password trackers
970             * @param end the upper bound of the range of password trackers (not inclusive)
971             * @return the range of password trackers
972             * @throws SystemException if a system exception occurred
973             */
974            @Override
975            public List<PasswordTracker> findAll(int start, int end)
976                    throws SystemException {
977                    return findAll(start, end, null);
978            }
979    
980            /**
981             * Returns an ordered range of all the password trackers.
982             *
983             * <p>
984             * 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.
985             * </p>
986             *
987             * @param start the lower bound of the range of password trackers
988             * @param end the upper bound of the range of password trackers (not inclusive)
989             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
990             * @return the ordered range of password trackers
991             * @throws SystemException if a system exception occurred
992             */
993            @Override
994            public List<PasswordTracker> findAll(int start, int end,
995                    OrderByComparator orderByComparator) throws SystemException {
996                    boolean pagination = true;
997                    FinderPath finderPath = null;
998                    Object[] finderArgs = null;
999    
1000                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1001                                    (orderByComparator == null)) {
1002                            pagination = false;
1003                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1004                            finderArgs = FINDER_ARGS_EMPTY;
1005                    }
1006                    else {
1007                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1008                            finderArgs = new Object[] { start, end, orderByComparator };
1009                    }
1010    
1011                    List<PasswordTracker> list = (List<PasswordTracker>)FinderCacheUtil.getResult(finderPath,
1012                                    finderArgs, this);
1013    
1014                    if (list == null) {
1015                            StringBundler query = null;
1016                            String sql = null;
1017    
1018                            if (orderByComparator != null) {
1019                                    query = new StringBundler(2 +
1020                                                    (orderByComparator.getOrderByFields().length * 3));
1021    
1022                                    query.append(_SQL_SELECT_PASSWORDTRACKER);
1023    
1024                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1025                                            orderByComparator);
1026    
1027                                    sql = query.toString();
1028                            }
1029                            else {
1030                                    sql = _SQL_SELECT_PASSWORDTRACKER;
1031    
1032                                    if (pagination) {
1033                                            sql = sql.concat(PasswordTrackerModelImpl.ORDER_BY_JPQL);
1034                                    }
1035                            }
1036    
1037                            Session session = null;
1038    
1039                            try {
1040                                    session = openSession();
1041    
1042                                    Query q = session.createQuery(sql);
1043    
1044                                    if (!pagination) {
1045                                            list = (List<PasswordTracker>)QueryUtil.list(q,
1046                                                            getDialect(), start, end, false);
1047    
1048                                            Collections.sort(list);
1049    
1050                                            list = new UnmodifiableList<PasswordTracker>(list);
1051                                    }
1052                                    else {
1053                                            list = (List<PasswordTracker>)QueryUtil.list(q,
1054                                                            getDialect(), start, end);
1055                                    }
1056    
1057                                    cacheResult(list);
1058    
1059                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1060                            }
1061                            catch (Exception e) {
1062                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1063    
1064                                    throw processException(e);
1065                            }
1066                            finally {
1067                                    closeSession(session);
1068                            }
1069                    }
1070    
1071                    return list;
1072            }
1073    
1074            /**
1075             * Removes all the password trackers from the database.
1076             *
1077             * @throws SystemException if a system exception occurred
1078             */
1079            @Override
1080            public void removeAll() throws SystemException {
1081                    for (PasswordTracker passwordTracker : findAll()) {
1082                            remove(passwordTracker);
1083                    }
1084            }
1085    
1086            /**
1087             * Returns the number of password trackers.
1088             *
1089             * @return the number of password trackers
1090             * @throws SystemException if a system exception occurred
1091             */
1092            @Override
1093            public int countAll() throws SystemException {
1094                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1095                                    FINDER_ARGS_EMPTY, this);
1096    
1097                    if (count == null) {
1098                            Session session = null;
1099    
1100                            try {
1101                                    session = openSession();
1102    
1103                                    Query q = session.createQuery(_SQL_COUNT_PASSWORDTRACKER);
1104    
1105                                    count = (Long)q.uniqueResult();
1106    
1107                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1108                                            FINDER_ARGS_EMPTY, count);
1109                            }
1110                            catch (Exception e) {
1111                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1112                                            FINDER_ARGS_EMPTY);
1113    
1114                                    throw processException(e);
1115                            }
1116                            finally {
1117                                    closeSession(session);
1118                            }
1119                    }
1120    
1121                    return count.intValue();
1122            }
1123    
1124            @Override
1125            protected Set<String> getBadColumnNames() {
1126                    return _badColumnNames;
1127            }
1128    
1129            /**
1130             * Initializes the password tracker persistence.
1131             */
1132            public void afterPropertiesSet() {
1133                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1134                                            com.liferay.portal.util.PropsUtil.get(
1135                                                    "value.object.listener.com.liferay.portal.model.PasswordTracker")));
1136    
1137                    if (listenerClassNames.length > 0) {
1138                            try {
1139                                    List<ModelListener<PasswordTracker>> listenersList = new ArrayList<ModelListener<PasswordTracker>>();
1140    
1141                                    for (String listenerClassName : listenerClassNames) {
1142                                            listenersList.add((ModelListener<PasswordTracker>)InstanceFactory.newInstance(
1143                                                            getClassLoader(), listenerClassName));
1144                                    }
1145    
1146                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1147                            }
1148                            catch (Exception e) {
1149                                    _log.error(e);
1150                            }
1151                    }
1152            }
1153    
1154            public void destroy() {
1155                    EntityCacheUtil.removeCache(PasswordTrackerImpl.class.getName());
1156                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1157                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1158                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1159            }
1160    
1161            private static final String _SQL_SELECT_PASSWORDTRACKER = "SELECT passwordTracker FROM PasswordTracker passwordTracker";
1162            private static final String _SQL_SELECT_PASSWORDTRACKER_WHERE = "SELECT passwordTracker FROM PasswordTracker passwordTracker WHERE ";
1163            private static final String _SQL_COUNT_PASSWORDTRACKER = "SELECT COUNT(passwordTracker) FROM PasswordTracker passwordTracker";
1164            private static final String _SQL_COUNT_PASSWORDTRACKER_WHERE = "SELECT COUNT(passwordTracker) FROM PasswordTracker passwordTracker WHERE ";
1165            private static final String _ORDER_BY_ENTITY_ALIAS = "passwordTracker.";
1166            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PasswordTracker exists with the primary key ";
1167            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PasswordTracker exists with the key {";
1168            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1169            private static Log _log = LogFactoryUtil.getLog(PasswordTrackerPersistenceImpl.class);
1170            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1171                                    "password"
1172                            });
1173            private static PasswordTracker _nullPasswordTracker = new PasswordTrackerImpl() {
1174                            @Override
1175                            public Object clone() {
1176                                    return this;
1177                            }
1178    
1179                            @Override
1180                            public CacheModel<PasswordTracker> toCacheModel() {
1181                                    return _nullPasswordTrackerCacheModel;
1182                            }
1183                    };
1184    
1185            private static CacheModel<PasswordTracker> _nullPasswordTrackerCacheModel = new CacheModel<PasswordTracker>() {
1186                            @Override
1187                            public PasswordTracker toEntityModel() {
1188                                    return _nullPasswordTracker;
1189                            }
1190                    };
1191    }