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