001    /**
002     * Copyright (c) 2000-2011 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                            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.getUserId()),
280                                    
281                            userIdMapperModelImpl.getType()
282                            });
283    
284                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_E,
285                            new Object[] {
286                                    userIdMapperModelImpl.getType(),
287                                    
288                            userIdMapperModelImpl.getExternalUserId()
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                            StringBundler query = null;
542    
543                            if (orderByComparator != null) {
544                                    query = new StringBundler(3 +
545                                                    (orderByComparator.getOrderByFields().length * 3));
546                            }
547                            else {
548                                    query = new StringBundler(2);
549                            }
550    
551                            query.append(_SQL_SELECT_USERIDMAPPER_WHERE);
552    
553                            query.append(_FINDER_COLUMN_USERID_USERID_2);
554    
555                            if (orderByComparator != null) {
556                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
557                                            orderByComparator);
558                            }
559    
560                            String sql = query.toString();
561    
562                            Session session = null;
563    
564                            try {
565                                    session = openSession();
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                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_USERID,
582                                                    finderArgs);
583                                    }
584                                    else {
585                                            cacheResult(list);
586    
587                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
588                                                    finderArgs, list);
589                                    }
590    
591                                    closeSession(session);
592                            }
593                    }
594    
595                    return list;
596            }
597    
598            /**
599             * Finds the first user id mapper in the ordered set where userId = &#63;.
600             *
601             * <p>
602             * 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.
603             * </p>
604             *
605             * @param userId the user id to search with
606             * @param orderByComparator the comparator to order the set by
607             * @return the first matching user id mapper
608             * @throws com.liferay.portal.NoSuchUserIdMapperException if a matching user id mapper could not be found
609             * @throws SystemException if a system exception occurred
610             */
611            public UserIdMapper findByUserId_First(long userId,
612                    OrderByComparator orderByComparator)
613                    throws NoSuchUserIdMapperException, SystemException {
614                    List<UserIdMapper> list = findByUserId(userId, 0, 1, orderByComparator);
615    
616                    if (list.isEmpty()) {
617                            StringBundler msg = new StringBundler(4);
618    
619                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
620    
621                            msg.append("userId=");
622                            msg.append(userId);
623    
624                            msg.append(StringPool.CLOSE_CURLY_BRACE);
625    
626                            throw new NoSuchUserIdMapperException(msg.toString());
627                    }
628                    else {
629                            return list.get(0);
630                    }
631            }
632    
633            /**
634             * Finds the last user id mapper in the ordered set where userId = &#63;.
635             *
636             * <p>
637             * 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.
638             * </p>
639             *
640             * @param userId the user id to search with
641             * @param orderByComparator the comparator to order the set by
642             * @return the last matching user id mapper
643             * @throws com.liferay.portal.NoSuchUserIdMapperException if a matching user id mapper could not be found
644             * @throws SystemException if a system exception occurred
645             */
646            public UserIdMapper findByUserId_Last(long userId,
647                    OrderByComparator orderByComparator)
648                    throws NoSuchUserIdMapperException, SystemException {
649                    int count = countByUserId(userId);
650    
651                    List<UserIdMapper> list = findByUserId(userId, count - 1, count,
652                                    orderByComparator);
653    
654                    if (list.isEmpty()) {
655                            StringBundler msg = new StringBundler(4);
656    
657                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
658    
659                            msg.append("userId=");
660                            msg.append(userId);
661    
662                            msg.append(StringPool.CLOSE_CURLY_BRACE);
663    
664                            throw new NoSuchUserIdMapperException(msg.toString());
665                    }
666                    else {
667                            return list.get(0);
668                    }
669            }
670    
671            /**
672             * Finds the user id mappers before and after the current user id mapper in the ordered set where userId = &#63;.
673             *
674             * <p>
675             * 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.
676             * </p>
677             *
678             * @param userIdMapperId the primary key of the current user id mapper
679             * @param userId the user id to search with
680             * @param orderByComparator the comparator to order the set by
681             * @return the previous, current, and next user id mapper
682             * @throws com.liferay.portal.NoSuchUserIdMapperException if a user id mapper with the primary key could not be found
683             * @throws SystemException if a system exception occurred
684             */
685            public UserIdMapper[] findByUserId_PrevAndNext(long userIdMapperId,
686                    long userId, OrderByComparator orderByComparator)
687                    throws NoSuchUserIdMapperException, SystemException {
688                    UserIdMapper userIdMapper = findByPrimaryKey(userIdMapperId);
689    
690                    Session session = null;
691    
692                    try {
693                            session = openSession();
694    
695                            UserIdMapper[] array = new UserIdMapperImpl[3];
696    
697                            array[0] = getByUserId_PrevAndNext(session, userIdMapper, userId,
698                                            orderByComparator, true);
699    
700                            array[1] = userIdMapper;
701    
702                            array[2] = getByUserId_PrevAndNext(session, userIdMapper, userId,
703                                            orderByComparator, false);
704    
705                            return array;
706                    }
707                    catch (Exception e) {
708                            throw processException(e);
709                    }
710                    finally {
711                            closeSession(session);
712                    }
713            }
714    
715            protected UserIdMapper getByUserId_PrevAndNext(Session session,
716                    UserIdMapper userIdMapper, long userId,
717                    OrderByComparator orderByComparator, boolean previous) {
718                    StringBundler query = null;
719    
720                    if (orderByComparator != null) {
721                            query = new StringBundler(6 +
722                                            (orderByComparator.getOrderByFields().length * 6));
723                    }
724                    else {
725                            query = new StringBundler(3);
726                    }
727    
728                    query.append(_SQL_SELECT_USERIDMAPPER_WHERE);
729    
730                    query.append(_FINDER_COLUMN_USERID_USERID_2);
731    
732                    if (orderByComparator != null) {
733                            String[] orderByFields = orderByComparator.getOrderByFields();
734    
735                            if (orderByFields.length > 0) {
736                                    query.append(WHERE_AND);
737                            }
738    
739                            for (int i = 0; i < orderByFields.length; i++) {
740                                    query.append(_ORDER_BY_ENTITY_ALIAS);
741                                    query.append(orderByFields[i]);
742    
743                                    if ((i + 1) < orderByFields.length) {
744                                            if (orderByComparator.isAscending() ^ previous) {
745                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
746                                            }
747                                            else {
748                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
749                                            }
750                                    }
751                                    else {
752                                            if (orderByComparator.isAscending() ^ previous) {
753                                                    query.append(WHERE_GREATER_THAN);
754                                            }
755                                            else {
756                                                    query.append(WHERE_LESSER_THAN);
757                                            }
758                                    }
759                            }
760    
761                            query.append(ORDER_BY_CLAUSE);
762    
763                            for (int i = 0; i < orderByFields.length; i++) {
764                                    query.append(_ORDER_BY_ENTITY_ALIAS);
765                                    query.append(orderByFields[i]);
766    
767                                    if ((i + 1) < orderByFields.length) {
768                                            if (orderByComparator.isAscending() ^ previous) {
769                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
770                                            }
771                                            else {
772                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
773                                            }
774                                    }
775                                    else {
776                                            if (orderByComparator.isAscending() ^ previous) {
777                                                    query.append(ORDER_BY_ASC);
778                                            }
779                                            else {
780                                                    query.append(ORDER_BY_DESC);
781                                            }
782                                    }
783                            }
784                    }
785    
786                    String sql = query.toString();
787    
788                    Query q = session.createQuery(sql);
789    
790                    q.setFirstResult(0);
791                    q.setMaxResults(2);
792    
793                    QueryPos qPos = QueryPos.getInstance(q);
794    
795                    qPos.add(userId);
796    
797                    if (orderByComparator != null) {
798                            Object[] values = orderByComparator.getOrderByValues(userIdMapper);
799    
800                            for (Object value : values) {
801                                    qPos.add(value);
802                            }
803                    }
804    
805                    List<UserIdMapper> list = q.list();
806    
807                    if (list.size() == 2) {
808                            return list.get(1);
809                    }
810                    else {
811                            return null;
812                    }
813            }
814    
815            /**
816             * 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.
817             *
818             * @param userId the user id to search with
819             * @param type the type to search with
820             * @return the matching user id mapper
821             * @throws com.liferay.portal.NoSuchUserIdMapperException if a matching user id mapper could not be found
822             * @throws SystemException if a system exception occurred
823             */
824            public UserIdMapper findByU_T(long userId, String type)
825                    throws NoSuchUserIdMapperException, SystemException {
826                    UserIdMapper userIdMapper = fetchByU_T(userId, type);
827    
828                    if (userIdMapper == null) {
829                            StringBundler msg = new StringBundler(6);
830    
831                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
832    
833                            msg.append("userId=");
834                            msg.append(userId);
835    
836                            msg.append(", type=");
837                            msg.append(type);
838    
839                            msg.append(StringPool.CLOSE_CURLY_BRACE);
840    
841                            if (_log.isWarnEnabled()) {
842                                    _log.warn(msg.toString());
843                            }
844    
845                            throw new NoSuchUserIdMapperException(msg.toString());
846                    }
847    
848                    return userIdMapper;
849            }
850    
851            /**
852             * 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.
853             *
854             * @param userId the user id to search with
855             * @param type the type to search with
856             * @return the matching user id mapper, or <code>null</code> if a matching user id mapper could not be found
857             * @throws SystemException if a system exception occurred
858             */
859            public UserIdMapper fetchByU_T(long userId, String type)
860                    throws SystemException {
861                    return fetchByU_T(userId, type, true);
862            }
863    
864            /**
865             * 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.
866             *
867             * @param userId the user id to search with
868             * @param type the type to search with
869             * @return the matching user id mapper, or <code>null</code> if a matching user id mapper could not be found
870             * @throws SystemException if a system exception occurred
871             */
872            public UserIdMapper fetchByU_T(long userId, String type,
873                    boolean retrieveFromCache) throws SystemException {
874                    Object[] finderArgs = new Object[] { userId, type };
875    
876                    Object result = null;
877    
878                    if (retrieveFromCache) {
879                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_T,
880                                            finderArgs, this);
881                    }
882    
883                    if (result == null) {
884                            StringBundler query = new StringBundler(3);
885    
886                            query.append(_SQL_SELECT_USERIDMAPPER_WHERE);
887    
888                            query.append(_FINDER_COLUMN_U_T_USERID_2);
889    
890                            if (type == null) {
891                                    query.append(_FINDER_COLUMN_U_T_TYPE_1);
892                            }
893                            else {
894                                    if (type.equals(StringPool.BLANK)) {
895                                            query.append(_FINDER_COLUMN_U_T_TYPE_3);
896                                    }
897                                    else {
898                                            query.append(_FINDER_COLUMN_U_T_TYPE_2);
899                                    }
900                            }
901    
902                            String sql = query.toString();
903    
904                            Session session = null;
905    
906                            try {
907                                    session = openSession();
908    
909                                    Query q = session.createQuery(sql);
910    
911                                    QueryPos qPos = QueryPos.getInstance(q);
912    
913                                    qPos.add(userId);
914    
915                                    if (type != null) {
916                                            qPos.add(type);
917                                    }
918    
919                                    List<UserIdMapper> list = q.list();
920    
921                                    result = list;
922    
923                                    UserIdMapper userIdMapper = null;
924    
925                                    if (list.isEmpty()) {
926                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
927                                                    finderArgs, list);
928                                    }
929                                    else {
930                                            userIdMapper = list.get(0);
931    
932                                            cacheResult(userIdMapper);
933    
934                                            if ((userIdMapper.getUserId() != userId) ||
935                                                            (userIdMapper.getType() == null) ||
936                                                            !userIdMapper.getType().equals(type)) {
937                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
938                                                            finderArgs, userIdMapper);
939                                            }
940                                    }
941    
942                                    return userIdMapper;
943                            }
944                            catch (Exception e) {
945                                    throw processException(e);
946                            }
947                            finally {
948                                    if (result == null) {
949                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T,
950                                                    finderArgs);
951                                    }
952    
953                                    closeSession(session);
954                            }
955                    }
956                    else {
957                            if (result instanceof List<?>) {
958                                    return null;
959                            }
960                            else {
961                                    return (UserIdMapper)result;
962                            }
963                    }
964            }
965    
966            /**
967             * 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.
968             *
969             * @param type the type to search with
970             * @param externalUserId the external user id to search with
971             * @return the matching user id mapper
972             * @throws com.liferay.portal.NoSuchUserIdMapperException if a matching user id mapper could not be found
973             * @throws SystemException if a system exception occurred
974             */
975            public UserIdMapper findByT_E(String type, String externalUserId)
976                    throws NoSuchUserIdMapperException, SystemException {
977                    UserIdMapper userIdMapper = fetchByT_E(type, externalUserId);
978    
979                    if (userIdMapper == null) {
980                            StringBundler msg = new StringBundler(6);
981    
982                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
983    
984                            msg.append("type=");
985                            msg.append(type);
986    
987                            msg.append(", externalUserId=");
988                            msg.append(externalUserId);
989    
990                            msg.append(StringPool.CLOSE_CURLY_BRACE);
991    
992                            if (_log.isWarnEnabled()) {
993                                    _log.warn(msg.toString());
994                            }
995    
996                            throw new NoSuchUserIdMapperException(msg.toString());
997                    }
998    
999                    return userIdMapper;
1000            }
1001    
1002            /**
1003             * 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.
1004             *
1005             * @param type the type to search with
1006             * @param externalUserId the external user id to search with
1007             * @return the matching user id mapper, or <code>null</code> if a matching user id mapper could not be found
1008             * @throws SystemException if a system exception occurred
1009             */
1010            public UserIdMapper fetchByT_E(String type, String externalUserId)
1011                    throws SystemException {
1012                    return fetchByT_E(type, externalUserId, true);
1013            }
1014    
1015            /**
1016             * 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.
1017             *
1018             * @param type the type to search with
1019             * @param externalUserId the external user id to search with
1020             * @return the matching user id mapper, or <code>null</code> if a matching user id mapper could not be found
1021             * @throws SystemException if a system exception occurred
1022             */
1023            public UserIdMapper fetchByT_E(String type, String externalUserId,
1024                    boolean retrieveFromCache) throws SystemException {
1025                    Object[] finderArgs = new Object[] { type, externalUserId };
1026    
1027                    Object result = null;
1028    
1029                    if (retrieveFromCache) {
1030                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_T_E,
1031                                            finderArgs, this);
1032                    }
1033    
1034                    if (result == null) {
1035                            StringBundler query = new StringBundler(3);
1036    
1037                            query.append(_SQL_SELECT_USERIDMAPPER_WHERE);
1038    
1039                            if (type == null) {
1040                                    query.append(_FINDER_COLUMN_T_E_TYPE_1);
1041                            }
1042                            else {
1043                                    if (type.equals(StringPool.BLANK)) {
1044                                            query.append(_FINDER_COLUMN_T_E_TYPE_3);
1045                                    }
1046                                    else {
1047                                            query.append(_FINDER_COLUMN_T_E_TYPE_2);
1048                                    }
1049                            }
1050    
1051                            if (externalUserId == null) {
1052                                    query.append(_FINDER_COLUMN_T_E_EXTERNALUSERID_1);
1053                            }
1054                            else {
1055                                    if (externalUserId.equals(StringPool.BLANK)) {
1056                                            query.append(_FINDER_COLUMN_T_E_EXTERNALUSERID_3);
1057                                    }
1058                                    else {
1059                                            query.append(_FINDER_COLUMN_T_E_EXTERNALUSERID_2);
1060                                    }
1061                            }
1062    
1063                            String sql = query.toString();
1064    
1065                            Session session = null;
1066    
1067                            try {
1068                                    session = openSession();
1069    
1070                                    Query q = session.createQuery(sql);
1071    
1072                                    QueryPos qPos = QueryPos.getInstance(q);
1073    
1074                                    if (type != null) {
1075                                            qPos.add(type);
1076                                    }
1077    
1078                                    if (externalUserId != null) {
1079                                            qPos.add(externalUserId);
1080                                    }
1081    
1082                                    List<UserIdMapper> list = q.list();
1083    
1084                                    result = list;
1085    
1086                                    UserIdMapper userIdMapper = null;
1087    
1088                                    if (list.isEmpty()) {
1089                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_E,
1090                                                    finderArgs, list);
1091                                    }
1092                                    else {
1093                                            userIdMapper = list.get(0);
1094    
1095                                            cacheResult(userIdMapper);
1096    
1097                                            if ((userIdMapper.getType() == null) ||
1098                                                            !userIdMapper.getType().equals(type) ||
1099                                                            (userIdMapper.getExternalUserId() == null) ||
1100                                                            !userIdMapper.getExternalUserId()
1101                                                                                             .equals(externalUserId)) {
1102                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_E,
1103                                                            finderArgs, userIdMapper);
1104                                            }
1105                                    }
1106    
1107                                    return userIdMapper;
1108                            }
1109                            catch (Exception e) {
1110                                    throw processException(e);
1111                            }
1112                            finally {
1113                                    if (result == null) {
1114                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_E,
1115                                                    finderArgs);
1116                                    }
1117    
1118                                    closeSession(session);
1119                            }
1120                    }
1121                    else {
1122                            if (result instanceof List<?>) {
1123                                    return null;
1124                            }
1125                            else {
1126                                    return (UserIdMapper)result;
1127                            }
1128                    }
1129            }
1130    
1131            /**
1132             * Finds all the user id mappers.
1133             *
1134             * @return the user id mappers
1135             * @throws SystemException if a system exception occurred
1136             */
1137            public List<UserIdMapper> findAll() throws SystemException {
1138                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1139            }
1140    
1141            /**
1142             * Finds a range of all the user id mappers.
1143             *
1144             * <p>
1145             * 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.
1146             * </p>
1147             *
1148             * @param start the lower bound of the range of user id mappers to return
1149             * @param end the upper bound of the range of user id mappers to return (not inclusive)
1150             * @return the range of user id mappers
1151             * @throws SystemException if a system exception occurred
1152             */
1153            public List<UserIdMapper> findAll(int start, int end)
1154                    throws SystemException {
1155                    return findAll(start, end, null);
1156            }
1157    
1158            /**
1159             * Finds an ordered range of all the user id mappers.
1160             *
1161             * <p>
1162             * 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.
1163             * </p>
1164             *
1165             * @param start the lower bound of the range of user id mappers to return
1166             * @param end the upper bound of the range of user id mappers to return (not inclusive)
1167             * @param orderByComparator the comparator to order the results by
1168             * @return the ordered range of user id mappers
1169             * @throws SystemException if a system exception occurred
1170             */
1171            public List<UserIdMapper> findAll(int start, int end,
1172                    OrderByComparator orderByComparator) throws SystemException {
1173                    Object[] finderArgs = new Object[] {
1174                                    String.valueOf(start), String.valueOf(end),
1175                                    String.valueOf(orderByComparator)
1176                            };
1177    
1178                    List<UserIdMapper> list = (List<UserIdMapper>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1179                                    finderArgs, this);
1180    
1181                    if (list == null) {
1182                            StringBundler query = null;
1183                            String sql = null;
1184    
1185                            if (orderByComparator != null) {
1186                                    query = new StringBundler(2 +
1187                                                    (orderByComparator.getOrderByFields().length * 3));
1188    
1189                                    query.append(_SQL_SELECT_USERIDMAPPER);
1190    
1191                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1192                                            orderByComparator);
1193    
1194                                    sql = query.toString();
1195                            }
1196                            else {
1197                                    sql = _SQL_SELECT_USERIDMAPPER;
1198                            }
1199    
1200                            Session session = null;
1201    
1202                            try {
1203                                    session = openSession();
1204    
1205                                    Query q = session.createQuery(sql);
1206    
1207                                    if (orderByComparator == null) {
1208                                            list = (List<UserIdMapper>)QueryUtil.list(q, getDialect(),
1209                                                            start, end, false);
1210    
1211                                            Collections.sort(list);
1212                                    }
1213                                    else {
1214                                            list = (List<UserIdMapper>)QueryUtil.list(q, getDialect(),
1215                                                            start, end);
1216                                    }
1217                            }
1218                            catch (Exception e) {
1219                                    throw processException(e);
1220                            }
1221                            finally {
1222                                    if (list == null) {
1223                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
1224                                                    finderArgs);
1225                                    }
1226                                    else {
1227                                            cacheResult(list);
1228    
1229                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
1230                                                    list);
1231                                    }
1232    
1233                                    closeSession(session);
1234                            }
1235                    }
1236    
1237                    return list;
1238            }
1239    
1240            /**
1241             * Removes all the user id mappers where userId = &#63; from the database.
1242             *
1243             * @param userId the user id to search with
1244             * @throws SystemException if a system exception occurred
1245             */
1246            public void removeByUserId(long userId) throws SystemException {
1247                    for (UserIdMapper userIdMapper : findByUserId(userId)) {
1248                            remove(userIdMapper);
1249                    }
1250            }
1251    
1252            /**
1253             * Removes the user id mapper where userId = &#63; and type = &#63; from the database.
1254             *
1255             * @param userId the user id to search with
1256             * @param type the type to search with
1257             * @throws SystemException if a system exception occurred
1258             */
1259            public void removeByU_T(long userId, String type)
1260                    throws NoSuchUserIdMapperException, SystemException {
1261                    UserIdMapper userIdMapper = findByU_T(userId, type);
1262    
1263                    remove(userIdMapper);
1264            }
1265    
1266            /**
1267             * Removes the user id mapper where type = &#63; and externalUserId = &#63; from the database.
1268             *
1269             * @param type the type to search with
1270             * @param externalUserId the external user id to search with
1271             * @throws SystemException if a system exception occurred
1272             */
1273            public void removeByT_E(String type, String externalUserId)
1274                    throws NoSuchUserIdMapperException, SystemException {
1275                    UserIdMapper userIdMapper = findByT_E(type, externalUserId);
1276    
1277                    remove(userIdMapper);
1278            }
1279    
1280            /**
1281             * Removes all the user id mappers from the database.
1282             *
1283             * @throws SystemException if a system exception occurred
1284             */
1285            public void removeAll() throws SystemException {
1286                    for (UserIdMapper userIdMapper : findAll()) {
1287                            remove(userIdMapper);
1288                    }
1289            }
1290    
1291            /**
1292             * Counts all the user id mappers where userId = &#63;.
1293             *
1294             * @param userId the user id to search with
1295             * @return the number of matching user id mappers
1296             * @throws SystemException if a system exception occurred
1297             */
1298            public int countByUserId(long userId) throws SystemException {
1299                    Object[] finderArgs = new Object[] { userId };
1300    
1301                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1302                                    finderArgs, this);
1303    
1304                    if (count == null) {
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                            Session session = null;
1314    
1315                            try {
1316                                    session = openSession();
1317    
1318                                    Query q = session.createQuery(sql);
1319    
1320                                    QueryPos qPos = QueryPos.getInstance(q);
1321    
1322                                    qPos.add(userId);
1323    
1324                                    count = (Long)q.uniqueResult();
1325                            }
1326                            catch (Exception e) {
1327                                    throw processException(e);
1328                            }
1329                            finally {
1330                                    if (count == null) {
1331                                            count = Long.valueOf(0);
1332                                    }
1333    
1334                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1335                                            finderArgs, count);
1336    
1337                                    closeSession(session);
1338                            }
1339                    }
1340    
1341                    return count.intValue();
1342            }
1343    
1344            /**
1345             * Counts all the user id mappers where userId = &#63; and type = &#63;.
1346             *
1347             * @param userId the user id to search with
1348             * @param type the type to search with
1349             * @return the number of matching user id mappers
1350             * @throws SystemException if a system exception occurred
1351             */
1352            public int countByU_T(long userId, String type) throws SystemException {
1353                    Object[] finderArgs = new Object[] { userId, type };
1354    
1355                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_T,
1356                                    finderArgs, this);
1357    
1358                    if (count == null) {
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                            Session session = null;
1380    
1381                            try {
1382                                    session = openSession();
1383    
1384                                    Query q = session.createQuery(sql);
1385    
1386                                    QueryPos qPos = QueryPos.getInstance(q);
1387    
1388                                    qPos.add(userId);
1389    
1390                                    if (type != null) {
1391                                            qPos.add(type);
1392                                    }
1393    
1394                                    count = (Long)q.uniqueResult();
1395                            }
1396                            catch (Exception e) {
1397                                    throw processException(e);
1398                            }
1399                            finally {
1400                                    if (count == null) {
1401                                            count = Long.valueOf(0);
1402                                    }
1403    
1404                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T, finderArgs,
1405                                            count);
1406    
1407                                    closeSession(session);
1408                            }
1409                    }
1410    
1411                    return count.intValue();
1412            }
1413    
1414            /**
1415             * Counts all the user id mappers where type = &#63; and externalUserId = &#63;.
1416             *
1417             * @param type the type to search with
1418             * @param externalUserId the external user id to search with
1419             * @return the number of matching user id mappers
1420             * @throws SystemException if a system exception occurred
1421             */
1422            public int countByT_E(String type, String externalUserId)
1423                    throws SystemException {
1424                    Object[] finderArgs = new Object[] { type, externalUserId };
1425    
1426                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_E,
1427                                    finderArgs, this);
1428    
1429                    if (count == null) {
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                            Session session = null;
1461    
1462                            try {
1463                                    session = openSession();
1464    
1465                                    Query q = session.createQuery(sql);
1466    
1467                                    QueryPos qPos = QueryPos.getInstance(q);
1468    
1469                                    if (type != null) {
1470                                            qPos.add(type);
1471                                    }
1472    
1473                                    if (externalUserId != null) {
1474                                            qPos.add(externalUserId);
1475                                    }
1476    
1477                                    count = (Long)q.uniqueResult();
1478                            }
1479                            catch (Exception e) {
1480                                    throw processException(e);
1481                            }
1482                            finally {
1483                                    if (count == null) {
1484                                            count = Long.valueOf(0);
1485                                    }
1486    
1487                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_E, finderArgs,
1488                                            count);
1489    
1490                                    closeSession(session);
1491                            }
1492                    }
1493    
1494                    return count.intValue();
1495            }
1496    
1497            /**
1498             * Counts all the user id mappers.
1499             *
1500             * @return the number of user id mappers
1501             * @throws SystemException if a system exception occurred
1502             */
1503            public int countAll() throws SystemException {
1504                    Object[] finderArgs = new Object[0];
1505    
1506                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1507                                    finderArgs, this);
1508    
1509                    if (count == null) {
1510                            Session session = null;
1511    
1512                            try {
1513                                    session = openSession();
1514    
1515                                    Query q = session.createQuery(_SQL_COUNT_USERIDMAPPER);
1516    
1517                                    count = (Long)q.uniqueResult();
1518                            }
1519                            catch (Exception e) {
1520                                    throw processException(e);
1521                            }
1522                            finally {
1523                                    if (count == null) {
1524                                            count = Long.valueOf(0);
1525                                    }
1526    
1527                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1528                                            count);
1529    
1530                                    closeSession(session);
1531                            }
1532                    }
1533    
1534                    return count.intValue();
1535            }
1536    
1537            /**
1538             * Initializes the user id mapper persistence.
1539             */
1540            public void afterPropertiesSet() {
1541                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1542                                            com.liferay.portal.util.PropsUtil.get(
1543                                                    "value.object.listener.com.liferay.portal.model.UserIdMapper")));
1544    
1545                    if (listenerClassNames.length > 0) {
1546                            try {
1547                                    List<ModelListener<UserIdMapper>> listenersList = new ArrayList<ModelListener<UserIdMapper>>();
1548    
1549                                    for (String listenerClassName : listenerClassNames) {
1550                                            listenersList.add((ModelListener<UserIdMapper>)InstanceFactory.newInstance(
1551                                                            listenerClassName));
1552                                    }
1553    
1554                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1555                            }
1556                            catch (Exception e) {
1557                                    _log.error(e);
1558                            }
1559                    }
1560            }
1561    
1562            public void destroy() {
1563                    EntityCacheUtil.removeCache(UserIdMapperImpl.class.getName());
1564                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1565                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
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    }