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