1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.service.persistence;
24  
25  import com.liferay.portal.NoSuchModelException;
26  import com.liferay.portal.NoSuchUserGroupException;
27  import com.liferay.portal.SystemException;
28  import com.liferay.portal.kernel.annotation.BeanReference;
29  import com.liferay.portal.kernel.cache.CacheRegistry;
30  import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
31  import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
32  import com.liferay.portal.kernel.dao.jdbc.RowMapper;
33  import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
34  import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
35  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
36  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
37  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
38  import com.liferay.portal.kernel.dao.orm.FinderPath;
39  import com.liferay.portal.kernel.dao.orm.Query;
40  import com.liferay.portal.kernel.dao.orm.QueryPos;
41  import com.liferay.portal.kernel.dao.orm.QueryUtil;
42  import com.liferay.portal.kernel.dao.orm.SQLQuery;
43  import com.liferay.portal.kernel.dao.orm.Session;
44  import com.liferay.portal.kernel.dao.orm.Type;
45  import com.liferay.portal.kernel.log.Log;
46  import com.liferay.portal.kernel.log.LogFactoryUtil;
47  import com.liferay.portal.kernel.util.GetterUtil;
48  import com.liferay.portal.kernel.util.OrderByComparator;
49  import com.liferay.portal.kernel.util.SetUtil;
50  import com.liferay.portal.kernel.util.StringBundler;
51  import com.liferay.portal.kernel.util.StringPool;
52  import com.liferay.portal.kernel.util.StringUtil;
53  import com.liferay.portal.kernel.util.Validator;
54  import com.liferay.portal.model.ModelListener;
55  import com.liferay.portal.model.UserGroup;
56  import com.liferay.portal.model.impl.UserGroupImpl;
57  import com.liferay.portal.model.impl.UserGroupModelImpl;
58  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
59  
60  import java.io.Serializable;
61  
62  import java.sql.Types;
63  
64  import java.util.ArrayList;
65  import java.util.Collections;
66  import java.util.List;
67  import java.util.Set;
68  
69  /**
70   * <a href="UserGroupPersistenceImpl.java.html"><b><i>View Source</i></b></a>
71   *
72   * <p>
73   * ServiceBuilder generated this class. Modifications in this class will be
74   * overwritten the next time is generated.
75   * </p>
76   *
77   * @author    Brian Wing Shun Chan
78   * @see       UserGroupPersistence
79   * @see       UserGroupUtil
80   * @generated
81   */
82  public class UserGroupPersistenceImpl extends BasePersistenceImpl<UserGroup>
83      implements UserGroupPersistence {
84      public static final String FINDER_CLASS_NAME_ENTITY = UserGroupImpl.class.getName();
85      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
86          ".List";
87      public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
88              UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
89              "findByCompanyId", new String[] { Long.class.getName() });
90      public static final FinderPath FINDER_PATH_FIND_BY_OBC_COMPANYID = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
91              UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
92              "findByCompanyId",
93              new String[] {
94                  Long.class.getName(),
95                  
96              "java.lang.Integer", "java.lang.Integer",
97                  "com.liferay.portal.kernel.util.OrderByComparator"
98              });
99      public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
100             UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
101             "countByCompanyId", new String[] { Long.class.getName() });
102     public static final FinderPath FINDER_PATH_FIND_BY_C_P = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
103             UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
104             "findByC_P",
105             new String[] { Long.class.getName(), Long.class.getName() });
106     public static final FinderPath FINDER_PATH_FIND_BY_OBC_C_P = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
107             UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
108             "findByC_P",
109             new String[] {
110                 Long.class.getName(), Long.class.getName(),
111                 
112             "java.lang.Integer", "java.lang.Integer",
113                 "com.liferay.portal.kernel.util.OrderByComparator"
114             });
115     public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
116             UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
117             "countByC_P",
118             new String[] { Long.class.getName(), Long.class.getName() });
119     public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
120             UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
121             "fetchByC_N",
122             new String[] { Long.class.getName(), String.class.getName() });
123     public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
124             UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
125             "countByC_N",
126             new String[] { Long.class.getName(), String.class.getName() });
127     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
128             UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
129             "findAll", new String[0]);
130     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
131             UserGroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
132             "countAll", new String[0]);
133 
134     public void cacheResult(UserGroup userGroup) {
135         EntityCacheUtil.putResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
136             UserGroupImpl.class, userGroup.getPrimaryKey(), userGroup);
137 
138         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
139             new Object[] { new Long(userGroup.getCompanyId()), userGroup.getName() },
140             userGroup);
141     }
142 
143     public void cacheResult(List<UserGroup> userGroups) {
144         for (UserGroup userGroup : userGroups) {
145             if (EntityCacheUtil.getResult(
146                         UserGroupModelImpl.ENTITY_CACHE_ENABLED,
147                         UserGroupImpl.class, userGroup.getPrimaryKey(), this) == null) {
148                 cacheResult(userGroup);
149             }
150         }
151     }
152 
153     public void clearCache() {
154         CacheRegistry.clear(UserGroupImpl.class.getName());
155         EntityCacheUtil.clearCache(UserGroupImpl.class.getName());
156         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
157         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
158     }
159 
160     public UserGroup create(long userGroupId) {
161         UserGroup userGroup = new UserGroupImpl();
162 
163         userGroup.setNew(true);
164         userGroup.setPrimaryKey(userGroupId);
165 
166         return userGroup;
167     }
168 
169     public UserGroup remove(Serializable primaryKey)
170         throws NoSuchModelException, SystemException {
171         return remove(((Long)primaryKey).longValue());
172     }
173 
174     public UserGroup remove(long userGroupId)
175         throws NoSuchUserGroupException, SystemException {
176         Session session = null;
177 
178         try {
179             session = openSession();
180 
181             UserGroup userGroup = (UserGroup)session.get(UserGroupImpl.class,
182                     new Long(userGroupId));
183 
184             if (userGroup == null) {
185                 if (_log.isWarnEnabled()) {
186                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + userGroupId);
187                 }
188 
189                 throw new NoSuchUserGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
190                     userGroupId);
191             }
192 
193             return remove(userGroup);
194         }
195         catch (NoSuchUserGroupException nsee) {
196             throw nsee;
197         }
198         catch (Exception e) {
199             throw processException(e);
200         }
201         finally {
202             closeSession(session);
203         }
204     }
205 
206     public UserGroup remove(UserGroup userGroup) throws SystemException {
207         for (ModelListener<UserGroup> listener : listeners) {
208             listener.onBeforeRemove(userGroup);
209         }
210 
211         userGroup = removeImpl(userGroup);
212 
213         for (ModelListener<UserGroup> listener : listeners) {
214             listener.onAfterRemove(userGroup);
215         }
216 
217         return userGroup;
218     }
219 
220     protected UserGroup removeImpl(UserGroup userGroup)
221         throws SystemException {
222         userGroup = toUnwrappedModel(userGroup);
223 
224         try {
225             clearUsers.clear(userGroup.getPrimaryKey());
226         }
227         catch (Exception e) {
228             throw processException(e);
229         }
230         finally {
231             FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
232         }
233 
234         Session session = null;
235 
236         try {
237             session = openSession();
238 
239             if (userGroup.isCachedModel() || BatchSessionUtil.isEnabled()) {
240                 Object staleObject = session.get(UserGroupImpl.class,
241                         userGroup.getPrimaryKeyObj());
242 
243                 if (staleObject != null) {
244                     session.evict(staleObject);
245                 }
246             }
247 
248             session.delete(userGroup);
249 
250             session.flush();
251         }
252         catch (Exception e) {
253             throw processException(e);
254         }
255         finally {
256             closeSession(session);
257         }
258 
259         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
260 
261         UserGroupModelImpl userGroupModelImpl = (UserGroupModelImpl)userGroup;
262 
263         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
264             new Object[] {
265                 new Long(userGroupModelImpl.getOriginalCompanyId()),
266                 
267             userGroupModelImpl.getOriginalName()
268             });
269 
270         EntityCacheUtil.removeResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
271             UserGroupImpl.class, userGroup.getPrimaryKey());
272 
273         return userGroup;
274     }
275 
276     /**
277      * @deprecated Use {@link BasePersistence#update(com.liferay.portal.model.BaseModel, boolean)}.
278      */
279     public UserGroup update(UserGroup userGroup) throws SystemException {
280         if (_log.isWarnEnabled()) {
281             _log.warn(
282                 "Using the deprecated update(UserGroup userGroup) method. Use update(UserGroup userGroup, boolean merge) instead.");
283         }
284 
285         return update(userGroup, false);
286     }
287 
288     public UserGroup updateImpl(com.liferay.portal.model.UserGroup userGroup,
289         boolean merge) throws SystemException {
290         userGroup = toUnwrappedModel(userGroup);
291 
292         boolean isNew = userGroup.isNew();
293 
294         UserGroupModelImpl userGroupModelImpl = (UserGroupModelImpl)userGroup;
295 
296         Session session = null;
297 
298         try {
299             session = openSession();
300 
301             BatchSessionUtil.update(session, userGroup, merge);
302 
303             userGroup.setNew(false);
304         }
305         catch (Exception e) {
306             throw processException(e);
307         }
308         finally {
309             closeSession(session);
310         }
311 
312         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
313 
314         EntityCacheUtil.putResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
315             UserGroupImpl.class, userGroup.getPrimaryKey(), userGroup);
316 
317         if (!isNew &&
318                 ((userGroup.getCompanyId() != userGroupModelImpl.getOriginalCompanyId()) ||
319                 !Validator.equals(userGroup.getName(),
320                     userGroupModelImpl.getOriginalName()))) {
321             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
322                 new Object[] {
323                     new Long(userGroupModelImpl.getOriginalCompanyId()),
324                     
325                 userGroupModelImpl.getOriginalName()
326                 });
327         }
328 
329         if (isNew ||
330                 ((userGroup.getCompanyId() != userGroupModelImpl.getOriginalCompanyId()) ||
331                 !Validator.equals(userGroup.getName(),
332                     userGroupModelImpl.getOriginalName()))) {
333             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
334                 new Object[] {
335                     new Long(userGroup.getCompanyId()),
336                     
337                 userGroup.getName()
338                 }, userGroup);
339         }
340 
341         return userGroup;
342     }
343 
344     protected UserGroup toUnwrappedModel(UserGroup userGroup) {
345         if (userGroup instanceof UserGroupImpl) {
346             return userGroup;
347         }
348 
349         UserGroupImpl userGroupImpl = new UserGroupImpl();
350 
351         userGroupImpl.setNew(userGroup.isNew());
352         userGroupImpl.setPrimaryKey(userGroup.getPrimaryKey());
353 
354         userGroupImpl.setUserGroupId(userGroup.getUserGroupId());
355         userGroupImpl.setCompanyId(userGroup.getCompanyId());
356         userGroupImpl.setParentUserGroupId(userGroup.getParentUserGroupId());
357         userGroupImpl.setName(userGroup.getName());
358         userGroupImpl.setDescription(userGroup.getDescription());
359 
360         return userGroupImpl;
361     }
362 
363     public UserGroup findByPrimaryKey(Serializable primaryKey)
364         throws NoSuchModelException, SystemException {
365         return findByPrimaryKey(((Long)primaryKey).longValue());
366     }
367 
368     public UserGroup findByPrimaryKey(long userGroupId)
369         throws NoSuchUserGroupException, SystemException {
370         UserGroup userGroup = fetchByPrimaryKey(userGroupId);
371 
372         if (userGroup == null) {
373             if (_log.isWarnEnabled()) {
374                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + userGroupId);
375             }
376 
377             throw new NoSuchUserGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
378                 userGroupId);
379         }
380 
381         return userGroup;
382     }
383 
384     public UserGroup fetchByPrimaryKey(Serializable primaryKey)
385         throws SystemException {
386         return fetchByPrimaryKey(((Long)primaryKey).longValue());
387     }
388 
389     public UserGroup fetchByPrimaryKey(long userGroupId)
390         throws SystemException {
391         UserGroup userGroup = (UserGroup)EntityCacheUtil.getResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
392                 UserGroupImpl.class, userGroupId, this);
393 
394         if (userGroup == null) {
395             Session session = null;
396 
397             try {
398                 session = openSession();
399 
400                 userGroup = (UserGroup)session.get(UserGroupImpl.class,
401                         new Long(userGroupId));
402             }
403             catch (Exception e) {
404                 throw processException(e);
405             }
406             finally {
407                 if (userGroup != null) {
408                     cacheResult(userGroup);
409                 }
410 
411                 closeSession(session);
412             }
413         }
414 
415         return userGroup;
416     }
417 
418     public List<UserGroup> findByCompanyId(long companyId)
419         throws SystemException {
420         Object[] finderArgs = new Object[] { new Long(companyId) };
421 
422         List<UserGroup> list = (List<UserGroup>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
423                 finderArgs, this);
424 
425         if (list == null) {
426             Session session = null;
427 
428             try {
429                 session = openSession();
430 
431                 StringBundler query = new StringBundler(3);
432 
433                 query.append(_SQL_SELECT_USERGROUP_WHERE);
434 
435                 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
436 
437                 query.append(UserGroupModelImpl.ORDER_BY_JPQL);
438 
439                 String sql = query.toString();
440 
441                 Query q = session.createQuery(sql);
442 
443                 QueryPos qPos = QueryPos.getInstance(q);
444 
445                 qPos.add(companyId);
446 
447                 list = q.list();
448             }
449             catch (Exception e) {
450                 throw processException(e);
451             }
452             finally {
453                 if (list == null) {
454                     list = new ArrayList<UserGroup>();
455                 }
456 
457                 cacheResult(list);
458 
459                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
460                     finderArgs, list);
461 
462                 closeSession(session);
463             }
464         }
465 
466         return list;
467     }
468 
469     public List<UserGroup> findByCompanyId(long companyId, int start, int end)
470         throws SystemException {
471         return findByCompanyId(companyId, start, end, null);
472     }
473 
474     public List<UserGroup> findByCompanyId(long companyId, int start, int end,
475         OrderByComparator obc) throws SystemException {
476         Object[] finderArgs = new Object[] {
477                 new Long(companyId),
478                 
479                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
480             };
481 
482         List<UserGroup> list = (List<UserGroup>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
483                 finderArgs, this);
484 
485         if (list == null) {
486             Session session = null;
487 
488             try {
489                 session = openSession();
490 
491                 StringBundler query = null;
492 
493                 if (obc != null) {
494                     query = new StringBundler(3 +
495                             (obc.getOrderByFields().length * 3));
496                 }
497                 else {
498                     query = new StringBundler(3);
499                 }
500 
501                 query.append(_SQL_SELECT_USERGROUP_WHERE);
502 
503                 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
504 
505                 if (obc != null) {
506                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
507                 }
508 
509                 else {
510                     query.append(UserGroupModelImpl.ORDER_BY_JPQL);
511                 }
512 
513                 String sql = query.toString();
514 
515                 Query q = session.createQuery(sql);
516 
517                 QueryPos qPos = QueryPos.getInstance(q);
518 
519                 qPos.add(companyId);
520 
521                 list = (List<UserGroup>)QueryUtil.list(q, getDialect(), start,
522                         end);
523             }
524             catch (Exception e) {
525                 throw processException(e);
526             }
527             finally {
528                 if (list == null) {
529                     list = new ArrayList<UserGroup>();
530                 }
531 
532                 cacheResult(list);
533 
534                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
535                     finderArgs, list);
536 
537                 closeSession(session);
538             }
539         }
540 
541         return list;
542     }
543 
544     public UserGroup findByCompanyId_First(long companyId, OrderByComparator obc)
545         throws NoSuchUserGroupException, SystemException {
546         List<UserGroup> list = findByCompanyId(companyId, 0, 1, obc);
547 
548         if (list.isEmpty()) {
549             StringBundler msg = new StringBundler(4);
550 
551             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
552 
553             msg.append("companyId=");
554             msg.append(companyId);
555 
556             msg.append(StringPool.CLOSE_CURLY_BRACE);
557 
558             throw new NoSuchUserGroupException(msg.toString());
559         }
560         else {
561             return list.get(0);
562         }
563     }
564 
565     public UserGroup findByCompanyId_Last(long companyId, OrderByComparator obc)
566         throws NoSuchUserGroupException, SystemException {
567         int count = countByCompanyId(companyId);
568 
569         List<UserGroup> list = findByCompanyId(companyId, count - 1, count, obc);
570 
571         if (list.isEmpty()) {
572             StringBundler msg = new StringBundler(4);
573 
574             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
575 
576             msg.append("companyId=");
577             msg.append(companyId);
578 
579             msg.append(StringPool.CLOSE_CURLY_BRACE);
580 
581             throw new NoSuchUserGroupException(msg.toString());
582         }
583         else {
584             return list.get(0);
585         }
586     }
587 
588     public UserGroup[] findByCompanyId_PrevAndNext(long userGroupId,
589         long companyId, OrderByComparator obc)
590         throws NoSuchUserGroupException, SystemException {
591         UserGroup userGroup = findByPrimaryKey(userGroupId);
592 
593         int count = countByCompanyId(companyId);
594 
595         Session session = null;
596 
597         try {
598             session = openSession();
599 
600             StringBundler query = null;
601 
602             if (obc != null) {
603                 query = new StringBundler(3 +
604                         (obc.getOrderByFields().length * 3));
605             }
606             else {
607                 query = new StringBundler(3);
608             }
609 
610             query.append(_SQL_SELECT_USERGROUP_WHERE);
611 
612             query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
613 
614             if (obc != null) {
615                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
616             }
617 
618             else {
619                 query.append(UserGroupModelImpl.ORDER_BY_JPQL);
620             }
621 
622             String sql = query.toString();
623 
624             Query q = session.createQuery(sql);
625 
626             QueryPos qPos = QueryPos.getInstance(q);
627 
628             qPos.add(companyId);
629 
630             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
631                     userGroup);
632 
633             UserGroup[] array = new UserGroupImpl[3];
634 
635             array[0] = (UserGroup)objArray[0];
636             array[1] = (UserGroup)objArray[1];
637             array[2] = (UserGroup)objArray[2];
638 
639             return array;
640         }
641         catch (Exception e) {
642             throw processException(e);
643         }
644         finally {
645             closeSession(session);
646         }
647     }
648 
649     public List<UserGroup> findByC_P(long companyId, long parentUserGroupId)
650         throws SystemException {
651         Object[] finderArgs = new Object[] {
652                 new Long(companyId), new Long(parentUserGroupId)
653             };
654 
655         List<UserGroup> list = (List<UserGroup>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_P,
656                 finderArgs, this);
657 
658         if (list == null) {
659             Session session = null;
660 
661             try {
662                 session = openSession();
663 
664                 StringBundler query = new StringBundler(4);
665 
666                 query.append(_SQL_SELECT_USERGROUP_WHERE);
667 
668                 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
669 
670                 query.append(_FINDER_COLUMN_C_P_PARENTUSERGROUPID_2);
671 
672                 query.append(UserGroupModelImpl.ORDER_BY_JPQL);
673 
674                 String sql = query.toString();
675 
676                 Query q = session.createQuery(sql);
677 
678                 QueryPos qPos = QueryPos.getInstance(q);
679 
680                 qPos.add(companyId);
681 
682                 qPos.add(parentUserGroupId);
683 
684                 list = q.list();
685             }
686             catch (Exception e) {
687                 throw processException(e);
688             }
689             finally {
690                 if (list == null) {
691                     list = new ArrayList<UserGroup>();
692                 }
693 
694                 cacheResult(list);
695 
696                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_P, finderArgs,
697                     list);
698 
699                 closeSession(session);
700             }
701         }
702 
703         return list;
704     }
705 
706     public List<UserGroup> findByC_P(long companyId, long parentUserGroupId,
707         int start, int end) throws SystemException {
708         return findByC_P(companyId, parentUserGroupId, start, end, null);
709     }
710 
711     public List<UserGroup> findByC_P(long companyId, long parentUserGroupId,
712         int start, int end, OrderByComparator obc) throws SystemException {
713         Object[] finderArgs = new Object[] {
714                 new Long(companyId), new Long(parentUserGroupId),
715                 
716                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
717             };
718 
719         List<UserGroup> list = (List<UserGroup>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_P,
720                 finderArgs, this);
721 
722         if (list == null) {
723             Session session = null;
724 
725             try {
726                 session = openSession();
727 
728                 StringBundler query = null;
729 
730                 if (obc != null) {
731                     query = new StringBundler(4 +
732                             (obc.getOrderByFields().length * 3));
733                 }
734                 else {
735                     query = new StringBundler(4);
736                 }
737 
738                 query.append(_SQL_SELECT_USERGROUP_WHERE);
739 
740                 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
741 
742                 query.append(_FINDER_COLUMN_C_P_PARENTUSERGROUPID_2);
743 
744                 if (obc != null) {
745                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
746                 }
747 
748                 else {
749                     query.append(UserGroupModelImpl.ORDER_BY_JPQL);
750                 }
751 
752                 String sql = query.toString();
753 
754                 Query q = session.createQuery(sql);
755 
756                 QueryPos qPos = QueryPos.getInstance(q);
757 
758                 qPos.add(companyId);
759 
760                 qPos.add(parentUserGroupId);
761 
762                 list = (List<UserGroup>)QueryUtil.list(q, getDialect(), start,
763                         end);
764             }
765             catch (Exception e) {
766                 throw processException(e);
767             }
768             finally {
769                 if (list == null) {
770                     list = new ArrayList<UserGroup>();
771                 }
772 
773                 cacheResult(list);
774 
775                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_P,
776                     finderArgs, list);
777 
778                 closeSession(session);
779             }
780         }
781 
782         return list;
783     }
784 
785     public UserGroup findByC_P_First(long companyId, long parentUserGroupId,
786         OrderByComparator obc) throws NoSuchUserGroupException, SystemException {
787         List<UserGroup> list = findByC_P(companyId, parentUserGroupId, 0, 1, obc);
788 
789         if (list.isEmpty()) {
790             StringBundler msg = new StringBundler(6);
791 
792             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
793 
794             msg.append("companyId=");
795             msg.append(companyId);
796 
797             msg.append(", parentUserGroupId=");
798             msg.append(parentUserGroupId);
799 
800             msg.append(StringPool.CLOSE_CURLY_BRACE);
801 
802             throw new NoSuchUserGroupException(msg.toString());
803         }
804         else {
805             return list.get(0);
806         }
807     }
808 
809     public UserGroup findByC_P_Last(long companyId, long parentUserGroupId,
810         OrderByComparator obc) throws NoSuchUserGroupException, SystemException {
811         int count = countByC_P(companyId, parentUserGroupId);
812 
813         List<UserGroup> list = findByC_P(companyId, parentUserGroupId,
814                 count - 1, count, obc);
815 
816         if (list.isEmpty()) {
817             StringBundler msg = new StringBundler(6);
818 
819             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
820 
821             msg.append("companyId=");
822             msg.append(companyId);
823 
824             msg.append(", parentUserGroupId=");
825             msg.append(parentUserGroupId);
826 
827             msg.append(StringPool.CLOSE_CURLY_BRACE);
828 
829             throw new NoSuchUserGroupException(msg.toString());
830         }
831         else {
832             return list.get(0);
833         }
834     }
835 
836     public UserGroup[] findByC_P_PrevAndNext(long userGroupId, long companyId,
837         long parentUserGroupId, OrderByComparator obc)
838         throws NoSuchUserGroupException, SystemException {
839         UserGroup userGroup = findByPrimaryKey(userGroupId);
840 
841         int count = countByC_P(companyId, parentUserGroupId);
842 
843         Session session = null;
844 
845         try {
846             session = openSession();
847 
848             StringBundler query = null;
849 
850             if (obc != null) {
851                 query = new StringBundler(4 +
852                         (obc.getOrderByFields().length * 3));
853             }
854             else {
855                 query = new StringBundler(4);
856             }
857 
858             query.append(_SQL_SELECT_USERGROUP_WHERE);
859 
860             query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
861 
862             query.append(_FINDER_COLUMN_C_P_PARENTUSERGROUPID_2);
863 
864             if (obc != null) {
865                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
866             }
867 
868             else {
869                 query.append(UserGroupModelImpl.ORDER_BY_JPQL);
870             }
871 
872             String sql = query.toString();
873 
874             Query q = session.createQuery(sql);
875 
876             QueryPos qPos = QueryPos.getInstance(q);
877 
878             qPos.add(companyId);
879 
880             qPos.add(parentUserGroupId);
881 
882             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
883                     userGroup);
884 
885             UserGroup[] array = new UserGroupImpl[3];
886 
887             array[0] = (UserGroup)objArray[0];
888             array[1] = (UserGroup)objArray[1];
889             array[2] = (UserGroup)objArray[2];
890 
891             return array;
892         }
893         catch (Exception e) {
894             throw processException(e);
895         }
896         finally {
897             closeSession(session);
898         }
899     }
900 
901     public UserGroup findByC_N(long companyId, String name)
902         throws NoSuchUserGroupException, SystemException {
903         UserGroup userGroup = fetchByC_N(companyId, name);
904 
905         if (userGroup == null) {
906             StringBundler msg = new StringBundler(6);
907 
908             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
909 
910             msg.append("companyId=");
911             msg.append(companyId);
912 
913             msg.append(", name=");
914             msg.append(name);
915 
916             msg.append(StringPool.CLOSE_CURLY_BRACE);
917 
918             if (_log.isWarnEnabled()) {
919                 _log.warn(msg.toString());
920             }
921 
922             throw new NoSuchUserGroupException(msg.toString());
923         }
924 
925         return userGroup;
926     }
927 
928     public UserGroup fetchByC_N(long companyId, String name)
929         throws SystemException {
930         return fetchByC_N(companyId, name, true);
931     }
932 
933     public UserGroup fetchByC_N(long companyId, String name,
934         boolean retrieveFromCache) throws SystemException {
935         Object[] finderArgs = new Object[] { new Long(companyId), name };
936 
937         Object result = null;
938 
939         if (retrieveFromCache) {
940             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
941                     finderArgs, this);
942         }
943 
944         if (result == null) {
945             Session session = null;
946 
947             try {
948                 session = openSession();
949 
950                 StringBundler query = new StringBundler(4);
951 
952                 query.append(_SQL_SELECT_USERGROUP_WHERE);
953 
954                 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
955 
956                 if (name == null) {
957                     query.append(_FINDER_COLUMN_C_N_NAME_1);
958                 }
959                 else {
960                     if (name.equals(StringPool.BLANK)) {
961                         query.append(_FINDER_COLUMN_C_N_NAME_3);
962                     }
963                     else {
964                         query.append(_FINDER_COLUMN_C_N_NAME_2);
965                     }
966                 }
967 
968                 query.append(UserGroupModelImpl.ORDER_BY_JPQL);
969 
970                 String sql = query.toString();
971 
972                 Query q = session.createQuery(sql);
973 
974                 QueryPos qPos = QueryPos.getInstance(q);
975 
976                 qPos.add(companyId);
977 
978                 if (name != null) {
979                     qPos.add(name);
980                 }
981 
982                 List<UserGroup> list = q.list();
983 
984                 result = list;
985 
986                 UserGroup userGroup = null;
987 
988                 if (list.isEmpty()) {
989                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
990                         finderArgs, list);
991                 }
992                 else {
993                     userGroup = list.get(0);
994 
995                     cacheResult(userGroup);
996 
997                     if ((userGroup.getCompanyId() != companyId) ||
998                             (userGroup.getName() == null) ||
999                             !userGroup.getName().equals(name)) {
1000                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
1001                            finderArgs, userGroup);
1002                    }
1003                }
1004
1005                return userGroup;
1006            }
1007            catch (Exception e) {
1008                throw processException(e);
1009            }
1010            finally {
1011                if (result == null) {
1012                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
1013                        finderArgs, new ArrayList<UserGroup>());
1014                }
1015
1016                closeSession(session);
1017            }
1018        }
1019        else {
1020            if (result instanceof List<?>) {
1021                return null;
1022            }
1023            else {
1024                return (UserGroup)result;
1025            }
1026        }
1027    }
1028
1029    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1030        throws SystemException {
1031        Session session = null;
1032
1033        try {
1034            session = openSession();
1035
1036            dynamicQuery.compile(session);
1037
1038            return dynamicQuery.list();
1039        }
1040        catch (Exception e) {
1041            throw processException(e);
1042        }
1043        finally {
1044            closeSession(session);
1045        }
1046    }
1047
1048    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1049        int start, int end) throws SystemException {
1050        Session session = null;
1051
1052        try {
1053            session = openSession();
1054
1055            dynamicQuery.setLimit(start, end);
1056
1057            dynamicQuery.compile(session);
1058
1059            return dynamicQuery.list();
1060        }
1061        catch (Exception e) {
1062            throw processException(e);
1063        }
1064        finally {
1065            closeSession(session);
1066        }
1067    }
1068
1069    public List<UserGroup> findAll() throws SystemException {
1070        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1071    }
1072
1073    public List<UserGroup> findAll(int start, int end)
1074        throws SystemException {
1075        return findAll(start, end, null);
1076    }
1077
1078    public List<UserGroup> findAll(int start, int end, OrderByComparator obc)
1079        throws SystemException {
1080        Object[] finderArgs = new Object[] {
1081                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1082            };
1083
1084        List<UserGroup> list = (List<UserGroup>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1085                finderArgs, this);
1086
1087        if (list == null) {
1088            Session session = null;
1089
1090            try {
1091                session = openSession();
1092
1093                StringBundler query = null;
1094                String sql = null;
1095
1096                if (obc != null) {
1097                    query = new StringBundler(2 +
1098                            (obc.getOrderByFields().length * 3));
1099
1100                    query.append(_SQL_SELECT_USERGROUP);
1101
1102                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1103
1104                    sql = query.toString();
1105                }
1106
1107                else {
1108                    sql = _SQL_SELECT_USERGROUP.concat(UserGroupModelImpl.ORDER_BY_JPQL);
1109                }
1110
1111                Query q = session.createQuery(sql);
1112
1113                if (obc == null) {
1114                    list = (List<UserGroup>)QueryUtil.list(q, getDialect(),
1115                            start, end, false);
1116
1117                    Collections.sort(list);
1118                }
1119                else {
1120                    list = (List<UserGroup>)QueryUtil.list(q, getDialect(),
1121                            start, end);
1122                }
1123            }
1124            catch (Exception e) {
1125                throw processException(e);
1126            }
1127            finally {
1128                if (list == null) {
1129                    list = new ArrayList<UserGroup>();
1130                }
1131
1132                cacheResult(list);
1133
1134                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1135
1136                closeSession(session);
1137            }
1138        }
1139
1140        return list;
1141    }
1142
1143    public void removeByCompanyId(long companyId) throws SystemException {
1144        for (UserGroup userGroup : findByCompanyId(companyId)) {
1145            remove(userGroup);
1146        }
1147    }
1148
1149    public void removeByC_P(long companyId, long parentUserGroupId)
1150        throws SystemException {
1151        for (UserGroup userGroup : findByC_P(companyId, parentUserGroupId)) {
1152            remove(userGroup);
1153        }
1154    }
1155
1156    public void removeByC_N(long companyId, String name)
1157        throws NoSuchUserGroupException, SystemException {
1158        UserGroup userGroup = findByC_N(companyId, name);
1159
1160        remove(userGroup);
1161    }
1162
1163    public void removeAll() throws SystemException {
1164        for (UserGroup userGroup : findAll()) {
1165            remove(userGroup);
1166        }
1167    }
1168
1169    public int countByCompanyId(long companyId) throws SystemException {
1170        Object[] finderArgs = new Object[] { new Long(companyId) };
1171
1172        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1173                finderArgs, this);
1174
1175        if (count == null) {
1176            Session session = null;
1177
1178            try {
1179                session = openSession();
1180
1181                StringBundler query = new StringBundler(2);
1182
1183                query.append(_SQL_COUNT_USERGROUP_WHERE);
1184
1185                query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1186
1187                String sql = query.toString();
1188
1189                Query q = session.createQuery(sql);
1190
1191                QueryPos qPos = QueryPos.getInstance(q);
1192
1193                qPos.add(companyId);
1194
1195                count = (Long)q.uniqueResult();
1196            }
1197            catch (Exception e) {
1198                throw processException(e);
1199            }
1200            finally {
1201                if (count == null) {
1202                    count = Long.valueOf(0);
1203                }
1204
1205                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1206                    finderArgs, count);
1207
1208                closeSession(session);
1209            }
1210        }
1211
1212        return count.intValue();
1213    }
1214
1215    public int countByC_P(long companyId, long parentUserGroupId)
1216        throws SystemException {
1217        Object[] finderArgs = new Object[] {
1218                new Long(companyId), new Long(parentUserGroupId)
1219            };
1220
1221        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_P,
1222                finderArgs, this);
1223
1224        if (count == null) {
1225            Session session = null;
1226
1227            try {
1228                session = openSession();
1229
1230                StringBundler query = new StringBundler(3);
1231
1232                query.append(_SQL_COUNT_USERGROUP_WHERE);
1233
1234                query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
1235
1236                query.append(_FINDER_COLUMN_C_P_PARENTUSERGROUPID_2);
1237
1238                String sql = query.toString();
1239
1240                Query q = session.createQuery(sql);
1241
1242                QueryPos qPos = QueryPos.getInstance(q);
1243
1244                qPos.add(companyId);
1245
1246                qPos.add(parentUserGroupId);
1247
1248                count = (Long)q.uniqueResult();
1249            }
1250            catch (Exception e) {
1251                throw processException(e);
1252            }
1253            finally {
1254                if (count == null) {
1255                    count = Long.valueOf(0);
1256                }
1257
1258                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_P, finderArgs,
1259                    count);
1260
1261                closeSession(session);
1262            }
1263        }
1264
1265        return count.intValue();
1266    }
1267
1268    public int countByC_N(long companyId, String name)
1269        throws SystemException {
1270        Object[] finderArgs = new Object[] { new Long(companyId), name };
1271
1272        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N,
1273                finderArgs, this);
1274
1275        if (count == null) {
1276            Session session = null;
1277
1278            try {
1279                session = openSession();
1280
1281                StringBundler query = new StringBundler(3);
1282
1283                query.append(_SQL_COUNT_USERGROUP_WHERE);
1284
1285                query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
1286
1287                if (name == null) {
1288                    query.append(_FINDER_COLUMN_C_N_NAME_1);
1289                }
1290                else {
1291                    if (name.equals(StringPool.BLANK)) {
1292                        query.append(_FINDER_COLUMN_C_N_NAME_3);
1293                    }
1294                    else {
1295                        query.append(_FINDER_COLUMN_C_N_NAME_2);
1296                    }
1297                }
1298
1299                String sql = query.toString();
1300
1301                Query q = session.createQuery(sql);
1302
1303                QueryPos qPos = QueryPos.getInstance(q);
1304
1305                qPos.add(companyId);
1306
1307                if (name != null) {
1308                    qPos.add(name);
1309                }
1310
1311                count = (Long)q.uniqueResult();
1312            }
1313            catch (Exception e) {
1314                throw processException(e);
1315            }
1316            finally {
1317                if (count == null) {
1318                    count = Long.valueOf(0);
1319                }
1320
1321                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, finderArgs,
1322                    count);
1323
1324                closeSession(session);
1325            }
1326        }
1327
1328        return count.intValue();
1329    }
1330
1331    public int countAll() throws SystemException {
1332        Object[] finderArgs = new Object[0];
1333
1334        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1335                finderArgs, this);
1336
1337        if (count == null) {
1338            Session session = null;
1339
1340            try {
1341                session = openSession();
1342
1343                Query q = session.createQuery(_SQL_COUNT_USERGROUP);
1344
1345                count = (Long)q.uniqueResult();
1346            }
1347            catch (Exception e) {
1348                throw processException(e);
1349            }
1350            finally {
1351                if (count == null) {
1352                    count = Long.valueOf(0);
1353                }
1354
1355                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1356                    count);
1357
1358                closeSession(session);
1359            }
1360        }
1361
1362        return count.intValue();
1363    }
1364
1365    public List<com.liferay.portal.model.User> getUsers(long pk)
1366        throws SystemException {
1367        return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1368    }
1369
1370    public List<com.liferay.portal.model.User> getUsers(long pk, int start,
1371        int end) throws SystemException {
1372        return getUsers(pk, start, end, null);
1373    }
1374
1375    public static final FinderPath FINDER_PATH_GET_USERS = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1376            UserGroupModelImpl.FINDER_CACHE_ENABLED_USERS_USERGROUPS,
1377            UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME, "getUsers",
1378            new String[] {
1379                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1380                "com.liferay.portal.kernel.util.OrderByComparator"
1381            });
1382
1383    public List<com.liferay.portal.model.User> getUsers(long pk, int start,
1384        int end, OrderByComparator obc) throws SystemException {
1385        Object[] finderArgs = new Object[] {
1386                new Long(pk), String.valueOf(start), String.valueOf(end),
1387                String.valueOf(obc)
1388            };
1389
1390        List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS,
1391                finderArgs, this);
1392
1393        if (list == null) {
1394            Session session = null;
1395
1396            try {
1397                session = openSession();
1398
1399                StringBundler query = null;
1400                String sql = null;
1401
1402                if (obc != null) {
1403                    query = new StringBundler(3);
1404
1405                    query.append(_SQL_GETUSERS);
1406                    query.append(ORDER_BY_CLAUSE);
1407                    query.append(obc.getOrderBy());
1408
1409                    sql = query.toString();
1410                }
1411
1412                sql = _SQL_GETUSERS;
1413
1414                SQLQuery q = session.createSQLQuery(sql);
1415
1416                q.addEntity("User_",
1417                    com.liferay.portal.model.impl.UserImpl.class);
1418
1419                QueryPos qPos = QueryPos.getInstance(q);
1420
1421                qPos.add(pk);
1422
1423                list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
1424                        getDialect(), start, end);
1425            }
1426            catch (Exception e) {
1427                throw processException(e);
1428            }
1429            finally {
1430                if (list == null) {
1431                    list = new ArrayList<com.liferay.portal.model.User>();
1432                }
1433
1434                userPersistence.cacheResult(list);
1435
1436                FinderCacheUtil.putResult(FINDER_PATH_GET_USERS, finderArgs,
1437                    list);
1438
1439                closeSession(session);
1440            }
1441        }
1442
1443        return list;
1444    }
1445
1446    public static final FinderPath FINDER_PATH_GET_USERS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1447            UserGroupModelImpl.FINDER_CACHE_ENABLED_USERS_USERGROUPS,
1448            UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME,
1449            "getUsersSize", new String[] { Long.class.getName() });
1450
1451    public int getUsersSize(long pk) throws SystemException {
1452        Object[] finderArgs = new Object[] { new Long(pk) };
1453
1454        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS_SIZE,
1455                finderArgs, this);
1456
1457        if (count == null) {
1458            Session session = null;
1459
1460            try {
1461                session = openSession();
1462
1463                SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
1464
1465                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1466
1467                QueryPos qPos = QueryPos.getInstance(q);
1468
1469                qPos.add(pk);
1470
1471                count = (Long)q.uniqueResult();
1472            }
1473            catch (Exception e) {
1474                throw processException(e);
1475            }
1476            finally {
1477                if (count == null) {
1478                    count = Long.valueOf(0);
1479                }
1480
1481                FinderCacheUtil.putResult(FINDER_PATH_GET_USERS_SIZE,
1482                    finderArgs, count);
1483
1484                closeSession(session);
1485            }
1486        }
1487
1488        return count.intValue();
1489    }
1490
1491    public static final FinderPath FINDER_PATH_CONTAINS_USER = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1492            UserGroupModelImpl.FINDER_CACHE_ENABLED_USERS_USERGROUPS,
1493            UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME,
1494            "containsUser",
1495            new String[] { Long.class.getName(), Long.class.getName() });
1496
1497    public boolean containsUser(long pk, long userPK) throws SystemException {
1498        Object[] finderArgs = new Object[] { new Long(pk), new Long(userPK) };
1499
1500        Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USER,
1501                finderArgs, this);
1502
1503        if (value == null) {
1504            try {
1505                value = Boolean.valueOf(containsUser.contains(pk, userPK));
1506            }
1507            catch (Exception e) {
1508                throw processException(e);
1509            }
1510            finally {
1511                if (value == null) {
1512                    value = Boolean.FALSE;
1513                }
1514
1515                FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USER,
1516                    finderArgs, value);
1517            }
1518        }
1519
1520        return value.booleanValue();
1521    }
1522
1523    public boolean containsUsers(long pk) throws SystemException {
1524        if (getUsersSize(pk) > 0) {
1525            return true;
1526        }
1527        else {
1528            return false;
1529        }
1530    }
1531
1532    public void addUser(long pk, long userPK) throws SystemException {
1533        try {
1534            addUser.add(pk, userPK);
1535        }
1536        catch (Exception e) {
1537            throw processException(e);
1538        }
1539        finally {
1540            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1541        }
1542    }
1543
1544    public void addUser(long pk, com.liferay.portal.model.User user)
1545        throws SystemException {
1546        try {
1547            addUser.add(pk, user.getPrimaryKey());
1548        }
1549        catch (Exception e) {
1550            throw processException(e);
1551        }
1552        finally {
1553            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1554        }
1555    }
1556
1557    public void addUsers(long pk, long[] userPKs) throws SystemException {
1558        try {
1559            for (long userPK : userPKs) {
1560                addUser.add(pk, userPK);
1561            }
1562        }
1563        catch (Exception e) {
1564            throw processException(e);
1565        }
1566        finally {
1567            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1568        }
1569    }
1570
1571    public void addUsers(long pk, List<com.liferay.portal.model.User> users)
1572        throws SystemException {
1573        try {
1574            for (com.liferay.portal.model.User user : users) {
1575                addUser.add(pk, user.getPrimaryKey());
1576            }
1577        }
1578        catch (Exception e) {
1579            throw processException(e);
1580        }
1581        finally {
1582            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1583        }
1584    }
1585
1586    public void clearUsers(long pk) throws SystemException {
1587        try {
1588            clearUsers.clear(pk);
1589        }
1590        catch (Exception e) {
1591            throw processException(e);
1592        }
1593        finally {
1594            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1595        }
1596    }
1597
1598    public void removeUser(long pk, long userPK) throws SystemException {
1599        try {
1600            removeUser.remove(pk, userPK);
1601        }
1602        catch (Exception e) {
1603            throw processException(e);
1604        }
1605        finally {
1606            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1607        }
1608    }
1609
1610    public void removeUser(long pk, com.liferay.portal.model.User user)
1611        throws SystemException {
1612        try {
1613            removeUser.remove(pk, user.getPrimaryKey());
1614        }
1615        catch (Exception e) {
1616            throw processException(e);
1617        }
1618        finally {
1619            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1620        }
1621    }
1622
1623    public void removeUsers(long pk, long[] userPKs) throws SystemException {
1624        try {
1625            for (long userPK : userPKs) {
1626                removeUser.remove(pk, userPK);
1627            }
1628        }
1629        catch (Exception e) {
1630            throw processException(e);
1631        }
1632        finally {
1633            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1634        }
1635    }
1636
1637    public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
1638        throws SystemException {
1639        try {
1640            for (com.liferay.portal.model.User user : users) {
1641                removeUser.remove(pk, user.getPrimaryKey());
1642            }
1643        }
1644        catch (Exception e) {
1645            throw processException(e);
1646        }
1647        finally {
1648            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1649        }
1650    }
1651
1652    public void setUsers(long pk, long[] userPKs) throws SystemException {
1653        try {
1654            Set<Long> userPKSet = SetUtil.fromArray(userPKs);
1655
1656            List<com.liferay.portal.model.User> users = getUsers(pk);
1657
1658            for (com.liferay.portal.model.User user : users) {
1659                if (!userPKSet.contains(user.getPrimaryKey())) {
1660                    removeUser.remove(pk, user.getPrimaryKey());
1661                }
1662                else {
1663                    userPKSet.remove(user.getPrimaryKey());
1664                }
1665            }
1666
1667            for (Long userPK : userPKSet) {
1668                addUser.add(pk, userPK);
1669            }
1670        }
1671        catch (Exception e) {
1672            throw processException(e);
1673        }
1674        finally {
1675            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1676        }
1677    }
1678
1679    public void setUsers(long pk, List<com.liferay.portal.model.User> users)
1680        throws SystemException {
1681        try {
1682            long[] userPKs = new long[users.size()];
1683
1684            for (int i = 0; i < users.size(); i++) {
1685                com.liferay.portal.model.User user = users.get(i);
1686
1687                userPKs[i] = user.getPrimaryKey();
1688            }
1689
1690            setUsers(pk, userPKs);
1691        }
1692        catch (Exception e) {
1693            throw processException(e);
1694        }
1695        finally {
1696            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
1697        }
1698    }
1699
1700    public void afterPropertiesSet() {
1701        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1702                    com.liferay.portal.util.PropsUtil.get(
1703                        "value.object.listener.com.liferay.portal.model.UserGroup")));
1704
1705        if (listenerClassNames.length > 0) {
1706            try {
1707                List<ModelListener<UserGroup>> listenersList = new ArrayList<ModelListener<UserGroup>>();
1708
1709                for (String listenerClassName : listenerClassNames) {
1710                    listenersList.add((ModelListener<UserGroup>)Class.forName(
1711                            listenerClassName).newInstance());
1712                }
1713
1714                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1715            }
1716            catch (Exception e) {
1717                _log.error(e);
1718            }
1719        }
1720
1721        containsUser = new ContainsUser(this);
1722
1723        addUser = new AddUser(this);
1724        clearUsers = new ClearUsers(this);
1725        removeUser = new RemoveUser(this);
1726    }
1727
1728    @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence")
1729    protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
1730    @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence")
1731    protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
1732    @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence")
1733    protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
1734    @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence")
1735    protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
1736    @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence")
1737    protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
1738    @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence")
1739    protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
1740    @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence")
1741    protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
1742    @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence")
1743    protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
1744    @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence")
1745    protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
1746    @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence")
1747    protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
1748    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence")
1749    protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
1750    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence")
1751    protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
1752    @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence")
1753    protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
1754    @BeanReference(name = "com.liferay.portal.service.persistence.LockPersistence")
1755    protected com.liferay.portal.service.persistence.LockPersistence lockPersistence;
1756    @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence")
1757    protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
1758    @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence")
1759    protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
1760    @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence")
1761    protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1762    @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence")
1763    protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
1764    @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence")
1765    protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
1766    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence")
1767    protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
1768    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence")
1769    protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1770    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence")
1771    protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
1772    @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence")
1773    protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
1774    @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence")
1775    protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
1776    @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence")
1777    protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
1778    @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence")
1779    protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
1780    @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence")
1781    protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
1782    @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence")
1783    protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
1784    @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence")
1785    protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
1786    @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence")
1787    protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
1788    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence")
1789    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1790    @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence")
1791    protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
1792    @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence")
1793    protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
1794    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence")
1795    protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
1796    @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence")
1797    protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
1798    @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence")
1799    protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
1800    @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence")
1801    protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
1802    @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence")
1803    protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
1804    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence")
1805    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1806    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence")
1807    protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
1808    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupGroupRolePersistence")
1809    protected com.liferay.portal.service.persistence.UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1810    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence")
1811    protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
1812    @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence")
1813    protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
1814    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence")
1815    protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
1816    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence")
1817    protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
1818    @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence")
1819    protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
1820    @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence")
1821    protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
1822    protected ContainsUser containsUser;
1823    protected AddUser addUser;
1824    protected ClearUsers clearUsers;
1825    protected RemoveUser removeUser;
1826
1827    protected class ContainsUser {
1828        protected ContainsUser(UserGroupPersistenceImpl persistenceImpl) {
1829            super();
1830
1831            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
1832                    _SQL_CONTAINSUSER,
1833                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
1834        }
1835
1836        protected boolean contains(long userGroupId, long userId) {
1837            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
1838                        new Long(userGroupId), new Long(userId)
1839                    });
1840
1841            if (results.size() > 0) {
1842                Integer count = results.get(0);
1843
1844                if (count.intValue() > 0) {
1845                    return true;
1846                }
1847            }
1848
1849            return false;
1850        }
1851
1852        private MappingSqlQuery _mappingSqlQuery;
1853    }
1854
1855    protected class AddUser {
1856        protected AddUser(UserGroupPersistenceImpl persistenceImpl) {
1857            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1858                    "INSERT INTO Users_UserGroups (userGroupId, userId) VALUES (?, ?)",
1859                    new int[] { Types.BIGINT, Types.BIGINT });
1860            _persistenceImpl = persistenceImpl;
1861        }
1862
1863        protected void add(long userGroupId, long userId)
1864            throws SystemException {
1865            if (!_persistenceImpl.containsUser.contains(userGroupId, userId)) {
1866                ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
1867
1868                for (ModelListener<UserGroup> listener : listeners) {
1869                    listener.onBeforeAddAssociation(userGroupId,
1870                        com.liferay.portal.model.User.class.getName(), userId);
1871                }
1872
1873                for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
1874                    listener.onBeforeAddAssociation(userId,
1875                        UserGroup.class.getName(), userGroupId);
1876                }
1877
1878                _sqlUpdate.update(new Object[] {
1879                        new Long(userGroupId), new Long(userId)
1880                    });
1881
1882                for (ModelListener<UserGroup> listener : listeners) {
1883                    listener.onAfterAddAssociation(userGroupId,
1884                        com.liferay.portal.model.User.class.getName(), userId);
1885                }
1886
1887                for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
1888                    listener.onAfterAddAssociation(userId,
1889                        UserGroup.class.getName(), userGroupId);
1890                }
1891            }
1892        }
1893
1894        private SqlUpdate _sqlUpdate;
1895        private UserGroupPersistenceImpl _persistenceImpl;
1896    }
1897
1898    protected class ClearUsers {
1899        protected ClearUsers(UserGroupPersistenceImpl persistenceImpl) {
1900            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1901                    "DELETE FROM Users_UserGroups WHERE userGroupId = ?",
1902                    new int[] { Types.BIGINT });
1903        }
1904
1905        protected void clear(long userGroupId) throws SystemException {
1906            ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
1907
1908            List<com.liferay.portal.model.User> users = null;
1909
1910            if ((listeners.length > 0) || (userListeners.length > 0)) {
1911                users = getUsers(userGroupId);
1912
1913                for (com.liferay.portal.model.User user : users) {
1914                    for (ModelListener<UserGroup> listener : listeners) {
1915                        listener.onBeforeRemoveAssociation(userGroupId,
1916                            com.liferay.portal.model.User.class.getName(),
1917                            user.getPrimaryKey());
1918                    }
1919
1920                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
1921                        listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
1922                            UserGroup.class.getName(), userGroupId);
1923                    }
1924                }
1925            }
1926
1927            _sqlUpdate.update(new Object[] { new Long(userGroupId) });
1928
1929            if ((listeners.length > 0) || (userListeners.length > 0)) {
1930                for (com.liferay.portal.model.User user : users) {
1931                    for (ModelListener<UserGroup> listener : listeners) {
1932                        listener.onAfterRemoveAssociation(userGroupId,
1933                            com.liferay.portal.model.User.class.getName(),
1934                            user.getPrimaryKey());
1935                    }
1936
1937                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
1938                        listener.onAfterRemoveAssociation(user.getPrimaryKey(),
1939                            UserGroup.class.getName(), userGroupId);
1940                    }
1941                }
1942            }
1943        }
1944
1945        private SqlUpdate _sqlUpdate;
1946    }
1947
1948    protected class RemoveUser {
1949        protected RemoveUser(UserGroupPersistenceImpl persistenceImpl) {
1950            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1951                    "DELETE FROM Users_UserGroups WHERE userGroupId = ? AND userId = ?",
1952                    new int[] { Types.BIGINT, Types.BIGINT });
1953            _persistenceImpl = persistenceImpl;
1954        }
1955
1956        protected void remove(long userGroupId, long userId)
1957            throws SystemException {
1958            if (_persistenceImpl.containsUser.contains(userGroupId, userId)) {
1959                ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
1960
1961                for (ModelListener<UserGroup> listener : listeners) {
1962                    listener.onBeforeRemoveAssociation(userGroupId,
1963                        com.liferay.portal.model.User.class.getName(), userId);
1964                }
1965
1966                for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
1967                    listener.onBeforeRemoveAssociation(userId,
1968                        UserGroup.class.getName(), userGroupId);
1969                }
1970
1971                _sqlUpdate.update(new Object[] {
1972                        new Long(userGroupId), new Long(userId)
1973                    });
1974
1975                for (ModelListener<UserGroup> listener : listeners) {
1976                    listener.onAfterRemoveAssociation(userGroupId,
1977                        com.liferay.portal.model.User.class.getName(), userId);
1978                }
1979
1980                for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
1981                    listener.onAfterRemoveAssociation(userId,
1982                        UserGroup.class.getName(), userGroupId);
1983                }
1984            }
1985        }
1986
1987        private SqlUpdate _sqlUpdate;
1988        private UserGroupPersistenceImpl _persistenceImpl;
1989    }
1990
1991    private static final String _SQL_SELECT_USERGROUP = "SELECT userGroup FROM UserGroup userGroup";
1992    private static final String _SQL_SELECT_USERGROUP_WHERE = "SELECT userGroup FROM UserGroup userGroup WHERE ";
1993    private static final String _SQL_COUNT_USERGROUP = "SELECT COUNT(userGroup) FROM UserGroup userGroup";
1994    private static final String _SQL_COUNT_USERGROUP_WHERE = "SELECT COUNT(userGroup) FROM UserGroup userGroup WHERE ";
1995    private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_UserGroups ON (Users_UserGroups.userId = User_.userId) WHERE (Users_UserGroups.userGroupId = ?)";
1996    private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_UserGroups WHERE userGroupId = ?";
1997    private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_UserGroups WHERE userGroupId = ? AND userId = ?";
1998    private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "userGroup.companyId = ?";
1999    private static final String _FINDER_COLUMN_C_P_COMPANYID_2 = "userGroup.companyId = ? AND ";
2000    private static final String _FINDER_COLUMN_C_P_PARENTUSERGROUPID_2 = "userGroup.parentUserGroupId = ?";
2001    private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "userGroup.companyId = ? AND ";
2002    private static final String _FINDER_COLUMN_C_N_NAME_1 = "userGroup.name IS NULL";
2003    private static final String _FINDER_COLUMN_C_N_NAME_2 = "userGroup.name = ?";
2004    private static final String _FINDER_COLUMN_C_N_NAME_3 = "(userGroup.name IS NULL OR userGroup.name = ?)";
2005    private static final String _ORDER_BY_ENTITY_ALIAS = "userGroup.";
2006    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No UserGroup exists with the primary key ";
2007    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No UserGroup exists with the key {";
2008    private static Log _log = LogFactoryUtil.getLog(UserGroupPersistenceImpl.class);
2009}