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