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