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