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.NoSuchOrgGroupRoleException;
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.orm.DynamicQuery;
31  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
32  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
33  import com.liferay.portal.kernel.dao.orm.FinderPath;
34  import com.liferay.portal.kernel.dao.orm.Query;
35  import com.liferay.portal.kernel.dao.orm.QueryPos;
36  import com.liferay.portal.kernel.dao.orm.QueryUtil;
37  import com.liferay.portal.kernel.dao.orm.Session;
38  import com.liferay.portal.kernel.log.Log;
39  import com.liferay.portal.kernel.log.LogFactoryUtil;
40  import com.liferay.portal.kernel.util.GetterUtil;
41  import com.liferay.portal.kernel.util.OrderByComparator;
42  import com.liferay.portal.kernel.util.StringBundler;
43  import com.liferay.portal.kernel.util.StringPool;
44  import com.liferay.portal.kernel.util.StringUtil;
45  import com.liferay.portal.model.ModelListener;
46  import com.liferay.portal.model.OrgGroupRole;
47  import com.liferay.portal.model.impl.OrgGroupRoleImpl;
48  import com.liferay.portal.model.impl.OrgGroupRoleModelImpl;
49  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
50  
51  import java.io.Serializable;
52  
53  import java.util.ArrayList;
54  import java.util.Collections;
55  import java.util.List;
56  
57  /**
58   * <a href="OrgGroupRolePersistenceImpl.java.html"><b><i>View Source</i></b></a>
59   *
60   * <p>
61   * ServiceBuilder generated this class. Modifications in this class will be
62   * overwritten the next time is generated.
63   * </p>
64   *
65   * @author    Brian Wing Shun Chan
66   * @see       OrgGroupRolePersistence
67   * @see       OrgGroupRoleUtil
68   * @generated
69   */
70  public class OrgGroupRolePersistenceImpl extends BasePersistenceImpl<OrgGroupRole>
71      implements OrgGroupRolePersistence {
72      public static final String FINDER_CLASS_NAME_ENTITY = OrgGroupRoleImpl.class.getName();
73      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
74          ".List";
75      public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
76              OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
77              "findByGroupId", new String[] { Long.class.getName() });
78      public static final FinderPath FINDER_PATH_FIND_BY_OBC_GROUPID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
79              OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
80              "findByGroupId",
81              new String[] {
82                  Long.class.getName(),
83                  
84              "java.lang.Integer", "java.lang.Integer",
85                  "com.liferay.portal.kernel.util.OrderByComparator"
86              });
87      public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
88              OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
89              "countByGroupId", new String[] { Long.class.getName() });
90      public static final FinderPath FINDER_PATH_FIND_BY_ROLEID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
91              OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
92              "findByRoleId", new String[] { Long.class.getName() });
93      public static final FinderPath FINDER_PATH_FIND_BY_OBC_ROLEID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
94              OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
95              "findByRoleId",
96              new String[] {
97                  Long.class.getName(),
98                  
99              "java.lang.Integer", "java.lang.Integer",
100                 "com.liferay.portal.kernel.util.OrderByComparator"
101             });
102     public static final FinderPath FINDER_PATH_COUNT_BY_ROLEID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
103             OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
104             "countByRoleId", new String[] { Long.class.getName() });
105     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
106             OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
107             "findAll", new String[0]);
108     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
109             OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
110             "countAll", new String[0]);
111 
112     public void cacheResult(OrgGroupRole orgGroupRole) {
113         EntityCacheUtil.putResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
114             OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey(), orgGroupRole);
115     }
116 
117     public void cacheResult(List<OrgGroupRole> orgGroupRoles) {
118         for (OrgGroupRole orgGroupRole : orgGroupRoles) {
119             if (EntityCacheUtil.getResult(
120                         OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
121                         OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey(),
122                         this) == null) {
123                 cacheResult(orgGroupRole);
124             }
125         }
126     }
127 
128     public void clearCache() {
129         CacheRegistry.clear(OrgGroupRoleImpl.class.getName());
130         EntityCacheUtil.clearCache(OrgGroupRoleImpl.class.getName());
131         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
132         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
133     }
134 
135     public OrgGroupRole create(OrgGroupRolePK orgGroupRolePK) {
136         OrgGroupRole orgGroupRole = new OrgGroupRoleImpl();
137 
138         orgGroupRole.setNew(true);
139         orgGroupRole.setPrimaryKey(orgGroupRolePK);
140 
141         return orgGroupRole;
142     }
143 
144     public OrgGroupRole remove(Serializable primaryKey)
145         throws NoSuchModelException, SystemException {
146         return remove((OrgGroupRolePK)primaryKey);
147     }
148 
149     public OrgGroupRole remove(OrgGroupRolePK orgGroupRolePK)
150         throws NoSuchOrgGroupRoleException, SystemException {
151         Session session = null;
152 
153         try {
154             session = openSession();
155 
156             OrgGroupRole orgGroupRole = (OrgGroupRole)session.get(OrgGroupRoleImpl.class,
157                     orgGroupRolePK);
158 
159             if (orgGroupRole == null) {
160                 if (_log.isWarnEnabled()) {
161                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
162                         orgGroupRolePK);
163                 }
164 
165                 throw new NoSuchOrgGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
166                     orgGroupRolePK);
167             }
168 
169             return remove(orgGroupRole);
170         }
171         catch (NoSuchOrgGroupRoleException nsee) {
172             throw nsee;
173         }
174         catch (Exception e) {
175             throw processException(e);
176         }
177         finally {
178             closeSession(session);
179         }
180     }
181 
182     public OrgGroupRole remove(OrgGroupRole orgGroupRole)
183         throws SystemException {
184         for (ModelListener<OrgGroupRole> listener : listeners) {
185             listener.onBeforeRemove(orgGroupRole);
186         }
187 
188         orgGroupRole = removeImpl(orgGroupRole);
189 
190         for (ModelListener<OrgGroupRole> listener : listeners) {
191             listener.onAfterRemove(orgGroupRole);
192         }
193 
194         return orgGroupRole;
195     }
196 
197     protected OrgGroupRole removeImpl(OrgGroupRole orgGroupRole)
198         throws SystemException {
199         orgGroupRole = toUnwrappedModel(orgGroupRole);
200 
201         Session session = null;
202 
203         try {
204             session = openSession();
205 
206             if (orgGroupRole.isCachedModel() || BatchSessionUtil.isEnabled()) {
207                 Object staleObject = session.get(OrgGroupRoleImpl.class,
208                         orgGroupRole.getPrimaryKeyObj());
209 
210                 if (staleObject != null) {
211                     session.evict(staleObject);
212                 }
213             }
214 
215             session.delete(orgGroupRole);
216 
217             session.flush();
218         }
219         catch (Exception e) {
220             throw processException(e);
221         }
222         finally {
223             closeSession(session);
224         }
225 
226         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
227 
228         EntityCacheUtil.removeResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
229             OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey());
230 
231         return orgGroupRole;
232     }
233 
234     /**
235      * @deprecated Use {@link BasePersistence#update(com.liferay.portal.model.BaseModel, boolean)}.
236      */
237     public OrgGroupRole update(OrgGroupRole orgGroupRole)
238         throws SystemException {
239         if (_log.isWarnEnabled()) {
240             _log.warn(
241                 "Using the deprecated update(OrgGroupRole orgGroupRole) method. Use update(OrgGroupRole orgGroupRole, boolean merge) instead.");
242         }
243 
244         return update(orgGroupRole, false);
245     }
246 
247     public OrgGroupRole updateImpl(
248         com.liferay.portal.model.OrgGroupRole orgGroupRole, boolean merge)
249         throws SystemException {
250         orgGroupRole = toUnwrappedModel(orgGroupRole);
251 
252         Session session = null;
253 
254         try {
255             session = openSession();
256 
257             BatchSessionUtil.update(session, orgGroupRole, merge);
258 
259             orgGroupRole.setNew(false);
260         }
261         catch (Exception e) {
262             throw processException(e);
263         }
264         finally {
265             closeSession(session);
266         }
267 
268         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
269 
270         EntityCacheUtil.putResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
271             OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey(), orgGroupRole);
272 
273         return orgGroupRole;
274     }
275 
276     protected OrgGroupRole toUnwrappedModel(OrgGroupRole orgGroupRole) {
277         if (orgGroupRole instanceof OrgGroupRoleImpl) {
278             return orgGroupRole;
279         }
280 
281         OrgGroupRoleImpl orgGroupRoleImpl = new OrgGroupRoleImpl();
282 
283         orgGroupRoleImpl.setNew(orgGroupRole.isNew());
284         orgGroupRoleImpl.setPrimaryKey(orgGroupRole.getPrimaryKey());
285 
286         orgGroupRoleImpl.setOrganizationId(orgGroupRole.getOrganizationId());
287         orgGroupRoleImpl.setGroupId(orgGroupRole.getGroupId());
288         orgGroupRoleImpl.setRoleId(orgGroupRole.getRoleId());
289 
290         return orgGroupRoleImpl;
291     }
292 
293     public OrgGroupRole findByPrimaryKey(Serializable primaryKey)
294         throws NoSuchModelException, SystemException {
295         return findByPrimaryKey((OrgGroupRolePK)primaryKey);
296     }
297 
298     public OrgGroupRole findByPrimaryKey(OrgGroupRolePK orgGroupRolePK)
299         throws NoSuchOrgGroupRoleException, SystemException {
300         OrgGroupRole orgGroupRole = fetchByPrimaryKey(orgGroupRolePK);
301 
302         if (orgGroupRole == null) {
303             if (_log.isWarnEnabled()) {
304                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + orgGroupRolePK);
305             }
306 
307             throw new NoSuchOrgGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
308                 orgGroupRolePK);
309         }
310 
311         return orgGroupRole;
312     }
313 
314     public OrgGroupRole fetchByPrimaryKey(Serializable primaryKey)
315         throws SystemException {
316         return fetchByPrimaryKey((OrgGroupRolePK)primaryKey);
317     }
318 
319     public OrgGroupRole fetchByPrimaryKey(OrgGroupRolePK orgGroupRolePK)
320         throws SystemException {
321         OrgGroupRole orgGroupRole = (OrgGroupRole)EntityCacheUtil.getResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
322                 OrgGroupRoleImpl.class, orgGroupRolePK, this);
323 
324         if (orgGroupRole == null) {
325             Session session = null;
326 
327             try {
328                 session = openSession();
329 
330                 orgGroupRole = (OrgGroupRole)session.get(OrgGroupRoleImpl.class,
331                         orgGroupRolePK);
332             }
333             catch (Exception e) {
334                 throw processException(e);
335             }
336             finally {
337                 if (orgGroupRole != null) {
338                     cacheResult(orgGroupRole);
339                 }
340 
341                 closeSession(session);
342             }
343         }
344 
345         return orgGroupRole;
346     }
347 
348     public List<OrgGroupRole> findByGroupId(long groupId)
349         throws SystemException {
350         Object[] finderArgs = new Object[] { new Long(groupId) };
351 
352         List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
353                 finderArgs, this);
354 
355         if (list == null) {
356             Session session = null;
357 
358             try {
359                 session = openSession();
360 
361                 StringBundler query = new StringBundler(2);
362 
363                 query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
364 
365                 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
366 
367                 String sql = query.toString();
368 
369                 Query q = session.createQuery(sql);
370 
371                 QueryPos qPos = QueryPos.getInstance(q);
372 
373                 qPos.add(groupId);
374 
375                 list = q.list();
376             }
377             catch (Exception e) {
378                 throw processException(e);
379             }
380             finally {
381                 if (list == null) {
382                     list = new ArrayList<OrgGroupRole>();
383                 }
384 
385                 cacheResult(list);
386 
387                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
388                     finderArgs, list);
389 
390                 closeSession(session);
391             }
392         }
393 
394         return list;
395     }
396 
397     public List<OrgGroupRole> findByGroupId(long groupId, int start, int end)
398         throws SystemException {
399         return findByGroupId(groupId, start, end, null);
400     }
401 
402     public List<OrgGroupRole> findByGroupId(long groupId, int start, int end,
403         OrderByComparator obc) throws SystemException {
404         Object[] finderArgs = new Object[] {
405                 new Long(groupId),
406                 
407                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
408             };
409 
410         List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
411                 finderArgs, this);
412 
413         if (list == null) {
414             Session session = null;
415 
416             try {
417                 session = openSession();
418 
419                 StringBundler query = null;
420 
421                 if (obc != null) {
422                     query = new StringBundler(3 +
423                             (obc.getOrderByFields().length * 3));
424                 }
425                 else {
426                     query = new StringBundler(2);
427                 }
428 
429                 query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
430 
431                 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
432 
433                 if (obc != null) {
434                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
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(groupId);
444 
445                 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
446                         start, end);
447             }
448             catch (Exception e) {
449                 throw processException(e);
450             }
451             finally {
452                 if (list == null) {
453                     list = new ArrayList<OrgGroupRole>();
454                 }
455 
456                 cacheResult(list);
457 
458                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
459                     finderArgs, list);
460 
461                 closeSession(session);
462             }
463         }
464 
465         return list;
466     }
467 
468     public OrgGroupRole findByGroupId_First(long groupId, OrderByComparator obc)
469         throws NoSuchOrgGroupRoleException, SystemException {
470         List<OrgGroupRole> list = findByGroupId(groupId, 0, 1, obc);
471 
472         if (list.isEmpty()) {
473             StringBundler msg = new StringBundler(4);
474 
475             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
476 
477             msg.append("groupId=");
478             msg.append(groupId);
479 
480             msg.append(StringPool.CLOSE_CURLY_BRACE);
481 
482             throw new NoSuchOrgGroupRoleException(msg.toString());
483         }
484         else {
485             return list.get(0);
486         }
487     }
488 
489     public OrgGroupRole findByGroupId_Last(long groupId, OrderByComparator obc)
490         throws NoSuchOrgGroupRoleException, SystemException {
491         int count = countByGroupId(groupId);
492 
493         List<OrgGroupRole> list = findByGroupId(groupId, count - 1, count, obc);
494 
495         if (list.isEmpty()) {
496             StringBundler msg = new StringBundler(4);
497 
498             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
499 
500             msg.append("groupId=");
501             msg.append(groupId);
502 
503             msg.append(StringPool.CLOSE_CURLY_BRACE);
504 
505             throw new NoSuchOrgGroupRoleException(msg.toString());
506         }
507         else {
508             return list.get(0);
509         }
510     }
511 
512     public OrgGroupRole[] findByGroupId_PrevAndNext(
513         OrgGroupRolePK orgGroupRolePK, long groupId, OrderByComparator obc)
514         throws NoSuchOrgGroupRoleException, SystemException {
515         OrgGroupRole orgGroupRole = findByPrimaryKey(orgGroupRolePK);
516 
517         int count = countByGroupId(groupId);
518 
519         Session session = null;
520 
521         try {
522             session = openSession();
523 
524             StringBundler query = null;
525 
526             if (obc != null) {
527                 query = new StringBundler(3 +
528                         (obc.getOrderByFields().length * 3));
529             }
530             else {
531                 query = new StringBundler(2);
532             }
533 
534             query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
535 
536             query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
537 
538             if (obc != null) {
539                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
540             }
541 
542             String sql = query.toString();
543 
544             Query q = session.createQuery(sql);
545 
546             QueryPos qPos = QueryPos.getInstance(q);
547 
548             qPos.add(groupId);
549 
550             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
551                     orgGroupRole);
552 
553             OrgGroupRole[] array = new OrgGroupRoleImpl[3];
554 
555             array[0] = (OrgGroupRole)objArray[0];
556             array[1] = (OrgGroupRole)objArray[1];
557             array[2] = (OrgGroupRole)objArray[2];
558 
559             return array;
560         }
561         catch (Exception e) {
562             throw processException(e);
563         }
564         finally {
565             closeSession(session);
566         }
567     }
568 
569     public List<OrgGroupRole> findByRoleId(long roleId)
570         throws SystemException {
571         Object[] finderArgs = new Object[] { new Long(roleId) };
572 
573         List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ROLEID,
574                 finderArgs, this);
575 
576         if (list == null) {
577             Session session = null;
578 
579             try {
580                 session = openSession();
581 
582                 StringBundler query = new StringBundler(2);
583 
584                 query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
585 
586                 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
587 
588                 String sql = query.toString();
589 
590                 Query q = session.createQuery(sql);
591 
592                 QueryPos qPos = QueryPos.getInstance(q);
593 
594                 qPos.add(roleId);
595 
596                 list = q.list();
597             }
598             catch (Exception e) {
599                 throw processException(e);
600             }
601             finally {
602                 if (list == null) {
603                     list = new ArrayList<OrgGroupRole>();
604                 }
605 
606                 cacheResult(list);
607 
608                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ROLEID,
609                     finderArgs, list);
610 
611                 closeSession(session);
612             }
613         }
614 
615         return list;
616     }
617 
618     public List<OrgGroupRole> findByRoleId(long roleId, int start, int end)
619         throws SystemException {
620         return findByRoleId(roleId, start, end, null);
621     }
622 
623     public List<OrgGroupRole> findByRoleId(long roleId, int start, int end,
624         OrderByComparator obc) throws SystemException {
625         Object[] finderArgs = new Object[] {
626                 new Long(roleId),
627                 
628                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
629             };
630 
631         List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_ROLEID,
632                 finderArgs, this);
633 
634         if (list == null) {
635             Session session = null;
636 
637             try {
638                 session = openSession();
639 
640                 StringBundler query = null;
641 
642                 if (obc != null) {
643                     query = new StringBundler(3 +
644                             (obc.getOrderByFields().length * 3));
645                 }
646                 else {
647                     query = new StringBundler(2);
648                 }
649 
650                 query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
651 
652                 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
653 
654                 if (obc != null) {
655                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
656                 }
657 
658                 String sql = query.toString();
659 
660                 Query q = session.createQuery(sql);
661 
662                 QueryPos qPos = QueryPos.getInstance(q);
663 
664                 qPos.add(roleId);
665 
666                 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
667                         start, end);
668             }
669             catch (Exception e) {
670                 throw processException(e);
671             }
672             finally {
673                 if (list == null) {
674                     list = new ArrayList<OrgGroupRole>();
675                 }
676 
677                 cacheResult(list);
678 
679                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_ROLEID,
680                     finderArgs, list);
681 
682                 closeSession(session);
683             }
684         }
685 
686         return list;
687     }
688 
689     public OrgGroupRole findByRoleId_First(long roleId, OrderByComparator obc)
690         throws NoSuchOrgGroupRoleException, SystemException {
691         List<OrgGroupRole> list = findByRoleId(roleId, 0, 1, obc);
692 
693         if (list.isEmpty()) {
694             StringBundler msg = new StringBundler(4);
695 
696             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
697 
698             msg.append("roleId=");
699             msg.append(roleId);
700 
701             msg.append(StringPool.CLOSE_CURLY_BRACE);
702 
703             throw new NoSuchOrgGroupRoleException(msg.toString());
704         }
705         else {
706             return list.get(0);
707         }
708     }
709 
710     public OrgGroupRole findByRoleId_Last(long roleId, OrderByComparator obc)
711         throws NoSuchOrgGroupRoleException, SystemException {
712         int count = countByRoleId(roleId);
713 
714         List<OrgGroupRole> list = findByRoleId(roleId, count - 1, count, obc);
715 
716         if (list.isEmpty()) {
717             StringBundler msg = new StringBundler(4);
718 
719             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
720 
721             msg.append("roleId=");
722             msg.append(roleId);
723 
724             msg.append(StringPool.CLOSE_CURLY_BRACE);
725 
726             throw new NoSuchOrgGroupRoleException(msg.toString());
727         }
728         else {
729             return list.get(0);
730         }
731     }
732 
733     public OrgGroupRole[] findByRoleId_PrevAndNext(
734         OrgGroupRolePK orgGroupRolePK, long roleId, OrderByComparator obc)
735         throws NoSuchOrgGroupRoleException, SystemException {
736         OrgGroupRole orgGroupRole = findByPrimaryKey(orgGroupRolePK);
737 
738         int count = countByRoleId(roleId);
739 
740         Session session = null;
741 
742         try {
743             session = openSession();
744 
745             StringBundler query = null;
746 
747             if (obc != null) {
748                 query = new StringBundler(3 +
749                         (obc.getOrderByFields().length * 3));
750             }
751             else {
752                 query = new StringBundler(2);
753             }
754 
755             query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
756 
757             query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
758 
759             if (obc != null) {
760                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
761             }
762 
763             String sql = query.toString();
764 
765             Query q = session.createQuery(sql);
766 
767             QueryPos qPos = QueryPos.getInstance(q);
768 
769             qPos.add(roleId);
770 
771             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
772                     orgGroupRole);
773 
774             OrgGroupRole[] array = new OrgGroupRoleImpl[3];
775 
776             array[0] = (OrgGroupRole)objArray[0];
777             array[1] = (OrgGroupRole)objArray[1];
778             array[2] = (OrgGroupRole)objArray[2];
779 
780             return array;
781         }
782         catch (Exception e) {
783             throw processException(e);
784         }
785         finally {
786             closeSession(session);
787         }
788     }
789 
790     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
791         throws SystemException {
792         Session session = null;
793 
794         try {
795             session = openSession();
796 
797             dynamicQuery.compile(session);
798 
799             return dynamicQuery.list();
800         }
801         catch (Exception e) {
802             throw processException(e);
803         }
804         finally {
805             closeSession(session);
806         }
807     }
808 
809     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
810         int start, int end) throws SystemException {
811         Session session = null;
812 
813         try {
814             session = openSession();
815 
816             dynamicQuery.setLimit(start, end);
817 
818             dynamicQuery.compile(session);
819 
820             return dynamicQuery.list();
821         }
822         catch (Exception e) {
823             throw processException(e);
824         }
825         finally {
826             closeSession(session);
827         }
828     }
829 
830     public List<OrgGroupRole> findAll() throws SystemException {
831         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
832     }
833 
834     public List<OrgGroupRole> findAll(int start, int end)
835         throws SystemException {
836         return findAll(start, end, null);
837     }
838 
839     public List<OrgGroupRole> findAll(int start, int end, OrderByComparator obc)
840         throws SystemException {
841         Object[] finderArgs = new Object[] {
842                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
843             };
844 
845         List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
846                 finderArgs, this);
847 
848         if (list == null) {
849             Session session = null;
850 
851             try {
852                 session = openSession();
853 
854                 StringBundler query = null;
855                 String sql = null;
856 
857                 if (obc != null) {
858                     query = new StringBundler(2 +
859                             (obc.getOrderByFields().length * 3));
860 
861                     query.append(_SQL_SELECT_ORGGROUPROLE);
862 
863                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
864 
865                     sql = query.toString();
866                 }
867 
868                 sql = _SQL_SELECT_ORGGROUPROLE;
869 
870                 Query q = session.createQuery(sql);
871 
872                 if (obc == null) {
873                     list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
874                             start, end, false);
875 
876                     Collections.sort(list);
877                 }
878                 else {
879                     list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
880                             start, end);
881                 }
882             }
883             catch (Exception e) {
884                 throw processException(e);
885             }
886             finally {
887                 if (list == null) {
888                     list = new ArrayList<OrgGroupRole>();
889                 }
890 
891                 cacheResult(list);
892 
893                 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
894 
895                 closeSession(session);
896             }
897         }
898 
899         return list;
900     }
901 
902     public void removeByGroupId(long groupId) throws SystemException {
903         for (OrgGroupRole orgGroupRole : findByGroupId(groupId)) {
904             remove(orgGroupRole);
905         }
906     }
907 
908     public void removeByRoleId(long roleId) throws SystemException {
909         for (OrgGroupRole orgGroupRole : findByRoleId(roleId)) {
910             remove(orgGroupRole);
911         }
912     }
913 
914     public void removeAll() throws SystemException {
915         for (OrgGroupRole orgGroupRole : findAll()) {
916             remove(orgGroupRole);
917         }
918     }
919 
920     public int countByGroupId(long groupId) throws SystemException {
921         Object[] finderArgs = new Object[] { new Long(groupId) };
922 
923         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
924                 finderArgs, this);
925 
926         if (count == null) {
927             Session session = null;
928 
929             try {
930                 session = openSession();
931 
932                 StringBundler query = new StringBundler(2);
933 
934                 query.append(_SQL_COUNT_ORGGROUPROLE_WHERE);
935 
936                 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
937 
938                 String sql = query.toString();
939 
940                 Query q = session.createQuery(sql);
941 
942                 QueryPos qPos = QueryPos.getInstance(q);
943 
944                 qPos.add(groupId);
945 
946                 count = (Long)q.uniqueResult();
947             }
948             catch (Exception e) {
949                 throw processException(e);
950             }
951             finally {
952                 if (count == null) {
953                     count = Long.valueOf(0);
954                 }
955 
956                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
957                     finderArgs, count);
958 
959                 closeSession(session);
960             }
961         }
962 
963         return count.intValue();
964     }
965 
966     public int countByRoleId(long roleId) throws SystemException {
967         Object[] finderArgs = new Object[] { new Long(roleId) };
968 
969         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ROLEID,
970                 finderArgs, this);
971 
972         if (count == null) {
973             Session session = null;
974 
975             try {
976                 session = openSession();
977 
978                 StringBundler query = new StringBundler(2);
979 
980                 query.append(_SQL_COUNT_ORGGROUPROLE_WHERE);
981 
982                 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
983 
984                 String sql = query.toString();
985 
986                 Query q = session.createQuery(sql);
987 
988                 QueryPos qPos = QueryPos.getInstance(q);
989 
990                 qPos.add(roleId);
991 
992                 count = (Long)q.uniqueResult();
993             }
994             catch (Exception e) {
995                 throw processException(e);
996             }
997             finally {
998                 if (count == null) {
999                     count = Long.valueOf(0);
1000                }
1001
1002                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROLEID,
1003                    finderArgs, count);
1004
1005                closeSession(session);
1006            }
1007        }
1008
1009        return count.intValue();
1010    }
1011
1012    public int countAll() throws SystemException {
1013        Object[] finderArgs = new Object[0];
1014
1015        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1016                finderArgs, this);
1017
1018        if (count == null) {
1019            Session session = null;
1020
1021            try {
1022                session = openSession();
1023
1024                Query q = session.createQuery(_SQL_COUNT_ORGGROUPROLE);
1025
1026                count = (Long)q.uniqueResult();
1027            }
1028            catch (Exception e) {
1029                throw processException(e);
1030            }
1031            finally {
1032                if (count == null) {
1033                    count = Long.valueOf(0);
1034                }
1035
1036                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1037                    count);
1038
1039                closeSession(session);
1040            }
1041        }
1042
1043        return count.intValue();
1044    }
1045
1046    public void afterPropertiesSet() {
1047        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1048                    com.liferay.portal.util.PropsUtil.get(
1049                        "value.object.listener.com.liferay.portal.model.OrgGroupRole")));
1050
1051        if (listenerClassNames.length > 0) {
1052            try {
1053                List<ModelListener<OrgGroupRole>> listenersList = new ArrayList<ModelListener<OrgGroupRole>>();
1054
1055                for (String listenerClassName : listenerClassNames) {
1056                    listenersList.add((ModelListener<OrgGroupRole>)Class.forName(
1057                            listenerClassName).newInstance());
1058                }
1059
1060                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1061            }
1062            catch (Exception e) {
1063                _log.error(e);
1064            }
1065        }
1066    }
1067
1068    @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence")
1069    protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
1070    @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence")
1071    protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
1072    @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence")
1073    protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
1074    @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence")
1075    protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
1076    @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence")
1077    protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
1078    @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence")
1079    protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
1080    @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence")
1081    protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
1082    @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence")
1083    protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
1084    @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence")
1085    protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
1086    @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence")
1087    protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
1088    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence")
1089    protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
1090    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence")
1091    protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
1092    @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence")
1093    protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
1094    @BeanReference(name = "com.liferay.portal.service.persistence.LockPersistence")
1095    protected com.liferay.portal.service.persistence.LockPersistence lockPersistence;
1096    @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence")
1097    protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
1098    @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence")
1099    protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
1100    @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence")
1101    protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1102    @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence")
1103    protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
1104    @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence")
1105    protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
1106    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence")
1107    protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
1108    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence")
1109    protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1110    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence")
1111    protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
1112    @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence")
1113    protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
1114    @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence")
1115    protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
1116    @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence")
1117    protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
1118    @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence")
1119    protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
1120    @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence")
1121    protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
1122    @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence")
1123    protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
1124    @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence")
1125    protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
1126    @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence")
1127    protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
1128    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence")
1129    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1130    @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence")
1131    protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
1132    @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence")
1133    protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
1134    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence")
1135    protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
1136    @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence")
1137    protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
1138    @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence")
1139    protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
1140    @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence")
1141    protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
1142    @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence")
1143    protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
1144    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence")
1145    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1146    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence")
1147    protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
1148    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupGroupRolePersistence")
1149    protected com.liferay.portal.service.persistence.UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1150    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence")
1151    protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
1152    @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence")
1153    protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
1154    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence")
1155    protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
1156    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence")
1157    protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
1158    @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence")
1159    protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
1160    @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence")
1161    protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
1162    private static final String _SQL_SELECT_ORGGROUPROLE = "SELECT orgGroupRole FROM OrgGroupRole orgGroupRole";
1163    private static final String _SQL_SELECT_ORGGROUPROLE_WHERE = "SELECT orgGroupRole FROM OrgGroupRole orgGroupRole WHERE ";
1164    private static final String _SQL_COUNT_ORGGROUPROLE = "SELECT COUNT(orgGroupRole) FROM OrgGroupRole orgGroupRole";
1165    private static final String _SQL_COUNT_ORGGROUPROLE_WHERE = "SELECT COUNT(orgGroupRole) FROM OrgGroupRole orgGroupRole WHERE ";
1166    private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "orgGroupRole.id.groupId = ?";
1167    private static final String _FINDER_COLUMN_ROLEID_ROLEID_2 = "orgGroupRole.id.roleId = ?";
1168    private static final String _ORDER_BY_ENTITY_ALIAS = "orgGroupRole.";
1169    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No OrgGroupRole exists with the primary key ";
1170    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No OrgGroupRole exists with the key {";
1171    private static Log _log = LogFactoryUtil.getLog(OrgGroupRolePersistenceImpl.class);
1172}