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