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