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