001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.NoSuchUserIdMapperException;
019    import com.liferay.portal.kernel.annotation.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.model.UserIdMapper;
040    import com.liferay.portal.model.impl.UserIdMapperImpl;
041    import com.liferay.portal.model.impl.UserIdMapperModelImpl;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import java.io.Serializable;
045    
046    import java.util.ArrayList;
047    import java.util.Collections;
048    import java.util.List;
049    
050    /**
051     * The persistence implementation for the user id mapper service.
052     *
053     * <p>
054     * Never modify or reference this class directly. Always use {@link UserIdMapperUtil} to access the user id mapper persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
055     * </p>
056     *
057     * <p>
058     * Caching information and settings can be found in <code>portal.properties</code>
059     * </p>
060     *
061     * @author Brian Wing Shun Chan
062     * @see UserIdMapperPersistence
063     * @see UserIdMapperUtil
064     * @generated
065     */
066    public class UserIdMapperPersistenceImpl extends BasePersistenceImpl<UserIdMapper>
067            implements UserIdMapperPersistence {
068            public static final String FINDER_CLASS_NAME_ENTITY = UserIdMapperImpl.class.getName();
069            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
070                    ".List";
071            public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
072                            UserIdMapperModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
073                            "findByUserId",
074                            new String[] {
075                                    Long.class.getName(),
076                                    
077                            "java.lang.Integer", "java.lang.Integer",
078                                    "com.liferay.portal.kernel.util.OrderByComparator"
079                            });
080            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
081                            UserIdMapperModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
082                            "countByUserId", new String[] { Long.class.getName() });
083            public static final FinderPath FINDER_PATH_FETCH_BY_U_T = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
084                            UserIdMapperModelImpl.FINDER_CACHE_ENABLED,
085                            FINDER_CLASS_NAME_ENTITY, "fetchByU_T",
086                            new String[] { Long.class.getName(), String.class.getName() });
087            public static final FinderPath FINDER_PATH_COUNT_BY_U_T = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
088                            UserIdMapperModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
089                            "countByU_T",
090                            new String[] { Long.class.getName(), String.class.getName() });
091            public static final FinderPath FINDER_PATH_FETCH_BY_T_E = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
092                            UserIdMapperModelImpl.FINDER_CACHE_ENABLED,
093                            FINDER_CLASS_NAME_ENTITY, "fetchByT_E",
094                            new String[] { String.class.getName(), String.class.getName() });
095            public static final FinderPath FINDER_PATH_COUNT_BY_T_E = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
096                            UserIdMapperModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
097                            "countByT_E",
098                            new String[] { String.class.getName(), String.class.getName() });
099            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
100                            UserIdMapperModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
101                            "findAll", new String[0]);
102            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
103                            UserIdMapperModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
104                            "countAll", new String[0]);
105    
106            /**
107             * Caches the user id mapper in the entity cache if it is enabled.
108             *
109             * @param userIdMapper the user id mapper to cache
110             */
111            public void cacheResult(UserIdMapper userIdMapper) {
112                    EntityCacheUtil.putResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
113                            UserIdMapperImpl.class, userIdMapper.getPrimaryKey(), userIdMapper);
114    
115                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
116                            new Object[] {
117                                    new Long(userIdMapper.getUserId()),
118                                    
119                            userIdMapper.getType()
120                            }, userIdMapper);
121    
122                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_E,
123                            new Object[] {
124                                    userIdMapper.getType(),
125                                    
126                            userIdMapper.getExternalUserId()
127                            }, userIdMapper);
128            }
129    
130            /**
131             * Caches the user id mappers in the entity cache if it is enabled.
132             *
133             * @param userIdMappers the user id mappers to cache
134             */
135            public void cacheResult(List<UserIdMapper> userIdMappers) {
136                    for (UserIdMapper userIdMapper : userIdMappers) {
137                            if (EntityCacheUtil.getResult(
138                                                    UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
139                                                    UserIdMapperImpl.class, userIdMapper.getPrimaryKey(),
140                                                    this) == null) {
141                                    cacheResult(userIdMapper);
142                            }
143                    }
144            }
145    
146            /**
147             * Clears the cache for all user id mappers.
148             *
149             * <p>
150             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
151             * </p>
152             */
153            public void clearCache() {
154                    CacheRegistryUtil.clear(UserIdMapperImpl.class.getName());
155                    EntityCacheUtil.clearCache(UserIdMapperImpl.class.getName());
156                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
157                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
158            }
159    
160            /**
161             * Clears the cache for the user id mapper.
162             *
163             * <p>
164             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
165             * </p>
166             */
167            public void clearCache(UserIdMapper userIdMapper) {
168                    EntityCacheUtil.removeResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
169                            UserIdMapperImpl.class, userIdMapper.getPrimaryKey());
170    
171                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T,
172                            new Object[] {
173                                    new Long(userIdMapper.getUserId()),
174                                    
175                            userIdMapper.getType()
176                            });
177    
178                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_E,
179                            new Object[] {
180                                    userIdMapper.getType(),
181                                    
182                            userIdMapper.getExternalUserId()
183                            });
184            }
185    
186            /**
187             * Creates a new user id mapper with the primary key. Does not add the user id mapper to the database.
188             *
189             * @param userIdMapperId the primary key for the new user id mapper
190             * @return the new user id mapper
191             */
192            public UserIdMapper create(long userIdMapperId) {
193                    UserIdMapper userIdMapper = new UserIdMapperImpl();
194    
195                    userIdMapper.setNew(true);
196                    userIdMapper.setPrimaryKey(userIdMapperId);
197    
198                    return userIdMapper;
199            }
200    
201            /**
202             * Removes the user id mapper with the primary key from the database. Also notifies the appropriate model listeners.
203             *
204             * @param primaryKey the primary key of the user id mapper to remove
205             * @return the user id mapper that was removed
206             * @throws com.liferay.portal.NoSuchModelException if a user id mapper with the primary key could not be found
207             * @throws SystemException if a system exception occurred
208             */
209            public UserIdMapper remove(Serializable primaryKey)
210                    throws NoSuchModelException, SystemException {
211                    return remove(((Long)primaryKey).longValue());
212            }
213    
214            /**
215             * Removes the user id mapper with the primary key from the database. Also notifies the appropriate model listeners.
216             *
217             * @param userIdMapperId the primary key of the user id mapper to remove
218             * @return the user id mapper that was removed
219             * @throws com.liferay.portal.NoSuchUserIdMapperException if a user id mapper with the primary key could not be found
220             * @throws SystemException if a system exception occurred
221             */
222            public UserIdMapper remove(long userIdMapperId)
223                    throws NoSuchUserIdMapperException, SystemException {
224                    Session session = null;
225    
226                    try {
227                            session = openSession();
228    
229                            UserIdMapper userIdMapper = (UserIdMapper)session.get(UserIdMapperImpl.class,
230                                            new Long(userIdMapperId));
231    
232                            if (userIdMapper == null) {
233                                    if (_log.isWarnEnabled()) {
234                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
235                                                    userIdMapperId);
236                                    }
237    
238                                    throw new NoSuchUserIdMapperException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
239                                            userIdMapperId);
240                            }
241    
242                            return remove(userIdMapper);
243                    }
244                    catch (NoSuchUserIdMapperException nsee) {
245                            throw nsee;
246                    }
247                    catch (Exception e) {
248                            throw processException(e);
249                    }
250                    finally {
251                            closeSession(session);
252                    }
253            }
254    
255            protected UserIdMapper removeImpl(UserIdMapper userIdMapper)
256                    throws SystemException {
257                    userIdMapper = toUnwrappedModel(userIdMapper);
258    
259                    Session session = null;
260    
261                    try {
262                            session = openSession();
263    
264                            if (userIdMapper.isCachedModel() || BatchSessionUtil.isEnabled()) {
265                                    Object staleObject = session.get(UserIdMapperImpl.class,
266                                                    userIdMapper.getPrimaryKeyObj());
267    
268                                    if (staleObject != null) {
269                                            session.evict(staleObject);
270                                    }
271                            }
272    
273                            session.delete(userIdMapper);
274    
275                            session.flush();
276                    }
277                    catch (Exception e) {
278                            throw processException(e);
279                    }
280                    finally {
281                            closeSession(session);
282                    }
283    
284                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
285    
286                    UserIdMapperModelImpl userIdMapperModelImpl = (UserIdMapperModelImpl)userIdMapper;
287    
288                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T,
289                            new Object[] {
290                                    new Long(userIdMapperModelImpl.getOriginalUserId()),
291                                    
292                            userIdMapperModelImpl.getOriginalType()
293                            });
294    
295                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_E,
296                            new Object[] {
297                                    userIdMapperModelImpl.getOriginalType(),
298                                    
299                            userIdMapperModelImpl.getOriginalExternalUserId()
300                            });
301    
302                    EntityCacheUtil.removeResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
303                            UserIdMapperImpl.class, userIdMapper.getPrimaryKey());
304    
305                    return userIdMapper;
306            }
307    
308            public UserIdMapper updateImpl(
309                    com.liferay.portal.model.UserIdMapper userIdMapper, boolean merge)
310                    throws SystemException {
311                    userIdMapper = toUnwrappedModel(userIdMapper);
312    
313                    boolean isNew = userIdMapper.isNew();
314    
315                    UserIdMapperModelImpl userIdMapperModelImpl = (UserIdMapperModelImpl)userIdMapper;
316    
317                    Session session = null;
318    
319                    try {
320                            session = openSession();
321    
322                            BatchSessionUtil.update(session, userIdMapper, merge);
323    
324                            userIdMapper.setNew(false);
325                    }
326                    catch (Exception e) {
327                            throw processException(e);
328                    }
329                    finally {
330                            closeSession(session);
331                    }
332    
333                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
334    
335                    EntityCacheUtil.putResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
336                            UserIdMapperImpl.class, userIdMapper.getPrimaryKey(), userIdMapper);
337    
338                    if (!isNew &&
339                                    ((userIdMapper.getUserId() != userIdMapperModelImpl.getOriginalUserId()) ||
340                                    !Validator.equals(userIdMapper.getType(),
341                                            userIdMapperModelImpl.getOriginalType()))) {
342                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T,
343                                    new Object[] {
344                                            new Long(userIdMapperModelImpl.getOriginalUserId()),
345                                            
346                                    userIdMapperModelImpl.getOriginalType()
347                                    });
348                    }
349    
350                    if (isNew ||
351                                    ((userIdMapper.getUserId() != userIdMapperModelImpl.getOriginalUserId()) ||
352                                    !Validator.equals(userIdMapper.getType(),
353                                            userIdMapperModelImpl.getOriginalType()))) {
354                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
355                                    new Object[] {
356                                            new Long(userIdMapper.getUserId()),
357                                            
358                                    userIdMapper.getType()
359                                    }, userIdMapper);
360                    }
361    
362                    if (!isNew &&
363                                    (!Validator.equals(userIdMapper.getType(),
364                                            userIdMapperModelImpl.getOriginalType()) ||
365                                    !Validator.equals(userIdMapper.getExternalUserId(),
366                                            userIdMapperModelImpl.getOriginalExternalUserId()))) {
367                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_E,
368                                    new Object[] {
369                                            userIdMapperModelImpl.getOriginalType(),
370                                            
371                                    userIdMapperModelImpl.getOriginalExternalUserId()
372                                    });
373                    }
374    
375                    if (isNew ||
376                                    (!Validator.equals(userIdMapper.getType(),
377                                            userIdMapperModelImpl.getOriginalType()) ||
378                                    !Validator.equals(userIdMapper.getExternalUserId(),
379                                            userIdMapperModelImpl.getOriginalExternalUserId()))) {
380                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_E,
381                                    new Object[] {
382                                            userIdMapper.getType(),
383                                            
384                                    userIdMapper.getExternalUserId()
385                                    }, userIdMapper);
386                    }
387    
388                    return userIdMapper;
389            }
390    
391            protected UserIdMapper toUnwrappedModel(UserIdMapper userIdMapper) {
392                    if (userIdMapper instanceof UserIdMapperImpl) {
393                            return userIdMapper;
394                    }
395    
396                    UserIdMapperImpl userIdMapperImpl = new UserIdMapperImpl();
397    
398                    userIdMapperImpl.setNew(userIdMapper.isNew());
399                    userIdMapperImpl.setPrimaryKey(userIdMapper.getPrimaryKey());
400    
401                    userIdMapperImpl.setUserIdMapperId(userIdMapper.getUserIdMapperId());
402                    userIdMapperImpl.setUserId(userIdMapper.getUserId());
403                    userIdMapperImpl.setType(userIdMapper.getType());
404                    userIdMapperImpl.setDescription(userIdMapper.getDescription());
405                    userIdMapperImpl.setExternalUserId(userIdMapper.getExternalUserId());
406    
407                    return userIdMapperImpl;
408            }
409    
410            /**
411             * Finds the user id mapper with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
412             *
413             * @param primaryKey the primary key of the user id mapper to find
414             * @return the user id mapper
415             * @throws com.liferay.portal.NoSuchModelException if a user id mapper with the primary key could not be found
416             * @throws SystemException if a system exception occurred
417             */
418            public UserIdMapper findByPrimaryKey(Serializable primaryKey)
419                    throws NoSuchModelException, SystemException {
420                    return findByPrimaryKey(((Long)primaryKey).longValue());
421            }
422    
423            /**
424             * Finds the user id mapper with the primary key or throws a {@link com.liferay.portal.NoSuchUserIdMapperException} if it could not be found.
425             *
426             * @param userIdMapperId the primary key of the user id mapper to find
427             * @return the user id mapper
428             * @throws com.liferay.portal.NoSuchUserIdMapperException if a user id mapper with the primary key could not be found
429             * @throws SystemException if a system exception occurred
430             */
431            public UserIdMapper findByPrimaryKey(long userIdMapperId)
432                    throws NoSuchUserIdMapperException, SystemException {
433                    UserIdMapper userIdMapper = fetchByPrimaryKey(userIdMapperId);
434    
435                    if (userIdMapper == null) {
436                            if (_log.isWarnEnabled()) {
437                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + userIdMapperId);
438                            }
439    
440                            throw new NoSuchUserIdMapperException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
441                                    userIdMapperId);
442                    }
443    
444                    return userIdMapper;
445            }
446    
447            /**
448             * Finds the user id mapper with the primary key or returns <code>null</code> if it could not be found.
449             *
450             * @param primaryKey the primary key of the user id mapper to find
451             * @return the user id mapper, or <code>null</code> if a user id mapper with the primary key could not be found
452             * @throws SystemException if a system exception occurred
453             */
454            public UserIdMapper fetchByPrimaryKey(Serializable primaryKey)
455                    throws SystemException {
456                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
457            }
458    
459            /**
460             * Finds the user id mapper with the primary key or returns <code>null</code> if it could not be found.
461             *
462             * @param userIdMapperId the primary key of the user id mapper to find
463             * @return the user id mapper, or <code>null</code> if a user id mapper with the primary key could not be found
464             * @throws SystemException if a system exception occurred
465             */
466            public UserIdMapper fetchByPrimaryKey(long userIdMapperId)
467                    throws SystemException {
468                    UserIdMapper userIdMapper = (UserIdMapper)EntityCacheUtil.getResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
469                                    UserIdMapperImpl.class, userIdMapperId, this);
470    
471                    if (userIdMapper == null) {
472                            Session session = null;
473    
474                            try {
475                                    session = openSession();
476    
477                                    userIdMapper = (UserIdMapper)session.get(UserIdMapperImpl.class,
478                                                    new Long(userIdMapperId));
479                            }
480                            catch (Exception e) {
481                                    throw processException(e);
482                            }
483                            finally {
484                                    if (userIdMapper != null) {
485                                            cacheResult(userIdMapper);
486                                    }
487    
488                                    closeSession(session);
489                            }
490                    }
491    
492                    return userIdMapper;
493            }
494    
495            /**
496             * Finds all the user id mappers where userId = &#63;.
497             *
498             * @param userId the user id to search with
499             * @return the matching user id mappers
500             * @throws SystemException if a system exception occurred
501             */
502            public List<UserIdMapper> findByUserId(long userId)
503                    throws SystemException {
504                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
505            }
506    
507            /**
508             * Finds a range of all the user id mappers where userId = &#63;.
509             *
510             * <p>
511             * 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.
512             * </p>
513             *
514             * @param userId the user id to search with
515             * @param start the lower bound of the range of user id mappers to return
516             * @param end the upper bound of the range of user id mappers to return (not inclusive)
517             * @return the range of matching user id mappers
518             * @throws SystemException if a system exception occurred
519             */
520            public List<UserIdMapper> findByUserId(long userId, int start, int end)
521                    throws SystemException {
522                    return findByUserId(userId, start, end, null);
523            }
524    
525            /**
526             * Finds an ordered range of all the user id mappers where userId = &#63;.
527             *
528             * <p>
529             * 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.
530             * </p>
531             *
532             * @param userId the user id to search with
533             * @param start the lower bound of the range of user id mappers to return
534             * @param end the upper bound of the range of user id mappers to return (not inclusive)
535             * @param orderByComparator the comparator to order the results by
536             * @return the ordered range of matching user id mappers
537             * @throws SystemException if a system exception occurred
538             */
539            public List<UserIdMapper> findByUserId(long userId, int start, int end,
540                    OrderByComparator orderByComparator) throws SystemException {
541                    Object[] finderArgs = new Object[] {
542                                    userId,
543                                    
544                                    String.valueOf(start), String.valueOf(end),
545                                    String.valueOf(orderByComparator)
546                            };
547    
548                    List<UserIdMapper> list = (List<UserIdMapper>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
549                                    finderArgs, this);
550    
551                    if (list == null) {
552                            Session session = null;
553    
554                            try {
555                                    session = openSession();
556    
557                                    StringBundler query = null;
558    
559                                    if (orderByComparator != null) {
560                                            query = new StringBundler(3 +
561                                                            (orderByComparator.getOrderByFields().length * 3));
562                                    }
563                                    else {
564                                            query = new StringBundler(2);
565                                    }
566    
567                                    query.append(_SQL_SELECT_USERIDMAPPER_WHERE);
568    
569                                    query.append(_FINDER_COLUMN_USERID_USERID_2);
570    
571                                    if (orderByComparator != null) {
572                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
573                                                    orderByComparator);
574                                    }
575    
576                                    String sql = query.toString();
577    
578                                    Query q = session.createQuery(sql);
579    
580                                    QueryPos qPos = QueryPos.getInstance(q);
581    
582                                    qPos.add(userId);
583    
584                                    list = (List<UserIdMapper>)QueryUtil.list(q, getDialect(),
585                                                    start, end);
586                            }
587                            catch (Exception e) {
588                                    throw processException(e);
589                            }
590                            finally {
591                                    if (list == null) {
592                                            list = new ArrayList<UserIdMapper>();
593                                    }
594    
595                                    cacheResult(list);
596    
597                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
598                                            finderArgs, list);
599    
600                                    closeSession(session);
601                            }
602                    }
603    
604                    return list;
605            }
606    
607            /**
608             * Finds the first user id mapper in the ordered set where userId = &#63;.
609             *
610             * <p>
611             * 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.
612             * </p>
613             *
614             * @param userId the user id to search with
615             * @param orderByComparator the comparator to order the set by
616             * @return the first matching user id mapper
617             * @throws com.liferay.portal.NoSuchUserIdMapperException if a matching user id mapper could not be found
618             * @throws SystemException if a system exception occurred
619             */
620            public UserIdMapper findByUserId_First(long userId,
621                    OrderByComparator orderByComparator)
622                    throws NoSuchUserIdMapperException, SystemException {
623                    List<UserIdMapper> list = findByUserId(userId, 0, 1, orderByComparator);
624    
625                    if (list.isEmpty()) {
626                            StringBundler msg = new StringBundler(4);
627    
628                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
629    
630                            msg.append("userId=");
631                            msg.append(userId);
632    
633                            msg.append(StringPool.CLOSE_CURLY_BRACE);
634    
635                            throw new NoSuchUserIdMapperException(msg.toString());
636                    }
637                    else {
638                            return list.get(0);
639                    }
640            }
641    
642            /**
643             * Finds the last user id mapper in the ordered set where userId = &#63;.
644             *
645             * <p>
646             * 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.
647             * </p>
648             *
649             * @param userId the user id to search with
650             * @param orderByComparator the comparator to order the set by
651             * @return the last matching user id mapper
652             * @throws com.liferay.portal.NoSuchUserIdMapperException if a matching user id mapper could not be found
653             * @throws SystemException if a system exception occurred
654             */
655            public UserIdMapper findByUserId_Last(long userId,
656                    OrderByComparator orderByComparator)
657                    throws NoSuchUserIdMapperException, SystemException {
658                    int count = countByUserId(userId);
659    
660                    List<UserIdMapper> list = findByUserId(userId, count - 1, count,
661                                    orderByComparator);
662    
663                    if (list.isEmpty()) {
664                            StringBundler msg = new StringBundler(4);
665    
666                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
667    
668                            msg.append("userId=");
669                            msg.append(userId);
670    
671                            msg.append(StringPool.CLOSE_CURLY_BRACE);
672    
673                            throw new NoSuchUserIdMapperException(msg.toString());
674                    }
675                    else {
676                            return list.get(0);
677                    }
678            }
679    
680            /**
681             * Finds the user id mappers before and after the current user id mapper in the ordered set where userId = &#63;.
682             *
683             * <p>
684             * 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.
685             * </p>
686             *
687             * @param userIdMapperId the primary key of the current user id mapper
688             * @param userId the user id to search with
689             * @param orderByComparator the comparator to order the set by
690             * @return the previous, current, and next user id mapper
691             * @throws com.liferay.portal.NoSuchUserIdMapperException if a user id mapper with the primary key could not be found
692             * @throws SystemException if a system exception occurred
693             */
694            public UserIdMapper[] findByUserId_PrevAndNext(long userIdMapperId,
695                    long userId, OrderByComparator orderByComparator)
696                    throws NoSuchUserIdMapperException, SystemException {
697                    UserIdMapper userIdMapper = findByPrimaryKey(userIdMapperId);
698    
699                    Session session = null;
700    
701                    try {
702                            session = openSession();
703    
704                            UserIdMapper[] array = new UserIdMapperImpl[3];
705    
706                            array[0] = getByUserId_PrevAndNext(session, userIdMapper, userId,
707                                            orderByComparator, true);
708    
709                            array[1] = userIdMapper;
710    
711                            array[2] = getByUserId_PrevAndNext(session, userIdMapper, userId,
712                                            orderByComparator, false);
713    
714                            return array;
715                    }
716                    catch (Exception e) {
717                            throw processException(e);
718                    }
719                    finally {
720                            closeSession(session);
721                    }
722            }
723    
724            protected UserIdMapper getByUserId_PrevAndNext(Session session,
725                    UserIdMapper userIdMapper, long userId,
726                    OrderByComparator orderByComparator, boolean previous) {
727                    StringBundler query = null;
728    
729                    if (orderByComparator != null) {
730                            query = new StringBundler(6 +
731                                            (orderByComparator.getOrderByFields().length * 6));
732                    }
733                    else {
734                            query = new StringBundler(3);
735                    }
736    
737                    query.append(_SQL_SELECT_USERIDMAPPER_WHERE);
738    
739                    query.append(_FINDER_COLUMN_USERID_USERID_2);
740    
741                    if (orderByComparator != null) {
742                            String[] orderByFields = orderByComparator.getOrderByFields();
743    
744                            if (orderByFields.length > 0) {
745                                    query.append(WHERE_AND);
746                            }
747    
748                            for (int i = 0; i < orderByFields.length; i++) {
749                                    query.append(_ORDER_BY_ENTITY_ALIAS);
750                                    query.append(orderByFields[i]);
751    
752                                    if ((i + 1) < orderByFields.length) {
753                                            if (orderByComparator.isAscending() ^ previous) {
754                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
755                                            }
756                                            else {
757                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
758                                            }
759                                    }
760                                    else {
761                                            if (orderByComparator.isAscending() ^ previous) {
762                                                    query.append(WHERE_GREATER_THAN);
763                                            }
764                                            else {
765                                                    query.append(WHERE_LESSER_THAN);
766                                            }
767                                    }
768                            }
769    
770                            query.append(ORDER_BY_CLAUSE);
771    
772                            for (int i = 0; i < orderByFields.length; i++) {
773                                    query.append(_ORDER_BY_ENTITY_ALIAS);
774                                    query.append(orderByFields[i]);
775    
776                                    if ((i + 1) < orderByFields.length) {
777                                            if (orderByComparator.isAscending() ^ previous) {
778                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
779                                            }
780                                            else {
781                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
782                                            }
783                                    }
784                                    else {
785                                            if (orderByComparator.isAscending() ^ previous) {
786                                                    query.append(ORDER_BY_ASC);
787                                            }
788                                            else {
789                                                    query.append(ORDER_BY_DESC);
790                                            }
791                                    }
792                            }
793                    }
794    
795                    String sql = query.toString();
796    
797                    Query q = session.createQuery(sql);
798    
799                    q.setFirstResult(0);
800                    q.setMaxResults(2);
801    
802                    QueryPos qPos = QueryPos.getInstance(q);
803    
804                    qPos.add(userId);
805    
806                    if (orderByComparator != null) {
807                            Object[] values = orderByComparator.getOrderByValues(userIdMapper);
808    
809                            for (Object value : values) {
810                                    qPos.add(value);
811                            }
812                    }
813    
814                    List<UserIdMapper> list = q.list();
815    
816                    if (list.size() == 2) {
817                            return list.get(1);
818                    }
819                    else {
820                            return null;
821                    }
822            }
823    
824            /**
825             * Finds the user id mapper where userId = &#63; and type = &#63; or throws a {@link com.liferay.portal.NoSuchUserIdMapperException} if it could not be found.
826             *
827             * @param userId the user id to search with
828             * @param type the type to search with
829             * @return the matching user id mapper
830             * @throws com.liferay.portal.NoSuchUserIdMapperException if a matching user id mapper could not be found
831             * @throws SystemException if a system exception occurred
832             */
833            public UserIdMapper findByU_T(long userId, String type)
834                    throws NoSuchUserIdMapperException, SystemException {
835                    UserIdMapper userIdMapper = fetchByU_T(userId, type);
836    
837                    if (userIdMapper == null) {
838                            StringBundler msg = new StringBundler(6);
839    
840                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
841    
842                            msg.append("userId=");
843                            msg.append(userId);
844    
845                            msg.append(", type=");
846                            msg.append(type);
847    
848                            msg.append(StringPool.CLOSE_CURLY_BRACE);
849    
850                            if (_log.isWarnEnabled()) {
851                                    _log.warn(msg.toString());
852                            }
853    
854                            throw new NoSuchUserIdMapperException(msg.toString());
855                    }
856    
857                    return userIdMapper;
858            }
859    
860            /**
861             * Finds the user id mapper where userId = &#63; and type = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
862             *
863             * @param userId the user id to search with
864             * @param type the type to search with
865             * @return the matching user id mapper, or <code>null</code> if a matching user id mapper could not be found
866             * @throws SystemException if a system exception occurred
867             */
868            public UserIdMapper fetchByU_T(long userId, String type)
869                    throws SystemException {
870                    return fetchByU_T(userId, type, true);
871            }
872    
873            /**
874             * Finds the user id mapper where userId = &#63; and type = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
875             *
876             * @param userId the user id to search with
877             * @param type the type to search with
878             * @return the matching user id mapper, or <code>null</code> if a matching user id mapper could not be found
879             * @throws SystemException if a system exception occurred
880             */
881            public UserIdMapper fetchByU_T(long userId, String type,
882                    boolean retrieveFromCache) throws SystemException {
883                    Object[] finderArgs = new Object[] { userId, type };
884    
885                    Object result = null;
886    
887                    if (retrieveFromCache) {
888                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_T,
889                                            finderArgs, this);
890                    }
891    
892                    if (result == null) {
893                            Session session = null;
894    
895                            try {
896                                    session = openSession();
897    
898                                    StringBundler query = new StringBundler(3);
899    
900                                    query.append(_SQL_SELECT_USERIDMAPPER_WHERE);
901    
902                                    query.append(_FINDER_COLUMN_U_T_USERID_2);
903    
904                                    if (type == null) {
905                                            query.append(_FINDER_COLUMN_U_T_TYPE_1);
906                                    }
907                                    else {
908                                            if (type.equals(StringPool.BLANK)) {
909                                                    query.append(_FINDER_COLUMN_U_T_TYPE_3);
910                                            }
911                                            else {
912                                                    query.append(_FINDER_COLUMN_U_T_TYPE_2);
913                                            }
914                                    }
915    
916                                    String sql = query.toString();
917    
918                                    Query q = session.createQuery(sql);
919    
920                                    QueryPos qPos = QueryPos.getInstance(q);
921    
922                                    qPos.add(userId);
923    
924                                    if (type != null) {
925                                            qPos.add(type);
926                                    }
927    
928                                    List<UserIdMapper> list = q.list();
929    
930                                    result = list;
931    
932                                    UserIdMapper userIdMapper = null;
933    
934                                    if (list.isEmpty()) {
935                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
936                                                    finderArgs, list);
937                                    }
938                                    else {
939                                            userIdMapper = list.get(0);
940    
941                                            cacheResult(userIdMapper);
942    
943                                            if ((userIdMapper.getUserId() != userId) ||
944                                                            (userIdMapper.getType() == null) ||
945                                                            !userIdMapper.getType().equals(type)) {
946                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
947                                                            finderArgs, userIdMapper);
948                                            }
949                                    }
950    
951                                    return userIdMapper;
952                            }
953                            catch (Exception e) {
954                                    throw processException(e);
955                            }
956                            finally {
957                                    if (result == null) {
958                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
959                                                    finderArgs, new ArrayList<UserIdMapper>());
960                                    }
961    
962                                    closeSession(session);
963                            }
964                    }
965                    else {
966                            if (result instanceof List<?>) {
967                                    return null;
968                            }
969                            else {
970                                    return (UserIdMapper)result;
971                            }
972                    }
973            }
974    
975            /**
976             * Finds the user id mapper where type = &#63; and externalUserId = &#63; or throws a {@link com.liferay.portal.NoSuchUserIdMapperException} if it could not be found.
977             *
978             * @param type the type to search with
979             * @param externalUserId the external user id to search with
980             * @return the matching user id mapper
981             * @throws com.liferay.portal.NoSuchUserIdMapperException if a matching user id mapper could not be found
982             * @throws SystemException if a system exception occurred
983             */
984            public UserIdMapper findByT_E(String type, String externalUserId)
985                    throws NoSuchUserIdMapperException, SystemException {
986                    UserIdMapper userIdMapper = fetchByT_E(type, externalUserId);
987    
988                    if (userIdMapper == null) {
989                            StringBundler msg = new StringBundler(6);
990    
991                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
992    
993                            msg.append("type=");
994                            msg.append(type);
995    
996                            msg.append(", externalUserId=");
997                            msg.append(externalUserId);
998    
999                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1000    
1001                            if (_log.isWarnEnabled()) {
1002                                    _log.warn(msg.toString());
1003                            }
1004    
1005                            throw new NoSuchUserIdMapperException(msg.toString());
1006                    }
1007    
1008                    return userIdMapper;
1009            }
1010    
1011            /**
1012             * Finds the user id mapper where type = &#63; and externalUserId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1013             *
1014             * @param type the type to search with
1015             * @param externalUserId the external user id to search with
1016             * @return the matching user id mapper, or <code>null</code> if a matching user id mapper could not be found
1017             * @throws SystemException if a system exception occurred
1018             */
1019            public UserIdMapper fetchByT_E(String type, String externalUserId)
1020                    throws SystemException {
1021                    return fetchByT_E(type, externalUserId, true);
1022            }
1023    
1024            /**
1025             * Finds the user id mapper where type = &#63; and externalUserId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1026             *
1027             * @param type the type to search with
1028             * @param externalUserId the external user id to search with
1029             * @return the matching user id mapper, or <code>null</code> if a matching user id mapper could not be found
1030             * @throws SystemException if a system exception occurred
1031             */
1032            public UserIdMapper fetchByT_E(String type, String externalUserId,
1033                    boolean retrieveFromCache) throws SystemException {
1034                    Object[] finderArgs = new Object[] { type, externalUserId };
1035    
1036                    Object result = null;
1037    
1038                    if (retrieveFromCache) {
1039                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_T_E,
1040                                            finderArgs, this);
1041                    }
1042    
1043                    if (result == null) {
1044                            Session session = null;
1045    
1046                            try {
1047                                    session = openSession();
1048    
1049                                    StringBundler query = new StringBundler(3);
1050    
1051                                    query.append(_SQL_SELECT_USERIDMAPPER_WHERE);
1052    
1053                                    if (type == null) {
1054                                            query.append(_FINDER_COLUMN_T_E_TYPE_1);
1055                                    }
1056                                    else {
1057                                            if (type.equals(StringPool.BLANK)) {
1058                                                    query.append(_FINDER_COLUMN_T_E_TYPE_3);
1059                                            }
1060                                            else {
1061                                                    query.append(_FINDER_COLUMN_T_E_TYPE_2);
1062                                            }
1063                                    }
1064    
1065                                    if (externalUserId == null) {
1066                                            query.append(_FINDER_COLUMN_T_E_EXTERNALUSERID_1);
1067                                    }
1068                                    else {
1069                                            if (externalUserId.equals(StringPool.BLANK)) {
1070                                                    query.append(_FINDER_COLUMN_T_E_EXTERNALUSERID_3);
1071                                            }
1072                                            else {
1073                                                    query.append(_FINDER_COLUMN_T_E_EXTERNALUSERID_2);
1074                                            }
1075                                    }
1076    
1077                                    String sql = query.toString();
1078    
1079                                    Query q = session.createQuery(sql);
1080    
1081                                    QueryPos qPos = QueryPos.getInstance(q);
1082    
1083                                    if (type != null) {
1084                                            qPos.add(type);
1085                                    }
1086    
1087                                    if (externalUserId != null) {
1088                                            qPos.add(externalUserId);
1089                                    }
1090    
1091                                    List<UserIdMapper> list = q.list();
1092    
1093                                    result = list;
1094    
1095                                    UserIdMapper userIdMapper = null;
1096    
1097                                    if (list.isEmpty()) {
1098                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_E,
1099                                                    finderArgs, list);
1100                                    }
1101                                    else {
1102                                            userIdMapper = list.get(0);
1103    
1104                                            cacheResult(userIdMapper);
1105    
1106                                            if ((userIdMapper.getType() == null) ||
1107                                                            !userIdMapper.getType().equals(type) ||
1108                                                            (userIdMapper.getExternalUserId() == null) ||
1109                                                            !userIdMapper.getExternalUserId()
1110                                                                                             .equals(externalUserId)) {
1111                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_E,
1112                                                            finderArgs, userIdMapper);
1113                                            }
1114                                    }
1115    
1116                                    return userIdMapper;
1117                            }
1118                            catch (Exception e) {
1119                                    throw processException(e);
1120                            }
1121                            finally {
1122                                    if (result == null) {
1123                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_E,
1124                                                    finderArgs, new ArrayList<UserIdMapper>());
1125                                    }
1126    
1127                                    closeSession(session);
1128                            }
1129                    }
1130                    else {
1131                            if (result instanceof List<?>) {
1132                                    return null;
1133                            }
1134                            else {
1135                                    return (UserIdMapper)result;
1136                            }
1137                    }
1138            }
1139    
1140            /**
1141             * Finds all the user id mappers.
1142             *
1143             * @return the user id mappers
1144             * @throws SystemException if a system exception occurred
1145             */
1146            public List<UserIdMapper> findAll() throws SystemException {
1147                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1148            }
1149    
1150            /**
1151             * Finds a range of all the user id mappers.
1152             *
1153             * <p>
1154             * 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.
1155             * </p>
1156             *
1157             * @param start the lower bound of the range of user id mappers to return
1158             * @param end the upper bound of the range of user id mappers to return (not inclusive)
1159             * @return the range of user id mappers
1160             * @throws SystemException if a system exception occurred
1161             */
1162            public List<UserIdMapper> findAll(int start, int end)
1163                    throws SystemException {
1164                    return findAll(start, end, null);
1165            }
1166    
1167            /**
1168             * Finds an ordered range of all the user id mappers.
1169             *
1170             * <p>
1171             * 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.
1172             * </p>
1173             *
1174             * @param start the lower bound of the range of user id mappers to return
1175             * @param end the upper bound of the range of user id mappers to return (not inclusive)
1176             * @param orderByComparator the comparator to order the results by
1177             * @return the ordered range of user id mappers
1178             * @throws SystemException if a system exception occurred
1179             */
1180            public List<UserIdMapper> findAll(int start, int end,
1181                    OrderByComparator orderByComparator) throws SystemException {
1182                    Object[] finderArgs = new Object[] {
1183                                    String.valueOf(start), String.valueOf(end),
1184                                    String.valueOf(orderByComparator)
1185                            };
1186    
1187                    List<UserIdMapper> list = (List<UserIdMapper>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1188                                    finderArgs, this);
1189    
1190                    if (list == null) {
1191                            Session session = null;
1192    
1193                            try {
1194                                    session = openSession();
1195    
1196                                    StringBundler query = null;
1197                                    String sql = null;
1198    
1199                                    if (orderByComparator != null) {
1200                                            query = new StringBundler(2 +
1201                                                            (orderByComparator.getOrderByFields().length * 3));
1202    
1203                                            query.append(_SQL_SELECT_USERIDMAPPER);
1204    
1205                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1206                                                    orderByComparator);
1207    
1208                                            sql = query.toString();
1209                                    }
1210                                    else {
1211                                            sql = _SQL_SELECT_USERIDMAPPER;
1212                                    }
1213    
1214                                    Query q = session.createQuery(sql);
1215    
1216                                    if (orderByComparator == null) {
1217                                            list = (List<UserIdMapper>)QueryUtil.list(q, getDialect(),
1218                                                            start, end, false);
1219    
1220                                            Collections.sort(list);
1221                                    }
1222                                    else {
1223                                            list = (List<UserIdMapper>)QueryUtil.list(q, getDialect(),
1224                                                            start, end);
1225                                    }
1226                            }
1227                            catch (Exception e) {
1228                                    throw processException(e);
1229                            }
1230                            finally {
1231                                    if (list == null) {
1232                                            list = new ArrayList<UserIdMapper>();
1233                                    }
1234    
1235                                    cacheResult(list);
1236    
1237                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1238    
1239                                    closeSession(session);
1240                            }
1241                    }
1242    
1243                    return list;
1244            }
1245    
1246            /**
1247             * Removes all the user id mappers where userId = &#63; from the database.
1248             *
1249             * @param userId the user id to search with
1250             * @throws SystemException if a system exception occurred
1251             */
1252            public void removeByUserId(long userId) throws SystemException {
1253                    for (UserIdMapper userIdMapper : findByUserId(userId)) {
1254                            remove(userIdMapper);
1255                    }
1256            }
1257    
1258            /**
1259             * Removes the user id mapper where userId = &#63; and type = &#63; from the database.
1260             *
1261             * @param userId the user id to search with
1262             * @param type the type to search with
1263             * @throws SystemException if a system exception occurred
1264             */
1265            public void removeByU_T(long userId, String type)
1266                    throws NoSuchUserIdMapperException, SystemException {
1267                    UserIdMapper userIdMapper = findByU_T(userId, type);
1268    
1269                    remove(userIdMapper);
1270            }
1271    
1272            /**
1273             * Removes the user id mapper where type = &#63; and externalUserId = &#63; from the database.
1274             *
1275             * @param type the type to search with
1276             * @param externalUserId the external user id to search with
1277             * @throws SystemException if a system exception occurred
1278             */
1279            public void removeByT_E(String type, String externalUserId)
1280                    throws NoSuchUserIdMapperException, SystemException {
1281                    UserIdMapper userIdMapper = findByT_E(type, externalUserId);
1282    
1283                    remove(userIdMapper);
1284            }
1285    
1286            /**
1287             * Removes all the user id mappers from the database.
1288             *
1289             * @throws SystemException if a system exception occurred
1290             */
1291            public void removeAll() throws SystemException {
1292                    for (UserIdMapper userIdMapper : findAll()) {
1293                            remove(userIdMapper);
1294                    }
1295            }
1296    
1297            /**
1298             * Counts all the user id mappers where userId = &#63;.
1299             *
1300             * @param userId the user id to search with
1301             * @return the number of matching user id mappers
1302             * @throws SystemException if a system exception occurred
1303             */
1304            public int countByUserId(long userId) throws SystemException {
1305                    Object[] finderArgs = new Object[] { userId };
1306    
1307                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1308                                    finderArgs, this);
1309    
1310                    if (count == null) {
1311                            Session session = null;
1312    
1313                            try {
1314                                    session = openSession();
1315    
1316                                    StringBundler query = new StringBundler(2);
1317    
1318                                    query.append(_SQL_COUNT_USERIDMAPPER_WHERE);
1319    
1320                                    query.append(_FINDER_COLUMN_USERID_USERID_2);
1321    
1322                                    String sql = query.toString();
1323    
1324                                    Query q = session.createQuery(sql);
1325    
1326                                    QueryPos qPos = QueryPos.getInstance(q);
1327    
1328                                    qPos.add(userId);
1329    
1330                                    count = (Long)q.uniqueResult();
1331                            }
1332                            catch (Exception e) {
1333                                    throw processException(e);
1334                            }
1335                            finally {
1336                                    if (count == null) {
1337                                            count = Long.valueOf(0);
1338                                    }
1339    
1340                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1341                                            finderArgs, count);
1342    
1343                                    closeSession(session);
1344                            }
1345                    }
1346    
1347                    return count.intValue();
1348            }
1349    
1350            /**
1351             * Counts all the user id mappers where userId = &#63; and type = &#63;.
1352             *
1353             * @param userId the user id to search with
1354             * @param type the type to search with
1355             * @return the number of matching user id mappers
1356             * @throws SystemException if a system exception occurred
1357             */
1358            public int countByU_T(long userId, String type) throws SystemException {
1359                    Object[] finderArgs = new Object[] { userId, type };
1360    
1361                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_T,
1362                                    finderArgs, this);
1363    
1364                    if (count == null) {
1365                            Session session = null;
1366    
1367                            try {
1368                                    session = openSession();
1369    
1370                                    StringBundler query = new StringBundler(3);
1371    
1372                                    query.append(_SQL_COUNT_USERIDMAPPER_WHERE);
1373    
1374                                    query.append(_FINDER_COLUMN_U_T_USERID_2);
1375    
1376                                    if (type == null) {
1377                                            query.append(_FINDER_COLUMN_U_T_TYPE_1);
1378                                    }
1379                                    else {
1380                                            if (type.equals(StringPool.BLANK)) {
1381                                                    query.append(_FINDER_COLUMN_U_T_TYPE_3);
1382                                            }
1383                                            else {
1384                                                    query.append(_FINDER_COLUMN_U_T_TYPE_2);
1385                                            }
1386                                    }
1387    
1388                                    String sql = query.toString();
1389    
1390                                    Query q = session.createQuery(sql);
1391    
1392                                    QueryPos qPos = QueryPos.getInstance(q);
1393    
1394                                    qPos.add(userId);
1395    
1396                                    if (type != null) {
1397                                            qPos.add(type);
1398                                    }
1399    
1400                                    count = (Long)q.uniqueResult();
1401                            }
1402                            catch (Exception e) {
1403                                    throw processException(e);
1404                            }
1405                            finally {
1406                                    if (count == null) {
1407                                            count = Long.valueOf(0);
1408                                    }
1409    
1410                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T, finderArgs,
1411                                            count);
1412    
1413                                    closeSession(session);
1414                            }
1415                    }
1416    
1417                    return count.intValue();
1418            }
1419    
1420            /**
1421             * Counts all the user id mappers where type = &#63; and externalUserId = &#63;.
1422             *
1423             * @param type the type to search with
1424             * @param externalUserId the external user id to search with
1425             * @return the number of matching user id mappers
1426             * @throws SystemException if a system exception occurred
1427             */
1428            public int countByT_E(String type, String externalUserId)
1429                    throws SystemException {
1430                    Object[] finderArgs = new Object[] { type, externalUserId };
1431    
1432                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_E,
1433                                    finderArgs, this);
1434    
1435                    if (count == null) {
1436                            Session session = null;
1437    
1438                            try {
1439                                    session = openSession();
1440    
1441                                    StringBundler query = new StringBundler(3);
1442    
1443                                    query.append(_SQL_COUNT_USERIDMAPPER_WHERE);
1444    
1445                                    if (type == null) {
1446                                            query.append(_FINDER_COLUMN_T_E_TYPE_1);
1447                                    }
1448                                    else {
1449                                            if (type.equals(StringPool.BLANK)) {
1450                                                    query.append(_FINDER_COLUMN_T_E_TYPE_3);
1451                                            }
1452                                            else {
1453                                                    query.append(_FINDER_COLUMN_T_E_TYPE_2);
1454                                            }
1455                                    }
1456    
1457                                    if (externalUserId == null) {
1458                                            query.append(_FINDER_COLUMN_T_E_EXTERNALUSERID_1);
1459                                    }
1460                                    else {
1461                                            if (externalUserId.equals(StringPool.BLANK)) {
1462                                                    query.append(_FINDER_COLUMN_T_E_EXTERNALUSERID_3);
1463                                            }
1464                                            else {
1465                                                    query.append(_FINDER_COLUMN_T_E_EXTERNALUSERID_2);
1466                                            }
1467                                    }
1468    
1469                                    String sql = query.toString();
1470    
1471                                    Query q = session.createQuery(sql);
1472    
1473                                    QueryPos qPos = QueryPos.getInstance(q);
1474    
1475                                    if (type != null) {
1476                                            qPos.add(type);
1477                                    }
1478    
1479                                    if (externalUserId != null) {
1480                                            qPos.add(externalUserId);
1481                                    }
1482    
1483                                    count = (Long)q.uniqueResult();
1484                            }
1485                            catch (Exception e) {
1486                                    throw processException(e);
1487                            }
1488                            finally {
1489                                    if (count == null) {
1490                                            count = Long.valueOf(0);
1491                                    }
1492    
1493                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_E, finderArgs,
1494                                            count);
1495    
1496                                    closeSession(session);
1497                            }
1498                    }
1499    
1500                    return count.intValue();
1501            }
1502    
1503            /**
1504             * Counts all the user id mappers.
1505             *
1506             * @return the number of user id mappers
1507             * @throws SystemException if a system exception occurred
1508             */
1509            public int countAll() throws SystemException {
1510                    Object[] finderArgs = new Object[0];
1511    
1512                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1513                                    finderArgs, this);
1514    
1515                    if (count == null) {
1516                            Session session = null;
1517    
1518                            try {
1519                                    session = openSession();
1520    
1521                                    Query q = session.createQuery(_SQL_COUNT_USERIDMAPPER);
1522    
1523                                    count = (Long)q.uniqueResult();
1524                            }
1525                            catch (Exception e) {
1526                                    throw processException(e);
1527                            }
1528                            finally {
1529                                    if (count == null) {
1530                                            count = Long.valueOf(0);
1531                                    }
1532    
1533                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1534                                            count);
1535    
1536                                    closeSession(session);
1537                            }
1538                    }
1539    
1540                    return count.intValue();
1541            }
1542    
1543            /**
1544             * Initializes the user id mapper persistence.
1545             */
1546            public void afterPropertiesSet() {
1547                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1548                                            com.liferay.portal.util.PropsUtil.get(
1549                                                    "value.object.listener.com.liferay.portal.model.UserIdMapper")));
1550    
1551                    if (listenerClassNames.length > 0) {
1552                            try {
1553                                    List<ModelListener<UserIdMapper>> listenersList = new ArrayList<ModelListener<UserIdMapper>>();
1554    
1555                                    for (String listenerClassName : listenerClassNames) {
1556                                            listenersList.add((ModelListener<UserIdMapper>)InstanceFactory.newInstance(
1557                                                            listenerClassName));
1558                                    }
1559    
1560                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1561                            }
1562                            catch (Exception e) {
1563                                    _log.error(e);
1564                            }
1565                    }
1566            }
1567    
1568            @BeanReference(type = AccountPersistence.class)
1569            protected AccountPersistence accountPersistence;
1570            @BeanReference(type = AddressPersistence.class)
1571            protected AddressPersistence addressPersistence;
1572            @BeanReference(type = BrowserTrackerPersistence.class)
1573            protected BrowserTrackerPersistence browserTrackerPersistence;
1574            @BeanReference(type = ClassNamePersistence.class)
1575            protected ClassNamePersistence classNamePersistence;
1576            @BeanReference(type = ClusterGroupPersistence.class)
1577            protected ClusterGroupPersistence clusterGroupPersistence;
1578            @BeanReference(type = CompanyPersistence.class)
1579            protected CompanyPersistence companyPersistence;
1580            @BeanReference(type = ContactPersistence.class)
1581            protected ContactPersistence contactPersistence;
1582            @BeanReference(type = CountryPersistence.class)
1583            protected CountryPersistence countryPersistence;
1584            @BeanReference(type = EmailAddressPersistence.class)
1585            protected EmailAddressPersistence emailAddressPersistence;
1586            @BeanReference(type = GroupPersistence.class)
1587            protected GroupPersistence groupPersistence;
1588            @BeanReference(type = ImagePersistence.class)
1589            protected ImagePersistence imagePersistence;
1590            @BeanReference(type = LayoutPersistence.class)
1591            protected LayoutPersistence layoutPersistence;
1592            @BeanReference(type = LayoutPrototypePersistence.class)
1593            protected LayoutPrototypePersistence layoutPrototypePersistence;
1594            @BeanReference(type = LayoutSetPersistence.class)
1595            protected LayoutSetPersistence layoutSetPersistence;
1596            @BeanReference(type = LayoutSetPrototypePersistence.class)
1597            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1598            @BeanReference(type = ListTypePersistence.class)
1599            protected ListTypePersistence listTypePersistence;
1600            @BeanReference(type = LockPersistence.class)
1601            protected LockPersistence lockPersistence;
1602            @BeanReference(type = MembershipRequestPersistence.class)
1603            protected MembershipRequestPersistence membershipRequestPersistence;
1604            @BeanReference(type = OrganizationPersistence.class)
1605            protected OrganizationPersistence organizationPersistence;
1606            @BeanReference(type = OrgGroupPermissionPersistence.class)
1607            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1608            @BeanReference(type = OrgGroupRolePersistence.class)
1609            protected OrgGroupRolePersistence orgGroupRolePersistence;
1610            @BeanReference(type = OrgLaborPersistence.class)
1611            protected OrgLaborPersistence orgLaborPersistence;
1612            @BeanReference(type = PasswordPolicyPersistence.class)
1613            protected PasswordPolicyPersistence passwordPolicyPersistence;
1614            @BeanReference(type = PasswordPolicyRelPersistence.class)
1615            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1616            @BeanReference(type = PasswordTrackerPersistence.class)
1617            protected PasswordTrackerPersistence passwordTrackerPersistence;
1618            @BeanReference(type = PermissionPersistence.class)
1619            protected PermissionPersistence permissionPersistence;
1620            @BeanReference(type = PhonePersistence.class)
1621            protected PhonePersistence phonePersistence;
1622            @BeanReference(type = PluginSettingPersistence.class)
1623            protected PluginSettingPersistence pluginSettingPersistence;
1624            @BeanReference(type = PortletPersistence.class)
1625            protected PortletPersistence portletPersistence;
1626            @BeanReference(type = PortletItemPersistence.class)
1627            protected PortletItemPersistence portletItemPersistence;
1628            @BeanReference(type = PortletPreferencesPersistence.class)
1629            protected PortletPreferencesPersistence portletPreferencesPersistence;
1630            @BeanReference(type = RegionPersistence.class)
1631            protected RegionPersistence regionPersistence;
1632            @BeanReference(type = ReleasePersistence.class)
1633            protected ReleasePersistence releasePersistence;
1634            @BeanReference(type = ResourcePersistence.class)
1635            protected ResourcePersistence resourcePersistence;
1636            @BeanReference(type = ResourceActionPersistence.class)
1637            protected ResourceActionPersistence resourceActionPersistence;
1638            @BeanReference(type = ResourceCodePersistence.class)
1639            protected ResourceCodePersistence resourceCodePersistence;
1640            @BeanReference(type = ResourcePermissionPersistence.class)
1641            protected ResourcePermissionPersistence resourcePermissionPersistence;
1642            @BeanReference(type = RolePersistence.class)
1643            protected RolePersistence rolePersistence;
1644            @BeanReference(type = ServiceComponentPersistence.class)
1645            protected ServiceComponentPersistence serviceComponentPersistence;
1646            @BeanReference(type = ShardPersistence.class)
1647            protected ShardPersistence shardPersistence;
1648            @BeanReference(type = SubscriptionPersistence.class)
1649            protected SubscriptionPersistence subscriptionPersistence;
1650            @BeanReference(type = TicketPersistence.class)
1651            protected TicketPersistence ticketPersistence;
1652            @BeanReference(type = TeamPersistence.class)
1653            protected TeamPersistence teamPersistence;
1654            @BeanReference(type = UserPersistence.class)
1655            protected UserPersistence userPersistence;
1656            @BeanReference(type = UserGroupPersistence.class)
1657            protected UserGroupPersistence userGroupPersistence;
1658            @BeanReference(type = UserGroupGroupRolePersistence.class)
1659            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1660            @BeanReference(type = UserGroupRolePersistence.class)
1661            protected UserGroupRolePersistence userGroupRolePersistence;
1662            @BeanReference(type = UserIdMapperPersistence.class)
1663            protected UserIdMapperPersistence userIdMapperPersistence;
1664            @BeanReference(type = UserTrackerPersistence.class)
1665            protected UserTrackerPersistence userTrackerPersistence;
1666            @BeanReference(type = UserTrackerPathPersistence.class)
1667            protected UserTrackerPathPersistence userTrackerPathPersistence;
1668            @BeanReference(type = WebDAVPropsPersistence.class)
1669            protected WebDAVPropsPersistence webDAVPropsPersistence;
1670            @BeanReference(type = WebsitePersistence.class)
1671            protected WebsitePersistence websitePersistence;
1672            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1673            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1674            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1675            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1676            private static final String _SQL_SELECT_USERIDMAPPER = "SELECT userIdMapper FROM UserIdMapper userIdMapper";
1677            private static final String _SQL_SELECT_USERIDMAPPER_WHERE = "SELECT userIdMapper FROM UserIdMapper userIdMapper WHERE ";
1678            private static final String _SQL_COUNT_USERIDMAPPER = "SELECT COUNT(userIdMapper) FROM UserIdMapper userIdMapper";
1679            private static final String _SQL_COUNT_USERIDMAPPER_WHERE = "SELECT COUNT(userIdMapper) FROM UserIdMapper userIdMapper WHERE ";
1680            private static final String _FINDER_COLUMN_USERID_USERID_2 = "userIdMapper.userId = ?";
1681            private static final String _FINDER_COLUMN_U_T_USERID_2 = "userIdMapper.userId = ? AND ";
1682            private static final String _FINDER_COLUMN_U_T_TYPE_1 = "userIdMapper.type IS NULL";
1683            private static final String _FINDER_COLUMN_U_T_TYPE_2 = "userIdMapper.type = ?";
1684            private static final String _FINDER_COLUMN_U_T_TYPE_3 = "(userIdMapper.type IS NULL OR userIdMapper.type = ?)";
1685            private static final String _FINDER_COLUMN_T_E_TYPE_1 = "userIdMapper.type IS NULL AND ";
1686            private static final String _FINDER_COLUMN_T_E_TYPE_2 = "userIdMapper.type = ? AND ";
1687            private static final String _FINDER_COLUMN_T_E_TYPE_3 = "(userIdMapper.type IS NULL OR userIdMapper.type = ?) AND ";
1688            private static final String _FINDER_COLUMN_T_E_EXTERNALUSERID_1 = "userIdMapper.externalUserId IS NULL";
1689            private static final String _FINDER_COLUMN_T_E_EXTERNALUSERID_2 = "userIdMapper.externalUserId = ?";
1690            private static final String _FINDER_COLUMN_T_E_EXTERNALUSERID_3 = "(userIdMapper.externalUserId IS NULL OR userIdMapper.externalUserId = ?)";
1691            private static final String _ORDER_BY_ENTITY_ALIAS = "userIdMapper.";
1692            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No UserIdMapper exists with the primary key ";
1693            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No UserIdMapper exists with the key {";
1694            private static Log _log = LogFactoryUtil.getLog(UserIdMapperPersistenceImpl.class);
1695    }