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