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