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