001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.NoSuchUserGroupException;
019    import com.liferay.portal.kernel.annotation.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
022    import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
023    import com.liferay.portal.kernel.dao.jdbc.RowMapper;
024    import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
025    import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
026    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
027    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
028    import com.liferay.portal.kernel.dao.orm.FinderPath;
029    import com.liferay.portal.kernel.dao.orm.Query;
030    import com.liferay.portal.kernel.dao.orm.QueryPos;
031    import com.liferay.portal.kernel.dao.orm.QueryUtil;
032    import com.liferay.portal.kernel.dao.orm.SQLQuery;
033    import com.liferay.portal.kernel.dao.orm.Session;
034    import com.liferay.portal.kernel.exception.SystemException;
035    import com.liferay.portal.kernel.log.Log;
036    import com.liferay.portal.kernel.log.LogFactoryUtil;
037    import com.liferay.portal.kernel.util.GetterUtil;
038    import com.liferay.portal.kernel.util.InstanceFactory;
039    import com.liferay.portal.kernel.util.OrderByComparator;
040    import com.liferay.portal.kernel.util.SetUtil;
041    import com.liferay.portal.kernel.util.StringBundler;
042    import com.liferay.portal.kernel.util.StringPool;
043    import com.liferay.portal.kernel.util.StringUtil;
044    import com.liferay.portal.kernel.util.Validator;
045    import com.liferay.portal.model.ModelListener;
046    import com.liferay.portal.model.UserGroup;
047    import com.liferay.portal.model.impl.UserGroupImpl;
048    import com.liferay.portal.model.impl.UserGroupModelImpl;
049    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
050    
051    import java.io.Serializable;
052    
053    import java.util.ArrayList;
054    import java.util.Collections;
055    import java.util.List;
056    import java.util.Set;
057    
058    /**
059     * @author    Brian Wing Shun Chan
060     * @see       UserGroupPersistence
061     * @see       UserGroupUtil
062     * @generated
063     */
064    public class UserGroupPersistenceImpl extends BasePersistenceImpl<UserGroup>
065            implements UserGroupPersistence {
066            public static final String FINDER_CLASS_NAME_ENTITY = UserGroupImpl.class.getName();
067            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
068                    ".List";
069            public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
070                            UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
071                            "findByCompanyId",
072                            new String[] {
073                                    Long.class.getName(),
074                                    
075                            "java.lang.Integer", "java.lang.Integer",
076                                    "com.liferay.portal.kernel.util.OrderByComparator"
077                            });
078            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
079                            UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
080                            "countByCompanyId", new String[] { Long.class.getName() });
081            public static final FinderPath FINDER_PATH_FIND_BY_C_P = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
082                            UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
083                            "findByC_P",
084                            new String[] {
085                                    Long.class.getName(), Long.class.getName(),
086                                    
087                            "java.lang.Integer", "java.lang.Integer",
088                                    "com.liferay.portal.kernel.util.OrderByComparator"
089                            });
090            public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
091                            UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
092                            "countByC_P",
093                            new String[] { Long.class.getName(), Long.class.getName() });
094            public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
095                            UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
096                            "fetchByC_N",
097                            new String[] { Long.class.getName(), String.class.getName() });
098            public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
099                            UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
100                            "countByC_N",
101                            new String[] { Long.class.getName(), String.class.getName() });
102            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
103                            UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
104                            "findAll", new String[0]);
105            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
106                            UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
107                            "countAll", new String[0]);
108    
109            public void cacheResult(UserGroup userGroup) {
110                    EntityCacheUtil.putResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
111                            UserGroupImpl.class, userGroup.getPrimaryKey(), userGroup);
112    
113                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
114                            new Object[] { new Long(userGroup.getCompanyId()), userGroup.getName() },
115                            userGroup);
116            }
117    
118            public void cacheResult(List<UserGroup> userGroups) {
119                    for (UserGroup userGroup : userGroups) {
120                            if (EntityCacheUtil.getResult(
121                                                    UserGroupModelImpl.ENTITY_CACHE_ENABLED,
122                                                    UserGroupImpl.class, userGroup.getPrimaryKey(), this) == null) {
123                                    cacheResult(userGroup);
124                            }
125                    }
126            }
127    
128            public void clearCache() {
129                    CacheRegistryUtil.clear(UserGroupImpl.class.getName());
130                    EntityCacheUtil.clearCache(UserGroupImpl.class.getName());
131                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
132                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
133            }
134    
135            public void clearCache(UserGroup userGroup) {
136                    EntityCacheUtil.removeResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
137                            UserGroupImpl.class, userGroup.getPrimaryKey());
138    
139                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
140                            new Object[] { new Long(userGroup.getCompanyId()), userGroup.getName() });
141            }
142    
143            public UserGroup create(long userGroupId) {
144                    UserGroup userGroup = new UserGroupImpl();
145    
146                    userGroup.setNew(true);
147                    userGroup.setPrimaryKey(userGroupId);
148    
149                    return userGroup;
150            }
151    
152            public UserGroup remove(Serializable primaryKey)
153                    throws NoSuchModelException, SystemException {
154                    return remove(((Long)primaryKey).longValue());
155            }
156    
157            public UserGroup remove(long userGroupId)
158                    throws NoSuchUserGroupException, SystemException {
159                    Session session = null;
160    
161                    try {
162                            session = openSession();
163    
164                            UserGroup userGroup = (UserGroup)session.get(UserGroupImpl.class,
165                                            new Long(userGroupId));
166    
167                            if (userGroup == null) {
168                                    if (_log.isWarnEnabled()) {
169                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + userGroupId);
170                                    }
171    
172                                    throw new NoSuchUserGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
173                                            userGroupId);
174                            }
175    
176                            return remove(userGroup);
177                    }
178                    catch (NoSuchUserGroupException nsee) {
179                            throw nsee;
180                    }
181                    catch (Exception e) {
182                            throw processException(e);
183                    }
184                    finally {
185                            closeSession(session);
186                    }
187            }
188    
189            protected UserGroup removeImpl(UserGroup userGroup)
190                    throws SystemException {
191                    userGroup = toUnwrappedModel(userGroup);
192    
193                    try {
194                            clearGroups.clear(userGroup.getPrimaryKey());
195                    }
196                    catch (Exception e) {
197                            throw processException(e);
198                    }
199                    finally {
200                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
201                    }
202    
203                    try {
204                            clearUsers.clear(userGroup.getPrimaryKey());
205                    }
206                    catch (Exception e) {
207                            throw processException(e);
208                    }
209                    finally {
210                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
211                    }
212    
213                    Session session = null;
214    
215                    try {
216                            session = openSession();
217    
218                            if (userGroup.isCachedModel() || BatchSessionUtil.isEnabled()) {
219                                    Object staleObject = session.get(UserGroupImpl.class,
220                                                    userGroup.getPrimaryKeyObj());
221    
222                                    if (staleObject != null) {
223                                            session.evict(staleObject);
224                                    }
225                            }
226    
227                            session.delete(userGroup);
228    
229                            session.flush();
230                    }
231                    catch (Exception e) {
232                            throw processException(e);
233                    }
234                    finally {
235                            closeSession(session);
236                    }
237    
238                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
239    
240                    UserGroupModelImpl userGroupModelImpl = (UserGroupModelImpl)userGroup;
241    
242                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
243                            new Object[] {
244                                    new Long(userGroupModelImpl.getOriginalCompanyId()),
245                                    
246                            userGroupModelImpl.getOriginalName()
247                            });
248    
249                    EntityCacheUtil.removeResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
250                            UserGroupImpl.class, userGroup.getPrimaryKey());
251    
252                    return userGroup;
253            }
254    
255            public UserGroup updateImpl(com.liferay.portal.model.UserGroup userGroup,
256                    boolean merge) throws SystemException {
257                    userGroup = toUnwrappedModel(userGroup);
258    
259                    boolean isNew = userGroup.isNew();
260    
261                    UserGroupModelImpl userGroupModelImpl = (UserGroupModelImpl)userGroup;
262    
263                    Session session = null;
264    
265                    try {
266                            session = openSession();
267    
268                            BatchSessionUtil.update(session, userGroup, merge);
269    
270                            userGroup.setNew(false);
271                    }
272                    catch (Exception e) {
273                            throw processException(e);
274                    }
275                    finally {
276                            closeSession(session);
277                    }
278    
279                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
280    
281                    EntityCacheUtil.putResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
282                            UserGroupImpl.class, userGroup.getPrimaryKey(), userGroup);
283    
284                    if (!isNew &&
285                                    ((userGroup.getCompanyId() != userGroupModelImpl.getOriginalCompanyId()) ||
286                                    !Validator.equals(userGroup.getName(),
287                                            userGroupModelImpl.getOriginalName()))) {
288                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
289                                    new Object[] {
290                                            new Long(userGroupModelImpl.getOriginalCompanyId()),
291                                            
292                                    userGroupModelImpl.getOriginalName()
293                                    });
294                    }
295    
296                    if (isNew ||
297                                    ((userGroup.getCompanyId() != userGroupModelImpl.getOriginalCompanyId()) ||
298                                    !Validator.equals(userGroup.getName(),
299                                            userGroupModelImpl.getOriginalName()))) {
300                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
301                                    new Object[] {
302                                            new Long(userGroup.getCompanyId()),
303                                            
304                                    userGroup.getName()
305                                    }, userGroup);
306                    }
307    
308                    return userGroup;
309            }
310    
311            protected UserGroup toUnwrappedModel(UserGroup userGroup) {
312                    if (userGroup instanceof UserGroupImpl) {
313                            return userGroup;
314                    }
315    
316                    UserGroupImpl userGroupImpl = new UserGroupImpl();
317    
318                    userGroupImpl.setNew(userGroup.isNew());
319                    userGroupImpl.setPrimaryKey(userGroup.getPrimaryKey());
320    
321                    userGroupImpl.setUserGroupId(userGroup.getUserGroupId());
322                    userGroupImpl.setCompanyId(userGroup.getCompanyId());
323                    userGroupImpl.setParentUserGroupId(userGroup.getParentUserGroupId());
324                    userGroupImpl.setName(userGroup.getName());
325                    userGroupImpl.setDescription(userGroup.getDescription());
326    
327                    return userGroupImpl;
328            }
329    
330            public UserGroup findByPrimaryKey(Serializable primaryKey)
331                    throws NoSuchModelException, SystemException {
332                    return findByPrimaryKey(((Long)primaryKey).longValue());
333            }
334    
335            public UserGroup findByPrimaryKey(long userGroupId)
336                    throws NoSuchUserGroupException, SystemException {
337                    UserGroup userGroup = fetchByPrimaryKey(userGroupId);
338    
339                    if (userGroup == null) {
340                            if (_log.isWarnEnabled()) {
341                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + userGroupId);
342                            }
343    
344                            throw new NoSuchUserGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
345                                    userGroupId);
346                    }
347    
348                    return userGroup;
349            }
350    
351            public UserGroup fetchByPrimaryKey(Serializable primaryKey)
352                    throws SystemException {
353                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
354            }
355    
356            public UserGroup fetchByPrimaryKey(long userGroupId)
357                    throws SystemException {
358                    UserGroup userGroup = (UserGroup)EntityCacheUtil.getResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
359                                    UserGroupImpl.class, userGroupId, this);
360    
361                    if (userGroup == null) {
362                            Session session = null;
363    
364                            try {
365                                    session = openSession();
366    
367                                    userGroup = (UserGroup)session.get(UserGroupImpl.class,
368                                                    new Long(userGroupId));
369                            }
370                            catch (Exception e) {
371                                    throw processException(e);
372                            }
373                            finally {
374                                    if (userGroup != null) {
375                                            cacheResult(userGroup);
376                                    }
377    
378                                    closeSession(session);
379                            }
380                    }
381    
382                    return userGroup;
383            }
384    
385            public List<UserGroup> findByCompanyId(long companyId)
386                    throws SystemException {
387                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
388                            null);
389            }
390    
391            public List<UserGroup> findByCompanyId(long companyId, int start, int end)
392                    throws SystemException {
393                    return findByCompanyId(companyId, start, end, null);
394            }
395    
396            public List<UserGroup> findByCompanyId(long companyId, int start, int end,
397                    OrderByComparator orderByComparator) throws SystemException {
398                    Object[] finderArgs = new Object[] {
399                                    companyId,
400                                    
401                                    String.valueOf(start), String.valueOf(end),
402                                    String.valueOf(orderByComparator)
403                            };
404    
405                    List<UserGroup> list = (List<UserGroup>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
406                                    finderArgs, this);
407    
408                    if (list == null) {
409                            Session session = null;
410    
411                            try {
412                                    session = openSession();
413    
414                                    StringBundler query = null;
415    
416                                    if (orderByComparator != null) {
417                                            query = new StringBundler(3 +
418                                                            (orderByComparator.getOrderByFields().length * 3));
419                                    }
420                                    else {
421                                            query = new StringBundler(3);
422                                    }
423    
424                                    query.append(_SQL_SELECT_USERGROUP_WHERE);
425    
426                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
427    
428                                    if (orderByComparator != null) {
429                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
430                                                    orderByComparator);
431                                    }
432    
433                                    else {
434                                            query.append(UserGroupModelImpl.ORDER_BY_JPQL);
435                                    }
436    
437                                    String sql = query.toString();
438    
439                                    Query q = session.createQuery(sql);
440    
441                                    QueryPos qPos = QueryPos.getInstance(q);
442    
443                                    qPos.add(companyId);
444    
445                                    list = (List<UserGroup>)QueryUtil.list(q, getDialect(), start,
446                                                    end);
447                            }
448                            catch (Exception e) {
449                                    throw processException(e);
450                            }
451                            finally {
452                                    if (list == null) {
453                                            list = new ArrayList<UserGroup>();
454                                    }
455    
456                                    cacheResult(list);
457    
458                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
459                                            finderArgs, list);
460    
461                                    closeSession(session);
462                            }
463                    }
464    
465                    return list;
466            }
467    
468            public UserGroup findByCompanyId_First(long companyId,
469                    OrderByComparator orderByComparator)
470                    throws NoSuchUserGroupException, SystemException {
471                    List<UserGroup> list = findByCompanyId(companyId, 0, 1,
472                                    orderByComparator);
473    
474                    if (list.isEmpty()) {
475                            StringBundler msg = new StringBundler(4);
476    
477                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
478    
479                            msg.append("companyId=");
480                            msg.append(companyId);
481    
482                            msg.append(StringPool.CLOSE_CURLY_BRACE);
483    
484                            throw new NoSuchUserGroupException(msg.toString());
485                    }
486                    else {
487                            return list.get(0);
488                    }
489            }
490    
491            public UserGroup findByCompanyId_Last(long companyId,
492                    OrderByComparator orderByComparator)
493                    throws NoSuchUserGroupException, SystemException {
494                    int count = countByCompanyId(companyId);
495    
496                    List<UserGroup> list = findByCompanyId(companyId, count - 1, count,
497                                    orderByComparator);
498    
499                    if (list.isEmpty()) {
500                            StringBundler msg = new StringBundler(4);
501    
502                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
503    
504                            msg.append("companyId=");
505                            msg.append(companyId);
506    
507                            msg.append(StringPool.CLOSE_CURLY_BRACE);
508    
509                            throw new NoSuchUserGroupException(msg.toString());
510                    }
511                    else {
512                            return list.get(0);
513                    }
514            }
515    
516            public UserGroup[] findByCompanyId_PrevAndNext(long userGroupId,
517                    long companyId, OrderByComparator orderByComparator)
518                    throws NoSuchUserGroupException, SystemException {
519                    UserGroup userGroup = findByPrimaryKey(userGroupId);
520    
521                    Session session = null;
522    
523                    try {
524                            session = openSession();
525    
526                            UserGroup[] array = new UserGroupImpl[3];
527    
528                            array[0] = getByCompanyId_PrevAndNext(session, userGroup,
529                                            companyId, orderByComparator, true);
530    
531                            array[1] = userGroup;
532    
533                            array[2] = getByCompanyId_PrevAndNext(session, userGroup,
534                                            companyId, orderByComparator, false);
535    
536                            return array;
537                    }
538                    catch (Exception e) {
539                            throw processException(e);
540                    }
541                    finally {
542                            closeSession(session);
543                    }
544            }
545    
546            protected UserGroup getByCompanyId_PrevAndNext(Session session,
547                    UserGroup userGroup, long companyId,
548                    OrderByComparator orderByComparator, boolean previous) {
549                    StringBundler query = null;
550    
551                    if (orderByComparator != null) {
552                            query = new StringBundler(6 +
553                                            (orderByComparator.getOrderByFields().length * 6));
554                    }
555                    else {
556                            query = new StringBundler(3);
557                    }
558    
559                    query.append(_SQL_SELECT_USERGROUP_WHERE);
560    
561                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
562    
563                    if (orderByComparator != null) {
564                            String[] orderByFields = orderByComparator.getOrderByFields();
565    
566                            if (orderByFields.length > 0) {
567                                    query.append(WHERE_AND);
568                            }
569    
570                            for (int i = 0; i < orderByFields.length; i++) {
571                                    query.append(_ORDER_BY_ENTITY_ALIAS);
572                                    query.append(orderByFields[i]);
573    
574                                    if ((i + 1) < orderByFields.length) {
575                                            if (orderByComparator.isAscending() ^ previous) {
576                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
577                                            }
578                                            else {
579                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
580                                            }
581                                    }
582                                    else {
583                                            if (orderByComparator.isAscending() ^ previous) {
584                                                    query.append(WHERE_GREATER_THAN);
585                                            }
586                                            else {
587                                                    query.append(WHERE_LESSER_THAN);
588                                            }
589                                    }
590                            }
591    
592                            query.append(ORDER_BY_CLAUSE);
593    
594                            for (int i = 0; i < orderByFields.length; i++) {
595                                    query.append(_ORDER_BY_ENTITY_ALIAS);
596                                    query.append(orderByFields[i]);
597    
598                                    if ((i + 1) < orderByFields.length) {
599                                            if (orderByComparator.isAscending() ^ previous) {
600                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
601                                            }
602                                            else {
603                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
604                                            }
605                                    }
606                                    else {
607                                            if (orderByComparator.isAscending() ^ previous) {
608                                                    query.append(ORDER_BY_ASC);
609                                            }
610                                            else {
611                                                    query.append(ORDER_BY_DESC);
612                                            }
613                                    }
614                            }
615                    }
616    
617                    else {
618                            query.append(UserGroupModelImpl.ORDER_BY_JPQL);
619                    }
620    
621                    String sql = query.toString();
622    
623                    Query q = session.createQuery(sql);
624    
625                    q.setFirstResult(0);
626                    q.setMaxResults(2);
627    
628                    QueryPos qPos = QueryPos.getInstance(q);
629    
630                    qPos.add(companyId);
631    
632                    if (orderByComparator != null) {
633                            Object[] values = orderByComparator.getOrderByValues(userGroup);
634    
635                            for (Object value : values) {
636                                    qPos.add(value);
637                            }
638                    }
639    
640                    List<UserGroup> list = q.list();
641    
642                    if (list.size() == 2) {
643                            return list.get(1);
644                    }
645                    else {
646                            return null;
647                    }
648            }
649    
650            public List<UserGroup> findByC_P(long companyId, long parentUserGroupId)
651                    throws SystemException {
652                    return findByC_P(companyId, parentUserGroupId, QueryUtil.ALL_POS,
653                            QueryUtil.ALL_POS, null);
654            }
655    
656            public List<UserGroup> findByC_P(long companyId, long parentUserGroupId,
657                    int start, int end) throws SystemException {
658                    return findByC_P(companyId, parentUserGroupId, start, end, null);
659            }
660    
661            public List<UserGroup> findByC_P(long companyId, long parentUserGroupId,
662                    int start, int end, OrderByComparator orderByComparator)
663                    throws SystemException {
664                    Object[] finderArgs = new Object[] {
665                                    companyId, parentUserGroupId,
666                                    
667                                    String.valueOf(start), String.valueOf(end),
668                                    String.valueOf(orderByComparator)
669                            };
670    
671                    List<UserGroup> list = (List<UserGroup>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_P,
672                                    finderArgs, this);
673    
674                    if (list == null) {
675                            Session session = null;
676    
677                            try {
678                                    session = openSession();
679    
680                                    StringBundler query = null;
681    
682                                    if (orderByComparator != null) {
683                                            query = new StringBundler(4 +
684                                                            (orderByComparator.getOrderByFields().length * 3));
685                                    }
686                                    else {
687                                            query = new StringBundler(4);
688                                    }
689    
690                                    query.append(_SQL_SELECT_USERGROUP_WHERE);
691    
692                                    query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
693    
694                                    query.append(_FINDER_COLUMN_C_P_PARENTUSERGROUPID_2);
695    
696                                    if (orderByComparator != null) {
697                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
698                                                    orderByComparator);
699                                    }
700    
701                                    else {
702                                            query.append(UserGroupModelImpl.ORDER_BY_JPQL);
703                                    }
704    
705                                    String sql = query.toString();
706    
707                                    Query q = session.createQuery(sql);
708    
709                                    QueryPos qPos = QueryPos.getInstance(q);
710    
711                                    qPos.add(companyId);
712    
713                                    qPos.add(parentUserGroupId);
714    
715                                    list = (List<UserGroup>)QueryUtil.list(q, getDialect(), start,
716                                                    end);
717                            }
718                            catch (Exception e) {
719                                    throw processException(e);
720                            }
721                            finally {
722                                    if (list == null) {
723                                            list = new ArrayList<UserGroup>();
724                                    }
725    
726                                    cacheResult(list);
727    
728                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_P, finderArgs,
729                                            list);
730    
731                                    closeSession(session);
732                            }
733                    }
734    
735                    return list;
736            }
737    
738            public UserGroup findByC_P_First(long companyId, long parentUserGroupId,
739                    OrderByComparator orderByComparator)
740                    throws NoSuchUserGroupException, SystemException {
741                    List<UserGroup> list = findByC_P(companyId, parentUserGroupId, 0, 1,
742                                    orderByComparator);
743    
744                    if (list.isEmpty()) {
745                            StringBundler msg = new StringBundler(6);
746    
747                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
748    
749                            msg.append("companyId=");
750                            msg.append(companyId);
751    
752                            msg.append(", parentUserGroupId=");
753                            msg.append(parentUserGroupId);
754    
755                            msg.append(StringPool.CLOSE_CURLY_BRACE);
756    
757                            throw new NoSuchUserGroupException(msg.toString());
758                    }
759                    else {
760                            return list.get(0);
761                    }
762            }
763    
764            public UserGroup findByC_P_Last(long companyId, long parentUserGroupId,
765                    OrderByComparator orderByComparator)
766                    throws NoSuchUserGroupException, SystemException {
767                    int count = countByC_P(companyId, parentUserGroupId);
768    
769                    List<UserGroup> list = findByC_P(companyId, parentUserGroupId,
770                                    count - 1, count, orderByComparator);
771    
772                    if (list.isEmpty()) {
773                            StringBundler msg = new StringBundler(6);
774    
775                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
776    
777                            msg.append("companyId=");
778                            msg.append(companyId);
779    
780                            msg.append(", parentUserGroupId=");
781                            msg.append(parentUserGroupId);
782    
783                            msg.append(StringPool.CLOSE_CURLY_BRACE);
784    
785                            throw new NoSuchUserGroupException(msg.toString());
786                    }
787                    else {
788                            return list.get(0);
789                    }
790            }
791    
792            public UserGroup[] findByC_P_PrevAndNext(long userGroupId, long companyId,
793                    long parentUserGroupId, OrderByComparator orderByComparator)
794                    throws NoSuchUserGroupException, SystemException {
795                    UserGroup userGroup = findByPrimaryKey(userGroupId);
796    
797                    Session session = null;
798    
799                    try {
800                            session = openSession();
801    
802                            UserGroup[] array = new UserGroupImpl[3];
803    
804                            array[0] = getByC_P_PrevAndNext(session, userGroup, companyId,
805                                            parentUserGroupId, orderByComparator, true);
806    
807                            array[1] = userGroup;
808    
809                            array[2] = getByC_P_PrevAndNext(session, userGroup, companyId,
810                                            parentUserGroupId, orderByComparator, false);
811    
812                            return array;
813                    }
814                    catch (Exception e) {
815                            throw processException(e);
816                    }
817                    finally {
818                            closeSession(session);
819                    }
820            }
821    
822            protected UserGroup getByC_P_PrevAndNext(Session session,
823                    UserGroup userGroup, long companyId, long parentUserGroupId,
824                    OrderByComparator orderByComparator, boolean previous) {
825                    StringBundler query = null;
826    
827                    if (orderByComparator != null) {
828                            query = new StringBundler(6 +
829                                            (orderByComparator.getOrderByFields().length * 6));
830                    }
831                    else {
832                            query = new StringBundler(3);
833                    }
834    
835                    query.append(_SQL_SELECT_USERGROUP_WHERE);
836    
837                    query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
838    
839                    query.append(_FINDER_COLUMN_C_P_PARENTUSERGROUPID_2);
840    
841                    if (orderByComparator != null) {
842                            String[] orderByFields = orderByComparator.getOrderByFields();
843    
844                            if (orderByFields.length > 0) {
845                                    query.append(WHERE_AND);
846                            }
847    
848                            for (int i = 0; i < orderByFields.length; i++) {
849                                    query.append(_ORDER_BY_ENTITY_ALIAS);
850                                    query.append(orderByFields[i]);
851    
852                                    if ((i + 1) < orderByFields.length) {
853                                            if (orderByComparator.isAscending() ^ previous) {
854                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
855                                            }
856                                            else {
857                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
858                                            }
859                                    }
860                                    else {
861                                            if (orderByComparator.isAscending() ^ previous) {
862                                                    query.append(WHERE_GREATER_THAN);
863                                            }
864                                            else {
865                                                    query.append(WHERE_LESSER_THAN);
866                                            }
867                                    }
868                            }
869    
870                            query.append(ORDER_BY_CLAUSE);
871    
872                            for (int i = 0; i < orderByFields.length; i++) {
873                                    query.append(_ORDER_BY_ENTITY_ALIAS);
874                                    query.append(orderByFields[i]);
875    
876                                    if ((i + 1) < orderByFields.length) {
877                                            if (orderByComparator.isAscending() ^ previous) {
878                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
879                                            }
880                                            else {
881                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
882                                            }
883                                    }
884                                    else {
885                                            if (orderByComparator.isAscending() ^ previous) {
886                                                    query.append(ORDER_BY_ASC);
887                                            }
888                                            else {
889                                                    query.append(ORDER_BY_DESC);
890                                            }
891                                    }
892                            }
893                    }
894    
895                    else {
896                            query.append(UserGroupModelImpl.ORDER_BY_JPQL);
897                    }
898    
899                    String sql = query.toString();
900    
901                    Query q = session.createQuery(sql);
902    
903                    q.setFirstResult(0);
904                    q.setMaxResults(2);
905    
906                    QueryPos qPos = QueryPos.getInstance(q);
907    
908                    qPos.add(companyId);
909    
910                    qPos.add(parentUserGroupId);
911    
912                    if (orderByComparator != null) {
913                            Object[] values = orderByComparator.getOrderByValues(userGroup);
914    
915                            for (Object value : values) {
916                                    qPos.add(value);
917                            }
918                    }
919    
920                    List<UserGroup> list = q.list();
921    
922                    if (list.size() == 2) {
923                            return list.get(1);
924                    }
925                    else {
926                            return null;
927                    }
928            }
929    
930            public UserGroup findByC_N(long companyId, String name)
931                    throws NoSuchUserGroupException, SystemException {
932                    UserGroup userGroup = fetchByC_N(companyId, name);
933    
934                    if (userGroup == null) {
935                            StringBundler msg = new StringBundler(6);
936    
937                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
938    
939                            msg.append("companyId=");
940                            msg.append(companyId);
941    
942                            msg.append(", name=");
943                            msg.append(name);
944    
945                            msg.append(StringPool.CLOSE_CURLY_BRACE);
946    
947                            if (_log.isWarnEnabled()) {
948                                    _log.warn(msg.toString());
949                            }
950    
951                            throw new NoSuchUserGroupException(msg.toString());
952                    }
953    
954                    return userGroup;
955            }
956    
957            public UserGroup fetchByC_N(long companyId, String name)
958                    throws SystemException {
959                    return fetchByC_N(companyId, name, true);
960            }
961    
962            public UserGroup fetchByC_N(long companyId, String name,
963                    boolean retrieveFromCache) throws SystemException {
964                    Object[] finderArgs = new Object[] { companyId, name };
965    
966                    Object result = null;
967    
968                    if (retrieveFromCache) {
969                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
970                                            finderArgs, this);
971                    }
972    
973                    if (result == null) {
974                            Session session = null;
975    
976                            try {
977                                    session = openSession();
978    
979                                    StringBundler query = new StringBundler(4);
980    
981                                    query.append(_SQL_SELECT_USERGROUP_WHERE);
982    
983                                    query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
984    
985                                    if (name == null) {
986                                            query.append(_FINDER_COLUMN_C_N_NAME_1);
987                                    }
988                                    else {
989                                            if (name.equals(StringPool.BLANK)) {
990                                                    query.append(_FINDER_COLUMN_C_N_NAME_3);
991                                            }
992                                            else {
993                                                    query.append(_FINDER_COLUMN_C_N_NAME_2);
994                                            }
995                                    }
996    
997                                    query.append(UserGroupModelImpl.ORDER_BY_JPQL);
998    
999                                    String sql = query.toString();
1000    
1001                                    Query q = session.createQuery(sql);
1002    
1003                                    QueryPos qPos = QueryPos.getInstance(q);
1004    
1005                                    qPos.add(companyId);
1006    
1007                                    if (name != null) {
1008                                            qPos.add(name);
1009                                    }
1010    
1011                                    List<UserGroup> list = q.list();
1012    
1013                                    result = list;
1014    
1015                                    UserGroup userGroup = null;
1016    
1017                                    if (list.isEmpty()) {
1018                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
1019                                                    finderArgs, list);
1020                                    }
1021                                    else {
1022                                            userGroup = list.get(0);
1023    
1024                                            cacheResult(userGroup);
1025    
1026                                            if ((userGroup.getCompanyId() != companyId) ||
1027                                                            (userGroup.getName() == null) ||
1028                                                            !userGroup.getName().equals(name)) {
1029                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
1030                                                            finderArgs, userGroup);
1031                                            }
1032                                    }
1033    
1034                                    return userGroup;
1035                            }
1036                            catch (Exception e) {
1037                                    throw processException(e);
1038                            }
1039                            finally {
1040                                    if (result == null) {
1041                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
1042                                                    finderArgs, new ArrayList<UserGroup>());
1043                                    }
1044    
1045                                    closeSession(session);
1046                            }
1047                    }
1048                    else {
1049                            if (result instanceof List<?>) {
1050                                    return null;
1051                            }
1052                            else {
1053                                    return (UserGroup)result;
1054                            }
1055                    }
1056            }
1057    
1058            public List<UserGroup> findAll() throws SystemException {
1059                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1060            }
1061    
1062            public List<UserGroup> findAll(int start, int end)
1063                    throws SystemException {
1064                    return findAll(start, end, null);
1065            }
1066    
1067            public List<UserGroup> findAll(int start, int end,
1068                    OrderByComparator orderByComparator) throws SystemException {
1069                    Object[] finderArgs = new Object[] {
1070                                    String.valueOf(start), String.valueOf(end),
1071                                    String.valueOf(orderByComparator)
1072                            };
1073    
1074                    List<UserGroup> list = (List<UserGroup>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1075                                    finderArgs, this);
1076    
1077                    if (list == null) {
1078                            Session session = null;
1079    
1080                            try {
1081                                    session = openSession();
1082    
1083                                    StringBundler query = null;
1084                                    String sql = null;
1085    
1086                                    if (orderByComparator != null) {
1087                                            query = new StringBundler(2 +
1088                                                            (orderByComparator.getOrderByFields().length * 3));
1089    
1090                                            query.append(_SQL_SELECT_USERGROUP);
1091    
1092                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1093                                                    orderByComparator);
1094    
1095                                            sql = query.toString();
1096                                    }
1097                                    else {
1098                                            sql = _SQL_SELECT_USERGROUP.concat(UserGroupModelImpl.ORDER_BY_JPQL);
1099                                    }
1100    
1101                                    Query q = session.createQuery(sql);
1102    
1103                                    if (orderByComparator == null) {
1104                                            list = (List<UserGroup>)QueryUtil.list(q, getDialect(),
1105                                                            start, end, false);
1106    
1107                                            Collections.sort(list);
1108                                    }
1109                                    else {
1110                                            list = (List<UserGroup>)QueryUtil.list(q, getDialect(),
1111                                                            start, end);
1112                                    }
1113                            }
1114                            catch (Exception e) {
1115                                    throw processException(e);
1116                            }
1117                            finally {
1118                                    if (list == null) {
1119                                            list = new ArrayList<UserGroup>();
1120                                    }
1121    
1122                                    cacheResult(list);
1123    
1124                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1125    
1126                                    closeSession(session);
1127                            }
1128                    }
1129    
1130                    return list;
1131            }
1132    
1133            public void removeByCompanyId(long companyId) throws SystemException {
1134                    for (UserGroup userGroup : findByCompanyId(companyId)) {
1135                            remove(userGroup);
1136                    }
1137            }
1138    
1139            public void removeByC_P(long companyId, long parentUserGroupId)
1140                    throws SystemException {
1141                    for (UserGroup userGroup : findByC_P(companyId, parentUserGroupId)) {
1142                            remove(userGroup);
1143                    }
1144            }
1145    
1146            public void removeByC_N(long companyId, String name)
1147                    throws NoSuchUserGroupException, SystemException {
1148                    UserGroup userGroup = findByC_N(companyId, name);
1149    
1150                    remove(userGroup);
1151            }
1152    
1153            public void removeAll() throws SystemException {
1154                    for (UserGroup userGroup : findAll()) {
1155                            remove(userGroup);
1156                    }
1157            }
1158    
1159            public int countByCompanyId(long companyId) throws SystemException {
1160                    Object[] finderArgs = new Object[] { companyId };
1161    
1162                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1163                                    finderArgs, this);
1164    
1165                    if (count == null) {
1166                            Session session = null;
1167    
1168                            try {
1169                                    session = openSession();
1170    
1171                                    StringBundler query = new StringBundler(2);
1172    
1173                                    query.append(_SQL_COUNT_USERGROUP_WHERE);
1174    
1175                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1176    
1177                                    String sql = query.toString();
1178    
1179                                    Query q = session.createQuery(sql);
1180    
1181                                    QueryPos qPos = QueryPos.getInstance(q);
1182    
1183                                    qPos.add(companyId);
1184    
1185                                    count = (Long)q.uniqueResult();
1186                            }
1187                            catch (Exception e) {
1188                                    throw processException(e);
1189                            }
1190                            finally {
1191                                    if (count == null) {
1192                                            count = Long.valueOf(0);
1193                                    }
1194    
1195                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1196                                            finderArgs, count);
1197    
1198                                    closeSession(session);
1199                            }
1200                    }
1201    
1202                    return count.intValue();
1203            }
1204    
1205            public int countByC_P(long companyId, long parentUserGroupId)
1206                    throws SystemException {
1207                    Object[] finderArgs = new Object[] { companyId, parentUserGroupId };
1208    
1209                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_P,
1210                                    finderArgs, this);
1211    
1212                    if (count == null) {
1213                            Session session = null;
1214    
1215                            try {
1216                                    session = openSession();
1217    
1218                                    StringBundler query = new StringBundler(3);
1219    
1220                                    query.append(_SQL_COUNT_USERGROUP_WHERE);
1221    
1222                                    query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
1223    
1224                                    query.append(_FINDER_COLUMN_C_P_PARENTUSERGROUPID_2);
1225    
1226                                    String sql = query.toString();
1227    
1228                                    Query q = session.createQuery(sql);
1229    
1230                                    QueryPos qPos = QueryPos.getInstance(q);
1231    
1232                                    qPos.add(companyId);
1233    
1234                                    qPos.add(parentUserGroupId);
1235    
1236                                    count = (Long)q.uniqueResult();
1237                            }
1238                            catch (Exception e) {
1239                                    throw processException(e);
1240                            }
1241                            finally {
1242                                    if (count == null) {
1243                                            count = Long.valueOf(0);
1244                                    }
1245    
1246                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_P, finderArgs,
1247                                            count);
1248    
1249                                    closeSession(session);
1250                            }
1251                    }
1252    
1253                    return count.intValue();
1254            }
1255    
1256            public int countByC_N(long companyId, String name)
1257                    throws SystemException {
1258                    Object[] finderArgs = new Object[] { companyId, name };
1259    
1260                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N,
1261                                    finderArgs, this);
1262    
1263                    if (count == null) {
1264                            Session session = null;
1265    
1266                            try {
1267                                    session = openSession();
1268    
1269                                    StringBundler query = new StringBundler(3);
1270    
1271                                    query.append(_SQL_COUNT_USERGROUP_WHERE);
1272    
1273                                    query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
1274    
1275                                    if (name == null) {
1276                                            query.append(_FINDER_COLUMN_C_N_NAME_1);
1277                                    }
1278                                    else {
1279                                            if (name.equals(StringPool.BLANK)) {
1280                                                    query.append(_FINDER_COLUMN_C_N_NAME_3);
1281                                            }
1282                                            else {
1283                                                    query.append(_FINDER_COLUMN_C_N_NAME_2);
1284                                            }
1285                                    }
1286    
1287                                    String sql = query.toString();
1288    
1289                                    Query q = session.createQuery(sql);
1290    
1291                                    QueryPos qPos = QueryPos.getInstance(q);
1292    
1293                                    qPos.add(companyId);
1294    
1295                                    if (name != null) {
1296                                            qPos.add(name);
1297                                    }
1298    
1299                                    count = (Long)q.uniqueResult();
1300                            }
1301                            catch (Exception e) {
1302                                    throw processException(e);
1303                            }
1304                            finally {
1305                                    if (count == null) {
1306                                            count = Long.valueOf(0);
1307                                    }
1308    
1309                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, finderArgs,
1310                                            count);
1311    
1312                                    closeSession(session);
1313                            }
1314                    }
1315    
1316                    return count.intValue();
1317            }
1318    
1319            public int countAll() throws SystemException {
1320                    Object[] finderArgs = new Object[0];
1321    
1322                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1323                                    finderArgs, this);
1324    
1325                    if (count == null) {
1326                            Session session = null;
1327    
1328                            try {
1329                                    session = openSession();
1330    
1331                                    Query q = session.createQuery(_SQL_COUNT_USERGROUP);
1332    
1333                                    count = (Long)q.uniqueResult();
1334                            }
1335                            catch (Exception e) {
1336                                    throw processException(e);
1337                            }
1338                            finally {
1339                                    if (count == null) {
1340                                            count = Long.valueOf(0);
1341                                    }
1342    
1343                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1344                                            count);
1345    
1346                                    closeSession(session);
1347                            }
1348                    }
1349    
1350                    return count.intValue();
1351            }
1352    
1353            public List<com.liferay.portal.model.Group> getGroups(long pk)
1354                    throws SystemException {
1355                    return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1356            }
1357    
1358            public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
1359                    int end) throws SystemException {
1360                    return getGroups(pk, start, end, null);
1361            }
1362    
1363            public static final FinderPath FINDER_PATH_GET_GROUPS = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1364                            UserGroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_USERGROUPS,
1365                            UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME,
1366                            "getGroups",
1367                            new String[] {
1368                                    Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1369                                    "com.liferay.portal.kernel.util.OrderByComparator"
1370                            });
1371    
1372            public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
1373                    int end, OrderByComparator orderByComparator) throws SystemException {
1374                    Object[] finderArgs = new Object[] {
1375                                    pk, String.valueOf(start), String.valueOf(end),
1376                                    String.valueOf(orderByComparator)
1377                            };
1378    
1379                    List<com.liferay.portal.model.Group> list = (List<com.liferay.portal.model.Group>)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS,
1380                                    finderArgs, this);
1381    
1382                    if (list == null) {
1383                            Session session = null;
1384    
1385                            try {
1386                                    session = openSession();
1387    
1388                                    String sql = null;
1389    
1390                                    if (orderByComparator != null) {
1391                                            sql = _SQL_GETGROUPS.concat(ORDER_BY_CLAUSE)
1392                                                                                    .concat(orderByComparator.getOrderBy());
1393                                    }
1394                                    else {
1395                                            sql = _SQL_GETGROUPS.concat(com.liferay.portal.model.impl.GroupModelImpl.ORDER_BY_SQL);
1396                                    }
1397    
1398                                    SQLQuery q = session.createSQLQuery(sql);
1399    
1400                                    q.addEntity("Group_",
1401                                            com.liferay.portal.model.impl.GroupImpl.class);
1402    
1403                                    QueryPos qPos = QueryPos.getInstance(q);
1404    
1405                                    qPos.add(pk);
1406    
1407                                    list = (List<com.liferay.portal.model.Group>)QueryUtil.list(q,
1408                                                    getDialect(), start, end);
1409                            }
1410                            catch (Exception e) {
1411                                    throw processException(e);
1412                            }
1413                            finally {
1414                                    if (list == null) {
1415                                            list = new ArrayList<com.liferay.portal.model.Group>();
1416                                    }
1417    
1418                                    groupPersistence.cacheResult(list);
1419    
1420                                    FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS, finderArgs,
1421                                            list);
1422    
1423                                    closeSession(session);
1424                            }
1425                    }
1426    
1427                    return list;
1428            }
1429    
1430            public static final FinderPath FINDER_PATH_GET_GROUPS_SIZE = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1431                            UserGroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_USERGROUPS,
1432                            UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME,
1433                            "getGroupsSize", new String[] { Long.class.getName() });
1434    
1435            public int getGroupsSize(long pk) throws SystemException {
1436                    Object[] finderArgs = new Object[] { pk };
1437    
1438                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS_SIZE,
1439                                    finderArgs, this);
1440    
1441                    if (count == null) {
1442                            Session session = null;
1443    
1444                            try {
1445                                    session = openSession();
1446    
1447                                    SQLQuery q = session.createSQLQuery(_SQL_GETGROUPSSIZE);
1448    
1449                                    q.addScalar(COUNT_COLUMN_NAME,
1450                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
1451    
1452                                    QueryPos qPos = QueryPos.getInstance(q);
1453    
1454                                    qPos.add(pk);
1455    
1456                                    count = (Long)q.uniqueResult();
1457                            }
1458                            catch (Exception e) {
1459                                    throw processException(e);
1460                            }
1461                            finally {
1462                                    if (count == null) {
1463                                            count = Long.valueOf(0);
1464                                    }
1465    
1466                                    FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS_SIZE,
1467                                            finderArgs, count);
1468    
1469                                    closeSession(session);
1470                            }
1471                    }
1472    
1473                    return count.intValue();
1474            }
1475    
1476            public static final FinderPath FINDER_PATH_CONTAINS_GROUP = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1477                            UserGroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_USERGROUPS,
1478                            UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME,
1479                            "containsGroup",
1480                            new String[] { Long.class.getName(), Long.class.getName() });
1481    
1482            public boolean containsGroup(long pk, long groupPK)
1483                    throws SystemException {
1484                    Object[] finderArgs = new Object[] { pk, groupPK };
1485    
1486                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_GROUP,
1487                                    finderArgs, this);
1488    
1489                    if (value == null) {
1490                            try {
1491                                    value = Boolean.valueOf(containsGroup.contains(pk, groupPK));
1492                            }
1493                            catch (Exception e) {
1494                                    throw processException(e);
1495                            }
1496                            finally {
1497                                    if (value == null) {
1498                                            value = Boolean.FALSE;
1499                                    }
1500    
1501                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_GROUP,
1502                                            finderArgs, value);
1503                            }
1504                    }
1505    
1506                    return value.booleanValue();
1507            }
1508    
1509            public boolean containsGroups(long pk) throws SystemException {
1510                    if (getGroupsSize(pk) > 0) {
1511                            return true;
1512                    }
1513                    else {
1514                            return false;
1515                    }
1516            }
1517    
1518            public void addGroup(long pk, long groupPK) throws SystemException {
1519                    try {
1520                            addGroup.add(pk, groupPK);
1521                    }
1522                    catch (Exception e) {
1523                            throw processException(e);
1524                    }
1525                    finally {
1526                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
1527                    }
1528            }
1529    
1530            public void addGroup(long pk, com.liferay.portal.model.Group group)
1531                    throws SystemException {
1532                    try {
1533                            addGroup.add(pk, group.getPrimaryKey());
1534                    }
1535                    catch (Exception e) {
1536                            throw processException(e);
1537                    }
1538                    finally {
1539                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
1540                    }
1541            }
1542    
1543            public void addGroups(long pk, long[] groupPKs) throws SystemException {
1544                    try {
1545                            for (long groupPK : groupPKs) {
1546                                    addGroup.add(pk, groupPK);
1547                            }
1548                    }
1549                    catch (Exception e) {
1550                            throw processException(e);
1551                    }
1552                    finally {
1553                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
1554                    }
1555            }
1556    
1557            public void addGroups(long pk, List<com.liferay.portal.model.Group> groups)
1558                    throws SystemException {
1559                    try {
1560                            for (com.liferay.portal.model.Group group : groups) {
1561                                    addGroup.add(pk, group.getPrimaryKey());
1562                            }
1563                    }
1564                    catch (Exception e) {
1565                            throw processException(e);
1566                    }
1567                    finally {
1568                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
1569                    }
1570            }
1571    
1572            public void clearGroups(long pk) throws SystemException {
1573                    try {
1574                            clearGroups.clear(pk);
1575                    }
1576                    catch (Exception e) {
1577                            throw processException(e);
1578                    }
1579                    finally {
1580                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
1581                    }
1582            }
1583    
1584            public void removeGroup(long pk, long groupPK) throws SystemException {
1585                    try {
1586                            removeGroup.remove(pk, groupPK);
1587                    }
1588                    catch (Exception e) {
1589                            throw processException(e);
1590                    }
1591                    finally {
1592                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
1593                    }
1594            }
1595    
1596            public void removeGroup(long pk, com.liferay.portal.model.Group group)
1597                    throws SystemException {
1598                    try {
1599                            removeGroup.remove(pk, group.getPrimaryKey());
1600                    }
1601                    catch (Exception e) {
1602                            throw processException(e);
1603                    }
1604                    finally {
1605                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
1606                    }
1607            }
1608    
1609            public void removeGroups(long pk, long[] groupPKs)
1610                    throws SystemException {
1611                    try {
1612                            for (long groupPK : groupPKs) {
1613                                    removeGroup.remove(pk, groupPK);
1614                            }
1615                    }
1616                    catch (Exception e) {
1617                            throw processException(e);
1618                    }
1619                    finally {
1620                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
1621                    }
1622            }
1623    
1624            public void removeGroups(long pk,
1625                    List<com.liferay.portal.model.Group> groups) throws SystemException {
1626                    try {
1627                            for (com.liferay.portal.model.Group group : groups) {
1628                                    removeGroup.remove(pk, group.getPrimaryKey());
1629                            }
1630                    }
1631                    catch (Exception e) {
1632                            throw processException(e);
1633                    }
1634                    finally {
1635                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
1636                    }
1637            }
1638    
1639            public void setGroups(long pk, long[] groupPKs) throws SystemException {
1640                    try {
1641                            Set<Long> groupPKSet = SetUtil.fromArray(groupPKs);
1642    
1643                            List<com.liferay.portal.model.Group> groups = getGroups(pk);
1644    
1645                            for (com.liferay.portal.model.Group group : groups) {
1646                                    if (!groupPKSet.contains(group.getPrimaryKey())) {
1647                                            removeGroup.remove(pk, group.getPrimaryKey());
1648                                    }
1649                                    else {
1650                                            groupPKSet.remove(group.getPrimaryKey());
1651                                    }
1652                            }
1653    
1654                            for (Long groupPK : groupPKSet) {
1655                                    addGroup.add(pk, groupPK);
1656                            }
1657                    }
1658                    catch (Exception e) {
1659                            throw processException(e);
1660                    }
1661                    finally {
1662                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
1663                    }
1664            }
1665    
1666            public void setGroups(long pk, List<com.liferay.portal.model.Group> groups)
1667                    throws SystemException {
1668                    try {
1669                            long[] groupPKs = new long[groups.size()];
1670    
1671                            for (int i = 0; i < groups.size(); i++) {
1672                                    com.liferay.portal.model.Group group = groups.get(i);
1673    
1674                                    groupPKs[i] = group.getPrimaryKey();
1675                            }
1676    
1677                            setGroups(pk, groupPKs);
1678                    }
1679                    catch (Exception e) {
1680                            throw processException(e);
1681                    }
1682                    finally {
1683                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
1684                    }
1685            }
1686    
1687            public List<com.liferay.portal.model.User> getUsers(long pk)
1688                    throws SystemException {
1689                    return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1690            }
1691    
1692            public List<com.liferay.portal.model.User> getUsers(long pk, int start,
1693                    int end) throws SystemException {
1694                    return getUsers(pk, start, end, null);
1695            }
1696    
1697            public static final FinderPath FINDER_PATH_GET_USERS = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1698                            UserGroupModelImpl.FINDER_CACHE_ENABLED_USERS_USERGROUPS,
1699                            UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME, "getUsers",
1700                            new String[] {
1701                                    Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1702                                    "com.liferay.portal.kernel.util.OrderByComparator"
1703                            });
1704    
1705            public List<com.liferay.portal.model.User> getUsers(long pk, int start,
1706                    int end, OrderByComparator orderByComparator) throws SystemException {
1707                    Object[] finderArgs = new Object[] {
1708                                    pk, String.valueOf(start), String.valueOf(end),
1709                                    String.valueOf(orderByComparator)
1710                            };
1711    
1712                    List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS,
1713                                    finderArgs, this);
1714    
1715                    if (list == null) {
1716                            Session session = null;
1717    
1718                            try {
1719                                    session = openSession();
1720    
1721                                    String sql = null;
1722    
1723                                    if (orderByComparator != null) {
1724                                            sql = _SQL_GETUSERS.concat(ORDER_BY_CLAUSE)
1725                                                                               .concat(orderByComparator.getOrderBy());
1726                                    }
1727                                    else {
1728                                            sql = _SQL_GETUSERS;
1729                                    }
1730    
1731                                    SQLQuery q = session.createSQLQuery(sql);
1732    
1733                                    q.addEntity("User_",
1734                                            com.liferay.portal.model.impl.UserImpl.class);
1735    
1736                                    QueryPos qPos = QueryPos.getInstance(q);
1737    
1738                                    qPos.add(pk);
1739    
1740                                    list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
1741                                                    getDialect(), start, end);
1742                            }
1743                            catch (Exception e) {
1744                                    throw processException(e);
1745                            }
1746                            finally {
1747                                    if (list == null) {
1748                                            list = new ArrayList<com.liferay.portal.model.User>();
1749                                    }
1750    
1751                                    userPersistence.cacheResult(list);
1752    
1753                                    FinderCacheUtil.putResult(FINDER_PATH_GET_USERS, finderArgs,
1754                                            list);
1755    
1756                                    closeSession(session);
1757                            }
1758                    }
1759    
1760                    return list;
1761            }
1762    
1763            public static final FinderPath FINDER_PATH_GET_USERS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1764                            UserGroupModelImpl.FINDER_CACHE_ENABLED_USERS_USERGROUPS,
1765                            UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME,
1766                            "getUsersSize", new String[] { Long.class.getName() });
1767    
1768            public int getUsersSize(long pk) throws SystemException {
1769                    Object[] finderArgs = new Object[] { pk };
1770    
1771                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS_SIZE,
1772                                    finderArgs, this);
1773    
1774                    if (count == null) {
1775                            Session session = null;
1776    
1777                            try {
1778                                    session = openSession();
1779    
1780                                    SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
1781    
1782                                    q.addScalar(COUNT_COLUMN_NAME,
1783                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
1784    
1785                                    QueryPos qPos = QueryPos.getInstance(q);
1786    
1787                                    qPos.add(pk);
1788    
1789                                    count = (Long)q.uniqueResult();
1790                            }
1791                            catch (Exception e) {
1792                                    throw processException(e);
1793                            }
1794                            finally {
1795                                    if (count == null) {
1796                                            count = Long.valueOf(0);
1797                                    }
1798    
1799                                    FinderCacheUtil.putResult(FINDER_PATH_GET_USERS_SIZE,
1800                                            finderArgs, count);
1801    
1802                                    closeSession(session);
1803                            }
1804                    }
1805    
1806                    return count.intValue();
1807            }
1808    
1809            public static final FinderPath FINDER_PATH_CONTAINS_USER = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1810                            UserGroupModelImpl.FINDER_CACHE_ENABLED_USERS_USERGROUPS,
1811                            UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME,
1812                            "containsUser",
1813                            new String[] { Long.class.getName(), Long.class.getName() });
1814    
1815            public boolean containsUser(long pk, long userPK) throws SystemException {
1816                    Object[] finderArgs = new Object[] { pk, userPK };
1817    
1818                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USER,
1819                                    finderArgs, this);
1820    
1821                    if (value == null) {
1822                            try {
1823                                    value = Boolean.valueOf(containsUser.contains(pk, userPK));
1824                            }
1825                            catch (Exception e) {
1826                                    throw processException(e);
1827                            }
1828                            finally {
1829                                    if (value == null) {
1830                                            value = Boolean.FALSE;
1831                                    }
1832    
1833                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USER,
1834                                            finderArgs, value);
1835                            }
1836                    }
1837    
1838                    return value.booleanValue();
1839            }
1840    
1841            public boolean containsUsers(long pk) throws SystemException {
1842                    if (getUsersSize(pk) > 0) {
1843                            return true;
1844                    }
1845                    else {
1846                            return false;
1847                    }
1848            }
1849    
1850            public void addUser(long pk, long userPK) throws SystemException {
1851                    try {
1852                            addUser.add(pk, userPK);
1853                    }
1854                    catch (Exception e) {
1855                            throw processException(e);
1856                    }
1857                    finally {
1858                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1859                    }
1860            }
1861    
1862            public void addUser(long pk, com.liferay.portal.model.User user)
1863                    throws SystemException {
1864                    try {
1865                            addUser.add(pk, user.getPrimaryKey());
1866                    }
1867                    catch (Exception e) {
1868                            throw processException(e);
1869                    }
1870                    finally {
1871                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1872                    }
1873            }
1874    
1875            public void addUsers(long pk, long[] userPKs) throws SystemException {
1876                    try {
1877                            for (long userPK : userPKs) {
1878                                    addUser.add(pk, userPK);
1879                            }
1880                    }
1881                    catch (Exception e) {
1882                            throw processException(e);
1883                    }
1884                    finally {
1885                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1886                    }
1887            }
1888    
1889            public void addUsers(long pk, List<com.liferay.portal.model.User> users)
1890                    throws SystemException {
1891                    try {
1892                            for (com.liferay.portal.model.User user : users) {
1893                                    addUser.add(pk, user.getPrimaryKey());
1894                            }
1895                    }
1896                    catch (Exception e) {
1897                            throw processException(e);
1898                    }
1899                    finally {
1900                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1901                    }
1902            }
1903    
1904            public void clearUsers(long pk) throws SystemException {
1905                    try {
1906                            clearUsers.clear(pk);
1907                    }
1908                    catch (Exception e) {
1909                            throw processException(e);
1910                    }
1911                    finally {
1912                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1913                    }
1914            }
1915    
1916            public void removeUser(long pk, long userPK) throws SystemException {
1917                    try {
1918                            removeUser.remove(pk, userPK);
1919                    }
1920                    catch (Exception e) {
1921                            throw processException(e);
1922                    }
1923                    finally {
1924                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1925                    }
1926            }
1927    
1928            public void removeUser(long pk, com.liferay.portal.model.User user)
1929                    throws SystemException {
1930                    try {
1931                            removeUser.remove(pk, user.getPrimaryKey());
1932                    }
1933                    catch (Exception e) {
1934                            throw processException(e);
1935                    }
1936                    finally {
1937                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1938                    }
1939            }
1940    
1941            public void removeUsers(long pk, long[] userPKs) throws SystemException {
1942                    try {
1943                            for (long userPK : userPKs) {
1944                                    removeUser.remove(pk, userPK);
1945                            }
1946                    }
1947                    catch (Exception e) {
1948                            throw processException(e);
1949                    }
1950                    finally {
1951                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1952                    }
1953            }
1954    
1955            public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
1956                    throws SystemException {
1957                    try {
1958                            for (com.liferay.portal.model.User user : users) {
1959                                    removeUser.remove(pk, user.getPrimaryKey());
1960                            }
1961                    }
1962                    catch (Exception e) {
1963                            throw processException(e);
1964                    }
1965                    finally {
1966                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1967                    }
1968            }
1969    
1970            public void setUsers(long pk, long[] userPKs) throws SystemException {
1971                    try {
1972                            Set<Long> userPKSet = SetUtil.fromArray(userPKs);
1973    
1974                            List<com.liferay.portal.model.User> users = getUsers(pk);
1975    
1976                            for (com.liferay.portal.model.User user : users) {
1977                                    if (!userPKSet.contains(user.getPrimaryKey())) {
1978                                            removeUser.remove(pk, user.getPrimaryKey());
1979                                    }
1980                                    else {
1981                                            userPKSet.remove(user.getPrimaryKey());
1982                                    }
1983                            }
1984    
1985                            for (Long userPK : userPKSet) {
1986                                    addUser.add(pk, userPK);
1987                            }
1988                    }
1989                    catch (Exception e) {
1990                            throw processException(e);
1991                    }
1992                    finally {
1993                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1994                    }
1995            }
1996    
1997            public void setUsers(long pk, List<com.liferay.portal.model.User> users)
1998                    throws SystemException {
1999                    try {
2000                            long[] userPKs = new long[users.size()];
2001    
2002                            for (int i = 0; i < users.size(); i++) {
2003                                    com.liferay.portal.model.User user = users.get(i);
2004    
2005                                    userPKs[i] = user.getPrimaryKey();
2006                            }
2007    
2008                            setUsers(pk, userPKs);
2009                    }
2010                    catch (Exception e) {
2011                            throw processException(e);
2012                    }
2013                    finally {
2014                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
2015                    }
2016            }
2017    
2018            public void afterPropertiesSet() {
2019                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2020                                            com.liferay.portal.util.PropsUtil.get(
2021                                                    "value.object.listener.com.liferay.portal.model.UserGroup")));
2022    
2023                    if (listenerClassNames.length > 0) {
2024                            try {
2025                                    List<ModelListener<UserGroup>> listenersList = new ArrayList<ModelListener<UserGroup>>();
2026    
2027                                    for (String listenerClassName : listenerClassNames) {
2028                                            listenersList.add((ModelListener<UserGroup>)InstanceFactory.newInstance(
2029                                                            listenerClassName));
2030                                    }
2031    
2032                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2033                            }
2034                            catch (Exception e) {
2035                                    _log.error(e);
2036                            }
2037                    }
2038    
2039                    containsGroup = new ContainsGroup(this);
2040    
2041                    addGroup = new AddGroup(this);
2042                    clearGroups = new ClearGroups(this);
2043                    removeGroup = new RemoveGroup(this);
2044    
2045                    containsUser = new ContainsUser(this);
2046    
2047                    addUser = new AddUser(this);
2048                    clearUsers = new ClearUsers(this);
2049                    removeUser = new RemoveUser(this);
2050            }
2051    
2052            @BeanReference(type = AccountPersistence.class)
2053            protected AccountPersistence accountPersistence;
2054            @BeanReference(type = AddressPersistence.class)
2055            protected AddressPersistence addressPersistence;
2056            @BeanReference(type = BrowserTrackerPersistence.class)
2057            protected BrowserTrackerPersistence browserTrackerPersistence;
2058            @BeanReference(type = ClassNamePersistence.class)
2059            protected ClassNamePersistence classNamePersistence;
2060            @BeanReference(type = CompanyPersistence.class)
2061            protected CompanyPersistence companyPersistence;
2062            @BeanReference(type = ContactPersistence.class)
2063            protected ContactPersistence contactPersistence;
2064            @BeanReference(type = CountryPersistence.class)
2065            protected CountryPersistence countryPersistence;
2066            @BeanReference(type = EmailAddressPersistence.class)
2067            protected EmailAddressPersistence emailAddressPersistence;
2068            @BeanReference(type = GroupPersistence.class)
2069            protected GroupPersistence groupPersistence;
2070            @BeanReference(type = ImagePersistence.class)
2071            protected ImagePersistence imagePersistence;
2072            @BeanReference(type = LayoutPersistence.class)
2073            protected LayoutPersistence layoutPersistence;
2074            @BeanReference(type = LayoutPrototypePersistence.class)
2075            protected LayoutPrototypePersistence layoutPrototypePersistence;
2076            @BeanReference(type = LayoutSetPersistence.class)
2077            protected LayoutSetPersistence layoutSetPersistence;
2078            @BeanReference(type = LayoutSetPrototypePersistence.class)
2079            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2080            @BeanReference(type = ListTypePersistence.class)
2081            protected ListTypePersistence listTypePersistence;
2082            @BeanReference(type = LockPersistence.class)
2083            protected LockPersistence lockPersistence;
2084            @BeanReference(type = MembershipRequestPersistence.class)
2085            protected MembershipRequestPersistence membershipRequestPersistence;
2086            @BeanReference(type = OrganizationPersistence.class)
2087            protected OrganizationPersistence organizationPersistence;
2088            @BeanReference(type = OrgGroupPermissionPersistence.class)
2089            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2090            @BeanReference(type = OrgGroupRolePersistence.class)
2091            protected OrgGroupRolePersistence orgGroupRolePersistence;
2092            @BeanReference(type = OrgLaborPersistence.class)
2093            protected OrgLaborPersistence orgLaborPersistence;
2094            @BeanReference(type = PasswordPolicyPersistence.class)
2095            protected PasswordPolicyPersistence passwordPolicyPersistence;
2096            @BeanReference(type = PasswordPolicyRelPersistence.class)
2097            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2098            @BeanReference(type = PasswordTrackerPersistence.class)
2099            protected PasswordTrackerPersistence passwordTrackerPersistence;
2100            @BeanReference(type = PermissionPersistence.class)
2101            protected PermissionPersistence permissionPersistence;
2102            @BeanReference(type = PhonePersistence.class)
2103            protected PhonePersistence phonePersistence;
2104            @BeanReference(type = PluginSettingPersistence.class)
2105            protected PluginSettingPersistence pluginSettingPersistence;
2106            @BeanReference(type = PortletPersistence.class)
2107            protected PortletPersistence portletPersistence;
2108            @BeanReference(type = PortletItemPersistence.class)
2109            protected PortletItemPersistence portletItemPersistence;
2110            @BeanReference(type = PortletPreferencesPersistence.class)
2111            protected PortletPreferencesPersistence portletPreferencesPersistence;
2112            @BeanReference(type = RegionPersistence.class)
2113            protected RegionPersistence regionPersistence;
2114            @BeanReference(type = ReleasePersistence.class)
2115            protected ReleasePersistence releasePersistence;
2116            @BeanReference(type = ResourcePersistence.class)
2117            protected ResourcePersistence resourcePersistence;
2118            @BeanReference(type = ResourceActionPersistence.class)
2119            protected ResourceActionPersistence resourceActionPersistence;
2120            @BeanReference(type = ResourceCodePersistence.class)
2121            protected ResourceCodePersistence resourceCodePersistence;
2122            @BeanReference(type = ResourcePermissionPersistence.class)
2123            protected ResourcePermissionPersistence resourcePermissionPersistence;
2124            @BeanReference(type = RolePersistence.class)
2125            protected RolePersistence rolePersistence;
2126            @BeanReference(type = ServiceComponentPersistence.class)
2127            protected ServiceComponentPersistence serviceComponentPersistence;
2128            @BeanReference(type = ShardPersistence.class)
2129            protected ShardPersistence shardPersistence;
2130            @BeanReference(type = SubscriptionPersistence.class)
2131            protected SubscriptionPersistence subscriptionPersistence;
2132            @BeanReference(type = TicketPersistence.class)
2133            protected TicketPersistence ticketPersistence;
2134            @BeanReference(type = TeamPersistence.class)
2135            protected TeamPersistence teamPersistence;
2136            @BeanReference(type = UserPersistence.class)
2137            protected UserPersistence userPersistence;
2138            @BeanReference(type = UserGroupPersistence.class)
2139            protected UserGroupPersistence userGroupPersistence;
2140            @BeanReference(type = UserGroupGroupRolePersistence.class)
2141            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2142            @BeanReference(type = UserGroupRolePersistence.class)
2143            protected UserGroupRolePersistence userGroupRolePersistence;
2144            @BeanReference(type = UserIdMapperPersistence.class)
2145            protected UserIdMapperPersistence userIdMapperPersistence;
2146            @BeanReference(type = UserTrackerPersistence.class)
2147            protected UserTrackerPersistence userTrackerPersistence;
2148            @BeanReference(type = UserTrackerPathPersistence.class)
2149            protected UserTrackerPathPersistence userTrackerPathPersistence;
2150            @BeanReference(type = WebDAVPropsPersistence.class)
2151            protected WebDAVPropsPersistence webDAVPropsPersistence;
2152            @BeanReference(type = WebsitePersistence.class)
2153            protected WebsitePersistence websitePersistence;
2154            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2155            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2156            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2157            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2158            protected ContainsGroup containsGroup;
2159            protected AddGroup addGroup;
2160            protected ClearGroups clearGroups;
2161            protected RemoveGroup removeGroup;
2162            protected ContainsUser containsUser;
2163            protected AddUser addUser;
2164            protected ClearUsers clearUsers;
2165            protected RemoveUser removeUser;
2166    
2167            protected class ContainsGroup {
2168                    protected ContainsGroup(UserGroupPersistenceImpl persistenceImpl) {
2169                            super();
2170    
2171                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2172                                            _SQL_CONTAINSGROUP,
2173                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
2174                                            RowMapper.COUNT);
2175                    }
2176    
2177                    protected boolean contains(long userGroupId, long groupId) {
2178                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2179                                                    new Long(userGroupId), new Long(groupId)
2180                                            });
2181    
2182                            if (results.size() > 0) {
2183                                    Integer count = results.get(0);
2184    
2185                                    if (count.intValue() > 0) {
2186                                            return true;
2187                                    }
2188                            }
2189    
2190                            return false;
2191                    }
2192    
2193                    private MappingSqlQuery<Integer> _mappingSqlQuery;
2194            }
2195    
2196            protected class AddGroup {
2197                    protected AddGroup(UserGroupPersistenceImpl persistenceImpl) {
2198                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2199                                            "INSERT INTO Groups_UserGroups (userGroupId, groupId) VALUES (?, ?)",
2200                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
2201                            _persistenceImpl = persistenceImpl;
2202                    }
2203    
2204                    protected void add(long userGroupId, long groupId)
2205                            throws SystemException {
2206                            if (!_persistenceImpl.containsGroup.contains(userGroupId, groupId)) {
2207                                    ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
2208    
2209                                    for (ModelListener<UserGroup> listener : listeners) {
2210                                            listener.onBeforeAddAssociation(userGroupId,
2211                                                    com.liferay.portal.model.Group.class.getName(), groupId);
2212                                    }
2213    
2214                                    for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2215                                            listener.onBeforeAddAssociation(groupId,
2216                                                    UserGroup.class.getName(), userGroupId);
2217                                    }
2218    
2219                                    _sqlUpdate.update(new Object[] {
2220                                                    new Long(userGroupId), new Long(groupId)
2221                                            });
2222    
2223                                    for (ModelListener<UserGroup> listener : listeners) {
2224                                            listener.onAfterAddAssociation(userGroupId,
2225                                                    com.liferay.portal.model.Group.class.getName(), groupId);
2226                                    }
2227    
2228                                    for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2229                                            listener.onAfterAddAssociation(groupId,
2230                                                    UserGroup.class.getName(), userGroupId);
2231                                    }
2232                            }
2233                    }
2234    
2235                    private SqlUpdate _sqlUpdate;
2236                    private UserGroupPersistenceImpl _persistenceImpl;
2237            }
2238    
2239            protected class ClearGroups {
2240                    protected ClearGroups(UserGroupPersistenceImpl persistenceImpl) {
2241                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2242                                            "DELETE FROM Groups_UserGroups WHERE userGroupId = ?",
2243                                            new int[] { java.sql.Types.BIGINT });
2244                    }
2245    
2246                    protected void clear(long userGroupId) throws SystemException {
2247                            ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
2248    
2249                            List<com.liferay.portal.model.Group> groups = null;
2250    
2251                            if ((listeners.length > 0) || (groupListeners.length > 0)) {
2252                                    groups = getGroups(userGroupId);
2253    
2254                                    for (com.liferay.portal.model.Group group : groups) {
2255                                            for (ModelListener<UserGroup> listener : listeners) {
2256                                                    listener.onBeforeRemoveAssociation(userGroupId,
2257                                                            com.liferay.portal.model.Group.class.getName(),
2258                                                            group.getPrimaryKey());
2259                                            }
2260    
2261                                            for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2262                                                    listener.onBeforeRemoveAssociation(group.getPrimaryKey(),
2263                                                            UserGroup.class.getName(), userGroupId);
2264                                            }
2265                                    }
2266                            }
2267    
2268                            _sqlUpdate.update(new Object[] { new Long(userGroupId) });
2269    
2270                            if ((listeners.length > 0) || (groupListeners.length > 0)) {
2271                                    for (com.liferay.portal.model.Group group : groups) {
2272                                            for (ModelListener<UserGroup> listener : listeners) {
2273                                                    listener.onAfterRemoveAssociation(userGroupId,
2274                                                            com.liferay.portal.model.Group.class.getName(),
2275                                                            group.getPrimaryKey());
2276                                            }
2277    
2278                                            for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2279                                                    listener.onAfterRemoveAssociation(group.getPrimaryKey(),
2280                                                            UserGroup.class.getName(), userGroupId);
2281                                            }
2282                                    }
2283                            }
2284                    }
2285    
2286                    private SqlUpdate _sqlUpdate;
2287            }
2288    
2289            protected class RemoveGroup {
2290                    protected RemoveGroup(UserGroupPersistenceImpl persistenceImpl) {
2291                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2292                                            "DELETE FROM Groups_UserGroups WHERE userGroupId = ? AND groupId = ?",
2293                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
2294                            _persistenceImpl = persistenceImpl;
2295                    }
2296    
2297                    protected void remove(long userGroupId, long groupId)
2298                            throws SystemException {
2299                            if (_persistenceImpl.containsGroup.contains(userGroupId, groupId)) {
2300                                    ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
2301    
2302                                    for (ModelListener<UserGroup> listener : listeners) {
2303                                            listener.onBeforeRemoveAssociation(userGroupId,
2304                                                    com.liferay.portal.model.Group.class.getName(), groupId);
2305                                    }
2306    
2307                                    for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2308                                            listener.onBeforeRemoveAssociation(groupId,
2309                                                    UserGroup.class.getName(), userGroupId);
2310                                    }
2311    
2312                                    _sqlUpdate.update(new Object[] {
2313                                                    new Long(userGroupId), new Long(groupId)
2314                                            });
2315    
2316                                    for (ModelListener<UserGroup> listener : listeners) {
2317                                            listener.onAfterRemoveAssociation(userGroupId,
2318                                                    com.liferay.portal.model.Group.class.getName(), groupId);
2319                                    }
2320    
2321                                    for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2322                                            listener.onAfterRemoveAssociation(groupId,
2323                                                    UserGroup.class.getName(), userGroupId);
2324                                    }
2325                            }
2326                    }
2327    
2328                    private SqlUpdate _sqlUpdate;
2329                    private UserGroupPersistenceImpl _persistenceImpl;
2330            }
2331    
2332            protected class ContainsUser {
2333                    protected ContainsUser(UserGroupPersistenceImpl persistenceImpl) {
2334                            super();
2335    
2336                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2337                                            _SQL_CONTAINSUSER,
2338                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
2339                                            RowMapper.COUNT);
2340                    }
2341    
2342                    protected boolean contains(long userGroupId, long userId) {
2343                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2344                                                    new Long(userGroupId), new Long(userId)
2345                                            });
2346    
2347                            if (results.size() > 0) {
2348                                    Integer count = results.get(0);
2349    
2350                                    if (count.intValue() > 0) {
2351                                            return true;
2352                                    }
2353                            }
2354    
2355                            return false;
2356                    }
2357    
2358                    private MappingSqlQuery<Integer> _mappingSqlQuery;
2359            }
2360    
2361            protected class AddUser {
2362                    protected AddUser(UserGroupPersistenceImpl persistenceImpl) {
2363                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2364                                            "INSERT INTO Users_UserGroups (userGroupId, userId) VALUES (?, ?)",
2365                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
2366                            _persistenceImpl = persistenceImpl;
2367                    }
2368    
2369                    protected void add(long userGroupId, long userId)
2370                            throws SystemException {
2371                            if (!_persistenceImpl.containsUser.contains(userGroupId, userId)) {
2372                                    ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
2373    
2374                                    for (ModelListener<UserGroup> listener : listeners) {
2375                                            listener.onBeforeAddAssociation(userGroupId,
2376                                                    com.liferay.portal.model.User.class.getName(), userId);
2377                                    }
2378    
2379                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2380                                            listener.onBeforeAddAssociation(userId,
2381                                                    UserGroup.class.getName(), userGroupId);
2382                                    }
2383    
2384                                    _sqlUpdate.update(new Object[] {
2385                                                    new Long(userGroupId), new Long(userId)
2386                                            });
2387    
2388                                    for (ModelListener<UserGroup> listener : listeners) {
2389                                            listener.onAfterAddAssociation(userGroupId,
2390                                                    com.liferay.portal.model.User.class.getName(), userId);
2391                                    }
2392    
2393                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2394                                            listener.onAfterAddAssociation(userId,
2395                                                    UserGroup.class.getName(), userGroupId);
2396                                    }
2397                            }
2398                    }
2399    
2400                    private SqlUpdate _sqlUpdate;
2401                    private UserGroupPersistenceImpl _persistenceImpl;
2402            }
2403    
2404            protected class ClearUsers {
2405                    protected ClearUsers(UserGroupPersistenceImpl persistenceImpl) {
2406                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2407                                            "DELETE FROM Users_UserGroups WHERE userGroupId = ?",
2408                                            new int[] { java.sql.Types.BIGINT });
2409                    }
2410    
2411                    protected void clear(long userGroupId) throws SystemException {
2412                            ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
2413    
2414                            List<com.liferay.portal.model.User> users = null;
2415    
2416                            if ((listeners.length > 0) || (userListeners.length > 0)) {
2417                                    users = getUsers(userGroupId);
2418    
2419                                    for (com.liferay.portal.model.User user : users) {
2420                                            for (ModelListener<UserGroup> listener : listeners) {
2421                                                    listener.onBeforeRemoveAssociation(userGroupId,
2422                                                            com.liferay.portal.model.User.class.getName(),
2423                                                            user.getPrimaryKey());
2424                                            }
2425    
2426                                            for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2427                                                    listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
2428                                                            UserGroup.class.getName(), userGroupId);
2429                                            }
2430                                    }
2431                            }
2432    
2433                            _sqlUpdate.update(new Object[] { new Long(userGroupId) });
2434    
2435                            if ((listeners.length > 0) || (userListeners.length > 0)) {
2436                                    for (com.liferay.portal.model.User user : users) {
2437                                            for (ModelListener<UserGroup> listener : listeners) {
2438                                                    listener.onAfterRemoveAssociation(userGroupId,
2439                                                            com.liferay.portal.model.User.class.getName(),
2440                                                            user.getPrimaryKey());
2441                                            }
2442    
2443                                            for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2444                                                    listener.onAfterRemoveAssociation(user.getPrimaryKey(),
2445                                                            UserGroup.class.getName(), userGroupId);
2446                                            }
2447                                    }
2448                            }
2449                    }
2450    
2451                    private SqlUpdate _sqlUpdate;
2452            }
2453    
2454            protected class RemoveUser {
2455                    protected RemoveUser(UserGroupPersistenceImpl persistenceImpl) {
2456                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2457                                            "DELETE FROM Users_UserGroups WHERE userGroupId = ? AND userId = ?",
2458                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
2459                            _persistenceImpl = persistenceImpl;
2460                    }
2461    
2462                    protected void remove(long userGroupId, long userId)
2463                            throws SystemException {
2464                            if (_persistenceImpl.containsUser.contains(userGroupId, userId)) {
2465                                    ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
2466    
2467                                    for (ModelListener<UserGroup> listener : listeners) {
2468                                            listener.onBeforeRemoveAssociation(userGroupId,
2469                                                    com.liferay.portal.model.User.class.getName(), userId);
2470                                    }
2471    
2472                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2473                                            listener.onBeforeRemoveAssociation(userId,
2474                                                    UserGroup.class.getName(), userGroupId);
2475                                    }
2476    
2477                                    _sqlUpdate.update(new Object[] {
2478                                                    new Long(userGroupId), new Long(userId)
2479                                            });
2480    
2481                                    for (ModelListener<UserGroup> listener : listeners) {
2482                                            listener.onAfterRemoveAssociation(userGroupId,
2483                                                    com.liferay.portal.model.User.class.getName(), userId);
2484                                    }
2485    
2486                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2487                                            listener.onAfterRemoveAssociation(userId,
2488                                                    UserGroup.class.getName(), userGroupId);
2489                                    }
2490                            }
2491                    }
2492    
2493                    private SqlUpdate _sqlUpdate;
2494                    private UserGroupPersistenceImpl _persistenceImpl;
2495            }
2496    
2497            private static final String _SQL_SELECT_USERGROUP = "SELECT userGroup FROM UserGroup userGroup";
2498            private static final String _SQL_SELECT_USERGROUP_WHERE = "SELECT userGroup FROM UserGroup userGroup WHERE ";
2499            private static final String _SQL_COUNT_USERGROUP = "SELECT COUNT(userGroup) FROM UserGroup userGroup";
2500            private static final String _SQL_COUNT_USERGROUP_WHERE = "SELECT COUNT(userGroup) FROM UserGroup userGroup WHERE ";
2501            private static final String _SQL_GETGROUPS = "SELECT {Group_.*} FROM Group_ INNER JOIN Groups_UserGroups ON (Groups_UserGroups.groupId = Group_.groupId) WHERE (Groups_UserGroups.userGroupId = ?)";
2502            private static final String _SQL_GETGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_UserGroups WHERE userGroupId = ?";
2503            private static final String _SQL_CONTAINSGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_UserGroups WHERE userGroupId = ? AND groupId = ?";
2504            private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_UserGroups ON (Users_UserGroups.userId = User_.userId) WHERE (Users_UserGroups.userGroupId = ?)";
2505            private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_UserGroups WHERE userGroupId = ?";
2506            private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_UserGroups WHERE userGroupId = ? AND userId = ?";
2507            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "userGroup.companyId = ?";
2508            private static final String _FINDER_COLUMN_C_P_COMPANYID_2 = "userGroup.companyId = ? AND ";
2509            private static final String _FINDER_COLUMN_C_P_PARENTUSERGROUPID_2 = "userGroup.parentUserGroupId = ?";
2510            private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "userGroup.companyId = ? AND ";
2511            private static final String _FINDER_COLUMN_C_N_NAME_1 = "userGroup.name IS NULL";
2512            private static final String _FINDER_COLUMN_C_N_NAME_2 = "userGroup.name = ?";
2513            private static final String _FINDER_COLUMN_C_N_NAME_3 = "(userGroup.name IS NULL OR userGroup.name = ?)";
2514            private static final String _ORDER_BY_ENTITY_ALIAS = "userGroup.";
2515            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No UserGroup exists with the primary key ";
2516            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No UserGroup exists with the key {";
2517            private static Log _log = LogFactoryUtil.getLog(UserGroupPersistenceImpl.class);
2518    }