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