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