001    /**
002     * Copyright (c) 2000-present 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.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.NoSuchUserException;
020    import com.liferay.portal.kernel.bean.BeanReference;
021    import com.liferay.portal.kernel.dao.orm.EntityCache;
022    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderCache;
024    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
025    import com.liferay.portal.kernel.dao.orm.FinderPath;
026    import com.liferay.portal.kernel.dao.orm.Query;
027    import com.liferay.portal.kernel.dao.orm.QueryPos;
028    import com.liferay.portal.kernel.dao.orm.QueryUtil;
029    import com.liferay.portal.kernel.dao.orm.Session;
030    import com.liferay.portal.kernel.log.Log;
031    import com.liferay.portal.kernel.log.LogFactoryUtil;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.SetUtil;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039    import com.liferay.portal.model.CacheModel;
040    import com.liferay.portal.model.MVCCModel;
041    import com.liferay.portal.model.User;
042    import com.liferay.portal.model.impl.UserImpl;
043    import com.liferay.portal.model.impl.UserModelImpl;
044    import com.liferay.portal.service.ServiceContext;
045    import com.liferay.portal.service.ServiceContextThreadLocal;
046    import com.liferay.portal.service.persistence.GroupPersistence;
047    import com.liferay.portal.service.persistence.OrganizationPersistence;
048    import com.liferay.portal.service.persistence.RolePersistence;
049    import com.liferay.portal.service.persistence.TeamPersistence;
050    import com.liferay.portal.service.persistence.UserGroupPersistence;
051    import com.liferay.portal.service.persistence.UserPersistence;
052    
053    import java.io.Serializable;
054    
055    import java.sql.Timestamp;
056    
057    import java.util.Collections;
058    import java.util.Date;
059    import java.util.HashMap;
060    import java.util.HashSet;
061    import java.util.Iterator;
062    import java.util.List;
063    import java.util.Map;
064    import java.util.Set;
065    
066    /**
067     * The persistence implementation for the user service.
068     *
069     * <p>
070     * Caching information and settings can be found in <code>portal.properties</code>
071     * </p>
072     *
073     * @author Brian Wing Shun Chan
074     * @see UserPersistence
075     * @see com.liferay.portal.service.persistence.UserUtil
076     * @generated
077     */
078    @ProviderType
079    public class UserPersistenceImpl extends BasePersistenceImpl<User>
080            implements UserPersistence {
081            /*
082             * NOTE FOR DEVELOPERS:
083             *
084             * Never modify or reference this class directly. Always use {@link UserUtil} to access the user persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
085             */
086            public static final String FINDER_CLASS_NAME_ENTITY = UserImpl.class.getName();
087            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
088                    ".List1";
089            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
090                    ".List2";
091            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
092                            UserModelImpl.FINDER_CACHE_ENABLED, UserImpl.class,
093                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
094            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
095                            UserModelImpl.FINDER_CACHE_ENABLED, UserImpl.class,
096                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
097            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
098                            UserModelImpl.FINDER_CACHE_ENABLED, Long.class,
099                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
100            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
101                            UserModelImpl.FINDER_CACHE_ENABLED, UserImpl.class,
102                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
103                            new String[] {
104                                    String.class.getName(),
105                                    
106                            Integer.class.getName(), Integer.class.getName(),
107                                    OrderByComparator.class.getName()
108                            });
109            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
110                            UserModelImpl.FINDER_CACHE_ENABLED, UserImpl.class,
111                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
112                            new String[] { String.class.getName() },
113                            UserModelImpl.UUID_COLUMN_BITMASK);
114            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
115                            UserModelImpl.FINDER_CACHE_ENABLED, Long.class,
116                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
117                            new String[] { String.class.getName() });
118    
119            /**
120             * Returns all the users where uuid = &#63;.
121             *
122             * @param uuid the uuid
123             * @return the matching users
124             */
125            @Override
126            public List<User> findByUuid(String uuid) {
127                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
128            }
129    
130            /**
131             * Returns a range of all the users where uuid = &#63;.
132             *
133             * <p>
134             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
135             * </p>
136             *
137             * @param uuid the uuid
138             * @param start the lower bound of the range of users
139             * @param end the upper bound of the range of users (not inclusive)
140             * @return the range of matching users
141             */
142            @Override
143            public List<User> findByUuid(String uuid, int start, int end) {
144                    return findByUuid(uuid, start, end, null);
145            }
146    
147            /**
148             * Returns an ordered range of all the users where uuid = &#63;.
149             *
150             * <p>
151             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
152             * </p>
153             *
154             * @param uuid the uuid
155             * @param start the lower bound of the range of users
156             * @param end the upper bound of the range of users (not inclusive)
157             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
158             * @return the ordered range of matching users
159             */
160            @Override
161            public List<User> findByUuid(String uuid, int start, int end,
162                    OrderByComparator<User> orderByComparator) {
163                    return findByUuid(uuid, start, end, orderByComparator, true);
164            }
165    
166            /**
167             * Returns an ordered range of all the users where uuid = &#63;.
168             *
169             * <p>
170             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
171             * </p>
172             *
173             * @param uuid the uuid
174             * @param start the lower bound of the range of users
175             * @param end the upper bound of the range of users (not inclusive)
176             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
177             * @param retrieveFromCache whether to retrieve from the finder cache
178             * @return the ordered range of matching users
179             */
180            @Override
181            public List<User> findByUuid(String uuid, int start, int end,
182                    OrderByComparator<User> orderByComparator, boolean retrieveFromCache) {
183                    boolean pagination = true;
184                    FinderPath finderPath = null;
185                    Object[] finderArgs = null;
186    
187                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
188                                    (orderByComparator == null)) {
189                            pagination = false;
190                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
191                            finderArgs = new Object[] { uuid };
192                    }
193                    else {
194                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
195                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
196                    }
197    
198                    List<User> list = null;
199    
200                    if (retrieveFromCache) {
201                            list = (List<User>)finderCache.getResult(finderPath, finderArgs,
202                                            this);
203    
204                            if ((list != null) && !list.isEmpty()) {
205                                    for (User user : list) {
206                                            if (!Validator.equals(uuid, user.getUuid())) {
207                                                    list = null;
208    
209                                                    break;
210                                            }
211                                    }
212                            }
213                    }
214    
215                    if (list == null) {
216                            StringBundler query = null;
217    
218                            if (orderByComparator != null) {
219                                    query = new StringBundler(3 +
220                                                    (orderByComparator.getOrderByFields().length * 3));
221                            }
222                            else {
223                                    query = new StringBundler(3);
224                            }
225    
226                            query.append(_SQL_SELECT_USER_WHERE);
227    
228                            boolean bindUuid = false;
229    
230                            if (uuid == null) {
231                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
232                            }
233                            else if (uuid.equals(StringPool.BLANK)) {
234                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
235                            }
236                            else {
237                                    bindUuid = true;
238    
239                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
240                            }
241    
242                            if (orderByComparator != null) {
243                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
244                                            orderByComparator);
245                            }
246                            else
247                             if (pagination) {
248                                    query.append(UserModelImpl.ORDER_BY_JPQL);
249                            }
250    
251                            String sql = query.toString();
252    
253                            Session session = null;
254    
255                            try {
256                                    session = openSession();
257    
258                                    Query q = session.createQuery(sql);
259    
260                                    QueryPos qPos = QueryPos.getInstance(q);
261    
262                                    if (bindUuid) {
263                                            qPos.add(uuid);
264                                    }
265    
266                                    if (!pagination) {
267                                            list = (List<User>)QueryUtil.list(q, getDialect(), start,
268                                                            end, false);
269    
270                                            Collections.sort(list);
271    
272                                            list = Collections.unmodifiableList(list);
273                                    }
274                                    else {
275                                            list = (List<User>)QueryUtil.list(q, getDialect(), start,
276                                                            end);
277                                    }
278    
279                                    cacheResult(list);
280    
281                                    finderCache.putResult(finderPath, finderArgs, list);
282                            }
283                            catch (Exception e) {
284                                    finderCache.removeResult(finderPath, finderArgs);
285    
286                                    throw processException(e);
287                            }
288                            finally {
289                                    closeSession(session);
290                            }
291                    }
292    
293                    return list;
294            }
295    
296            /**
297             * Returns the first user in the ordered set where uuid = &#63;.
298             *
299             * @param uuid the uuid
300             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
301             * @return the first matching user
302             * @throws NoSuchUserException if a matching user could not be found
303             */
304            @Override
305            public User findByUuid_First(String uuid,
306                    OrderByComparator<User> orderByComparator) throws NoSuchUserException {
307                    User user = fetchByUuid_First(uuid, orderByComparator);
308    
309                    if (user != null) {
310                            return user;
311                    }
312    
313                    StringBundler msg = new StringBundler(4);
314    
315                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
316    
317                    msg.append("uuid=");
318                    msg.append(uuid);
319    
320                    msg.append(StringPool.CLOSE_CURLY_BRACE);
321    
322                    throw new NoSuchUserException(msg.toString());
323            }
324    
325            /**
326             * Returns the first user in the ordered set where uuid = &#63;.
327             *
328             * @param uuid the uuid
329             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
330             * @return the first matching user, or <code>null</code> if a matching user could not be found
331             */
332            @Override
333            public User fetchByUuid_First(String uuid,
334                    OrderByComparator<User> orderByComparator) {
335                    List<User> list = findByUuid(uuid, 0, 1, orderByComparator);
336    
337                    if (!list.isEmpty()) {
338                            return list.get(0);
339                    }
340    
341                    return null;
342            }
343    
344            /**
345             * Returns the last user in the ordered set where uuid = &#63;.
346             *
347             * @param uuid the uuid
348             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
349             * @return the last matching user
350             * @throws NoSuchUserException if a matching user could not be found
351             */
352            @Override
353            public User findByUuid_Last(String uuid,
354                    OrderByComparator<User> orderByComparator) throws NoSuchUserException {
355                    User user = fetchByUuid_Last(uuid, orderByComparator);
356    
357                    if (user != null) {
358                            return user;
359                    }
360    
361                    StringBundler msg = new StringBundler(4);
362    
363                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
364    
365                    msg.append("uuid=");
366                    msg.append(uuid);
367    
368                    msg.append(StringPool.CLOSE_CURLY_BRACE);
369    
370                    throw new NoSuchUserException(msg.toString());
371            }
372    
373            /**
374             * Returns the last user in the ordered set where uuid = &#63;.
375             *
376             * @param uuid the uuid
377             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
378             * @return the last matching user, or <code>null</code> if a matching user could not be found
379             */
380            @Override
381            public User fetchByUuid_Last(String uuid,
382                    OrderByComparator<User> orderByComparator) {
383                    int count = countByUuid(uuid);
384    
385                    if (count == 0) {
386                            return null;
387                    }
388    
389                    List<User> list = findByUuid(uuid, count - 1, count, orderByComparator);
390    
391                    if (!list.isEmpty()) {
392                            return list.get(0);
393                    }
394    
395                    return null;
396            }
397    
398            /**
399             * Returns the users before and after the current user in the ordered set where uuid = &#63;.
400             *
401             * @param userId the primary key of the current user
402             * @param uuid the uuid
403             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
404             * @return the previous, current, and next user
405             * @throws NoSuchUserException if a user with the primary key could not be found
406             */
407            @Override
408            public User[] findByUuid_PrevAndNext(long userId, String uuid,
409                    OrderByComparator<User> orderByComparator) throws NoSuchUserException {
410                    User user = findByPrimaryKey(userId);
411    
412                    Session session = null;
413    
414                    try {
415                            session = openSession();
416    
417                            User[] array = new UserImpl[3];
418    
419                            array[0] = getByUuid_PrevAndNext(session, user, uuid,
420                                            orderByComparator, true);
421    
422                            array[1] = user;
423    
424                            array[2] = getByUuid_PrevAndNext(session, user, uuid,
425                                            orderByComparator, false);
426    
427                            return array;
428                    }
429                    catch (Exception e) {
430                            throw processException(e);
431                    }
432                    finally {
433                            closeSession(session);
434                    }
435            }
436    
437            protected User getByUuid_PrevAndNext(Session session, User user,
438                    String uuid, OrderByComparator<User> orderByComparator, boolean previous) {
439                    StringBundler query = null;
440    
441                    if (orderByComparator != null) {
442                            query = new StringBundler(6 +
443                                            (orderByComparator.getOrderByFields().length * 6));
444                    }
445                    else {
446                            query = new StringBundler(3);
447                    }
448    
449                    query.append(_SQL_SELECT_USER_WHERE);
450    
451                    boolean bindUuid = false;
452    
453                    if (uuid == null) {
454                            query.append(_FINDER_COLUMN_UUID_UUID_1);
455                    }
456                    else if (uuid.equals(StringPool.BLANK)) {
457                            query.append(_FINDER_COLUMN_UUID_UUID_3);
458                    }
459                    else {
460                            bindUuid = true;
461    
462                            query.append(_FINDER_COLUMN_UUID_UUID_2);
463                    }
464    
465                    if (orderByComparator != null) {
466                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
467    
468                            if (orderByConditionFields.length > 0) {
469                                    query.append(WHERE_AND);
470                            }
471    
472                            for (int i = 0; i < orderByConditionFields.length; i++) {
473                                    query.append(_ORDER_BY_ENTITY_ALIAS);
474                                    query.append(orderByConditionFields[i]);
475    
476                                    if ((i + 1) < orderByConditionFields.length) {
477                                            if (orderByComparator.isAscending() ^ previous) {
478                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
479                                            }
480                                            else {
481                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
482                                            }
483                                    }
484                                    else {
485                                            if (orderByComparator.isAscending() ^ previous) {
486                                                    query.append(WHERE_GREATER_THAN);
487                                            }
488                                            else {
489                                                    query.append(WHERE_LESSER_THAN);
490                                            }
491                                    }
492                            }
493    
494                            query.append(ORDER_BY_CLAUSE);
495    
496                            String[] orderByFields = orderByComparator.getOrderByFields();
497    
498                            for (int i = 0; i < orderByFields.length; i++) {
499                                    query.append(_ORDER_BY_ENTITY_ALIAS);
500                                    query.append(orderByFields[i]);
501    
502                                    if ((i + 1) < orderByFields.length) {
503                                            if (orderByComparator.isAscending() ^ previous) {
504                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
505                                            }
506                                            else {
507                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
508                                            }
509                                    }
510                                    else {
511                                            if (orderByComparator.isAscending() ^ previous) {
512                                                    query.append(ORDER_BY_ASC);
513                                            }
514                                            else {
515                                                    query.append(ORDER_BY_DESC);
516                                            }
517                                    }
518                            }
519                    }
520                    else {
521                            query.append(UserModelImpl.ORDER_BY_JPQL);
522                    }
523    
524                    String sql = query.toString();
525    
526                    Query q = session.createQuery(sql);
527    
528                    q.setFirstResult(0);
529                    q.setMaxResults(2);
530    
531                    QueryPos qPos = QueryPos.getInstance(q);
532    
533                    if (bindUuid) {
534                            qPos.add(uuid);
535                    }
536    
537                    if (orderByComparator != null) {
538                            Object[] values = orderByComparator.getOrderByConditionValues(user);
539    
540                            for (Object value : values) {
541                                    qPos.add(value);
542                            }
543                    }
544    
545                    List<User> list = q.list();
546    
547                    if (list.size() == 2) {
548                            return list.get(1);
549                    }
550                    else {
551                            return null;
552                    }
553            }
554    
555            /**
556             * Removes all the users where uuid = &#63; from the database.
557             *
558             * @param uuid the uuid
559             */
560            @Override
561            public void removeByUuid(String uuid) {
562                    for (User user : findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
563                                    null)) {
564                            remove(user);
565                    }
566            }
567    
568            /**
569             * Returns the number of users where uuid = &#63;.
570             *
571             * @param uuid the uuid
572             * @return the number of matching users
573             */
574            @Override
575            public int countByUuid(String uuid) {
576                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
577    
578                    Object[] finderArgs = new Object[] { uuid };
579    
580                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
581    
582                    if (count == null) {
583                            StringBundler query = new StringBundler(2);
584    
585                            query.append(_SQL_COUNT_USER_WHERE);
586    
587                            boolean bindUuid = false;
588    
589                            if (uuid == null) {
590                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
591                            }
592                            else if (uuid.equals(StringPool.BLANK)) {
593                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
594                            }
595                            else {
596                                    bindUuid = true;
597    
598                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
599                            }
600    
601                            String sql = query.toString();
602    
603                            Session session = null;
604    
605                            try {
606                                    session = openSession();
607    
608                                    Query q = session.createQuery(sql);
609    
610                                    QueryPos qPos = QueryPos.getInstance(q);
611    
612                                    if (bindUuid) {
613                                            qPos.add(uuid);
614                                    }
615    
616                                    count = (Long)q.uniqueResult();
617    
618                                    finderCache.putResult(finderPath, finderArgs, count);
619                            }
620                            catch (Exception e) {
621                                    finderCache.removeResult(finderPath, finderArgs);
622    
623                                    throw processException(e);
624                            }
625                            finally {
626                                    closeSession(session);
627                            }
628                    }
629    
630                    return count.intValue();
631            }
632    
633            private static final String _FINDER_COLUMN_UUID_UUID_1 = "user.uuid IS NULL";
634            private static final String _FINDER_COLUMN_UUID_UUID_2 = "user.uuid = ?";
635            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(user.uuid IS NULL OR user.uuid = '')";
636            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
637                            UserModelImpl.FINDER_CACHE_ENABLED, UserImpl.class,
638                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
639                            new String[] {
640                                    String.class.getName(), Long.class.getName(),
641                                    
642                            Integer.class.getName(), Integer.class.getName(),
643                                    OrderByComparator.class.getName()
644                            });
645            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
646                    new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
647                            UserModelImpl.FINDER_CACHE_ENABLED, UserImpl.class,
648                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
649                            new String[] { String.class.getName(), Long.class.getName() },
650                            UserModelImpl.UUID_COLUMN_BITMASK |
651                            UserModelImpl.COMPANYID_COLUMN_BITMASK);
652            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
653                            UserModelImpl.FINDER_CACHE_ENABLED, Long.class,
654                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
655                            new String[] { String.class.getName(), Long.class.getName() });
656    
657            /**
658             * Returns all the users where uuid = &#63; and companyId = &#63;.
659             *
660             * @param uuid the uuid
661             * @param companyId the company ID
662             * @return the matching users
663             */
664            @Override
665            public List<User> findByUuid_C(String uuid, long companyId) {
666                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
667                            QueryUtil.ALL_POS, null);
668            }
669    
670            /**
671             * Returns a range of all the users where uuid = &#63; and companyId = &#63;.
672             *
673             * <p>
674             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
675             * </p>
676             *
677             * @param uuid the uuid
678             * @param companyId the company ID
679             * @param start the lower bound of the range of users
680             * @param end the upper bound of the range of users (not inclusive)
681             * @return the range of matching users
682             */
683            @Override
684            public List<User> findByUuid_C(String uuid, long companyId, int start,
685                    int end) {
686                    return findByUuid_C(uuid, companyId, start, end, null);
687            }
688    
689            /**
690             * Returns an ordered range of all the users where uuid = &#63; and companyId = &#63;.
691             *
692             * <p>
693             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
694             * </p>
695             *
696             * @param uuid the uuid
697             * @param companyId the company ID
698             * @param start the lower bound of the range of users
699             * @param end the upper bound of the range of users (not inclusive)
700             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
701             * @return the ordered range of matching users
702             */
703            @Override
704            public List<User> findByUuid_C(String uuid, long companyId, int start,
705                    int end, OrderByComparator<User> orderByComparator) {
706                    return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
707            }
708    
709            /**
710             * Returns an ordered range of all the users where uuid = &#63; and companyId = &#63;.
711             *
712             * <p>
713             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
714             * </p>
715             *
716             * @param uuid the uuid
717             * @param companyId the company ID
718             * @param start the lower bound of the range of users
719             * @param end the upper bound of the range of users (not inclusive)
720             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
721             * @param retrieveFromCache whether to retrieve from the finder cache
722             * @return the ordered range of matching users
723             */
724            @Override
725            public List<User> findByUuid_C(String uuid, long companyId, int start,
726                    int end, OrderByComparator<User> orderByComparator,
727                    boolean retrieveFromCache) {
728                    boolean pagination = true;
729                    FinderPath finderPath = null;
730                    Object[] finderArgs = null;
731    
732                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
733                                    (orderByComparator == null)) {
734                            pagination = false;
735                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
736                            finderArgs = new Object[] { uuid, companyId };
737                    }
738                    else {
739                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
740                            finderArgs = new Object[] {
741                                            uuid, companyId,
742                                            
743                                            start, end, orderByComparator
744                                    };
745                    }
746    
747                    List<User> list = null;
748    
749                    if (retrieveFromCache) {
750                            list = (List<User>)finderCache.getResult(finderPath, finderArgs,
751                                            this);
752    
753                            if ((list != null) && !list.isEmpty()) {
754                                    for (User user : list) {
755                                            if (!Validator.equals(uuid, user.getUuid()) ||
756                                                            (companyId != user.getCompanyId())) {
757                                                    list = null;
758    
759                                                    break;
760                                            }
761                                    }
762                            }
763                    }
764    
765                    if (list == null) {
766                            StringBundler query = null;
767    
768                            if (orderByComparator != null) {
769                                    query = new StringBundler(4 +
770                                                    (orderByComparator.getOrderByFields().length * 3));
771                            }
772                            else {
773                                    query = new StringBundler(4);
774                            }
775    
776                            query.append(_SQL_SELECT_USER_WHERE);
777    
778                            boolean bindUuid = false;
779    
780                            if (uuid == null) {
781                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
782                            }
783                            else if (uuid.equals(StringPool.BLANK)) {
784                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
785                            }
786                            else {
787                                    bindUuid = true;
788    
789                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
790                            }
791    
792                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
793    
794                            if (orderByComparator != null) {
795                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
796                                            orderByComparator);
797                            }
798                            else
799                             if (pagination) {
800                                    query.append(UserModelImpl.ORDER_BY_JPQL);
801                            }
802    
803                            String sql = query.toString();
804    
805                            Session session = null;
806    
807                            try {
808                                    session = openSession();
809    
810                                    Query q = session.createQuery(sql);
811    
812                                    QueryPos qPos = QueryPos.getInstance(q);
813    
814                                    if (bindUuid) {
815                                            qPos.add(uuid);
816                                    }
817    
818                                    qPos.add(companyId);
819    
820                                    if (!pagination) {
821                                            list = (List<User>)QueryUtil.list(q, getDialect(), start,
822                                                            end, false);
823    
824                                            Collections.sort(list);
825    
826                                            list = Collections.unmodifiableList(list);
827                                    }
828                                    else {
829                                            list = (List<User>)QueryUtil.list(q, getDialect(), start,
830                                                            end);
831                                    }
832    
833                                    cacheResult(list);
834    
835                                    finderCache.putResult(finderPath, finderArgs, list);
836                            }
837                            catch (Exception e) {
838                                    finderCache.removeResult(finderPath, finderArgs);
839    
840                                    throw processException(e);
841                            }
842                            finally {
843                                    closeSession(session);
844                            }
845                    }
846    
847                    return list;
848            }
849    
850            /**
851             * Returns the first user in the ordered set where uuid = &#63; and companyId = &#63;.
852             *
853             * @param uuid the uuid
854             * @param companyId the company ID
855             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
856             * @return the first matching user
857             * @throws NoSuchUserException if a matching user could not be found
858             */
859            @Override
860            public User findByUuid_C_First(String uuid, long companyId,
861                    OrderByComparator<User> orderByComparator) throws NoSuchUserException {
862                    User user = fetchByUuid_C_First(uuid, companyId, orderByComparator);
863    
864                    if (user != null) {
865                            return user;
866                    }
867    
868                    StringBundler msg = new StringBundler(6);
869    
870                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
871    
872                    msg.append("uuid=");
873                    msg.append(uuid);
874    
875                    msg.append(", companyId=");
876                    msg.append(companyId);
877    
878                    msg.append(StringPool.CLOSE_CURLY_BRACE);
879    
880                    throw new NoSuchUserException(msg.toString());
881            }
882    
883            /**
884             * Returns the first user in the ordered set where uuid = &#63; and companyId = &#63;.
885             *
886             * @param uuid the uuid
887             * @param companyId the company ID
888             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
889             * @return the first matching user, or <code>null</code> if a matching user could not be found
890             */
891            @Override
892            public User fetchByUuid_C_First(String uuid, long companyId,
893                    OrderByComparator<User> orderByComparator) {
894                    List<User> list = findByUuid_C(uuid, companyId, 0, 1, orderByComparator);
895    
896                    if (!list.isEmpty()) {
897                            return list.get(0);
898                    }
899    
900                    return null;
901            }
902    
903            /**
904             * Returns the last user in the ordered set where uuid = &#63; and companyId = &#63;.
905             *
906             * @param uuid the uuid
907             * @param companyId the company ID
908             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
909             * @return the last matching user
910             * @throws NoSuchUserException if a matching user could not be found
911             */
912            @Override
913            public User findByUuid_C_Last(String uuid, long companyId,
914                    OrderByComparator<User> orderByComparator) throws NoSuchUserException {
915                    User user = fetchByUuid_C_Last(uuid, companyId, orderByComparator);
916    
917                    if (user != null) {
918                            return user;
919                    }
920    
921                    StringBundler msg = new StringBundler(6);
922    
923                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
924    
925                    msg.append("uuid=");
926                    msg.append(uuid);
927    
928                    msg.append(", companyId=");
929                    msg.append(companyId);
930    
931                    msg.append(StringPool.CLOSE_CURLY_BRACE);
932    
933                    throw new NoSuchUserException(msg.toString());
934            }
935    
936            /**
937             * Returns the last user in the ordered set where uuid = &#63; and companyId = &#63;.
938             *
939             * @param uuid the uuid
940             * @param companyId the company ID
941             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
942             * @return the last matching user, or <code>null</code> if a matching user could not be found
943             */
944            @Override
945            public User fetchByUuid_C_Last(String uuid, long companyId,
946                    OrderByComparator<User> orderByComparator) {
947                    int count = countByUuid_C(uuid, companyId);
948    
949                    if (count == 0) {
950                            return null;
951                    }
952    
953                    List<User> list = findByUuid_C(uuid, companyId, count - 1, count,
954                                    orderByComparator);
955    
956                    if (!list.isEmpty()) {
957                            return list.get(0);
958                    }
959    
960                    return null;
961            }
962    
963            /**
964             * Returns the users before and after the current user in the ordered set where uuid = &#63; and companyId = &#63;.
965             *
966             * @param userId the primary key of the current user
967             * @param uuid the uuid
968             * @param companyId the company ID
969             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
970             * @return the previous, current, and next user
971             * @throws NoSuchUserException if a user with the primary key could not be found
972             */
973            @Override
974            public User[] findByUuid_C_PrevAndNext(long userId, String uuid,
975                    long companyId, OrderByComparator<User> orderByComparator)
976                    throws NoSuchUserException {
977                    User user = findByPrimaryKey(userId);
978    
979                    Session session = null;
980    
981                    try {
982                            session = openSession();
983    
984                            User[] array = new UserImpl[3];
985    
986                            array[0] = getByUuid_C_PrevAndNext(session, user, uuid, companyId,
987                                            orderByComparator, true);
988    
989                            array[1] = user;
990    
991                            array[2] = getByUuid_C_PrevAndNext(session, user, uuid, companyId,
992                                            orderByComparator, false);
993    
994                            return array;
995                    }
996                    catch (Exception e) {
997                            throw processException(e);
998                    }
999                    finally {
1000                            closeSession(session);
1001                    }
1002            }
1003    
1004            protected User getByUuid_C_PrevAndNext(Session session, User user,
1005                    String uuid, long companyId, OrderByComparator<User> orderByComparator,
1006                    boolean previous) {
1007                    StringBundler query = null;
1008    
1009                    if (orderByComparator != null) {
1010                            query = new StringBundler(6 +
1011                                            (orderByComparator.getOrderByFields().length * 6));
1012                    }
1013                    else {
1014                            query = new StringBundler(3);
1015                    }
1016    
1017                    query.append(_SQL_SELECT_USER_WHERE);
1018    
1019                    boolean bindUuid = false;
1020    
1021                    if (uuid == null) {
1022                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1023                    }
1024                    else if (uuid.equals(StringPool.BLANK)) {
1025                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1026                    }
1027                    else {
1028                            bindUuid = true;
1029    
1030                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1031                    }
1032    
1033                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1034    
1035                    if (orderByComparator != null) {
1036                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1037    
1038                            if (orderByConditionFields.length > 0) {
1039                                    query.append(WHERE_AND);
1040                            }
1041    
1042                            for (int i = 0; i < orderByConditionFields.length; i++) {
1043                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1044                                    query.append(orderByConditionFields[i]);
1045    
1046                                    if ((i + 1) < orderByConditionFields.length) {
1047                                            if (orderByComparator.isAscending() ^ previous) {
1048                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1049                                            }
1050                                            else {
1051                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1052                                            }
1053                                    }
1054                                    else {
1055                                            if (orderByComparator.isAscending() ^ previous) {
1056                                                    query.append(WHERE_GREATER_THAN);
1057                                            }
1058                                            else {
1059                                                    query.append(WHERE_LESSER_THAN);
1060                                            }
1061                                    }
1062                            }
1063    
1064                            query.append(ORDER_BY_CLAUSE);
1065    
1066                            String[] orderByFields = orderByComparator.getOrderByFields();
1067    
1068                            for (int i = 0; i < orderByFields.length; i++) {
1069                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1070                                    query.append(orderByFields[i]);
1071    
1072                                    if ((i + 1) < orderByFields.length) {
1073                                            if (orderByComparator.isAscending() ^ previous) {
1074                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1075                                            }
1076                                            else {
1077                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1078                                            }
1079                                    }
1080                                    else {
1081                                            if (orderByComparator.isAscending() ^ previous) {
1082                                                    query.append(ORDER_BY_ASC);
1083                                            }
1084                                            else {
1085                                                    query.append(ORDER_BY_DESC);
1086                                            }
1087                                    }
1088                            }
1089                    }
1090                    else {
1091                            query.append(UserModelImpl.ORDER_BY_JPQL);
1092                    }
1093    
1094                    String sql = query.toString();
1095    
1096                    Query q = session.createQuery(sql);
1097    
1098                    q.setFirstResult(0);
1099                    q.setMaxResults(2);
1100    
1101                    QueryPos qPos = QueryPos.getInstance(q);
1102    
1103                    if (bindUuid) {
1104                            qPos.add(uuid);
1105                    }
1106    
1107                    qPos.add(companyId);
1108    
1109                    if (orderByComparator != null) {
1110                            Object[] values = orderByComparator.getOrderByConditionValues(user);
1111    
1112                            for (Object value : values) {
1113                                    qPos.add(value);
1114                            }
1115                    }
1116    
1117                    List<User> list = q.list();
1118    
1119                    if (list.size() == 2) {
1120                            return list.get(1);
1121                    }
1122                    else {
1123                            return null;
1124                    }
1125            }
1126    
1127            /**
1128             * Removes all the users where uuid = &#63; and companyId = &#63; from the database.
1129             *
1130             * @param uuid the uuid
1131             * @param companyId the company ID
1132             */
1133            @Override
1134            public void removeByUuid_C(String uuid, long companyId) {
1135                    for (User user : findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1136                                    QueryUtil.ALL_POS, null)) {
1137                            remove(user);
1138                    }
1139            }
1140    
1141            /**
1142             * Returns the number of users where uuid = &#63; and companyId = &#63;.
1143             *
1144             * @param uuid the uuid
1145             * @param companyId the company ID
1146             * @return the number of matching users
1147             */
1148            @Override
1149            public int countByUuid_C(String uuid, long companyId) {
1150                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1151    
1152                    Object[] finderArgs = new Object[] { uuid, companyId };
1153    
1154                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1155    
1156                    if (count == null) {
1157                            StringBundler query = new StringBundler(3);
1158    
1159                            query.append(_SQL_COUNT_USER_WHERE);
1160    
1161                            boolean bindUuid = false;
1162    
1163                            if (uuid == null) {
1164                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1165                            }
1166                            else if (uuid.equals(StringPool.BLANK)) {
1167                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1168                            }
1169                            else {
1170                                    bindUuid = true;
1171    
1172                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1173                            }
1174    
1175                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1176    
1177                            String sql = query.toString();
1178    
1179                            Session session = null;
1180    
1181                            try {
1182                                    session = openSession();
1183    
1184                                    Query q = session.createQuery(sql);
1185    
1186                                    QueryPos qPos = QueryPos.getInstance(q);
1187    
1188                                    if (bindUuid) {
1189                                            qPos.add(uuid);
1190                                    }
1191    
1192                                    qPos.add(companyId);
1193    
1194                                    count = (Long)q.uniqueResult();
1195    
1196                                    finderCache.putResult(finderPath, finderArgs, count);
1197                            }
1198                            catch (Exception e) {
1199                                    finderCache.removeResult(finderPath, finderArgs);
1200    
1201                                    throw processException(e);
1202                            }
1203                            finally {
1204                                    closeSession(session);
1205                            }
1206                    }
1207    
1208                    return count.intValue();
1209            }
1210    
1211            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "user.uuid IS NULL AND ";
1212            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "user.uuid = ? AND ";
1213            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(user.uuid IS NULL OR user.uuid = '') AND ";
1214            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "user.companyId = ?";
1215            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
1216                    new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
1217                            UserModelImpl.FINDER_CACHE_ENABLED, UserImpl.class,
1218                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
1219                            new String[] {
1220                                    Long.class.getName(),
1221                                    
1222                            Integer.class.getName(), Integer.class.getName(),
1223                                    OrderByComparator.class.getName()
1224                            });
1225            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
1226                    new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
1227                            UserModelImpl.FINDER_CACHE_ENABLED, UserImpl.class,
1228                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
1229                            new String[] { Long.class.getName() },
1230                            UserModelImpl.COMPANYID_COLUMN_BITMASK);
1231            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
1232                            UserModelImpl.FINDER_CACHE_ENABLED, Long.class,
1233                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
1234                            new String[] { Long.class.getName() });
1235    
1236            /**
1237             * Returns all the users where companyId = &#63;.
1238             *
1239             * @param companyId the company ID
1240             * @return the matching users
1241             */
1242            @Override
1243            public List<User> findByCompanyId(long companyId) {
1244                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1245                            null);
1246            }
1247    
1248            /**
1249             * Returns a range of all the users where companyId = &#63;.
1250             *
1251             * <p>
1252             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
1253             * </p>
1254             *
1255             * @param companyId the company ID
1256             * @param start the lower bound of the range of users
1257             * @param end the upper bound of the range of users (not inclusive)
1258             * @return the range of matching users
1259             */
1260            @Override
1261            public List<User> findByCompanyId(long companyId, int start, int end) {
1262                    return findByCompanyId(companyId, start, end, null);
1263            }
1264    
1265            /**
1266             * Returns an ordered range of all the users where companyId = &#63;.
1267             *
1268             * <p>
1269             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
1270             * </p>
1271             *
1272             * @param companyId the company ID
1273             * @param start the lower bound of the range of users
1274             * @param end the upper bound of the range of users (not inclusive)
1275             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1276             * @return the ordered range of matching users
1277             */
1278            @Override
1279            public List<User> findByCompanyId(long companyId, int start, int end,
1280                    OrderByComparator<User> orderByComparator) {
1281                    return findByCompanyId(companyId, start, end, orderByComparator, true);
1282            }
1283    
1284            /**
1285             * Returns an ordered range of all the users where companyId = &#63;.
1286             *
1287             * <p>
1288             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
1289             * </p>
1290             *
1291             * @param companyId the company ID
1292             * @param start the lower bound of the range of users
1293             * @param end the upper bound of the range of users (not inclusive)
1294             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1295             * @param retrieveFromCache whether to retrieve from the finder cache
1296             * @return the ordered range of matching users
1297             */
1298            @Override
1299            public List<User> findByCompanyId(long companyId, int start, int end,
1300                    OrderByComparator<User> orderByComparator, boolean retrieveFromCache) {
1301                    boolean pagination = true;
1302                    FinderPath finderPath = null;
1303                    Object[] finderArgs = null;
1304    
1305                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1306                                    (orderByComparator == null)) {
1307                            pagination = false;
1308                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1309                            finderArgs = new Object[] { companyId };
1310                    }
1311                    else {
1312                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1313                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
1314                    }
1315    
1316                    List<User> list = null;
1317    
1318                    if (retrieveFromCache) {
1319                            list = (List<User>)finderCache.getResult(finderPath, finderArgs,
1320                                            this);
1321    
1322                            if ((list != null) && !list.isEmpty()) {
1323                                    for (User user : list) {
1324                                            if ((companyId != user.getCompanyId())) {
1325                                                    list = null;
1326    
1327                                                    break;
1328                                            }
1329                                    }
1330                            }
1331                    }
1332    
1333                    if (list == null) {
1334                            StringBundler query = null;
1335    
1336                            if (orderByComparator != null) {
1337                                    query = new StringBundler(3 +
1338                                                    (orderByComparator.getOrderByFields().length * 3));
1339                            }
1340                            else {
1341                                    query = new StringBundler(3);
1342                            }
1343    
1344                            query.append(_SQL_SELECT_USER_WHERE);
1345    
1346                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1347    
1348                            if (orderByComparator != null) {
1349                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1350                                            orderByComparator);
1351                            }
1352                            else
1353                             if (pagination) {
1354                                    query.append(UserModelImpl.ORDER_BY_JPQL);
1355                            }
1356    
1357                            String sql = query.toString();
1358    
1359                            Session session = null;
1360    
1361                            try {
1362                                    session = openSession();
1363    
1364                                    Query q = session.createQuery(sql);
1365    
1366                                    QueryPos qPos = QueryPos.getInstance(q);
1367    
1368                                    qPos.add(companyId);
1369    
1370                                    if (!pagination) {
1371                                            list = (List<User>)QueryUtil.list(q, getDialect(), start,
1372                                                            end, false);
1373    
1374                                            Collections.sort(list);
1375    
1376                                            list = Collections.unmodifiableList(list);
1377                                    }
1378                                    else {
1379                                            list = (List<User>)QueryUtil.list(q, getDialect(), start,
1380                                                            end);
1381                                    }
1382    
1383                                    cacheResult(list);
1384    
1385                                    finderCache.putResult(finderPath, finderArgs, list);
1386                            }
1387                            catch (Exception e) {
1388                                    finderCache.removeResult(finderPath, finderArgs);
1389    
1390                                    throw processException(e);
1391                            }
1392                            finally {
1393                                    closeSession(session);
1394                            }
1395                    }
1396    
1397                    return list;
1398            }
1399    
1400            /**
1401             * Returns the first user in the ordered set where companyId = &#63;.
1402             *
1403             * @param companyId the company ID
1404             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1405             * @return the first matching user
1406             * @throws NoSuchUserException if a matching user could not be found
1407             */
1408            @Override
1409            public User findByCompanyId_First(long companyId,
1410                    OrderByComparator<User> orderByComparator) throws NoSuchUserException {
1411                    User user = fetchByCompanyId_First(companyId, orderByComparator);
1412    
1413                    if (user != null) {
1414                            return user;
1415                    }
1416    
1417                    StringBundler msg = new StringBundler(4);
1418    
1419                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1420    
1421                    msg.append("companyId=");
1422                    msg.append(companyId);
1423    
1424                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1425    
1426                    throw new NoSuchUserException(msg.toString());
1427            }
1428    
1429            /**
1430             * Returns the first user in the ordered set where companyId = &#63;.
1431             *
1432             * @param companyId the company ID
1433             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1434             * @return the first matching user, or <code>null</code> if a matching user could not be found
1435             */
1436            @Override
1437            public User fetchByCompanyId_First(long companyId,
1438                    OrderByComparator<User> orderByComparator) {
1439                    List<User> list = findByCompanyId(companyId, 0, 1, orderByComparator);
1440    
1441                    if (!list.isEmpty()) {
1442                            return list.get(0);
1443                    }
1444    
1445                    return null;
1446            }
1447    
1448            /**
1449             * Returns the last user in the ordered set where companyId = &#63;.
1450             *
1451             * @param companyId the company ID
1452             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1453             * @return the last matching user
1454             * @throws NoSuchUserException if a matching user could not be found
1455             */
1456            @Override
1457            public User findByCompanyId_Last(long companyId,
1458                    OrderByComparator<User> orderByComparator) throws NoSuchUserException {
1459                    User user = fetchByCompanyId_Last(companyId, orderByComparator);
1460    
1461                    if (user != null) {
1462                            return user;
1463                    }
1464    
1465                    StringBundler msg = new StringBundler(4);
1466    
1467                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1468    
1469                    msg.append("companyId=");
1470                    msg.append(companyId);
1471    
1472                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1473    
1474                    throw new NoSuchUserException(msg.toString());
1475            }
1476    
1477            /**
1478             * Returns the last user in the ordered set where companyId = &#63;.
1479             *
1480             * @param companyId the company ID
1481             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1482             * @return the last matching user, or <code>null</code> if a matching user could not be found
1483             */
1484            @Override
1485            public User fetchByCompanyId_Last(long companyId,
1486                    OrderByComparator<User> orderByComparator) {
1487                    int count = countByCompanyId(companyId);
1488    
1489                    if (count == 0) {
1490                            return null;
1491                    }
1492    
1493                    List<User> list = findByCompanyId(companyId, count - 1, count,
1494                                    orderByComparator);
1495    
1496                    if (!list.isEmpty()) {
1497                            return list.get(0);
1498                    }
1499    
1500                    return null;
1501            }
1502    
1503            /**
1504             * Returns the users before and after the current user in the ordered set where companyId = &#63;.
1505             *
1506             * @param userId the primary key of the current user
1507             * @param companyId the company ID
1508             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1509             * @return the previous, current, and next user
1510             * @throws NoSuchUserException if a user with the primary key could not be found
1511             */
1512            @Override
1513            public User[] findByCompanyId_PrevAndNext(long userId, long companyId,
1514                    OrderByComparator<User> orderByComparator) throws NoSuchUserException {
1515                    User user = findByPrimaryKey(userId);
1516    
1517                    Session session = null;
1518    
1519                    try {
1520                            session = openSession();
1521    
1522                            User[] array = new UserImpl[3];
1523    
1524                            array[0] = getByCompanyId_PrevAndNext(session, user, companyId,
1525                                            orderByComparator, true);
1526    
1527                            array[1] = user;
1528    
1529                            array[2] = getByCompanyId_PrevAndNext(session, user, companyId,
1530                                            orderByComparator, false);
1531    
1532                            return array;
1533                    }
1534                    catch (Exception e) {
1535                            throw processException(e);
1536                    }
1537                    finally {
1538                            closeSession(session);
1539                    }
1540            }
1541    
1542            protected User getByCompanyId_PrevAndNext(Session session, User user,
1543                    long companyId, OrderByComparator<User> orderByComparator,
1544                    boolean previous) {
1545                    StringBundler query = null;
1546    
1547                    if (orderByComparator != null) {
1548                            query = new StringBundler(6 +
1549                                            (orderByComparator.getOrderByFields().length * 6));
1550                    }
1551                    else {
1552                            query = new StringBundler(3);
1553                    }
1554    
1555                    query.append(_SQL_SELECT_USER_WHERE);
1556    
1557                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1558    
1559                    if (orderByComparator != null) {
1560                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1561    
1562                            if (orderByConditionFields.length > 0) {
1563                                    query.append(WHERE_AND);
1564                            }
1565    
1566                            for (int i = 0; i < orderByConditionFields.length; i++) {
1567                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1568                                    query.append(orderByConditionFields[i]);
1569    
1570                                    if ((i + 1) < orderByConditionFields.length) {
1571                                            if (orderByComparator.isAscending() ^ previous) {
1572                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1573                                            }
1574                                            else {
1575                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1576                                            }
1577                                    }
1578                                    else {
1579                                            if (orderByComparator.isAscending() ^ previous) {
1580                                                    query.append(WHERE_GREATER_THAN);
1581                                            }
1582                                            else {
1583                                                    query.append(WHERE_LESSER_THAN);
1584                                            }
1585                                    }
1586                            }
1587    
1588                            query.append(ORDER_BY_CLAUSE);
1589    
1590                            String[] orderByFields = orderByComparator.getOrderByFields();
1591    
1592                            for (int i = 0; i < orderByFields.length; i++) {
1593                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1594                                    query.append(orderByFields[i]);
1595    
1596                                    if ((i + 1) < orderByFields.length) {
1597                                            if (orderByComparator.isAscending() ^ previous) {
1598                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1599                                            }
1600                                            else {
1601                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1602                                            }
1603                                    }
1604                                    else {
1605                                            if (orderByComparator.isAscending() ^ previous) {
1606                                                    query.append(ORDER_BY_ASC);
1607                                            }
1608                                            else {
1609                                                    query.append(ORDER_BY_DESC);
1610                                            }
1611                                    }
1612                            }
1613                    }
1614                    else {
1615                            query.append(UserModelImpl.ORDER_BY_JPQL);
1616                    }
1617    
1618                    String sql = query.toString();
1619    
1620                    Query q = session.createQuery(sql);
1621    
1622                    q.setFirstResult(0);
1623                    q.setMaxResults(2);
1624    
1625                    QueryPos qPos = QueryPos.getInstance(q);
1626    
1627                    qPos.add(companyId);
1628    
1629                    if (orderByComparator != null) {
1630                            Object[] values = orderByComparator.getOrderByConditionValues(user);
1631    
1632                            for (Object value : values) {
1633                                    qPos.add(value);
1634                            }
1635                    }
1636    
1637                    List<User> list = q.list();
1638    
1639                    if (list.size() == 2) {
1640                            return list.get(1);
1641                    }
1642                    else {
1643                            return null;
1644                    }
1645            }
1646    
1647            /**
1648             * Removes all the users where companyId = &#63; from the database.
1649             *
1650             * @param companyId the company ID
1651             */
1652            @Override
1653            public void removeByCompanyId(long companyId) {
1654                    for (User user : findByCompanyId(companyId, QueryUtil.ALL_POS,
1655                                    QueryUtil.ALL_POS, null)) {
1656                            remove(user);
1657                    }
1658            }
1659    
1660            /**
1661             * Returns the number of users where companyId = &#63;.
1662             *
1663             * @param companyId the company ID
1664             * @return the number of matching users
1665             */
1666            @Override
1667            public int countByCompanyId(long companyId) {
1668                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
1669    
1670                    Object[] finderArgs = new Object[] { companyId };
1671    
1672                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1673    
1674                    if (count == null) {
1675                            StringBundler query = new StringBundler(2);
1676    
1677                            query.append(_SQL_COUNT_USER_WHERE);
1678    
1679                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1680    
1681                            String sql = query.toString();
1682    
1683                            Session session = null;
1684    
1685                            try {
1686                                    session = openSession();
1687    
1688                                    Query q = session.createQuery(sql);
1689    
1690                                    QueryPos qPos = QueryPos.getInstance(q);
1691    
1692                                    qPos.add(companyId);
1693    
1694                                    count = (Long)q.uniqueResult();
1695    
1696                                    finderCache.putResult(finderPath, finderArgs, count);
1697                            }
1698                            catch (Exception e) {
1699                                    finderCache.removeResult(finderPath, finderArgs);
1700    
1701                                    throw processException(e);
1702                            }
1703                            finally {
1704                                    closeSession(session);
1705                            }
1706                    }
1707    
1708                    return count.intValue();
1709            }
1710    
1711            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "user.companyId = ?";
1712            public static final FinderPath FINDER_PATH_FETCH_BY_CONTACTID = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
1713                            UserModelImpl.FINDER_CACHE_ENABLED, UserImpl.class,
1714                            FINDER_CLASS_NAME_ENTITY, "fetchByContactId",
1715                            new String[] { Long.class.getName() },
1716                            UserModelImpl.CONTACTID_COLUMN_BITMASK);
1717            public static final FinderPath FINDER_PATH_COUNT_BY_CONTACTID = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
1718                            UserModelImpl.FINDER_CACHE_ENABLED, Long.class,
1719                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByContactId",
1720                            new String[] { Long.class.getName() });
1721    
1722            /**
1723             * Returns the user where contactId = &#63; or throws a {@link NoSuchUserException} if it could not be found.
1724             *
1725             * @param contactId the contact ID
1726             * @return the matching user
1727             * @throws NoSuchUserException if a matching user could not be found
1728             */
1729            @Override
1730            public User findByContactId(long contactId) throws NoSuchUserException {
1731                    User user = fetchByContactId(contactId);
1732    
1733                    if (user == null) {
1734                            StringBundler msg = new StringBundler(4);
1735    
1736                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1737    
1738                            msg.append("contactId=");
1739                            msg.append(contactId);
1740    
1741                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1742    
1743                            if (_log.isWarnEnabled()) {
1744                                    _log.warn(msg.toString());
1745                            }
1746    
1747                            throw new NoSuchUserException(msg.toString());
1748                    }
1749    
1750                    return user;
1751            }
1752    
1753            /**
1754             * Returns the user where contactId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1755             *
1756             * @param contactId the contact ID
1757             * @return the matching user, or <code>null</code> if a matching user could not be found
1758             */
1759            @Override
1760            public User fetchByContactId(long contactId) {
1761                    return fetchByContactId(contactId, true);
1762            }
1763    
1764            /**
1765             * Returns the user where contactId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1766             *
1767             * @param contactId the contact ID
1768             * @param retrieveFromCache whether to retrieve from the finder cache
1769             * @return the matching user, or <code>null</code> if a matching user could not be found
1770             */
1771            @Override
1772            public User fetchByContactId(long contactId, boolean retrieveFromCache) {
1773                    Object[] finderArgs = new Object[] { contactId };
1774    
1775                    Object result = null;
1776    
1777                    if (retrieveFromCache) {
1778                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_CONTACTID,
1779                                            finderArgs, this);
1780                    }
1781    
1782                    if (result instanceof User) {
1783                            User user = (User)result;
1784    
1785                            if ((contactId != user.getContactId())) {
1786                                    result = null;
1787                            }
1788                    }
1789    
1790                    if (result == null) {
1791                            StringBundler query = new StringBundler(3);
1792    
1793                            query.append(_SQL_SELECT_USER_WHERE);
1794    
1795                            query.append(_FINDER_COLUMN_CONTACTID_CONTACTID_2);
1796    
1797                            String sql = query.toString();
1798    
1799                            Session session = null;
1800    
1801                            try {
1802                                    session = openSession();
1803    
1804                                    Query q = session.createQuery(sql);
1805    
1806                                    QueryPos qPos = QueryPos.getInstance(q);
1807    
1808                                    qPos.add(contactId);
1809    
1810                                    List<User> list = q.list();
1811    
1812                                    if (list.isEmpty()) {
1813                                            finderCache.putResult(FINDER_PATH_FETCH_BY_CONTACTID,
1814                                                    finderArgs, list);
1815                                    }
1816                                    else {
1817                                            User user = list.get(0);
1818    
1819                                            result = user;
1820    
1821                                            cacheResult(user);
1822    
1823                                            if ((user.getContactId() != contactId)) {
1824                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_CONTACTID,
1825                                                            finderArgs, user);
1826                                            }
1827                                    }
1828                            }
1829                            catch (Exception e) {
1830                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_CONTACTID,
1831                                            finderArgs);
1832    
1833                                    throw processException(e);
1834                            }
1835                            finally {
1836                                    closeSession(session);
1837                            }
1838                    }
1839    
1840                    if (result instanceof List<?>) {
1841                            return null;
1842                    }
1843                    else {
1844                            return (User)result;
1845                    }
1846            }
1847    
1848            /**
1849             * Removes the user where contactId = &#63; from the database.
1850             *
1851             * @param contactId the contact ID
1852             * @return the user that was removed
1853             */
1854            @Override
1855            public User removeByContactId(long contactId) throws NoSuchUserException {
1856                    User user = findByContactId(contactId);
1857    
1858                    return remove(user);
1859            }
1860    
1861            /**
1862             * Returns the number of users where contactId = &#63;.
1863             *
1864             * @param contactId the contact ID
1865             * @return the number of matching users
1866             */
1867            @Override
1868            public int countByContactId(long contactId) {
1869                    FinderPath finderPath = FINDER_PATH_COUNT_BY_CONTACTID;
1870    
1871                    Object[] finderArgs = new Object[] { contactId };
1872    
1873                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1874    
1875                    if (count == null) {
1876                            StringBundler query = new StringBundler(2);
1877    
1878                            query.append(_SQL_COUNT_USER_WHERE);
1879    
1880                            query.append(_FINDER_COLUMN_CONTACTID_CONTACTID_2);
1881    
1882                            String sql = query.toString();
1883    
1884                            Session session = null;
1885    
1886                            try {
1887                                    session = openSession();
1888    
1889                                    Query q = session.createQuery(sql);
1890    
1891                                    QueryPos qPos = QueryPos.getInstance(q);
1892    
1893                                    qPos.add(contactId);
1894    
1895                                    count = (Long)q.uniqueResult();
1896    
1897                                    finderCache.putResult(finderPath, finderArgs, count);
1898                            }
1899                            catch (Exception e) {
1900                                    finderCache.removeResult(finderPath, finderArgs);
1901    
1902                                    throw processException(e);
1903                            }
1904                            finally {
1905                                    closeSession(session);
1906                            }
1907                    }
1908    
1909                    return count.intValue();
1910            }
1911    
1912            private static final String _FINDER_COLUMN_CONTACTID_CONTACTID_2 = "user.contactId = ?";
1913            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_EMAILADDRESS =
1914                    new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
1915                            UserModelImpl.FINDER_CACHE_ENABLED, UserImpl.class,
1916                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByEmailAddress",
1917                            new String[] {
1918                                    String.class.getName(),
1919                                    
1920                            Integer.class.getName(), Integer.class.getName(),
1921                                    OrderByComparator.class.getName()
1922                            });
1923            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_EMAILADDRESS =
1924                    new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
1925                            UserModelImpl.FINDER_CACHE_ENABLED, UserImpl.class,
1926                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByEmailAddress",
1927                            new String[] { String.class.getName() },
1928                            UserModelImpl.EMAILADDRESS_COLUMN_BITMASK);
1929            public static final FinderPath FINDER_PATH_COUNT_BY_EMAILADDRESS = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
1930                            UserModelImpl.FINDER_CACHE_ENABLED, Long.class,
1931                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByEmailAddress",
1932                            new String[] { String.class.getName() });
1933    
1934            /**
1935             * Returns all the users where emailAddress = &#63;.
1936             *
1937             * @param emailAddress the email address
1938             * @return the matching users
1939             */
1940            @Override
1941            public List<User> findByEmailAddress(String emailAddress) {
1942                    return findByEmailAddress(emailAddress, QueryUtil.ALL_POS,
1943                            QueryUtil.ALL_POS, null);
1944            }
1945    
1946            /**
1947             * Returns a range of all the users where emailAddress = &#63;.
1948             *
1949             * <p>
1950             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
1951             * </p>
1952             *
1953             * @param emailAddress the email address
1954             * @param start the lower bound of the range of users
1955             * @param end the upper bound of the range of users (not inclusive)
1956             * @return the range of matching users
1957             */
1958            @Override
1959            public List<User> findByEmailAddress(String emailAddress, int start, int end) {
1960                    return findByEmailAddress(emailAddress, start, end, null);
1961            }
1962    
1963            /**
1964             * Returns an ordered range of all the users where emailAddress = &#63;.
1965             *
1966             * <p>
1967             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
1968             * </p>
1969             *
1970             * @param emailAddress the email address
1971             * @param start the lower bound of the range of users
1972             * @param end the upper bound of the range of users (not inclusive)
1973             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1974             * @return the ordered range of matching users
1975             */
1976            @Override
1977            public List<User> findByEmailAddress(String emailAddress, int start,
1978                    int end, OrderByComparator<User> orderByComparator) {
1979                    return findByEmailAddress(emailAddress, start, end, orderByComparator,
1980                            true);
1981            }
1982    
1983            /**
1984             * Returns an ordered range of all the users where emailAddress = &#63;.
1985             *
1986             * <p>
1987             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
1988             * </p>
1989             *
1990             * @param emailAddress the email address
1991             * @param start the lower bound of the range of users
1992             * @param end the upper bound of the range of users (not inclusive)
1993             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1994             * @param retrieveFromCache whether to retrieve from the finder cache
1995             * @return the ordered range of matching users
1996             */
1997            @Override
1998            public List<User> findByEmailAddress(String emailAddress, int start,
1999                    int end, OrderByComparator<User> orderByComparator,
2000                    boolean retrieveFromCache) {
2001                    boolean pagination = true;
2002                    FinderPath finderPath = null;
2003                    Object[] finderArgs = null;
2004    
2005                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2006                                    (orderByComparator == null)) {
2007                            pagination = false;
2008                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_EMAILADDRESS;
2009                            finderArgs = new Object[] { emailAddress };
2010                    }
2011                    else {
2012                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_EMAILADDRESS;
2013                            finderArgs = new Object[] {
2014                                            emailAddress,
2015                                            
2016                                            start, end, orderByComparator
2017                                    };
2018                    }
2019    
2020                    List<User> list = null;
2021    
2022                    if (retrieveFromCache) {
2023                            list = (List<User>)finderCache.getResult(finderPath, finderArgs,
2024                                            this);
2025    
2026                            if ((list != null) && !list.isEmpty()) {
2027                                    for (User user : list) {
2028                                            if (!Validator.equals(emailAddress, user.getEmailAddress())) {
2029                                                    list = null;
2030    
2031                                                    break;
2032                                            }
2033                                    }
2034                            }
2035                    }
2036    
2037                    if (list == null) {
2038                            StringBundler query = null;
2039    
2040                            if (orderByComparator != null) {
2041                                    query = new StringBundler(3 +
2042                                                    (orderByComparator.getOrderByFields().length * 3));
2043                            }
2044                            else {
2045                                    query = new StringBundler(3);
2046                            }
2047    
2048                            query.append(_SQL_SELECT_USER_WHERE);
2049    
2050                            boolean bindEmailAddress = false;
2051    
2052                            if (emailAddress == null) {
2053                                    query.append(_FINDER_COLUMN_EMAILADDRESS_EMAILADDRESS_1);
2054                            }
2055                            else if (emailAddress.equals(StringPool.BLANK)) {
2056                                    query.append(_FINDER_COLUMN_EMAILADDRESS_EMAILADDRESS_3);
2057                            }
2058                            else {
2059                                    bindEmailAddress = true;
2060    
2061                                    query.append(_FINDER_COLUMN_EMAILADDRESS_EMAILADDRESS_2);
2062                            }
2063    
2064                            if (orderByComparator != null) {
2065                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2066                                            orderByComparator);
2067                            }
2068                            else
2069                             if (pagination) {
2070                                    query.append(UserModelImpl.ORDER_BY_JPQL);
2071                            }
2072    
2073                            String sql = query.toString();
2074    
2075                            Session session = null;
2076    
2077                            try {
2078                                    session = openSession();
2079    
2080                                    Query q = session.createQuery(sql);
2081    
2082                                    QueryPos qPos = QueryPos.getInstance(q);
2083    
2084                                    if (bindEmailAddress) {
2085                                            qPos.add(emailAddress);
2086                                    }
2087    
2088                                    if (!pagination) {
2089                                            list = (List<User>)QueryUtil.list(q, getDialect(), start,
2090                                                            end, false);
2091    
2092                                            Collections.sort(list);
2093    
2094                                            list = Collections.unmodifiableList(list);
2095                                    }
2096                                    else {
2097                                            list = (List<User>)QueryUtil.list(q, getDialect(), start,
2098                                                            end);
2099                                    }
2100    
2101                                    cacheResult(list);
2102    
2103                                    finderCache.putResult(finderPath, finderArgs, list);
2104                            }
2105                            catch (Exception e) {
2106                                    finderCache.removeResult(finderPath, finderArgs);
2107    
2108                                    throw processException(e);
2109                            }
2110                            finally {
2111                                    closeSession(session);
2112                            }
2113                    }
2114    
2115                    return list;
2116            }
2117    
2118            /**
2119             * Returns the first user in the ordered set where emailAddress = &#63;.
2120             *
2121             * @param emailAddress the email address
2122             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2123             * @return the first matching user
2124             * @throws NoSuchUserException if a matching user could not be found
2125             */
2126            @Override
2127            public User findByEmailAddress_First(String emailAddress,
2128                    OrderByComparator<User> orderByComparator) throws NoSuchUserException {
2129                    User user = fetchByEmailAddress_First(emailAddress, orderByComparator);
2130    
2131                    if (user != null) {
2132                            return user;
2133                    }
2134    
2135                    StringBundler msg = new StringBundler(4);
2136    
2137                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2138    
2139                    msg.append("emailAddress=");
2140                    msg.append(emailAddress);
2141    
2142                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2143    
2144                    throw new NoSuchUserException(msg.toString());
2145            }
2146    
2147            /**
2148             * Returns the first user in the ordered set where emailAddress = &#63;.
2149             *
2150             * @param emailAddress the email address
2151             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2152             * @return the first matching user, or <code>null</code> if a matching user could not be found
2153             */
2154            @Override
2155            public User fetchByEmailAddress_First(String emailAddress,
2156                    OrderByComparator<User> orderByComparator) {
2157                    List<User> list = findByEmailAddress(emailAddress, 0, 1,
2158                                    orderByComparator);
2159    
2160                    if (!list.isEmpty()) {
2161                            return list.get(0);
2162                    }
2163    
2164                    return null;
2165            }
2166    
2167            /**
2168             * Returns the last user in the ordered set where emailAddress = &#63;.
2169             *
2170             * @param emailAddress the email address
2171             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2172             * @return the last matching user
2173             * @throws NoSuchUserException if a matching user could not be found
2174             */
2175            @Override
2176            public User findByEmailAddress_Last(String emailAddress,
2177                    OrderByComparator<User> orderByComparator) throws NoSuchUserException {
2178                    User user = fetchByEmailAddress_Last(emailAddress, orderByComparator);
2179    
2180                    if (user != null) {
2181                            return user;
2182                    }
2183    
2184                    StringBundler msg = new StringBundler(4);
2185    
2186                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2187    
2188                    msg.append("emailAddress=");
2189                    msg.append(emailAddress);
2190    
2191                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2192    
2193                    throw new NoSuchUserException(msg.toString());
2194            }
2195    
2196            /**
2197             * Returns the last user in the ordered set where emailAddress = &#63;.
2198             *
2199             * @param emailAddress the email address
2200             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2201             * @return the last matching user, or <code>null</code> if a matching user could not be found
2202             */
2203            @Override
2204            public User fetchByEmailAddress_Last(String emailAddress,
2205                    OrderByComparator<User> orderByComparator) {
2206                    int count = countByEmailAddress(emailAddress);
2207    
2208                    if (count == 0) {
2209                            return null;
2210                    }
2211    
2212                    List<User> list = findByEmailAddress(emailAddress, count - 1, count,
2213                                    orderByComparator);
2214    
2215                    if (!list.isEmpty()) {
2216                            return list.get(0);
2217                    }
2218    
2219                    return null;
2220            }
2221    
2222            /**
2223             * Returns the users before and after the current user in the ordered set where emailAddress = &#63;.
2224             *
2225             * @param userId the primary key of the current user
2226             * @param emailAddress the email address
2227             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2228             * @return the previous, current, and next user
2229             * @throws NoSuchUserException if a user with the primary key could not be found
2230             */
2231            @Override
2232            public User[] findByEmailAddress_PrevAndNext(long userId,
2233                    String emailAddress, OrderByComparator<User> orderByComparator)
2234                    throws NoSuchUserException {
2235                    User user = findByPrimaryKey(userId);
2236    
2237                    Session session = null;
2238    
2239                    try {
2240                            session = openSession();
2241    
2242                            User[] array = new UserImpl[3];
2243    
2244                            array[0] = getByEmailAddress_PrevAndNext(session, user,
2245                                            emailAddress, orderByComparator, true);
2246    
2247                            array[1] = user;
2248    
2249                            array[2] = getByEmailAddress_PrevAndNext(session, user,
2250                                            emailAddress, orderByComparator, false);
2251    
2252                            return array;
2253                    }
2254                    catch (Exception e) {
2255                            throw processException(e);
2256                    }
2257                    finally {
2258                            closeSession(session);
2259                    }
2260            }
2261    
2262            protected User getByEmailAddress_PrevAndNext(Session session, User user,
2263                    String emailAddress, OrderByComparator<User> orderByComparator,
2264                    boolean previous) {
2265                    StringBundler query = null;
2266    
2267                    if (orderByComparator != null) {
2268                            query = new StringBundler(6 +
2269                                            (orderByComparator.getOrderByFields().length * 6));
2270                    }
2271                    else {
2272                            query = new StringBundler(3);
2273                    }
2274    
2275                    query.append(_SQL_SELECT_USER_WHERE);
2276    
2277                    boolean bindEmailAddress = false;
2278    
2279                    if (emailAddress == null) {
2280                            query.append(_FINDER_COLUMN_EMAILADDRESS_EMAILADDRESS_1);
2281                    }
2282                    else if (emailAddress.equals(StringPool.BLANK)) {
2283                            query.append(_FINDER_COLUMN_EMAILADDRESS_EMAILADDRESS_3);
2284                    }
2285                    else {
2286                            bindEmailAddress = true;
2287    
2288                            query.append(_FINDER_COLUMN_EMAILADDRESS_EMAILADDRESS_2);
2289                    }
2290    
2291                    if (orderByComparator != null) {
2292                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2293    
2294                            if (orderByConditionFields.length > 0) {
2295                                    query.append(WHERE_AND);
2296                            }
2297    
2298                            for (int i = 0; i < orderByConditionFields.length; i++) {
2299                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2300                                    query.append(orderByConditionFields[i]);
2301    
2302                                    if ((i + 1) < orderByConditionFields.length) {
2303                                            if (orderByComparator.isAscending() ^ previous) {
2304                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2305                                            }
2306                                            else {
2307                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2308                                            }
2309                                    }
2310                                    else {
2311                                            if (orderByComparator.isAscending() ^ previous) {
2312                                                    query.append(WHERE_GREATER_THAN);
2313                                            }
2314                                            else {
2315                                                    query.append(WHERE_LESSER_THAN);
2316                                            }
2317                                    }
2318                            }
2319    
2320                            query.append(ORDER_BY_CLAUSE);
2321    
2322                            String[] orderByFields = orderByComparator.getOrderByFields();
2323    
2324                            for (int i = 0; i < orderByFields.length; i++) {
2325                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2326                                    query.append(orderByFields[i]);
2327    
2328                                    if ((i + 1) < orderByFields.length) {
2329                                            if (orderByComparator.isAscending() ^ previous) {
2330                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2331                                            }
2332                                            else {
2333                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2334                                            }
2335                                    }
2336                                    else {
2337                                            if (orderByComparator.isAscending() ^ previous) {
2338                                                    query.append(ORDER_BY_ASC);
2339                                            }
2340                                            else {
2341                                                    query.append(ORDER_BY_DESC);
2342                                            }
2343                                    }
2344                            }
2345                    }
2346                    else {
2347                            query.append(UserModelImpl.ORDER_BY_JPQL);
2348                    }
2349    
2350                    String sql = query.toString();
2351    
2352                    Query q = session.createQuery(sql);
2353    
2354                    q.setFirstResult(0);
2355                    q.setMaxResults(2);
2356    
2357                    QueryPos qPos = QueryPos.getInstance(q);
2358    
2359                    if (bindEmailAddress) {
2360                            qPos.add(emailAddress);
2361                    }
2362    
2363                    if (orderByComparator != null) {
2364                            Object[] values = orderByComparator.getOrderByConditionValues(user);
2365    
2366                            for (Object value : values) {
2367                                    qPos.add(value);
2368                            }
2369                    }
2370    
2371                    List<User> list = q.list();
2372    
2373                    if (list.size() == 2) {
2374                            return list.get(1);
2375                    }
2376                    else {
2377                            return null;
2378                    }
2379            }
2380    
2381            /**
2382             * Removes all the users where emailAddress = &#63; from the database.
2383             *
2384             * @param emailAddress the email address
2385             */
2386            @Override
2387            public void removeByEmailAddress(String emailAddress) {
2388                    for (User user : findByEmailAddress(emailAddress, QueryUtil.ALL_POS,
2389                                    QueryUtil.ALL_POS, null)) {
2390                            remove(user);
2391                    }
2392            }
2393    
2394            /**
2395             * Returns the number of users where emailAddress = &#63;.
2396             *
2397             * @param emailAddress the email address
2398             * @return the number of matching users
2399             */
2400            @Override
2401            public int countByEmailAddress(String emailAddress) {
2402                    FinderPath finderPath = FINDER_PATH_COUNT_BY_EMAILADDRESS;
2403    
2404                    Object[] finderArgs = new Object[] { emailAddress };
2405    
2406                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2407    
2408                    if (count == null) {
2409                            StringBundler query = new StringBundler(2);
2410    
2411                            query.append(_SQL_COUNT_USER_WHERE);
2412    
2413                            boolean bindEmailAddress = false;
2414    
2415                            if (emailAddress == null) {
2416                                    query.append(_FINDER_COLUMN_EMAILADDRESS_EMAILADDRESS_1);
2417                            }
2418                            else if (emailAddress.equals(StringPool.BLANK)) {
2419                                    query.append(_FINDER_COLUMN_EMAILADDRESS_EMAILADDRESS_3);
2420                            }
2421                            else {
2422                                    bindEmailAddress = true;
2423    
2424                                    query.append(_FINDER_COLUMN_EMAILADDRESS_EMAILADDRESS_2);
2425                            }
2426    
2427                            String sql = query.toString();
2428    
2429                            Session session = null;
2430    
2431                            try {
2432                                    session = openSession();
2433    
2434                                    Query q = session.createQuery(sql);
2435    
2436                                    QueryPos qPos = QueryPos.getInstance(q);
2437    
2438                                    if (bindEmailAddress) {
2439                                            qPos.add(emailAddress);
2440                                    }
2441    
2442                                    count = (Long)q.uniqueResult();
2443    
2444                                    finderCache.putResult(finderPath, finderArgs, count);
2445                            }
2446                            catch (Exception e) {
2447                                    finderCache.removeResult(finderPath, finderArgs);
2448    
2449                                    throw processException(e);
2450                            }
2451                            finally {
2452                                    closeSession(session);
2453                            }
2454                    }
2455    
2456                    return count.intValue();
2457            }
2458    
2459            private static final String _FINDER_COLUMN_EMAILADDRESS_EMAILADDRESS_1 = "user.emailAddress IS NULL";
2460            private static final String _FINDER_COLUMN_EMAILADDRESS_EMAILADDRESS_2 = "user.emailAddress = ?";
2461            private static final String _FINDER_COLUMN_EMAILADDRESS_EMAILADDRESS_3 = "(user.emailAddress IS NULL OR user.emailAddress = '')";
2462            public static final FinderPath FINDER_PATH_FETCH_BY_PORTRAITID = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
2463                            UserModelImpl.FINDER_CACHE_ENABLED, UserImpl.class,
2464                            FINDER_CLASS_NAME_ENTITY, "fetchByPortraitId",
2465                            new String[] { Long.class.getName() },
2466                            UserModelImpl.PORTRAITID_COLUMN_BITMASK);
2467            public static final FinderPath FINDER_PATH_COUNT_BY_PORTRAITID = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
2468                            UserModelImpl.FINDER_CACHE_ENABLED, Long.class,
2469                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByPortraitId",
2470                            new String[] { Long.class.getName() });
2471    
2472            /**
2473             * Returns the user where portraitId = &#63; or throws a {@link NoSuchUserException} if it could not be found.
2474             *
2475             * @param portraitId the portrait ID
2476             * @return the matching user
2477             * @throws NoSuchUserException if a matching user could not be found
2478             */
2479            @Override
2480            public User findByPortraitId(long portraitId) throws NoSuchUserException {
2481                    User user = fetchByPortraitId(portraitId);
2482    
2483                    if (user == null) {
2484                            StringBundler msg = new StringBundler(4);
2485    
2486                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2487    
2488                            msg.append("portraitId=");
2489                            msg.append(portraitId);
2490    
2491                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2492    
2493                            if (_log.isWarnEnabled()) {
2494                                    _log.warn(msg.toString());
2495                            }
2496    
2497                            throw new NoSuchUserException(msg.toString());
2498                    }
2499    
2500                    return user;
2501            }
2502    
2503            /**
2504             * Returns the user where portraitId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2505             *
2506             * @param portraitId the portrait ID
2507             * @return the matching user, or <code>null</code> if a matching user could not be found
2508             */
2509            @Override
2510            public User fetchByPortraitId(long portraitId) {
2511                    return fetchByPortraitId(portraitId, true);
2512            }
2513    
2514            /**
2515             * Returns the user where portraitId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2516             *
2517             * @param portraitId the portrait ID
2518             * @param retrieveFromCache whether to retrieve from the finder cache
2519             * @return the matching user, or <code>null</code> if a matching user could not be found
2520             */
2521            @Override
2522            public User fetchByPortraitId(long portraitId, boolean retrieveFromCache) {
2523                    Object[] finderArgs = new Object[] { portraitId };
2524    
2525                    Object result = null;
2526    
2527                    if (retrieveFromCache) {
2528                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_PORTRAITID,
2529                                            finderArgs, this);
2530                    }
2531    
2532                    if (result instanceof User) {
2533                            User user = (User)result;
2534    
2535                            if ((portraitId != user.getPortraitId())) {
2536                                    result = null;
2537                            }
2538                    }
2539    
2540                    if (result == null) {
2541                            StringBundler query = new StringBundler(3);
2542    
2543                            query.append(_SQL_SELECT_USER_WHERE);
2544    
2545                            query.append(_FINDER_COLUMN_PORTRAITID_PORTRAITID_2);
2546    
2547                            String sql = query.toString();
2548    
2549                            Session session = null;
2550    
2551                            try {
2552                                    session = openSession();
2553    
2554                                    Query q = session.createQuery(sql);
2555    
2556                                    QueryPos qPos = QueryPos.getInstance(q);
2557    
2558                                    qPos.add(portraitId);
2559    
2560                                    List<User> list = q.list();
2561    
2562                                    if (list.isEmpty()) {
2563                                            finderCache.putResult(FINDER_PATH_FETCH_BY_PORTRAITID,
2564                                                    finderArgs, list);
2565                                    }
2566                                    else {
2567                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
2568                                                    _log.warn(
2569                                                            "UserPersistenceImpl.fetchByPortraitId(long, boolean) with parameters (" +
2570                                                            StringUtil.merge(finderArgs) +
2571                                                            ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
2572                                            }
2573    
2574                                            User user = list.get(0);
2575    
2576                                            result = user;
2577    
2578                                            cacheResult(user);
2579    
2580                                            if ((user.getPortraitId() != portraitId)) {
2581                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_PORTRAITID,
2582                                                            finderArgs, user);
2583                                            }
2584                                    }
2585                            }
2586                            catch (Exception e) {
2587                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_PORTRAITID,
2588                                            finderArgs);
2589    
2590                                    throw processException(e);
2591                            }
2592                            finally {
2593                                    closeSession(session);
2594                            }
2595                    }
2596    
2597                    if (result instanceof List<?>) {
2598                            return null;
2599                    }
2600                    else {
2601                            return (User)result;
2602                    }
2603            }
2604    
2605            /**
2606             * Removes the user where portraitId = &#63; from the database.
2607             *
2608             * @param portraitId the portrait ID
2609             * @return the user that was removed
2610             */
2611            @Override
2612            public User removeByPortraitId(long portraitId) throws NoSuchUserException {
2613                    User user = findByPortraitId(portraitId);
2614    
2615                    return remove(user);
2616            }
2617    
2618            /**
2619             * Returns the number of users where portraitId = &#63;.
2620             *
2621             * @param portraitId the portrait ID
2622             * @return the number of matching users
2623             */
2624            @Override
2625            public int countByPortraitId(long portraitId) {
2626                    FinderPath finderPath = FINDER_PATH_COUNT_BY_PORTRAITID;
2627    
2628                    Object[] finderArgs = new Object[] { portraitId };
2629    
2630                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2631    
2632                    if (count == null) {
2633                            StringBundler query = new StringBundler(2);
2634    
2635                            query.append(_SQL_COUNT_USER_WHERE);
2636    
2637                            query.append(_FINDER_COLUMN_PORTRAITID_PORTRAITID_2);
2638    
2639                            String sql = query.toString();
2640    
2641                            Session session = null;
2642    
2643                            try {
2644                                    session = openSession();
2645    
2646                                    Query q = session.createQuery(sql);
2647    
2648                                    QueryPos qPos = QueryPos.getInstance(q);
2649    
2650                                    qPos.add(portraitId);
2651    
2652                                    count = (Long)q.uniqueResult();
2653    
2654                                    finderCache.putResult(finderPath, finderArgs, count);
2655                            }
2656                            catch (Exception e) {
2657                                    finderCache.removeResult(finderPath, finderArgs);
2658    
2659                                    throw processException(e);
2660                            }
2661                            finally {
2662                                    closeSession(session);
2663                            }
2664                    }
2665    
2666                    return count.intValue();
2667            }
2668    
2669            private static final String _FINDER_COLUMN_PORTRAITID_PORTRAITID_2 = "user.portraitId = ?";
2670            public static final FinderPath FINDER_PATH_FETCH_BY_C_U = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
2671                            UserModelImpl.FINDER_CACHE_ENABLED, UserImpl.class,
2672                            FINDER_CLASS_NAME_ENTITY, "fetchByC_U",
2673                            new String[] { Long.class.getName(), Long.class.getName() },
2674                            UserModelImpl.COMPANYID_COLUMN_BITMASK |
2675                            UserModelImpl.USERID_COLUMN_BITMASK);
2676            public static final FinderPath FINDER_PATH_COUNT_BY_C_U = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
2677                            UserModelImpl.FINDER_CACHE_ENABLED, Long.class,
2678                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_U",
2679                            new String[] { Long.class.getName(), Long.class.getName() });
2680    
2681            /**
2682             * Returns the user where companyId = &#63; and userId = &#63; or throws a {@link NoSuchUserException} if it could not be found.
2683             *
2684             * @param companyId the company ID
2685             * @param userId the user ID
2686             * @return the matching user
2687             * @throws NoSuchUserException if a matching user could not be found
2688             */
2689            @Override
2690            public User findByC_U(long companyId, long userId)
2691                    throws NoSuchUserException {
2692                    User user = fetchByC_U(companyId, userId);
2693    
2694                    if (user == null) {
2695                            StringBundler msg = new StringBundler(6);
2696    
2697                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2698    
2699                            msg.append("companyId=");
2700                            msg.append(companyId);
2701    
2702                            msg.append(", userId=");
2703                            msg.append(userId);
2704    
2705                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2706    
2707                            if (_log.isWarnEnabled()) {
2708                                    _log.warn(msg.toString());
2709                            }
2710    
2711                            throw new NoSuchUserException(msg.toString());
2712                    }
2713    
2714                    return user;
2715            }
2716    
2717            /**
2718             * Returns the user where companyId = &#63; and userId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2719             *
2720             * @param companyId the company ID
2721             * @param userId the user ID
2722             * @return the matching user, or <code>null</code> if a matching user could not be found
2723             */
2724            @Override
2725            public User fetchByC_U(long companyId, long userId) {
2726                    return fetchByC_U(companyId, userId, true);
2727            }
2728    
2729            /**
2730             * Returns the user where companyId = &#63; and userId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2731             *
2732             * @param companyId the company ID
2733             * @param userId the user ID
2734             * @param retrieveFromCache whether to retrieve from the finder cache
2735             * @return the matching user, or <code>null</code> if a matching user could not be found
2736             */
2737            @Override
2738            public User fetchByC_U(long companyId, long userId,
2739                    boolean retrieveFromCache) {
2740                    Object[] finderArgs = new Object[] { companyId, userId };
2741    
2742                    Object result = null;
2743    
2744                    if (retrieveFromCache) {
2745                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_C_U,
2746                                            finderArgs, this);
2747                    }
2748    
2749                    if (result instanceof User) {
2750                            User user = (User)result;
2751    
2752                            if ((companyId != user.getCompanyId()) ||
2753                                            (userId != user.getUserId())) {
2754                                    result = null;
2755                            }
2756                    }
2757    
2758                    if (result == null) {
2759                            StringBundler query = new StringBundler(4);
2760    
2761                            query.append(_SQL_SELECT_USER_WHERE);
2762    
2763                            query.append(_FINDER_COLUMN_C_U_COMPANYID_2);
2764    
2765                            query.append(_FINDER_COLUMN_C_U_USERID_2);
2766    
2767                            String sql = query.toString();
2768    
2769                            Session session = null;
2770    
2771                            try {
2772                                    session = openSession();
2773    
2774                                    Query q = session.createQuery(sql);
2775    
2776                                    QueryPos qPos = QueryPos.getInstance(q);
2777    
2778                                    qPos.add(companyId);
2779    
2780                                    qPos.add(userId);
2781    
2782                                    List<User> list = q.list();
2783    
2784                                    if (list.isEmpty()) {
2785                                            finderCache.putResult(FINDER_PATH_FETCH_BY_C_U, finderArgs,
2786                                                    list);
2787                                    }
2788                                    else {
2789                                            User user = list.get(0);
2790    
2791                                            result = user;
2792    
2793                                            cacheResult(user);
2794    
2795                                            if ((user.getCompanyId() != companyId) ||
2796                                                            (user.getUserId() != userId)) {
2797                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_U,
2798                                                            finderArgs, user);
2799                                            }
2800                                    }
2801                            }
2802                            catch (Exception e) {
2803                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_C_U, finderArgs);
2804    
2805                                    throw processException(e);
2806                            }
2807                            finally {
2808                                    closeSession(session);
2809                            }
2810                    }
2811    
2812                    if (result instanceof List<?>) {
2813                            return null;
2814                    }
2815                    else {
2816                            return (User)result;
2817                    }
2818            }
2819    
2820            /**
2821             * Removes the user where companyId = &#63; and userId = &#63; from the database.
2822             *
2823             * @param companyId the company ID
2824             * @param userId the user ID
2825             * @return the user that was removed
2826             */
2827            @Override
2828            public User removeByC_U(long companyId, long userId)
2829                    throws NoSuchUserException {
2830                    User user = findByC_U(companyId, userId);
2831    
2832                    return remove(user);
2833            }
2834    
2835            /**
2836             * Returns the number of users where companyId = &#63; and userId = &#63;.
2837             *
2838             * @param companyId the company ID
2839             * @param userId the user ID
2840             * @return the number of matching users
2841             */
2842            @Override
2843            public int countByC_U(long companyId, long userId) {
2844                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_U;
2845    
2846                    Object[] finderArgs = new Object[] { companyId, userId };
2847    
2848                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2849    
2850                    if (count == null) {
2851                            StringBundler query = new StringBundler(3);
2852    
2853                            query.append(_SQL_COUNT_USER_WHERE);
2854    
2855                            query.append(_FINDER_COLUMN_C_U_COMPANYID_2);
2856    
2857                            query.append(_FINDER_COLUMN_C_U_USERID_2);
2858    
2859                            String sql = query.toString();
2860    
2861                            Session session = null;
2862    
2863                            try {
2864                                    session = openSession();
2865    
2866                                    Query q = session.createQuery(sql);
2867    
2868                                    QueryPos qPos = QueryPos.getInstance(q);
2869    
2870                                    qPos.add(companyId);
2871    
2872                                    qPos.add(userId);
2873    
2874                                    count = (Long)q.uniqueResult();
2875    
2876                                    finderCache.putResult(finderPath, finderArgs, count);
2877                            }
2878                            catch (Exception e) {
2879                                    finderCache.removeResult(finderPath, finderArgs);
2880    
2881                                    throw processException(e);
2882                            }
2883                            finally {
2884                                    closeSession(session);
2885                            }
2886                    }
2887    
2888                    return count.intValue();
2889            }
2890    
2891            private static final String _FINDER_COLUMN_C_U_COMPANYID_2 = "user.companyId = ? AND ";
2892            private static final String _FINDER_COLUMN_C_U_USERID_2 = "user.userId = ?";
2893            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_CD = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
2894                            UserModelImpl.FINDER_CACHE_ENABLED, UserImpl.class,
2895                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_CD",
2896                            new String[] {
2897                                    Long.class.getName(), Date.class.getName(),
2898                                    
2899                            Integer.class.getName(), Integer.class.getName(),
2900                                    OrderByComparator.class.getName()
2901                            });
2902            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_CD = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
2903                            UserModelImpl.FINDER_CACHE_ENABLED, UserImpl.class,
2904                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_CD",
2905                            new String[] { Long.class.getName(), Date.class.getName() },
2906                            UserModelImpl.COMPANYID_COLUMN_BITMASK |
2907                            UserModelImpl.CREATEDATE_COLUMN_BITMASK);
2908            public static final FinderPath FINDER_PATH_COUNT_BY_C_CD = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
2909                            UserModelImpl.FINDER_CACHE_ENABLED, Long.class,
2910                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_CD",
2911                            new String[] { Long.class.getName(), Date.class.getName() });
2912    
2913            /**
2914             * Returns all the users where companyId = &#63; and createDate = &#63;.
2915             *
2916             * @param companyId the company ID
2917             * @param createDate the create date
2918             * @return the matching users
2919             */
2920            @Override
2921            public List<User> findByC_CD(long companyId, Date createDate) {
2922                    return findByC_CD(companyId, createDate, QueryUtil.ALL_POS,
2923                            QueryUtil.ALL_POS, null);
2924            }
2925    
2926            /**
2927             * Returns a range of all the users where companyId = &#63; and createDate = &#63;.
2928             *
2929             * <p>
2930             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
2931             * </p>
2932             *
2933             * @param companyId the company ID
2934             * @param createDate the create date
2935             * @param start the lower bound of the range of users
2936             * @param end the upper bound of the range of users (not inclusive)
2937             * @return the range of matching users
2938             */
2939            @Override
2940            public List<User> findByC_CD(long companyId, Date createDate, int start,
2941                    int end) {
2942                    return findByC_CD(companyId, createDate, start, end, null);
2943            }
2944    
2945            /**
2946             * Returns an ordered range of all the users where companyId = &#63; and createDate = &#63;.
2947             *
2948             * <p>
2949             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
2950             * </p>
2951             *
2952             * @param companyId the company ID
2953             * @param createDate the create date
2954             * @param start the lower bound of the range of users
2955             * @param end the upper bound of the range of users (not inclusive)
2956             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2957             * @return the ordered range of matching users
2958             */
2959            @Override
2960            public List<User> findByC_CD(long companyId, Date createDate, int start,
2961                    int end, OrderByComparator<User> orderByComparator) {
2962                    return findByC_CD(companyId, createDate, start, end, orderByComparator,
2963                            true);
2964            }
2965    
2966            /**
2967             * Returns an ordered range of all the users where companyId = &#63; and createDate = &#63;.
2968             *
2969             * <p>
2970             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
2971             * </p>
2972             *
2973             * @param companyId the company ID
2974             * @param createDate the create date
2975             * @param start the lower bound of the range of users
2976             * @param end the upper bound of the range of users (not inclusive)
2977             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2978             * @param retrieveFromCache whether to retrieve from the finder cache
2979             * @return the ordered range of matching users
2980             */
2981            @Override
2982            public List<User> findByC_CD(long companyId, Date createDate, int start,
2983                    int end, OrderByComparator<User> orderByComparator,
2984                    boolean retrieveFromCache) {
2985                    boolean pagination = true;
2986                    FinderPath finderPath = null;
2987                    Object[] finderArgs = null;
2988    
2989                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2990                                    (orderByComparator == null)) {
2991                            pagination = false;
2992                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_CD;
2993                            finderArgs = new Object[] { companyId, createDate };
2994                    }
2995                    else {
2996                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_CD;
2997                            finderArgs = new Object[] {
2998                                            companyId, createDate,
2999                                            
3000                                            start, end, orderByComparator
3001                                    };
3002                    }
3003    
3004                    List<User> list = null;
3005    
3006                    if (retrieveFromCache) {
3007                            list = (List<User>)finderCache.getResult(finderPath, finderArgs,
3008                                            this);
3009    
3010                            if ((list != null) && !list.isEmpty()) {
3011                                    for (User user : list) {
3012                                            if ((companyId != user.getCompanyId()) ||
3013                                                            !Validator.equals(createDate, user.getCreateDate())) {
3014                                                    list = null;
3015    
3016                                                    break;
3017                                            }
3018                                    }
3019                            }
3020                    }
3021    
3022                    if (list == null) {
3023                            StringBundler query = null;
3024    
3025                            if (orderByComparator != null) {
3026                                    query = new StringBundler(4 +
3027                                                    (orderByComparator.getOrderByFields().length * 3));
3028                            }
3029                            else {
3030                                    query = new StringBundler(4);
3031                            }
3032    
3033                            query.append(_SQL_SELECT_USER_WHERE);
3034    
3035                            query.append(_FINDER_COLUMN_C_CD_COMPANYID_2);
3036    
3037                            boolean bindCreateDate = false;
3038    
3039                            if (createDate == null) {
3040                                    query.append(_FINDER_COLUMN_C_CD_CREATEDATE_1);
3041                            }
3042                            else {
3043                                    bindCreateDate = true;
3044    
3045                                    query.append(_FINDER_COLUMN_C_CD_CREATEDATE_2);
3046                            }
3047    
3048                            if (orderByComparator != null) {
3049                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3050                                            orderByComparator);
3051                            }
3052                            else
3053                             if (pagination) {
3054                                    query.append(UserModelImpl.ORDER_BY_JPQL);
3055                            }
3056    
3057                            String sql = query.toString();
3058    
3059                            Session session = null;
3060    
3061                            try {
3062                                    session = openSession();
3063    
3064                                    Query q = session.createQuery(sql);
3065    
3066                                    QueryPos qPos = QueryPos.getInstance(q);
3067    
3068                                    qPos.add(companyId);
3069    
3070                                    if (bindCreateDate) {
3071                                            qPos.add(new Timestamp(createDate.getTime()));
3072                                    }
3073    
3074                                    if (!pagination) {
3075                                            list = (List<User>)QueryUtil.list(q, getDialect(), start,
3076                                                            end, false);
3077    
3078                                            Collections.sort(list);
3079    
3080                                            list = Collections.unmodifiableList(list);
3081                                    }
3082                                    else {
3083                                            list = (List<User>)QueryUtil.list(q, getDialect(), start,
3084                                                            end);
3085                                    }
3086    
3087                                    cacheResult(list);
3088    
3089                                    finderCache.putResult(finderPath, finderArgs, list);
3090                            }
3091                            catch (Exception e) {
3092                                    finderCache.removeResult(finderPath, finderArgs);
3093    
3094                                    throw processException(e);
3095                            }
3096                            finally {
3097                                    closeSession(session);
3098                            }
3099                    }
3100    
3101                    return list;
3102            }
3103    
3104            /**
3105             * Returns the first user in the ordered set where companyId = &#63; and createDate = &#63;.
3106             *
3107             * @param companyId the company ID
3108             * @param createDate the create date
3109             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3110             * @return the first matching user
3111             * @throws NoSuchUserException if a matching user could not be found
3112             */
3113            @Override
3114            public User findByC_CD_First(long companyId, Date createDate,
3115                    OrderByComparator<User> orderByComparator) throws NoSuchUserException {
3116                    User user = fetchByC_CD_First(companyId, createDate, orderByComparator);
3117    
3118                    if (user != null) {
3119                            return user;
3120                    }
3121    
3122                    StringBundler msg = new StringBundler(6);
3123    
3124                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3125    
3126                    msg.append("companyId=");
3127                    msg.append(companyId);
3128    
3129                    msg.append(", createDate=");
3130                    msg.append(createDate);
3131    
3132                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3133    
3134                    throw new NoSuchUserException(msg.toString());
3135            }
3136    
3137            /**
3138             * Returns the first user in the ordered set where companyId = &#63; and createDate = &#63;.
3139             *
3140             * @param companyId the company ID
3141             * @param createDate the create date
3142             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3143             * @return the first matching user, or <code>null</code> if a matching user could not be found
3144             */
3145            @Override
3146            public User fetchByC_CD_First(long companyId, Date createDate,
3147                    OrderByComparator<User> orderByComparator) {
3148                    List<User> list = findByC_CD(companyId, createDate, 0, 1,
3149                                    orderByComparator);
3150    
3151                    if (!list.isEmpty()) {
3152                            return list.get(0);
3153                    }
3154    
3155                    return null;
3156            }
3157    
3158            /**
3159             * Returns the last user in the ordered set where companyId = &#63; and createDate = &#63;.
3160             *
3161             * @param companyId the company ID
3162             * @param createDate the create date
3163             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3164             * @return the last matching user
3165             * @throws NoSuchUserException if a matching user could not be found
3166             */
3167            @Override
3168            public User findByC_CD_Last(long companyId, Date createDate,
3169                    OrderByComparator<User> orderByComparator) throws NoSuchUserException {
3170                    User user = fetchByC_CD_Last(companyId, createDate, orderByComparator);
3171    
3172                    if (user != null) {
3173                            return user;
3174                    }
3175    
3176                    StringBundler msg = new StringBundler(6);
3177    
3178                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3179    
3180                    msg.append("companyId=");
3181                    msg.append(companyId);
3182    
3183                    msg.append(", createDate=");
3184                    msg.append(createDate);
3185    
3186                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3187    
3188                    throw new NoSuchUserException(msg.toString());
3189            }
3190    
3191            /**
3192             * Returns the last user in the ordered set where companyId = &#63; and createDate = &#63;.
3193             *
3194             * @param companyId the company ID
3195             * @param createDate the create date
3196             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3197             * @return the last matching user, or <code>null</code> if a matching user could not be found
3198             */
3199            @Override
3200            public User fetchByC_CD_Last(long companyId, Date createDate,
3201                    OrderByComparator<User> orderByComparator) {
3202                    int count = countByC_CD(companyId, createDate);
3203    
3204                    if (count == 0) {
3205                            return null;
3206                    }
3207    
3208                    List<User> list = findByC_CD(companyId, createDate, count - 1, count,
3209                                    orderByComparator);
3210    
3211                    if (!list.isEmpty()) {
3212                            return list.get(0);
3213                    }
3214    
3215                    return null;
3216            }
3217    
3218            /**
3219             * Returns the users before and after the current user in the ordered set where companyId = &#63; and createDate = &#63;.
3220             *
3221             * @param userId the primary key of the current user
3222             * @param companyId the company ID
3223             * @param createDate the create date
3224             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3225             * @return the previous, current, and next user
3226             * @throws NoSuchUserException if a user with the primary key could not be found
3227             */
3228            @Override
3229            public User[] findByC_CD_PrevAndNext(long userId, long companyId,
3230                    Date createDate, OrderByComparator<User> orderByComparator)
3231                    throws NoSuchUserException {
3232                    User user = findByPrimaryKey(userId);
3233    
3234                    Session session = null;
3235    
3236                    try {
3237                            session = openSession();
3238    
3239                            User[] array = new UserImpl[3];
3240    
3241                            array[0] = getByC_CD_PrevAndNext(session, user, companyId,
3242                                            createDate, orderByComparator, true);
3243    
3244                            array[1] = user;
3245    
3246                            array[2] = getByC_CD_PrevAndNext(session, user, companyId,
3247                                            createDate, orderByComparator, false);
3248    
3249                            return array;
3250                    }
3251                    catch (Exception e) {
3252                            throw processException(e);
3253                    }
3254                    finally {
3255                            closeSession(session);
3256                    }
3257            }
3258    
3259            protected User getByC_CD_PrevAndNext(Session session, User user,
3260                    long companyId, Date createDate,
3261                    OrderByComparator<User> orderByComparator, boolean previous) {
3262                    StringBundler query = null;
3263    
3264                    if (orderByComparator != null) {
3265                            query = new StringBundler(6 +
3266                                            (orderByComparator.getOrderByFields().length * 6));
3267                    }
3268                    else {
3269                            query = new StringBundler(3);
3270                    }
3271    
3272                    query.append(_SQL_SELECT_USER_WHERE);
3273    
3274                    query.append(_FINDER_COLUMN_C_CD_COMPANYID_2);
3275    
3276                    boolean bindCreateDate = false;
3277    
3278                    if (createDate == null) {
3279                            query.append(_FINDER_COLUMN_C_CD_CREATEDATE_1);
3280                    }
3281                    else {
3282                            bindCreateDate = true;
3283    
3284                            query.append(_FINDER_COLUMN_C_CD_CREATEDATE_2);
3285                    }
3286    
3287                    if (orderByComparator != null) {
3288                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3289    
3290                            if (orderByConditionFields.length > 0) {
3291                                    query.append(WHERE_AND);
3292                            }
3293    
3294                            for (int i = 0; i < orderByConditionFields.length; i++) {
3295                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3296                                    query.append(orderByConditionFields[i]);
3297    
3298                                    if ((i + 1) < orderByConditionFields.length) {
3299                                            if (orderByComparator.isAscending() ^ previous) {
3300                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3301                                            }
3302                                            else {
3303                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3304                                            }
3305                                    }
3306                                    else {
3307                                            if (orderByComparator.isAscending() ^ previous) {
3308                                                    query.append(WHERE_GREATER_THAN);
3309                                            }
3310                                            else {
3311                                                    query.append(WHERE_LESSER_THAN);
3312                                            }
3313                                    }
3314                            }
3315    
3316                            query.append(ORDER_BY_CLAUSE);
3317    
3318                            String[] orderByFields = orderByComparator.getOrderByFields();
3319    
3320                            for (int i = 0; i < orderByFields.length; i++) {
3321                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3322                                    query.append(orderByFields[i]);
3323    
3324                                    if ((i + 1) < orderByFields.length) {
3325                                            if (orderByComparator.isAscending() ^ previous) {
3326                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3327                                            }
3328                                            else {
3329                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3330                                            }
3331                                    }
3332                                    else {
3333                                            if (orderByComparator.isAscending() ^ previous) {
3334                                                    query.append(ORDER_BY_ASC);
3335                                            }
3336                                            else {
3337                                                    query.append(ORDER_BY_DESC);
3338                                            }
3339                                    }
3340                            }
3341                    }
3342                    else {
3343                            query.append(UserModelImpl.ORDER_BY_JPQL);
3344                    }
3345    
3346                    String sql = query.toString();
3347    
3348                    Query q = session.createQuery(sql);
3349    
3350                    q.setFirstResult(0);
3351                    q.setMaxResults(2);
3352    
3353                    QueryPos qPos = QueryPos.getInstance(q);
3354    
3355                    qPos.add(companyId);
3356    
3357                    if (bindCreateDate) {
3358                            qPos.add(new Timestamp(createDate.getTime()));
3359                    }
3360    
3361                    if (orderByComparator != null) {
3362                            Object[] values = orderByComparator.getOrderByConditionValues(user);
3363    
3364                            for (Object value : values) {
3365                                    qPos.add(value);
3366                            }
3367                    }
3368    
3369                    List<User> list = q.list();
3370    
3371                    if (list.size() == 2) {
3372                            return list.get(1);
3373                    }
3374                    else {
3375                            return null;
3376                    }
3377            }
3378    
3379            /**
3380             * Removes all the users where companyId = &#63; and createDate = &#63; from the database.
3381             *
3382             * @param companyId the company ID
3383             * @param createDate the create date
3384             */
3385            @Override
3386            public void removeByC_CD(long companyId, Date createDate) {
3387                    for (User user : findByC_CD(companyId, createDate, QueryUtil.ALL_POS,
3388                                    QueryUtil.ALL_POS, null)) {
3389                            remove(user);
3390                    }
3391            }
3392    
3393            /**
3394             * Returns the number of users where companyId = &#63; and createDate = &#63;.
3395             *
3396             * @param companyId the company ID
3397             * @param createDate the create date
3398             * @return the number of matching users
3399             */
3400            @Override
3401            public int countByC_CD(long companyId, Date createDate) {
3402                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_CD;
3403    
3404                    Object[] finderArgs = new Object[] { companyId, createDate };
3405    
3406                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3407    
3408                    if (count == null) {
3409                            StringBundler query = new StringBundler(3);
3410    
3411                            query.append(_SQL_COUNT_USER_WHERE);
3412    
3413                            query.append(_FINDER_COLUMN_C_CD_COMPANYID_2);
3414    
3415                            boolean bindCreateDate = false;
3416    
3417                            if (createDate == null) {
3418                                    query.append(_FINDER_COLUMN_C_CD_CREATEDATE_1);
3419                            }
3420                            else {
3421                                    bindCreateDate = true;
3422    
3423                                    query.append(_FINDER_COLUMN_C_CD_CREATEDATE_2);
3424                            }
3425    
3426                            String sql = query.toString();
3427    
3428                            Session session = null;
3429    
3430                            try {
3431                                    session = openSession();
3432    
3433                                    Query q = session.createQuery(sql);
3434    
3435                                    QueryPos qPos = QueryPos.getInstance(q);
3436    
3437                                    qPos.add(companyId);
3438    
3439                                    if (bindCreateDate) {
3440                                            qPos.add(new Timestamp(createDate.getTime()));
3441                                    }
3442    
3443                                    count = (Long)q.uniqueResult();
3444    
3445                                    finderCache.putResult(finderPath, finderArgs, count);
3446                            }
3447                            catch (Exception e) {
3448                                    finderCache.removeResult(finderPath, finderArgs);
3449    
3450                                    throw processException(e);
3451                            }
3452                            finally {
3453                                    closeSession(session);
3454                            }
3455                    }
3456    
3457                    return count.intValue();
3458            }
3459    
3460            private static final String _FINDER_COLUMN_C_CD_COMPANYID_2 = "user.companyId = ? AND ";
3461            private static final String _FINDER_COLUMN_C_CD_CREATEDATE_1 = "user.createDate IS NULL";
3462            private static final String _FINDER_COLUMN_C_CD_CREATEDATE_2 = "user.createDate = ?";
3463            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_MD = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
3464                            UserModelImpl.FINDER_CACHE_ENABLED, UserImpl.class,
3465                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_MD",
3466                            new String[] {
3467                                    Long.class.getName(), Date.class.getName(),
3468                                    
3469                            Integer.class.getName(), Integer.class.getName(),
3470                                    OrderByComparator.class.getName()
3471                            });
3472            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_MD = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
3473                            UserModelImpl.FINDER_CACHE_ENABLED, UserImpl.class,
3474                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_MD",
3475                            new String[] { Long.class.getName(), Date.class.getName() },
3476                            UserModelImpl.COMPANYID_COLUMN_BITMASK |
3477                            UserModelImpl.MODIFIEDDATE_COLUMN_BITMASK);
3478            public static final FinderPath FINDER_PATH_COUNT_BY_C_MD = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
3479                            UserModelImpl.FINDER_CACHE_ENABLED, Long.class,
3480                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_MD",
3481                            new String[] { Long.class.getName(), Date.class.getName() });
3482    
3483            /**
3484             * Returns all the users where companyId = &#63; and modifiedDate = &#63;.
3485             *
3486             * @param companyId the company ID
3487             * @param modifiedDate the modified date
3488             * @return the matching users
3489             */
3490            @Override
3491            public List<User> findByC_MD(long companyId, Date modifiedDate) {
3492                    return findByC_MD(companyId, modifiedDate, QueryUtil.ALL_POS,
3493                            QueryUtil.ALL_POS, null);
3494            }
3495    
3496            /**
3497             * Returns a range of all the users where companyId = &#63; and modifiedDate = &#63;.
3498             *
3499             * <p>
3500             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
3501             * </p>
3502             *
3503             * @param companyId the company ID
3504             * @param modifiedDate the modified date
3505             * @param start the lower bound of the range of users
3506             * @param end the upper bound of the range of users (not inclusive)
3507             * @return the range of matching users
3508             */
3509            @Override
3510            public List<User> findByC_MD(long companyId, Date modifiedDate, int start,
3511                    int end) {
3512                    return findByC_MD(companyId, modifiedDate, start, end, null);
3513            }
3514    
3515            /**
3516             * Returns an ordered range of all the users where companyId = &#63; and modifiedDate = &#63;.
3517             *
3518             * <p>
3519             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
3520             * </p>
3521             *
3522             * @param companyId the company ID
3523             * @param modifiedDate the modified date
3524             * @param start the lower bound of the range of users
3525             * @param end the upper bound of the range of users (not inclusive)
3526             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3527             * @return the ordered range of matching users
3528             */
3529            @Override
3530            public List<User> findByC_MD(long companyId, Date modifiedDate, int start,
3531                    int end, OrderByComparator<User> orderByComparator) {
3532                    return findByC_MD(companyId, modifiedDate, start, end,
3533                            orderByComparator, true);
3534            }
3535    
3536            /**
3537             * Returns an ordered range of all the users where companyId = &#63; and modifiedDate = &#63;.
3538             *
3539             * <p>
3540             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
3541             * </p>
3542             *
3543             * @param companyId the company ID
3544             * @param modifiedDate the modified date
3545             * @param start the lower bound of the range of users
3546             * @param end the upper bound of the range of users (not inclusive)
3547             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3548             * @param retrieveFromCache whether to retrieve from the finder cache
3549             * @return the ordered range of matching users
3550             */
3551            @Override
3552            public List<User> findByC_MD(long companyId, Date modifiedDate, int start,
3553                    int end, OrderByComparator<User> orderByComparator,
3554                    boolean retrieveFromCache) {
3555                    boolean pagination = true;
3556                    FinderPath finderPath = null;
3557                    Object[] finderArgs = null;
3558    
3559                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3560                                    (orderByComparator == null)) {
3561                            pagination = false;
3562                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_MD;
3563                            finderArgs = new Object[] { companyId, modifiedDate };
3564                    }
3565                    else {
3566                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_MD;
3567                            finderArgs = new Object[] {
3568                                            companyId, modifiedDate,
3569                                            
3570                                            start, end, orderByComparator
3571                                    };
3572                    }
3573    
3574                    List<User> list = null;
3575    
3576                    if (retrieveFromCache) {
3577                            list = (List<User>)finderCache.getResult(finderPath, finderArgs,
3578                                            this);
3579    
3580                            if ((list != null) && !list.isEmpty()) {
3581                                    for (User user : list) {
3582                                            if ((companyId != user.getCompanyId()) ||
3583                                                            !Validator.equals(modifiedDate,
3584                                                                    user.getModifiedDate())) {
3585                                                    list = null;
3586    
3587                                                    break;
3588                                            }
3589                                    }
3590                            }
3591                    }
3592    
3593                    if (list == null) {
3594                            StringBundler query = null;
3595    
3596                            if (orderByComparator != null) {
3597                                    query = new StringBundler(4 +
3598                                                    (orderByComparator.getOrderByFields().length * 3));
3599                            }
3600                            else {
3601                                    query = new StringBundler(4);
3602                            }
3603    
3604                            query.append(_SQL_SELECT_USER_WHERE);
3605    
3606                            query.append(_FINDER_COLUMN_C_MD_COMPANYID_2);
3607    
3608                            boolean bindModifiedDate = false;
3609    
3610                            if (modifiedDate == null) {
3611                                    query.append(_FINDER_COLUMN_C_MD_MODIFIEDDATE_1);
3612                            }
3613                            else {
3614                                    bindModifiedDate = true;
3615    
3616                                    query.append(_FINDER_COLUMN_C_MD_MODIFIEDDATE_2);
3617                            }
3618    
3619                            if (orderByComparator != null) {
3620                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3621                                            orderByComparator);
3622                            }
3623                            else
3624                             if (pagination) {
3625                                    query.append(UserModelImpl.ORDER_BY_JPQL);
3626                            }
3627    
3628                            String sql = query.toString();
3629    
3630                            Session session = null;
3631    
3632                            try {
3633                                    session = openSession();
3634    
3635                                    Query q = session.createQuery(sql);
3636    
3637                                    QueryPos qPos = QueryPos.getInstance(q);
3638    
3639                                    qPos.add(companyId);
3640    
3641                                    if (bindModifiedDate) {
3642                                            qPos.add(new Timestamp(modifiedDate.getTime()));
3643                                    }
3644    
3645                                    if (!pagination) {
3646                                            list = (List<User>)QueryUtil.list(q, getDialect(), start,
3647                                                            end, false);
3648    
3649                                            Collections.sort(list);
3650    
3651                                            list = Collections.unmodifiableList(list);
3652                                    }
3653                                    else {
3654                                            list = (List<User>)QueryUtil.list(q, getDialect(), start,
3655                                                            end);
3656                                    }
3657    
3658                                    cacheResult(list);
3659    
3660                                    finderCache.putResult(finderPath, finderArgs, list);
3661                            }
3662                            catch (Exception e) {
3663                                    finderCache.removeResult(finderPath, finderArgs);
3664    
3665                                    throw processException(e);
3666                            }
3667                            finally {
3668                                    closeSession(session);
3669                            }
3670                    }
3671    
3672                    return list;
3673            }
3674    
3675            /**
3676             * Returns the first user in the ordered set where companyId = &#63; and modifiedDate = &#63;.
3677             *
3678             * @param companyId the company ID
3679             * @param modifiedDate the modified date
3680             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3681             * @return the first matching user
3682             * @throws NoSuchUserException if a matching user could not be found
3683             */
3684            @Override
3685            public User findByC_MD_First(long companyId, Date modifiedDate,
3686                    OrderByComparator<User> orderByComparator) throws NoSuchUserException {
3687                    User user = fetchByC_MD_First(companyId, modifiedDate, orderByComparator);
3688    
3689                    if (user != null) {
3690                            return user;
3691                    }
3692    
3693                    StringBundler msg = new StringBundler(6);
3694    
3695                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3696    
3697                    msg.append("companyId=");
3698                    msg.append(companyId);
3699    
3700                    msg.append(", modifiedDate=");
3701                    msg.append(modifiedDate);
3702    
3703                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3704    
3705                    throw new NoSuchUserException(msg.toString());
3706            }
3707    
3708            /**
3709             * Returns the first user in the ordered set where companyId = &#63; and modifiedDate = &#63;.
3710             *
3711             * @param companyId the company ID
3712             * @param modifiedDate the modified date
3713             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3714             * @return the first matching user, or <code>null</code> if a matching user could not be found
3715             */
3716            @Override
3717            public User fetchByC_MD_First(long companyId, Date modifiedDate,
3718                    OrderByComparator<User> orderByComparator) {
3719                    List<User> list = findByC_MD(companyId, modifiedDate, 0, 1,
3720                                    orderByComparator);
3721    
3722                    if (!list.isEmpty()) {
3723                            return list.get(0);
3724                    }
3725    
3726                    return null;
3727            }
3728    
3729            /**
3730             * Returns the last user in the ordered set where companyId = &#63; and modifiedDate = &#63;.
3731             *
3732             * @param companyId the company ID
3733             * @param modifiedDate the modified date
3734             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3735             * @return the last matching user
3736             * @throws NoSuchUserException if a matching user could not be found
3737             */
3738            @Override
3739            public User findByC_MD_Last(long companyId, Date modifiedDate,
3740                    OrderByComparator<User> orderByComparator) throws NoSuchUserException {
3741                    User user = fetchByC_MD_Last(companyId, modifiedDate, orderByComparator);
3742    
3743                    if (user != null) {
3744                            return user;
3745                    }
3746    
3747                    StringBundler msg = new StringBundler(6);
3748    
3749                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3750    
3751                    msg.append("companyId=");
3752                    msg.append(companyId);
3753    
3754                    msg.append(", modifiedDate=");
3755                    msg.append(modifiedDate);
3756    
3757                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3758    
3759                    throw new NoSuchUserException(msg.toString());
3760            }
3761    
3762            /**
3763             * Returns the last user in the ordered set where companyId = &#63; and modifiedDate = &#63;.
3764             *
3765             * @param companyId the company ID
3766             * @param modifiedDate the modified date
3767             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3768             * @return the last matching user, or <code>null</code> if a matching user could not be found
3769             */
3770            @Override
3771            public User fetchByC_MD_Last(long companyId, Date modifiedDate,
3772                    OrderByComparator<User> orderByComparator) {
3773                    int count = countByC_MD(companyId, modifiedDate);
3774    
3775                    if (count == 0) {
3776                            return null;
3777                    }
3778    
3779                    List<User> list = findByC_MD(companyId, modifiedDate, count - 1, count,
3780                                    orderByComparator);
3781    
3782                    if (!list.isEmpty()) {
3783                            return list.get(0);
3784                    }
3785    
3786                    return null;
3787            }
3788    
3789            /**
3790             * Returns the users before and after the current user in the ordered set where companyId = &#63; and modifiedDate = &#63;.
3791             *
3792             * @param userId the primary key of the current user
3793             * @param companyId the company ID
3794             * @param modifiedDate the modified date
3795             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3796             * @return the previous, current, and next user
3797             * @throws NoSuchUserException if a user with the primary key could not be found
3798             */
3799            @Override
3800            public User[] findByC_MD_PrevAndNext(long userId, long companyId,
3801                    Date modifiedDate, OrderByComparator<User> orderByComparator)
3802                    throws NoSuchUserException {
3803                    User user = findByPrimaryKey(userId);
3804    
3805                    Session session = null;
3806    
3807                    try {
3808                            session = openSession();
3809    
3810                            User[] array = new UserImpl[3];
3811    
3812                            array[0] = getByC_MD_PrevAndNext(session, user, companyId,
3813                                            modifiedDate, orderByComparator, true);
3814    
3815                            array[1] = user;
3816    
3817                            array[2] = getByC_MD_PrevAndNext(session, user, companyId,
3818                                            modifiedDate, orderByComparator, false);
3819    
3820                            return array;
3821                    }
3822                    catch (Exception e) {
3823                            throw processException(e);
3824                    }
3825                    finally {
3826                            closeSession(session);
3827                    }
3828            }
3829    
3830            protected User getByC_MD_PrevAndNext(Session session, User user,
3831                    long companyId, Date modifiedDate,
3832                    OrderByComparator<User> orderByComparator, boolean previous) {
3833                    StringBundler query = null;
3834    
3835                    if (orderByComparator != null) {
3836                            query = new StringBundler(6 +
3837                                            (orderByComparator.getOrderByFields().length * 6));
3838                    }
3839                    else {
3840                            query = new StringBundler(3);
3841                    }
3842    
3843                    query.append(_SQL_SELECT_USER_WHERE);
3844    
3845                    query.append(_FINDER_COLUMN_C_MD_COMPANYID_2);
3846    
3847                    boolean bindModifiedDate = false;
3848    
3849                    if (modifiedDate == null) {
3850                            query.append(_FINDER_COLUMN_C_MD_MODIFIEDDATE_1);
3851                    }
3852                    else {
3853                            bindModifiedDate = true;
3854    
3855                            query.append(_FINDER_COLUMN_C_MD_MODIFIEDDATE_2);
3856                    }
3857    
3858                    if (orderByComparator != null) {
3859                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3860    
3861                            if (orderByConditionFields.length > 0) {
3862                                    query.append(WHERE_AND);
3863                            }
3864    
3865                            for (int i = 0; i < orderByConditionFields.length; i++) {
3866                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3867                                    query.append(orderByConditionFields[i]);
3868    
3869                                    if ((i + 1) < orderByConditionFields.length) {
3870                                            if (orderByComparator.isAscending() ^ previous) {
3871                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3872                                            }
3873                                            else {
3874                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3875                                            }
3876                                    }
3877                                    else {
3878                                            if (orderByComparator.isAscending() ^ previous) {
3879                                                    query.append(WHERE_GREATER_THAN);
3880                                            }
3881                                            else {
3882                                                    query.append(WHERE_LESSER_THAN);
3883                                            }
3884                                    }
3885                            }
3886    
3887                            query.append(ORDER_BY_CLAUSE);
3888    
3889                            String[] orderByFields = orderByComparator.getOrderByFields();
3890    
3891                            for (int i = 0; i < orderByFields.length; i++) {
3892                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3893                                    query.append(orderByFields[i]);
3894    
3895                                    if ((i + 1) < orderByFields.length) {
3896                                            if (orderByComparator.isAscending() ^ previous) {
3897                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3898                                            }
3899                                            else {
3900                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3901                                            }
3902                                    }
3903                                    else {
3904                                            if (orderByComparator.isAscending() ^ previous) {
3905                                                    query.append(ORDER_BY_ASC);
3906                                            }
3907                                            else {
3908                                                    query.append(ORDER_BY_DESC);
3909                                            }
3910                                    }
3911                            }
3912                    }
3913                    else {
3914                            query.append(UserModelImpl.ORDER_BY_JPQL);
3915                    }
3916    
3917                    String sql = query.toString();
3918    
3919                    Query q = session.createQuery(sql);
3920    
3921                    q.setFirstResult(0);
3922                    q.setMaxResults(2);
3923    
3924                    QueryPos qPos = QueryPos.getInstance(q);
3925    
3926                    qPos.add(companyId);
3927    
3928                    if (bindModifiedDate) {
3929                            qPos.add(new Timestamp(modifiedDate.getTime()));
3930                    }
3931    
3932                    if (orderByComparator != null) {
3933                            Object[] values = orderByComparator.getOrderByConditionValues(user);
3934    
3935                            for (Object value : values) {
3936                                    qPos.add(value);
3937                            }
3938                    }
3939    
3940                    List<User> list = q.list();
3941    
3942                    if (list.size() == 2) {
3943                            return list.get(1);
3944                    }
3945                    else {
3946                            return null;
3947                    }
3948            }
3949    
3950            /**
3951             * Removes all the users where companyId = &#63; and modifiedDate = &#63; from the database.
3952             *
3953             * @param companyId the company ID
3954             * @param modifiedDate the modified date
3955             */
3956            @Override
3957            public void removeByC_MD(long companyId, Date modifiedDate) {
3958                    for (User user : findByC_MD(companyId, modifiedDate, QueryUtil.ALL_POS,
3959                                    QueryUtil.ALL_POS, null)) {
3960                            remove(user);
3961                    }
3962            }
3963    
3964            /**
3965             * Returns the number of users where companyId = &#63; and modifiedDate = &#63;.
3966             *
3967             * @param companyId the company ID
3968             * @param modifiedDate the modified date
3969             * @return the number of matching users
3970             */
3971            @Override
3972            public int countByC_MD(long companyId, Date modifiedDate) {
3973                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_MD;
3974    
3975                    Object[] finderArgs = new Object[] { companyId, modifiedDate };
3976    
3977                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3978    
3979                    if (count == null) {
3980                            StringBundler query = new StringBundler(3);
3981    
3982                            query.append(_SQL_COUNT_USER_WHERE);
3983    
3984                            query.append(_FINDER_COLUMN_C_MD_COMPANYID_2);
3985    
3986                            boolean bindModifiedDate = false;
3987    
3988                            if (modifiedDate == null) {
3989                                    query.append(_FINDER_COLUMN_C_MD_MODIFIEDDATE_1);
3990                            }
3991                            else {
3992                                    bindModifiedDate = true;
3993    
3994                                    query.append(_FINDER_COLUMN_C_MD_MODIFIEDDATE_2);
3995                            }
3996    
3997                            String sql = query.toString();
3998    
3999                            Session session = null;
4000    
4001                            try {
4002                                    session = openSession();
4003    
4004                                    Query q = session.createQuery(sql);
4005    
4006                                    QueryPos qPos = QueryPos.getInstance(q);
4007    
4008                                    qPos.add(companyId);
4009    
4010                                    if (bindModifiedDate) {
4011                                            qPos.add(new Timestamp(modifiedDate.getTime()));
4012                                    }
4013    
4014                                    count = (Long)q.uniqueResult();
4015    
4016                                    finderCache.putResult(finderPath, finderArgs, count);
4017                            }
4018                            catch (Exception e) {
4019                                    finderCache.removeResult(finderPath, finderArgs);
4020    
4021                                    throw processException(e);
4022                            }
4023                            finally {
4024                                    closeSession(session);
4025                            }
4026                    }
4027    
4028                    return count.intValue();
4029            }
4030    
4031            private static final String _FINDER_COLUMN_C_MD_COMPANYID_2 = "user.companyId = ? AND ";
4032            private static final String _FINDER_COLUMN_C_MD_MODIFIEDDATE_1 = "user.modifiedDate IS NULL";
4033            private static final String _FINDER_COLUMN_C_MD_MODIFIEDDATE_2 = "user.modifiedDate = ?";
4034            public static final FinderPath FINDER_PATH_FETCH_BY_C_DU = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
4035                            UserModelImpl.FINDER_CACHE_ENABLED, UserImpl.class,
4036                            FINDER_CLASS_NAME_ENTITY, "fetchByC_DU",
4037                            new String[] { Long.class.getName(), Boolean.class.getName() },
4038                            UserModelImpl.COMPANYID_COLUMN_BITMASK |
4039                            UserModelImpl.DEFAULTUSER_COLUMN_BITMASK);
4040            public static final FinderPath FINDER_PATH_COUNT_BY_C_DU = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
4041                            UserModelImpl.FINDER_CACHE_ENABLED, Long.class,
4042                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_DU",
4043                            new String[] { Long.class.getName(), Boolean.class.getName() });
4044    
4045            /**
4046             * Returns the user where companyId = &#63; and defaultUser = &#63; or throws a {@link NoSuchUserException} if it could not be found.
4047             *
4048             * @param companyId the company ID
4049             * @param defaultUser the default user
4050             * @return the matching user
4051             * @throws NoSuchUserException if a matching user could not be found
4052             */
4053            @Override
4054            public User findByC_DU(long companyId, boolean defaultUser)
4055                    throws NoSuchUserException {
4056                    User user = fetchByC_DU(companyId, defaultUser);
4057    
4058                    if (user == null) {
4059                            StringBundler msg = new StringBundler(6);
4060    
4061                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4062    
4063                            msg.append("companyId=");
4064                            msg.append(companyId);
4065    
4066                            msg.append(", defaultUser=");
4067                            msg.append(defaultUser);
4068    
4069                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4070    
4071                            if (_log.isWarnEnabled()) {
4072                                    _log.warn(msg.toString());
4073                            }
4074    
4075                            throw new NoSuchUserException(msg.toString());
4076                    }
4077    
4078                    return user;
4079            }
4080    
4081            /**
4082             * Returns the user where companyId = &#63; and defaultUser = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
4083             *
4084             * @param companyId the company ID
4085             * @param defaultUser the default user
4086             * @return the matching user, or <code>null</code> if a matching user could not be found
4087             */
4088            @Override
4089            public User fetchByC_DU(long companyId, boolean defaultUser) {
4090                    return fetchByC_DU(companyId, defaultUser, true);
4091            }
4092    
4093            /**
4094             * Returns the user where companyId = &#63; and defaultUser = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
4095             *
4096             * @param companyId the company ID
4097             * @param defaultUser the default user
4098             * @param retrieveFromCache whether to retrieve from the finder cache
4099             * @return the matching user, or <code>null</code> if a matching user could not be found
4100             */
4101            @Override
4102            public User fetchByC_DU(long companyId, boolean defaultUser,
4103                    boolean retrieveFromCache) {
4104                    Object[] finderArgs = new Object[] { companyId, defaultUser };
4105    
4106                    Object result = null;
4107    
4108                    if (retrieveFromCache) {
4109                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_C_DU,
4110                                            finderArgs, this);
4111                    }
4112    
4113                    if (result instanceof User) {
4114                            User user = (User)result;
4115    
4116                            if ((companyId != user.getCompanyId()) ||
4117                                            (defaultUser != user.getDefaultUser())) {
4118                                    result = null;
4119                            }
4120                    }
4121    
4122                    if (result == null) {
4123                            StringBundler query = new StringBundler(4);
4124    
4125                            query.append(_SQL_SELECT_USER_WHERE);
4126    
4127                            query.append(_FINDER_COLUMN_C_DU_COMPANYID_2);
4128    
4129                            query.append(_FINDER_COLUMN_C_DU_DEFAULTUSER_2);
4130    
4131                            String sql = query.toString();
4132    
4133                            Session session = null;
4134    
4135                            try {
4136                                    session = openSession();
4137    
4138                                    Query q = session.createQuery(sql);
4139    
4140                                    QueryPos qPos = QueryPos.getInstance(q);
4141    
4142                                    qPos.add(companyId);
4143    
4144                                    qPos.add(defaultUser);
4145    
4146                                    List<User> list = q.list();
4147    
4148                                    if (list.isEmpty()) {
4149                                            finderCache.putResult(FINDER_PATH_FETCH_BY_C_DU,
4150                                                    finderArgs, list);
4151                                    }
4152                                    else {
4153                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
4154                                                    _log.warn(
4155                                                            "UserPersistenceImpl.fetchByC_DU(long, boolean, boolean) with parameters (" +
4156                                                            StringUtil.merge(finderArgs) +
4157                                                            ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
4158                                            }
4159    
4160                                            User user = list.get(0);
4161    
4162                                            result = user;
4163    
4164                                            cacheResult(user);
4165    
4166                                            if ((user.getCompanyId() != companyId) ||
4167                                                            (user.getDefaultUser() != defaultUser)) {
4168                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_DU,
4169                                                            finderArgs, user);
4170                                            }
4171                                    }
4172                            }
4173                            catch (Exception e) {
4174                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_C_DU, finderArgs);
4175    
4176                                    throw processException(e);
4177                            }
4178                            finally {
4179                                    closeSession(session);
4180                            }
4181                    }
4182    
4183                    if (result instanceof List<?>) {
4184                            return null;
4185                    }
4186                    else {
4187                            return (User)result;
4188                    }
4189            }
4190    
4191            /**
4192             * Removes the user where companyId = &#63; and defaultUser = &#63; from the database.
4193             *
4194             * @param companyId the company ID
4195             * @param defaultUser the default user
4196             * @return the user that was removed
4197             */
4198            @Override
4199            public User removeByC_DU(long companyId, boolean defaultUser)
4200                    throws NoSuchUserException {
4201                    User user = findByC_DU(companyId, defaultUser);
4202    
4203                    return remove(user);
4204            }
4205    
4206            /**
4207             * Returns the number of users where companyId = &#63; and defaultUser = &#63;.
4208             *
4209             * @param companyId the company ID
4210             * @param defaultUser the default user
4211             * @return the number of matching users
4212             */
4213            @Override
4214            public int countByC_DU(long companyId, boolean defaultUser) {
4215                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_DU;
4216    
4217                    Object[] finderArgs = new Object[] { companyId, defaultUser };
4218    
4219                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4220    
4221                    if (count == null) {
4222                            StringBundler query = new StringBundler(3);
4223    
4224                            query.append(_SQL_COUNT_USER_WHERE);
4225    
4226                            query.append(_FINDER_COLUMN_C_DU_COMPANYID_2);
4227    
4228                            query.append(_FINDER_COLUMN_C_DU_DEFAULTUSER_2);
4229    
4230                            String sql = query.toString();
4231    
4232                            Session session = null;
4233    
4234                            try {
4235                                    session = openSession();
4236    
4237                                    Query q = session.createQuery(sql);
4238    
4239                                    QueryPos qPos = QueryPos.getInstance(q);
4240    
4241                                    qPos.add(companyId);
4242    
4243                                    qPos.add(defaultUser);
4244    
4245                                    count = (Long)q.uniqueResult();
4246    
4247                                    finderCache.putResult(finderPath, finderArgs, count);
4248                            }
4249                            catch (Exception e) {
4250                                    finderCache.removeResult(finderPath, finderArgs);
4251    
4252                                    throw processException(e);
4253                            }
4254                            finally {
4255                                    closeSession(session);
4256                            }
4257                    }
4258    
4259                    return count.intValue();
4260            }
4261    
4262            private static final String _FINDER_COLUMN_C_DU_COMPANYID_2 = "user.companyId = ? AND ";
4263            private static final String _FINDER_COLUMN_C_DU_DEFAULTUSER_2 = "user.defaultUser = ?";
4264            public static final FinderPath FINDER_PATH_FETCH_BY_C_SN = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
4265                            UserModelImpl.FINDER_CACHE_ENABLED, UserImpl.class,
4266                            FINDER_CLASS_NAME_ENTITY, "fetchByC_SN",
4267                            new String[] { Long.class.getName(), String.class.getName() },
4268                            UserModelImpl.COMPANYID_COLUMN_BITMASK |
4269                            UserModelImpl.SCREENNAME_COLUMN_BITMASK);
4270            public static final FinderPath FINDER_PATH_COUNT_BY_C_SN = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
4271                            UserModelImpl.FINDER_CACHE_ENABLED, Long.class,
4272                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_SN",
4273                            new String[] { Long.class.getName(), String.class.getName() });
4274    
4275            /**
4276             * Returns the user where companyId = &#63; and screenName = &#63; or throws a {@link NoSuchUserException} if it could not be found.
4277             *
4278             * @param companyId the company ID
4279             * @param screenName the screen name
4280             * @return the matching user
4281             * @throws NoSuchUserException if a matching user could not be found
4282             */
4283            @Override
4284            public User findByC_SN(long companyId, String screenName)
4285                    throws NoSuchUserException {
4286                    User user = fetchByC_SN(companyId, screenName);
4287    
4288                    if (user == null) {
4289                            StringBundler msg = new StringBundler(6);
4290    
4291                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4292    
4293                            msg.append("companyId=");
4294                            msg.append(companyId);
4295    
4296                            msg.append(", screenName=");
4297                            msg.append(screenName);
4298    
4299                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4300    
4301                            if (_log.isWarnEnabled()) {
4302                                    _log.warn(msg.toString());
4303                            }
4304    
4305                            throw new NoSuchUserException(msg.toString());
4306                    }
4307    
4308                    return user;
4309            }
4310    
4311            /**
4312             * Returns the user where companyId = &#63; and screenName = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
4313             *
4314             * @param companyId the company ID
4315             * @param screenName the screen name
4316             * @return the matching user, or <code>null</code> if a matching user could not be found
4317             */
4318            @Override
4319            public User fetchByC_SN(long companyId, String screenName) {
4320                    return fetchByC_SN(companyId, screenName, true);
4321            }
4322    
4323            /**
4324             * Returns the user where companyId = &#63; and screenName = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
4325             *
4326             * @param companyId the company ID
4327             * @param screenName the screen name
4328             * @param retrieveFromCache whether to retrieve from the finder cache
4329             * @return the matching user, or <code>null</code> if a matching user could not be found
4330             */
4331            @Override
4332            public User fetchByC_SN(long companyId, String screenName,
4333                    boolean retrieveFromCache) {
4334                    Object[] finderArgs = new Object[] { companyId, screenName };
4335    
4336                    Object result = null;
4337    
4338                    if (retrieveFromCache) {
4339                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_C_SN,
4340                                            finderArgs, this);
4341                    }
4342    
4343                    if (result instanceof User) {
4344                            User user = (User)result;
4345    
4346                            if ((companyId != user.getCompanyId()) ||
4347                                            !Validator.equals(screenName, user.getScreenName())) {
4348                                    result = null;
4349                            }
4350                    }
4351    
4352                    if (result == null) {
4353                            StringBundler query = new StringBundler(4);
4354    
4355                            query.append(_SQL_SELECT_USER_WHERE);
4356    
4357                            query.append(_FINDER_COLUMN_C_SN_COMPANYID_2);
4358    
4359                            boolean bindScreenName = false;
4360    
4361                            if (screenName == null) {
4362                                    query.append(_FINDER_COLUMN_C_SN_SCREENNAME_1);
4363                            }
4364                            else if (screenName.equals(StringPool.BLANK)) {
4365                                    query.append(_FINDER_COLUMN_C_SN_SCREENNAME_3);
4366                            }
4367                            else {
4368                                    bindScreenName = true;
4369    
4370                                    query.append(_FINDER_COLUMN_C_SN_SCREENNAME_2);
4371                            }
4372    
4373                            String sql = query.toString();
4374    
4375                            Session session = null;
4376    
4377                            try {
4378                                    session = openSession();
4379    
4380                                    Query q = session.createQuery(sql);
4381    
4382                                    QueryPos qPos = QueryPos.getInstance(q);
4383    
4384                                    qPos.add(companyId);
4385    
4386                                    if (bindScreenName) {
4387                                            qPos.add(screenName);
4388                                    }
4389    
4390                                    List<User> list = q.list();
4391    
4392                                    if (list.isEmpty()) {
4393                                            finderCache.putResult(FINDER_PATH_FETCH_BY_C_SN,
4394                                                    finderArgs, list);
4395                                    }
4396                                    else {
4397                                            User user = list.get(0);
4398    
4399                                            result = user;
4400    
4401                                            cacheResult(user);
4402    
4403                                            if ((user.getCompanyId() != companyId) ||
4404                                                            (user.getScreenName() == null) ||
4405                                                            !user.getScreenName().equals(screenName)) {
4406                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_SN,
4407                                                            finderArgs, user);
4408                                            }
4409                                    }
4410                            }
4411                            catch (Exception e) {
4412                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_C_SN, finderArgs);
4413    
4414                                    throw processException(e);
4415                            }
4416                            finally {
4417                                    closeSession(session);
4418                            }
4419                    }
4420    
4421                    if (result instanceof List<?>) {
4422                            return null;
4423                    }
4424                    else {
4425                            return (User)result;
4426                    }
4427            }
4428    
4429            /**
4430             * Removes the user where companyId = &#63; and screenName = &#63; from the database.
4431             *
4432             * @param companyId the company ID
4433             * @param screenName the screen name
4434             * @return the user that was removed
4435             */
4436            @Override
4437            public User removeByC_SN(long companyId, String screenName)
4438                    throws NoSuchUserException {
4439                    User user = findByC_SN(companyId, screenName);
4440    
4441                    return remove(user);
4442            }
4443    
4444            /**
4445             * Returns the number of users where companyId = &#63; and screenName = &#63;.
4446             *
4447             * @param companyId the company ID
4448             * @param screenName the screen name
4449             * @return the number of matching users
4450             */
4451            @Override
4452            public int countByC_SN(long companyId, String screenName) {
4453                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_SN;
4454    
4455                    Object[] finderArgs = new Object[] { companyId, screenName };
4456    
4457                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4458    
4459                    if (count == null) {
4460                            StringBundler query = new StringBundler(3);
4461    
4462                            query.append(_SQL_COUNT_USER_WHERE);
4463    
4464                            query.append(_FINDER_COLUMN_C_SN_COMPANYID_2);
4465    
4466                            boolean bindScreenName = false;
4467    
4468                            if (screenName == null) {
4469                                    query.append(_FINDER_COLUMN_C_SN_SCREENNAME_1);
4470                            }
4471                            else if (screenName.equals(StringPool.BLANK)) {
4472                                    query.append(_FINDER_COLUMN_C_SN_SCREENNAME_3);
4473                            }
4474                            else {
4475                                    bindScreenName = true;
4476    
4477                                    query.append(_FINDER_COLUMN_C_SN_SCREENNAME_2);
4478                            }
4479    
4480                            String sql = query.toString();
4481    
4482                            Session session = null;
4483    
4484                            try {
4485                                    session = openSession();
4486    
4487                                    Query q = session.createQuery(sql);
4488    
4489                                    QueryPos qPos = QueryPos.getInstance(q);
4490    
4491                                    qPos.add(companyId);
4492    
4493                                    if (bindScreenName) {
4494                                            qPos.add(screenName);
4495                                    }
4496    
4497                                    count = (Long)q.uniqueResult();
4498    
4499                                    finderCache.putResult(finderPath, finderArgs, count);
4500                            }
4501                            catch (Exception e) {
4502                                    finderCache.removeResult(finderPath, finderArgs);
4503    
4504                                    throw processException(e);
4505                            }
4506                            finally {
4507                                    closeSession(session);
4508                            }
4509                    }
4510    
4511                    return count.intValue();
4512            }
4513    
4514            private static final String _FINDER_COLUMN_C_SN_COMPANYID_2 = "user.companyId = ? AND ";
4515            private static final String _FINDER_COLUMN_C_SN_SCREENNAME_1 = "user.screenName IS NULL";
4516            private static final String _FINDER_COLUMN_C_SN_SCREENNAME_2 = "user.screenName = ?";
4517            private static final String _FINDER_COLUMN_C_SN_SCREENNAME_3 = "(user.screenName IS NULL OR user.screenName = '')";
4518            public static final FinderPath FINDER_PATH_FETCH_BY_C_EA = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
4519                            UserModelImpl.FINDER_CACHE_ENABLED, UserImpl.class,
4520                            FINDER_CLASS_NAME_ENTITY, "fetchByC_EA",
4521                            new String[] { Long.class.getName(), String.class.getName() },
4522                            UserModelImpl.COMPANYID_COLUMN_BITMASK |
4523                            UserModelImpl.EMAILADDRESS_COLUMN_BITMASK);
4524            public static final FinderPath FINDER_PATH_COUNT_BY_C_EA = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
4525                            UserModelImpl.FINDER_CACHE_ENABLED, Long.class,
4526                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_EA",
4527                            new String[] { Long.class.getName(), String.class.getName() });
4528    
4529            /**
4530             * Returns the user where companyId = &#63; and emailAddress = &#63; or throws a {@link NoSuchUserException} if it could not be found.
4531             *
4532             * @param companyId the company ID
4533             * @param emailAddress the email address
4534             * @return the matching user
4535             * @throws NoSuchUserException if a matching user could not be found
4536             */
4537            @Override
4538            public User findByC_EA(long companyId, String emailAddress)
4539                    throws NoSuchUserException {
4540                    User user = fetchByC_EA(companyId, emailAddress);
4541    
4542                    if (user == null) {
4543                            StringBundler msg = new StringBundler(6);
4544    
4545                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4546    
4547                            msg.append("companyId=");
4548                            msg.append(companyId);
4549    
4550                            msg.append(", emailAddress=");
4551                            msg.append(emailAddress);
4552    
4553                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4554    
4555                            if (_log.isWarnEnabled()) {
4556                                    _log.warn(msg.toString());
4557                            }
4558    
4559                            throw new NoSuchUserException(msg.toString());
4560                    }
4561    
4562                    return user;
4563            }
4564    
4565            /**
4566             * Returns the user where companyId = &#63; and emailAddress = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
4567             *
4568             * @param companyId the company ID
4569             * @param emailAddress the email address
4570             * @return the matching user, or <code>null</code> if a matching user could not be found
4571             */
4572            @Override
4573            public User fetchByC_EA(long companyId, String emailAddress) {
4574                    return fetchByC_EA(companyId, emailAddress, true);
4575            }
4576    
4577            /**
4578             * Returns the user where companyId = &#63; and emailAddress = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
4579             *
4580             * @param companyId the company ID
4581             * @param emailAddress the email address
4582             * @param retrieveFromCache whether to retrieve from the finder cache
4583             * @return the matching user, or <code>null</code> if a matching user could not be found
4584             */
4585            @Override
4586            public User fetchByC_EA(long companyId, String emailAddress,
4587                    boolean retrieveFromCache) {
4588                    Object[] finderArgs = new Object[] { companyId, emailAddress };
4589    
4590                    Object result = null;
4591    
4592                    if (retrieveFromCache) {
4593                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_C_EA,
4594                                            finderArgs, this);
4595                    }
4596    
4597                    if (result instanceof User) {
4598                            User user = (User)result;
4599    
4600                            if ((companyId != user.getCompanyId()) ||
4601                                            !Validator.equals(emailAddress, user.getEmailAddress())) {
4602                                    result = null;
4603                            }
4604                    }
4605    
4606                    if (result == null) {
4607                            StringBundler query = new StringBundler(4);
4608    
4609                            query.append(_SQL_SELECT_USER_WHERE);
4610    
4611                            query.append(_FINDER_COLUMN_C_EA_COMPANYID_2);
4612    
4613                            boolean bindEmailAddress = false;
4614    
4615                            if (emailAddress == null) {
4616                                    query.append(_FINDER_COLUMN_C_EA_EMAILADDRESS_1);
4617                            }
4618                            else if (emailAddress.equals(StringPool.BLANK)) {
4619                                    query.append(_FINDER_COLUMN_C_EA_EMAILADDRESS_3);
4620                            }
4621                            else {
4622                                    bindEmailAddress = true;
4623    
4624                                    query.append(_FINDER_COLUMN_C_EA_EMAILADDRESS_2);
4625                            }
4626    
4627                            String sql = query.toString();
4628    
4629                            Session session = null;
4630    
4631                            try {
4632                                    session = openSession();
4633    
4634                                    Query q = session.createQuery(sql);
4635    
4636                                    QueryPos qPos = QueryPos.getInstance(q);
4637    
4638                                    qPos.add(companyId);
4639    
4640                                    if (bindEmailAddress) {
4641                                            qPos.add(emailAddress);
4642                                    }
4643    
4644                                    List<User> list = q.list();
4645    
4646                                    if (list.isEmpty()) {
4647                                            finderCache.putResult(FINDER_PATH_FETCH_BY_C_EA,
4648                                                    finderArgs, list);
4649                                    }
4650                                    else {
4651                                            User user = list.get(0);
4652    
4653                                            result = user;
4654    
4655                                            cacheResult(user);
4656    
4657                                            if ((user.getCompanyId() != companyId) ||
4658                                                            (user.getEmailAddress() == null) ||
4659                                                            !user.getEmailAddress().equals(emailAddress)) {
4660                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_EA,
4661                                                            finderArgs, user);
4662                                            }
4663                                    }
4664                            }
4665                            catch (Exception e) {
4666                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_C_EA, finderArgs);
4667    
4668                                    throw processException(e);
4669                            }
4670                            finally {
4671                                    closeSession(session);
4672                            }
4673                    }
4674    
4675                    if (result instanceof List<?>) {
4676                            return null;
4677                    }
4678                    else {
4679                            return (User)result;
4680                    }
4681            }
4682    
4683            /**
4684             * Removes the user where companyId = &#63; and emailAddress = &#63; from the database.
4685             *
4686             * @param companyId the company ID
4687             * @param emailAddress the email address
4688             * @return the user that was removed
4689             */
4690            @Override
4691            public User removeByC_EA(long companyId, String emailAddress)
4692                    throws NoSuchUserException {
4693                    User user = findByC_EA(companyId, emailAddress);
4694    
4695                    return remove(user);
4696            }
4697    
4698            /**
4699             * Returns the number of users where companyId = &#63; and emailAddress = &#63;.
4700             *
4701             * @param companyId the company ID
4702             * @param emailAddress the email address
4703             * @return the number of matching users
4704             */
4705            @Override
4706            public int countByC_EA(long companyId, String emailAddress) {
4707                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_EA;
4708    
4709                    Object[] finderArgs = new Object[] { companyId, emailAddress };
4710    
4711                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4712    
4713                    if (count == null) {
4714                            StringBundler query = new StringBundler(3);
4715    
4716                            query.append(_SQL_COUNT_USER_WHERE);
4717    
4718                            query.append(_FINDER_COLUMN_C_EA_COMPANYID_2);
4719    
4720                            boolean bindEmailAddress = false;
4721    
4722                            if (emailAddress == null) {
4723                                    query.append(_FINDER_COLUMN_C_EA_EMAILADDRESS_1);
4724                            }
4725                            else if (emailAddress.equals(StringPool.BLANK)) {
4726                                    query.append(_FINDER_COLUMN_C_EA_EMAILADDRESS_3);
4727                            }
4728                            else {
4729                                    bindEmailAddress = true;
4730    
4731                                    query.append(_FINDER_COLUMN_C_EA_EMAILADDRESS_2);
4732                            }
4733    
4734                            String sql = query.toString();
4735    
4736                            Session session = null;
4737    
4738                            try {
4739                                    session = openSession();
4740    
4741                                    Query q = session.createQuery(sql);
4742    
4743                                    QueryPos qPos = QueryPos.getInstance(q);
4744    
4745                                    qPos.add(companyId);
4746    
4747                                    if (bindEmailAddress) {
4748                                            qPos.add(emailAddress);
4749                                    }
4750    
4751                                    count = (Long)q.uniqueResult();
4752    
4753                                    finderCache.putResult(finderPath, finderArgs, count);
4754                            }
4755                            catch (Exception e) {
4756                                    finderCache.removeResult(finderPath, finderArgs);
4757    
4758                                    throw processException(e);
4759                            }
4760                            finally {
4761                                    closeSession(session);
4762                            }
4763                    }
4764    
4765                    return count.intValue();
4766            }
4767    
4768            private static final String _FINDER_COLUMN_C_EA_COMPANYID_2 = "user.companyId = ? AND ";
4769            private static final String _FINDER_COLUMN_C_EA_EMAILADDRESS_1 = "user.emailAddress IS NULL";
4770            private static final String _FINDER_COLUMN_C_EA_EMAILADDRESS_2 = "user.emailAddress = ?";
4771            private static final String _FINDER_COLUMN_C_EA_EMAILADDRESS_3 = "(user.emailAddress IS NULL OR user.emailAddress = '')";
4772            public static final FinderPath FINDER_PATH_FETCH_BY_C_FID = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
4773                            UserModelImpl.FINDER_CACHE_ENABLED, UserImpl.class,
4774                            FINDER_CLASS_NAME_ENTITY, "fetchByC_FID",
4775                            new String[] { Long.class.getName(), Long.class.getName() },
4776                            UserModelImpl.COMPANYID_COLUMN_BITMASK |
4777                            UserModelImpl.FACEBOOKID_COLUMN_BITMASK);
4778            public static final FinderPath FINDER_PATH_COUNT_BY_C_FID = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
4779                            UserModelImpl.FINDER_CACHE_ENABLED, Long.class,
4780                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_FID",
4781                            new String[] { Long.class.getName(), Long.class.getName() });
4782    
4783            /**
4784             * Returns the user where companyId = &#63; and facebookId = &#63; or throws a {@link NoSuchUserException} if it could not be found.
4785             *
4786             * @param companyId the company ID
4787             * @param facebookId the facebook ID
4788             * @return the matching user
4789             * @throws NoSuchUserException if a matching user could not be found
4790             */
4791            @Override
4792            public User findByC_FID(long companyId, long facebookId)
4793                    throws NoSuchUserException {
4794                    User user = fetchByC_FID(companyId, facebookId);
4795    
4796                    if (user == null) {
4797                            StringBundler msg = new StringBundler(6);
4798    
4799                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4800    
4801                            msg.append("companyId=");
4802                            msg.append(companyId);
4803    
4804                            msg.append(", facebookId=");
4805                            msg.append(facebookId);
4806    
4807                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4808    
4809                            if (_log.isWarnEnabled()) {
4810                                    _log.warn(msg.toString());
4811                            }
4812    
4813                            throw new NoSuchUserException(msg.toString());
4814                    }
4815    
4816                    return user;
4817            }
4818    
4819            /**
4820             * Returns the user where companyId = &#63; and facebookId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
4821             *
4822             * @param companyId the company ID
4823             * @param facebookId the facebook ID
4824             * @return the matching user, or <code>null</code> if a matching user could not be found
4825             */
4826            @Override
4827            public User fetchByC_FID(long companyId, long facebookId) {
4828                    return fetchByC_FID(companyId, facebookId, true);
4829            }
4830    
4831            /**
4832             * Returns the user where companyId = &#63; and facebookId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
4833             *
4834             * @param companyId the company ID
4835             * @param facebookId the facebook ID
4836             * @param retrieveFromCache whether to retrieve from the finder cache
4837             * @return the matching user, or <code>null</code> if a matching user could not be found
4838             */
4839            @Override
4840            public User fetchByC_FID(long companyId, long facebookId,
4841                    boolean retrieveFromCache) {
4842                    Object[] finderArgs = new Object[] { companyId, facebookId };
4843    
4844                    Object result = null;
4845    
4846                    if (retrieveFromCache) {
4847                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_C_FID,
4848                                            finderArgs, this);
4849                    }
4850    
4851                    if (result instanceof User) {
4852                            User user = (User)result;
4853    
4854                            if ((companyId != user.getCompanyId()) ||
4855                                            (facebookId != user.getFacebookId())) {
4856                                    result = null;
4857                            }
4858                    }
4859    
4860                    if (result == null) {
4861                            StringBundler query = new StringBundler(4);
4862    
4863                            query.append(_SQL_SELECT_USER_WHERE);
4864    
4865                            query.append(_FINDER_COLUMN_C_FID_COMPANYID_2);
4866    
4867                            query.append(_FINDER_COLUMN_C_FID_FACEBOOKID_2);
4868    
4869                            String sql = query.toString();
4870    
4871                            Session session = null;
4872    
4873                            try {
4874                                    session = openSession();
4875    
4876                                    Query q = session.createQuery(sql);
4877    
4878                                    QueryPos qPos = QueryPos.getInstance(q);
4879    
4880                                    qPos.add(companyId);
4881    
4882                                    qPos.add(facebookId);
4883    
4884                                    List<User> list = q.list();
4885    
4886                                    if (list.isEmpty()) {
4887                                            finderCache.putResult(FINDER_PATH_FETCH_BY_C_FID,
4888                                                    finderArgs, list);
4889                                    }
4890                                    else {
4891                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
4892                                                    _log.warn(
4893                                                            "UserPersistenceImpl.fetchByC_FID(long, long, boolean) with parameters (" +
4894                                                            StringUtil.merge(finderArgs) +
4895                                                            ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
4896                                            }
4897    
4898                                            User user = list.get(0);
4899    
4900                                            result = user;
4901    
4902                                            cacheResult(user);
4903    
4904                                            if ((user.getCompanyId() != companyId) ||
4905                                                            (user.getFacebookId() != facebookId)) {
4906                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_FID,
4907                                                            finderArgs, user);
4908                                            }
4909                                    }
4910                            }
4911                            catch (Exception e) {
4912                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_C_FID, finderArgs);
4913    
4914                                    throw processException(e);
4915                            }
4916                            finally {
4917                                    closeSession(session);
4918                            }
4919                    }
4920    
4921                    if (result instanceof List<?>) {
4922                            return null;
4923                    }
4924                    else {
4925                            return (User)result;
4926                    }
4927            }
4928    
4929            /**
4930             * Removes the user where companyId = &#63; and facebookId = &#63; from the database.
4931             *
4932             * @param companyId the company ID
4933             * @param facebookId the facebook ID
4934             * @return the user that was removed
4935             */
4936            @Override
4937            public User removeByC_FID(long companyId, long facebookId)
4938                    throws NoSuchUserException {
4939                    User user = findByC_FID(companyId, facebookId);
4940    
4941                    return remove(user);
4942            }
4943    
4944            /**
4945             * Returns the number of users where companyId = &#63; and facebookId = &#63;.
4946             *
4947             * @param companyId the company ID
4948             * @param facebookId the facebook ID
4949             * @return the number of matching users
4950             */
4951            @Override
4952            public int countByC_FID(long companyId, long facebookId) {
4953                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_FID;
4954    
4955                    Object[] finderArgs = new Object[] { companyId, facebookId };
4956    
4957                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4958    
4959                    if (count == null) {
4960                            StringBundler query = new StringBundler(3);
4961    
4962                            query.append(_SQL_COUNT_USER_WHERE);
4963    
4964                            query.append(_FINDER_COLUMN_C_FID_COMPANYID_2);
4965    
4966                            query.append(_FINDER_COLUMN_C_FID_FACEBOOKID_2);
4967    
4968                            String sql = query.toString();
4969    
4970                            Session session = null;
4971    
4972                            try {
4973                                    session = openSession();
4974    
4975                                    Query q = session.createQuery(sql);
4976    
4977                                    QueryPos qPos = QueryPos.getInstance(q);
4978    
4979                                    qPos.add(companyId);
4980    
4981                                    qPos.add(facebookId);
4982    
4983                                    count = (Long)q.uniqueResult();
4984    
4985                                    finderCache.putResult(finderPath, finderArgs, count);
4986                            }
4987                            catch (Exception e) {
4988                                    finderCache.removeResult(finderPath, finderArgs);
4989    
4990                                    throw processException(e);
4991                            }
4992                            finally {
4993                                    closeSession(session);
4994                            }
4995                    }
4996    
4997                    return count.intValue();
4998            }
4999    
5000            private static final String _FINDER_COLUMN_C_FID_COMPANYID_2 = "user.companyId = ? AND ";
5001            private static final String _FINDER_COLUMN_C_FID_FACEBOOKID_2 = "user.facebookId = ?";
5002            public static final FinderPath FINDER_PATH_FETCH_BY_C_O = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
5003                            UserModelImpl.FINDER_CACHE_ENABLED, UserImpl.class,
5004                            FINDER_CLASS_NAME_ENTITY, "fetchByC_O",
5005                            new String[] { Long.class.getName(), String.class.getName() },
5006                            UserModelImpl.COMPANYID_COLUMN_BITMASK |
5007                            UserModelImpl.OPENID_COLUMN_BITMASK);
5008            public static final FinderPath FINDER_PATH_COUNT_BY_C_O = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
5009                            UserModelImpl.FINDER_CACHE_ENABLED, Long.class,
5010                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_O",
5011                            new String[] { Long.class.getName(), String.class.getName() });
5012    
5013            /**
5014             * Returns the user where companyId = &#63; and openId = &#63; or throws a {@link NoSuchUserException} if it could not be found.
5015             *
5016             * @param companyId the company ID
5017             * @param openId the open ID
5018             * @return the matching user
5019             * @throws NoSuchUserException if a matching user could not be found
5020             */
5021            @Override
5022            public User findByC_O(long companyId, String openId)
5023                    throws NoSuchUserException {
5024                    User user = fetchByC_O(companyId, openId);
5025    
5026                    if (user == null) {
5027                            StringBundler msg = new StringBundler(6);
5028    
5029                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5030    
5031                            msg.append("companyId=");
5032                            msg.append(companyId);
5033    
5034                            msg.append(", openId=");
5035                            msg.append(openId);
5036    
5037                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5038    
5039                            if (_log.isWarnEnabled()) {
5040                                    _log.warn(msg.toString());
5041                            }
5042    
5043                            throw new NoSuchUserException(msg.toString());
5044                    }
5045    
5046                    return user;
5047            }
5048    
5049            /**
5050             * Returns the user where companyId = &#63; and openId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
5051             *
5052             * @param companyId the company ID
5053             * @param openId the open ID
5054             * @return the matching user, or <code>null</code> if a matching user could not be found
5055             */
5056            @Override
5057            public User fetchByC_O(long companyId, String openId) {
5058                    return fetchByC_O(companyId, openId, true);
5059            }
5060    
5061            /**
5062             * Returns the user where companyId = &#63; and openId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
5063             *
5064             * @param companyId the company ID
5065             * @param openId the open ID
5066             * @param retrieveFromCache whether to retrieve from the finder cache
5067             * @return the matching user, or <code>null</code> if a matching user could not be found
5068             */
5069            @Override
5070            public User fetchByC_O(long companyId, String openId,
5071                    boolean retrieveFromCache) {
5072                    Object[] finderArgs = new Object[] { companyId, openId };
5073    
5074                    Object result = null;
5075    
5076                    if (retrieveFromCache) {
5077                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_C_O,
5078                                            finderArgs, this);
5079                    }
5080    
5081                    if (result instanceof User) {
5082                            User user = (User)result;
5083    
5084                            if ((companyId != user.getCompanyId()) ||
5085                                            !Validator.equals(openId, user.getOpenId())) {
5086                                    result = null;
5087                            }
5088                    }
5089    
5090                    if (result == null) {
5091                            StringBundler query = new StringBundler(4);
5092    
5093                            query.append(_SQL_SELECT_USER_WHERE);
5094    
5095                            query.append(_FINDER_COLUMN_C_O_COMPANYID_2);
5096    
5097                            boolean bindOpenId = false;
5098    
5099                            if (openId == null) {
5100                                    query.append(_FINDER_COLUMN_C_O_OPENID_1);
5101                            }
5102                            else if (openId.equals(StringPool.BLANK)) {
5103                                    query.append(_FINDER_COLUMN_C_O_OPENID_3);
5104                            }
5105                            else {
5106                                    bindOpenId = true;
5107    
5108                                    query.append(_FINDER_COLUMN_C_O_OPENID_2);
5109                            }
5110    
5111                            String sql = query.toString();
5112    
5113                            Session session = null;
5114    
5115                            try {
5116                                    session = openSession();
5117    
5118                                    Query q = session.createQuery(sql);
5119    
5120                                    QueryPos qPos = QueryPos.getInstance(q);
5121    
5122                                    qPos.add(companyId);
5123    
5124                                    if (bindOpenId) {
5125                                            qPos.add(openId);
5126                                    }
5127    
5128                                    List<User> list = q.list();
5129    
5130                                    if (list.isEmpty()) {
5131                                            finderCache.putResult(FINDER_PATH_FETCH_BY_C_O, finderArgs,
5132                                                    list);
5133                                    }
5134                                    else {
5135                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
5136                                                    _log.warn(
5137                                                            "UserPersistenceImpl.fetchByC_O(long, String, boolean) with parameters (" +
5138                                                            StringUtil.merge(finderArgs) +
5139                                                            ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
5140                                            }
5141    
5142                                            User user = list.get(0);
5143    
5144                                            result = user;
5145    
5146                                            cacheResult(user);
5147    
5148                                            if ((user.getCompanyId() != companyId) ||
5149                                                            (user.getOpenId() == null) ||
5150                                                            !user.getOpenId().equals(openId)) {
5151                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_O,
5152                                                            finderArgs, user);
5153                                            }
5154                                    }
5155                            }
5156                            catch (Exception e) {
5157                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_C_O, finderArgs);
5158    
5159                                    throw processException(e);
5160                            }
5161                            finally {
5162                                    closeSession(session);
5163                            }
5164                    }
5165    
5166                    if (result instanceof List<?>) {
5167                            return null;
5168                    }
5169                    else {
5170                            return (User)result;
5171                    }
5172            }
5173    
5174            /**
5175             * Removes the user where companyId = &#63; and openId = &#63; from the database.
5176             *
5177             * @param companyId the company ID
5178             * @param openId the open ID
5179             * @return the user that was removed
5180             */
5181            @Override
5182            public User removeByC_O(long companyId, String openId)
5183                    throws NoSuchUserException {
5184                    User user = findByC_O(companyId, openId);
5185    
5186                    return remove(user);
5187            }
5188    
5189            /**
5190             * Returns the number of users where companyId = &#63; and openId = &#63;.
5191             *
5192             * @param companyId the company ID
5193             * @param openId the open ID
5194             * @return the number of matching users
5195             */
5196            @Override
5197            public int countByC_O(long companyId, String openId) {
5198                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_O;
5199    
5200                    Object[] finderArgs = new Object[] { companyId, openId };
5201    
5202                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
5203    
5204                    if (count == null) {
5205                            StringBundler query = new StringBundler(3);
5206    
5207                            query.append(_SQL_COUNT_USER_WHERE);
5208    
5209                            query.append(_FINDER_COLUMN_C_O_COMPANYID_2);
5210    
5211                            boolean bindOpenId = false;
5212    
5213                            if (openId == null) {
5214                                    query.append(_FINDER_COLUMN_C_O_OPENID_1);
5215                            }
5216                            else if (openId.equals(StringPool.BLANK)) {
5217                                    query.append(_FINDER_COLUMN_C_O_OPENID_3);
5218                            }
5219                            else {
5220                                    bindOpenId = true;
5221    
5222                                    query.append(_FINDER_COLUMN_C_O_OPENID_2);
5223                            }
5224    
5225                            String sql = query.toString();
5226    
5227                            Session session = null;
5228    
5229                            try {
5230                                    session = openSession();
5231    
5232                                    Query q = session.createQuery(sql);
5233    
5234                                    QueryPos qPos = QueryPos.getInstance(q);
5235    
5236                                    qPos.add(companyId);
5237    
5238                                    if (bindOpenId) {
5239                                            qPos.add(openId);
5240                                    }
5241    
5242                                    count = (Long)q.uniqueResult();
5243    
5244                                    finderCache.putResult(finderPath, finderArgs, count);
5245                            }
5246                            catch (Exception e) {
5247                                    finderCache.removeResult(finderPath, finderArgs);
5248    
5249                                    throw processException(e);
5250                            }
5251                            finally {
5252                                    closeSession(session);
5253                            }
5254                    }
5255    
5256                    return count.intValue();
5257            }
5258    
5259            private static final String _FINDER_COLUMN_C_O_COMPANYID_2 = "user.companyId = ? AND ";
5260            private static final String _FINDER_COLUMN_C_O_OPENID_1 = "user.openId IS NULL";
5261            private static final String _FINDER_COLUMN_C_O_OPENID_2 = "user.openId = ?";
5262            private static final String _FINDER_COLUMN_C_O_OPENID_3 = "(user.openId IS NULL OR user.openId = '')";
5263            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
5264                            UserModelImpl.FINDER_CACHE_ENABLED, UserImpl.class,
5265                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_S",
5266                            new String[] {
5267                                    Long.class.getName(), Integer.class.getName(),
5268                                    
5269                            Integer.class.getName(), Integer.class.getName(),
5270                                    OrderByComparator.class.getName()
5271                            });
5272            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
5273                            UserModelImpl.FINDER_CACHE_ENABLED, UserImpl.class,
5274                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_S",
5275                            new String[] { Long.class.getName(), Integer.class.getName() },
5276                            UserModelImpl.COMPANYID_COLUMN_BITMASK |
5277                            UserModelImpl.STATUS_COLUMN_BITMASK);
5278            public static final FinderPath FINDER_PATH_COUNT_BY_C_S = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
5279                            UserModelImpl.FINDER_CACHE_ENABLED, Long.class,
5280                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_S",
5281                            new String[] { Long.class.getName(), Integer.class.getName() });
5282    
5283            /**
5284             * Returns all the users where companyId = &#63; and status = &#63;.
5285             *
5286             * @param companyId the company ID
5287             * @param status the status
5288             * @return the matching users
5289             */
5290            @Override
5291            public List<User> findByC_S(long companyId, int status) {
5292                    return findByC_S(companyId, status, QueryUtil.ALL_POS,
5293                            QueryUtil.ALL_POS, null);
5294            }
5295    
5296            /**
5297             * Returns a range of all the users where companyId = &#63; and status = &#63;.
5298             *
5299             * <p>
5300             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
5301             * </p>
5302             *
5303             * @param companyId the company ID
5304             * @param status the status
5305             * @param start the lower bound of the range of users
5306             * @param end the upper bound of the range of users (not inclusive)
5307             * @return the range of matching users
5308             */
5309            @Override
5310            public List<User> findByC_S(long companyId, int status, int start, int end) {
5311                    return findByC_S(companyId, status, start, end, null);
5312            }
5313    
5314            /**
5315             * Returns an ordered range of all the users where companyId = &#63; and status = &#63;.
5316             *
5317             * <p>
5318             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
5319             * </p>
5320             *
5321             * @param companyId the company ID
5322             * @param status the status
5323             * @param start the lower bound of the range of users
5324             * @param end the upper bound of the range of users (not inclusive)
5325             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5326             * @return the ordered range of matching users
5327             */
5328            @Override
5329            public List<User> findByC_S(long companyId, int status, int start, int end,
5330                    OrderByComparator<User> orderByComparator) {
5331                    return findByC_S(companyId, status, start, end, orderByComparator, true);
5332            }
5333    
5334            /**
5335             * Returns an ordered range of all the users where companyId = &#63; and status = &#63;.
5336             *
5337             * <p>
5338             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
5339             * </p>
5340             *
5341             * @param companyId the company ID
5342             * @param status the status
5343             * @param start the lower bound of the range of users
5344             * @param end the upper bound of the range of users (not inclusive)
5345             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5346             * @param retrieveFromCache whether to retrieve from the finder cache
5347             * @return the ordered range of matching users
5348             */
5349            @Override
5350            public List<User> findByC_S(long companyId, int status, int start, int end,
5351                    OrderByComparator<User> orderByComparator, boolean retrieveFromCache) {
5352                    boolean pagination = true;
5353                    FinderPath finderPath = null;
5354                    Object[] finderArgs = null;
5355    
5356                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5357                                    (orderByComparator == null)) {
5358                            pagination = false;
5359                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S;
5360                            finderArgs = new Object[] { companyId, status };
5361                    }
5362                    else {
5363                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S;
5364                            finderArgs = new Object[] {
5365                                            companyId, status,
5366                                            
5367                                            start, end, orderByComparator
5368                                    };
5369                    }
5370    
5371                    List<User> list = null;
5372    
5373                    if (retrieveFromCache) {
5374                            list = (List<User>)finderCache.getResult(finderPath, finderArgs,
5375                                            this);
5376    
5377                            if ((list != null) && !list.isEmpty()) {
5378                                    for (User user : list) {
5379                                            if ((companyId != user.getCompanyId()) ||
5380                                                            (status != user.getStatus())) {
5381                                                    list = null;
5382    
5383                                                    break;
5384                                            }
5385                                    }
5386                            }
5387                    }
5388    
5389                    if (list == null) {
5390                            StringBundler query = null;
5391    
5392                            if (orderByComparator != null) {
5393                                    query = new StringBundler(4 +
5394                                                    (orderByComparator.getOrderByFields().length * 3));
5395                            }
5396                            else {
5397                                    query = new StringBundler(4);
5398                            }
5399    
5400                            query.append(_SQL_SELECT_USER_WHERE);
5401    
5402                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
5403    
5404                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
5405    
5406                            if (orderByComparator != null) {
5407                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5408                                            orderByComparator);
5409                            }
5410                            else
5411                             if (pagination) {
5412                                    query.append(UserModelImpl.ORDER_BY_JPQL);
5413                            }
5414    
5415                            String sql = query.toString();
5416    
5417                            Session session = null;
5418    
5419                            try {
5420                                    session = openSession();
5421    
5422                                    Query q = session.createQuery(sql);
5423    
5424                                    QueryPos qPos = QueryPos.getInstance(q);
5425    
5426                                    qPos.add(companyId);
5427    
5428                                    qPos.add(status);
5429    
5430                                    if (!pagination) {
5431                                            list = (List<User>)QueryUtil.list(q, getDialect(), start,
5432                                                            end, false);
5433    
5434                                            Collections.sort(list);
5435    
5436                                            list = Collections.unmodifiableList(list);
5437                                    }
5438                                    else {
5439                                            list = (List<User>)QueryUtil.list(q, getDialect(), start,
5440                                                            end);
5441                                    }
5442    
5443                                    cacheResult(list);
5444    
5445                                    finderCache.putResult(finderPath, finderArgs, list);
5446                            }
5447                            catch (Exception e) {
5448                                    finderCache.removeResult(finderPath, finderArgs);
5449    
5450                                    throw processException(e);
5451                            }
5452                            finally {
5453                                    closeSession(session);
5454                            }
5455                    }
5456    
5457                    return list;
5458            }
5459    
5460            /**
5461             * Returns the first user in the ordered set where companyId = &#63; and status = &#63;.
5462             *
5463             * @param companyId the company ID
5464             * @param status the status
5465             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5466             * @return the first matching user
5467             * @throws NoSuchUserException if a matching user could not be found
5468             */
5469            @Override
5470            public User findByC_S_First(long companyId, int status,
5471                    OrderByComparator<User> orderByComparator) throws NoSuchUserException {
5472                    User user = fetchByC_S_First(companyId, status, orderByComparator);
5473    
5474                    if (user != null) {
5475                            return user;
5476                    }
5477    
5478                    StringBundler msg = new StringBundler(6);
5479    
5480                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5481    
5482                    msg.append("companyId=");
5483                    msg.append(companyId);
5484    
5485                    msg.append(", status=");
5486                    msg.append(status);
5487    
5488                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5489    
5490                    throw new NoSuchUserException(msg.toString());
5491            }
5492    
5493            /**
5494             * Returns the first user in the ordered set where companyId = &#63; and status = &#63;.
5495             *
5496             * @param companyId the company ID
5497             * @param status the status
5498             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5499             * @return the first matching user, or <code>null</code> if a matching user could not be found
5500             */
5501            @Override
5502            public User fetchByC_S_First(long companyId, int status,
5503                    OrderByComparator<User> orderByComparator) {
5504                    List<User> list = findByC_S(companyId, status, 0, 1, orderByComparator);
5505    
5506                    if (!list.isEmpty()) {
5507                            return list.get(0);
5508                    }
5509    
5510                    return null;
5511            }
5512    
5513            /**
5514             * Returns the last user in the ordered set where companyId = &#63; and status = &#63;.
5515             *
5516             * @param companyId the company ID
5517             * @param status the status
5518             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5519             * @return the last matching user
5520             * @throws NoSuchUserException if a matching user could not be found
5521             */
5522            @Override
5523            public User findByC_S_Last(long companyId, int status,
5524                    OrderByComparator<User> orderByComparator) throws NoSuchUserException {
5525                    User user = fetchByC_S_Last(companyId, status, orderByComparator);
5526    
5527                    if (user != null) {
5528                            return user;
5529                    }
5530    
5531                    StringBundler msg = new StringBundler(6);
5532    
5533                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5534    
5535                    msg.append("companyId=");
5536                    msg.append(companyId);
5537    
5538                    msg.append(", status=");
5539                    msg.append(status);
5540    
5541                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5542    
5543                    throw new NoSuchUserException(msg.toString());
5544            }
5545    
5546            /**
5547             * Returns the last user in the ordered set where companyId = &#63; and status = &#63;.
5548             *
5549             * @param companyId the company ID
5550             * @param status the status
5551             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5552             * @return the last matching user, or <code>null</code> if a matching user could not be found
5553             */
5554            @Override
5555            public User fetchByC_S_Last(long companyId, int status,
5556                    OrderByComparator<User> orderByComparator) {
5557                    int count = countByC_S(companyId, status);
5558    
5559                    if (count == 0) {
5560                            return null;
5561                    }
5562    
5563                    List<User> list = findByC_S(companyId, status, count - 1, count,
5564                                    orderByComparator);
5565    
5566                    if (!list.isEmpty()) {
5567                            return list.get(0);
5568                    }
5569    
5570                    return null;
5571            }
5572    
5573            /**
5574             * Returns the users before and after the current user in the ordered set where companyId = &#63; and status = &#63;.
5575             *
5576             * @param userId the primary key of the current user
5577             * @param companyId the company ID
5578             * @param status the status
5579             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5580             * @return the previous, current, and next user
5581             * @throws NoSuchUserException if a user with the primary key could not be found
5582             */
5583            @Override
5584            public User[] findByC_S_PrevAndNext(long userId, long companyId,
5585                    int status, OrderByComparator<User> orderByComparator)
5586                    throws NoSuchUserException {
5587                    User user = findByPrimaryKey(userId);
5588    
5589                    Session session = null;
5590    
5591                    try {
5592                            session = openSession();
5593    
5594                            User[] array = new UserImpl[3];
5595    
5596                            array[0] = getByC_S_PrevAndNext(session, user, companyId, status,
5597                                            orderByComparator, true);
5598    
5599                            array[1] = user;
5600    
5601                            array[2] = getByC_S_PrevAndNext(session, user, companyId, status,
5602                                            orderByComparator, false);
5603    
5604                            return array;
5605                    }
5606                    catch (Exception e) {
5607                            throw processException(e);
5608                    }
5609                    finally {
5610                            closeSession(session);
5611                    }
5612            }
5613    
5614            protected User getByC_S_PrevAndNext(Session session, User user,
5615                    long companyId, int status, OrderByComparator<User> orderByComparator,
5616                    boolean previous) {
5617                    StringBundler query = null;
5618    
5619                    if (orderByComparator != null) {
5620                            query = new StringBundler(6 +
5621                                            (orderByComparator.getOrderByFields().length * 6));
5622                    }
5623                    else {
5624                            query = new StringBundler(3);
5625                    }
5626    
5627                    query.append(_SQL_SELECT_USER_WHERE);
5628    
5629                    query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
5630    
5631                    query.append(_FINDER_COLUMN_C_S_STATUS_2);
5632    
5633                    if (orderByComparator != null) {
5634                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5635    
5636                            if (orderByConditionFields.length > 0) {
5637                                    query.append(WHERE_AND);
5638                            }
5639    
5640                            for (int i = 0; i < orderByConditionFields.length; i++) {
5641                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5642                                    query.append(orderByConditionFields[i]);
5643    
5644                                    if ((i + 1) < orderByConditionFields.length) {
5645                                            if (orderByComparator.isAscending() ^ previous) {
5646                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5647                                            }
5648                                            else {
5649                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5650                                            }
5651                                    }
5652                                    else {
5653                                            if (orderByComparator.isAscending() ^ previous) {
5654                                                    query.append(WHERE_GREATER_THAN);
5655                                            }
5656                                            else {
5657                                                    query.append(WHERE_LESSER_THAN);
5658                                            }
5659                                    }
5660                            }
5661    
5662                            query.append(ORDER_BY_CLAUSE);
5663    
5664                            String[] orderByFields = orderByComparator.getOrderByFields();
5665    
5666                            for (int i = 0; i < orderByFields.length; i++) {
5667                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5668                                    query.append(orderByFields[i]);
5669    
5670                                    if ((i + 1) < orderByFields.length) {
5671                                            if (orderByComparator.isAscending() ^ previous) {
5672                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5673                                            }
5674                                            else {
5675                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5676                                            }
5677                                    }
5678                                    else {
5679                                            if (orderByComparator.isAscending() ^ previous) {
5680                                                    query.append(ORDER_BY_ASC);
5681                                            }
5682                                            else {
5683                                                    query.append(ORDER_BY_DESC);
5684                                            }
5685                                    }
5686                            }
5687                    }
5688                    else {
5689                            query.append(UserModelImpl.ORDER_BY_JPQL);
5690                    }
5691    
5692                    String sql = query.toString();
5693    
5694                    Query q = session.createQuery(sql);
5695    
5696                    q.setFirstResult(0);
5697                    q.setMaxResults(2);
5698    
5699                    QueryPos qPos = QueryPos.getInstance(q);
5700    
5701                    qPos.add(companyId);
5702    
5703                    qPos.add(status);
5704    
5705                    if (orderByComparator != null) {
5706                            Object[] values = orderByComparator.getOrderByConditionValues(user);
5707    
5708                            for (Object value : values) {
5709                                    qPos.add(value);
5710                            }
5711                    }
5712    
5713                    List<User> list = q.list();
5714    
5715                    if (list.size() == 2) {
5716                            return list.get(1);
5717                    }
5718                    else {
5719                            return null;
5720                    }
5721            }
5722    
5723            /**
5724             * Removes all the users where companyId = &#63; and status = &#63; from the database.
5725             *
5726             * @param companyId the company ID
5727             * @param status the status
5728             */
5729            @Override
5730            public void removeByC_S(long companyId, int status) {
5731                    for (User user : findByC_S(companyId, status, QueryUtil.ALL_POS,
5732                                    QueryUtil.ALL_POS, null)) {
5733                            remove(user);
5734                    }
5735            }
5736    
5737            /**
5738             * Returns the number of users where companyId = &#63; and status = &#63;.
5739             *
5740             * @param companyId the company ID
5741             * @param status the status
5742             * @return the number of matching users
5743             */
5744            @Override
5745            public int countByC_S(long companyId, int status) {
5746                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_S;
5747    
5748                    Object[] finderArgs = new Object[] { companyId, status };
5749    
5750                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
5751    
5752                    if (count == null) {
5753                            StringBundler query = new StringBundler(3);
5754    
5755                            query.append(_SQL_COUNT_USER_WHERE);
5756    
5757                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
5758    
5759                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
5760    
5761                            String sql = query.toString();
5762    
5763                            Session session = null;
5764    
5765                            try {
5766                                    session = openSession();
5767    
5768                                    Query q = session.createQuery(sql);
5769    
5770                                    QueryPos qPos = QueryPos.getInstance(q);
5771    
5772                                    qPos.add(companyId);
5773    
5774                                    qPos.add(status);
5775    
5776                                    count = (Long)q.uniqueResult();
5777    
5778                                    finderCache.putResult(finderPath, finderArgs, count);
5779                            }
5780                            catch (Exception e) {
5781                                    finderCache.removeResult(finderPath, finderArgs);
5782    
5783                                    throw processException(e);
5784                            }
5785                            finally {
5786                                    closeSession(session);
5787                            }
5788                    }
5789    
5790                    return count.intValue();
5791            }
5792    
5793            private static final String _FINDER_COLUMN_C_S_COMPANYID_2 = "user.companyId = ? AND ";
5794            private static final String _FINDER_COLUMN_C_S_STATUS_2 = "user.status = ?";
5795            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_CD_MD = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
5796                            UserModelImpl.FINDER_CACHE_ENABLED, UserImpl.class,
5797                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_CD_MD",
5798                            new String[] {
5799                                    Long.class.getName(), Date.class.getName(), Date.class.getName(),
5800                                    
5801                            Integer.class.getName(), Integer.class.getName(),
5802                                    OrderByComparator.class.getName()
5803                            });
5804            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_CD_MD =
5805                    new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
5806                            UserModelImpl.FINDER_CACHE_ENABLED, UserImpl.class,
5807                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_CD_MD",
5808                            new String[] {
5809                                    Long.class.getName(), Date.class.getName(), Date.class.getName()
5810                            },
5811                            UserModelImpl.COMPANYID_COLUMN_BITMASK |
5812                            UserModelImpl.CREATEDATE_COLUMN_BITMASK |
5813                            UserModelImpl.MODIFIEDDATE_COLUMN_BITMASK);
5814            public static final FinderPath FINDER_PATH_COUNT_BY_C_CD_MD = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
5815                            UserModelImpl.FINDER_CACHE_ENABLED, Long.class,
5816                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_CD_MD",
5817                            new String[] {
5818                                    Long.class.getName(), Date.class.getName(), Date.class.getName()
5819                            });
5820    
5821            /**
5822             * Returns all the users where companyId = &#63; and createDate = &#63; and modifiedDate = &#63;.
5823             *
5824             * @param companyId the company ID
5825             * @param createDate the create date
5826             * @param modifiedDate the modified date
5827             * @return the matching users
5828             */
5829            @Override
5830            public List<User> findByC_CD_MD(long companyId, Date createDate,
5831                    Date modifiedDate) {
5832                    return findByC_CD_MD(companyId, createDate, modifiedDate,
5833                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5834            }
5835    
5836            /**
5837             * Returns a range of all the users where companyId = &#63; and createDate = &#63; and modifiedDate = &#63;.
5838             *
5839             * <p>
5840             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
5841             * </p>
5842             *
5843             * @param companyId the company ID
5844             * @param createDate the create date
5845             * @param modifiedDate the modified date
5846             * @param start the lower bound of the range of users
5847             * @param end the upper bound of the range of users (not inclusive)
5848             * @return the range of matching users
5849             */
5850            @Override
5851            public List<User> findByC_CD_MD(long companyId, Date createDate,
5852                    Date modifiedDate, int start, int end) {
5853                    return findByC_CD_MD(companyId, createDate, modifiedDate, start, end,
5854                            null);
5855            }
5856    
5857            /**
5858             * Returns an ordered range of all the users where companyId = &#63; and createDate = &#63; and modifiedDate = &#63;.
5859             *
5860             * <p>
5861             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
5862             * </p>
5863             *
5864             * @param companyId the company ID
5865             * @param createDate the create date
5866             * @param modifiedDate the modified date
5867             * @param start the lower bound of the range of users
5868             * @param end the upper bound of the range of users (not inclusive)
5869             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5870             * @return the ordered range of matching users
5871             */
5872            @Override
5873            public List<User> findByC_CD_MD(long companyId, Date createDate,
5874                    Date modifiedDate, int start, int end,
5875                    OrderByComparator<User> orderByComparator) {
5876                    return findByC_CD_MD(companyId, createDate, modifiedDate, start, end,
5877                            orderByComparator, true);
5878            }
5879    
5880            /**
5881             * Returns an ordered range of all the users where companyId = &#63; and createDate = &#63; and modifiedDate = &#63;.
5882             *
5883             * <p>
5884             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
5885             * </p>
5886             *
5887             * @param companyId the company ID
5888             * @param createDate the create date
5889             * @param modifiedDate the modified date
5890             * @param start the lower bound of the range of users
5891             * @param end the upper bound of the range of users (not inclusive)
5892             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5893             * @param retrieveFromCache whether to retrieve from the finder cache
5894             * @return the ordered range of matching users
5895             */
5896            @Override
5897            public List<User> findByC_CD_MD(long companyId, Date createDate,
5898                    Date modifiedDate, int start, int end,
5899                    OrderByComparator<User> orderByComparator, boolean retrieveFromCache) {
5900                    boolean pagination = true;
5901                    FinderPath finderPath = null;
5902                    Object[] finderArgs = null;
5903    
5904                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5905                                    (orderByComparator == null)) {
5906                            pagination = false;
5907                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_CD_MD;
5908                            finderArgs = new Object[] { companyId, createDate, modifiedDate };
5909                    }
5910                    else {
5911                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_CD_MD;
5912                            finderArgs = new Object[] {
5913                                            companyId, createDate, modifiedDate,
5914                                            
5915                                            start, end, orderByComparator
5916                                    };
5917                    }
5918    
5919                    List<User> list = null;
5920    
5921                    if (retrieveFromCache) {
5922                            list = (List<User>)finderCache.getResult(finderPath, finderArgs,
5923                                            this);
5924    
5925                            if ((list != null) && !list.isEmpty()) {
5926                                    for (User user : list) {
5927                                            if ((companyId != user.getCompanyId()) ||
5928                                                            !Validator.equals(createDate, user.getCreateDate()) ||
5929                                                            !Validator.equals(modifiedDate,
5930                                                                    user.getModifiedDate())) {
5931                                                    list = null;
5932    
5933                                                    break;
5934                                            }
5935                                    }
5936                            }
5937                    }
5938    
5939                    if (list == null) {
5940                            StringBundler query = null;
5941    
5942                            if (orderByComparator != null) {
5943                                    query = new StringBundler(5 +
5944                                                    (orderByComparator.getOrderByFields().length * 3));
5945                            }
5946                            else {
5947                                    query = new StringBundler(5);
5948                            }
5949    
5950                            query.append(_SQL_SELECT_USER_WHERE);
5951    
5952                            query.append(_FINDER_COLUMN_C_CD_MD_COMPANYID_2);
5953    
5954                            boolean bindCreateDate = false;
5955    
5956                            if (createDate == null) {
5957                                    query.append(_FINDER_COLUMN_C_CD_MD_CREATEDATE_1);
5958                            }
5959                            else {
5960                                    bindCreateDate = true;
5961    
5962                                    query.append(_FINDER_COLUMN_C_CD_MD_CREATEDATE_2);
5963                            }
5964    
5965                            boolean bindModifiedDate = false;
5966    
5967                            if (modifiedDate == null) {
5968                                    query.append(_FINDER_COLUMN_C_CD_MD_MODIFIEDDATE_1);
5969                            }
5970                            else {
5971                                    bindModifiedDate = true;
5972    
5973                                    query.append(_FINDER_COLUMN_C_CD_MD_MODIFIEDDATE_2);
5974                            }
5975    
5976                            if (orderByComparator != null) {
5977                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5978                                            orderByComparator);
5979                            }
5980                            else
5981                             if (pagination) {
5982                                    query.append(UserModelImpl.ORDER_BY_JPQL);
5983                            }
5984    
5985                            String sql = query.toString();
5986    
5987                            Session session = null;
5988    
5989                            try {
5990                                    session = openSession();
5991    
5992                                    Query q = session.createQuery(sql);
5993    
5994                                    QueryPos qPos = QueryPos.getInstance(q);
5995    
5996                                    qPos.add(companyId);
5997    
5998                                    if (bindCreateDate) {
5999                                            qPos.add(new Timestamp(createDate.getTime()));
6000                                    }
6001    
6002                                    if (bindModifiedDate) {
6003                                            qPos.add(new Timestamp(modifiedDate.getTime()));
6004                                    }
6005    
6006                                    if (!pagination) {
6007                                            list = (List<User>)QueryUtil.list(q, getDialect(), start,
6008                                                            end, false);
6009    
6010                                            Collections.sort(list);
6011    
6012                                            list = Collections.unmodifiableList(list);
6013                                    }
6014                                    else {
6015                                            list = (List<User>)QueryUtil.list(q, getDialect(), start,
6016                                                            end);
6017                                    }
6018    
6019                                    cacheResult(list);
6020    
6021                                    finderCache.putResult(finderPath, finderArgs, list);
6022                            }
6023                            catch (Exception e) {
6024                                    finderCache.removeResult(finderPath, finderArgs);
6025    
6026                                    throw processException(e);
6027                            }
6028                            finally {
6029                                    closeSession(session);
6030                            }
6031                    }
6032    
6033                    return list;
6034            }
6035    
6036            /**
6037             * Returns the first user in the ordered set where companyId = &#63; and createDate = &#63; and modifiedDate = &#63;.
6038             *
6039             * @param companyId the company ID
6040             * @param createDate the create date
6041             * @param modifiedDate the modified date
6042             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6043             * @return the first matching user
6044             * @throws NoSuchUserException if a matching user could not be found
6045             */
6046            @Override
6047            public User findByC_CD_MD_First(long companyId, Date createDate,
6048                    Date modifiedDate, OrderByComparator<User> orderByComparator)
6049                    throws NoSuchUserException {
6050                    User user = fetchByC_CD_MD_First(companyId, createDate, modifiedDate,
6051                                    orderByComparator);
6052    
6053                    if (user != null) {
6054                            return user;
6055                    }
6056    
6057                    StringBundler msg = new StringBundler(8);
6058    
6059                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6060    
6061                    msg.append("companyId=");
6062                    msg.append(companyId);
6063    
6064                    msg.append(", createDate=");
6065                    msg.append(createDate);
6066    
6067                    msg.append(", modifiedDate=");
6068                    msg.append(modifiedDate);
6069    
6070                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6071    
6072                    throw new NoSuchUserException(msg.toString());
6073            }
6074    
6075            /**
6076             * Returns the first user in the ordered set where companyId = &#63; and createDate = &#63; and modifiedDate = &#63;.
6077             *
6078             * @param companyId the company ID
6079             * @param createDate the create date
6080             * @param modifiedDate the modified date
6081             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6082             * @return the first matching user, or <code>null</code> if a matching user could not be found
6083             */
6084            @Override
6085            public User fetchByC_CD_MD_First(long companyId, Date createDate,
6086                    Date modifiedDate, OrderByComparator<User> orderByComparator) {
6087                    List<User> list = findByC_CD_MD(companyId, createDate, modifiedDate, 0,
6088                                    1, orderByComparator);
6089    
6090                    if (!list.isEmpty()) {
6091                            return list.get(0);
6092                    }
6093    
6094                    return null;
6095            }
6096    
6097            /**
6098             * Returns the last user in the ordered set where companyId = &#63; and createDate = &#63; and modifiedDate = &#63;.
6099             *
6100             * @param companyId the company ID
6101             * @param createDate the create date
6102             * @param modifiedDate the modified date
6103             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6104             * @return the last matching user
6105             * @throws NoSuchUserException if a matching user could not be found
6106             */
6107            @Override
6108            public User findByC_CD_MD_Last(long companyId, Date createDate,
6109                    Date modifiedDate, OrderByComparator<User> orderByComparator)
6110                    throws NoSuchUserException {
6111                    User user = fetchByC_CD_MD_Last(companyId, createDate, modifiedDate,
6112                                    orderByComparator);
6113    
6114                    if (user != null) {
6115                            return user;
6116                    }
6117    
6118                    StringBundler msg = new StringBundler(8);
6119    
6120                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6121    
6122                    msg.append("companyId=");
6123                    msg.append(companyId);
6124    
6125                    msg.append(", createDate=");
6126                    msg.append(createDate);
6127    
6128                    msg.append(", modifiedDate=");
6129                    msg.append(modifiedDate);
6130    
6131                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6132    
6133                    throw new NoSuchUserException(msg.toString());
6134            }
6135    
6136            /**
6137             * Returns the last user in the ordered set where companyId = &#63; and createDate = &#63; and modifiedDate = &#63;.
6138             *
6139             * @param companyId the company ID
6140             * @param createDate the create date
6141             * @param modifiedDate the modified date
6142             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6143             * @return the last matching user, or <code>null</code> if a matching user could not be found
6144             */
6145            @Override
6146            public User fetchByC_CD_MD_Last(long companyId, Date createDate,
6147                    Date modifiedDate, OrderByComparator<User> orderByComparator) {
6148                    int count = countByC_CD_MD(companyId, createDate, modifiedDate);
6149    
6150                    if (count == 0) {
6151                            return null;
6152                    }
6153    
6154                    List<User> list = findByC_CD_MD(companyId, createDate, modifiedDate,
6155                                    count - 1, count, orderByComparator);
6156    
6157                    if (!list.isEmpty()) {
6158                            return list.get(0);
6159                    }
6160    
6161                    return null;
6162            }
6163    
6164            /**
6165             * Returns the users before and after the current user in the ordered set where companyId = &#63; and createDate = &#63; and modifiedDate = &#63;.
6166             *
6167             * @param userId the primary key of the current user
6168             * @param companyId the company ID
6169             * @param createDate the create date
6170             * @param modifiedDate the modified date
6171             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6172             * @return the previous, current, and next user
6173             * @throws NoSuchUserException if a user with the primary key could not be found
6174             */
6175            @Override
6176            public User[] findByC_CD_MD_PrevAndNext(long userId, long companyId,
6177                    Date createDate, Date modifiedDate,
6178                    OrderByComparator<User> orderByComparator) throws NoSuchUserException {
6179                    User user = findByPrimaryKey(userId);
6180    
6181                    Session session = null;
6182    
6183                    try {
6184                            session = openSession();
6185    
6186                            User[] array = new UserImpl[3];
6187    
6188                            array[0] = getByC_CD_MD_PrevAndNext(session, user, companyId,
6189                                            createDate, modifiedDate, orderByComparator, true);
6190    
6191                            array[1] = user;
6192    
6193                            array[2] = getByC_CD_MD_PrevAndNext(session, user, companyId,
6194                                            createDate, modifiedDate, orderByComparator, false);
6195    
6196                            return array;
6197                    }
6198                    catch (Exception e) {
6199                            throw processException(e);
6200                    }
6201                    finally {
6202                            closeSession(session);
6203                    }
6204            }
6205    
6206            protected User getByC_CD_MD_PrevAndNext(Session session, User user,
6207                    long companyId, Date createDate, Date modifiedDate,
6208                    OrderByComparator<User> orderByComparator, boolean previous) {
6209                    StringBundler query = null;
6210    
6211                    if (orderByComparator != null) {
6212                            query = new StringBundler(6 +
6213                                            (orderByComparator.getOrderByFields().length * 6));
6214                    }
6215                    else {
6216                            query = new StringBundler(3);
6217                    }
6218    
6219                    query.append(_SQL_SELECT_USER_WHERE);
6220    
6221                    query.append(_FINDER_COLUMN_C_CD_MD_COMPANYID_2);
6222    
6223                    boolean bindCreateDate = false;
6224    
6225                    if (createDate == null) {
6226                            query.append(_FINDER_COLUMN_C_CD_MD_CREATEDATE_1);
6227                    }
6228                    else {
6229                            bindCreateDate = true;
6230    
6231                            query.append(_FINDER_COLUMN_C_CD_MD_CREATEDATE_2);
6232                    }
6233    
6234                    boolean bindModifiedDate = false;
6235    
6236                    if (modifiedDate == null) {
6237                            query.append(_FINDER_COLUMN_C_CD_MD_MODIFIEDDATE_1);
6238                    }
6239                    else {
6240                            bindModifiedDate = true;
6241    
6242                            query.append(_FINDER_COLUMN_C_CD_MD_MODIFIEDDATE_2);
6243                    }
6244    
6245                    if (orderByComparator != null) {
6246                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6247    
6248                            if (orderByConditionFields.length > 0) {
6249                                    query.append(WHERE_AND);
6250                            }
6251    
6252                            for (int i = 0; i < orderByConditionFields.length; i++) {
6253                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6254                                    query.append(orderByConditionFields[i]);
6255    
6256                                    if ((i + 1) < orderByConditionFields.length) {
6257                                            if (orderByComparator.isAscending() ^ previous) {
6258                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6259                                            }
6260                                            else {
6261                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6262                                            }
6263                                    }
6264                                    else {
6265                                            if (orderByComparator.isAscending() ^ previous) {
6266                                                    query.append(WHERE_GREATER_THAN);
6267                                            }
6268                                            else {
6269                                                    query.append(WHERE_LESSER_THAN);
6270                                            }
6271                                    }
6272                            }
6273    
6274                            query.append(ORDER_BY_CLAUSE);
6275    
6276                            String[] orderByFields = orderByComparator.getOrderByFields();
6277    
6278                            for (int i = 0; i < orderByFields.length; i++) {
6279                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6280                                    query.append(orderByFields[i]);
6281    
6282                                    if ((i + 1) < orderByFields.length) {
6283                                            if (orderByComparator.isAscending() ^ previous) {
6284                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6285                                            }
6286                                            else {
6287                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6288                                            }
6289                                    }
6290                                    else {
6291                                            if (orderByComparator.isAscending() ^ previous) {
6292                                                    query.append(ORDER_BY_ASC);
6293                                            }
6294                                            else {
6295                                                    query.append(ORDER_BY_DESC);
6296                                            }
6297                                    }
6298                            }
6299                    }
6300                    else {
6301                            query.append(UserModelImpl.ORDER_BY_JPQL);
6302                    }
6303    
6304                    String sql = query.toString();
6305    
6306                    Query q = session.createQuery(sql);
6307    
6308                    q.setFirstResult(0);
6309                    q.setMaxResults(2);
6310    
6311                    QueryPos qPos = QueryPos.getInstance(q);
6312    
6313                    qPos.add(companyId);
6314    
6315                    if (bindCreateDate) {
6316                            qPos.add(new Timestamp(createDate.getTime()));
6317                    }
6318    
6319                    if (bindModifiedDate) {
6320                            qPos.add(new Timestamp(modifiedDate.getTime()));
6321                    }
6322    
6323                    if (orderByComparator != null) {
6324                            Object[] values = orderByComparator.getOrderByConditionValues(user);
6325    
6326                            for (Object value : values) {
6327                                    qPos.add(value);
6328                            }
6329                    }
6330    
6331                    List<User> list = q.list();
6332    
6333                    if (list.size() == 2) {
6334                            return list.get(1);
6335                    }
6336                    else {
6337                            return null;
6338                    }
6339            }
6340    
6341            /**
6342             * Removes all the users where companyId = &#63; and createDate = &#63; and modifiedDate = &#63; from the database.
6343             *
6344             * @param companyId the company ID
6345             * @param createDate the create date
6346             * @param modifiedDate the modified date
6347             */
6348            @Override
6349            public void removeByC_CD_MD(long companyId, Date createDate,
6350                    Date modifiedDate) {
6351                    for (User user : findByC_CD_MD(companyId, createDate, modifiedDate,
6352                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6353                            remove(user);
6354                    }
6355            }
6356    
6357            /**
6358             * Returns the number of users where companyId = &#63; and createDate = &#63; and modifiedDate = &#63;.
6359             *
6360             * @param companyId the company ID
6361             * @param createDate the create date
6362             * @param modifiedDate the modified date
6363             * @return the number of matching users
6364             */
6365            @Override
6366            public int countByC_CD_MD(long companyId, Date createDate, Date modifiedDate) {
6367                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_CD_MD;
6368    
6369                    Object[] finderArgs = new Object[] { companyId, createDate, modifiedDate };
6370    
6371                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
6372    
6373                    if (count == null) {
6374                            StringBundler query = new StringBundler(4);
6375    
6376                            query.append(_SQL_COUNT_USER_WHERE);
6377    
6378                            query.append(_FINDER_COLUMN_C_CD_MD_COMPANYID_2);
6379    
6380                            boolean bindCreateDate = false;
6381    
6382                            if (createDate == null) {
6383                                    query.append(_FINDER_COLUMN_C_CD_MD_CREATEDATE_1);
6384                            }
6385                            else {
6386                                    bindCreateDate = true;
6387    
6388                                    query.append(_FINDER_COLUMN_C_CD_MD_CREATEDATE_2);
6389                            }
6390    
6391                            boolean bindModifiedDate = false;
6392    
6393                            if (modifiedDate == null) {
6394                                    query.append(_FINDER_COLUMN_C_CD_MD_MODIFIEDDATE_1);
6395                            }
6396                            else {
6397                                    bindModifiedDate = true;
6398    
6399                                    query.append(_FINDER_COLUMN_C_CD_MD_MODIFIEDDATE_2);
6400                            }
6401    
6402                            String sql = query.toString();
6403    
6404                            Session session = null;
6405    
6406                            try {
6407                                    session = openSession();
6408    
6409                                    Query q = session.createQuery(sql);
6410    
6411                                    QueryPos qPos = QueryPos.getInstance(q);
6412    
6413                                    qPos.add(companyId);
6414    
6415                                    if (bindCreateDate) {
6416                                            qPos.add(new Timestamp(createDate.getTime()));
6417                                    }
6418    
6419                                    if (bindModifiedDate) {
6420                                            qPos.add(new Timestamp(modifiedDate.getTime()));
6421                                    }
6422    
6423                                    count = (Long)q.uniqueResult();
6424    
6425                                    finderCache.putResult(finderPath, finderArgs, count);
6426                            }
6427                            catch (Exception e) {
6428                                    finderCache.removeResult(finderPath, finderArgs);
6429    
6430                                    throw processException(e);
6431                            }
6432                            finally {
6433                                    closeSession(session);
6434                            }
6435                    }
6436    
6437                    return count.intValue();
6438            }
6439    
6440            private static final String _FINDER_COLUMN_C_CD_MD_COMPANYID_2 = "user.companyId = ? AND ";
6441            private static final String _FINDER_COLUMN_C_CD_MD_CREATEDATE_1 = "user.createDate IS NULL AND ";
6442            private static final String _FINDER_COLUMN_C_CD_MD_CREATEDATE_2 = "user.createDate = ? AND ";
6443            private static final String _FINDER_COLUMN_C_CD_MD_MODIFIEDDATE_1 = "user.modifiedDate IS NULL";
6444            private static final String _FINDER_COLUMN_C_CD_MD_MODIFIEDDATE_2 = "user.modifiedDate = ?";
6445            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_DU_S = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
6446                            UserModelImpl.FINDER_CACHE_ENABLED, UserImpl.class,
6447                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_DU_S",
6448                            new String[] {
6449                                    Long.class.getName(), Boolean.class.getName(),
6450                                    Integer.class.getName(),
6451                                    
6452                            Integer.class.getName(), Integer.class.getName(),
6453                                    OrderByComparator.class.getName()
6454                            });
6455            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_DU_S =
6456                    new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
6457                            UserModelImpl.FINDER_CACHE_ENABLED, UserImpl.class,
6458                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_DU_S",
6459                            new String[] {
6460                                    Long.class.getName(), Boolean.class.getName(),
6461                                    Integer.class.getName()
6462                            },
6463                            UserModelImpl.COMPANYID_COLUMN_BITMASK |
6464                            UserModelImpl.DEFAULTUSER_COLUMN_BITMASK |
6465                            UserModelImpl.STATUS_COLUMN_BITMASK);
6466            public static final FinderPath FINDER_PATH_COUNT_BY_C_DU_S = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
6467                            UserModelImpl.FINDER_CACHE_ENABLED, Long.class,
6468                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_DU_S",
6469                            new String[] {
6470                                    Long.class.getName(), Boolean.class.getName(),
6471                                    Integer.class.getName()
6472                            });
6473    
6474            /**
6475             * Returns all the users where companyId = &#63; and defaultUser = &#63; and status = &#63;.
6476             *
6477             * @param companyId the company ID
6478             * @param defaultUser the default user
6479             * @param status the status
6480             * @return the matching users
6481             */
6482            @Override
6483            public List<User> findByC_DU_S(long companyId, boolean defaultUser,
6484                    int status) {
6485                    return findByC_DU_S(companyId, defaultUser, status, QueryUtil.ALL_POS,
6486                            QueryUtil.ALL_POS, null);
6487            }
6488    
6489            /**
6490             * Returns a range of all the users where companyId = &#63; and defaultUser = &#63; and status = &#63;.
6491             *
6492             * <p>
6493             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
6494             * </p>
6495             *
6496             * @param companyId the company ID
6497             * @param defaultUser the default user
6498             * @param status the status
6499             * @param start the lower bound of the range of users
6500             * @param end the upper bound of the range of users (not inclusive)
6501             * @return the range of matching users
6502             */
6503            @Override
6504            public List<User> findByC_DU_S(long companyId, boolean defaultUser,
6505                    int status, int start, int end) {
6506                    return findByC_DU_S(companyId, defaultUser, status, start, end, null);
6507            }
6508    
6509            /**
6510             * Returns an ordered range of all the users where companyId = &#63; and defaultUser = &#63; and status = &#63;.
6511             *
6512             * <p>
6513             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
6514             * </p>
6515             *
6516             * @param companyId the company ID
6517             * @param defaultUser the default user
6518             * @param status the status
6519             * @param start the lower bound of the range of users
6520             * @param end the upper bound of the range of users (not inclusive)
6521             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6522             * @return the ordered range of matching users
6523             */
6524            @Override
6525            public List<User> findByC_DU_S(long companyId, boolean defaultUser,
6526                    int status, int start, int end,
6527                    OrderByComparator<User> orderByComparator) {
6528                    return findByC_DU_S(companyId, defaultUser, status, start, end,
6529                            orderByComparator, true);
6530            }
6531    
6532            /**
6533             * Returns an ordered range of all the users where companyId = &#63; and defaultUser = &#63; and status = &#63;.
6534             *
6535             * <p>
6536             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
6537             * </p>
6538             *
6539             * @param companyId the company ID
6540             * @param defaultUser the default user
6541             * @param status the status
6542             * @param start the lower bound of the range of users
6543             * @param end the upper bound of the range of users (not inclusive)
6544             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6545             * @param retrieveFromCache whether to retrieve from the finder cache
6546             * @return the ordered range of matching users
6547             */
6548            @Override
6549            public List<User> findByC_DU_S(long companyId, boolean defaultUser,
6550                    int status, int start, int end,
6551                    OrderByComparator<User> orderByComparator, boolean retrieveFromCache) {
6552                    boolean pagination = true;
6553                    FinderPath finderPath = null;
6554                    Object[] finderArgs = null;
6555    
6556                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6557                                    (orderByComparator == null)) {
6558                            pagination = false;
6559                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_DU_S;
6560                            finderArgs = new Object[] { companyId, defaultUser, status };
6561                    }
6562                    else {
6563                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_DU_S;
6564                            finderArgs = new Object[] {
6565                                            companyId, defaultUser, status,
6566                                            
6567                                            start, end, orderByComparator
6568                                    };
6569                    }
6570    
6571                    List<User> list = null;
6572    
6573                    if (retrieveFromCache) {
6574                            list = (List<User>)finderCache.getResult(finderPath, finderArgs,
6575                                            this);
6576    
6577                            if ((list != null) && !list.isEmpty()) {
6578                                    for (User user : list) {
6579                                            if ((companyId != user.getCompanyId()) ||
6580                                                            (defaultUser != user.getDefaultUser()) ||
6581                                                            (status != user.getStatus())) {
6582                                                    list = null;
6583    
6584                                                    break;
6585                                            }
6586                                    }
6587                            }
6588                    }
6589    
6590                    if (list == null) {
6591                            StringBundler query = null;
6592    
6593                            if (orderByComparator != null) {
6594                                    query = new StringBundler(5 +
6595                                                    (orderByComparator.getOrderByFields().length * 3));
6596                            }
6597                            else {
6598                                    query = new StringBundler(5);
6599                            }
6600    
6601                            query.append(_SQL_SELECT_USER_WHERE);
6602    
6603                            query.append(_FINDER_COLUMN_C_DU_S_COMPANYID_2);
6604    
6605                            query.append(_FINDER_COLUMN_C_DU_S_DEFAULTUSER_2);
6606    
6607                            query.append(_FINDER_COLUMN_C_DU_S_STATUS_2);
6608    
6609                            if (orderByComparator != null) {
6610                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6611                                            orderByComparator);
6612                            }
6613                            else
6614                             if (pagination) {
6615                                    query.append(UserModelImpl.ORDER_BY_JPQL);
6616                            }
6617    
6618                            String sql = query.toString();
6619    
6620                            Session session = null;
6621    
6622                            try {
6623                                    session = openSession();
6624    
6625                                    Query q = session.createQuery(sql);
6626    
6627                                    QueryPos qPos = QueryPos.getInstance(q);
6628    
6629                                    qPos.add(companyId);
6630    
6631                                    qPos.add(defaultUser);
6632    
6633                                    qPos.add(status);
6634    
6635                                    if (!pagination) {
6636                                            list = (List<User>)QueryUtil.list(q, getDialect(), start,
6637                                                            end, false);
6638    
6639                                            Collections.sort(list);
6640    
6641                                            list = Collections.unmodifiableList(list);
6642                                    }
6643                                    else {
6644                                            list = (List<User>)QueryUtil.list(q, getDialect(), start,
6645                                                            end);
6646                                    }
6647    
6648                                    cacheResult(list);
6649    
6650                                    finderCache.putResult(finderPath, finderArgs, list);
6651                            }
6652                            catch (Exception e) {
6653                                    finderCache.removeResult(finderPath, finderArgs);
6654    
6655                                    throw processException(e);
6656                            }
6657                            finally {
6658                                    closeSession(session);
6659                            }
6660                    }
6661    
6662                    return list;
6663            }
6664    
6665            /**
6666             * Returns the first user in the ordered set where companyId = &#63; and defaultUser = &#63; and status = &#63;.
6667             *
6668             * @param companyId the company ID
6669             * @param defaultUser the default user
6670             * @param status the status
6671             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6672             * @return the first matching user
6673             * @throws NoSuchUserException if a matching user could not be found
6674             */
6675            @Override
6676            public User findByC_DU_S_First(long companyId, boolean defaultUser,
6677                    int status, OrderByComparator<User> orderByComparator)
6678                    throws NoSuchUserException {
6679                    User user = fetchByC_DU_S_First(companyId, defaultUser, status,
6680                                    orderByComparator);
6681    
6682                    if (user != null) {
6683                            return user;
6684                    }
6685    
6686                    StringBundler msg = new StringBundler(8);
6687    
6688                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6689    
6690                    msg.append("companyId=");
6691                    msg.append(companyId);
6692    
6693                    msg.append(", defaultUser=");
6694                    msg.append(defaultUser);
6695    
6696                    msg.append(", status=");
6697                    msg.append(status);
6698    
6699                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6700    
6701                    throw new NoSuchUserException(msg.toString());
6702            }
6703    
6704            /**
6705             * Returns the first user in the ordered set where companyId = &#63; and defaultUser = &#63; and status = &#63;.
6706             *
6707             * @param companyId the company ID
6708             * @param defaultUser the default user
6709             * @param status the status
6710             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6711             * @return the first matching user, or <code>null</code> if a matching user could not be found
6712             */
6713            @Override
6714            public User fetchByC_DU_S_First(long companyId, boolean defaultUser,
6715                    int status, OrderByComparator<User> orderByComparator) {
6716                    List<User> list = findByC_DU_S(companyId, defaultUser, status, 0, 1,
6717                                    orderByComparator);
6718    
6719                    if (!list.isEmpty()) {
6720                            return list.get(0);
6721                    }
6722    
6723                    return null;
6724            }
6725    
6726            /**
6727             * Returns the last user in the ordered set where companyId = &#63; and defaultUser = &#63; and status = &#63;.
6728             *
6729             * @param companyId the company ID
6730             * @param defaultUser the default user
6731             * @param status the status
6732             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6733             * @return the last matching user
6734             * @throws NoSuchUserException if a matching user could not be found
6735             */
6736            @Override
6737            public User findByC_DU_S_Last(long companyId, boolean defaultUser,
6738                    int status, OrderByComparator<User> orderByComparator)
6739                    throws NoSuchUserException {
6740                    User user = fetchByC_DU_S_Last(companyId, defaultUser, status,
6741                                    orderByComparator);
6742    
6743                    if (user != null) {
6744                            return user;
6745                    }
6746    
6747                    StringBundler msg = new StringBundler(8);
6748    
6749                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6750    
6751                    msg.append("companyId=");
6752                    msg.append(companyId);
6753    
6754                    msg.append(", defaultUser=");
6755                    msg.append(defaultUser);
6756    
6757                    msg.append(", status=");
6758                    msg.append(status);
6759    
6760                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6761    
6762                    throw new NoSuchUserException(msg.toString());
6763            }
6764    
6765            /**
6766             * Returns the last user in the ordered set where companyId = &#63; and defaultUser = &#63; and status = &#63;.
6767             *
6768             * @param companyId the company ID
6769             * @param defaultUser the default user
6770             * @param status the status
6771             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6772             * @return the last matching user, or <code>null</code> if a matching user could not be found
6773             */
6774            @Override
6775            public User fetchByC_DU_S_Last(long companyId, boolean defaultUser,
6776                    int status, OrderByComparator<User> orderByComparator) {
6777                    int count = countByC_DU_S(companyId, defaultUser, status);
6778    
6779                    if (count == 0) {
6780                            return null;
6781                    }
6782    
6783                    List<User> list = findByC_DU_S(companyId, defaultUser, status,
6784                                    count - 1, count, orderByComparator);
6785    
6786                    if (!list.isEmpty()) {
6787                            return list.get(0);
6788                    }
6789    
6790                    return null;
6791            }
6792    
6793            /**
6794             * Returns the users before and after the current user in the ordered set where companyId = &#63; and defaultUser = &#63; and status = &#63;.
6795             *
6796             * @param userId the primary key of the current user
6797             * @param companyId the company ID
6798             * @param defaultUser the default user
6799             * @param status the status
6800             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6801             * @return the previous, current, and next user
6802             * @throws NoSuchUserException if a user with the primary key could not be found
6803             */
6804            @Override
6805            public User[] findByC_DU_S_PrevAndNext(long userId, long companyId,
6806                    boolean defaultUser, int status,
6807                    OrderByComparator<User> orderByComparator) throws NoSuchUserException {
6808                    User user = findByPrimaryKey(userId);
6809    
6810                    Session session = null;
6811    
6812                    try {
6813                            session = openSession();
6814    
6815                            User[] array = new UserImpl[3];
6816    
6817                            array[0] = getByC_DU_S_PrevAndNext(session, user, companyId,
6818                                            defaultUser, status, orderByComparator, true);
6819    
6820                            array[1] = user;
6821    
6822                            array[2] = getByC_DU_S_PrevAndNext(session, user, companyId,
6823                                            defaultUser, status, orderByComparator, false);
6824    
6825                            return array;
6826                    }
6827                    catch (Exception e) {
6828                            throw processException(e);
6829                    }
6830                    finally {
6831                            closeSession(session);
6832                    }
6833            }
6834    
6835            protected User getByC_DU_S_PrevAndNext(Session session, User user,
6836                    long companyId, boolean defaultUser, int status,
6837                    OrderByComparator<User> orderByComparator, boolean previous) {
6838                    StringBundler query = null;
6839    
6840                    if (orderByComparator != null) {
6841                            query = new StringBundler(6 +
6842                                            (orderByComparator.getOrderByFields().length * 6));
6843                    }
6844                    else {
6845                            query = new StringBundler(3);
6846                    }
6847    
6848                    query.append(_SQL_SELECT_USER_WHERE);
6849    
6850                    query.append(_FINDER_COLUMN_C_DU_S_COMPANYID_2);
6851    
6852                    query.append(_FINDER_COLUMN_C_DU_S_DEFAULTUSER_2);
6853    
6854                    query.append(_FINDER_COLUMN_C_DU_S_STATUS_2);
6855    
6856                    if (orderByComparator != null) {
6857                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6858    
6859                            if (orderByConditionFields.length > 0) {
6860                                    query.append(WHERE_AND);
6861                            }
6862    
6863                            for (int i = 0; i < orderByConditionFields.length; i++) {
6864                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6865                                    query.append(orderByConditionFields[i]);
6866    
6867                                    if ((i + 1) < orderByConditionFields.length) {
6868                                            if (orderByComparator.isAscending() ^ previous) {
6869                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6870                                            }
6871                                            else {
6872                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6873                                            }
6874                                    }
6875                                    else {
6876                                            if (orderByComparator.isAscending() ^ previous) {
6877                                                    query.append(WHERE_GREATER_THAN);
6878                                            }
6879                                            else {
6880                                                    query.append(WHERE_LESSER_THAN);
6881                                            }
6882                                    }
6883                            }
6884    
6885                            query.append(ORDER_BY_CLAUSE);
6886    
6887                            String[] orderByFields = orderByComparator.getOrderByFields();
6888    
6889                            for (int i = 0; i < orderByFields.length; i++) {
6890                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6891                                    query.append(orderByFields[i]);
6892    
6893                                    if ((i + 1) < orderByFields.length) {
6894                                            if (orderByComparator.isAscending() ^ previous) {
6895                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6896                                            }
6897                                            else {
6898                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6899                                            }
6900                                    }
6901                                    else {
6902                                            if (orderByComparator.isAscending() ^ previous) {
6903                                                    query.append(ORDER_BY_ASC);
6904                                            }
6905                                            else {
6906                                                    query.append(ORDER_BY_DESC);
6907                                            }
6908                                    }
6909                            }
6910                    }
6911                    else {
6912                            query.append(UserModelImpl.ORDER_BY_JPQL);
6913                    }
6914    
6915                    String sql = query.toString();
6916    
6917                    Query q = session.createQuery(sql);
6918    
6919                    q.setFirstResult(0);
6920                    q.setMaxResults(2);
6921    
6922                    QueryPos qPos = QueryPos.getInstance(q);
6923    
6924                    qPos.add(companyId);
6925    
6926                    qPos.add(defaultUser);
6927    
6928                    qPos.add(status);
6929    
6930                    if (orderByComparator != null) {
6931                            Object[] values = orderByComparator.getOrderByConditionValues(user);
6932    
6933                            for (Object value : values) {
6934                                    qPos.add(value);
6935                            }
6936                    }
6937    
6938                    List<User> list = q.list();
6939    
6940                    if (list.size() == 2) {
6941                            return list.get(1);
6942                    }
6943                    else {
6944                            return null;
6945                    }
6946            }
6947    
6948            /**
6949             * Removes all the users where companyId = &#63; and defaultUser = &#63; and status = &#63; from the database.
6950             *
6951             * @param companyId the company ID
6952             * @param defaultUser the default user
6953             * @param status the status
6954             */
6955            @Override
6956            public void removeByC_DU_S(long companyId, boolean defaultUser, int status) {
6957                    for (User user : findByC_DU_S(companyId, defaultUser, status,
6958                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6959                            remove(user);
6960                    }
6961            }
6962    
6963            /**
6964             * Returns the number of users where companyId = &#63; and defaultUser = &#63; and status = &#63;.
6965             *
6966             * @param companyId the company ID
6967             * @param defaultUser the default user
6968             * @param status the status
6969             * @return the number of matching users
6970             */
6971            @Override
6972            public int countByC_DU_S(long companyId, boolean defaultUser, int status) {
6973                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_DU_S;
6974    
6975                    Object[] finderArgs = new Object[] { companyId, defaultUser, status };
6976    
6977                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
6978    
6979                    if (count == null) {
6980                            StringBundler query = new StringBundler(4);
6981    
6982                            query.append(_SQL_COUNT_USER_WHERE);
6983    
6984                            query.append(_FINDER_COLUMN_C_DU_S_COMPANYID_2);
6985    
6986                            query.append(_FINDER_COLUMN_C_DU_S_DEFAULTUSER_2);
6987    
6988                            query.append(_FINDER_COLUMN_C_DU_S_STATUS_2);
6989    
6990                            String sql = query.toString();
6991    
6992                            Session session = null;
6993    
6994                            try {
6995                                    session = openSession();
6996    
6997                                    Query q = session.createQuery(sql);
6998    
6999                                    QueryPos qPos = QueryPos.getInstance(q);
7000    
7001                                    qPos.add(companyId);
7002    
7003                                    qPos.add(defaultUser);
7004    
7005                                    qPos.add(status);
7006    
7007                                    count = (Long)q.uniqueResult();
7008    
7009                                    finderCache.putResult(finderPath, finderArgs, count);
7010                            }
7011                            catch (Exception e) {
7012                                    finderCache.removeResult(finderPath, finderArgs);
7013    
7014                                    throw processException(e);
7015                            }
7016                            finally {
7017                                    closeSession(session);
7018                            }
7019                    }
7020    
7021                    return count.intValue();
7022            }
7023    
7024            private static final String _FINDER_COLUMN_C_DU_S_COMPANYID_2 = "user.companyId = ? AND ";
7025            private static final String _FINDER_COLUMN_C_DU_S_DEFAULTUSER_2 = "user.defaultUser = ? AND ";
7026            private static final String _FINDER_COLUMN_C_DU_S_STATUS_2 = "user.status = ?";
7027    
7028            public UserPersistenceImpl() {
7029                    setModelClass(User.class);
7030            }
7031    
7032            /**
7033             * Caches the user in the entity cache if it is enabled.
7034             *
7035             * @param user the user
7036             */
7037            @Override
7038            public void cacheResult(User user) {
7039                    entityCache.putResult(UserModelImpl.ENTITY_CACHE_ENABLED,
7040                            UserImpl.class, user.getPrimaryKey(), user);
7041    
7042                    finderCache.putResult(FINDER_PATH_FETCH_BY_CONTACTID,
7043                            new Object[] { user.getContactId() }, user);
7044    
7045                    finderCache.putResult(FINDER_PATH_FETCH_BY_PORTRAITID,
7046                            new Object[] { user.getPortraitId() }, user);
7047    
7048                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_U,
7049                            new Object[] { user.getCompanyId(), user.getUserId() }, user);
7050    
7051                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_DU,
7052                            new Object[] { user.getCompanyId(), user.getDefaultUser() }, user);
7053    
7054                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_SN,
7055                            new Object[] { user.getCompanyId(), user.getScreenName() }, user);
7056    
7057                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_EA,
7058                            new Object[] { user.getCompanyId(), user.getEmailAddress() }, user);
7059    
7060                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_FID,
7061                            new Object[] { user.getCompanyId(), user.getFacebookId() }, user);
7062    
7063                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_O,
7064                            new Object[] { user.getCompanyId(), user.getOpenId() }, user);
7065    
7066                    user.resetOriginalValues();
7067            }
7068    
7069            /**
7070             * Caches the users in the entity cache if it is enabled.
7071             *
7072             * @param users the users
7073             */
7074            @Override
7075            public void cacheResult(List<User> users) {
7076                    for (User user : users) {
7077                            if (entityCache.getResult(UserModelImpl.ENTITY_CACHE_ENABLED,
7078                                                    UserImpl.class, user.getPrimaryKey()) == null) {
7079                                    cacheResult(user);
7080                            }
7081                            else {
7082                                    user.resetOriginalValues();
7083                            }
7084                    }
7085            }
7086    
7087            /**
7088             * Clears the cache for all users.
7089             *
7090             * <p>
7091             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
7092             * </p>
7093             */
7094            @Override
7095            public void clearCache() {
7096                    entityCache.clearCache(UserImpl.class);
7097    
7098                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
7099                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7100                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7101            }
7102    
7103            /**
7104             * Clears the cache for the user.
7105             *
7106             * <p>
7107             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
7108             * </p>
7109             */
7110            @Override
7111            public void clearCache(User user) {
7112                    entityCache.removeResult(UserModelImpl.ENTITY_CACHE_ENABLED,
7113                            UserImpl.class, user.getPrimaryKey());
7114    
7115                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7116                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7117    
7118                    clearUniqueFindersCache((UserModelImpl)user);
7119            }
7120    
7121            @Override
7122            public void clearCache(List<User> users) {
7123                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7124                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7125    
7126                    for (User user : users) {
7127                            entityCache.removeResult(UserModelImpl.ENTITY_CACHE_ENABLED,
7128                                    UserImpl.class, user.getPrimaryKey());
7129    
7130                            clearUniqueFindersCache((UserModelImpl)user);
7131                    }
7132            }
7133    
7134            protected void cacheUniqueFindersCache(UserModelImpl userModelImpl,
7135                    boolean isNew) {
7136                    if (isNew) {
7137                            Object[] args = new Object[] { userModelImpl.getContactId() };
7138    
7139                            finderCache.putResult(FINDER_PATH_COUNT_BY_CONTACTID, args,
7140                                    Long.valueOf(1));
7141                            finderCache.putResult(FINDER_PATH_FETCH_BY_CONTACTID, args,
7142                                    userModelImpl);
7143    
7144                            args = new Object[] { userModelImpl.getPortraitId() };
7145    
7146                            finderCache.putResult(FINDER_PATH_COUNT_BY_PORTRAITID, args,
7147                                    Long.valueOf(1));
7148                            finderCache.putResult(FINDER_PATH_FETCH_BY_PORTRAITID, args,
7149                                    userModelImpl);
7150    
7151                            args = new Object[] {
7152                                            userModelImpl.getCompanyId(), userModelImpl.getUserId()
7153                                    };
7154    
7155                            finderCache.putResult(FINDER_PATH_COUNT_BY_C_U, args,
7156                                    Long.valueOf(1));
7157                            finderCache.putResult(FINDER_PATH_FETCH_BY_C_U, args, userModelImpl);
7158    
7159                            args = new Object[] {
7160                                            userModelImpl.getCompanyId(), userModelImpl.getDefaultUser()
7161                                    };
7162    
7163                            finderCache.putResult(FINDER_PATH_COUNT_BY_C_DU, args,
7164                                    Long.valueOf(1));
7165                            finderCache.putResult(FINDER_PATH_FETCH_BY_C_DU, args, userModelImpl);
7166    
7167                            args = new Object[] {
7168                                            userModelImpl.getCompanyId(), userModelImpl.getScreenName()
7169                                    };
7170    
7171                            finderCache.putResult(FINDER_PATH_COUNT_BY_C_SN, args,
7172                                    Long.valueOf(1));
7173                            finderCache.putResult(FINDER_PATH_FETCH_BY_C_SN, args, userModelImpl);
7174    
7175                            args = new Object[] {
7176                                            userModelImpl.getCompanyId(),
7177                                            userModelImpl.getEmailAddress()
7178                                    };
7179    
7180                            finderCache.putResult(FINDER_PATH_COUNT_BY_C_EA, args,
7181                                    Long.valueOf(1));
7182                            finderCache.putResult(FINDER_PATH_FETCH_BY_C_EA, args, userModelImpl);
7183    
7184                            args = new Object[] {
7185                                            userModelImpl.getCompanyId(), userModelImpl.getFacebookId()
7186                                    };
7187    
7188                            finderCache.putResult(FINDER_PATH_COUNT_BY_C_FID, args,
7189                                    Long.valueOf(1));
7190                            finderCache.putResult(FINDER_PATH_FETCH_BY_C_FID, args,
7191                                    userModelImpl);
7192    
7193                            args = new Object[] {
7194                                            userModelImpl.getCompanyId(), userModelImpl.getOpenId()
7195                                    };
7196    
7197                            finderCache.putResult(FINDER_PATH_COUNT_BY_C_O, args,
7198                                    Long.valueOf(1));
7199                            finderCache.putResult(FINDER_PATH_FETCH_BY_C_O, args, userModelImpl);
7200                    }
7201                    else {
7202                            if ((userModelImpl.getColumnBitmask() &
7203                                            FINDER_PATH_FETCH_BY_CONTACTID.getColumnBitmask()) != 0) {
7204                                    Object[] args = new Object[] { userModelImpl.getContactId() };
7205    
7206                                    finderCache.putResult(FINDER_PATH_COUNT_BY_CONTACTID, args,
7207                                            Long.valueOf(1));
7208                                    finderCache.putResult(FINDER_PATH_FETCH_BY_CONTACTID, args,
7209                                            userModelImpl);
7210                            }
7211    
7212                            if ((userModelImpl.getColumnBitmask() &
7213                                            FINDER_PATH_FETCH_BY_PORTRAITID.getColumnBitmask()) != 0) {
7214                                    Object[] args = new Object[] { userModelImpl.getPortraitId() };
7215    
7216                                    finderCache.putResult(FINDER_PATH_COUNT_BY_PORTRAITID, args,
7217                                            Long.valueOf(1));
7218                                    finderCache.putResult(FINDER_PATH_FETCH_BY_PORTRAITID, args,
7219                                            userModelImpl);
7220                            }
7221    
7222                            if ((userModelImpl.getColumnBitmask() &
7223                                            FINDER_PATH_FETCH_BY_C_U.getColumnBitmask()) != 0) {
7224                                    Object[] args = new Object[] {
7225                                                    userModelImpl.getCompanyId(), userModelImpl.getUserId()
7226                                            };
7227    
7228                                    finderCache.putResult(FINDER_PATH_COUNT_BY_C_U, args,
7229                                            Long.valueOf(1));
7230                                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_U, args,
7231                                            userModelImpl);
7232                            }
7233    
7234                            if ((userModelImpl.getColumnBitmask() &
7235                                            FINDER_PATH_FETCH_BY_C_DU.getColumnBitmask()) != 0) {
7236                                    Object[] args = new Object[] {
7237                                                    userModelImpl.getCompanyId(),
7238                                                    userModelImpl.getDefaultUser()
7239                                            };
7240    
7241                                    finderCache.putResult(FINDER_PATH_COUNT_BY_C_DU, args,
7242                                            Long.valueOf(1));
7243                                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_DU, args,
7244                                            userModelImpl);
7245                            }
7246    
7247                            if ((userModelImpl.getColumnBitmask() &
7248                                            FINDER_PATH_FETCH_BY_C_SN.getColumnBitmask()) != 0) {
7249                                    Object[] args = new Object[] {
7250                                                    userModelImpl.getCompanyId(),
7251                                                    userModelImpl.getScreenName()
7252                                            };
7253    
7254                                    finderCache.putResult(FINDER_PATH_COUNT_BY_C_SN, args,
7255                                            Long.valueOf(1));
7256                                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_SN, args,
7257                                            userModelImpl);
7258                            }
7259    
7260                            if ((userModelImpl.getColumnBitmask() &
7261                                            FINDER_PATH_FETCH_BY_C_EA.getColumnBitmask()) != 0) {
7262                                    Object[] args = new Object[] {
7263                                                    userModelImpl.getCompanyId(),
7264                                                    userModelImpl.getEmailAddress()
7265                                            };
7266    
7267                                    finderCache.putResult(FINDER_PATH_COUNT_BY_C_EA, args,
7268                                            Long.valueOf(1));
7269                                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_EA, args,
7270                                            userModelImpl);
7271                            }
7272    
7273                            if ((userModelImpl.getColumnBitmask() &
7274                                            FINDER_PATH_FETCH_BY_C_FID.getColumnBitmask()) != 0) {
7275                                    Object[] args = new Object[] {
7276                                                    userModelImpl.getCompanyId(),
7277                                                    userModelImpl.getFacebookId()
7278                                            };
7279    
7280                                    finderCache.putResult(FINDER_PATH_COUNT_BY_C_FID, args,
7281                                            Long.valueOf(1));
7282                                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_FID, args,
7283                                            userModelImpl);
7284                            }
7285    
7286                            if ((userModelImpl.getColumnBitmask() &
7287                                            FINDER_PATH_FETCH_BY_C_O.getColumnBitmask()) != 0) {
7288                                    Object[] args = new Object[] {
7289                                                    userModelImpl.getCompanyId(), userModelImpl.getOpenId()
7290                                            };
7291    
7292                                    finderCache.putResult(FINDER_PATH_COUNT_BY_C_O, args,
7293                                            Long.valueOf(1));
7294                                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_O, args,
7295                                            userModelImpl);
7296                            }
7297                    }
7298            }
7299    
7300            protected void clearUniqueFindersCache(UserModelImpl userModelImpl) {
7301                    Object[] args = new Object[] { userModelImpl.getContactId() };
7302    
7303                    finderCache.removeResult(FINDER_PATH_COUNT_BY_CONTACTID, args);
7304                    finderCache.removeResult(FINDER_PATH_FETCH_BY_CONTACTID, args);
7305    
7306                    if ((userModelImpl.getColumnBitmask() &
7307                                    FINDER_PATH_FETCH_BY_CONTACTID.getColumnBitmask()) != 0) {
7308                            args = new Object[] { userModelImpl.getOriginalContactId() };
7309    
7310                            finderCache.removeResult(FINDER_PATH_COUNT_BY_CONTACTID, args);
7311                            finderCache.removeResult(FINDER_PATH_FETCH_BY_CONTACTID, args);
7312                    }
7313    
7314                    args = new Object[] { userModelImpl.getPortraitId() };
7315    
7316                    finderCache.removeResult(FINDER_PATH_COUNT_BY_PORTRAITID, args);
7317                    finderCache.removeResult(FINDER_PATH_FETCH_BY_PORTRAITID, args);
7318    
7319                    if ((userModelImpl.getColumnBitmask() &
7320                                    FINDER_PATH_FETCH_BY_PORTRAITID.getColumnBitmask()) != 0) {
7321                            args = new Object[] { userModelImpl.getOriginalPortraitId() };
7322    
7323                            finderCache.removeResult(FINDER_PATH_COUNT_BY_PORTRAITID, args);
7324                            finderCache.removeResult(FINDER_PATH_FETCH_BY_PORTRAITID, args);
7325                    }
7326    
7327                    args = new Object[] {
7328                                    userModelImpl.getCompanyId(), userModelImpl.getUserId()
7329                            };
7330    
7331                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_U, args);
7332                    finderCache.removeResult(FINDER_PATH_FETCH_BY_C_U, args);
7333    
7334                    if ((userModelImpl.getColumnBitmask() &
7335                                    FINDER_PATH_FETCH_BY_C_U.getColumnBitmask()) != 0) {
7336                            args = new Object[] {
7337                                            userModelImpl.getOriginalCompanyId(),
7338                                            userModelImpl.getOriginalUserId()
7339                                    };
7340    
7341                            finderCache.removeResult(FINDER_PATH_COUNT_BY_C_U, args);
7342                            finderCache.removeResult(FINDER_PATH_FETCH_BY_C_U, args);
7343                    }
7344    
7345                    args = new Object[] {
7346                                    userModelImpl.getCompanyId(), userModelImpl.getDefaultUser()
7347                            };
7348    
7349                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_DU, args);
7350                    finderCache.removeResult(FINDER_PATH_FETCH_BY_C_DU, args);
7351    
7352                    if ((userModelImpl.getColumnBitmask() &
7353                                    FINDER_PATH_FETCH_BY_C_DU.getColumnBitmask()) != 0) {
7354                            args = new Object[] {
7355                                            userModelImpl.getOriginalCompanyId(),
7356                                            userModelImpl.getOriginalDefaultUser()
7357                                    };
7358    
7359                            finderCache.removeResult(FINDER_PATH_COUNT_BY_C_DU, args);
7360                            finderCache.removeResult(FINDER_PATH_FETCH_BY_C_DU, args);
7361                    }
7362    
7363                    args = new Object[] {
7364                                    userModelImpl.getCompanyId(), userModelImpl.getScreenName()
7365                            };
7366    
7367                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_SN, args);
7368                    finderCache.removeResult(FINDER_PATH_FETCH_BY_C_SN, args);
7369    
7370                    if ((userModelImpl.getColumnBitmask() &
7371                                    FINDER_PATH_FETCH_BY_C_SN.getColumnBitmask()) != 0) {
7372                            args = new Object[] {
7373                                            userModelImpl.getOriginalCompanyId(),
7374                                            userModelImpl.getOriginalScreenName()
7375                                    };
7376    
7377                            finderCache.removeResult(FINDER_PATH_COUNT_BY_C_SN, args);
7378                            finderCache.removeResult(FINDER_PATH_FETCH_BY_C_SN, args);
7379                    }
7380    
7381                    args = new Object[] {
7382                                    userModelImpl.getCompanyId(), userModelImpl.getEmailAddress()
7383                            };
7384    
7385                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_EA, args);
7386                    finderCache.removeResult(FINDER_PATH_FETCH_BY_C_EA, args);
7387    
7388                    if ((userModelImpl.getColumnBitmask() &
7389                                    FINDER_PATH_FETCH_BY_C_EA.getColumnBitmask()) != 0) {
7390                            args = new Object[] {
7391                                            userModelImpl.getOriginalCompanyId(),
7392                                            userModelImpl.getOriginalEmailAddress()
7393                                    };
7394    
7395                            finderCache.removeResult(FINDER_PATH_COUNT_BY_C_EA, args);
7396                            finderCache.removeResult(FINDER_PATH_FETCH_BY_C_EA, args);
7397                    }
7398    
7399                    args = new Object[] {
7400                                    userModelImpl.getCompanyId(), userModelImpl.getFacebookId()
7401                            };
7402    
7403                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_FID, args);
7404                    finderCache.removeResult(FINDER_PATH_FETCH_BY_C_FID, args);
7405    
7406                    if ((userModelImpl.getColumnBitmask() &
7407                                    FINDER_PATH_FETCH_BY_C_FID.getColumnBitmask()) != 0) {
7408                            args = new Object[] {
7409                                            userModelImpl.getOriginalCompanyId(),
7410                                            userModelImpl.getOriginalFacebookId()
7411                                    };
7412    
7413                            finderCache.removeResult(FINDER_PATH_COUNT_BY_C_FID, args);
7414                            finderCache.removeResult(FINDER_PATH_FETCH_BY_C_FID, args);
7415                    }
7416    
7417                    args = new Object[] {
7418                                    userModelImpl.getCompanyId(), userModelImpl.getOpenId()
7419                            };
7420    
7421                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_O, args);
7422                    finderCache.removeResult(FINDER_PATH_FETCH_BY_C_O, args);
7423    
7424                    if ((userModelImpl.getColumnBitmask() &
7425                                    FINDER_PATH_FETCH_BY_C_O.getColumnBitmask()) != 0) {
7426                            args = new Object[] {
7427                                            userModelImpl.getOriginalCompanyId(),
7428                                            userModelImpl.getOriginalOpenId()
7429                                    };
7430    
7431                            finderCache.removeResult(FINDER_PATH_COUNT_BY_C_O, args);
7432                            finderCache.removeResult(FINDER_PATH_FETCH_BY_C_O, args);
7433                    }
7434            }
7435    
7436            /**
7437             * Creates a new user with the primary key. Does not add the user to the database.
7438             *
7439             * @param userId the primary key for the new user
7440             * @return the new user
7441             */
7442            @Override
7443            public User create(long userId) {
7444                    User user = new UserImpl();
7445    
7446                    user.setNew(true);
7447                    user.setPrimaryKey(userId);
7448    
7449                    String uuid = PortalUUIDUtil.generate();
7450    
7451                    user.setUuid(uuid);
7452    
7453                    return user;
7454            }
7455    
7456            /**
7457             * Removes the user with the primary key from the database. Also notifies the appropriate model listeners.
7458             *
7459             * @param userId the primary key of the user
7460             * @return the user that was removed
7461             * @throws NoSuchUserException if a user with the primary key could not be found
7462             */
7463            @Override
7464            public User remove(long userId) throws NoSuchUserException {
7465                    return remove((Serializable)userId);
7466            }
7467    
7468            /**
7469             * Removes the user with the primary key from the database. Also notifies the appropriate model listeners.
7470             *
7471             * @param primaryKey the primary key of the user
7472             * @return the user that was removed
7473             * @throws NoSuchUserException if a user with the primary key could not be found
7474             */
7475            @Override
7476            public User remove(Serializable primaryKey) throws NoSuchUserException {
7477                    Session session = null;
7478    
7479                    try {
7480                            session = openSession();
7481    
7482                            User user = (User)session.get(UserImpl.class, primaryKey);
7483    
7484                            if (user == null) {
7485                                    if (_log.isWarnEnabled()) {
7486                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
7487                                    }
7488    
7489                                    throw new NoSuchUserException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
7490                                            primaryKey);
7491                            }
7492    
7493                            return remove(user);
7494                    }
7495                    catch (NoSuchUserException nsee) {
7496                            throw nsee;
7497                    }
7498                    catch (Exception e) {
7499                            throw processException(e);
7500                    }
7501                    finally {
7502                            closeSession(session);
7503                    }
7504            }
7505    
7506            @Override
7507            protected User removeImpl(User user) {
7508                    user = toUnwrappedModel(user);
7509    
7510                    userToGroupTableMapper.deleteLeftPrimaryKeyTableMappings(0,
7511                            user.getPrimaryKey());
7512    
7513                    userToOrganizationTableMapper.deleteLeftPrimaryKeyTableMappings(0,
7514                            user.getPrimaryKey());
7515    
7516                    userToRoleTableMapper.deleteLeftPrimaryKeyTableMappings(0,
7517                            user.getPrimaryKey());
7518    
7519                    userToTeamTableMapper.deleteLeftPrimaryKeyTableMappings(0,
7520                            user.getPrimaryKey());
7521    
7522                    userToUserGroupTableMapper.deleteLeftPrimaryKeyTableMappings(0,
7523                            user.getPrimaryKey());
7524    
7525                    Session session = null;
7526    
7527                    try {
7528                            session = openSession();
7529    
7530                            if (!session.contains(user)) {
7531                                    user = (User)session.get(UserImpl.class, user.getPrimaryKeyObj());
7532                            }
7533    
7534                            if (user != null) {
7535                                    session.delete(user);
7536                            }
7537                    }
7538                    catch (Exception e) {
7539                            throw processException(e);
7540                    }
7541                    finally {
7542                            closeSession(session);
7543                    }
7544    
7545                    if (user != null) {
7546                            clearCache(user);
7547                    }
7548    
7549                    return user;
7550            }
7551    
7552            @Override
7553            public User updateImpl(User user) {
7554                    user = toUnwrappedModel(user);
7555    
7556                    boolean isNew = user.isNew();
7557    
7558                    UserModelImpl userModelImpl = (UserModelImpl)user;
7559    
7560                    if (Validator.isNull(user.getUuid())) {
7561                            String uuid = PortalUUIDUtil.generate();
7562    
7563                            user.setUuid(uuid);
7564                    }
7565    
7566                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
7567    
7568                    Date now = new Date();
7569    
7570                    if (isNew && (user.getCreateDate() == null)) {
7571                            if (serviceContext == null) {
7572                                    user.setCreateDate(now);
7573                            }
7574                            else {
7575                                    user.setCreateDate(serviceContext.getCreateDate(now));
7576                            }
7577                    }
7578    
7579                    if (!userModelImpl.hasSetModifiedDate()) {
7580                            if (serviceContext == null) {
7581                                    user.setModifiedDate(now);
7582                            }
7583                            else {
7584                                    user.setModifiedDate(serviceContext.getModifiedDate(now));
7585                            }
7586                    }
7587    
7588                    Session session = null;
7589    
7590                    try {
7591                            session = openSession();
7592    
7593                            if (user.isNew()) {
7594                                    session.save(user);
7595    
7596                                    user.setNew(false);
7597                            }
7598                            else {
7599                                    user = (User)session.merge(user);
7600                            }
7601                    }
7602                    catch (Exception e) {
7603                            throw processException(e);
7604                    }
7605                    finally {
7606                            closeSession(session);
7607                    }
7608    
7609                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7610    
7611                    if (isNew || !UserModelImpl.COLUMN_BITMASK_ENABLED) {
7612                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7613                    }
7614    
7615                    else {
7616                            if ((userModelImpl.getColumnBitmask() &
7617                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
7618                                    Object[] args = new Object[] { userModelImpl.getOriginalUuid() };
7619    
7620                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
7621                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
7622                                            args);
7623    
7624                                    args = new Object[] { userModelImpl.getUuid() };
7625    
7626                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
7627                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
7628                                            args);
7629                            }
7630    
7631                            if ((userModelImpl.getColumnBitmask() &
7632                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
7633                                    Object[] args = new Object[] {
7634                                                    userModelImpl.getOriginalUuid(),
7635                                                    userModelImpl.getOriginalCompanyId()
7636                                            };
7637    
7638                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
7639                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
7640                                            args);
7641    
7642                                    args = new Object[] {
7643                                                    userModelImpl.getUuid(), userModelImpl.getCompanyId()
7644                                            };
7645    
7646                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
7647                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
7648                                            args);
7649                            }
7650    
7651                            if ((userModelImpl.getColumnBitmask() &
7652                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
7653                                    Object[] args = new Object[] {
7654                                                    userModelImpl.getOriginalCompanyId()
7655                                            };
7656    
7657                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
7658                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
7659                                            args);
7660    
7661                                    args = new Object[] { userModelImpl.getCompanyId() };
7662    
7663                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
7664                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
7665                                            args);
7666                            }
7667    
7668                            if ((userModelImpl.getColumnBitmask() &
7669                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_EMAILADDRESS.getColumnBitmask()) != 0) {
7670                                    Object[] args = new Object[] {
7671                                                    userModelImpl.getOriginalEmailAddress()
7672                                            };
7673    
7674                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_EMAILADDRESS, args);
7675                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_EMAILADDRESS,
7676                                            args);
7677    
7678                                    args = new Object[] { userModelImpl.getEmailAddress() };
7679    
7680                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_EMAILADDRESS, args);
7681                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_EMAILADDRESS,
7682                                            args);
7683                            }
7684    
7685                            if ((userModelImpl.getColumnBitmask() &
7686                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_CD.getColumnBitmask()) != 0) {
7687                                    Object[] args = new Object[] {
7688                                                    userModelImpl.getOriginalCompanyId(),
7689                                                    userModelImpl.getOriginalCreateDate()
7690                                            };
7691    
7692                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_CD, args);
7693                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_CD,
7694                                            args);
7695    
7696                                    args = new Object[] {
7697                                                    userModelImpl.getCompanyId(),
7698                                                    userModelImpl.getCreateDate()
7699                                            };
7700    
7701                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_CD, args);
7702                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_CD,
7703                                            args);
7704                            }
7705    
7706                            if ((userModelImpl.getColumnBitmask() &
7707                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_MD.getColumnBitmask()) != 0) {
7708                                    Object[] args = new Object[] {
7709                                                    userModelImpl.getOriginalCompanyId(),
7710                                                    userModelImpl.getOriginalModifiedDate()
7711                                            };
7712    
7713                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_MD, args);
7714                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_MD,
7715                                            args);
7716    
7717                                    args = new Object[] {
7718                                                    userModelImpl.getCompanyId(),
7719                                                    userModelImpl.getModifiedDate()
7720                                            };
7721    
7722                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_MD, args);
7723                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_MD,
7724                                            args);
7725                            }
7726    
7727                            if ((userModelImpl.getColumnBitmask() &
7728                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S.getColumnBitmask()) != 0) {
7729                                    Object[] args = new Object[] {
7730                                                    userModelImpl.getOriginalCompanyId(),
7731                                                    userModelImpl.getOriginalStatus()
7732                                            };
7733    
7734                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
7735                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
7736                                            args);
7737    
7738                                    args = new Object[] {
7739                                                    userModelImpl.getCompanyId(), userModelImpl.getStatus()
7740                                            };
7741    
7742                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
7743                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
7744                                            args);
7745                            }
7746    
7747                            if ((userModelImpl.getColumnBitmask() &
7748                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_CD_MD.getColumnBitmask()) != 0) {
7749                                    Object[] args = new Object[] {
7750                                                    userModelImpl.getOriginalCompanyId(),
7751                                                    userModelImpl.getOriginalCreateDate(),
7752                                                    userModelImpl.getOriginalModifiedDate()
7753                                            };
7754    
7755                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_CD_MD, args);
7756                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_CD_MD,
7757                                            args);
7758    
7759                                    args = new Object[] {
7760                                                    userModelImpl.getCompanyId(),
7761                                                    userModelImpl.getCreateDate(),
7762                                                    userModelImpl.getModifiedDate()
7763                                            };
7764    
7765                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_CD_MD, args);
7766                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_CD_MD,
7767                                            args);
7768                            }
7769    
7770                            if ((userModelImpl.getColumnBitmask() &
7771                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_DU_S.getColumnBitmask()) != 0) {
7772                                    Object[] args = new Object[] {
7773                                                    userModelImpl.getOriginalCompanyId(),
7774                                                    userModelImpl.getOriginalDefaultUser(),
7775                                                    userModelImpl.getOriginalStatus()
7776                                            };
7777    
7778                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_DU_S, args);
7779                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_DU_S,
7780                                            args);
7781    
7782                                    args = new Object[] {
7783                                                    userModelImpl.getCompanyId(),
7784                                                    userModelImpl.getDefaultUser(),
7785                                                    userModelImpl.getStatus()
7786                                            };
7787    
7788                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_DU_S, args);
7789                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_DU_S,
7790                                            args);
7791                            }
7792                    }
7793    
7794                    entityCache.putResult(UserModelImpl.ENTITY_CACHE_ENABLED,
7795                            UserImpl.class, user.getPrimaryKey(), user, false);
7796    
7797                    clearUniqueFindersCache(userModelImpl);
7798                    cacheUniqueFindersCache(userModelImpl, isNew);
7799    
7800                    user.resetOriginalValues();
7801    
7802                    return user;
7803            }
7804    
7805            protected User toUnwrappedModel(User user) {
7806                    if (user instanceof UserImpl) {
7807                            return user;
7808                    }
7809    
7810                    UserImpl userImpl = new UserImpl();
7811    
7812                    userImpl.setNew(user.isNew());
7813                    userImpl.setPrimaryKey(user.getPrimaryKey());
7814    
7815                    userImpl.setMvccVersion(user.getMvccVersion());
7816                    userImpl.setUuid(user.getUuid());
7817                    userImpl.setUserId(user.getUserId());
7818                    userImpl.setCompanyId(user.getCompanyId());
7819                    userImpl.setCreateDate(user.getCreateDate());
7820                    userImpl.setModifiedDate(user.getModifiedDate());
7821                    userImpl.setDefaultUser(user.isDefaultUser());
7822                    userImpl.setContactId(user.getContactId());
7823                    userImpl.setPassword(user.getPassword());
7824                    userImpl.setPasswordEncrypted(user.isPasswordEncrypted());
7825                    userImpl.setPasswordReset(user.isPasswordReset());
7826                    userImpl.setPasswordModifiedDate(user.getPasswordModifiedDate());
7827                    userImpl.setDigest(user.getDigest());
7828                    userImpl.setReminderQueryQuestion(user.getReminderQueryQuestion());
7829                    userImpl.setReminderQueryAnswer(user.getReminderQueryAnswer());
7830                    userImpl.setGraceLoginCount(user.getGraceLoginCount());
7831                    userImpl.setScreenName(user.getScreenName());
7832                    userImpl.setEmailAddress(user.getEmailAddress());
7833                    userImpl.setFacebookId(user.getFacebookId());
7834                    userImpl.setLdapServerId(user.getLdapServerId());
7835                    userImpl.setOpenId(user.getOpenId());
7836                    userImpl.setPortraitId(user.getPortraitId());
7837                    userImpl.setLanguageId(user.getLanguageId());
7838                    userImpl.setTimeZoneId(user.getTimeZoneId());
7839                    userImpl.setGreeting(user.getGreeting());
7840                    userImpl.setComments(user.getComments());
7841                    userImpl.setFirstName(user.getFirstName());
7842                    userImpl.setMiddleName(user.getMiddleName());
7843                    userImpl.setLastName(user.getLastName());
7844                    userImpl.setJobTitle(user.getJobTitle());
7845                    userImpl.setLoginDate(user.getLoginDate());
7846                    userImpl.setLoginIP(user.getLoginIP());
7847                    userImpl.setLastLoginDate(user.getLastLoginDate());
7848                    userImpl.setLastLoginIP(user.getLastLoginIP());
7849                    userImpl.setLastFailedLoginDate(user.getLastFailedLoginDate());
7850                    userImpl.setFailedLoginAttempts(user.getFailedLoginAttempts());
7851                    userImpl.setLockout(user.isLockout());
7852                    userImpl.setLockoutDate(user.getLockoutDate());
7853                    userImpl.setAgreedToTermsOfUse(user.isAgreedToTermsOfUse());
7854                    userImpl.setEmailAddressVerified(user.isEmailAddressVerified());
7855                    userImpl.setStatus(user.getStatus());
7856    
7857                    return userImpl;
7858            }
7859    
7860            /**
7861             * Returns the user with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
7862             *
7863             * @param primaryKey the primary key of the user
7864             * @return the user
7865             * @throws NoSuchUserException if a user with the primary key could not be found
7866             */
7867            @Override
7868            public User findByPrimaryKey(Serializable primaryKey)
7869                    throws NoSuchUserException {
7870                    User user = fetchByPrimaryKey(primaryKey);
7871    
7872                    if (user == null) {
7873                            if (_log.isWarnEnabled()) {
7874                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
7875                            }
7876    
7877                            throw new NoSuchUserException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
7878                                    primaryKey);
7879                    }
7880    
7881                    return user;
7882            }
7883    
7884            /**
7885             * Returns the user with the primary key or throws a {@link NoSuchUserException} if it could not be found.
7886             *
7887             * @param userId the primary key of the user
7888             * @return the user
7889             * @throws NoSuchUserException if a user with the primary key could not be found
7890             */
7891            @Override
7892            public User findByPrimaryKey(long userId) throws NoSuchUserException {
7893                    return findByPrimaryKey((Serializable)userId);
7894            }
7895    
7896            /**
7897             * Returns the user with the primary key or returns <code>null</code> if it could not be found.
7898             *
7899             * @param primaryKey the primary key of the user
7900             * @return the user, or <code>null</code> if a user with the primary key could not be found
7901             */
7902            @Override
7903            public User fetchByPrimaryKey(Serializable primaryKey) {
7904                    User user = (User)entityCache.getResult(UserModelImpl.ENTITY_CACHE_ENABLED,
7905                                    UserImpl.class, primaryKey);
7906    
7907                    if (user == _nullUser) {
7908                            return null;
7909                    }
7910    
7911                    if (user == null) {
7912                            Session session = null;
7913    
7914                            try {
7915                                    session = openSession();
7916    
7917                                    user = (User)session.get(UserImpl.class, primaryKey);
7918    
7919                                    if (user != null) {
7920                                            cacheResult(user);
7921                                    }
7922                                    else {
7923                                            entityCache.putResult(UserModelImpl.ENTITY_CACHE_ENABLED,
7924                                                    UserImpl.class, primaryKey, _nullUser);
7925                                    }
7926                            }
7927                            catch (Exception e) {
7928                                    entityCache.removeResult(UserModelImpl.ENTITY_CACHE_ENABLED,
7929                                            UserImpl.class, primaryKey);
7930    
7931                                    throw processException(e);
7932                            }
7933                            finally {
7934                                    closeSession(session);
7935                            }
7936                    }
7937    
7938                    return user;
7939            }
7940    
7941            /**
7942             * Returns the user with the primary key or returns <code>null</code> if it could not be found.
7943             *
7944             * @param userId the primary key of the user
7945             * @return the user, or <code>null</code> if a user with the primary key could not be found
7946             */
7947            @Override
7948            public User fetchByPrimaryKey(long userId) {
7949                    return fetchByPrimaryKey((Serializable)userId);
7950            }
7951    
7952            @Override
7953            public Map<Serializable, User> fetchByPrimaryKeys(
7954                    Set<Serializable> primaryKeys) {
7955                    if (primaryKeys.isEmpty()) {
7956                            return Collections.emptyMap();
7957                    }
7958    
7959                    Map<Serializable, User> map = new HashMap<Serializable, User>();
7960    
7961                    if (primaryKeys.size() == 1) {
7962                            Iterator<Serializable> iterator = primaryKeys.iterator();
7963    
7964                            Serializable primaryKey = iterator.next();
7965    
7966                            User user = fetchByPrimaryKey(primaryKey);
7967    
7968                            if (user != null) {
7969                                    map.put(primaryKey, user);
7970                            }
7971    
7972                            return map;
7973                    }
7974    
7975                    Set<Serializable> uncachedPrimaryKeys = null;
7976    
7977                    for (Serializable primaryKey : primaryKeys) {
7978                            User user = (User)entityCache.getResult(UserModelImpl.ENTITY_CACHE_ENABLED,
7979                                            UserImpl.class, primaryKey);
7980    
7981                            if (user == null) {
7982                                    if (uncachedPrimaryKeys == null) {
7983                                            uncachedPrimaryKeys = new HashSet<Serializable>();
7984                                    }
7985    
7986                                    uncachedPrimaryKeys.add(primaryKey);
7987                            }
7988                            else {
7989                                    map.put(primaryKey, user);
7990                            }
7991                    }
7992    
7993                    if (uncachedPrimaryKeys == null) {
7994                            return map;
7995                    }
7996    
7997                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
7998                                    1);
7999    
8000                    query.append(_SQL_SELECT_USER_WHERE_PKS_IN);
8001    
8002                    for (Serializable primaryKey : uncachedPrimaryKeys) {
8003                            query.append(String.valueOf(primaryKey));
8004    
8005                            query.append(StringPool.COMMA);
8006                    }
8007    
8008                    query.setIndex(query.index() - 1);
8009    
8010                    query.append(StringPool.CLOSE_PARENTHESIS);
8011    
8012                    String sql = query.toString();
8013    
8014                    Session session = null;
8015    
8016                    try {
8017                            session = openSession();
8018    
8019                            Query q = session.createQuery(sql);
8020    
8021                            for (User user : (List<User>)q.list()) {
8022                                    map.put(user.getPrimaryKeyObj(), user);
8023    
8024                                    cacheResult(user);
8025    
8026                                    uncachedPrimaryKeys.remove(user.getPrimaryKeyObj());
8027                            }
8028    
8029                            for (Serializable primaryKey : uncachedPrimaryKeys) {
8030                                    entityCache.putResult(UserModelImpl.ENTITY_CACHE_ENABLED,
8031                                            UserImpl.class, primaryKey, _nullUser);
8032                            }
8033                    }
8034                    catch (Exception e) {
8035                            throw processException(e);
8036                    }
8037                    finally {
8038                            closeSession(session);
8039                    }
8040    
8041                    return map;
8042            }
8043    
8044            /**
8045             * Returns all the users.
8046             *
8047             * @return the users
8048             */
8049            @Override
8050            public List<User> findAll() {
8051                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8052            }
8053    
8054            /**
8055             * Returns a range of all the users.
8056             *
8057             * <p>
8058             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
8059             * </p>
8060             *
8061             * @param start the lower bound of the range of users
8062             * @param end the upper bound of the range of users (not inclusive)
8063             * @return the range of users
8064             */
8065            @Override
8066            public List<User> findAll(int start, int end) {
8067                    return findAll(start, end, null);
8068            }
8069    
8070            /**
8071             * Returns an ordered range of all the users.
8072             *
8073             * <p>
8074             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
8075             * </p>
8076             *
8077             * @param start the lower bound of the range of users
8078             * @param end the upper bound of the range of users (not inclusive)
8079             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8080             * @return the ordered range of users
8081             */
8082            @Override
8083            public List<User> findAll(int start, int end,
8084                    OrderByComparator<User> orderByComparator) {
8085                    return findAll(start, end, orderByComparator, true);
8086            }
8087    
8088            /**
8089             * Returns an ordered range of all the users.
8090             *
8091             * <p>
8092             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
8093             * </p>
8094             *
8095             * @param start the lower bound of the range of users
8096             * @param end the upper bound of the range of users (not inclusive)
8097             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8098             * @param retrieveFromCache whether to retrieve from the finder cache
8099             * @return the ordered range of users
8100             */
8101            @Override
8102            public List<User> findAll(int start, int end,
8103                    OrderByComparator<User> orderByComparator, boolean retrieveFromCache) {
8104                    boolean pagination = true;
8105                    FinderPath finderPath = null;
8106                    Object[] finderArgs = null;
8107    
8108                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8109                                    (orderByComparator == null)) {
8110                            pagination = false;
8111                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
8112                            finderArgs = FINDER_ARGS_EMPTY;
8113                    }
8114                    else {
8115                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
8116                            finderArgs = new Object[] { start, end, orderByComparator };
8117                    }
8118    
8119                    List<User> list = null;
8120    
8121                    if (retrieveFromCache) {
8122                            list = (List<User>)finderCache.getResult(finderPath, finderArgs,
8123                                            this);
8124                    }
8125    
8126                    if (list == null) {
8127                            StringBundler query = null;
8128                            String sql = null;
8129    
8130                            if (orderByComparator != null) {
8131                                    query = new StringBundler(2 +
8132                                                    (orderByComparator.getOrderByFields().length * 3));
8133    
8134                                    query.append(_SQL_SELECT_USER);
8135    
8136                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8137                                            orderByComparator);
8138    
8139                                    sql = query.toString();
8140                            }
8141                            else {
8142                                    sql = _SQL_SELECT_USER;
8143    
8144                                    if (pagination) {
8145                                            sql = sql.concat(UserModelImpl.ORDER_BY_JPQL);
8146                                    }
8147                            }
8148    
8149                            Session session = null;
8150    
8151                            try {
8152                                    session = openSession();
8153    
8154                                    Query q = session.createQuery(sql);
8155    
8156                                    if (!pagination) {
8157                                            list = (List<User>)QueryUtil.list(q, getDialect(), start,
8158                                                            end, false);
8159    
8160                                            Collections.sort(list);
8161    
8162                                            list = Collections.unmodifiableList(list);
8163                                    }
8164                                    else {
8165                                            list = (List<User>)QueryUtil.list(q, getDialect(), start,
8166                                                            end);
8167                                    }
8168    
8169                                    cacheResult(list);
8170    
8171                                    finderCache.putResult(finderPath, finderArgs, list);
8172                            }
8173                            catch (Exception e) {
8174                                    finderCache.removeResult(finderPath, finderArgs);
8175    
8176                                    throw processException(e);
8177                            }
8178                            finally {
8179                                    closeSession(session);
8180                            }
8181                    }
8182    
8183                    return list;
8184            }
8185    
8186            /**
8187             * Removes all the users from the database.
8188             *
8189             */
8190            @Override
8191            public void removeAll() {
8192                    for (User user : findAll()) {
8193                            remove(user);
8194                    }
8195            }
8196    
8197            /**
8198             * Returns the number of users.
8199             *
8200             * @return the number of users
8201             */
8202            @Override
8203            public int countAll() {
8204                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
8205                                    FINDER_ARGS_EMPTY, this);
8206    
8207                    if (count == null) {
8208                            Session session = null;
8209    
8210                            try {
8211                                    session = openSession();
8212    
8213                                    Query q = session.createQuery(_SQL_COUNT_USER);
8214    
8215                                    count = (Long)q.uniqueResult();
8216    
8217                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
8218                                            count);
8219                            }
8220                            catch (Exception e) {
8221                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
8222                                            FINDER_ARGS_EMPTY);
8223    
8224                                    throw processException(e);
8225                            }
8226                            finally {
8227                                    closeSession(session);
8228                            }
8229                    }
8230    
8231                    return count.intValue();
8232            }
8233    
8234            /**
8235             * Returns the primaryKeys of groups associated with the user.
8236             *
8237             * @param pk the primary key of the user
8238             * @return long[] of the primaryKeys of groups associated with the user
8239             */
8240            @Override
8241            public long[] getGroupPrimaryKeys(long pk) {
8242                    long[] pks = userToGroupTableMapper.getRightPrimaryKeys(0, pk);
8243    
8244                    return pks.clone();
8245            }
8246    
8247            /**
8248             * Returns all the groups associated with the user.
8249             *
8250             * @param pk the primary key of the user
8251             * @return the groups associated with the user
8252             */
8253            @Override
8254            public List<com.liferay.portal.model.Group> getGroups(long pk) {
8255                    return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
8256            }
8257    
8258            /**
8259             * Returns a range of all the groups associated with the user.
8260             *
8261             * <p>
8262             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
8263             * </p>
8264             *
8265             * @param pk the primary key of the user
8266             * @param start the lower bound of the range of users
8267             * @param end the upper bound of the range of users (not inclusive)
8268             * @return the range of groups associated with the user
8269             */
8270            @Override
8271            public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
8272                    int end) {
8273                    return getGroups(pk, start, end, null);
8274            }
8275    
8276            /**
8277             * Returns an ordered range of all the groups associated with the user.
8278             *
8279             * <p>
8280             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
8281             * </p>
8282             *
8283             * @param pk the primary key of the user
8284             * @param start the lower bound of the range of users
8285             * @param end the upper bound of the range of users (not inclusive)
8286             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8287             * @return the ordered range of groups associated with the user
8288             */
8289            @Override
8290            public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
8291                    int end,
8292                    OrderByComparator<com.liferay.portal.model.Group> orderByComparator) {
8293                    return userToGroupTableMapper.getRightBaseModels(0, pk, start, end,
8294                            orderByComparator);
8295            }
8296    
8297            /**
8298             * Returns the number of groups associated with the user.
8299             *
8300             * @param pk the primary key of the user
8301             * @return the number of groups associated with the user
8302             */
8303            @Override
8304            public int getGroupsSize(long pk) {
8305                    long[] pks = userToGroupTableMapper.getRightPrimaryKeys(0, pk);
8306    
8307                    return pks.length;
8308            }
8309    
8310            /**
8311             * Returns <code>true</code> if the group is associated with the user.
8312             *
8313             * @param pk the primary key of the user
8314             * @param groupPK the primary key of the group
8315             * @return <code>true</code> if the group is associated with the user; <code>false</code> otherwise
8316             */
8317            @Override
8318            public boolean containsGroup(long pk, long groupPK) {
8319                    return userToGroupTableMapper.containsTableMapping(0, pk, groupPK);
8320            }
8321    
8322            /**
8323             * Returns <code>true</code> if the user has any groups associated with it.
8324             *
8325             * @param pk the primary key of the user to check for associations with groups
8326             * @return <code>true</code> if the user has any groups associated with it; <code>false</code> otherwise
8327             */
8328            @Override
8329            public boolean containsGroups(long pk) {
8330                    if (getGroupsSize(pk) > 0) {
8331                            return true;
8332                    }
8333                    else {
8334                            return false;
8335                    }
8336            }
8337    
8338            /**
8339             * Adds an association between the user and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8340             *
8341             * @param pk the primary key of the user
8342             * @param groupPK the primary key of the group
8343             */
8344            @Override
8345            public void addGroup(long pk, long groupPK) {
8346                    userToGroupTableMapper.addTableMapping(0, pk, groupPK);
8347            }
8348    
8349            /**
8350             * Adds an association between the user and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8351             *
8352             * @param pk the primary key of the user
8353             * @param group the group
8354             */
8355            @Override
8356            public void addGroup(long pk, com.liferay.portal.model.Group group) {
8357                    userToGroupTableMapper.addTableMapping(0, pk, group.getPrimaryKey());
8358            }
8359    
8360            /**
8361             * Adds an association between the user and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8362             *
8363             * @param pk the primary key of the user
8364             * @param groupPKs the primary keys of the groups
8365             */
8366            @Override
8367            public void addGroups(long pk, long[] groupPKs) {
8368                    for (long groupPK : groupPKs) {
8369                            userToGroupTableMapper.addTableMapping(0, pk, groupPK);
8370                    }
8371            }
8372    
8373            /**
8374             * Adds an association between the user and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8375             *
8376             * @param pk the primary key of the user
8377             * @param groups the groups
8378             */
8379            @Override
8380            public void addGroups(long pk, List<com.liferay.portal.model.Group> groups) {
8381                    for (com.liferay.portal.model.Group group : groups) {
8382                            userToGroupTableMapper.addTableMapping(0, pk, group.getPrimaryKey());
8383                    }
8384            }
8385    
8386            /**
8387             * Clears all associations between the user and its groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8388             *
8389             * @param pk the primary key of the user to clear the associated groups from
8390             */
8391            @Override
8392            public void clearGroups(long pk) {
8393                    userToGroupTableMapper.deleteLeftPrimaryKeyTableMappings(0, pk);
8394            }
8395    
8396            /**
8397             * Removes the association between the user and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8398             *
8399             * @param pk the primary key of the user
8400             * @param groupPK the primary key of the group
8401             */
8402            @Override
8403            public void removeGroup(long pk, long groupPK) {
8404                    userToGroupTableMapper.deleteTableMapping(0, pk, groupPK);
8405            }
8406    
8407            /**
8408             * Removes the association between the user and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8409             *
8410             * @param pk the primary key of the user
8411             * @param group the group
8412             */
8413            @Override
8414            public void removeGroup(long pk, com.liferay.portal.model.Group group) {
8415                    userToGroupTableMapper.deleteTableMapping(0, pk, group.getPrimaryKey());
8416            }
8417    
8418            /**
8419             * Removes the association between the user and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8420             *
8421             * @param pk the primary key of the user
8422             * @param groupPKs the primary keys of the groups
8423             */
8424            @Override
8425            public void removeGroups(long pk, long[] groupPKs) {
8426                    for (long groupPK : groupPKs) {
8427                            userToGroupTableMapper.deleteTableMapping(0, pk, groupPK);
8428                    }
8429            }
8430    
8431            /**
8432             * Removes the association between the user and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8433             *
8434             * @param pk the primary key of the user
8435             * @param groups the groups
8436             */
8437            @Override
8438            public void removeGroups(long pk,
8439                    List<com.liferay.portal.model.Group> groups) {
8440                    for (com.liferay.portal.model.Group group : groups) {
8441                            userToGroupTableMapper.deleteTableMapping(0, pk,
8442                                    group.getPrimaryKey());
8443                    }
8444            }
8445    
8446            /**
8447             * Sets the groups associated with the user, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8448             *
8449             * @param pk the primary key of the user
8450             * @param groupPKs the primary keys of the groups to be associated with the user
8451             */
8452            @Override
8453            public void setGroups(long pk, long[] groupPKs) {
8454                    Set<Long> newGroupPKsSet = SetUtil.fromArray(groupPKs);
8455                    Set<Long> oldGroupPKsSet = SetUtil.fromArray(userToGroupTableMapper.getRightPrimaryKeys(
8456                                            0, pk));
8457    
8458                    Set<Long> removeGroupPKsSet = new HashSet<Long>(oldGroupPKsSet);
8459    
8460                    removeGroupPKsSet.removeAll(newGroupPKsSet);
8461    
8462                    for (long removeGroupPK : removeGroupPKsSet) {
8463                            userToGroupTableMapper.deleteTableMapping(0, pk, removeGroupPK);
8464                    }
8465    
8466                    newGroupPKsSet.removeAll(oldGroupPKsSet);
8467    
8468                    for (long newGroupPK : newGroupPKsSet) {
8469                            userToGroupTableMapper.addTableMapping(0, pk, newGroupPK);
8470                    }
8471            }
8472    
8473            /**
8474             * Sets the groups associated with the user, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8475             *
8476             * @param pk the primary key of the user
8477             * @param groups the groups to be associated with the user
8478             */
8479            @Override
8480            public void setGroups(long pk, List<com.liferay.portal.model.Group> groups) {
8481                    try {
8482                            long[] groupPKs = new long[groups.size()];
8483    
8484                            for (int i = 0; i < groups.size(); i++) {
8485                                    com.liferay.portal.model.Group group = groups.get(i);
8486    
8487                                    groupPKs[i] = group.getPrimaryKey();
8488                            }
8489    
8490                            setGroups(pk, groupPKs);
8491                    }
8492                    catch (Exception e) {
8493                            throw processException(e);
8494                    }
8495            }
8496    
8497            /**
8498             * Returns the primaryKeys of organizations associated with the user.
8499             *
8500             * @param pk the primary key of the user
8501             * @return long[] of the primaryKeys of organizations associated with the user
8502             */
8503            @Override
8504            public long[] getOrganizationPrimaryKeys(long pk) {
8505                    long[] pks = userToOrganizationTableMapper.getRightPrimaryKeys(0, pk);
8506    
8507                    return pks.clone();
8508            }
8509    
8510            /**
8511             * Returns all the organizations associated with the user.
8512             *
8513             * @param pk the primary key of the user
8514             * @return the organizations associated with the user
8515             */
8516            @Override
8517            public List<com.liferay.portal.model.Organization> getOrganizations(long pk) {
8518                    return getOrganizations(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
8519            }
8520    
8521            /**
8522             * Returns a range of all the organizations associated with the user.
8523             *
8524             * <p>
8525             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
8526             * </p>
8527             *
8528             * @param pk the primary key of the user
8529             * @param start the lower bound of the range of users
8530             * @param end the upper bound of the range of users (not inclusive)
8531             * @return the range of organizations associated with the user
8532             */
8533            @Override
8534            public List<com.liferay.portal.model.Organization> getOrganizations(
8535                    long pk, int start, int end) {
8536                    return getOrganizations(pk, start, end, null);
8537            }
8538    
8539            /**
8540             * Returns an ordered range of all the organizations associated with the user.
8541             *
8542             * <p>
8543             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
8544             * </p>
8545             *
8546             * @param pk the primary key of the user
8547             * @param start the lower bound of the range of users
8548             * @param end the upper bound of the range of users (not inclusive)
8549             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8550             * @return the ordered range of organizations associated with the user
8551             */
8552            @Override
8553            public List<com.liferay.portal.model.Organization> getOrganizations(
8554                    long pk, int start, int end,
8555                    OrderByComparator<com.liferay.portal.model.Organization> orderByComparator) {
8556                    return userToOrganizationTableMapper.getRightBaseModels(0, pk, start,
8557                            end, orderByComparator);
8558            }
8559    
8560            /**
8561             * Returns the number of organizations associated with the user.
8562             *
8563             * @param pk the primary key of the user
8564             * @return the number of organizations associated with the user
8565             */
8566            @Override
8567            public int getOrganizationsSize(long pk) {
8568                    long[] pks = userToOrganizationTableMapper.getRightPrimaryKeys(0, pk);
8569    
8570                    return pks.length;
8571            }
8572    
8573            /**
8574             * Returns <code>true</code> if the organization is associated with the user.
8575             *
8576             * @param pk the primary key of the user
8577             * @param organizationPK the primary key of the organization
8578             * @return <code>true</code> if the organization is associated with the user; <code>false</code> otherwise
8579             */
8580            @Override
8581            public boolean containsOrganization(long pk, long organizationPK) {
8582                    return userToOrganizationTableMapper.containsTableMapping(0, pk,
8583                            organizationPK);
8584            }
8585    
8586            /**
8587             * Returns <code>true</code> if the user has any organizations associated with it.
8588             *
8589             * @param pk the primary key of the user to check for associations with organizations
8590             * @return <code>true</code> if the user has any organizations associated with it; <code>false</code> otherwise
8591             */
8592            @Override
8593            public boolean containsOrganizations(long pk) {
8594                    if (getOrganizationsSize(pk) > 0) {
8595                            return true;
8596                    }
8597                    else {
8598                            return false;
8599                    }
8600            }
8601    
8602            /**
8603             * Adds an association between the user and the organization. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8604             *
8605             * @param pk the primary key of the user
8606             * @param organizationPK the primary key of the organization
8607             */
8608            @Override
8609            public void addOrganization(long pk, long organizationPK) {
8610                    userToOrganizationTableMapper.addTableMapping(0, pk, organizationPK);
8611            }
8612    
8613            /**
8614             * Adds an association between the user and the organization. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8615             *
8616             * @param pk the primary key of the user
8617             * @param organization the organization
8618             */
8619            @Override
8620            public void addOrganization(long pk,
8621                    com.liferay.portal.model.Organization organization) {
8622                    userToOrganizationTableMapper.addTableMapping(0, pk,
8623                            organization.getPrimaryKey());
8624            }
8625    
8626            /**
8627             * Adds an association between the user and the organizations. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8628             *
8629             * @param pk the primary key of the user
8630             * @param organizationPKs the primary keys of the organizations
8631             */
8632            @Override
8633            public void addOrganizations(long pk, long[] organizationPKs) {
8634                    for (long organizationPK : organizationPKs) {
8635                            userToOrganizationTableMapper.addTableMapping(0, pk, organizationPK);
8636                    }
8637            }
8638    
8639            /**
8640             * Adds an association between the user and the organizations. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8641             *
8642             * @param pk the primary key of the user
8643             * @param organizations the organizations
8644             */
8645            @Override
8646            public void addOrganizations(long pk,
8647                    List<com.liferay.portal.model.Organization> organizations) {
8648                    for (com.liferay.portal.model.Organization organization : organizations) {
8649                            userToOrganizationTableMapper.addTableMapping(0, pk,
8650                                    organization.getPrimaryKey());
8651                    }
8652            }
8653    
8654            /**
8655             * Clears all associations between the user and its organizations. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8656             *
8657             * @param pk the primary key of the user to clear the associated organizations from
8658             */
8659            @Override
8660            public void clearOrganizations(long pk) {
8661                    userToOrganizationTableMapper.deleteLeftPrimaryKeyTableMappings(0, pk);
8662            }
8663    
8664            /**
8665             * Removes the association between the user and the organization. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8666             *
8667             * @param pk the primary key of the user
8668             * @param organizationPK the primary key of the organization
8669             */
8670            @Override
8671            public void removeOrganization(long pk, long organizationPK) {
8672                    userToOrganizationTableMapper.deleteTableMapping(0, pk, organizationPK);
8673            }
8674    
8675            /**
8676             * Removes the association between the user and the organization. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8677             *
8678             * @param pk the primary key of the user
8679             * @param organization the organization
8680             */
8681            @Override
8682            public void removeOrganization(long pk,
8683                    com.liferay.portal.model.Organization organization) {
8684                    userToOrganizationTableMapper.deleteTableMapping(0, pk,
8685                            organization.getPrimaryKey());
8686            }
8687    
8688            /**
8689             * Removes the association between the user and the organizations. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8690             *
8691             * @param pk the primary key of the user
8692             * @param organizationPKs the primary keys of the organizations
8693             */
8694            @Override
8695            public void removeOrganizations(long pk, long[] organizationPKs) {
8696                    for (long organizationPK : organizationPKs) {
8697                            userToOrganizationTableMapper.deleteTableMapping(0, pk,
8698                                    organizationPK);
8699                    }
8700            }
8701    
8702            /**
8703             * Removes the association between the user and the organizations. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8704             *
8705             * @param pk the primary key of the user
8706             * @param organizations the organizations
8707             */
8708            @Override
8709            public void removeOrganizations(long pk,
8710                    List<com.liferay.portal.model.Organization> organizations) {
8711                    for (com.liferay.portal.model.Organization organization : organizations) {
8712                            userToOrganizationTableMapper.deleteTableMapping(0, pk,
8713                                    organization.getPrimaryKey());
8714                    }
8715            }
8716    
8717            /**
8718             * Sets the organizations associated with the user, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8719             *
8720             * @param pk the primary key of the user
8721             * @param organizationPKs the primary keys of the organizations to be associated with the user
8722             */
8723            @Override
8724            public void setOrganizations(long pk, long[] organizationPKs) {
8725                    Set<Long> newOrganizationPKsSet = SetUtil.fromArray(organizationPKs);
8726                    Set<Long> oldOrganizationPKsSet = SetUtil.fromArray(userToOrganizationTableMapper.getRightPrimaryKeys(
8727                                            0, pk));
8728    
8729                    Set<Long> removeOrganizationPKsSet = new HashSet<Long>(oldOrganizationPKsSet);
8730    
8731                    removeOrganizationPKsSet.removeAll(newOrganizationPKsSet);
8732    
8733                    for (long removeOrganizationPK : removeOrganizationPKsSet) {
8734                            userToOrganizationTableMapper.deleteTableMapping(0, pk,
8735                                    removeOrganizationPK);
8736                    }
8737    
8738                    newOrganizationPKsSet.removeAll(oldOrganizationPKsSet);
8739    
8740                    for (long newOrganizationPK : newOrganizationPKsSet) {
8741                            userToOrganizationTableMapper.addTableMapping(0, pk,
8742                                    newOrganizationPK);
8743                    }
8744            }
8745    
8746            /**
8747             * Sets the organizations associated with the user, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8748             *
8749             * @param pk the primary key of the user
8750             * @param organizations the organizations to be associated with the user
8751             */
8752            @Override
8753            public void setOrganizations(long pk,
8754                    List<com.liferay.portal.model.Organization> organizations) {
8755                    try {
8756                            long[] organizationPKs = new long[organizations.size()];
8757    
8758                            for (int i = 0; i < organizations.size(); i++) {
8759                                    com.liferay.portal.model.Organization organization = organizations.get(i);
8760    
8761                                    organizationPKs[i] = organization.getPrimaryKey();
8762                            }
8763    
8764                            setOrganizations(pk, organizationPKs);
8765                    }
8766                    catch (Exception e) {
8767                            throw processException(e);
8768                    }
8769            }
8770    
8771            /**
8772             * Returns the primaryKeys of roles associated with the user.
8773             *
8774             * @param pk the primary key of the user
8775             * @return long[] of the primaryKeys of roles associated with the user
8776             */
8777            @Override
8778            public long[] getRolePrimaryKeys(long pk) {
8779                    long[] pks = userToRoleTableMapper.getRightPrimaryKeys(0, pk);
8780    
8781                    return pks.clone();
8782            }
8783    
8784            /**
8785             * Returns all the roles associated with the user.
8786             *
8787             * @param pk the primary key of the user
8788             * @return the roles associated with the user
8789             */
8790            @Override
8791            public List<com.liferay.portal.model.Role> getRoles(long pk) {
8792                    return getRoles(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
8793            }
8794    
8795            /**
8796             * Returns a range of all the roles associated with the user.
8797             *
8798             * <p>
8799             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
8800             * </p>
8801             *
8802             * @param pk the primary key of the user
8803             * @param start the lower bound of the range of users
8804             * @param end the upper bound of the range of users (not inclusive)
8805             * @return the range of roles associated with the user
8806             */
8807            @Override
8808            public List<com.liferay.portal.model.Role> getRoles(long pk, int start,
8809                    int end) {
8810                    return getRoles(pk, start, end, null);
8811            }
8812    
8813            /**
8814             * Returns an ordered range of all the roles associated with the user.
8815             *
8816             * <p>
8817             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
8818             * </p>
8819             *
8820             * @param pk the primary key of the user
8821             * @param start the lower bound of the range of users
8822             * @param end the upper bound of the range of users (not inclusive)
8823             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8824             * @return the ordered range of roles associated with the user
8825             */
8826            @Override
8827            public List<com.liferay.portal.model.Role> getRoles(long pk, int start,
8828                    int end,
8829                    OrderByComparator<com.liferay.portal.model.Role> orderByComparator) {
8830                    return userToRoleTableMapper.getRightBaseModels(0, pk, start, end,
8831                            orderByComparator);
8832            }
8833    
8834            /**
8835             * Returns the number of roles associated with the user.
8836             *
8837             * @param pk the primary key of the user
8838             * @return the number of roles associated with the user
8839             */
8840            @Override
8841            public int getRolesSize(long pk) {
8842                    long[] pks = userToRoleTableMapper.getRightPrimaryKeys(0, pk);
8843    
8844                    return pks.length;
8845            }
8846    
8847            /**
8848             * Returns <code>true</code> if the role is associated with the user.
8849             *
8850             * @param pk the primary key of the user
8851             * @param rolePK the primary key of the role
8852             * @return <code>true</code> if the role is associated with the user; <code>false</code> otherwise
8853             */
8854            @Override
8855            public boolean containsRole(long pk, long rolePK) {
8856                    return userToRoleTableMapper.containsTableMapping(0, pk, rolePK);
8857            }
8858    
8859            /**
8860             * Returns <code>true</code> if the user has any roles associated with it.
8861             *
8862             * @param pk the primary key of the user to check for associations with roles
8863             * @return <code>true</code> if the user has any roles associated with it; <code>false</code> otherwise
8864             */
8865            @Override
8866            public boolean containsRoles(long pk) {
8867                    if (getRolesSize(pk) > 0) {
8868                            return true;
8869                    }
8870                    else {
8871                            return false;
8872                    }
8873            }
8874    
8875            /**
8876             * Adds an association between the user and the role. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8877             *
8878             * @param pk the primary key of the user
8879             * @param rolePK the primary key of the role
8880             */
8881            @Override
8882            public void addRole(long pk, long rolePK) {
8883                    userToRoleTableMapper.addTableMapping(0, pk, rolePK);
8884            }
8885    
8886            /**
8887             * Adds an association between the user and the role. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8888             *
8889             * @param pk the primary key of the user
8890             * @param role the role
8891             */
8892            @Override
8893            public void addRole(long pk, com.liferay.portal.model.Role role) {
8894                    userToRoleTableMapper.addTableMapping(0, pk, role.getPrimaryKey());
8895            }
8896    
8897            /**
8898             * Adds an association between the user and the roles. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8899             *
8900             * @param pk the primary key of the user
8901             * @param rolePKs the primary keys of the roles
8902             */
8903            @Override
8904            public void addRoles(long pk, long[] rolePKs) {
8905                    for (long rolePK : rolePKs) {
8906                            userToRoleTableMapper.addTableMapping(0, pk, rolePK);
8907                    }
8908            }
8909    
8910            /**
8911             * Adds an association between the user and the roles. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8912             *
8913             * @param pk the primary key of the user
8914             * @param roles the roles
8915             */
8916            @Override
8917            public void addRoles(long pk, List<com.liferay.portal.model.Role> roles) {
8918                    for (com.liferay.portal.model.Role role : roles) {
8919                            userToRoleTableMapper.addTableMapping(0, pk, role.getPrimaryKey());
8920                    }
8921            }
8922    
8923            /**
8924             * Clears all associations between the user and its roles. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8925             *
8926             * @param pk the primary key of the user to clear the associated roles from
8927             */
8928            @Override
8929            public void clearRoles(long pk) {
8930                    userToRoleTableMapper.deleteLeftPrimaryKeyTableMappings(0, pk);
8931            }
8932    
8933            /**
8934             * Removes the association between the user and the role. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8935             *
8936             * @param pk the primary key of the user
8937             * @param rolePK the primary key of the role
8938             */
8939            @Override
8940            public void removeRole(long pk, long rolePK) {
8941                    userToRoleTableMapper.deleteTableMapping(0, pk, rolePK);
8942            }
8943    
8944            /**
8945             * Removes the association between the user and the role. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8946             *
8947             * @param pk the primary key of the user
8948             * @param role the role
8949             */
8950            @Override
8951            public void removeRole(long pk, com.liferay.portal.model.Role role) {
8952                    userToRoleTableMapper.deleteTableMapping(0, pk, role.getPrimaryKey());
8953            }
8954    
8955            /**
8956             * Removes the association between the user and the roles. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8957             *
8958             * @param pk the primary key of the user
8959             * @param rolePKs the primary keys of the roles
8960             */
8961            @Override
8962            public void removeRoles(long pk, long[] rolePKs) {
8963                    for (long rolePK : rolePKs) {
8964                            userToRoleTableMapper.deleteTableMapping(0, pk, rolePK);
8965                    }
8966            }
8967    
8968            /**
8969             * Removes the association between the user and the roles. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8970             *
8971             * @param pk the primary key of the user
8972             * @param roles the roles
8973             */
8974            @Override
8975            public void removeRoles(long pk, List<com.liferay.portal.model.Role> roles) {
8976                    for (com.liferay.portal.model.Role role : roles) {
8977                            userToRoleTableMapper.deleteTableMapping(0, pk, role.getPrimaryKey());
8978                    }
8979            }
8980    
8981            /**
8982             * Sets the roles associated with the user, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8983             *
8984             * @param pk the primary key of the user
8985             * @param rolePKs the primary keys of the roles to be associated with the user
8986             */
8987            @Override
8988            public void setRoles(long pk, long[] rolePKs) {
8989                    Set<Long> newRolePKsSet = SetUtil.fromArray(rolePKs);
8990                    Set<Long> oldRolePKsSet = SetUtil.fromArray(userToRoleTableMapper.getRightPrimaryKeys(
8991                                            0, pk));
8992    
8993                    Set<Long> removeRolePKsSet = new HashSet<Long>(oldRolePKsSet);
8994    
8995                    removeRolePKsSet.removeAll(newRolePKsSet);
8996    
8997                    for (long removeRolePK : removeRolePKsSet) {
8998                            userToRoleTableMapper.deleteTableMapping(0, pk, removeRolePK);
8999                    }
9000    
9001                    newRolePKsSet.removeAll(oldRolePKsSet);
9002    
9003                    for (long newRolePK : newRolePKsSet) {
9004                            userToRoleTableMapper.addTableMapping(0, pk, newRolePK);
9005                    }
9006            }
9007    
9008            /**
9009             * Sets the roles associated with the user, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9010             *
9011             * @param pk the primary key of the user
9012             * @param roles the roles to be associated with the user
9013             */
9014            @Override
9015            public void setRoles(long pk, List<com.liferay.portal.model.Role> roles) {
9016                    try {
9017                            long[] rolePKs = new long[roles.size()];
9018    
9019                            for (int i = 0; i < roles.size(); i++) {
9020                                    com.liferay.portal.model.Role role = roles.get(i);
9021    
9022                                    rolePKs[i] = role.getPrimaryKey();
9023                            }
9024    
9025                            setRoles(pk, rolePKs);
9026                    }
9027                    catch (Exception e) {
9028                            throw processException(e);
9029                    }
9030            }
9031    
9032            /**
9033             * Returns the primaryKeys of teams associated with the user.
9034             *
9035             * @param pk the primary key of the user
9036             * @return long[] of the primaryKeys of teams associated with the user
9037             */
9038            @Override
9039            public long[] getTeamPrimaryKeys(long pk) {
9040                    long[] pks = userToTeamTableMapper.getRightPrimaryKeys(0, pk);
9041    
9042                    return pks.clone();
9043            }
9044    
9045            /**
9046             * Returns all the teams associated with the user.
9047             *
9048             * @param pk the primary key of the user
9049             * @return the teams associated with the user
9050             */
9051            @Override
9052            public List<com.liferay.portal.model.Team> getTeams(long pk) {
9053                    return getTeams(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
9054            }
9055    
9056            /**
9057             * Returns a range of all the teams associated with the user.
9058             *
9059             * <p>
9060             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
9061             * </p>
9062             *
9063             * @param pk the primary key of the user
9064             * @param start the lower bound of the range of users
9065             * @param end the upper bound of the range of users (not inclusive)
9066             * @return the range of teams associated with the user
9067             */
9068            @Override
9069            public List<com.liferay.portal.model.Team> getTeams(long pk, int start,
9070                    int end) {
9071                    return getTeams(pk, start, end, null);
9072            }
9073    
9074            /**
9075             * Returns an ordered range of all the teams associated with the user.
9076             *
9077             * <p>
9078             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
9079             * </p>
9080             *
9081             * @param pk the primary key of the user
9082             * @param start the lower bound of the range of users
9083             * @param end the upper bound of the range of users (not inclusive)
9084             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9085             * @return the ordered range of teams associated with the user
9086             */
9087            @Override
9088            public List<com.liferay.portal.model.Team> getTeams(long pk, int start,
9089                    int end,
9090                    OrderByComparator<com.liferay.portal.model.Team> orderByComparator) {
9091                    return userToTeamTableMapper.getRightBaseModels(0, pk, start, end,
9092                            orderByComparator);
9093            }
9094    
9095            /**
9096             * Returns the number of teams associated with the user.
9097             *
9098             * @param pk the primary key of the user
9099             * @return the number of teams associated with the user
9100             */
9101            @Override
9102            public int getTeamsSize(long pk) {
9103                    long[] pks = userToTeamTableMapper.getRightPrimaryKeys(0, pk);
9104    
9105                    return pks.length;
9106            }
9107    
9108            /**
9109             * Returns <code>true</code> if the team is associated with the user.
9110             *
9111             * @param pk the primary key of the user
9112             * @param teamPK the primary key of the team
9113             * @return <code>true</code> if the team is associated with the user; <code>false</code> otherwise
9114             */
9115            @Override
9116            public boolean containsTeam(long pk, long teamPK) {
9117                    return userToTeamTableMapper.containsTableMapping(0, pk, teamPK);
9118            }
9119    
9120            /**
9121             * Returns <code>true</code> if the user has any teams associated with it.
9122             *
9123             * @param pk the primary key of the user to check for associations with teams
9124             * @return <code>true</code> if the user has any teams associated with it; <code>false</code> otherwise
9125             */
9126            @Override
9127            public boolean containsTeams(long pk) {
9128                    if (getTeamsSize(pk) > 0) {
9129                            return true;
9130                    }
9131                    else {
9132                            return false;
9133                    }
9134            }
9135    
9136            /**
9137             * Adds an association between the user and the team. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9138             *
9139             * @param pk the primary key of the user
9140             * @param teamPK the primary key of the team
9141             */
9142            @Override
9143            public void addTeam(long pk, long teamPK) {
9144                    userToTeamTableMapper.addTableMapping(0, pk, teamPK);
9145            }
9146    
9147            /**
9148             * Adds an association between the user and the team. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9149             *
9150             * @param pk the primary key of the user
9151             * @param team the team
9152             */
9153            @Override
9154            public void addTeam(long pk, com.liferay.portal.model.Team team) {
9155                    userToTeamTableMapper.addTableMapping(0, pk, team.getPrimaryKey());
9156            }
9157    
9158            /**
9159             * Adds an association between the user and the teams. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9160             *
9161             * @param pk the primary key of the user
9162             * @param teamPKs the primary keys of the teams
9163             */
9164            @Override
9165            public void addTeams(long pk, long[] teamPKs) {
9166                    for (long teamPK : teamPKs) {
9167                            userToTeamTableMapper.addTableMapping(0, pk, teamPK);
9168                    }
9169            }
9170    
9171            /**
9172             * Adds an association between the user and the teams. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9173             *
9174             * @param pk the primary key of the user
9175             * @param teams the teams
9176             */
9177            @Override
9178            public void addTeams(long pk, List<com.liferay.portal.model.Team> teams) {
9179                    for (com.liferay.portal.model.Team team : teams) {
9180                            userToTeamTableMapper.addTableMapping(0, pk, team.getPrimaryKey());
9181                    }
9182            }
9183    
9184            /**
9185             * Clears all associations between the user and its teams. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9186             *
9187             * @param pk the primary key of the user to clear the associated teams from
9188             */
9189            @Override
9190            public void clearTeams(long pk) {
9191                    userToTeamTableMapper.deleteLeftPrimaryKeyTableMappings(0, pk);
9192            }
9193    
9194            /**
9195             * Removes the association between the user and the team. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9196             *
9197             * @param pk the primary key of the user
9198             * @param teamPK the primary key of the team
9199             */
9200            @Override
9201            public void removeTeam(long pk, long teamPK) {
9202                    userToTeamTableMapper.deleteTableMapping(0, pk, teamPK);
9203            }
9204    
9205            /**
9206             * Removes the association between the user and the team. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9207             *
9208             * @param pk the primary key of the user
9209             * @param team the team
9210             */
9211            @Override
9212            public void removeTeam(long pk, com.liferay.portal.model.Team team) {
9213                    userToTeamTableMapper.deleteTableMapping(0, pk, team.getPrimaryKey());
9214            }
9215    
9216            /**
9217             * Removes the association between the user and the teams. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9218             *
9219             * @param pk the primary key of the user
9220             * @param teamPKs the primary keys of the teams
9221             */
9222            @Override
9223            public void removeTeams(long pk, long[] teamPKs) {
9224                    for (long teamPK : teamPKs) {
9225                            userToTeamTableMapper.deleteTableMapping(0, pk, teamPK);
9226                    }
9227            }
9228    
9229            /**
9230             * Removes the association between the user and the teams. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9231             *
9232             * @param pk the primary key of the user
9233             * @param teams the teams
9234             */
9235            @Override
9236            public void removeTeams(long pk, List<com.liferay.portal.model.Team> teams) {
9237                    for (com.liferay.portal.model.Team team : teams) {
9238                            userToTeamTableMapper.deleteTableMapping(0, pk, team.getPrimaryKey());
9239                    }
9240            }
9241    
9242            /**
9243             * Sets the teams associated with the user, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9244             *
9245             * @param pk the primary key of the user
9246             * @param teamPKs the primary keys of the teams to be associated with the user
9247             */
9248            @Override
9249            public void setTeams(long pk, long[] teamPKs) {
9250                    Set<Long> newTeamPKsSet = SetUtil.fromArray(teamPKs);
9251                    Set<Long> oldTeamPKsSet = SetUtil.fromArray(userToTeamTableMapper.getRightPrimaryKeys(
9252                                            0, pk));
9253    
9254                    Set<Long> removeTeamPKsSet = new HashSet<Long>(oldTeamPKsSet);
9255    
9256                    removeTeamPKsSet.removeAll(newTeamPKsSet);
9257    
9258                    for (long removeTeamPK : removeTeamPKsSet) {
9259                            userToTeamTableMapper.deleteTableMapping(0, pk, removeTeamPK);
9260                    }
9261    
9262                    newTeamPKsSet.removeAll(oldTeamPKsSet);
9263    
9264                    for (long newTeamPK : newTeamPKsSet) {
9265                            userToTeamTableMapper.addTableMapping(0, pk, newTeamPK);
9266                    }
9267            }
9268    
9269            /**
9270             * Sets the teams associated with the user, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9271             *
9272             * @param pk the primary key of the user
9273             * @param teams the teams to be associated with the user
9274             */
9275            @Override
9276            public void setTeams(long pk, List<com.liferay.portal.model.Team> teams) {
9277                    try {
9278                            long[] teamPKs = new long[teams.size()];
9279    
9280                            for (int i = 0; i < teams.size(); i++) {
9281                                    com.liferay.portal.model.Team team = teams.get(i);
9282    
9283                                    teamPKs[i] = team.getPrimaryKey();
9284                            }
9285    
9286                            setTeams(pk, teamPKs);
9287                    }
9288                    catch (Exception e) {
9289                            throw processException(e);
9290                    }
9291            }
9292    
9293            /**
9294             * Returns the primaryKeys of user groups associated with the user.
9295             *
9296             * @param pk the primary key of the user
9297             * @return long[] of the primaryKeys of user groups associated with the user
9298             */
9299            @Override
9300            public long[] getUserGroupPrimaryKeys(long pk) {
9301                    long[] pks = userToUserGroupTableMapper.getRightPrimaryKeys(0, pk);
9302    
9303                    return pks.clone();
9304            }
9305    
9306            /**
9307             * Returns all the user groups associated with the user.
9308             *
9309             * @param pk the primary key of the user
9310             * @return the user groups associated with the user
9311             */
9312            @Override
9313            public List<com.liferay.portal.model.UserGroup> getUserGroups(long pk) {
9314                    return getUserGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
9315            }
9316    
9317            /**
9318             * Returns a range of all the user groups associated with the user.
9319             *
9320             * <p>
9321             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
9322             * </p>
9323             *
9324             * @param pk the primary key of the user
9325             * @param start the lower bound of the range of users
9326             * @param end the upper bound of the range of users (not inclusive)
9327             * @return the range of user groups associated with the user
9328             */
9329            @Override
9330            public List<com.liferay.portal.model.UserGroup> getUserGroups(long pk,
9331                    int start, int end) {
9332                    return getUserGroups(pk, start, end, null);
9333            }
9334    
9335            /**
9336             * Returns an ordered range of all the user groups associated with the user.
9337             *
9338             * <p>
9339             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserModelImpl}. 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.
9340             * </p>
9341             *
9342             * @param pk the primary key of the user
9343             * @param start the lower bound of the range of users
9344             * @param end the upper bound of the range of users (not inclusive)
9345             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9346             * @return the ordered range of user groups associated with the user
9347             */
9348            @Override
9349            public List<com.liferay.portal.model.UserGroup> getUserGroups(long pk,
9350                    int start, int end,
9351                    OrderByComparator<com.liferay.portal.model.UserGroup> orderByComparator) {
9352                    return userToUserGroupTableMapper.getRightBaseModels(0, pk, start, end,
9353                            orderByComparator);
9354            }
9355    
9356            /**
9357             * Returns the number of user groups associated with the user.
9358             *
9359             * @param pk the primary key of the user
9360             * @return the number of user groups associated with the user
9361             */
9362            @Override
9363            public int getUserGroupsSize(long pk) {
9364                    long[] pks = userToUserGroupTableMapper.getRightPrimaryKeys(0, pk);
9365    
9366                    return pks.length;
9367            }
9368    
9369            /**
9370             * Returns <code>true</code> if the user group is associated with the user.
9371             *
9372             * @param pk the primary key of the user
9373             * @param userGroupPK the primary key of the user group
9374             * @return <code>true</code> if the user group is associated with the user; <code>false</code> otherwise
9375             */
9376            @Override
9377            public boolean containsUserGroup(long pk, long userGroupPK) {
9378                    return userToUserGroupTableMapper.containsTableMapping(0, pk,
9379                            userGroupPK);
9380            }
9381    
9382            /**
9383             * Returns <code>true</code> if the user has any user groups associated with it.
9384             *
9385             * @param pk the primary key of the user to check for associations with user groups
9386             * @return <code>true</code> if the user has any user groups associated with it; <code>false</code> otherwise
9387             */
9388            @Override
9389            public boolean containsUserGroups(long pk) {
9390                    if (getUserGroupsSize(pk) > 0) {
9391                            return true;
9392                    }
9393                    else {
9394                            return false;
9395                    }
9396            }
9397    
9398            /**
9399             * Adds an association between the user and the user group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9400             *
9401             * @param pk the primary key of the user
9402             * @param userGroupPK the primary key of the user group
9403             */
9404            @Override
9405            public void addUserGroup(long pk, long userGroupPK) {
9406                    userToUserGroupTableMapper.addTableMapping(0, pk, userGroupPK);
9407            }
9408    
9409            /**
9410             * Adds an association between the user and the user group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9411             *
9412             * @param pk the primary key of the user
9413             * @param userGroup the user group
9414             */
9415            @Override
9416            public void addUserGroup(long pk,
9417                    com.liferay.portal.model.UserGroup userGroup) {
9418                    userToUserGroupTableMapper.addTableMapping(0, pk,
9419                            userGroup.getPrimaryKey());
9420            }
9421    
9422            /**
9423             * Adds an association between the user and the user groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9424             *
9425             * @param pk the primary key of the user
9426             * @param userGroupPKs the primary keys of the user groups
9427             */
9428            @Override
9429            public void addUserGroups(long pk, long[] userGroupPKs) {
9430                    for (long userGroupPK : userGroupPKs) {
9431                            userToUserGroupTableMapper.addTableMapping(0, pk, userGroupPK);
9432                    }
9433            }
9434    
9435            /**
9436             * Adds an association between the user and the user groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9437             *
9438             * @param pk the primary key of the user
9439             * @param userGroups the user groups
9440             */
9441            @Override
9442            public void addUserGroups(long pk,
9443                    List<com.liferay.portal.model.UserGroup> userGroups) {
9444                    for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
9445                            userToUserGroupTableMapper.addTableMapping(0, pk,
9446                                    userGroup.getPrimaryKey());
9447                    }
9448            }
9449    
9450            /**
9451             * Clears all associations between the user and its user groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9452             *
9453             * @param pk the primary key of the user to clear the associated user groups from
9454             */
9455            @Override
9456            public void clearUserGroups(long pk) {
9457                    userToUserGroupTableMapper.deleteLeftPrimaryKeyTableMappings(0, pk);
9458            }
9459    
9460            /**
9461             * Removes the association between the user and the user group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9462             *
9463             * @param pk the primary key of the user
9464             * @param userGroupPK the primary key of the user group
9465             */
9466            @Override
9467            public void removeUserGroup(long pk, long userGroupPK) {
9468                    userToUserGroupTableMapper.deleteTableMapping(0, pk, userGroupPK);
9469            }
9470    
9471            /**
9472             * Removes the association between the user and the user group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9473             *
9474             * @param pk the primary key of the user
9475             * @param userGroup the user group
9476             */
9477            @Override
9478            public void removeUserGroup(long pk,
9479                    com.liferay.portal.model.UserGroup userGroup) {
9480                    userToUserGroupTableMapper.deleteTableMapping(0, pk,
9481                            userGroup.getPrimaryKey());
9482            }
9483    
9484            /**
9485             * Removes the association between the user and the user groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9486             *
9487             * @param pk the primary key of the user
9488             * @param userGroupPKs the primary keys of the user groups
9489             */
9490            @Override
9491            public void removeUserGroups(long pk, long[] userGroupPKs) {
9492                    for (long userGroupPK : userGroupPKs) {
9493                            userToUserGroupTableMapper.deleteTableMapping(0, pk, userGroupPK);
9494                    }
9495            }
9496    
9497            /**
9498             * Removes the association between the user and the user groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9499             *
9500             * @param pk the primary key of the user
9501             * @param userGroups the user groups
9502             */
9503            @Override
9504            public void removeUserGroups(long pk,
9505                    List<com.liferay.portal.model.UserGroup> userGroups) {
9506                    for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
9507                            userToUserGroupTableMapper.deleteTableMapping(0, pk,
9508                                    userGroup.getPrimaryKey());
9509                    }
9510            }
9511    
9512            /**
9513             * Sets the user groups associated with the user, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9514             *
9515             * @param pk the primary key of the user
9516             * @param userGroupPKs the primary keys of the user groups to be associated with the user
9517             */
9518            @Override
9519            public void setUserGroups(long pk, long[] userGroupPKs) {
9520                    Set<Long> newUserGroupPKsSet = SetUtil.fromArray(userGroupPKs);
9521                    Set<Long> oldUserGroupPKsSet = SetUtil.fromArray(userToUserGroupTableMapper.getRightPrimaryKeys(
9522                                            0, pk));
9523    
9524                    Set<Long> removeUserGroupPKsSet = new HashSet<Long>(oldUserGroupPKsSet);
9525    
9526                    removeUserGroupPKsSet.removeAll(newUserGroupPKsSet);
9527    
9528                    for (long removeUserGroupPK : removeUserGroupPKsSet) {
9529                            userToUserGroupTableMapper.deleteTableMapping(0, pk,
9530                                    removeUserGroupPK);
9531                    }
9532    
9533                    newUserGroupPKsSet.removeAll(oldUserGroupPKsSet);
9534    
9535                    for (long newUserGroupPK : newUserGroupPKsSet) {
9536                            userToUserGroupTableMapper.addTableMapping(0, pk, newUserGroupPK);
9537                    }
9538            }
9539    
9540            /**
9541             * Sets the user groups associated with the user, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9542             *
9543             * @param pk the primary key of the user
9544             * @param userGroups the user groups to be associated with the user
9545             */
9546            @Override
9547            public void setUserGroups(long pk,
9548                    List<com.liferay.portal.model.UserGroup> userGroups) {
9549                    try {
9550                            long[] userGroupPKs = new long[userGroups.size()];
9551    
9552                            for (int i = 0; i < userGroups.size(); i++) {
9553                                    com.liferay.portal.model.UserGroup userGroup = userGroups.get(i);
9554    
9555                                    userGroupPKs[i] = userGroup.getPrimaryKey();
9556                            }
9557    
9558                            setUserGroups(pk, userGroupPKs);
9559                    }
9560                    catch (Exception e) {
9561                            throw processException(e);
9562                    }
9563            }
9564    
9565            @Override
9566            public Set<String> getBadColumnNames() {
9567                    return _badColumnNames;
9568            }
9569    
9570            @Override
9571            protected Map<String, Integer> getTableColumnsMap() {
9572                    return UserModelImpl.TABLE_COLUMNS_MAP;
9573            }
9574    
9575            /**
9576             * Initializes the user persistence.
9577             */
9578            public void afterPropertiesSet() {
9579                    userToGroupTableMapper = TableMapperFactory.getTableMapper("Users_Groups",
9580                                    "companyId", "userId", "groupId", this, groupPersistence);
9581    
9582                    userToOrganizationTableMapper = TableMapperFactory.getTableMapper("Users_Orgs",
9583                                    "companyId", "userId", "organizationId", this,
9584                                    organizationPersistence);
9585    
9586                    userToRoleTableMapper = TableMapperFactory.getTableMapper("Users_Roles",
9587                                    "companyId", "userId", "roleId", this, rolePersistence);
9588    
9589                    userToTeamTableMapper = TableMapperFactory.getTableMapper("Users_Teams",
9590                                    "companyId", "userId", "teamId", this, teamPersistence);
9591    
9592                    userToUserGroupTableMapper = TableMapperFactory.getTableMapper("Users_UserGroups",
9593                                    "companyId", "userId", "userGroupId", this, userGroupPersistence);
9594            }
9595    
9596            public void destroy() {
9597                    entityCache.removeCache(UserImpl.class.getName());
9598                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
9599                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
9600                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
9601    
9602                    TableMapperFactory.removeTableMapper("Users_Groups");
9603                    TableMapperFactory.removeTableMapper("Users_Orgs");
9604                    TableMapperFactory.removeTableMapper("Users_Roles");
9605                    TableMapperFactory.removeTableMapper("Users_Teams");
9606                    TableMapperFactory.removeTableMapper("Users_UserGroups");
9607            }
9608    
9609            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
9610            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
9611            @BeanReference(type = GroupPersistence.class)
9612            protected GroupPersistence groupPersistence;
9613            protected TableMapper<User, com.liferay.portal.model.Group> userToGroupTableMapper;
9614            @BeanReference(type = OrganizationPersistence.class)
9615            protected OrganizationPersistence organizationPersistence;
9616            protected TableMapper<User, com.liferay.portal.model.Organization> userToOrganizationTableMapper;
9617            @BeanReference(type = RolePersistence.class)
9618            protected RolePersistence rolePersistence;
9619            protected TableMapper<User, com.liferay.portal.model.Role> userToRoleTableMapper;
9620            @BeanReference(type = TeamPersistence.class)
9621            protected TeamPersistence teamPersistence;
9622            protected TableMapper<User, com.liferay.portal.model.Team> userToTeamTableMapper;
9623            @BeanReference(type = UserGroupPersistence.class)
9624            protected UserGroupPersistence userGroupPersistence;
9625            protected TableMapper<User, com.liferay.portal.model.UserGroup> userToUserGroupTableMapper;
9626            private static final String _SQL_SELECT_USER = "SELECT user FROM User user";
9627            private static final String _SQL_SELECT_USER_WHERE_PKS_IN = "SELECT user FROM User user WHERE userId IN (";
9628            private static final String _SQL_SELECT_USER_WHERE = "SELECT user FROM User user WHERE ";
9629            private static final String _SQL_COUNT_USER = "SELECT COUNT(user) FROM User user";
9630            private static final String _SQL_COUNT_USER_WHERE = "SELECT COUNT(user) FROM User user WHERE ";
9631            private static final String _ORDER_BY_ENTITY_ALIAS = "user.";
9632            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No User exists with the primary key ";
9633            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No User exists with the key {";
9634            private static final Log _log = LogFactoryUtil.getLog(UserPersistenceImpl.class);
9635            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
9636                                    "uuid", "password"
9637                            });
9638            private static final User _nullUser = new UserImpl() {
9639                            @Override
9640                            public Object clone() {
9641                                    return this;
9642                            }
9643    
9644                            @Override
9645                            public CacheModel<User> toCacheModel() {
9646                                    return _nullUserCacheModel;
9647                            }
9648                    };
9649    
9650            private static final CacheModel<User> _nullUserCacheModel = new NullCacheModel();
9651    
9652            private static class NullCacheModel implements CacheModel<User>, MVCCModel {
9653                    @Override
9654                    public long getMvccVersion() {
9655                            return -1;
9656                    }
9657    
9658                    @Override
9659                    public void setMvccVersion(long mvccVersion) {
9660                    }
9661    
9662                    @Override
9663                    public User toEntityModel() {
9664                            return _nullUser;
9665                    }
9666            }
9667    }