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