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