001    /**
002     * Copyright (c) 2000-present 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.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.NoSuchUserIdMapperException;
020    import com.liferay.portal.kernel.dao.orm.EntityCache;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCache;
023    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024    import com.liferay.portal.kernel.dao.orm.FinderPath;
025    import com.liferay.portal.kernel.dao.orm.Query;
026    import com.liferay.portal.kernel.dao.orm.QueryPos;
027    import com.liferay.portal.kernel.dao.orm.QueryUtil;
028    import com.liferay.portal.kernel.dao.orm.Session;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.OrderByComparator;
032    import com.liferay.portal.kernel.util.SetUtil;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.Validator;
036    import com.liferay.portal.model.CacheModel;
037    import com.liferay.portal.model.MVCCModel;
038    import com.liferay.portal.model.UserIdMapper;
039    import com.liferay.portal.model.impl.UserIdMapperImpl;
040    import com.liferay.portal.model.impl.UserIdMapperModelImpl;
041    import com.liferay.portal.service.persistence.UserIdMapperPersistence;
042    
043    import java.io.Serializable;
044    
045    import java.util.Collections;
046    import java.util.HashMap;
047    import java.util.HashSet;
048    import java.util.Iterator;
049    import java.util.List;
050    import java.util.Map;
051    import java.util.Set;
052    
053    /**
054     * The persistence implementation for the user ID mapper service.
055     *
056     * <p>
057     * Caching information and settings can be found in <code>portal.properties</code>
058     * </p>
059     *
060     * @author Brian Wing Shun Chan
061     * @see UserIdMapperPersistence
062     * @see com.liferay.portal.service.persistence.UserIdMapperUtil
063     * @generated
064     */
065    @ProviderType
066    public class UserIdMapperPersistenceImpl extends BasePersistenceImpl<UserIdMapper>
067            implements UserIdMapperPersistence {
068            /*
069             * NOTE FOR DEVELOPERS:
070             *
071             * 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.
072             */
073            public static final String FINDER_CLASS_NAME_ENTITY = UserIdMapperImpl.class.getName();
074            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075                    ".List1";
076            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077                    ".List2";
078            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
079                            UserIdMapperModelImpl.FINDER_CACHE_ENABLED, UserIdMapperImpl.class,
080                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
081            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
082                            UserIdMapperModelImpl.FINDER_CACHE_ENABLED, UserIdMapperImpl.class,
083                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
084            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
085                            UserIdMapperModelImpl.FINDER_CACHE_ENABLED, Long.class,
086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
087            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
088                            UserIdMapperModelImpl.FINDER_CACHE_ENABLED, UserIdMapperImpl.class,
089                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
090                            new String[] {
091                                    Long.class.getName(),
092                                    
093                            Integer.class.getName(), Integer.class.getName(),
094                                    OrderByComparator.class.getName()
095                            });
096            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
097                    new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
098                            UserIdMapperModelImpl.FINDER_CACHE_ENABLED, UserIdMapperImpl.class,
099                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
100                            new String[] { Long.class.getName() },
101                            UserIdMapperModelImpl.USERID_COLUMN_BITMASK);
102            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
103                            UserIdMapperModelImpl.FINDER_CACHE_ENABLED, Long.class,
104                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
105                            new String[] { Long.class.getName() });
106    
107            /**
108             * Returns all the user ID mappers where userId = &#63;.
109             *
110             * @param userId the user ID
111             * @return the matching user ID mappers
112             */
113            @Override
114            public List<UserIdMapper> findByUserId(long userId) {
115                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
116            }
117    
118            /**
119             * Returns a range of all the user ID mappers where userId = &#63;.
120             *
121             * <p>
122             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserIdMapperModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
123             * </p>
124             *
125             * @param userId the user ID
126             * @param start the lower bound of the range of user ID mappers
127             * @param end the upper bound of the range of user ID mappers (not inclusive)
128             * @return the range of matching user ID mappers
129             */
130            @Override
131            public List<UserIdMapper> findByUserId(long userId, int start, int end) {
132                    return findByUserId(userId, start, end, null);
133            }
134    
135            /**
136             * Returns an ordered range of all the user ID mappers where userId = &#63;.
137             *
138             * <p>
139             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserIdMapperModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
140             * </p>
141             *
142             * @param userId the user ID
143             * @param start the lower bound of the range of user ID mappers
144             * @param end the upper bound of the range of user ID mappers (not inclusive)
145             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
146             * @return the ordered range of matching user ID mappers
147             */
148            @Override
149            public List<UserIdMapper> findByUserId(long userId, int start, int end,
150                    OrderByComparator<UserIdMapper> orderByComparator) {
151                    return findByUserId(userId, start, end, orderByComparator, true);
152            }
153    
154            /**
155             * Returns an ordered range of all the user ID mappers where userId = &#63;.
156             *
157             * <p>
158             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserIdMapperModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
159             * </p>
160             *
161             * @param userId the user ID
162             * @param start the lower bound of the range of user ID mappers
163             * @param end the upper bound of the range of user ID mappers (not inclusive)
164             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
165             * @param retrieveFromCache whether to retrieve from the finder cache
166             * @return the ordered range of matching user ID mappers
167             */
168            @Override
169            public List<UserIdMapper> findByUserId(long userId, int start, int end,
170                    OrderByComparator<UserIdMapper> orderByComparator,
171                    boolean retrieveFromCache) {
172                    boolean pagination = true;
173                    FinderPath finderPath = null;
174                    Object[] finderArgs = null;
175    
176                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
177                                    (orderByComparator == null)) {
178                            pagination = false;
179                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
180                            finderArgs = new Object[] { userId };
181                    }
182                    else {
183                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
184                            finderArgs = new Object[] { userId, start, end, orderByComparator };
185                    }
186    
187                    List<UserIdMapper> list = null;
188    
189                    if (retrieveFromCache) {
190                            list = (List<UserIdMapper>)finderCache.getResult(finderPath,
191                                            finderArgs, this);
192    
193                            if ((list != null) && !list.isEmpty()) {
194                                    for (UserIdMapper userIdMapper : list) {
195                                            if ((userId != userIdMapper.getUserId())) {
196                                                    list = null;
197    
198                                                    break;
199                                            }
200                                    }
201                            }
202                    }
203    
204                    if (list == null) {
205                            StringBundler query = null;
206    
207                            if (orderByComparator != null) {
208                                    query = new StringBundler(3 +
209                                                    (orderByComparator.getOrderByFields().length * 3));
210                            }
211                            else {
212                                    query = new StringBundler(3);
213                            }
214    
215                            query.append(_SQL_SELECT_USERIDMAPPER_WHERE);
216    
217                            query.append(_FINDER_COLUMN_USERID_USERID_2);
218    
219                            if (orderByComparator != null) {
220                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
221                                            orderByComparator);
222                            }
223                            else
224                             if (pagination) {
225                                    query.append(UserIdMapperModelImpl.ORDER_BY_JPQL);
226                            }
227    
228                            String sql = query.toString();
229    
230                            Session session = null;
231    
232                            try {
233                                    session = openSession();
234    
235                                    Query q = session.createQuery(sql);
236    
237                                    QueryPos qPos = QueryPos.getInstance(q);
238    
239                                    qPos.add(userId);
240    
241                                    if (!pagination) {
242                                            list = (List<UserIdMapper>)QueryUtil.list(q, getDialect(),
243                                                            start, end, false);
244    
245                                            Collections.sort(list);
246    
247                                            list = Collections.unmodifiableList(list);
248                                    }
249                                    else {
250                                            list = (List<UserIdMapper>)QueryUtil.list(q, getDialect(),
251                                                            start, end);
252                                    }
253    
254                                    cacheResult(list);
255    
256                                    finderCache.putResult(finderPath, finderArgs, list);
257                            }
258                            catch (Exception e) {
259                                    finderCache.removeResult(finderPath, finderArgs);
260    
261                                    throw processException(e);
262                            }
263                            finally {
264                                    closeSession(session);
265                            }
266                    }
267    
268                    return list;
269            }
270    
271            /**
272             * Returns the first user ID mapper in the ordered set where userId = &#63;.
273             *
274             * @param userId the user ID
275             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
276             * @return the first matching user ID mapper
277             * @throws NoSuchUserIdMapperException if a matching user ID mapper could not be found
278             */
279            @Override
280            public UserIdMapper findByUserId_First(long userId,
281                    OrderByComparator<UserIdMapper> orderByComparator)
282                    throws NoSuchUserIdMapperException {
283                    UserIdMapper userIdMapper = fetchByUserId_First(userId,
284                                    orderByComparator);
285    
286                    if (userIdMapper != null) {
287                            return userIdMapper;
288                    }
289    
290                    StringBundler msg = new StringBundler(4);
291    
292                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
293    
294                    msg.append("userId=");
295                    msg.append(userId);
296    
297                    msg.append(StringPool.CLOSE_CURLY_BRACE);
298    
299                    throw new NoSuchUserIdMapperException(msg.toString());
300            }
301    
302            /**
303             * Returns the first user ID mapper in the ordered set where userId = &#63;.
304             *
305             * @param userId the user ID
306             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
307             * @return the first matching user ID mapper, or <code>null</code> if a matching user ID mapper could not be found
308             */
309            @Override
310            public UserIdMapper fetchByUserId_First(long userId,
311                    OrderByComparator<UserIdMapper> orderByComparator) {
312                    List<UserIdMapper> list = findByUserId(userId, 0, 1, orderByComparator);
313    
314                    if (!list.isEmpty()) {
315                            return list.get(0);
316                    }
317    
318                    return null;
319            }
320    
321            /**
322             * Returns the last user ID mapper in the ordered set where userId = &#63;.
323             *
324             * @param userId the user ID
325             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
326             * @return the last matching user ID mapper
327             * @throws NoSuchUserIdMapperException if a matching user ID mapper could not be found
328             */
329            @Override
330            public UserIdMapper findByUserId_Last(long userId,
331                    OrderByComparator<UserIdMapper> orderByComparator)
332                    throws NoSuchUserIdMapperException {
333                    UserIdMapper userIdMapper = fetchByUserId_Last(userId, orderByComparator);
334    
335                    if (userIdMapper != null) {
336                            return userIdMapper;
337                    }
338    
339                    StringBundler msg = new StringBundler(4);
340    
341                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
342    
343                    msg.append("userId=");
344                    msg.append(userId);
345    
346                    msg.append(StringPool.CLOSE_CURLY_BRACE);
347    
348                    throw new NoSuchUserIdMapperException(msg.toString());
349            }
350    
351            /**
352             * Returns the last user ID mapper in the ordered set where userId = &#63;.
353             *
354             * @param userId the user ID
355             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
356             * @return the last matching user ID mapper, or <code>null</code> if a matching user ID mapper could not be found
357             */
358            @Override
359            public UserIdMapper fetchByUserId_Last(long userId,
360                    OrderByComparator<UserIdMapper> orderByComparator) {
361                    int count = countByUserId(userId);
362    
363                    if (count == 0) {
364                            return null;
365                    }
366    
367                    List<UserIdMapper> list = findByUserId(userId, count - 1, count,
368                                    orderByComparator);
369    
370                    if (!list.isEmpty()) {
371                            return list.get(0);
372                    }
373    
374                    return null;
375            }
376    
377            /**
378             * Returns the user ID mappers before and after the current user ID mapper in the ordered set where userId = &#63;.
379             *
380             * @param userIdMapperId the primary key of the current user ID mapper
381             * @param userId the user ID
382             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
383             * @return the previous, current, and next user ID mapper
384             * @throws NoSuchUserIdMapperException if a user ID mapper with the primary key could not be found
385             */
386            @Override
387            public UserIdMapper[] findByUserId_PrevAndNext(long userIdMapperId,
388                    long userId, OrderByComparator<UserIdMapper> orderByComparator)
389                    throws NoSuchUserIdMapperException {
390                    UserIdMapper userIdMapper = findByPrimaryKey(userIdMapperId);
391    
392                    Session session = null;
393    
394                    try {
395                            session = openSession();
396    
397                            UserIdMapper[] array = new UserIdMapperImpl[3];
398    
399                            array[0] = getByUserId_PrevAndNext(session, userIdMapper, userId,
400                                            orderByComparator, true);
401    
402                            array[1] = userIdMapper;
403    
404                            array[2] = getByUserId_PrevAndNext(session, userIdMapper, userId,
405                                            orderByComparator, false);
406    
407                            return array;
408                    }
409                    catch (Exception e) {
410                            throw processException(e);
411                    }
412                    finally {
413                            closeSession(session);
414                    }
415            }
416    
417            protected UserIdMapper getByUserId_PrevAndNext(Session session,
418                    UserIdMapper userIdMapper, long userId,
419                    OrderByComparator<UserIdMapper> orderByComparator, boolean previous) {
420                    StringBundler query = null;
421    
422                    if (orderByComparator != null) {
423                            query = new StringBundler(6 +
424                                            (orderByComparator.getOrderByFields().length * 6));
425                    }
426                    else {
427                            query = new StringBundler(3);
428                    }
429    
430                    query.append(_SQL_SELECT_USERIDMAPPER_WHERE);
431    
432                    query.append(_FINDER_COLUMN_USERID_USERID_2);
433    
434                    if (orderByComparator != null) {
435                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
436    
437                            if (orderByConditionFields.length > 0) {
438                                    query.append(WHERE_AND);
439                            }
440    
441                            for (int i = 0; i < orderByConditionFields.length; i++) {
442                                    query.append(_ORDER_BY_ENTITY_ALIAS);
443                                    query.append(orderByConditionFields[i]);
444    
445                                    if ((i + 1) < orderByConditionFields.length) {
446                                            if (orderByComparator.isAscending() ^ previous) {
447                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
448                                            }
449                                            else {
450                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
451                                            }
452                                    }
453                                    else {
454                                            if (orderByComparator.isAscending() ^ previous) {
455                                                    query.append(WHERE_GREATER_THAN);
456                                            }
457                                            else {
458                                                    query.append(WHERE_LESSER_THAN);
459                                            }
460                                    }
461                            }
462    
463                            query.append(ORDER_BY_CLAUSE);
464    
465                            String[] orderByFields = orderByComparator.getOrderByFields();
466    
467                            for (int i = 0; i < orderByFields.length; i++) {
468                                    query.append(_ORDER_BY_ENTITY_ALIAS);
469                                    query.append(orderByFields[i]);
470    
471                                    if ((i + 1) < orderByFields.length) {
472                                            if (orderByComparator.isAscending() ^ previous) {
473                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
474                                            }
475                                            else {
476                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
477                                            }
478                                    }
479                                    else {
480                                            if (orderByComparator.isAscending() ^ previous) {
481                                                    query.append(ORDER_BY_ASC);
482                                            }
483                                            else {
484                                                    query.append(ORDER_BY_DESC);
485                                            }
486                                    }
487                            }
488                    }
489                    else {
490                            query.append(UserIdMapperModelImpl.ORDER_BY_JPQL);
491                    }
492    
493                    String sql = query.toString();
494    
495                    Query q = session.createQuery(sql);
496    
497                    q.setFirstResult(0);
498                    q.setMaxResults(2);
499    
500                    QueryPos qPos = QueryPos.getInstance(q);
501    
502                    qPos.add(userId);
503    
504                    if (orderByComparator != null) {
505                            Object[] values = orderByComparator.getOrderByConditionValues(userIdMapper);
506    
507                            for (Object value : values) {
508                                    qPos.add(value);
509                            }
510                    }
511    
512                    List<UserIdMapper> list = q.list();
513    
514                    if (list.size() == 2) {
515                            return list.get(1);
516                    }
517                    else {
518                            return null;
519                    }
520            }
521    
522            /**
523             * Removes all the user ID mappers where userId = &#63; from the database.
524             *
525             * @param userId the user ID
526             */
527            @Override
528            public void removeByUserId(long userId) {
529                    for (UserIdMapper userIdMapper : findByUserId(userId,
530                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
531                            remove(userIdMapper);
532                    }
533            }
534    
535            /**
536             * Returns the number of user ID mappers where userId = &#63;.
537             *
538             * @param userId the user ID
539             * @return the number of matching user ID mappers
540             */
541            @Override
542            public int countByUserId(long userId) {
543                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
544    
545                    Object[] finderArgs = new Object[] { userId };
546    
547                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
548    
549                    if (count == null) {
550                            StringBundler query = new StringBundler(2);
551    
552                            query.append(_SQL_COUNT_USERIDMAPPER_WHERE);
553    
554                            query.append(_FINDER_COLUMN_USERID_USERID_2);
555    
556                            String sql = query.toString();
557    
558                            Session session = null;
559    
560                            try {
561                                    session = openSession();
562    
563                                    Query q = session.createQuery(sql);
564    
565                                    QueryPos qPos = QueryPos.getInstance(q);
566    
567                                    qPos.add(userId);
568    
569                                    count = (Long)q.uniqueResult();
570    
571                                    finderCache.putResult(finderPath, finderArgs, count);
572                            }
573                            catch (Exception e) {
574                                    finderCache.removeResult(finderPath, finderArgs);
575    
576                                    throw processException(e);
577                            }
578                            finally {
579                                    closeSession(session);
580                            }
581                    }
582    
583                    return count.intValue();
584            }
585    
586            private static final String _FINDER_COLUMN_USERID_USERID_2 = "userIdMapper.userId = ?";
587            public static final FinderPath FINDER_PATH_FETCH_BY_U_T = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
588                            UserIdMapperModelImpl.FINDER_CACHE_ENABLED, UserIdMapperImpl.class,
589                            FINDER_CLASS_NAME_ENTITY, "fetchByU_T",
590                            new String[] { Long.class.getName(), String.class.getName() },
591                            UserIdMapperModelImpl.USERID_COLUMN_BITMASK |
592                            UserIdMapperModelImpl.TYPE_COLUMN_BITMASK);
593            public static final FinderPath FINDER_PATH_COUNT_BY_U_T = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
594                            UserIdMapperModelImpl.FINDER_CACHE_ENABLED, Long.class,
595                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_T",
596                            new String[] { Long.class.getName(), String.class.getName() });
597    
598            /**
599             * Returns the user ID mapper where userId = &#63; and type = &#63; or throws a {@link NoSuchUserIdMapperException} if it could not be found.
600             *
601             * @param userId the user ID
602             * @param type the type
603             * @return the matching user ID mapper
604             * @throws NoSuchUserIdMapperException if a matching user ID mapper could not be found
605             */
606            @Override
607            public UserIdMapper findByU_T(long userId, String type)
608                    throws NoSuchUserIdMapperException {
609                    UserIdMapper userIdMapper = fetchByU_T(userId, type);
610    
611                    if (userIdMapper == null) {
612                            StringBundler msg = new StringBundler(6);
613    
614                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
615    
616                            msg.append("userId=");
617                            msg.append(userId);
618    
619                            msg.append(", type=");
620                            msg.append(type);
621    
622                            msg.append(StringPool.CLOSE_CURLY_BRACE);
623    
624                            if (_log.isWarnEnabled()) {
625                                    _log.warn(msg.toString());
626                            }
627    
628                            throw new NoSuchUserIdMapperException(msg.toString());
629                    }
630    
631                    return userIdMapper;
632            }
633    
634            /**
635             * Returns 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.
636             *
637             * @param userId the user ID
638             * @param type the type
639             * @return the matching user ID mapper, or <code>null</code> if a matching user ID mapper could not be found
640             */
641            @Override
642            public UserIdMapper fetchByU_T(long userId, String type) {
643                    return fetchByU_T(userId, type, true);
644            }
645    
646            /**
647             * Returns 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.
648             *
649             * @param userId the user ID
650             * @param type the type
651             * @param retrieveFromCache whether to retrieve from the finder cache
652             * @return the matching user ID mapper, or <code>null</code> if a matching user ID mapper could not be found
653             */
654            @Override
655            public UserIdMapper fetchByU_T(long userId, String type,
656                    boolean retrieveFromCache) {
657                    Object[] finderArgs = new Object[] { userId, type };
658    
659                    Object result = null;
660    
661                    if (retrieveFromCache) {
662                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_U_T,
663                                            finderArgs, this);
664                    }
665    
666                    if (result instanceof UserIdMapper) {
667                            UserIdMapper userIdMapper = (UserIdMapper)result;
668    
669                            if ((userId != userIdMapper.getUserId()) ||
670                                            !Validator.equals(type, userIdMapper.getType())) {
671                                    result = null;
672                            }
673                    }
674    
675                    if (result == null) {
676                            StringBundler query = new StringBundler(4);
677    
678                            query.append(_SQL_SELECT_USERIDMAPPER_WHERE);
679    
680                            query.append(_FINDER_COLUMN_U_T_USERID_2);
681    
682                            boolean bindType = false;
683    
684                            if (type == null) {
685                                    query.append(_FINDER_COLUMN_U_T_TYPE_1);
686                            }
687                            else if (type.equals(StringPool.BLANK)) {
688                                    query.append(_FINDER_COLUMN_U_T_TYPE_3);
689                            }
690                            else {
691                                    bindType = true;
692    
693                                    query.append(_FINDER_COLUMN_U_T_TYPE_2);
694                            }
695    
696                            String sql = query.toString();
697    
698                            Session session = null;
699    
700                            try {
701                                    session = openSession();
702    
703                                    Query q = session.createQuery(sql);
704    
705                                    QueryPos qPos = QueryPos.getInstance(q);
706    
707                                    qPos.add(userId);
708    
709                                    if (bindType) {
710                                            qPos.add(type);
711                                    }
712    
713                                    List<UserIdMapper> list = q.list();
714    
715                                    if (list.isEmpty()) {
716                                            finderCache.putResult(FINDER_PATH_FETCH_BY_U_T, finderArgs,
717                                                    list);
718                                    }
719                                    else {
720                                            UserIdMapper userIdMapper = list.get(0);
721    
722                                            result = userIdMapper;
723    
724                                            cacheResult(userIdMapper);
725    
726                                            if ((userIdMapper.getUserId() != userId) ||
727                                                            (userIdMapper.getType() == null) ||
728                                                            !userIdMapper.getType().equals(type)) {
729                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_U_T,
730                                                            finderArgs, userIdMapper);
731                                            }
732                                    }
733                            }
734                            catch (Exception e) {
735                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_U_T, finderArgs);
736    
737                                    throw processException(e);
738                            }
739                            finally {
740                                    closeSession(session);
741                            }
742                    }
743    
744                    if (result instanceof List<?>) {
745                            return null;
746                    }
747                    else {
748                            return (UserIdMapper)result;
749                    }
750            }
751    
752            /**
753             * Removes the user ID mapper where userId = &#63; and type = &#63; from the database.
754             *
755             * @param userId the user ID
756             * @param type the type
757             * @return the user ID mapper that was removed
758             */
759            @Override
760            public UserIdMapper removeByU_T(long userId, String type)
761                    throws NoSuchUserIdMapperException {
762                    UserIdMapper userIdMapper = findByU_T(userId, type);
763    
764                    return remove(userIdMapper);
765            }
766    
767            /**
768             * Returns the number of user ID mappers where userId = &#63; and type = &#63;.
769             *
770             * @param userId the user ID
771             * @param type the type
772             * @return the number of matching user ID mappers
773             */
774            @Override
775            public int countByU_T(long userId, String type) {
776                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_T;
777    
778                    Object[] finderArgs = new Object[] { userId, type };
779    
780                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
781    
782                    if (count == null) {
783                            StringBundler query = new StringBundler(3);
784    
785                            query.append(_SQL_COUNT_USERIDMAPPER_WHERE);
786    
787                            query.append(_FINDER_COLUMN_U_T_USERID_2);
788    
789                            boolean bindType = false;
790    
791                            if (type == null) {
792                                    query.append(_FINDER_COLUMN_U_T_TYPE_1);
793                            }
794                            else if (type.equals(StringPool.BLANK)) {
795                                    query.append(_FINDER_COLUMN_U_T_TYPE_3);
796                            }
797                            else {
798                                    bindType = true;
799    
800                                    query.append(_FINDER_COLUMN_U_T_TYPE_2);
801                            }
802    
803                            String sql = query.toString();
804    
805                            Session session = null;
806    
807                            try {
808                                    session = openSession();
809    
810                                    Query q = session.createQuery(sql);
811    
812                                    QueryPos qPos = QueryPos.getInstance(q);
813    
814                                    qPos.add(userId);
815    
816                                    if (bindType) {
817                                            qPos.add(type);
818                                    }
819    
820                                    count = (Long)q.uniqueResult();
821    
822                                    finderCache.putResult(finderPath, finderArgs, count);
823                            }
824                            catch (Exception e) {
825                                    finderCache.removeResult(finderPath, finderArgs);
826    
827                                    throw processException(e);
828                            }
829                            finally {
830                                    closeSession(session);
831                            }
832                    }
833    
834                    return count.intValue();
835            }
836    
837            private static final String _FINDER_COLUMN_U_T_USERID_2 = "userIdMapper.userId = ? AND ";
838            private static final String _FINDER_COLUMN_U_T_TYPE_1 = "userIdMapper.type IS NULL";
839            private static final String _FINDER_COLUMN_U_T_TYPE_2 = "userIdMapper.type = ?";
840            private static final String _FINDER_COLUMN_U_T_TYPE_3 = "(userIdMapper.type IS NULL OR userIdMapper.type = '')";
841            public static final FinderPath FINDER_PATH_FETCH_BY_T_E = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
842                            UserIdMapperModelImpl.FINDER_CACHE_ENABLED, UserIdMapperImpl.class,
843                            FINDER_CLASS_NAME_ENTITY, "fetchByT_E",
844                            new String[] { String.class.getName(), String.class.getName() },
845                            UserIdMapperModelImpl.TYPE_COLUMN_BITMASK |
846                            UserIdMapperModelImpl.EXTERNALUSERID_COLUMN_BITMASK);
847            public static final FinderPath FINDER_PATH_COUNT_BY_T_E = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
848                            UserIdMapperModelImpl.FINDER_CACHE_ENABLED, Long.class,
849                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_E",
850                            new String[] { String.class.getName(), String.class.getName() });
851    
852            /**
853             * Returns the user ID mapper where type = &#63; and externalUserId = &#63; or throws a {@link NoSuchUserIdMapperException} if it could not be found.
854             *
855             * @param type the type
856             * @param externalUserId the external user ID
857             * @return the matching user ID mapper
858             * @throws NoSuchUserIdMapperException if a matching user ID mapper could not be found
859             */
860            @Override
861            public UserIdMapper findByT_E(String type, String externalUserId)
862                    throws NoSuchUserIdMapperException {
863                    UserIdMapper userIdMapper = fetchByT_E(type, externalUserId);
864    
865                    if (userIdMapper == null) {
866                            StringBundler msg = new StringBundler(6);
867    
868                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
869    
870                            msg.append("type=");
871                            msg.append(type);
872    
873                            msg.append(", externalUserId=");
874                            msg.append(externalUserId);
875    
876                            msg.append(StringPool.CLOSE_CURLY_BRACE);
877    
878                            if (_log.isWarnEnabled()) {
879                                    _log.warn(msg.toString());
880                            }
881    
882                            throw new NoSuchUserIdMapperException(msg.toString());
883                    }
884    
885                    return userIdMapper;
886            }
887    
888            /**
889             * Returns 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.
890             *
891             * @param type the type
892             * @param externalUserId the external user ID
893             * @return the matching user ID mapper, or <code>null</code> if a matching user ID mapper could not be found
894             */
895            @Override
896            public UserIdMapper fetchByT_E(String type, String externalUserId) {
897                    return fetchByT_E(type, externalUserId, true);
898            }
899    
900            /**
901             * Returns 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.
902             *
903             * @param type the type
904             * @param externalUserId the external user ID
905             * @param retrieveFromCache whether to retrieve from the finder cache
906             * @return the matching user ID mapper, or <code>null</code> if a matching user ID mapper could not be found
907             */
908            @Override
909            public UserIdMapper fetchByT_E(String type, String externalUserId,
910                    boolean retrieveFromCache) {
911                    Object[] finderArgs = new Object[] { type, externalUserId };
912    
913                    Object result = null;
914    
915                    if (retrieveFromCache) {
916                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_T_E,
917                                            finderArgs, this);
918                    }
919    
920                    if (result instanceof UserIdMapper) {
921                            UserIdMapper userIdMapper = (UserIdMapper)result;
922    
923                            if (!Validator.equals(type, userIdMapper.getType()) ||
924                                            !Validator.equals(externalUserId,
925                                                    userIdMapper.getExternalUserId())) {
926                                    result = null;
927                            }
928                    }
929    
930                    if (result == null) {
931                            StringBundler query = new StringBundler(4);
932    
933                            query.append(_SQL_SELECT_USERIDMAPPER_WHERE);
934    
935                            boolean bindType = false;
936    
937                            if (type == null) {
938                                    query.append(_FINDER_COLUMN_T_E_TYPE_1);
939                            }
940                            else if (type.equals(StringPool.BLANK)) {
941                                    query.append(_FINDER_COLUMN_T_E_TYPE_3);
942                            }
943                            else {
944                                    bindType = true;
945    
946                                    query.append(_FINDER_COLUMN_T_E_TYPE_2);
947                            }
948    
949                            boolean bindExternalUserId = false;
950    
951                            if (externalUserId == null) {
952                                    query.append(_FINDER_COLUMN_T_E_EXTERNALUSERID_1);
953                            }
954                            else if (externalUserId.equals(StringPool.BLANK)) {
955                                    query.append(_FINDER_COLUMN_T_E_EXTERNALUSERID_3);
956                            }
957                            else {
958                                    bindExternalUserId = true;
959    
960                                    query.append(_FINDER_COLUMN_T_E_EXTERNALUSERID_2);
961                            }
962    
963                            String sql = query.toString();
964    
965                            Session session = null;
966    
967                            try {
968                                    session = openSession();
969    
970                                    Query q = session.createQuery(sql);
971    
972                                    QueryPos qPos = QueryPos.getInstance(q);
973    
974                                    if (bindType) {
975                                            qPos.add(type);
976                                    }
977    
978                                    if (bindExternalUserId) {
979                                            qPos.add(externalUserId);
980                                    }
981    
982                                    List<UserIdMapper> list = q.list();
983    
984                                    if (list.isEmpty()) {
985                                            finderCache.putResult(FINDER_PATH_FETCH_BY_T_E, finderArgs,
986                                                    list);
987                                    }
988                                    else {
989                                            UserIdMapper userIdMapper = list.get(0);
990    
991                                            result = userIdMapper;
992    
993                                            cacheResult(userIdMapper);
994    
995                                            if ((userIdMapper.getType() == null) ||
996                                                            !userIdMapper.getType().equals(type) ||
997                                                            (userIdMapper.getExternalUserId() == null) ||
998                                                            !userIdMapper.getExternalUserId()
999                                                                                             .equals(externalUserId)) {
1000                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_T_E,
1001                                                            finderArgs, userIdMapper);
1002                                            }
1003                                    }
1004                            }
1005                            catch (Exception e) {
1006                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_T_E, finderArgs);
1007    
1008                                    throw processException(e);
1009                            }
1010                            finally {
1011                                    closeSession(session);
1012                            }
1013                    }
1014    
1015                    if (result instanceof List<?>) {
1016                            return null;
1017                    }
1018                    else {
1019                            return (UserIdMapper)result;
1020                    }
1021            }
1022    
1023            /**
1024             * Removes the user ID mapper where type = &#63; and externalUserId = &#63; from the database.
1025             *
1026             * @param type the type
1027             * @param externalUserId the external user ID
1028             * @return the user ID mapper that was removed
1029             */
1030            @Override
1031            public UserIdMapper removeByT_E(String type, String externalUserId)
1032                    throws NoSuchUserIdMapperException {
1033                    UserIdMapper userIdMapper = findByT_E(type, externalUserId);
1034    
1035                    return remove(userIdMapper);
1036            }
1037    
1038            /**
1039             * Returns the number of user ID mappers where type = &#63; and externalUserId = &#63;.
1040             *
1041             * @param type the type
1042             * @param externalUserId the external user ID
1043             * @return the number of matching user ID mappers
1044             */
1045            @Override
1046            public int countByT_E(String type, String externalUserId) {
1047                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_E;
1048    
1049                    Object[] finderArgs = new Object[] { type, externalUserId };
1050    
1051                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1052    
1053                    if (count == null) {
1054                            StringBundler query = new StringBundler(3);
1055    
1056                            query.append(_SQL_COUNT_USERIDMAPPER_WHERE);
1057    
1058                            boolean bindType = false;
1059    
1060                            if (type == null) {
1061                                    query.append(_FINDER_COLUMN_T_E_TYPE_1);
1062                            }
1063                            else if (type.equals(StringPool.BLANK)) {
1064                                    query.append(_FINDER_COLUMN_T_E_TYPE_3);
1065                            }
1066                            else {
1067                                    bindType = true;
1068    
1069                                    query.append(_FINDER_COLUMN_T_E_TYPE_2);
1070                            }
1071    
1072                            boolean bindExternalUserId = false;
1073    
1074                            if (externalUserId == null) {
1075                                    query.append(_FINDER_COLUMN_T_E_EXTERNALUSERID_1);
1076                            }
1077                            else if (externalUserId.equals(StringPool.BLANK)) {
1078                                    query.append(_FINDER_COLUMN_T_E_EXTERNALUSERID_3);
1079                            }
1080                            else {
1081                                    bindExternalUserId = true;
1082    
1083                                    query.append(_FINDER_COLUMN_T_E_EXTERNALUSERID_2);
1084                            }
1085    
1086                            String sql = query.toString();
1087    
1088                            Session session = null;
1089    
1090                            try {
1091                                    session = openSession();
1092    
1093                                    Query q = session.createQuery(sql);
1094    
1095                                    QueryPos qPos = QueryPos.getInstance(q);
1096    
1097                                    if (bindType) {
1098                                            qPos.add(type);
1099                                    }
1100    
1101                                    if (bindExternalUserId) {
1102                                            qPos.add(externalUserId);
1103                                    }
1104    
1105                                    count = (Long)q.uniqueResult();
1106    
1107                                    finderCache.putResult(finderPath, finderArgs, count);
1108                            }
1109                            catch (Exception e) {
1110                                    finderCache.removeResult(finderPath, finderArgs);
1111    
1112                                    throw processException(e);
1113                            }
1114                            finally {
1115                                    closeSession(session);
1116                            }
1117                    }
1118    
1119                    return count.intValue();
1120            }
1121    
1122            private static final String _FINDER_COLUMN_T_E_TYPE_1 = "userIdMapper.type IS NULL AND ";
1123            private static final String _FINDER_COLUMN_T_E_TYPE_2 = "userIdMapper.type = ? AND ";
1124            private static final String _FINDER_COLUMN_T_E_TYPE_3 = "(userIdMapper.type IS NULL OR userIdMapper.type = '') AND ";
1125            private static final String _FINDER_COLUMN_T_E_EXTERNALUSERID_1 = "userIdMapper.externalUserId IS NULL";
1126            private static final String _FINDER_COLUMN_T_E_EXTERNALUSERID_2 = "userIdMapper.externalUserId = ?";
1127            private static final String _FINDER_COLUMN_T_E_EXTERNALUSERID_3 = "(userIdMapper.externalUserId IS NULL OR userIdMapper.externalUserId = '')";
1128    
1129            public UserIdMapperPersistenceImpl() {
1130                    setModelClass(UserIdMapper.class);
1131            }
1132    
1133            /**
1134             * Caches the user ID mapper in the entity cache if it is enabled.
1135             *
1136             * @param userIdMapper the user ID mapper
1137             */
1138            @Override
1139            public void cacheResult(UserIdMapper userIdMapper) {
1140                    entityCache.putResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
1141                            UserIdMapperImpl.class, userIdMapper.getPrimaryKey(), userIdMapper);
1142    
1143                    finderCache.putResult(FINDER_PATH_FETCH_BY_U_T,
1144                            new Object[] { userIdMapper.getUserId(), userIdMapper.getType() },
1145                            userIdMapper);
1146    
1147                    finderCache.putResult(FINDER_PATH_FETCH_BY_T_E,
1148                            new Object[] {
1149                                    userIdMapper.getType(), userIdMapper.getExternalUserId()
1150                            }, userIdMapper);
1151    
1152                    userIdMapper.resetOriginalValues();
1153            }
1154    
1155            /**
1156             * Caches the user ID mappers in the entity cache if it is enabled.
1157             *
1158             * @param userIdMappers the user ID mappers
1159             */
1160            @Override
1161            public void cacheResult(List<UserIdMapper> userIdMappers) {
1162                    for (UserIdMapper userIdMapper : userIdMappers) {
1163                            if (entityCache.getResult(
1164                                                    UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
1165                                                    UserIdMapperImpl.class, userIdMapper.getPrimaryKey()) == null) {
1166                                    cacheResult(userIdMapper);
1167                            }
1168                            else {
1169                                    userIdMapper.resetOriginalValues();
1170                            }
1171                    }
1172            }
1173    
1174            /**
1175             * Clears the cache for all user ID mappers.
1176             *
1177             * <p>
1178             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
1179             * </p>
1180             */
1181            @Override
1182            public void clearCache() {
1183                    entityCache.clearCache(UserIdMapperImpl.class);
1184    
1185                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
1186                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1187                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1188            }
1189    
1190            /**
1191             * Clears the cache for the user ID mapper.
1192             *
1193             * <p>
1194             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
1195             * </p>
1196             */
1197            @Override
1198            public void clearCache(UserIdMapper userIdMapper) {
1199                    entityCache.removeResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
1200                            UserIdMapperImpl.class, userIdMapper.getPrimaryKey());
1201    
1202                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1203                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1204    
1205                    clearUniqueFindersCache((UserIdMapperModelImpl)userIdMapper);
1206            }
1207    
1208            @Override
1209            public void clearCache(List<UserIdMapper> userIdMappers) {
1210                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1211                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1212    
1213                    for (UserIdMapper userIdMapper : userIdMappers) {
1214                            entityCache.removeResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
1215                                    UserIdMapperImpl.class, userIdMapper.getPrimaryKey());
1216    
1217                            clearUniqueFindersCache((UserIdMapperModelImpl)userIdMapper);
1218                    }
1219            }
1220    
1221            protected void cacheUniqueFindersCache(
1222                    UserIdMapperModelImpl userIdMapperModelImpl, boolean isNew) {
1223                    if (isNew) {
1224                            Object[] args = new Object[] {
1225                                            userIdMapperModelImpl.getUserId(),
1226                                            userIdMapperModelImpl.getType()
1227                                    };
1228    
1229                            finderCache.putResult(FINDER_PATH_COUNT_BY_U_T, args,
1230                                    Long.valueOf(1));
1231                            finderCache.putResult(FINDER_PATH_FETCH_BY_U_T, args,
1232                                    userIdMapperModelImpl);
1233    
1234                            args = new Object[] {
1235                                            userIdMapperModelImpl.getType(),
1236                                            userIdMapperModelImpl.getExternalUserId()
1237                                    };
1238    
1239                            finderCache.putResult(FINDER_PATH_COUNT_BY_T_E, args,
1240                                    Long.valueOf(1));
1241                            finderCache.putResult(FINDER_PATH_FETCH_BY_T_E, args,
1242                                    userIdMapperModelImpl);
1243                    }
1244                    else {
1245                            if ((userIdMapperModelImpl.getColumnBitmask() &
1246                                            FINDER_PATH_FETCH_BY_U_T.getColumnBitmask()) != 0) {
1247                                    Object[] args = new Object[] {
1248                                                    userIdMapperModelImpl.getUserId(),
1249                                                    userIdMapperModelImpl.getType()
1250                                            };
1251    
1252                                    finderCache.putResult(FINDER_PATH_COUNT_BY_U_T, args,
1253                                            Long.valueOf(1));
1254                                    finderCache.putResult(FINDER_PATH_FETCH_BY_U_T, args,
1255                                            userIdMapperModelImpl);
1256                            }
1257    
1258                            if ((userIdMapperModelImpl.getColumnBitmask() &
1259                                            FINDER_PATH_FETCH_BY_T_E.getColumnBitmask()) != 0) {
1260                                    Object[] args = new Object[] {
1261                                                    userIdMapperModelImpl.getType(),
1262                                                    userIdMapperModelImpl.getExternalUserId()
1263                                            };
1264    
1265                                    finderCache.putResult(FINDER_PATH_COUNT_BY_T_E, args,
1266                                            Long.valueOf(1));
1267                                    finderCache.putResult(FINDER_PATH_FETCH_BY_T_E, args,
1268                                            userIdMapperModelImpl);
1269                            }
1270                    }
1271            }
1272    
1273            protected void clearUniqueFindersCache(
1274                    UserIdMapperModelImpl userIdMapperModelImpl) {
1275                    Object[] args = new Object[] {
1276                                    userIdMapperModelImpl.getUserId(),
1277                                    userIdMapperModelImpl.getType()
1278                            };
1279    
1280                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_T, args);
1281                    finderCache.removeResult(FINDER_PATH_FETCH_BY_U_T, args);
1282    
1283                    if ((userIdMapperModelImpl.getColumnBitmask() &
1284                                    FINDER_PATH_FETCH_BY_U_T.getColumnBitmask()) != 0) {
1285                            args = new Object[] {
1286                                            userIdMapperModelImpl.getOriginalUserId(),
1287                                            userIdMapperModelImpl.getOriginalType()
1288                                    };
1289    
1290                            finderCache.removeResult(FINDER_PATH_COUNT_BY_U_T, args);
1291                            finderCache.removeResult(FINDER_PATH_FETCH_BY_U_T, args);
1292                    }
1293    
1294                    args = new Object[] {
1295                                    userIdMapperModelImpl.getType(),
1296                                    userIdMapperModelImpl.getExternalUserId()
1297                            };
1298    
1299                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_E, args);
1300                    finderCache.removeResult(FINDER_PATH_FETCH_BY_T_E, args);
1301    
1302                    if ((userIdMapperModelImpl.getColumnBitmask() &
1303                                    FINDER_PATH_FETCH_BY_T_E.getColumnBitmask()) != 0) {
1304                            args = new Object[] {
1305                                            userIdMapperModelImpl.getOriginalType(),
1306                                            userIdMapperModelImpl.getOriginalExternalUserId()
1307                                    };
1308    
1309                            finderCache.removeResult(FINDER_PATH_COUNT_BY_T_E, args);
1310                            finderCache.removeResult(FINDER_PATH_FETCH_BY_T_E, args);
1311                    }
1312            }
1313    
1314            /**
1315             * Creates a new user ID mapper with the primary key. Does not add the user ID mapper to the database.
1316             *
1317             * @param userIdMapperId the primary key for the new user ID mapper
1318             * @return the new user ID mapper
1319             */
1320            @Override
1321            public UserIdMapper create(long userIdMapperId) {
1322                    UserIdMapper userIdMapper = new UserIdMapperImpl();
1323    
1324                    userIdMapper.setNew(true);
1325                    userIdMapper.setPrimaryKey(userIdMapperId);
1326    
1327                    return userIdMapper;
1328            }
1329    
1330            /**
1331             * Removes the user ID mapper with the primary key from the database. Also notifies the appropriate model listeners.
1332             *
1333             * @param userIdMapperId the primary key of the user ID mapper
1334             * @return the user ID mapper that was removed
1335             * @throws NoSuchUserIdMapperException if a user ID mapper with the primary key could not be found
1336             */
1337            @Override
1338            public UserIdMapper remove(long userIdMapperId)
1339                    throws NoSuchUserIdMapperException {
1340                    return remove((Serializable)userIdMapperId);
1341            }
1342    
1343            /**
1344             * Removes the user ID mapper with the primary key from the database. Also notifies the appropriate model listeners.
1345             *
1346             * @param primaryKey the primary key of the user ID mapper
1347             * @return the user ID mapper that was removed
1348             * @throws NoSuchUserIdMapperException if a user ID mapper with the primary key could not be found
1349             */
1350            @Override
1351            public UserIdMapper remove(Serializable primaryKey)
1352                    throws NoSuchUserIdMapperException {
1353                    Session session = null;
1354    
1355                    try {
1356                            session = openSession();
1357    
1358                            UserIdMapper userIdMapper = (UserIdMapper)session.get(UserIdMapperImpl.class,
1359                                            primaryKey);
1360    
1361                            if (userIdMapper == null) {
1362                                    if (_log.isWarnEnabled()) {
1363                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1364                                    }
1365    
1366                                    throw new NoSuchUserIdMapperException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1367                                            primaryKey);
1368                            }
1369    
1370                            return remove(userIdMapper);
1371                    }
1372                    catch (NoSuchUserIdMapperException nsee) {
1373                            throw nsee;
1374                    }
1375                    catch (Exception e) {
1376                            throw processException(e);
1377                    }
1378                    finally {
1379                            closeSession(session);
1380                    }
1381            }
1382    
1383            @Override
1384            protected UserIdMapper removeImpl(UserIdMapper userIdMapper) {
1385                    userIdMapper = toUnwrappedModel(userIdMapper);
1386    
1387                    Session session = null;
1388    
1389                    try {
1390                            session = openSession();
1391    
1392                            if (!session.contains(userIdMapper)) {
1393                                    userIdMapper = (UserIdMapper)session.get(UserIdMapperImpl.class,
1394                                                    userIdMapper.getPrimaryKeyObj());
1395                            }
1396    
1397                            if (userIdMapper != null) {
1398                                    session.delete(userIdMapper);
1399                            }
1400                    }
1401                    catch (Exception e) {
1402                            throw processException(e);
1403                    }
1404                    finally {
1405                            closeSession(session);
1406                    }
1407    
1408                    if (userIdMapper != null) {
1409                            clearCache(userIdMapper);
1410                    }
1411    
1412                    return userIdMapper;
1413            }
1414    
1415            @Override
1416            public UserIdMapper updateImpl(UserIdMapper userIdMapper) {
1417                    userIdMapper = toUnwrappedModel(userIdMapper);
1418    
1419                    boolean isNew = userIdMapper.isNew();
1420    
1421                    UserIdMapperModelImpl userIdMapperModelImpl = (UserIdMapperModelImpl)userIdMapper;
1422    
1423                    Session session = null;
1424    
1425                    try {
1426                            session = openSession();
1427    
1428                            if (userIdMapper.isNew()) {
1429                                    session.save(userIdMapper);
1430    
1431                                    userIdMapper.setNew(false);
1432                            }
1433                            else {
1434                                    userIdMapper = (UserIdMapper)session.merge(userIdMapper);
1435                            }
1436                    }
1437                    catch (Exception e) {
1438                            throw processException(e);
1439                    }
1440                    finally {
1441                            closeSession(session);
1442                    }
1443    
1444                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1445    
1446                    if (isNew || !UserIdMapperModelImpl.COLUMN_BITMASK_ENABLED) {
1447                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1448                    }
1449    
1450                    else {
1451                            if ((userIdMapperModelImpl.getColumnBitmask() &
1452                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
1453                                    Object[] args = new Object[] {
1454                                                    userIdMapperModelImpl.getOriginalUserId()
1455                                            };
1456    
1457                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1458                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1459                                            args);
1460    
1461                                    args = new Object[] { userIdMapperModelImpl.getUserId() };
1462    
1463                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1464                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1465                                            args);
1466                            }
1467                    }
1468    
1469                    entityCache.putResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
1470                            UserIdMapperImpl.class, userIdMapper.getPrimaryKey(), userIdMapper,
1471                            false);
1472    
1473                    clearUniqueFindersCache(userIdMapperModelImpl);
1474                    cacheUniqueFindersCache(userIdMapperModelImpl, isNew);
1475    
1476                    userIdMapper.resetOriginalValues();
1477    
1478                    return userIdMapper;
1479            }
1480    
1481            protected UserIdMapper toUnwrappedModel(UserIdMapper userIdMapper) {
1482                    if (userIdMapper instanceof UserIdMapperImpl) {
1483                            return userIdMapper;
1484                    }
1485    
1486                    UserIdMapperImpl userIdMapperImpl = new UserIdMapperImpl();
1487    
1488                    userIdMapperImpl.setNew(userIdMapper.isNew());
1489                    userIdMapperImpl.setPrimaryKey(userIdMapper.getPrimaryKey());
1490    
1491                    userIdMapperImpl.setMvccVersion(userIdMapper.getMvccVersion());
1492                    userIdMapperImpl.setUserIdMapperId(userIdMapper.getUserIdMapperId());
1493                    userIdMapperImpl.setUserId(userIdMapper.getUserId());
1494                    userIdMapperImpl.setType(userIdMapper.getType());
1495                    userIdMapperImpl.setDescription(userIdMapper.getDescription());
1496                    userIdMapperImpl.setExternalUserId(userIdMapper.getExternalUserId());
1497    
1498                    return userIdMapperImpl;
1499            }
1500    
1501            /**
1502             * Returns the user ID mapper with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1503             *
1504             * @param primaryKey the primary key of the user ID mapper
1505             * @return the user ID mapper
1506             * @throws NoSuchUserIdMapperException if a user ID mapper with the primary key could not be found
1507             */
1508            @Override
1509            public UserIdMapper findByPrimaryKey(Serializable primaryKey)
1510                    throws NoSuchUserIdMapperException {
1511                    UserIdMapper userIdMapper = fetchByPrimaryKey(primaryKey);
1512    
1513                    if (userIdMapper == null) {
1514                            if (_log.isWarnEnabled()) {
1515                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1516                            }
1517    
1518                            throw new NoSuchUserIdMapperException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1519                                    primaryKey);
1520                    }
1521    
1522                    return userIdMapper;
1523            }
1524    
1525            /**
1526             * Returns the user ID mapper with the primary key or throws a {@link NoSuchUserIdMapperException} if it could not be found.
1527             *
1528             * @param userIdMapperId the primary key of the user ID mapper
1529             * @return the user ID mapper
1530             * @throws NoSuchUserIdMapperException if a user ID mapper with the primary key could not be found
1531             */
1532            @Override
1533            public UserIdMapper findByPrimaryKey(long userIdMapperId)
1534                    throws NoSuchUserIdMapperException {
1535                    return findByPrimaryKey((Serializable)userIdMapperId);
1536            }
1537    
1538            /**
1539             * Returns the user ID mapper with the primary key or returns <code>null</code> if it could not be found.
1540             *
1541             * @param primaryKey the primary key of the user ID mapper
1542             * @return the user ID mapper, or <code>null</code> if a user ID mapper with the primary key could not be found
1543             */
1544            @Override
1545            public UserIdMapper fetchByPrimaryKey(Serializable primaryKey) {
1546                    UserIdMapper userIdMapper = (UserIdMapper)entityCache.getResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
1547                                    UserIdMapperImpl.class, primaryKey);
1548    
1549                    if (userIdMapper == _nullUserIdMapper) {
1550                            return null;
1551                    }
1552    
1553                    if (userIdMapper == null) {
1554                            Session session = null;
1555    
1556                            try {
1557                                    session = openSession();
1558    
1559                                    userIdMapper = (UserIdMapper)session.get(UserIdMapperImpl.class,
1560                                                    primaryKey);
1561    
1562                                    if (userIdMapper != null) {
1563                                            cacheResult(userIdMapper);
1564                                    }
1565                                    else {
1566                                            entityCache.putResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
1567                                                    UserIdMapperImpl.class, primaryKey, _nullUserIdMapper);
1568                                    }
1569                            }
1570                            catch (Exception e) {
1571                                    entityCache.removeResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
1572                                            UserIdMapperImpl.class, primaryKey);
1573    
1574                                    throw processException(e);
1575                            }
1576                            finally {
1577                                    closeSession(session);
1578                            }
1579                    }
1580    
1581                    return userIdMapper;
1582            }
1583    
1584            /**
1585             * Returns the user ID mapper with the primary key or returns <code>null</code> if it could not be found.
1586             *
1587             * @param userIdMapperId the primary key of the user ID mapper
1588             * @return the user ID mapper, or <code>null</code> if a user ID mapper with the primary key could not be found
1589             */
1590            @Override
1591            public UserIdMapper fetchByPrimaryKey(long userIdMapperId) {
1592                    return fetchByPrimaryKey((Serializable)userIdMapperId);
1593            }
1594    
1595            @Override
1596            public Map<Serializable, UserIdMapper> fetchByPrimaryKeys(
1597                    Set<Serializable> primaryKeys) {
1598                    if (primaryKeys.isEmpty()) {
1599                            return Collections.emptyMap();
1600                    }
1601    
1602                    Map<Serializable, UserIdMapper> map = new HashMap<Serializable, UserIdMapper>();
1603    
1604                    if (primaryKeys.size() == 1) {
1605                            Iterator<Serializable> iterator = primaryKeys.iterator();
1606    
1607                            Serializable primaryKey = iterator.next();
1608    
1609                            UserIdMapper userIdMapper = fetchByPrimaryKey(primaryKey);
1610    
1611                            if (userIdMapper != null) {
1612                                    map.put(primaryKey, userIdMapper);
1613                            }
1614    
1615                            return map;
1616                    }
1617    
1618                    Set<Serializable> uncachedPrimaryKeys = null;
1619    
1620                    for (Serializable primaryKey : primaryKeys) {
1621                            UserIdMapper userIdMapper = (UserIdMapper)entityCache.getResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
1622                                            UserIdMapperImpl.class, primaryKey);
1623    
1624                            if (userIdMapper == null) {
1625                                    if (uncachedPrimaryKeys == null) {
1626                                            uncachedPrimaryKeys = new HashSet<Serializable>();
1627                                    }
1628    
1629                                    uncachedPrimaryKeys.add(primaryKey);
1630                            }
1631                            else {
1632                                    map.put(primaryKey, userIdMapper);
1633                            }
1634                    }
1635    
1636                    if (uncachedPrimaryKeys == null) {
1637                            return map;
1638                    }
1639    
1640                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1641                                    1);
1642    
1643                    query.append(_SQL_SELECT_USERIDMAPPER_WHERE_PKS_IN);
1644    
1645                    for (Serializable primaryKey : uncachedPrimaryKeys) {
1646                            query.append(String.valueOf(primaryKey));
1647    
1648                            query.append(StringPool.COMMA);
1649                    }
1650    
1651                    query.setIndex(query.index() - 1);
1652    
1653                    query.append(StringPool.CLOSE_PARENTHESIS);
1654    
1655                    String sql = query.toString();
1656    
1657                    Session session = null;
1658    
1659                    try {
1660                            session = openSession();
1661    
1662                            Query q = session.createQuery(sql);
1663    
1664                            for (UserIdMapper userIdMapper : (List<UserIdMapper>)q.list()) {
1665                                    map.put(userIdMapper.getPrimaryKeyObj(), userIdMapper);
1666    
1667                                    cacheResult(userIdMapper);
1668    
1669                                    uncachedPrimaryKeys.remove(userIdMapper.getPrimaryKeyObj());
1670                            }
1671    
1672                            for (Serializable primaryKey : uncachedPrimaryKeys) {
1673                                    entityCache.putResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
1674                                            UserIdMapperImpl.class, primaryKey, _nullUserIdMapper);
1675                            }
1676                    }
1677                    catch (Exception e) {
1678                            throw processException(e);
1679                    }
1680                    finally {
1681                            closeSession(session);
1682                    }
1683    
1684                    return map;
1685            }
1686    
1687            /**
1688             * Returns all the user ID mappers.
1689             *
1690             * @return the user ID mappers
1691             */
1692            @Override
1693            public List<UserIdMapper> findAll() {
1694                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1695            }
1696    
1697            /**
1698             * Returns a range of all the user ID mappers.
1699             *
1700             * <p>
1701             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserIdMapperModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1702             * </p>
1703             *
1704             * @param start the lower bound of the range of user ID mappers
1705             * @param end the upper bound of the range of user ID mappers (not inclusive)
1706             * @return the range of user ID mappers
1707             */
1708            @Override
1709            public List<UserIdMapper> findAll(int start, int end) {
1710                    return findAll(start, end, null);
1711            }
1712    
1713            /**
1714             * Returns an ordered range of all the user ID mappers.
1715             *
1716             * <p>
1717             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserIdMapperModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1718             * </p>
1719             *
1720             * @param start the lower bound of the range of user ID mappers
1721             * @param end the upper bound of the range of user ID mappers (not inclusive)
1722             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1723             * @return the ordered range of user ID mappers
1724             */
1725            @Override
1726            public List<UserIdMapper> findAll(int start, int end,
1727                    OrderByComparator<UserIdMapper> orderByComparator) {
1728                    return findAll(start, end, orderByComparator, true);
1729            }
1730    
1731            /**
1732             * Returns an ordered range of all the user ID mappers.
1733             *
1734             * <p>
1735             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link UserIdMapperModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1736             * </p>
1737             *
1738             * @param start the lower bound of the range of user ID mappers
1739             * @param end the upper bound of the range of user ID mappers (not inclusive)
1740             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1741             * @param retrieveFromCache whether to retrieve from the finder cache
1742             * @return the ordered range of user ID mappers
1743             */
1744            @Override
1745            public List<UserIdMapper> findAll(int start, int end,
1746                    OrderByComparator<UserIdMapper> orderByComparator,
1747                    boolean retrieveFromCache) {
1748                    boolean pagination = true;
1749                    FinderPath finderPath = null;
1750                    Object[] finderArgs = null;
1751    
1752                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1753                                    (orderByComparator == null)) {
1754                            pagination = false;
1755                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1756                            finderArgs = FINDER_ARGS_EMPTY;
1757                    }
1758                    else {
1759                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1760                            finderArgs = new Object[] { start, end, orderByComparator };
1761                    }
1762    
1763                    List<UserIdMapper> list = null;
1764    
1765                    if (retrieveFromCache) {
1766                            list = (List<UserIdMapper>)finderCache.getResult(finderPath,
1767                                            finderArgs, this);
1768                    }
1769    
1770                    if (list == null) {
1771                            StringBundler query = null;
1772                            String sql = null;
1773    
1774                            if (orderByComparator != null) {
1775                                    query = new StringBundler(2 +
1776                                                    (orderByComparator.getOrderByFields().length * 3));
1777    
1778                                    query.append(_SQL_SELECT_USERIDMAPPER);
1779    
1780                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1781                                            orderByComparator);
1782    
1783                                    sql = query.toString();
1784                            }
1785                            else {
1786                                    sql = _SQL_SELECT_USERIDMAPPER;
1787    
1788                                    if (pagination) {
1789                                            sql = sql.concat(UserIdMapperModelImpl.ORDER_BY_JPQL);
1790                                    }
1791                            }
1792    
1793                            Session session = null;
1794    
1795                            try {
1796                                    session = openSession();
1797    
1798                                    Query q = session.createQuery(sql);
1799    
1800                                    if (!pagination) {
1801                                            list = (List<UserIdMapper>)QueryUtil.list(q, getDialect(),
1802                                                            start, end, false);
1803    
1804                                            Collections.sort(list);
1805    
1806                                            list = Collections.unmodifiableList(list);
1807                                    }
1808                                    else {
1809                                            list = (List<UserIdMapper>)QueryUtil.list(q, getDialect(),
1810                                                            start, end);
1811                                    }
1812    
1813                                    cacheResult(list);
1814    
1815                                    finderCache.putResult(finderPath, finderArgs, list);
1816                            }
1817                            catch (Exception e) {
1818                                    finderCache.removeResult(finderPath, finderArgs);
1819    
1820                                    throw processException(e);
1821                            }
1822                            finally {
1823                                    closeSession(session);
1824                            }
1825                    }
1826    
1827                    return list;
1828            }
1829    
1830            /**
1831             * Removes all the user ID mappers from the database.
1832             *
1833             */
1834            @Override
1835            public void removeAll() {
1836                    for (UserIdMapper userIdMapper : findAll()) {
1837                            remove(userIdMapper);
1838                    }
1839            }
1840    
1841            /**
1842             * Returns the number of user ID mappers.
1843             *
1844             * @return the number of user ID mappers
1845             */
1846            @Override
1847            public int countAll() {
1848                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
1849                                    FINDER_ARGS_EMPTY, this);
1850    
1851                    if (count == null) {
1852                            Session session = null;
1853    
1854                            try {
1855                                    session = openSession();
1856    
1857                                    Query q = session.createQuery(_SQL_COUNT_USERIDMAPPER);
1858    
1859                                    count = (Long)q.uniqueResult();
1860    
1861                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
1862                                            count);
1863                            }
1864                            catch (Exception e) {
1865                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
1866                                            FINDER_ARGS_EMPTY);
1867    
1868                                    throw processException(e);
1869                            }
1870                            finally {
1871                                    closeSession(session);
1872                            }
1873                    }
1874    
1875                    return count.intValue();
1876            }
1877    
1878            @Override
1879            public Set<String> getBadColumnNames() {
1880                    return _badColumnNames;
1881            }
1882    
1883            @Override
1884            protected Map<String, Integer> getTableColumnsMap() {
1885                    return UserIdMapperModelImpl.TABLE_COLUMNS_MAP;
1886            }
1887    
1888            /**
1889             * Initializes the user ID mapper persistence.
1890             */
1891            public void afterPropertiesSet() {
1892            }
1893    
1894            public void destroy() {
1895                    entityCache.removeCache(UserIdMapperImpl.class.getName());
1896                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
1897                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1898                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1899            }
1900    
1901            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
1902            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
1903            private static final String _SQL_SELECT_USERIDMAPPER = "SELECT userIdMapper FROM UserIdMapper userIdMapper";
1904            private static final String _SQL_SELECT_USERIDMAPPER_WHERE_PKS_IN = "SELECT userIdMapper FROM UserIdMapper userIdMapper WHERE userIdMapperId IN (";
1905            private static final String _SQL_SELECT_USERIDMAPPER_WHERE = "SELECT userIdMapper FROM UserIdMapper userIdMapper WHERE ";
1906            private static final String _SQL_COUNT_USERIDMAPPER = "SELECT COUNT(userIdMapper) FROM UserIdMapper userIdMapper";
1907            private static final String _SQL_COUNT_USERIDMAPPER_WHERE = "SELECT COUNT(userIdMapper) FROM UserIdMapper userIdMapper WHERE ";
1908            private static final String _ORDER_BY_ENTITY_ALIAS = "userIdMapper.";
1909            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No UserIdMapper exists with the primary key ";
1910            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No UserIdMapper exists with the key {";
1911            private static final Log _log = LogFactoryUtil.getLog(UserIdMapperPersistenceImpl.class);
1912            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1913                                    "type"
1914                            });
1915            private static final UserIdMapper _nullUserIdMapper = new UserIdMapperImpl() {
1916                            @Override
1917                            public Object clone() {
1918                                    return this;
1919                            }
1920    
1921                            @Override
1922                            public CacheModel<UserIdMapper> toCacheModel() {
1923                                    return _nullUserIdMapperCacheModel;
1924                            }
1925                    };
1926    
1927            private static final CacheModel<UserIdMapper> _nullUserIdMapperCacheModel = new NullCacheModel();
1928    
1929            private static class NullCacheModel implements CacheModel<UserIdMapper>,
1930                    MVCCModel {
1931                    @Override
1932                    public long getMvccVersion() {
1933                            return -1;
1934                    }
1935    
1936                    @Override
1937                    public void setMvccVersion(long mvccVersion) {
1938                    }
1939    
1940                    @Override
1941                    public UserIdMapper toEntityModel() {
1942                            return _nullUserIdMapper;
1943                    }
1944            }
1945    }