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