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