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