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