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