001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.NoSuchPermissionException;
019    import com.liferay.portal.kernel.annotation.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
022    import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
023    import com.liferay.portal.kernel.dao.jdbc.RowMapper;
024    import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
025    import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
026    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
027    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
028    import com.liferay.portal.kernel.dao.orm.FinderPath;
029    import com.liferay.portal.kernel.dao.orm.Query;
030    import com.liferay.portal.kernel.dao.orm.QueryPos;
031    import com.liferay.portal.kernel.dao.orm.QueryUtil;
032    import com.liferay.portal.kernel.dao.orm.SQLQuery;
033    import com.liferay.portal.kernel.dao.orm.Session;
034    import com.liferay.portal.kernel.exception.SystemException;
035    import com.liferay.portal.kernel.log.Log;
036    import com.liferay.portal.kernel.log.LogFactoryUtil;
037    import com.liferay.portal.kernel.util.GetterUtil;
038    import com.liferay.portal.kernel.util.InstanceFactory;
039    import com.liferay.portal.kernel.util.OrderByComparator;
040    import com.liferay.portal.kernel.util.SetUtil;
041    import com.liferay.portal.kernel.util.StringBundler;
042    import com.liferay.portal.kernel.util.StringPool;
043    import com.liferay.portal.kernel.util.StringUtil;
044    import com.liferay.portal.kernel.util.Validator;
045    import com.liferay.portal.model.ModelListener;
046    import com.liferay.portal.model.Permission;
047    import com.liferay.portal.model.impl.PermissionImpl;
048    import com.liferay.portal.model.impl.PermissionModelImpl;
049    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
050    
051    import java.io.Serializable;
052    
053    import java.util.ArrayList;
054    import java.util.Collections;
055    import java.util.List;
056    import java.util.Set;
057    
058    /**
059     * @author    Brian Wing Shun Chan
060     * @see       PermissionPersistence
061     * @see       PermissionUtil
062     * @generated
063     */
064    public class PermissionPersistenceImpl extends BasePersistenceImpl<Permission>
065            implements PermissionPersistence {
066            public static final String FINDER_CLASS_NAME_ENTITY = PermissionImpl.class.getName();
067            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
068                    ".List";
069            public static final FinderPath FINDER_PATH_FIND_BY_RESOURCEID = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
070                            PermissionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
071                            "findByResourceId",
072                            new String[] {
073                                    Long.class.getName(),
074                                    
075                            "java.lang.Integer", "java.lang.Integer",
076                                    "com.liferay.portal.kernel.util.OrderByComparator"
077                            });
078            public static final FinderPath FINDER_PATH_COUNT_BY_RESOURCEID = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
079                            PermissionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
080                            "countByResourceId", new String[] { Long.class.getName() });
081            public static final FinderPath FINDER_PATH_FETCH_BY_A_R = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
082                            PermissionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
083                            "fetchByA_R",
084                            new String[] { String.class.getName(), Long.class.getName() });
085            public static final FinderPath FINDER_PATH_COUNT_BY_A_R = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
086                            PermissionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
087                            "countByA_R",
088                            new String[] { String.class.getName(), Long.class.getName() });
089            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
090                            PermissionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
091                            "findAll", new String[0]);
092            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
093                            PermissionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
094                            "countAll", new String[0]);
095    
096            public void cacheResult(Permission permission) {
097                    EntityCacheUtil.putResult(PermissionModelImpl.ENTITY_CACHE_ENABLED,
098                            PermissionImpl.class, permission.getPrimaryKey(), permission);
099    
100                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A_R,
101                            new Object[] {
102                                    permission.getActionId(), new Long(permission.getResourceId())
103                            }, permission);
104            }
105    
106            public void cacheResult(List<Permission> permissions) {
107                    for (Permission permission : permissions) {
108                            if (EntityCacheUtil.getResult(
109                                                    PermissionModelImpl.ENTITY_CACHE_ENABLED,
110                                                    PermissionImpl.class, permission.getPrimaryKey(), this) == null) {
111                                    cacheResult(permission);
112                            }
113                    }
114            }
115    
116            public void clearCache() {
117                    CacheRegistryUtil.clear(PermissionImpl.class.getName());
118                    EntityCacheUtil.clearCache(PermissionImpl.class.getName());
119                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
120                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
121            }
122    
123            public void clearCache(Permission permission) {
124                    EntityCacheUtil.removeResult(PermissionModelImpl.ENTITY_CACHE_ENABLED,
125                            PermissionImpl.class, permission.getPrimaryKey());
126    
127                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A_R,
128                            new Object[] {
129                                    permission.getActionId(), new Long(permission.getResourceId())
130                            });
131            }
132    
133            public Permission create(long permissionId) {
134                    Permission permission = new PermissionImpl();
135    
136                    permission.setNew(true);
137                    permission.setPrimaryKey(permissionId);
138    
139                    return permission;
140            }
141    
142            public Permission remove(Serializable primaryKey)
143                    throws NoSuchModelException, SystemException {
144                    return remove(((Long)primaryKey).longValue());
145            }
146    
147            public Permission remove(long permissionId)
148                    throws NoSuchPermissionException, SystemException {
149                    Session session = null;
150    
151                    try {
152                            session = openSession();
153    
154                            Permission permission = (Permission)session.get(PermissionImpl.class,
155                                            new Long(permissionId));
156    
157                            if (permission == null) {
158                                    if (_log.isWarnEnabled()) {
159                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + permissionId);
160                                    }
161    
162                                    throw new NoSuchPermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
163                                            permissionId);
164                            }
165    
166                            return remove(permission);
167                    }
168                    catch (NoSuchPermissionException nsee) {
169                            throw nsee;
170                    }
171                    catch (Exception e) {
172                            throw processException(e);
173                    }
174                    finally {
175                            closeSession(session);
176                    }
177            }
178    
179            protected Permission removeImpl(Permission permission)
180                    throws SystemException {
181                    permission = toUnwrappedModel(permission);
182    
183                    try {
184                            clearGroups.clear(permission.getPrimaryKey());
185                    }
186                    catch (Exception e) {
187                            throw processException(e);
188                    }
189                    finally {
190                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
191                    }
192    
193                    try {
194                            clearRoles.clear(permission.getPrimaryKey());
195                    }
196                    catch (Exception e) {
197                            throw processException(e);
198                    }
199                    finally {
200                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
201                    }
202    
203                    try {
204                            clearUsers.clear(permission.getPrimaryKey());
205                    }
206                    catch (Exception e) {
207                            throw processException(e);
208                    }
209                    finally {
210                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
211                    }
212    
213                    Session session = null;
214    
215                    try {
216                            session = openSession();
217    
218                            if (permission.isCachedModel() || BatchSessionUtil.isEnabled()) {
219                                    Object staleObject = session.get(PermissionImpl.class,
220                                                    permission.getPrimaryKeyObj());
221    
222                                    if (staleObject != null) {
223                                            session.evict(staleObject);
224                                    }
225                            }
226    
227                            session.delete(permission);
228    
229                            session.flush();
230                    }
231                    catch (Exception e) {
232                            throw processException(e);
233                    }
234                    finally {
235                            closeSession(session);
236                    }
237    
238                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
239    
240                    PermissionModelImpl permissionModelImpl = (PermissionModelImpl)permission;
241    
242                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A_R,
243                            new Object[] {
244                                    permissionModelImpl.getOriginalActionId(),
245                                    new Long(permissionModelImpl.getOriginalResourceId())
246                            });
247    
248                    EntityCacheUtil.removeResult(PermissionModelImpl.ENTITY_CACHE_ENABLED,
249                            PermissionImpl.class, permission.getPrimaryKey());
250    
251                    return permission;
252            }
253    
254            public Permission updateImpl(
255                    com.liferay.portal.model.Permission permission, boolean merge)
256                    throws SystemException {
257                    permission = toUnwrappedModel(permission);
258    
259                    boolean isNew = permission.isNew();
260    
261                    PermissionModelImpl permissionModelImpl = (PermissionModelImpl)permission;
262    
263                    Session session = null;
264    
265                    try {
266                            session = openSession();
267    
268                            BatchSessionUtil.update(session, permission, merge);
269    
270                            permission.setNew(false);
271                    }
272                    catch (Exception e) {
273                            throw processException(e);
274                    }
275                    finally {
276                            closeSession(session);
277                    }
278    
279                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
280    
281                    EntityCacheUtil.putResult(PermissionModelImpl.ENTITY_CACHE_ENABLED,
282                            PermissionImpl.class, permission.getPrimaryKey(), permission);
283    
284                    if (!isNew &&
285                                    (!Validator.equals(permission.getActionId(),
286                                            permissionModelImpl.getOriginalActionId()) ||
287                                    (permission.getResourceId() != permissionModelImpl.getOriginalResourceId()))) {
288                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A_R,
289                                    new Object[] {
290                                            permissionModelImpl.getOriginalActionId(),
291                                            new Long(permissionModelImpl.getOriginalResourceId())
292                                    });
293                    }
294    
295                    if (isNew ||
296                                    (!Validator.equals(permission.getActionId(),
297                                            permissionModelImpl.getOriginalActionId()) ||
298                                    (permission.getResourceId() != permissionModelImpl.getOriginalResourceId()))) {
299                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A_R,
300                                    new Object[] {
301                                            permission.getActionId(),
302                                            new Long(permission.getResourceId())
303                                    }, permission);
304                    }
305    
306                    return permission;
307            }
308    
309            protected Permission toUnwrappedModel(Permission permission) {
310                    if (permission instanceof PermissionImpl) {
311                            return permission;
312                    }
313    
314                    PermissionImpl permissionImpl = new PermissionImpl();
315    
316                    permissionImpl.setNew(permission.isNew());
317                    permissionImpl.setPrimaryKey(permission.getPrimaryKey());
318    
319                    permissionImpl.setPermissionId(permission.getPermissionId());
320                    permissionImpl.setCompanyId(permission.getCompanyId());
321                    permissionImpl.setActionId(permission.getActionId());
322                    permissionImpl.setResourceId(permission.getResourceId());
323    
324                    return permissionImpl;
325            }
326    
327            public Permission findByPrimaryKey(Serializable primaryKey)
328                    throws NoSuchModelException, SystemException {
329                    return findByPrimaryKey(((Long)primaryKey).longValue());
330            }
331    
332            public Permission findByPrimaryKey(long permissionId)
333                    throws NoSuchPermissionException, SystemException {
334                    Permission permission = fetchByPrimaryKey(permissionId);
335    
336                    if (permission == null) {
337                            if (_log.isWarnEnabled()) {
338                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + permissionId);
339                            }
340    
341                            throw new NoSuchPermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
342                                    permissionId);
343                    }
344    
345                    return permission;
346            }
347    
348            public Permission fetchByPrimaryKey(Serializable primaryKey)
349                    throws SystemException {
350                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
351            }
352    
353            public Permission fetchByPrimaryKey(long permissionId)
354                    throws SystemException {
355                    Permission permission = (Permission)EntityCacheUtil.getResult(PermissionModelImpl.ENTITY_CACHE_ENABLED,
356                                    PermissionImpl.class, permissionId, this);
357    
358                    if (permission == null) {
359                            Session session = null;
360    
361                            try {
362                                    session = openSession();
363    
364                                    permission = (Permission)session.get(PermissionImpl.class,
365                                                    new Long(permissionId));
366                            }
367                            catch (Exception e) {
368                                    throw processException(e);
369                            }
370                            finally {
371                                    if (permission != null) {
372                                            cacheResult(permission);
373                                    }
374    
375                                    closeSession(session);
376                            }
377                    }
378    
379                    return permission;
380            }
381    
382            public List<Permission> findByResourceId(long resourceId)
383                    throws SystemException {
384                    return findByResourceId(resourceId, QueryUtil.ALL_POS,
385                            QueryUtil.ALL_POS, null);
386            }
387    
388            public List<Permission> findByResourceId(long resourceId, int start, int end)
389                    throws SystemException {
390                    return findByResourceId(resourceId, start, end, null);
391            }
392    
393            public List<Permission> findByResourceId(long resourceId, int start,
394                    int end, OrderByComparator orderByComparator) throws SystemException {
395                    Object[] finderArgs = new Object[] {
396                                    resourceId,
397                                    
398                                    String.valueOf(start), String.valueOf(end),
399                                    String.valueOf(orderByComparator)
400                            };
401    
402                    List<Permission> list = (List<Permission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_RESOURCEID,
403                                    finderArgs, this);
404    
405                    if (list == null) {
406                            Session session = null;
407    
408                            try {
409                                    session = openSession();
410    
411                                    StringBundler query = null;
412    
413                                    if (orderByComparator != null) {
414                                            query = new StringBundler(3 +
415                                                            (orderByComparator.getOrderByFields().length * 3));
416                                    }
417                                    else {
418                                            query = new StringBundler(2);
419                                    }
420    
421                                    query.append(_SQL_SELECT_PERMISSION_WHERE);
422    
423                                    query.append(_FINDER_COLUMN_RESOURCEID_RESOURCEID_2);
424    
425                                    if (orderByComparator != null) {
426                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
427                                                    orderByComparator);
428                                    }
429    
430                                    String sql = query.toString();
431    
432                                    Query q = session.createQuery(sql);
433    
434                                    QueryPos qPos = QueryPos.getInstance(q);
435    
436                                    qPos.add(resourceId);
437    
438                                    list = (List<Permission>)QueryUtil.list(q, getDialect(), start,
439                                                    end);
440                            }
441                            catch (Exception e) {
442                                    throw processException(e);
443                            }
444                            finally {
445                                    if (list == null) {
446                                            list = new ArrayList<Permission>();
447                                    }
448    
449                                    cacheResult(list);
450    
451                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_RESOURCEID,
452                                            finderArgs, list);
453    
454                                    closeSession(session);
455                            }
456                    }
457    
458                    return list;
459            }
460    
461            public Permission findByResourceId_First(long resourceId,
462                    OrderByComparator orderByComparator)
463                    throws NoSuchPermissionException, SystemException {
464                    List<Permission> list = findByResourceId(resourceId, 0, 1,
465                                    orderByComparator);
466    
467                    if (list.isEmpty()) {
468                            StringBundler msg = new StringBundler(4);
469    
470                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
471    
472                            msg.append("resourceId=");
473                            msg.append(resourceId);
474    
475                            msg.append(StringPool.CLOSE_CURLY_BRACE);
476    
477                            throw new NoSuchPermissionException(msg.toString());
478                    }
479                    else {
480                            return list.get(0);
481                    }
482            }
483    
484            public Permission findByResourceId_Last(long resourceId,
485                    OrderByComparator orderByComparator)
486                    throws NoSuchPermissionException, SystemException {
487                    int count = countByResourceId(resourceId);
488    
489                    List<Permission> list = findByResourceId(resourceId, count - 1, count,
490                                    orderByComparator);
491    
492                    if (list.isEmpty()) {
493                            StringBundler msg = new StringBundler(4);
494    
495                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
496    
497                            msg.append("resourceId=");
498                            msg.append(resourceId);
499    
500                            msg.append(StringPool.CLOSE_CURLY_BRACE);
501    
502                            throw new NoSuchPermissionException(msg.toString());
503                    }
504                    else {
505                            return list.get(0);
506                    }
507            }
508    
509            public Permission[] findByResourceId_PrevAndNext(long permissionId,
510                    long resourceId, OrderByComparator orderByComparator)
511                    throws NoSuchPermissionException, SystemException {
512                    Permission permission = findByPrimaryKey(permissionId);
513    
514                    Session session = null;
515    
516                    try {
517                            session = openSession();
518    
519                            Permission[] array = new PermissionImpl[3];
520    
521                            array[0] = getByResourceId_PrevAndNext(session, permission,
522                                            resourceId, orderByComparator, true);
523    
524                            array[1] = permission;
525    
526                            array[2] = getByResourceId_PrevAndNext(session, permission,
527                                            resourceId, orderByComparator, false);
528    
529                            return array;
530                    }
531                    catch (Exception e) {
532                            throw processException(e);
533                    }
534                    finally {
535                            closeSession(session);
536                    }
537            }
538    
539            protected Permission getByResourceId_PrevAndNext(Session session,
540                    Permission permission, long resourceId,
541                    OrderByComparator orderByComparator, boolean previous) {
542                    StringBundler query = null;
543    
544                    if (orderByComparator != null) {
545                            query = new StringBundler(6 +
546                                            (orderByComparator.getOrderByFields().length * 6));
547                    }
548                    else {
549                            query = new StringBundler(3);
550                    }
551    
552                    query.append(_SQL_SELECT_PERMISSION_WHERE);
553    
554                    query.append(_FINDER_COLUMN_RESOURCEID_RESOURCEID_2);
555    
556                    if (orderByComparator != null) {
557                            String[] orderByFields = orderByComparator.getOrderByFields();
558    
559                            if (orderByFields.length > 0) {
560                                    query.append(WHERE_AND);
561                            }
562    
563                            for (int i = 0; i < orderByFields.length; i++) {
564                                    query.append(_ORDER_BY_ENTITY_ALIAS);
565                                    query.append(orderByFields[i]);
566    
567                                    if ((i + 1) < orderByFields.length) {
568                                            if (orderByComparator.isAscending() ^ previous) {
569                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
570                                            }
571                                            else {
572                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
573                                            }
574                                    }
575                                    else {
576                                            if (orderByComparator.isAscending() ^ previous) {
577                                                    query.append(WHERE_GREATER_THAN);
578                                            }
579                                            else {
580                                                    query.append(WHERE_LESSER_THAN);
581                                            }
582                                    }
583                            }
584    
585                            query.append(ORDER_BY_CLAUSE);
586    
587                            for (int i = 0; i < orderByFields.length; i++) {
588                                    query.append(_ORDER_BY_ENTITY_ALIAS);
589                                    query.append(orderByFields[i]);
590    
591                                    if ((i + 1) < orderByFields.length) {
592                                            if (orderByComparator.isAscending() ^ previous) {
593                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
594                                            }
595                                            else {
596                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
597                                            }
598                                    }
599                                    else {
600                                            if (orderByComparator.isAscending() ^ previous) {
601                                                    query.append(ORDER_BY_ASC);
602                                            }
603                                            else {
604                                                    query.append(ORDER_BY_DESC);
605                                            }
606                                    }
607                            }
608                    }
609    
610                    String sql = query.toString();
611    
612                    Query q = session.createQuery(sql);
613    
614                    q.setFirstResult(0);
615                    q.setMaxResults(2);
616    
617                    QueryPos qPos = QueryPos.getInstance(q);
618    
619                    qPos.add(resourceId);
620    
621                    if (orderByComparator != null) {
622                            Object[] values = orderByComparator.getOrderByValues(permission);
623    
624                            for (Object value : values) {
625                                    qPos.add(value);
626                            }
627                    }
628    
629                    List<Permission> list = q.list();
630    
631                    if (list.size() == 2) {
632                            return list.get(1);
633                    }
634                    else {
635                            return null;
636                    }
637            }
638    
639            public Permission findByA_R(String actionId, long resourceId)
640                    throws NoSuchPermissionException, SystemException {
641                    Permission permission = fetchByA_R(actionId, resourceId);
642    
643                    if (permission == null) {
644                            StringBundler msg = new StringBundler(6);
645    
646                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
647    
648                            msg.append("actionId=");
649                            msg.append(actionId);
650    
651                            msg.append(", resourceId=");
652                            msg.append(resourceId);
653    
654                            msg.append(StringPool.CLOSE_CURLY_BRACE);
655    
656                            if (_log.isWarnEnabled()) {
657                                    _log.warn(msg.toString());
658                            }
659    
660                            throw new NoSuchPermissionException(msg.toString());
661                    }
662    
663                    return permission;
664            }
665    
666            public Permission fetchByA_R(String actionId, long resourceId)
667                    throws SystemException {
668                    return fetchByA_R(actionId, resourceId, true);
669            }
670    
671            public Permission fetchByA_R(String actionId, long resourceId,
672                    boolean retrieveFromCache) throws SystemException {
673                    Object[] finderArgs = new Object[] { actionId, resourceId };
674    
675                    Object result = null;
676    
677                    if (retrieveFromCache) {
678                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_A_R,
679                                            finderArgs, this);
680                    }
681    
682                    if (result == null) {
683                            Session session = null;
684    
685                            try {
686                                    session = openSession();
687    
688                                    StringBundler query = new StringBundler(3);
689    
690                                    query.append(_SQL_SELECT_PERMISSION_WHERE);
691    
692                                    if (actionId == null) {
693                                            query.append(_FINDER_COLUMN_A_R_ACTIONID_1);
694                                    }
695                                    else {
696                                            if (actionId.equals(StringPool.BLANK)) {
697                                                    query.append(_FINDER_COLUMN_A_R_ACTIONID_3);
698                                            }
699                                            else {
700                                                    query.append(_FINDER_COLUMN_A_R_ACTIONID_2);
701                                            }
702                                    }
703    
704                                    query.append(_FINDER_COLUMN_A_R_RESOURCEID_2);
705    
706                                    String sql = query.toString();
707    
708                                    Query q = session.createQuery(sql);
709    
710                                    QueryPos qPos = QueryPos.getInstance(q);
711    
712                                    if (actionId != null) {
713                                            qPos.add(actionId);
714                                    }
715    
716                                    qPos.add(resourceId);
717    
718                                    List<Permission> list = q.list();
719    
720                                    result = list;
721    
722                                    Permission permission = null;
723    
724                                    if (list.isEmpty()) {
725                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A_R,
726                                                    finderArgs, list);
727                                    }
728                                    else {
729                                            permission = list.get(0);
730    
731                                            cacheResult(permission);
732    
733                                            if ((permission.getActionId() == null) ||
734                                                            !permission.getActionId().equals(actionId) ||
735                                                            (permission.getResourceId() != resourceId)) {
736                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A_R,
737                                                            finderArgs, permission);
738                                            }
739                                    }
740    
741                                    return permission;
742                            }
743                            catch (Exception e) {
744                                    throw processException(e);
745                            }
746                            finally {
747                                    if (result == null) {
748                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A_R,
749                                                    finderArgs, new ArrayList<Permission>());
750                                    }
751    
752                                    closeSession(session);
753                            }
754                    }
755                    else {
756                            if (result instanceof List<?>) {
757                                    return null;
758                            }
759                            else {
760                                    return (Permission)result;
761                            }
762                    }
763            }
764    
765            public List<Permission> findAll() throws SystemException {
766                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
767            }
768    
769            public List<Permission> findAll(int start, int end)
770                    throws SystemException {
771                    return findAll(start, end, null);
772            }
773    
774            public List<Permission> findAll(int start, int end,
775                    OrderByComparator orderByComparator) throws SystemException {
776                    Object[] finderArgs = new Object[] {
777                                    String.valueOf(start), String.valueOf(end),
778                                    String.valueOf(orderByComparator)
779                            };
780    
781                    List<Permission> list = (List<Permission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
782                                    finderArgs, this);
783    
784                    if (list == null) {
785                            Session session = null;
786    
787                            try {
788                                    session = openSession();
789    
790                                    StringBundler query = null;
791                                    String sql = null;
792    
793                                    if (orderByComparator != null) {
794                                            query = new StringBundler(2 +
795                                                            (orderByComparator.getOrderByFields().length * 3));
796    
797                                            query.append(_SQL_SELECT_PERMISSION);
798    
799                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
800                                                    orderByComparator);
801    
802                                            sql = query.toString();
803                                    }
804                                    else {
805                                            sql = _SQL_SELECT_PERMISSION;
806                                    }
807    
808                                    Query q = session.createQuery(sql);
809    
810                                    if (orderByComparator == null) {
811                                            list = (List<Permission>)QueryUtil.list(q, getDialect(),
812                                                            start, end, false);
813    
814                                            Collections.sort(list);
815                                    }
816                                    else {
817                                            list = (List<Permission>)QueryUtil.list(q, getDialect(),
818                                                            start, end);
819                                    }
820                            }
821                            catch (Exception e) {
822                                    throw processException(e);
823                            }
824                            finally {
825                                    if (list == null) {
826                                            list = new ArrayList<Permission>();
827                                    }
828    
829                                    cacheResult(list);
830    
831                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
832    
833                                    closeSession(session);
834                            }
835                    }
836    
837                    return list;
838            }
839    
840            public void removeByResourceId(long resourceId) throws SystemException {
841                    for (Permission permission : findByResourceId(resourceId)) {
842                            remove(permission);
843                    }
844            }
845    
846            public void removeByA_R(String actionId, long resourceId)
847                    throws NoSuchPermissionException, SystemException {
848                    Permission permission = findByA_R(actionId, resourceId);
849    
850                    remove(permission);
851            }
852    
853            public void removeAll() throws SystemException {
854                    for (Permission permission : findAll()) {
855                            remove(permission);
856                    }
857            }
858    
859            public int countByResourceId(long resourceId) throws SystemException {
860                    Object[] finderArgs = new Object[] { resourceId };
861    
862                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_RESOURCEID,
863                                    finderArgs, this);
864    
865                    if (count == null) {
866                            Session session = null;
867    
868                            try {
869                                    session = openSession();
870    
871                                    StringBundler query = new StringBundler(2);
872    
873                                    query.append(_SQL_COUNT_PERMISSION_WHERE);
874    
875                                    query.append(_FINDER_COLUMN_RESOURCEID_RESOURCEID_2);
876    
877                                    String sql = query.toString();
878    
879                                    Query q = session.createQuery(sql);
880    
881                                    QueryPos qPos = QueryPos.getInstance(q);
882    
883                                    qPos.add(resourceId);
884    
885                                    count = (Long)q.uniqueResult();
886                            }
887                            catch (Exception e) {
888                                    throw processException(e);
889                            }
890                            finally {
891                                    if (count == null) {
892                                            count = Long.valueOf(0);
893                                    }
894    
895                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_RESOURCEID,
896                                            finderArgs, count);
897    
898                                    closeSession(session);
899                            }
900                    }
901    
902                    return count.intValue();
903            }
904    
905            public int countByA_R(String actionId, long resourceId)
906                    throws SystemException {
907                    Object[] finderArgs = new Object[] { actionId, resourceId };
908    
909                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_A_R,
910                                    finderArgs, this);
911    
912                    if (count == null) {
913                            Session session = null;
914    
915                            try {
916                                    session = openSession();
917    
918                                    StringBundler query = new StringBundler(3);
919    
920                                    query.append(_SQL_COUNT_PERMISSION_WHERE);
921    
922                                    if (actionId == null) {
923                                            query.append(_FINDER_COLUMN_A_R_ACTIONID_1);
924                                    }
925                                    else {
926                                            if (actionId.equals(StringPool.BLANK)) {
927                                                    query.append(_FINDER_COLUMN_A_R_ACTIONID_3);
928                                            }
929                                            else {
930                                                    query.append(_FINDER_COLUMN_A_R_ACTIONID_2);
931                                            }
932                                    }
933    
934                                    query.append(_FINDER_COLUMN_A_R_RESOURCEID_2);
935    
936                                    String sql = query.toString();
937    
938                                    Query q = session.createQuery(sql);
939    
940                                    QueryPos qPos = QueryPos.getInstance(q);
941    
942                                    if (actionId != null) {
943                                            qPos.add(actionId);
944                                    }
945    
946                                    qPos.add(resourceId);
947    
948                                    count = (Long)q.uniqueResult();
949                            }
950                            catch (Exception e) {
951                                    throw processException(e);
952                            }
953                            finally {
954                                    if (count == null) {
955                                            count = Long.valueOf(0);
956                                    }
957    
958                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A_R, finderArgs,
959                                            count);
960    
961                                    closeSession(session);
962                            }
963                    }
964    
965                    return count.intValue();
966            }
967    
968            public int countAll() throws SystemException {
969                    Object[] finderArgs = new Object[0];
970    
971                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
972                                    finderArgs, this);
973    
974                    if (count == null) {
975                            Session session = null;
976    
977                            try {
978                                    session = openSession();
979    
980                                    Query q = session.createQuery(_SQL_COUNT_PERMISSION);
981    
982                                    count = (Long)q.uniqueResult();
983                            }
984                            catch (Exception e) {
985                                    throw processException(e);
986                            }
987                            finally {
988                                    if (count == null) {
989                                            count = Long.valueOf(0);
990                                    }
991    
992                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
993                                            count);
994    
995                                    closeSession(session);
996                            }
997                    }
998    
999                    return count.intValue();
1000            }
1001    
1002            public List<com.liferay.portal.model.Group> getGroups(long pk)
1003                    throws SystemException {
1004                    return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1005            }
1006    
1007            public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
1008                    int end) throws SystemException {
1009                    return getGroups(pk, start, end, null);
1010            }
1011    
1012            public static final FinderPath FINDER_PATH_GET_GROUPS = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1013                            PermissionModelImpl.FINDER_CACHE_ENABLED_GROUPS_PERMISSIONS,
1014                            PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME,
1015                            "getGroups",
1016                            new String[] {
1017                                    Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1018                                    "com.liferay.portal.kernel.util.OrderByComparator"
1019                            });
1020    
1021            public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
1022                    int end, OrderByComparator orderByComparator) throws SystemException {
1023                    Object[] finderArgs = new Object[] {
1024                                    pk, String.valueOf(start), String.valueOf(end),
1025                                    String.valueOf(orderByComparator)
1026                            };
1027    
1028                    List<com.liferay.portal.model.Group> list = (List<com.liferay.portal.model.Group>)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS,
1029                                    finderArgs, this);
1030    
1031                    if (list == null) {
1032                            Session session = null;
1033    
1034                            try {
1035                                    session = openSession();
1036    
1037                                    String sql = null;
1038    
1039                                    if (orderByComparator != null) {
1040                                            sql = _SQL_GETGROUPS.concat(ORDER_BY_CLAUSE)
1041                                                                                    .concat(orderByComparator.getOrderBy());
1042                                    }
1043                                    else {
1044                                            sql = _SQL_GETGROUPS.concat(com.liferay.portal.model.impl.GroupModelImpl.ORDER_BY_SQL);
1045                                    }
1046    
1047                                    SQLQuery q = session.createSQLQuery(sql);
1048    
1049                                    q.addEntity("Group_",
1050                                            com.liferay.portal.model.impl.GroupImpl.class);
1051    
1052                                    QueryPos qPos = QueryPos.getInstance(q);
1053    
1054                                    qPos.add(pk);
1055    
1056                                    list = (List<com.liferay.portal.model.Group>)QueryUtil.list(q,
1057                                                    getDialect(), start, end);
1058                            }
1059                            catch (Exception e) {
1060                                    throw processException(e);
1061                            }
1062                            finally {
1063                                    if (list == null) {
1064                                            list = new ArrayList<com.liferay.portal.model.Group>();
1065                                    }
1066    
1067                                    groupPersistence.cacheResult(list);
1068    
1069                                    FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS, finderArgs,
1070                                            list);
1071    
1072                                    closeSession(session);
1073                            }
1074                    }
1075    
1076                    return list;
1077            }
1078    
1079            public static final FinderPath FINDER_PATH_GET_GROUPS_SIZE = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1080                            PermissionModelImpl.FINDER_CACHE_ENABLED_GROUPS_PERMISSIONS,
1081                            PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME,
1082                            "getGroupsSize", new String[] { Long.class.getName() });
1083    
1084            public int getGroupsSize(long pk) throws SystemException {
1085                    Object[] finderArgs = new Object[] { pk };
1086    
1087                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS_SIZE,
1088                                    finderArgs, this);
1089    
1090                    if (count == null) {
1091                            Session session = null;
1092    
1093                            try {
1094                                    session = openSession();
1095    
1096                                    SQLQuery q = session.createSQLQuery(_SQL_GETGROUPSSIZE);
1097    
1098                                    q.addScalar(COUNT_COLUMN_NAME,
1099                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
1100    
1101                                    QueryPos qPos = QueryPos.getInstance(q);
1102    
1103                                    qPos.add(pk);
1104    
1105                                    count = (Long)q.uniqueResult();
1106                            }
1107                            catch (Exception e) {
1108                                    throw processException(e);
1109                            }
1110                            finally {
1111                                    if (count == null) {
1112                                            count = Long.valueOf(0);
1113                                    }
1114    
1115                                    FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS_SIZE,
1116                                            finderArgs, count);
1117    
1118                                    closeSession(session);
1119                            }
1120                    }
1121    
1122                    return count.intValue();
1123            }
1124    
1125            public static final FinderPath FINDER_PATH_CONTAINS_GROUP = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1126                            PermissionModelImpl.FINDER_CACHE_ENABLED_GROUPS_PERMISSIONS,
1127                            PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME,
1128                            "containsGroup",
1129                            new String[] { Long.class.getName(), Long.class.getName() });
1130    
1131            public boolean containsGroup(long pk, long groupPK)
1132                    throws SystemException {
1133                    Object[] finderArgs = new Object[] { pk, groupPK };
1134    
1135                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_GROUP,
1136                                    finderArgs, this);
1137    
1138                    if (value == null) {
1139                            try {
1140                                    value = Boolean.valueOf(containsGroup.contains(pk, groupPK));
1141                            }
1142                            catch (Exception e) {
1143                                    throw processException(e);
1144                            }
1145                            finally {
1146                                    if (value == null) {
1147                                            value = Boolean.FALSE;
1148                                    }
1149    
1150                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_GROUP,
1151                                            finderArgs, value);
1152                            }
1153                    }
1154    
1155                    return value.booleanValue();
1156            }
1157    
1158            public boolean containsGroups(long pk) throws SystemException {
1159                    if (getGroupsSize(pk) > 0) {
1160                            return true;
1161                    }
1162                    else {
1163                            return false;
1164                    }
1165            }
1166    
1167            public void addGroup(long pk, long groupPK) throws SystemException {
1168                    try {
1169                            addGroup.add(pk, groupPK);
1170                    }
1171                    catch (Exception e) {
1172                            throw processException(e);
1173                    }
1174                    finally {
1175                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1176                    }
1177            }
1178    
1179            public void addGroup(long pk, com.liferay.portal.model.Group group)
1180                    throws SystemException {
1181                    try {
1182                            addGroup.add(pk, group.getPrimaryKey());
1183                    }
1184                    catch (Exception e) {
1185                            throw processException(e);
1186                    }
1187                    finally {
1188                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1189                    }
1190            }
1191    
1192            public void addGroups(long pk, long[] groupPKs) throws SystemException {
1193                    try {
1194                            for (long groupPK : groupPKs) {
1195                                    addGroup.add(pk, groupPK);
1196                            }
1197                    }
1198                    catch (Exception e) {
1199                            throw processException(e);
1200                    }
1201                    finally {
1202                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1203                    }
1204            }
1205    
1206            public void addGroups(long pk, List<com.liferay.portal.model.Group> groups)
1207                    throws SystemException {
1208                    try {
1209                            for (com.liferay.portal.model.Group group : groups) {
1210                                    addGroup.add(pk, group.getPrimaryKey());
1211                            }
1212                    }
1213                    catch (Exception e) {
1214                            throw processException(e);
1215                    }
1216                    finally {
1217                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1218                    }
1219            }
1220    
1221            public void clearGroups(long pk) throws SystemException {
1222                    try {
1223                            clearGroups.clear(pk);
1224                    }
1225                    catch (Exception e) {
1226                            throw processException(e);
1227                    }
1228                    finally {
1229                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1230                    }
1231            }
1232    
1233            public void removeGroup(long pk, long groupPK) throws SystemException {
1234                    try {
1235                            removeGroup.remove(pk, groupPK);
1236                    }
1237                    catch (Exception e) {
1238                            throw processException(e);
1239                    }
1240                    finally {
1241                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1242                    }
1243            }
1244    
1245            public void removeGroup(long pk, com.liferay.portal.model.Group group)
1246                    throws SystemException {
1247                    try {
1248                            removeGroup.remove(pk, group.getPrimaryKey());
1249                    }
1250                    catch (Exception e) {
1251                            throw processException(e);
1252                    }
1253                    finally {
1254                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1255                    }
1256            }
1257    
1258            public void removeGroups(long pk, long[] groupPKs)
1259                    throws SystemException {
1260                    try {
1261                            for (long groupPK : groupPKs) {
1262                                    removeGroup.remove(pk, groupPK);
1263                            }
1264                    }
1265                    catch (Exception e) {
1266                            throw processException(e);
1267                    }
1268                    finally {
1269                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1270                    }
1271            }
1272    
1273            public void removeGroups(long pk,
1274                    List<com.liferay.portal.model.Group> groups) throws SystemException {
1275                    try {
1276                            for (com.liferay.portal.model.Group group : groups) {
1277                                    removeGroup.remove(pk, group.getPrimaryKey());
1278                            }
1279                    }
1280                    catch (Exception e) {
1281                            throw processException(e);
1282                    }
1283                    finally {
1284                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1285                    }
1286            }
1287    
1288            public void setGroups(long pk, long[] groupPKs) throws SystemException {
1289                    try {
1290                            Set<Long> groupPKSet = SetUtil.fromArray(groupPKs);
1291    
1292                            List<com.liferay.portal.model.Group> groups = getGroups(pk);
1293    
1294                            for (com.liferay.portal.model.Group group : groups) {
1295                                    if (!groupPKSet.contains(group.getPrimaryKey())) {
1296                                            removeGroup.remove(pk, group.getPrimaryKey());
1297                                    }
1298                                    else {
1299                                            groupPKSet.remove(group.getPrimaryKey());
1300                                    }
1301                            }
1302    
1303                            for (Long groupPK : groupPKSet) {
1304                                    addGroup.add(pk, groupPK);
1305                            }
1306                    }
1307                    catch (Exception e) {
1308                            throw processException(e);
1309                    }
1310                    finally {
1311                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1312                    }
1313            }
1314    
1315            public void setGroups(long pk, List<com.liferay.portal.model.Group> groups)
1316                    throws SystemException {
1317                    try {
1318                            long[] groupPKs = new long[groups.size()];
1319    
1320                            for (int i = 0; i < groups.size(); i++) {
1321                                    com.liferay.portal.model.Group group = groups.get(i);
1322    
1323                                    groupPKs[i] = group.getPrimaryKey();
1324                            }
1325    
1326                            setGroups(pk, groupPKs);
1327                    }
1328                    catch (Exception e) {
1329                            throw processException(e);
1330                    }
1331                    finally {
1332                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1333                    }
1334            }
1335    
1336            public List<com.liferay.portal.model.Role> getRoles(long pk)
1337                    throws SystemException {
1338                    return getRoles(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1339            }
1340    
1341            public List<com.liferay.portal.model.Role> getRoles(long pk, int start,
1342                    int end) throws SystemException {
1343                    return getRoles(pk, start, end, null);
1344            }
1345    
1346            public static final FinderPath FINDER_PATH_GET_ROLES = new FinderPath(com.liferay.portal.model.impl.RoleModelImpl.ENTITY_CACHE_ENABLED,
1347                            PermissionModelImpl.FINDER_CACHE_ENABLED_ROLES_PERMISSIONS,
1348                            PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME,
1349                            "getRoles",
1350                            new String[] {
1351                                    Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1352                                    "com.liferay.portal.kernel.util.OrderByComparator"
1353                            });
1354    
1355            public List<com.liferay.portal.model.Role> getRoles(long pk, int start,
1356                    int end, OrderByComparator orderByComparator) throws SystemException {
1357                    Object[] finderArgs = new Object[] {
1358                                    pk, String.valueOf(start), String.valueOf(end),
1359                                    String.valueOf(orderByComparator)
1360                            };
1361    
1362                    List<com.liferay.portal.model.Role> list = (List<com.liferay.portal.model.Role>)FinderCacheUtil.getResult(FINDER_PATH_GET_ROLES,
1363                                    finderArgs, this);
1364    
1365                    if (list == null) {
1366                            Session session = null;
1367    
1368                            try {
1369                                    session = openSession();
1370    
1371                                    String sql = null;
1372    
1373                                    if (orderByComparator != null) {
1374                                            sql = _SQL_GETROLES.concat(ORDER_BY_CLAUSE)
1375                                                                               .concat(orderByComparator.getOrderBy());
1376                                    }
1377                                    else {
1378                                            sql = _SQL_GETROLES.concat(com.liferay.portal.model.impl.RoleModelImpl.ORDER_BY_SQL);
1379                                    }
1380    
1381                                    SQLQuery q = session.createSQLQuery(sql);
1382    
1383                                    q.addEntity("Role_",
1384                                            com.liferay.portal.model.impl.RoleImpl.class);
1385    
1386                                    QueryPos qPos = QueryPos.getInstance(q);
1387    
1388                                    qPos.add(pk);
1389    
1390                                    list = (List<com.liferay.portal.model.Role>)QueryUtil.list(q,
1391                                                    getDialect(), start, end);
1392                            }
1393                            catch (Exception e) {
1394                                    throw processException(e);
1395                            }
1396                            finally {
1397                                    if (list == null) {
1398                                            list = new ArrayList<com.liferay.portal.model.Role>();
1399                                    }
1400    
1401                                    rolePersistence.cacheResult(list);
1402    
1403                                    FinderCacheUtil.putResult(FINDER_PATH_GET_ROLES, finderArgs,
1404                                            list);
1405    
1406                                    closeSession(session);
1407                            }
1408                    }
1409    
1410                    return list;
1411            }
1412    
1413            public static final FinderPath FINDER_PATH_GET_ROLES_SIZE = new FinderPath(com.liferay.portal.model.impl.RoleModelImpl.ENTITY_CACHE_ENABLED,
1414                            PermissionModelImpl.FINDER_CACHE_ENABLED_ROLES_PERMISSIONS,
1415                            PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME,
1416                            "getRolesSize", new String[] { Long.class.getName() });
1417    
1418            public int getRolesSize(long pk) throws SystemException {
1419                    Object[] finderArgs = new Object[] { pk };
1420    
1421                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_ROLES_SIZE,
1422                                    finderArgs, this);
1423    
1424                    if (count == null) {
1425                            Session session = null;
1426    
1427                            try {
1428                                    session = openSession();
1429    
1430                                    SQLQuery q = session.createSQLQuery(_SQL_GETROLESSIZE);
1431    
1432                                    q.addScalar(COUNT_COLUMN_NAME,
1433                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
1434    
1435                                    QueryPos qPos = QueryPos.getInstance(q);
1436    
1437                                    qPos.add(pk);
1438    
1439                                    count = (Long)q.uniqueResult();
1440                            }
1441                            catch (Exception e) {
1442                                    throw processException(e);
1443                            }
1444                            finally {
1445                                    if (count == null) {
1446                                            count = Long.valueOf(0);
1447                                    }
1448    
1449                                    FinderCacheUtil.putResult(FINDER_PATH_GET_ROLES_SIZE,
1450                                            finderArgs, count);
1451    
1452                                    closeSession(session);
1453                            }
1454                    }
1455    
1456                    return count.intValue();
1457            }
1458    
1459            public static final FinderPath FINDER_PATH_CONTAINS_ROLE = new FinderPath(com.liferay.portal.model.impl.RoleModelImpl.ENTITY_CACHE_ENABLED,
1460                            PermissionModelImpl.FINDER_CACHE_ENABLED_ROLES_PERMISSIONS,
1461                            PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME,
1462                            "containsRole",
1463                            new String[] { Long.class.getName(), Long.class.getName() });
1464    
1465            public boolean containsRole(long pk, long rolePK) throws SystemException {
1466                    Object[] finderArgs = new Object[] { pk, rolePK };
1467    
1468                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_ROLE,
1469                                    finderArgs, this);
1470    
1471                    if (value == null) {
1472                            try {
1473                                    value = Boolean.valueOf(containsRole.contains(pk, rolePK));
1474                            }
1475                            catch (Exception e) {
1476                                    throw processException(e);
1477                            }
1478                            finally {
1479                                    if (value == null) {
1480                                            value = Boolean.FALSE;
1481                                    }
1482    
1483                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_ROLE,
1484                                            finderArgs, value);
1485                            }
1486                    }
1487    
1488                    return value.booleanValue();
1489            }
1490    
1491            public boolean containsRoles(long pk) throws SystemException {
1492                    if (getRolesSize(pk) > 0) {
1493                            return true;
1494                    }
1495                    else {
1496                            return false;
1497                    }
1498            }
1499    
1500            public void addRole(long pk, long rolePK) throws SystemException {
1501                    try {
1502                            addRole.add(pk, rolePK);
1503                    }
1504                    catch (Exception e) {
1505                            throw processException(e);
1506                    }
1507                    finally {
1508                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
1509                    }
1510            }
1511    
1512            public void addRole(long pk, com.liferay.portal.model.Role role)
1513                    throws SystemException {
1514                    try {
1515                            addRole.add(pk, role.getPrimaryKey());
1516                    }
1517                    catch (Exception e) {
1518                            throw processException(e);
1519                    }
1520                    finally {
1521                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
1522                    }
1523            }
1524    
1525            public void addRoles(long pk, long[] rolePKs) throws SystemException {
1526                    try {
1527                            for (long rolePK : rolePKs) {
1528                                    addRole.add(pk, rolePK);
1529                            }
1530                    }
1531                    catch (Exception e) {
1532                            throw processException(e);
1533                    }
1534                    finally {
1535                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
1536                    }
1537            }
1538    
1539            public void addRoles(long pk, List<com.liferay.portal.model.Role> roles)
1540                    throws SystemException {
1541                    try {
1542                            for (com.liferay.portal.model.Role role : roles) {
1543                                    addRole.add(pk, role.getPrimaryKey());
1544                            }
1545                    }
1546                    catch (Exception e) {
1547                            throw processException(e);
1548                    }
1549                    finally {
1550                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
1551                    }
1552            }
1553    
1554            public void clearRoles(long pk) throws SystemException {
1555                    try {
1556                            clearRoles.clear(pk);
1557                    }
1558                    catch (Exception e) {
1559                            throw processException(e);
1560                    }
1561                    finally {
1562                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
1563                    }
1564            }
1565    
1566            public void removeRole(long pk, long rolePK) throws SystemException {
1567                    try {
1568                            removeRole.remove(pk, rolePK);
1569                    }
1570                    catch (Exception e) {
1571                            throw processException(e);
1572                    }
1573                    finally {
1574                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
1575                    }
1576            }
1577    
1578            public void removeRole(long pk, com.liferay.portal.model.Role role)
1579                    throws SystemException {
1580                    try {
1581                            removeRole.remove(pk, role.getPrimaryKey());
1582                    }
1583                    catch (Exception e) {
1584                            throw processException(e);
1585                    }
1586                    finally {
1587                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
1588                    }
1589            }
1590    
1591            public void removeRoles(long pk, long[] rolePKs) throws SystemException {
1592                    try {
1593                            for (long rolePK : rolePKs) {
1594                                    removeRole.remove(pk, rolePK);
1595                            }
1596                    }
1597                    catch (Exception e) {
1598                            throw processException(e);
1599                    }
1600                    finally {
1601                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
1602                    }
1603            }
1604    
1605            public void removeRoles(long pk, List<com.liferay.portal.model.Role> roles)
1606                    throws SystemException {
1607                    try {
1608                            for (com.liferay.portal.model.Role role : roles) {
1609                                    removeRole.remove(pk, role.getPrimaryKey());
1610                            }
1611                    }
1612                    catch (Exception e) {
1613                            throw processException(e);
1614                    }
1615                    finally {
1616                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
1617                    }
1618            }
1619    
1620            public void setRoles(long pk, long[] rolePKs) throws SystemException {
1621                    try {
1622                            Set<Long> rolePKSet = SetUtil.fromArray(rolePKs);
1623    
1624                            List<com.liferay.portal.model.Role> roles = getRoles(pk);
1625    
1626                            for (com.liferay.portal.model.Role role : roles) {
1627                                    if (!rolePKSet.contains(role.getPrimaryKey())) {
1628                                            removeRole.remove(pk, role.getPrimaryKey());
1629                                    }
1630                                    else {
1631                                            rolePKSet.remove(role.getPrimaryKey());
1632                                    }
1633                            }
1634    
1635                            for (Long rolePK : rolePKSet) {
1636                                    addRole.add(pk, rolePK);
1637                            }
1638                    }
1639                    catch (Exception e) {
1640                            throw processException(e);
1641                    }
1642                    finally {
1643                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
1644                    }
1645            }
1646    
1647            public void setRoles(long pk, List<com.liferay.portal.model.Role> roles)
1648                    throws SystemException {
1649                    try {
1650                            long[] rolePKs = new long[roles.size()];
1651    
1652                            for (int i = 0; i < roles.size(); i++) {
1653                                    com.liferay.portal.model.Role role = roles.get(i);
1654    
1655                                    rolePKs[i] = role.getPrimaryKey();
1656                            }
1657    
1658                            setRoles(pk, rolePKs);
1659                    }
1660                    catch (Exception e) {
1661                            throw processException(e);
1662                    }
1663                    finally {
1664                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
1665                    }
1666            }
1667    
1668            public List<com.liferay.portal.model.User> getUsers(long pk)
1669                    throws SystemException {
1670                    return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1671            }
1672    
1673            public List<com.liferay.portal.model.User> getUsers(long pk, int start,
1674                    int end) throws SystemException {
1675                    return getUsers(pk, start, end, null);
1676            }
1677    
1678            public static final FinderPath FINDER_PATH_GET_USERS = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1679                            PermissionModelImpl.FINDER_CACHE_ENABLED_USERS_PERMISSIONS,
1680                            PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME,
1681                            "getUsers",
1682                            new String[] {
1683                                    Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1684                                    "com.liferay.portal.kernel.util.OrderByComparator"
1685                            });
1686    
1687            public List<com.liferay.portal.model.User> getUsers(long pk, int start,
1688                    int end, OrderByComparator orderByComparator) throws SystemException {
1689                    Object[] finderArgs = new Object[] {
1690                                    pk, String.valueOf(start), String.valueOf(end),
1691                                    String.valueOf(orderByComparator)
1692                            };
1693    
1694                    List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS,
1695                                    finderArgs, this);
1696    
1697                    if (list == null) {
1698                            Session session = null;
1699    
1700                            try {
1701                                    session = openSession();
1702    
1703                                    String sql = null;
1704    
1705                                    if (orderByComparator != null) {
1706                                            sql = _SQL_GETUSERS.concat(ORDER_BY_CLAUSE)
1707                                                                               .concat(orderByComparator.getOrderBy());
1708                                    }
1709                                    else {
1710                                            sql = _SQL_GETUSERS;
1711                                    }
1712    
1713                                    SQLQuery q = session.createSQLQuery(sql);
1714    
1715                                    q.addEntity("User_",
1716                                            com.liferay.portal.model.impl.UserImpl.class);
1717    
1718                                    QueryPos qPos = QueryPos.getInstance(q);
1719    
1720                                    qPos.add(pk);
1721    
1722                                    list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
1723                                                    getDialect(), start, end);
1724                            }
1725                            catch (Exception e) {
1726                                    throw processException(e);
1727                            }
1728                            finally {
1729                                    if (list == null) {
1730                                            list = new ArrayList<com.liferay.portal.model.User>();
1731                                    }
1732    
1733                                    userPersistence.cacheResult(list);
1734    
1735                                    FinderCacheUtil.putResult(FINDER_PATH_GET_USERS, finderArgs,
1736                                            list);
1737    
1738                                    closeSession(session);
1739                            }
1740                    }
1741    
1742                    return list;
1743            }
1744    
1745            public static final FinderPath FINDER_PATH_GET_USERS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1746                            PermissionModelImpl.FINDER_CACHE_ENABLED_USERS_PERMISSIONS,
1747                            PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME,
1748                            "getUsersSize", new String[] { Long.class.getName() });
1749    
1750            public int getUsersSize(long pk) throws SystemException {
1751                    Object[] finderArgs = new Object[] { pk };
1752    
1753                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS_SIZE,
1754                                    finderArgs, this);
1755    
1756                    if (count == null) {
1757                            Session session = null;
1758    
1759                            try {
1760                                    session = openSession();
1761    
1762                                    SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
1763    
1764                                    q.addScalar(COUNT_COLUMN_NAME,
1765                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
1766    
1767                                    QueryPos qPos = QueryPos.getInstance(q);
1768    
1769                                    qPos.add(pk);
1770    
1771                                    count = (Long)q.uniqueResult();
1772                            }
1773                            catch (Exception e) {
1774                                    throw processException(e);
1775                            }
1776                            finally {
1777                                    if (count == null) {
1778                                            count = Long.valueOf(0);
1779                                    }
1780    
1781                                    FinderCacheUtil.putResult(FINDER_PATH_GET_USERS_SIZE,
1782                                            finderArgs, count);
1783    
1784                                    closeSession(session);
1785                            }
1786                    }
1787    
1788                    return count.intValue();
1789            }
1790    
1791            public static final FinderPath FINDER_PATH_CONTAINS_USER = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1792                            PermissionModelImpl.FINDER_CACHE_ENABLED_USERS_PERMISSIONS,
1793                            PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME,
1794                            "containsUser",
1795                            new String[] { Long.class.getName(), Long.class.getName() });
1796    
1797            public boolean containsUser(long pk, long userPK) throws SystemException {
1798                    Object[] finderArgs = new Object[] { pk, userPK };
1799    
1800                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USER,
1801                                    finderArgs, this);
1802    
1803                    if (value == null) {
1804                            try {
1805                                    value = Boolean.valueOf(containsUser.contains(pk, userPK));
1806                            }
1807                            catch (Exception e) {
1808                                    throw processException(e);
1809                            }
1810                            finally {
1811                                    if (value == null) {
1812                                            value = Boolean.FALSE;
1813                                    }
1814    
1815                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USER,
1816                                            finderArgs, value);
1817                            }
1818                    }
1819    
1820                    return value.booleanValue();
1821            }
1822    
1823            public boolean containsUsers(long pk) throws SystemException {
1824                    if (getUsersSize(pk) > 0) {
1825                            return true;
1826                    }
1827                    else {
1828                            return false;
1829                    }
1830            }
1831    
1832            public void addUser(long pk, long userPK) throws SystemException {
1833                    try {
1834                            addUser.add(pk, userPK);
1835                    }
1836                    catch (Exception e) {
1837                            throw processException(e);
1838                    }
1839                    finally {
1840                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
1841                    }
1842            }
1843    
1844            public void addUser(long pk, com.liferay.portal.model.User user)
1845                    throws SystemException {
1846                    try {
1847                            addUser.add(pk, user.getPrimaryKey());
1848                    }
1849                    catch (Exception e) {
1850                            throw processException(e);
1851                    }
1852                    finally {
1853                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
1854                    }
1855            }
1856    
1857            public void addUsers(long pk, long[] userPKs) throws SystemException {
1858                    try {
1859                            for (long userPK : userPKs) {
1860                                    addUser.add(pk, userPK);
1861                            }
1862                    }
1863                    catch (Exception e) {
1864                            throw processException(e);
1865                    }
1866                    finally {
1867                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
1868                    }
1869            }
1870    
1871            public void addUsers(long pk, List<com.liferay.portal.model.User> users)
1872                    throws SystemException {
1873                    try {
1874                            for (com.liferay.portal.model.User user : users) {
1875                                    addUser.add(pk, user.getPrimaryKey());
1876                            }
1877                    }
1878                    catch (Exception e) {
1879                            throw processException(e);
1880                    }
1881                    finally {
1882                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
1883                    }
1884            }
1885    
1886            public void clearUsers(long pk) throws SystemException {
1887                    try {
1888                            clearUsers.clear(pk);
1889                    }
1890                    catch (Exception e) {
1891                            throw processException(e);
1892                    }
1893                    finally {
1894                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
1895                    }
1896            }
1897    
1898            public void removeUser(long pk, long userPK) throws SystemException {
1899                    try {
1900                            removeUser.remove(pk, userPK);
1901                    }
1902                    catch (Exception e) {
1903                            throw processException(e);
1904                    }
1905                    finally {
1906                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
1907                    }
1908            }
1909    
1910            public void removeUser(long pk, com.liferay.portal.model.User user)
1911                    throws SystemException {
1912                    try {
1913                            removeUser.remove(pk, user.getPrimaryKey());
1914                    }
1915                    catch (Exception e) {
1916                            throw processException(e);
1917                    }
1918                    finally {
1919                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
1920                    }
1921            }
1922    
1923            public void removeUsers(long pk, long[] userPKs) throws SystemException {
1924                    try {
1925                            for (long userPK : userPKs) {
1926                                    removeUser.remove(pk, userPK);
1927                            }
1928                    }
1929                    catch (Exception e) {
1930                            throw processException(e);
1931                    }
1932                    finally {
1933                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
1934                    }
1935            }
1936    
1937            public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
1938                    throws SystemException {
1939                    try {
1940                            for (com.liferay.portal.model.User user : users) {
1941                                    removeUser.remove(pk, user.getPrimaryKey());
1942                            }
1943                    }
1944                    catch (Exception e) {
1945                            throw processException(e);
1946                    }
1947                    finally {
1948                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
1949                    }
1950            }
1951    
1952            public void setUsers(long pk, long[] userPKs) throws SystemException {
1953                    try {
1954                            Set<Long> userPKSet = SetUtil.fromArray(userPKs);
1955    
1956                            List<com.liferay.portal.model.User> users = getUsers(pk);
1957    
1958                            for (com.liferay.portal.model.User user : users) {
1959                                    if (!userPKSet.contains(user.getPrimaryKey())) {
1960                                            removeUser.remove(pk, user.getPrimaryKey());
1961                                    }
1962                                    else {
1963                                            userPKSet.remove(user.getPrimaryKey());
1964                                    }
1965                            }
1966    
1967                            for (Long userPK : userPKSet) {
1968                                    addUser.add(pk, userPK);
1969                            }
1970                    }
1971                    catch (Exception e) {
1972                            throw processException(e);
1973                    }
1974                    finally {
1975                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
1976                    }
1977            }
1978    
1979            public void setUsers(long pk, List<com.liferay.portal.model.User> users)
1980                    throws SystemException {
1981                    try {
1982                            long[] userPKs = new long[users.size()];
1983    
1984                            for (int i = 0; i < users.size(); i++) {
1985                                    com.liferay.portal.model.User user = users.get(i);
1986    
1987                                    userPKs[i] = user.getPrimaryKey();
1988                            }
1989    
1990                            setUsers(pk, userPKs);
1991                    }
1992                    catch (Exception e) {
1993                            throw processException(e);
1994                    }
1995                    finally {
1996                            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
1997                    }
1998            }
1999    
2000            public void afterPropertiesSet() {
2001                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2002                                            com.liferay.portal.util.PropsUtil.get(
2003                                                    "value.object.listener.com.liferay.portal.model.Permission")));
2004    
2005                    if (listenerClassNames.length > 0) {
2006                            try {
2007                                    List<ModelListener<Permission>> listenersList = new ArrayList<ModelListener<Permission>>();
2008    
2009                                    for (String listenerClassName : listenerClassNames) {
2010                                            listenersList.add((ModelListener<Permission>)InstanceFactory.newInstance(
2011                                                            listenerClassName));
2012                                    }
2013    
2014                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2015                            }
2016                            catch (Exception e) {
2017                                    _log.error(e);
2018                            }
2019                    }
2020    
2021                    containsGroup = new ContainsGroup(this);
2022    
2023                    addGroup = new AddGroup(this);
2024                    clearGroups = new ClearGroups(this);
2025                    removeGroup = new RemoveGroup(this);
2026    
2027                    containsRole = new ContainsRole(this);
2028    
2029                    addRole = new AddRole(this);
2030                    clearRoles = new ClearRoles(this);
2031                    removeRole = new RemoveRole(this);
2032    
2033                    containsUser = new ContainsUser(this);
2034    
2035                    addUser = new AddUser(this);
2036                    clearUsers = new ClearUsers(this);
2037                    removeUser = new RemoveUser(this);
2038            }
2039    
2040            @BeanReference(type = AccountPersistence.class)
2041            protected AccountPersistence accountPersistence;
2042            @BeanReference(type = AddressPersistence.class)
2043            protected AddressPersistence addressPersistence;
2044            @BeanReference(type = BrowserTrackerPersistence.class)
2045            protected BrowserTrackerPersistence browserTrackerPersistence;
2046            @BeanReference(type = ClassNamePersistence.class)
2047            protected ClassNamePersistence classNamePersistence;
2048            @BeanReference(type = CompanyPersistence.class)
2049            protected CompanyPersistence companyPersistence;
2050            @BeanReference(type = ContactPersistence.class)
2051            protected ContactPersistence contactPersistence;
2052            @BeanReference(type = CountryPersistence.class)
2053            protected CountryPersistence countryPersistence;
2054            @BeanReference(type = EmailAddressPersistence.class)
2055            protected EmailAddressPersistence emailAddressPersistence;
2056            @BeanReference(type = GroupPersistence.class)
2057            protected GroupPersistence groupPersistence;
2058            @BeanReference(type = ImagePersistence.class)
2059            protected ImagePersistence imagePersistence;
2060            @BeanReference(type = LayoutPersistence.class)
2061            protected LayoutPersistence layoutPersistence;
2062            @BeanReference(type = LayoutPrototypePersistence.class)
2063            protected LayoutPrototypePersistence layoutPrototypePersistence;
2064            @BeanReference(type = LayoutSetPersistence.class)
2065            protected LayoutSetPersistence layoutSetPersistence;
2066            @BeanReference(type = LayoutSetPrototypePersistence.class)
2067            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2068            @BeanReference(type = ListTypePersistence.class)
2069            protected ListTypePersistence listTypePersistence;
2070            @BeanReference(type = LockPersistence.class)
2071            protected LockPersistence lockPersistence;
2072            @BeanReference(type = MembershipRequestPersistence.class)
2073            protected MembershipRequestPersistence membershipRequestPersistence;
2074            @BeanReference(type = OrganizationPersistence.class)
2075            protected OrganizationPersistence organizationPersistence;
2076            @BeanReference(type = OrgGroupPermissionPersistence.class)
2077            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2078            @BeanReference(type = OrgGroupRolePersistence.class)
2079            protected OrgGroupRolePersistence orgGroupRolePersistence;
2080            @BeanReference(type = OrgLaborPersistence.class)
2081            protected OrgLaborPersistence orgLaborPersistence;
2082            @BeanReference(type = PasswordPolicyPersistence.class)
2083            protected PasswordPolicyPersistence passwordPolicyPersistence;
2084            @BeanReference(type = PasswordPolicyRelPersistence.class)
2085            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2086            @BeanReference(type = PasswordTrackerPersistence.class)
2087            protected PasswordTrackerPersistence passwordTrackerPersistence;
2088            @BeanReference(type = PermissionPersistence.class)
2089            protected PermissionPersistence permissionPersistence;
2090            @BeanReference(type = PhonePersistence.class)
2091            protected PhonePersistence phonePersistence;
2092            @BeanReference(type = PluginSettingPersistence.class)
2093            protected PluginSettingPersistence pluginSettingPersistence;
2094            @BeanReference(type = PortletPersistence.class)
2095            protected PortletPersistence portletPersistence;
2096            @BeanReference(type = PortletItemPersistence.class)
2097            protected PortletItemPersistence portletItemPersistence;
2098            @BeanReference(type = PortletPreferencesPersistence.class)
2099            protected PortletPreferencesPersistence portletPreferencesPersistence;
2100            @BeanReference(type = RegionPersistence.class)
2101            protected RegionPersistence regionPersistence;
2102            @BeanReference(type = ReleasePersistence.class)
2103            protected ReleasePersistence releasePersistence;
2104            @BeanReference(type = ResourcePersistence.class)
2105            protected ResourcePersistence resourcePersistence;
2106            @BeanReference(type = ResourceActionPersistence.class)
2107            protected ResourceActionPersistence resourceActionPersistence;
2108            @BeanReference(type = ResourceCodePersistence.class)
2109            protected ResourceCodePersistence resourceCodePersistence;
2110            @BeanReference(type = ResourcePermissionPersistence.class)
2111            protected ResourcePermissionPersistence resourcePermissionPersistence;
2112            @BeanReference(type = RolePersistence.class)
2113            protected RolePersistence rolePersistence;
2114            @BeanReference(type = ServiceComponentPersistence.class)
2115            protected ServiceComponentPersistence serviceComponentPersistence;
2116            @BeanReference(type = ShardPersistence.class)
2117            protected ShardPersistence shardPersistence;
2118            @BeanReference(type = SubscriptionPersistence.class)
2119            protected SubscriptionPersistence subscriptionPersistence;
2120            @BeanReference(type = TicketPersistence.class)
2121            protected TicketPersistence ticketPersistence;
2122            @BeanReference(type = TeamPersistence.class)
2123            protected TeamPersistence teamPersistence;
2124            @BeanReference(type = UserPersistence.class)
2125            protected UserPersistence userPersistence;
2126            @BeanReference(type = UserGroupPersistence.class)
2127            protected UserGroupPersistence userGroupPersistence;
2128            @BeanReference(type = UserGroupGroupRolePersistence.class)
2129            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2130            @BeanReference(type = UserGroupRolePersistence.class)
2131            protected UserGroupRolePersistence userGroupRolePersistence;
2132            @BeanReference(type = UserIdMapperPersistence.class)
2133            protected UserIdMapperPersistence userIdMapperPersistence;
2134            @BeanReference(type = UserTrackerPersistence.class)
2135            protected UserTrackerPersistence userTrackerPersistence;
2136            @BeanReference(type = UserTrackerPathPersistence.class)
2137            protected UserTrackerPathPersistence userTrackerPathPersistence;
2138            @BeanReference(type = WebDAVPropsPersistence.class)
2139            protected WebDAVPropsPersistence webDAVPropsPersistence;
2140            @BeanReference(type = WebsitePersistence.class)
2141            protected WebsitePersistence websitePersistence;
2142            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2143            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2144            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2145            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2146            protected ContainsGroup containsGroup;
2147            protected AddGroup addGroup;
2148            protected ClearGroups clearGroups;
2149            protected RemoveGroup removeGroup;
2150            protected ContainsRole containsRole;
2151            protected AddRole addRole;
2152            protected ClearRoles clearRoles;
2153            protected RemoveRole removeRole;
2154            protected ContainsUser containsUser;
2155            protected AddUser addUser;
2156            protected ClearUsers clearUsers;
2157            protected RemoveUser removeUser;
2158    
2159            protected class ContainsGroup {
2160                    protected ContainsGroup(PermissionPersistenceImpl persistenceImpl) {
2161                            super();
2162    
2163                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2164                                            _SQL_CONTAINSGROUP,
2165                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
2166                                            RowMapper.COUNT);
2167                    }
2168    
2169                    protected boolean contains(long permissionId, long groupId) {
2170                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2171                                                    new Long(permissionId), new Long(groupId)
2172                                            });
2173    
2174                            if (results.size() > 0) {
2175                                    Integer count = results.get(0);
2176    
2177                                    if (count.intValue() > 0) {
2178                                            return true;
2179                                    }
2180                            }
2181    
2182                            return false;
2183                    }
2184    
2185                    private MappingSqlQuery<Integer> _mappingSqlQuery;
2186            }
2187    
2188            protected class AddGroup {
2189                    protected AddGroup(PermissionPersistenceImpl persistenceImpl) {
2190                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2191                                            "INSERT INTO Groups_Permissions (permissionId, groupId) VALUES (?, ?)",
2192                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
2193                            _persistenceImpl = persistenceImpl;
2194                    }
2195    
2196                    protected void add(long permissionId, long groupId)
2197                            throws SystemException {
2198                            if (!_persistenceImpl.containsGroup.contains(permissionId, groupId)) {
2199                                    ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
2200    
2201                                    for (ModelListener<Permission> listener : listeners) {
2202                                            listener.onBeforeAddAssociation(permissionId,
2203                                                    com.liferay.portal.model.Group.class.getName(), groupId);
2204                                    }
2205    
2206                                    for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2207                                            listener.onBeforeAddAssociation(groupId,
2208                                                    Permission.class.getName(), permissionId);
2209                                    }
2210    
2211                                    _sqlUpdate.update(new Object[] {
2212                                                    new Long(permissionId), new Long(groupId)
2213                                            });
2214    
2215                                    for (ModelListener<Permission> listener : listeners) {
2216                                            listener.onAfterAddAssociation(permissionId,
2217                                                    com.liferay.portal.model.Group.class.getName(), groupId);
2218                                    }
2219    
2220                                    for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2221                                            listener.onAfterAddAssociation(groupId,
2222                                                    Permission.class.getName(), permissionId);
2223                                    }
2224                            }
2225                    }
2226    
2227                    private SqlUpdate _sqlUpdate;
2228                    private PermissionPersistenceImpl _persistenceImpl;
2229            }
2230    
2231            protected class ClearGroups {
2232                    protected ClearGroups(PermissionPersistenceImpl persistenceImpl) {
2233                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2234                                            "DELETE FROM Groups_Permissions WHERE permissionId = ?",
2235                                            new int[] { java.sql.Types.BIGINT });
2236                    }
2237    
2238                    protected void clear(long permissionId) throws SystemException {
2239                            ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
2240    
2241                            List<com.liferay.portal.model.Group> groups = null;
2242    
2243                            if ((listeners.length > 0) || (groupListeners.length > 0)) {
2244                                    groups = getGroups(permissionId);
2245    
2246                                    for (com.liferay.portal.model.Group group : groups) {
2247                                            for (ModelListener<Permission> listener : listeners) {
2248                                                    listener.onBeforeRemoveAssociation(permissionId,
2249                                                            com.liferay.portal.model.Group.class.getName(),
2250                                                            group.getPrimaryKey());
2251                                            }
2252    
2253                                            for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2254                                                    listener.onBeforeRemoveAssociation(group.getPrimaryKey(),
2255                                                            Permission.class.getName(), permissionId);
2256                                            }
2257                                    }
2258                            }
2259    
2260                            _sqlUpdate.update(new Object[] { new Long(permissionId) });
2261    
2262                            if ((listeners.length > 0) || (groupListeners.length > 0)) {
2263                                    for (com.liferay.portal.model.Group group : groups) {
2264                                            for (ModelListener<Permission> listener : listeners) {
2265                                                    listener.onAfterRemoveAssociation(permissionId,
2266                                                            com.liferay.portal.model.Group.class.getName(),
2267                                                            group.getPrimaryKey());
2268                                            }
2269    
2270                                            for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2271                                                    listener.onAfterRemoveAssociation(group.getPrimaryKey(),
2272                                                            Permission.class.getName(), permissionId);
2273                                            }
2274                                    }
2275                            }
2276                    }
2277    
2278                    private SqlUpdate _sqlUpdate;
2279            }
2280    
2281            protected class RemoveGroup {
2282                    protected RemoveGroup(PermissionPersistenceImpl persistenceImpl) {
2283                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2284                                            "DELETE FROM Groups_Permissions WHERE permissionId = ? AND groupId = ?",
2285                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
2286                            _persistenceImpl = persistenceImpl;
2287                    }
2288    
2289                    protected void remove(long permissionId, long groupId)
2290                            throws SystemException {
2291                            if (_persistenceImpl.containsGroup.contains(permissionId, groupId)) {
2292                                    ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
2293    
2294                                    for (ModelListener<Permission> listener : listeners) {
2295                                            listener.onBeforeRemoveAssociation(permissionId,
2296                                                    com.liferay.portal.model.Group.class.getName(), groupId);
2297                                    }
2298    
2299                                    for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2300                                            listener.onBeforeRemoveAssociation(groupId,
2301                                                    Permission.class.getName(), permissionId);
2302                                    }
2303    
2304                                    _sqlUpdate.update(new Object[] {
2305                                                    new Long(permissionId), new Long(groupId)
2306                                            });
2307    
2308                                    for (ModelListener<Permission> listener : listeners) {
2309                                            listener.onAfterRemoveAssociation(permissionId,
2310                                                    com.liferay.portal.model.Group.class.getName(), groupId);
2311                                    }
2312    
2313                                    for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2314                                            listener.onAfterRemoveAssociation(groupId,
2315                                                    Permission.class.getName(), permissionId);
2316                                    }
2317                            }
2318                    }
2319    
2320                    private SqlUpdate _sqlUpdate;
2321                    private PermissionPersistenceImpl _persistenceImpl;
2322            }
2323    
2324            protected class ContainsRole {
2325                    protected ContainsRole(PermissionPersistenceImpl persistenceImpl) {
2326                            super();
2327    
2328                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2329                                            _SQL_CONTAINSROLE,
2330                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
2331                                            RowMapper.COUNT);
2332                    }
2333    
2334                    protected boolean contains(long permissionId, long roleId) {
2335                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2336                                                    new Long(permissionId), new Long(roleId)
2337                                            });
2338    
2339                            if (results.size() > 0) {
2340                                    Integer count = results.get(0);
2341    
2342                                    if (count.intValue() > 0) {
2343                                            return true;
2344                                    }
2345                            }
2346    
2347                            return false;
2348                    }
2349    
2350                    private MappingSqlQuery<Integer> _mappingSqlQuery;
2351            }
2352    
2353            protected class AddRole {
2354                    protected AddRole(PermissionPersistenceImpl persistenceImpl) {
2355                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2356                                            "INSERT INTO Roles_Permissions (permissionId, roleId) VALUES (?, ?)",
2357                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
2358                            _persistenceImpl = persistenceImpl;
2359                    }
2360    
2361                    protected void add(long permissionId, long roleId)
2362                            throws SystemException {
2363                            if (!_persistenceImpl.containsRole.contains(permissionId, roleId)) {
2364                                    ModelListener<com.liferay.portal.model.Role>[] roleListeners = rolePersistence.getListeners();
2365    
2366                                    for (ModelListener<Permission> listener : listeners) {
2367                                            listener.onBeforeAddAssociation(permissionId,
2368                                                    com.liferay.portal.model.Role.class.getName(), roleId);
2369                                    }
2370    
2371                                    for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
2372                                            listener.onBeforeAddAssociation(roleId,
2373                                                    Permission.class.getName(), permissionId);
2374                                    }
2375    
2376                                    _sqlUpdate.update(new Object[] {
2377                                                    new Long(permissionId), new Long(roleId)
2378                                            });
2379    
2380                                    for (ModelListener<Permission> listener : listeners) {
2381                                            listener.onAfterAddAssociation(permissionId,
2382                                                    com.liferay.portal.model.Role.class.getName(), roleId);
2383                                    }
2384    
2385                                    for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
2386                                            listener.onAfterAddAssociation(roleId,
2387                                                    Permission.class.getName(), permissionId);
2388                                    }
2389                            }
2390                    }
2391    
2392                    private SqlUpdate _sqlUpdate;
2393                    private PermissionPersistenceImpl _persistenceImpl;
2394            }
2395    
2396            protected class ClearRoles {
2397                    protected ClearRoles(PermissionPersistenceImpl persistenceImpl) {
2398                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2399                                            "DELETE FROM Roles_Permissions WHERE permissionId = ?",
2400                                            new int[] { java.sql.Types.BIGINT });
2401                    }
2402    
2403                    protected void clear(long permissionId) throws SystemException {
2404                            ModelListener<com.liferay.portal.model.Role>[] roleListeners = rolePersistence.getListeners();
2405    
2406                            List<com.liferay.portal.model.Role> roles = null;
2407    
2408                            if ((listeners.length > 0) || (roleListeners.length > 0)) {
2409                                    roles = getRoles(permissionId);
2410    
2411                                    for (com.liferay.portal.model.Role role : roles) {
2412                                            for (ModelListener<Permission> listener : listeners) {
2413                                                    listener.onBeforeRemoveAssociation(permissionId,
2414                                                            com.liferay.portal.model.Role.class.getName(),
2415                                                            role.getPrimaryKey());
2416                                            }
2417    
2418                                            for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
2419                                                    listener.onBeforeRemoveAssociation(role.getPrimaryKey(),
2420                                                            Permission.class.getName(), permissionId);
2421                                            }
2422                                    }
2423                            }
2424    
2425                            _sqlUpdate.update(new Object[] { new Long(permissionId) });
2426    
2427                            if ((listeners.length > 0) || (roleListeners.length > 0)) {
2428                                    for (com.liferay.portal.model.Role role : roles) {
2429                                            for (ModelListener<Permission> listener : listeners) {
2430                                                    listener.onAfterRemoveAssociation(permissionId,
2431                                                            com.liferay.portal.model.Role.class.getName(),
2432                                                            role.getPrimaryKey());
2433                                            }
2434    
2435                                            for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
2436                                                    listener.onAfterRemoveAssociation(role.getPrimaryKey(),
2437                                                            Permission.class.getName(), permissionId);
2438                                            }
2439                                    }
2440                            }
2441                    }
2442    
2443                    private SqlUpdate _sqlUpdate;
2444            }
2445    
2446            protected class RemoveRole {
2447                    protected RemoveRole(PermissionPersistenceImpl persistenceImpl) {
2448                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2449                                            "DELETE FROM Roles_Permissions WHERE permissionId = ? AND roleId = ?",
2450                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
2451                            _persistenceImpl = persistenceImpl;
2452                    }
2453    
2454                    protected void remove(long permissionId, long roleId)
2455                            throws SystemException {
2456                            if (_persistenceImpl.containsRole.contains(permissionId, roleId)) {
2457                                    ModelListener<com.liferay.portal.model.Role>[] roleListeners = rolePersistence.getListeners();
2458    
2459                                    for (ModelListener<Permission> listener : listeners) {
2460                                            listener.onBeforeRemoveAssociation(permissionId,
2461                                                    com.liferay.portal.model.Role.class.getName(), roleId);
2462                                    }
2463    
2464                                    for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
2465                                            listener.onBeforeRemoveAssociation(roleId,
2466                                                    Permission.class.getName(), permissionId);
2467                                    }
2468    
2469                                    _sqlUpdate.update(new Object[] {
2470                                                    new Long(permissionId), new Long(roleId)
2471                                            });
2472    
2473                                    for (ModelListener<Permission> listener : listeners) {
2474                                            listener.onAfterRemoveAssociation(permissionId,
2475                                                    com.liferay.portal.model.Role.class.getName(), roleId);
2476                                    }
2477    
2478                                    for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
2479                                            listener.onAfterRemoveAssociation(roleId,
2480                                                    Permission.class.getName(), permissionId);
2481                                    }
2482                            }
2483                    }
2484    
2485                    private SqlUpdate _sqlUpdate;
2486                    private PermissionPersistenceImpl _persistenceImpl;
2487            }
2488    
2489            protected class ContainsUser {
2490                    protected ContainsUser(PermissionPersistenceImpl persistenceImpl) {
2491                            super();
2492    
2493                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2494                                            _SQL_CONTAINSUSER,
2495                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
2496                                            RowMapper.COUNT);
2497                    }
2498    
2499                    protected boolean contains(long permissionId, long userId) {
2500                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2501                                                    new Long(permissionId), new Long(userId)
2502                                            });
2503    
2504                            if (results.size() > 0) {
2505                                    Integer count = results.get(0);
2506    
2507                                    if (count.intValue() > 0) {
2508                                            return true;
2509                                    }
2510                            }
2511    
2512                            return false;
2513                    }
2514    
2515                    private MappingSqlQuery<Integer> _mappingSqlQuery;
2516            }
2517    
2518            protected class AddUser {
2519                    protected AddUser(PermissionPersistenceImpl persistenceImpl) {
2520                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2521                                            "INSERT INTO Users_Permissions (permissionId, userId) VALUES (?, ?)",
2522                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
2523                            _persistenceImpl = persistenceImpl;
2524                    }
2525    
2526                    protected void add(long permissionId, long userId)
2527                            throws SystemException {
2528                            if (!_persistenceImpl.containsUser.contains(permissionId, userId)) {
2529                                    ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
2530    
2531                                    for (ModelListener<Permission> listener : listeners) {
2532                                            listener.onBeforeAddAssociation(permissionId,
2533                                                    com.liferay.portal.model.User.class.getName(), userId);
2534                                    }
2535    
2536                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2537                                            listener.onBeforeAddAssociation(userId,
2538                                                    Permission.class.getName(), permissionId);
2539                                    }
2540    
2541                                    _sqlUpdate.update(new Object[] {
2542                                                    new Long(permissionId), new Long(userId)
2543                                            });
2544    
2545                                    for (ModelListener<Permission> listener : listeners) {
2546                                            listener.onAfterAddAssociation(permissionId,
2547                                                    com.liferay.portal.model.User.class.getName(), userId);
2548                                    }
2549    
2550                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2551                                            listener.onAfterAddAssociation(userId,
2552                                                    Permission.class.getName(), permissionId);
2553                                    }
2554                            }
2555                    }
2556    
2557                    private SqlUpdate _sqlUpdate;
2558                    private PermissionPersistenceImpl _persistenceImpl;
2559            }
2560    
2561            protected class ClearUsers {
2562                    protected ClearUsers(PermissionPersistenceImpl persistenceImpl) {
2563                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2564                                            "DELETE FROM Users_Permissions WHERE permissionId = ?",
2565                                            new int[] { java.sql.Types.BIGINT });
2566                    }
2567    
2568                    protected void clear(long permissionId) throws SystemException {
2569                            ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
2570    
2571                            List<com.liferay.portal.model.User> users = null;
2572    
2573                            if ((listeners.length > 0) || (userListeners.length > 0)) {
2574                                    users = getUsers(permissionId);
2575    
2576                                    for (com.liferay.portal.model.User user : users) {
2577                                            for (ModelListener<Permission> listener : listeners) {
2578                                                    listener.onBeforeRemoveAssociation(permissionId,
2579                                                            com.liferay.portal.model.User.class.getName(),
2580                                                            user.getPrimaryKey());
2581                                            }
2582    
2583                                            for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2584                                                    listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
2585                                                            Permission.class.getName(), permissionId);
2586                                            }
2587                                    }
2588                            }
2589    
2590                            _sqlUpdate.update(new Object[] { new Long(permissionId) });
2591    
2592                            if ((listeners.length > 0) || (userListeners.length > 0)) {
2593                                    for (com.liferay.portal.model.User user : users) {
2594                                            for (ModelListener<Permission> listener : listeners) {
2595                                                    listener.onAfterRemoveAssociation(permissionId,
2596                                                            com.liferay.portal.model.User.class.getName(),
2597                                                            user.getPrimaryKey());
2598                                            }
2599    
2600                                            for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2601                                                    listener.onAfterRemoveAssociation(user.getPrimaryKey(),
2602                                                            Permission.class.getName(), permissionId);
2603                                            }
2604                                    }
2605                            }
2606                    }
2607    
2608                    private SqlUpdate _sqlUpdate;
2609            }
2610    
2611            protected class RemoveUser {
2612                    protected RemoveUser(PermissionPersistenceImpl persistenceImpl) {
2613                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2614                                            "DELETE FROM Users_Permissions WHERE permissionId = ? AND userId = ?",
2615                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
2616                            _persistenceImpl = persistenceImpl;
2617                    }
2618    
2619                    protected void remove(long permissionId, long userId)
2620                            throws SystemException {
2621                            if (_persistenceImpl.containsUser.contains(permissionId, userId)) {
2622                                    ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
2623    
2624                                    for (ModelListener<Permission> listener : listeners) {
2625                                            listener.onBeforeRemoveAssociation(permissionId,
2626                                                    com.liferay.portal.model.User.class.getName(), userId);
2627                                    }
2628    
2629                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2630                                            listener.onBeforeRemoveAssociation(userId,
2631                                                    Permission.class.getName(), permissionId);
2632                                    }
2633    
2634                                    _sqlUpdate.update(new Object[] {
2635                                                    new Long(permissionId), new Long(userId)
2636                                            });
2637    
2638                                    for (ModelListener<Permission> listener : listeners) {
2639                                            listener.onAfterRemoveAssociation(permissionId,
2640                                                    com.liferay.portal.model.User.class.getName(), userId);
2641                                    }
2642    
2643                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2644                                            listener.onAfterRemoveAssociation(userId,
2645                                                    Permission.class.getName(), permissionId);
2646                                    }
2647                            }
2648                    }
2649    
2650                    private SqlUpdate _sqlUpdate;
2651                    private PermissionPersistenceImpl _persistenceImpl;
2652            }
2653    
2654            private static final String _SQL_SELECT_PERMISSION = "SELECT permission FROM Permission permission";
2655            private static final String _SQL_SELECT_PERMISSION_WHERE = "SELECT permission FROM Permission permission WHERE ";
2656            private static final String _SQL_COUNT_PERMISSION = "SELECT COUNT(permission) FROM Permission permission";
2657            private static final String _SQL_COUNT_PERMISSION_WHERE = "SELECT COUNT(permission) FROM Permission permission WHERE ";
2658            private static final String _SQL_GETGROUPS = "SELECT {Group_.*} FROM Group_ INNER JOIN Groups_Permissions ON (Groups_Permissions.groupId = Group_.groupId) WHERE (Groups_Permissions.permissionId = ?)";
2659            private static final String _SQL_GETGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Permissions WHERE permissionId = ?";
2660            private static final String _SQL_CONTAINSGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Permissions WHERE permissionId = ? AND groupId = ?";
2661            private static final String _SQL_GETROLES = "SELECT {Role_.*} FROM Role_ INNER JOIN Roles_Permissions ON (Roles_Permissions.roleId = Role_.roleId) WHERE (Roles_Permissions.permissionId = ?)";
2662            private static final String _SQL_GETROLESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Roles_Permissions WHERE permissionId = ?";
2663            private static final String _SQL_CONTAINSROLE = "SELECT COUNT(*) AS COUNT_VALUE FROM Roles_Permissions WHERE permissionId = ? AND roleId = ?";
2664            private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_Permissions ON (Users_Permissions.userId = User_.userId) WHERE (Users_Permissions.permissionId = ?)";
2665            private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Permissions WHERE permissionId = ?";
2666            private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Permissions WHERE permissionId = ? AND userId = ?";
2667            private static final String _FINDER_COLUMN_RESOURCEID_RESOURCEID_2 = "permission.resourceId = ?";
2668            private static final String _FINDER_COLUMN_A_R_ACTIONID_1 = "permission.actionId IS NULL AND ";
2669            private static final String _FINDER_COLUMN_A_R_ACTIONID_2 = "permission.actionId = ? AND ";
2670            private static final String _FINDER_COLUMN_A_R_ACTIONID_3 = "(permission.actionId IS NULL OR permission.actionId = ?) AND ";
2671            private static final String _FINDER_COLUMN_A_R_RESOURCEID_2 = "permission.resourceId = ?";
2672            private static final String _ORDER_BY_ENTITY_ALIAS = "permission.";
2673            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Permission exists with the primary key ";
2674            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Permission exists with the key {";
2675            private static Log _log = LogFactoryUtil.getLog(PermissionPersistenceImpl.class);
2676    }