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