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