0001: /**
0002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
0003: *
0004: * Permission is hereby granted, free of charge, to any person obtaining a copy
0005: * of this software and associated documentation files (the "Software"), to deal
0006: * in the Software without restriction, including without limitation the rights
0007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0008: * copies of the Software, and to permit persons to whom the Software is
0009: * furnished to do so, subject to the following conditions:
0010: *
0011: * The above copyright notice and this permission notice shall be included in
0012: * all copies or substantial portions of the Software.
0013: *
0014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0020: * SOFTWARE.
0021: */package com.liferay.portal.service.persistence;
0022:
0023: import com.liferay.portal.NoSuchGroupException;
0024: import com.liferay.portal.SystemException;
0025: import com.liferay.portal.kernel.dao.DynamicQuery;
0026: import com.liferay.portal.kernel.dao.DynamicQueryInitializer;
0027: import com.liferay.portal.kernel.util.GetterUtil;
0028: import com.liferay.portal.kernel.util.OrderByComparator;
0029: import com.liferay.portal.kernel.util.StringMaker;
0030: import com.liferay.portal.kernel.util.StringPool;
0031: import com.liferay.portal.kernel.util.Validator;
0032: import com.liferay.portal.model.Group;
0033: import com.liferay.portal.model.ModelListener;
0034: import com.liferay.portal.model.impl.GroupImpl;
0035: import com.liferay.portal.model.impl.GroupModelImpl;
0036: import com.liferay.portal.spring.hibernate.FinderCache;
0037: import com.liferay.portal.spring.hibernate.HibernateUtil;
0038: import com.liferay.portal.util.PropsUtil;
0039:
0040: import com.liferay.util.dao.hibernate.QueryPos;
0041: import com.liferay.util.dao.hibernate.QueryUtil;
0042:
0043: import org.apache.commons.logging.Log;
0044: import org.apache.commons.logging.LogFactory;
0045:
0046: import org.hibernate.Hibernate;
0047: import org.hibernate.Query;
0048: import org.hibernate.SQLQuery;
0049: import org.hibernate.Session;
0050:
0051: import org.springframework.dao.DataAccessException;
0052:
0053: import org.springframework.jdbc.core.SqlParameter;
0054: import org.springframework.jdbc.object.MappingSqlQuery;
0055: import org.springframework.jdbc.object.SqlUpdate;
0056:
0057: import java.sql.ResultSet;
0058: import java.sql.SQLException;
0059: import java.sql.Types;
0060:
0061: import java.util.Collections;
0062: import java.util.Iterator;
0063: import java.util.List;
0064:
0065: /**
0066: * <a href="GroupPersistenceImpl.java.html"><b><i>View Source</i></b></a>
0067: *
0068: * @author Brian Wing Shun Chan
0069: *
0070: */
0071: public class GroupPersistenceImpl extends BasePersistence implements
0072: GroupPersistence {
0073: public Group create(long groupId) {
0074: Group group = new GroupImpl();
0075:
0076: group.setNew(true);
0077: group.setPrimaryKey(groupId);
0078:
0079: return group;
0080: }
0081:
0082: public Group remove(long groupId) throws NoSuchGroupException,
0083: SystemException {
0084: Session session = null;
0085:
0086: try {
0087: session = openSession();
0088:
0089: Group group = (Group) session.get(GroupImpl.class,
0090: new Long(groupId));
0091:
0092: if (group == null) {
0093: if (_log.isWarnEnabled()) {
0094: _log.warn("No Group exists with the primary key "
0095: + groupId);
0096: }
0097:
0098: throw new NoSuchGroupException(
0099: "No Group exists with the primary key "
0100: + groupId);
0101: }
0102:
0103: return remove(group);
0104: } catch (NoSuchGroupException nsee) {
0105: throw nsee;
0106: } catch (Exception e) {
0107: throw HibernateUtil.processException(e);
0108: } finally {
0109: closeSession(session);
0110: }
0111: }
0112:
0113: public Group remove(Group group) throws SystemException {
0114: ModelListener listener = _getListener();
0115:
0116: if (listener != null) {
0117: listener.onBeforeRemove(group);
0118: }
0119:
0120: group = removeImpl(group);
0121:
0122: if (listener != null) {
0123: listener.onAfterRemove(group);
0124: }
0125:
0126: return group;
0127: }
0128:
0129: protected Group removeImpl(Group group) throws SystemException {
0130: try {
0131: clearOrganizations.clear(group.getPrimaryKey());
0132: } catch (Exception e) {
0133: throw HibernateUtil.processException(e);
0134: } finally {
0135: FinderCache.clearCache("Groups_Orgs");
0136: }
0137:
0138: try {
0139: clearPermissions.clear(group.getPrimaryKey());
0140: } catch (Exception e) {
0141: throw HibernateUtil.processException(e);
0142: } finally {
0143: FinderCache.clearCache("Groups_Permissions");
0144: }
0145:
0146: try {
0147: clearRoles.clear(group.getPrimaryKey());
0148: } catch (Exception e) {
0149: throw HibernateUtil.processException(e);
0150: } finally {
0151: FinderCache.clearCache("Groups_Roles");
0152: }
0153:
0154: try {
0155: clearUserGroups.clear(group.getPrimaryKey());
0156: } catch (Exception e) {
0157: throw HibernateUtil.processException(e);
0158: } finally {
0159: FinderCache.clearCache("Groups_UserGroups");
0160: }
0161:
0162: try {
0163: clearUsers.clear(group.getPrimaryKey());
0164: } catch (Exception e) {
0165: throw HibernateUtil.processException(e);
0166: } finally {
0167: FinderCache.clearCache("Users_Groups");
0168: }
0169:
0170: Session session = null;
0171:
0172: try {
0173: session = openSession();
0174:
0175: session.delete(group);
0176:
0177: session.flush();
0178:
0179: return group;
0180: } catch (Exception e) {
0181: throw HibernateUtil.processException(e);
0182: } finally {
0183: closeSession(session);
0184:
0185: FinderCache.clearCache(Group.class.getName());
0186: }
0187: }
0188:
0189: public Group update(Group group) throws SystemException {
0190: return update(group, false);
0191: }
0192:
0193: public Group update(Group group, boolean merge)
0194: throws SystemException {
0195: ModelListener listener = _getListener();
0196:
0197: boolean isNew = group.isNew();
0198:
0199: if (listener != null) {
0200: if (isNew) {
0201: listener.onBeforeCreate(group);
0202: } else {
0203: listener.onBeforeUpdate(group);
0204: }
0205: }
0206:
0207: group = updateImpl(group, merge);
0208:
0209: if (listener != null) {
0210: if (isNew) {
0211: listener.onAfterCreate(group);
0212: } else {
0213: listener.onAfterUpdate(group);
0214: }
0215: }
0216:
0217: return group;
0218: }
0219:
0220: public Group updateImpl(com.liferay.portal.model.Group group,
0221: boolean merge) throws SystemException {
0222: FinderCache.clearCache("Groups_Orgs");
0223: FinderCache.clearCache("Groups_Permissions");
0224: FinderCache.clearCache("Groups_Roles");
0225: FinderCache.clearCache("Groups_UserGroups");
0226: FinderCache.clearCache("Users_Groups");
0227:
0228: Session session = null;
0229:
0230: try {
0231: session = openSession();
0232:
0233: if (merge) {
0234: session.merge(group);
0235: } else {
0236: if (group.isNew()) {
0237: session.save(group);
0238: }
0239: }
0240:
0241: session.flush();
0242:
0243: group.setNew(false);
0244:
0245: return group;
0246: } catch (Exception e) {
0247: throw HibernateUtil.processException(e);
0248: } finally {
0249: closeSession(session);
0250:
0251: FinderCache.clearCache(Group.class.getName());
0252: }
0253: }
0254:
0255: public Group findByPrimaryKey(long groupId)
0256: throws NoSuchGroupException, SystemException {
0257: Group group = fetchByPrimaryKey(groupId);
0258:
0259: if (group == null) {
0260: if (_log.isWarnEnabled()) {
0261: _log.warn("No Group exists with the primary key "
0262: + groupId);
0263: }
0264:
0265: throw new NoSuchGroupException(
0266: "No Group exists with the primary key " + groupId);
0267: }
0268:
0269: return group;
0270: }
0271:
0272: public Group fetchByPrimaryKey(long groupId) throws SystemException {
0273: Session session = null;
0274:
0275: try {
0276: session = openSession();
0277:
0278: return (Group) session.get(GroupImpl.class, new Long(
0279: groupId));
0280: } catch (Exception e) {
0281: throw HibernateUtil.processException(e);
0282: } finally {
0283: closeSession(session);
0284: }
0285: }
0286:
0287: public Group findByLiveGroupId(long liveGroupId)
0288: throws NoSuchGroupException, SystemException {
0289: Group group = fetchByLiveGroupId(liveGroupId);
0290:
0291: if (group == null) {
0292: StringMaker msg = new StringMaker();
0293:
0294: msg.append("No Group exists with the key {");
0295:
0296: msg.append("liveGroupId=" + liveGroupId);
0297:
0298: msg.append(StringPool.CLOSE_CURLY_BRACE);
0299:
0300: if (_log.isWarnEnabled()) {
0301: _log.warn(msg.toString());
0302: }
0303:
0304: throw new NoSuchGroupException(msg.toString());
0305: }
0306:
0307: return group;
0308: }
0309:
0310: public Group fetchByLiveGroupId(long liveGroupId)
0311: throws SystemException {
0312: boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED;
0313: String finderClassName = Group.class.getName();
0314: String finderMethodName = "fetchByLiveGroupId";
0315: String[] finderParams = new String[] { Long.class.getName() };
0316: Object[] finderArgs = new Object[] { new Long(liveGroupId) };
0317:
0318: Object result = null;
0319:
0320: if (finderClassNameCacheEnabled) {
0321: result = FinderCache.getResult(finderClassName,
0322: finderMethodName, finderParams, finderArgs,
0323: getSessionFactory());
0324: }
0325:
0326: if (result == null) {
0327: Session session = null;
0328:
0329: try {
0330: session = openSession();
0331:
0332: StringMaker query = new StringMaker();
0333:
0334: query
0335: .append("FROM com.liferay.portal.model.Group WHERE ");
0336:
0337: query.append("liveGroupId = ?");
0338:
0339: query.append(" ");
0340:
0341: query.append("ORDER BY ");
0342:
0343: query.append("name ASC");
0344:
0345: Query q = session.createQuery(query.toString());
0346:
0347: int queryPos = 0;
0348:
0349: q.setLong(queryPos++, liveGroupId);
0350:
0351: List list = q.list();
0352:
0353: FinderCache.putResult(finderClassNameCacheEnabled,
0354: finderClassName, finderMethodName,
0355: finderParams, finderArgs, list);
0356:
0357: if (list.size() == 0) {
0358: return null;
0359: } else {
0360: return (Group) list.get(0);
0361: }
0362: } catch (Exception e) {
0363: throw HibernateUtil.processException(e);
0364: } finally {
0365: closeSession(session);
0366: }
0367: } else {
0368: List list = (List) result;
0369:
0370: if (list.size() == 0) {
0371: return null;
0372: } else {
0373: return (Group) list.get(0);
0374: }
0375: }
0376: }
0377:
0378: public Group findByC_N(long companyId, String name)
0379: throws NoSuchGroupException, SystemException {
0380: Group group = fetchByC_N(companyId, name);
0381:
0382: if (group == null) {
0383: StringMaker msg = new StringMaker();
0384:
0385: msg.append("No Group exists with the key {");
0386:
0387: msg.append("companyId=" + companyId);
0388:
0389: msg.append(", ");
0390: msg.append("name=" + name);
0391:
0392: msg.append(StringPool.CLOSE_CURLY_BRACE);
0393:
0394: if (_log.isWarnEnabled()) {
0395: _log.warn(msg.toString());
0396: }
0397:
0398: throw new NoSuchGroupException(msg.toString());
0399: }
0400:
0401: return group;
0402: }
0403:
0404: public Group fetchByC_N(long companyId, String name)
0405: throws SystemException {
0406: boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED;
0407: String finderClassName = Group.class.getName();
0408: String finderMethodName = "fetchByC_N";
0409: String[] finderParams = new String[] { Long.class.getName(),
0410: String.class.getName() };
0411: Object[] finderArgs = new Object[] { new Long(companyId), name };
0412:
0413: Object result = null;
0414:
0415: if (finderClassNameCacheEnabled) {
0416: result = FinderCache.getResult(finderClassName,
0417: finderMethodName, finderParams, finderArgs,
0418: getSessionFactory());
0419: }
0420:
0421: if (result == null) {
0422: Session session = null;
0423:
0424: try {
0425: session = openSession();
0426:
0427: StringMaker query = new StringMaker();
0428:
0429: query
0430: .append("FROM com.liferay.portal.model.Group WHERE ");
0431:
0432: query.append("companyId = ?");
0433:
0434: query.append(" AND ");
0435:
0436: if (name == null) {
0437: query.append("name IS NULL");
0438: } else {
0439: query.append("name = ?");
0440: }
0441:
0442: query.append(" ");
0443:
0444: query.append("ORDER BY ");
0445:
0446: query.append("name ASC");
0447:
0448: Query q = session.createQuery(query.toString());
0449:
0450: int queryPos = 0;
0451:
0452: q.setLong(queryPos++, companyId);
0453:
0454: if (name != null) {
0455: q.setString(queryPos++, name);
0456: }
0457:
0458: List list = q.list();
0459:
0460: FinderCache.putResult(finderClassNameCacheEnabled,
0461: finderClassName, finderMethodName,
0462: finderParams, finderArgs, list);
0463:
0464: if (list.size() == 0) {
0465: return null;
0466: } else {
0467: return (Group) list.get(0);
0468: }
0469: } catch (Exception e) {
0470: throw HibernateUtil.processException(e);
0471: } finally {
0472: closeSession(session);
0473: }
0474: } else {
0475: List list = (List) result;
0476:
0477: if (list.size() == 0) {
0478: return null;
0479: } else {
0480: return (Group) list.get(0);
0481: }
0482: }
0483: }
0484:
0485: public Group findByC_F(long companyId, String friendlyURL)
0486: throws NoSuchGroupException, SystemException {
0487: Group group = fetchByC_F(companyId, friendlyURL);
0488:
0489: if (group == null) {
0490: StringMaker msg = new StringMaker();
0491:
0492: msg.append("No Group exists with the key {");
0493:
0494: msg.append("companyId=" + companyId);
0495:
0496: msg.append(", ");
0497: msg.append("friendlyURL=" + friendlyURL);
0498:
0499: msg.append(StringPool.CLOSE_CURLY_BRACE);
0500:
0501: if (_log.isWarnEnabled()) {
0502: _log.warn(msg.toString());
0503: }
0504:
0505: throw new NoSuchGroupException(msg.toString());
0506: }
0507:
0508: return group;
0509: }
0510:
0511: public Group fetchByC_F(long companyId, String friendlyURL)
0512: throws SystemException {
0513: boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED;
0514: String finderClassName = Group.class.getName();
0515: String finderMethodName = "fetchByC_F";
0516: String[] finderParams = new String[] { Long.class.getName(),
0517: String.class.getName() };
0518: Object[] finderArgs = new Object[] { new Long(companyId),
0519: friendlyURL };
0520:
0521: Object result = null;
0522:
0523: if (finderClassNameCacheEnabled) {
0524: result = FinderCache.getResult(finderClassName,
0525: finderMethodName, finderParams, finderArgs,
0526: getSessionFactory());
0527: }
0528:
0529: if (result == null) {
0530: Session session = null;
0531:
0532: try {
0533: session = openSession();
0534:
0535: StringMaker query = new StringMaker();
0536:
0537: query
0538: .append("FROM com.liferay.portal.model.Group WHERE ");
0539:
0540: query.append("companyId = ?");
0541:
0542: query.append(" AND ");
0543:
0544: if (friendlyURL == null) {
0545: query.append("friendlyURL IS NULL");
0546: } else {
0547: query.append("lower(friendlyURL) = ?");
0548: }
0549:
0550: query.append(" ");
0551:
0552: query.append("ORDER BY ");
0553:
0554: query.append("name ASC");
0555:
0556: Query q = session.createQuery(query.toString());
0557:
0558: int queryPos = 0;
0559:
0560: q.setLong(queryPos++, companyId);
0561:
0562: if (friendlyURL != null) {
0563: q.setString(queryPos++, friendlyURL);
0564: }
0565:
0566: List list = q.list();
0567:
0568: FinderCache.putResult(finderClassNameCacheEnabled,
0569: finderClassName, finderMethodName,
0570: finderParams, finderArgs, list);
0571:
0572: if (list.size() == 0) {
0573: return null;
0574: } else {
0575: return (Group) list.get(0);
0576: }
0577: } catch (Exception e) {
0578: throw HibernateUtil.processException(e);
0579: } finally {
0580: closeSession(session);
0581: }
0582: } else {
0583: List list = (List) result;
0584:
0585: if (list.size() == 0) {
0586: return null;
0587: } else {
0588: return (Group) list.get(0);
0589: }
0590: }
0591: }
0592:
0593: public Group findByC_C_C(long companyId, long classNameId,
0594: long classPK) throws NoSuchGroupException, SystemException {
0595: Group group = fetchByC_C_C(companyId, classNameId, classPK);
0596:
0597: if (group == null) {
0598: StringMaker msg = new StringMaker();
0599:
0600: msg.append("No Group exists with the key {");
0601:
0602: msg.append("companyId=" + companyId);
0603:
0604: msg.append(", ");
0605: msg.append("classNameId=" + classNameId);
0606:
0607: msg.append(", ");
0608: msg.append("classPK=" + classPK);
0609:
0610: msg.append(StringPool.CLOSE_CURLY_BRACE);
0611:
0612: if (_log.isWarnEnabled()) {
0613: _log.warn(msg.toString());
0614: }
0615:
0616: throw new NoSuchGroupException(msg.toString());
0617: }
0618:
0619: return group;
0620: }
0621:
0622: public Group fetchByC_C_C(long companyId, long classNameId,
0623: long classPK) throws SystemException {
0624: boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED;
0625: String finderClassName = Group.class.getName();
0626: String finderMethodName = "fetchByC_C_C";
0627: String[] finderParams = new String[] { Long.class.getName(),
0628: Long.class.getName(), Long.class.getName() };
0629: Object[] finderArgs = new Object[] { new Long(companyId),
0630: new Long(classNameId), new Long(classPK) };
0631:
0632: Object result = null;
0633:
0634: if (finderClassNameCacheEnabled) {
0635: result = FinderCache.getResult(finderClassName,
0636: finderMethodName, finderParams, finderArgs,
0637: getSessionFactory());
0638: }
0639:
0640: if (result == null) {
0641: Session session = null;
0642:
0643: try {
0644: session = openSession();
0645:
0646: StringMaker query = new StringMaker();
0647:
0648: query
0649: .append("FROM com.liferay.portal.model.Group WHERE ");
0650:
0651: query.append("companyId = ?");
0652:
0653: query.append(" AND ");
0654:
0655: query.append("classNameId = ?");
0656:
0657: query.append(" AND ");
0658:
0659: query.append("classPK = ?");
0660:
0661: query.append(" ");
0662:
0663: query.append("ORDER BY ");
0664:
0665: query.append("name ASC");
0666:
0667: Query q = session.createQuery(query.toString());
0668:
0669: int queryPos = 0;
0670:
0671: q.setLong(queryPos++, companyId);
0672:
0673: q.setLong(queryPos++, classNameId);
0674:
0675: q.setLong(queryPos++, classPK);
0676:
0677: List list = q.list();
0678:
0679: FinderCache.putResult(finderClassNameCacheEnabled,
0680: finderClassName, finderMethodName,
0681: finderParams, finderArgs, list);
0682:
0683: if (list.size() == 0) {
0684: return null;
0685: } else {
0686: return (Group) list.get(0);
0687: }
0688: } catch (Exception e) {
0689: throw HibernateUtil.processException(e);
0690: } finally {
0691: closeSession(session);
0692: }
0693: } else {
0694: List list = (List) result;
0695:
0696: if (list.size() == 0) {
0697: return null;
0698: } else {
0699: return (Group) list.get(0);
0700: }
0701: }
0702: }
0703:
0704: public List findWithDynamicQuery(
0705: DynamicQueryInitializer queryInitializer)
0706: throws SystemException {
0707: Session session = null;
0708:
0709: try {
0710: session = openSession();
0711:
0712: DynamicQuery query = queryInitializer.initialize(session);
0713:
0714: return query.list();
0715: } catch (Exception e) {
0716: throw HibernateUtil.processException(e);
0717: } finally {
0718: closeSession(session);
0719: }
0720: }
0721:
0722: public List findWithDynamicQuery(
0723: DynamicQueryInitializer queryInitializer, int begin, int end)
0724: throws SystemException {
0725: Session session = null;
0726:
0727: try {
0728: session = openSession();
0729:
0730: DynamicQuery query = queryInitializer.initialize(session);
0731:
0732: query.setLimit(begin, end);
0733:
0734: return query.list();
0735: } catch (Exception e) {
0736: throw HibernateUtil.processException(e);
0737: } finally {
0738: closeSession(session);
0739: }
0740: }
0741:
0742: public List findAll() throws SystemException {
0743: return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
0744: }
0745:
0746: public List findAll(int begin, int end) throws SystemException {
0747: return findAll(begin, end, null);
0748: }
0749:
0750: public List findAll(int begin, int end, OrderByComparator obc)
0751: throws SystemException {
0752: boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED;
0753: String finderClassName = Group.class.getName();
0754: String finderMethodName = "findAll";
0755: String[] finderParams = new String[] { "java.lang.Integer",
0756: "java.lang.Integer",
0757: "com.liferay.portal.kernel.util.OrderByComparator" };
0758: Object[] finderArgs = new Object[] { String.valueOf(begin),
0759: String.valueOf(end), String.valueOf(obc) };
0760:
0761: Object result = null;
0762:
0763: if (finderClassNameCacheEnabled) {
0764: result = FinderCache.getResult(finderClassName,
0765: finderMethodName, finderParams, finderArgs,
0766: getSessionFactory());
0767: }
0768:
0769: if (result == null) {
0770: Session session = null;
0771:
0772: try {
0773: session = openSession();
0774:
0775: StringMaker query = new StringMaker();
0776:
0777: query.append("FROM com.liferay.portal.model.Group ");
0778:
0779: if (obc != null) {
0780: query.append("ORDER BY ");
0781: query.append(obc.getOrderBy());
0782: }
0783:
0784: else {
0785: query.append("ORDER BY ");
0786:
0787: query.append("name ASC");
0788: }
0789:
0790: Query q = session.createQuery(query.toString());
0791:
0792: List list = QueryUtil.list(q, getDialect(), begin, end);
0793:
0794: if (obc == null) {
0795: Collections.sort(list);
0796: }
0797:
0798: FinderCache.putResult(finderClassNameCacheEnabled,
0799: finderClassName, finderMethodName,
0800: finderParams, finderArgs, list);
0801:
0802: return list;
0803: } catch (Exception e) {
0804: throw HibernateUtil.processException(e);
0805: } finally {
0806: closeSession(session);
0807: }
0808: } else {
0809: return (List) result;
0810: }
0811: }
0812:
0813: public void removeByLiveGroupId(long liveGroupId)
0814: throws NoSuchGroupException, SystemException {
0815: Group group = findByLiveGroupId(liveGroupId);
0816:
0817: remove(group);
0818: }
0819:
0820: public void removeByC_N(long companyId, String name)
0821: throws NoSuchGroupException, SystemException {
0822: Group group = findByC_N(companyId, name);
0823:
0824: remove(group);
0825: }
0826:
0827: public void removeByC_F(long companyId, String friendlyURL)
0828: throws NoSuchGroupException, SystemException {
0829: Group group = findByC_F(companyId, friendlyURL);
0830:
0831: remove(group);
0832: }
0833:
0834: public void removeByC_C_C(long companyId, long classNameId,
0835: long classPK) throws NoSuchGroupException, SystemException {
0836: Group group = findByC_C_C(companyId, classNameId, classPK);
0837:
0838: remove(group);
0839: }
0840:
0841: public void removeAll() throws SystemException {
0842: Iterator itr = findAll().iterator();
0843:
0844: while (itr.hasNext()) {
0845: remove((Group) itr.next());
0846: }
0847: }
0848:
0849: public int countByLiveGroupId(long liveGroupId)
0850: throws SystemException {
0851: boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED;
0852: String finderClassName = Group.class.getName();
0853: String finderMethodName = "countByLiveGroupId";
0854: String[] finderParams = new String[] { Long.class.getName() };
0855: Object[] finderArgs = new Object[] { new Long(liveGroupId) };
0856:
0857: Object result = null;
0858:
0859: if (finderClassNameCacheEnabled) {
0860: result = FinderCache.getResult(finderClassName,
0861: finderMethodName, finderParams, finderArgs,
0862: getSessionFactory());
0863: }
0864:
0865: if (result == null) {
0866: Session session = null;
0867:
0868: try {
0869: session = openSession();
0870:
0871: StringMaker query = new StringMaker();
0872:
0873: query.append("SELECT COUNT(*) ");
0874: query
0875: .append("FROM com.liferay.portal.model.Group WHERE ");
0876:
0877: query.append("liveGroupId = ?");
0878:
0879: query.append(" ");
0880:
0881: Query q = session.createQuery(query.toString());
0882:
0883: int queryPos = 0;
0884:
0885: q.setLong(queryPos++, liveGroupId);
0886:
0887: Long count = null;
0888:
0889: Iterator itr = q.list().iterator();
0890:
0891: if (itr.hasNext()) {
0892: count = (Long) itr.next();
0893: }
0894:
0895: if (count == null) {
0896: count = new Long(0);
0897: }
0898:
0899: FinderCache.putResult(finderClassNameCacheEnabled,
0900: finderClassName, finderMethodName,
0901: finderParams, finderArgs, count);
0902:
0903: return count.intValue();
0904: } catch (Exception e) {
0905: throw HibernateUtil.processException(e);
0906: } finally {
0907: closeSession(session);
0908: }
0909: } else {
0910: return ((Long) result).intValue();
0911: }
0912: }
0913:
0914: public int countByC_N(long companyId, String name)
0915: throws SystemException {
0916: boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED;
0917: String finderClassName = Group.class.getName();
0918: String finderMethodName = "countByC_N";
0919: String[] finderParams = new String[] { Long.class.getName(),
0920: String.class.getName() };
0921: Object[] finderArgs = new Object[] { new Long(companyId), name };
0922:
0923: Object result = null;
0924:
0925: if (finderClassNameCacheEnabled) {
0926: result = FinderCache.getResult(finderClassName,
0927: finderMethodName, finderParams, finderArgs,
0928: getSessionFactory());
0929: }
0930:
0931: if (result == null) {
0932: Session session = null;
0933:
0934: try {
0935: session = openSession();
0936:
0937: StringMaker query = new StringMaker();
0938:
0939: query.append("SELECT COUNT(*) ");
0940: query
0941: .append("FROM com.liferay.portal.model.Group WHERE ");
0942:
0943: query.append("companyId = ?");
0944:
0945: query.append(" AND ");
0946:
0947: if (name == null) {
0948: query.append("name IS NULL");
0949: } else {
0950: query.append("name = ?");
0951: }
0952:
0953: query.append(" ");
0954:
0955: Query q = session.createQuery(query.toString());
0956:
0957: int queryPos = 0;
0958:
0959: q.setLong(queryPos++, companyId);
0960:
0961: if (name != null) {
0962: q.setString(queryPos++, name);
0963: }
0964:
0965: Long count = null;
0966:
0967: Iterator itr = q.list().iterator();
0968:
0969: if (itr.hasNext()) {
0970: count = (Long) itr.next();
0971: }
0972:
0973: if (count == null) {
0974: count = new Long(0);
0975: }
0976:
0977: FinderCache.putResult(finderClassNameCacheEnabled,
0978: finderClassName, finderMethodName,
0979: finderParams, finderArgs, count);
0980:
0981: return count.intValue();
0982: } catch (Exception e) {
0983: throw HibernateUtil.processException(e);
0984: } finally {
0985: closeSession(session);
0986: }
0987: } else {
0988: return ((Long) result).intValue();
0989: }
0990: }
0991:
0992: public int countByC_F(long companyId, String friendlyURL)
0993: throws SystemException {
0994: boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED;
0995: String finderClassName = Group.class.getName();
0996: String finderMethodName = "countByC_F";
0997: String[] finderParams = new String[] { Long.class.getName(),
0998: String.class.getName() };
0999: Object[] finderArgs = new Object[] { new Long(companyId),
1000: friendlyURL };
1001:
1002: Object result = null;
1003:
1004: if (finderClassNameCacheEnabled) {
1005: result = FinderCache.getResult(finderClassName,
1006: finderMethodName, finderParams, finderArgs,
1007: getSessionFactory());
1008: }
1009:
1010: if (result == null) {
1011: Session session = null;
1012:
1013: try {
1014: session = openSession();
1015:
1016: StringMaker query = new StringMaker();
1017:
1018: query.append("SELECT COUNT(*) ");
1019: query
1020: .append("FROM com.liferay.portal.model.Group WHERE ");
1021:
1022: query.append("companyId = ?");
1023:
1024: query.append(" AND ");
1025:
1026: if (friendlyURL == null) {
1027: query.append("friendlyURL IS NULL");
1028: } else {
1029: query.append("lower(friendlyURL) = ?");
1030: }
1031:
1032: query.append(" ");
1033:
1034: Query q = session.createQuery(query.toString());
1035:
1036: int queryPos = 0;
1037:
1038: q.setLong(queryPos++, companyId);
1039:
1040: if (friendlyURL != null) {
1041: q.setString(queryPos++, friendlyURL);
1042: }
1043:
1044: Long count = null;
1045:
1046: Iterator itr = q.list().iterator();
1047:
1048: if (itr.hasNext()) {
1049: count = (Long) itr.next();
1050: }
1051:
1052: if (count == null) {
1053: count = new Long(0);
1054: }
1055:
1056: FinderCache.putResult(finderClassNameCacheEnabled,
1057: finderClassName, finderMethodName,
1058: finderParams, finderArgs, count);
1059:
1060: return count.intValue();
1061: } catch (Exception e) {
1062: throw HibernateUtil.processException(e);
1063: } finally {
1064: closeSession(session);
1065: }
1066: } else {
1067: return ((Long) result).intValue();
1068: }
1069: }
1070:
1071: public int countByC_C_C(long companyId, long classNameId,
1072: long classPK) throws SystemException {
1073: boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED;
1074: String finderClassName = Group.class.getName();
1075: String finderMethodName = "countByC_C_C";
1076: String[] finderParams = new String[] { Long.class.getName(),
1077: Long.class.getName(), Long.class.getName() };
1078: Object[] finderArgs = new Object[] { new Long(companyId),
1079: new Long(classNameId), new Long(classPK) };
1080:
1081: Object result = null;
1082:
1083: if (finderClassNameCacheEnabled) {
1084: result = FinderCache.getResult(finderClassName,
1085: finderMethodName, finderParams, finderArgs,
1086: getSessionFactory());
1087: }
1088:
1089: if (result == null) {
1090: Session session = null;
1091:
1092: try {
1093: session = openSession();
1094:
1095: StringMaker query = new StringMaker();
1096:
1097: query.append("SELECT COUNT(*) ");
1098: query
1099: .append("FROM com.liferay.portal.model.Group WHERE ");
1100:
1101: query.append("companyId = ?");
1102:
1103: query.append(" AND ");
1104:
1105: query.append("classNameId = ?");
1106:
1107: query.append(" AND ");
1108:
1109: query.append("classPK = ?");
1110:
1111: query.append(" ");
1112:
1113: Query q = session.createQuery(query.toString());
1114:
1115: int queryPos = 0;
1116:
1117: q.setLong(queryPos++, companyId);
1118:
1119: q.setLong(queryPos++, classNameId);
1120:
1121: q.setLong(queryPos++, classPK);
1122:
1123: Long count = null;
1124:
1125: Iterator itr = q.list().iterator();
1126:
1127: if (itr.hasNext()) {
1128: count = (Long) itr.next();
1129: }
1130:
1131: if (count == null) {
1132: count = new Long(0);
1133: }
1134:
1135: FinderCache.putResult(finderClassNameCacheEnabled,
1136: finderClassName, finderMethodName,
1137: finderParams, finderArgs, count);
1138:
1139: return count.intValue();
1140: } catch (Exception e) {
1141: throw HibernateUtil.processException(e);
1142: } finally {
1143: closeSession(session);
1144: }
1145: } else {
1146: return ((Long) result).intValue();
1147: }
1148: }
1149:
1150: public int countAll() throws SystemException {
1151: boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED;
1152: String finderClassName = Group.class.getName();
1153: String finderMethodName = "countAll";
1154: String[] finderParams = new String[] {};
1155: Object[] finderArgs = new Object[] {};
1156:
1157: Object result = null;
1158:
1159: if (finderClassNameCacheEnabled) {
1160: result = FinderCache.getResult(finderClassName,
1161: finderMethodName, finderParams, finderArgs,
1162: getSessionFactory());
1163: }
1164:
1165: if (result == null) {
1166: Session session = null;
1167:
1168: try {
1169: session = openSession();
1170:
1171: Query q = session
1172: .createQuery("SELECT COUNT(*) FROM com.liferay.portal.model.Group");
1173:
1174: Long count = null;
1175:
1176: Iterator itr = q.list().iterator();
1177:
1178: if (itr.hasNext()) {
1179: count = (Long) itr.next();
1180: }
1181:
1182: if (count == null) {
1183: count = new Long(0);
1184: }
1185:
1186: FinderCache.putResult(finderClassNameCacheEnabled,
1187: finderClassName, finderMethodName,
1188: finderParams, finderArgs, count);
1189:
1190: return count.intValue();
1191: } catch (Exception e) {
1192: throw HibernateUtil.processException(e);
1193: } finally {
1194: closeSession(session);
1195: }
1196: } else {
1197: return ((Long) result).intValue();
1198: }
1199: }
1200:
1201: public List getOrganizations(long pk) throws NoSuchGroupException,
1202: SystemException {
1203: return getOrganizations(pk, QueryUtil.ALL_POS,
1204: QueryUtil.ALL_POS);
1205: }
1206:
1207: public List getOrganizations(long pk, int begin, int end)
1208: throws NoSuchGroupException, SystemException {
1209: return getOrganizations(pk, begin, end, null);
1210: }
1211:
1212: public List getOrganizations(long pk, int begin, int end,
1213: OrderByComparator obc) throws NoSuchGroupException,
1214: SystemException {
1215: boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED_GROUPS_ORGS;
1216: String finderClassName = "Groups_Orgs";
1217: String finderMethodName = "getOrganizations";
1218: String[] finderParams = new String[] { Long.class.getName(),
1219: "java.lang.Integer", "java.lang.Integer",
1220: "com.liferay.portal.kernel.util.OrderByComparator" };
1221: Object[] finderArgs = new Object[] { new Long(pk),
1222: String.valueOf(begin), String.valueOf(end),
1223: String.valueOf(obc) };
1224:
1225: Object result = null;
1226:
1227: if (finderClassNameCacheEnabled) {
1228: result = FinderCache.getResult(finderClassName,
1229: finderMethodName, finderParams, finderArgs,
1230: getSessionFactory());
1231: }
1232:
1233: if (result == null) {
1234: Session session = null;
1235:
1236: try {
1237: session = HibernateUtil.openSession();
1238:
1239: StringMaker sm = new StringMaker();
1240:
1241: sm.append(_SQL_GETORGANIZATIONS);
1242:
1243: if (obc != null) {
1244: sm.append("ORDER BY ");
1245: sm.append(obc.getOrderBy());
1246: }
1247:
1248: else {
1249: sm.append("ORDER BY ");
1250:
1251: sm.append("Organization_.name ASC");
1252: }
1253:
1254: String sql = sm.toString();
1255:
1256: SQLQuery q = session.createSQLQuery(sql);
1257:
1258: q
1259: .addEntity(
1260: "Organization_",
1261: com.liferay.portal.model.impl.OrganizationImpl.class);
1262:
1263: QueryPos qPos = QueryPos.getInstance(q);
1264:
1265: qPos.add(pk);
1266:
1267: List list = QueryUtil.list(q, getDialect(), begin, end);
1268:
1269: FinderCache.putResult(finderClassNameCacheEnabled,
1270: finderClassName, finderMethodName,
1271: finderParams, finderArgs, list);
1272:
1273: return list;
1274: } catch (Exception e) {
1275: throw new SystemException(e);
1276: } finally {
1277: closeSession(session);
1278: }
1279: } else {
1280: return (List) result;
1281: }
1282: }
1283:
1284: public int getOrganizationsSize(long pk) throws SystemException {
1285: boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED_GROUPS_ORGS;
1286: String finderClassName = "Groups_Orgs";
1287: String finderMethodName = "getOrganizationsSize";
1288: String[] finderParams = new String[] { Long.class.getName() };
1289: Object[] finderArgs = new Object[] { new Long(pk) };
1290:
1291: Object result = null;
1292:
1293: if (finderClassNameCacheEnabled) {
1294: result = FinderCache.getResult(finderClassName,
1295: finderMethodName, finderParams, finderArgs,
1296: getSessionFactory());
1297: }
1298:
1299: if (result == null) {
1300: Session session = null;
1301:
1302: try {
1303: session = openSession();
1304:
1305: SQLQuery q = session
1306: .createSQLQuery(_SQL_GETORGANIZATIONSSIZE);
1307:
1308: q.addScalar(HibernateUtil.getCountColumnName(),
1309: Hibernate.LONG);
1310:
1311: QueryPos qPos = QueryPos.getInstance(q);
1312:
1313: qPos.add(pk);
1314:
1315: Long count = null;
1316:
1317: Iterator itr = q.list().iterator();
1318:
1319: if (itr.hasNext()) {
1320: count = (Long) itr.next();
1321: }
1322:
1323: if (count == null) {
1324: count = new Long(0);
1325: }
1326:
1327: FinderCache.putResult(finderClassNameCacheEnabled,
1328: finderClassName, finderMethodName,
1329: finderParams, finderArgs, count);
1330:
1331: return count.intValue();
1332: } catch (Exception e) {
1333: throw HibernateUtil.processException(e);
1334: } finally {
1335: closeSession(session);
1336: }
1337: } else {
1338: return ((Long) result).intValue();
1339: }
1340: }
1341:
1342: public boolean containsOrganization(long pk, long organizationPK)
1343: throws SystemException {
1344: boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED_GROUPS_ORGS;
1345: String finderClassName = "Groups_Orgs";
1346: String finderMethodName = "containsOrganizations";
1347: String[] finderParams = new String[] { Long.class.getName(),
1348:
1349: Long.class.getName() };
1350: Object[] finderArgs = new Object[] { new Long(pk),
1351:
1352: new Long(organizationPK) };
1353:
1354: Object result = null;
1355:
1356: if (finderClassNameCacheEnabled) {
1357: result = FinderCache.getResult(finderClassName,
1358: finderMethodName, finderParams, finderArgs,
1359: getSessionFactory());
1360: }
1361:
1362: if (result == null) {
1363: try {
1364: Boolean value = Boolean.valueOf(containsOrganization
1365: .contains(pk, organizationPK));
1366:
1367: FinderCache.putResult(finderClassNameCacheEnabled,
1368: finderClassName, finderMethodName,
1369: finderParams, finderArgs, value);
1370:
1371: return value.booleanValue();
1372: } catch (DataAccessException dae) {
1373: throw new SystemException(dae);
1374: }
1375: } else {
1376: return ((Boolean) result).booleanValue();
1377: }
1378: }
1379:
1380: public boolean containsOrganizations(long pk)
1381: throws SystemException {
1382: if (getOrganizationsSize(pk) > 0) {
1383: return true;
1384: } else {
1385: return false;
1386: }
1387: }
1388:
1389: public void addOrganization(long pk, long organizationPK)
1390: throws NoSuchGroupException,
1391: com.liferay.portal.NoSuchOrganizationException,
1392: SystemException {
1393: try {
1394: addOrganization.add(pk, organizationPK);
1395: } catch (DataAccessException dae) {
1396: throw new SystemException(dae);
1397: } finally {
1398: FinderCache.clearCache("Groups_Orgs");
1399: }
1400: }
1401:
1402: public void addOrganization(long pk,
1403: com.liferay.portal.model.Organization organization)
1404: throws NoSuchGroupException,
1405: com.liferay.portal.NoSuchOrganizationException,
1406: SystemException {
1407: try {
1408: addOrganization.add(pk, organization.getPrimaryKey());
1409: } catch (DataAccessException dae) {
1410: throw new SystemException(dae);
1411: } finally {
1412: FinderCache.clearCache("Groups_Orgs");
1413: }
1414: }
1415:
1416: public void addOrganizations(long pk, long[] organizationPKs)
1417: throws NoSuchGroupException,
1418: com.liferay.portal.NoSuchOrganizationException,
1419: SystemException {
1420: try {
1421: for (int i = 0; i < organizationPKs.length; i++) {
1422: addOrganization.add(pk, organizationPKs[i]);
1423: }
1424: } catch (DataAccessException dae) {
1425: throw new SystemException(dae);
1426: } finally {
1427: FinderCache.clearCache("Groups_Orgs");
1428: }
1429: }
1430:
1431: public void addOrganizations(long pk, List organizations)
1432: throws NoSuchGroupException,
1433: com.liferay.portal.NoSuchOrganizationException,
1434: SystemException {
1435: try {
1436: for (int i = 0; i < organizations.size(); i++) {
1437: com.liferay.portal.model.Organization organization = (com.liferay.portal.model.Organization) organizations
1438: .get(i);
1439:
1440: addOrganization.add(pk, organization.getPrimaryKey());
1441: }
1442: } catch (DataAccessException dae) {
1443: throw new SystemException(dae);
1444: } finally {
1445: FinderCache.clearCache("Groups_Orgs");
1446: }
1447: }
1448:
1449: public void clearOrganizations(long pk)
1450: throws NoSuchGroupException, SystemException {
1451: try {
1452: clearOrganizations.clear(pk);
1453: } catch (DataAccessException dae) {
1454: throw new SystemException(dae);
1455: } finally {
1456: FinderCache.clearCache("Groups_Orgs");
1457: }
1458: }
1459:
1460: public void removeOrganization(long pk, long organizationPK)
1461: throws NoSuchGroupException,
1462: com.liferay.portal.NoSuchOrganizationException,
1463: SystemException {
1464: try {
1465: removeOrganization.remove(pk, organizationPK);
1466: } catch (DataAccessException dae) {
1467: throw new SystemException(dae);
1468: } finally {
1469: FinderCache.clearCache("Groups_Orgs");
1470: }
1471: }
1472:
1473: public void removeOrganization(long pk,
1474: com.liferay.portal.model.Organization organization)
1475: throws NoSuchGroupException,
1476: com.liferay.portal.NoSuchOrganizationException,
1477: SystemException {
1478: try {
1479: removeOrganization.remove(pk, organization.getPrimaryKey());
1480: } catch (DataAccessException dae) {
1481: throw new SystemException(dae);
1482: } finally {
1483: FinderCache.clearCache("Groups_Orgs");
1484: }
1485: }
1486:
1487: public void removeOrganizations(long pk, long[] organizationPKs)
1488: throws NoSuchGroupException,
1489: com.liferay.portal.NoSuchOrganizationException,
1490: SystemException {
1491: try {
1492: for (int i = 0; i < organizationPKs.length; i++) {
1493: removeOrganization.remove(pk, organizationPKs[i]);
1494: }
1495: } catch (DataAccessException dae) {
1496: throw new SystemException(dae);
1497: } finally {
1498: FinderCache.clearCache("Groups_Orgs");
1499: }
1500: }
1501:
1502: public void removeOrganizations(long pk, List organizations)
1503: throws NoSuchGroupException,
1504: com.liferay.portal.NoSuchOrganizationException,
1505: SystemException {
1506: try {
1507: for (int i = 0; i < organizations.size(); i++) {
1508: com.liferay.portal.model.Organization organization = (com.liferay.portal.model.Organization) organizations
1509: .get(i);
1510:
1511: removeOrganization.remove(pk, organization
1512: .getPrimaryKey());
1513: }
1514: } catch (DataAccessException dae) {
1515: throw new SystemException(dae);
1516: } finally {
1517: FinderCache.clearCache("Groups_Orgs");
1518: }
1519: }
1520:
1521: public void setOrganizations(long pk, long[] organizationPKs)
1522: throws NoSuchGroupException,
1523: com.liferay.portal.NoSuchOrganizationException,
1524: SystemException {
1525: try {
1526: clearOrganizations.clear(pk);
1527:
1528: for (int i = 0; i < organizationPKs.length; i++) {
1529: addOrganization.add(pk, organizationPKs[i]);
1530: }
1531: } catch (DataAccessException dae) {
1532: throw new SystemException(dae);
1533: } finally {
1534: FinderCache.clearCache("Groups_Orgs");
1535: }
1536: }
1537:
1538: public void setOrganizations(long pk, List organizations)
1539: throws NoSuchGroupException,
1540: com.liferay.portal.NoSuchOrganizationException,
1541: SystemException {
1542: try {
1543: clearOrganizations.clear(pk);
1544:
1545: for (int i = 0; i < organizations.size(); i++) {
1546: com.liferay.portal.model.Organization organization = (com.liferay.portal.model.Organization) organizations
1547: .get(i);
1548:
1549: addOrganization.add(pk, organization.getPrimaryKey());
1550: }
1551: } catch (DataAccessException dae) {
1552: throw new SystemException(dae);
1553: } finally {
1554: FinderCache.clearCache("Groups_Orgs");
1555: }
1556: }
1557:
1558: public List getPermissions(long pk) throws NoSuchGroupException,
1559: SystemException {
1560: return getPermissions(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1561: }
1562:
1563: public List getPermissions(long pk, int begin, int end)
1564: throws NoSuchGroupException, SystemException {
1565: return getPermissions(pk, begin, end, null);
1566: }
1567:
1568: public List getPermissions(long pk, int begin, int end,
1569: OrderByComparator obc) throws NoSuchGroupException,
1570: SystemException {
1571: boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED_GROUPS_PERMISSIONS;
1572: String finderClassName = "Groups_Permissions";
1573: String finderMethodName = "getPermissions";
1574: String[] finderParams = new String[] { Long.class.getName(),
1575: "java.lang.Integer", "java.lang.Integer",
1576: "com.liferay.portal.kernel.util.OrderByComparator" };
1577: Object[] finderArgs = new Object[] { new Long(pk),
1578: String.valueOf(begin), String.valueOf(end),
1579: String.valueOf(obc) };
1580:
1581: Object result = null;
1582:
1583: if (finderClassNameCacheEnabled) {
1584: result = FinderCache.getResult(finderClassName,
1585: finderMethodName, finderParams, finderArgs,
1586: getSessionFactory());
1587: }
1588:
1589: if (result == null) {
1590: Session session = null;
1591:
1592: try {
1593: session = HibernateUtil.openSession();
1594:
1595: StringMaker sm = new StringMaker();
1596:
1597: sm.append(_SQL_GETPERMISSIONS);
1598:
1599: if (obc != null) {
1600: sm.append("ORDER BY ");
1601: sm.append(obc.getOrderBy());
1602: }
1603:
1604: String sql = sm.toString();
1605:
1606: SQLQuery q = session.createSQLQuery(sql);
1607:
1608: q
1609: .addEntity(
1610: "Permission_",
1611: com.liferay.portal.model.impl.PermissionImpl.class);
1612:
1613: QueryPos qPos = QueryPos.getInstance(q);
1614:
1615: qPos.add(pk);
1616:
1617: List list = QueryUtil.list(q, getDialect(), begin, end);
1618:
1619: FinderCache.putResult(finderClassNameCacheEnabled,
1620: finderClassName, finderMethodName,
1621: finderParams, finderArgs, list);
1622:
1623: return list;
1624: } catch (Exception e) {
1625: throw new SystemException(e);
1626: } finally {
1627: closeSession(session);
1628: }
1629: } else {
1630: return (List) result;
1631: }
1632: }
1633:
1634: public int getPermissionsSize(long pk) throws SystemException {
1635: boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED_GROUPS_PERMISSIONS;
1636: String finderClassName = "Groups_Permissions";
1637: String finderMethodName = "getPermissionsSize";
1638: String[] finderParams = new String[] { Long.class.getName() };
1639: Object[] finderArgs = new Object[] { new Long(pk) };
1640:
1641: Object result = null;
1642:
1643: if (finderClassNameCacheEnabled) {
1644: result = FinderCache.getResult(finderClassName,
1645: finderMethodName, finderParams, finderArgs,
1646: getSessionFactory());
1647: }
1648:
1649: if (result == null) {
1650: Session session = null;
1651:
1652: try {
1653: session = openSession();
1654:
1655: SQLQuery q = session
1656: .createSQLQuery(_SQL_GETPERMISSIONSSIZE);
1657:
1658: q.addScalar(HibernateUtil.getCountColumnName(),
1659: Hibernate.LONG);
1660:
1661: QueryPos qPos = QueryPos.getInstance(q);
1662:
1663: qPos.add(pk);
1664:
1665: Long count = null;
1666:
1667: Iterator itr = q.list().iterator();
1668:
1669: if (itr.hasNext()) {
1670: count = (Long) itr.next();
1671: }
1672:
1673: if (count == null) {
1674: count = new Long(0);
1675: }
1676:
1677: FinderCache.putResult(finderClassNameCacheEnabled,
1678: finderClassName, finderMethodName,
1679: finderParams, finderArgs, count);
1680:
1681: return count.intValue();
1682: } catch (Exception e) {
1683: throw HibernateUtil.processException(e);
1684: } finally {
1685: closeSession(session);
1686: }
1687: } else {
1688: return ((Long) result).intValue();
1689: }
1690: }
1691:
1692: public boolean containsPermission(long pk, long permissionPK)
1693: throws SystemException {
1694: boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED_GROUPS_PERMISSIONS;
1695: String finderClassName = "Groups_Permissions";
1696: String finderMethodName = "containsPermissions";
1697: String[] finderParams = new String[] { Long.class.getName(),
1698:
1699: Long.class.getName() };
1700: Object[] finderArgs = new Object[] { new Long(pk),
1701: new Long(permissionPK) };
1702:
1703: Object result = null;
1704:
1705: if (finderClassNameCacheEnabled) {
1706: result = FinderCache.getResult(finderClassName,
1707: finderMethodName, finderParams, finderArgs,
1708: getSessionFactory());
1709: }
1710:
1711: if (result == null) {
1712: try {
1713: Boolean value = Boolean.valueOf(containsPermission
1714: .contains(pk, permissionPK));
1715:
1716: FinderCache.putResult(finderClassNameCacheEnabled,
1717: finderClassName, finderMethodName,
1718: finderParams, finderArgs, value);
1719:
1720: return value.booleanValue();
1721: } catch (DataAccessException dae) {
1722: throw new SystemException(dae);
1723: }
1724: } else {
1725: return ((Boolean) result).booleanValue();
1726: }
1727: }
1728:
1729: public boolean containsPermissions(long pk) throws SystemException {
1730: if (getPermissionsSize(pk) > 0) {
1731: return true;
1732: } else {
1733: return false;
1734: }
1735: }
1736:
1737: public void addPermission(long pk, long permissionPK)
1738: throws NoSuchGroupException,
1739: com.liferay.portal.NoSuchPermissionException,
1740: SystemException {
1741: try {
1742: addPermission.add(pk, permissionPK);
1743: } catch (DataAccessException dae) {
1744: throw new SystemException(dae);
1745: } finally {
1746: FinderCache.clearCache("Groups_Permissions");
1747: }
1748: }
1749:
1750: public void addPermission(long pk,
1751: com.liferay.portal.model.Permission permission)
1752: throws NoSuchGroupException,
1753: com.liferay.portal.NoSuchPermissionException,
1754: SystemException {
1755: try {
1756: addPermission.add(pk, permission.getPrimaryKey());
1757: } catch (DataAccessException dae) {
1758: throw new SystemException(dae);
1759: } finally {
1760: FinderCache.clearCache("Groups_Permissions");
1761: }
1762: }
1763:
1764: public void addPermissions(long pk, long[] permissionPKs)
1765: throws NoSuchGroupException,
1766: com.liferay.portal.NoSuchPermissionException,
1767: SystemException {
1768: try {
1769: for (int i = 0; i < permissionPKs.length; i++) {
1770: addPermission.add(pk, permissionPKs[i]);
1771: }
1772: } catch (DataAccessException dae) {
1773: throw new SystemException(dae);
1774: } finally {
1775: FinderCache.clearCache("Groups_Permissions");
1776: }
1777: }
1778:
1779: public void addPermissions(long pk, List permissions)
1780: throws NoSuchGroupException,
1781: com.liferay.portal.NoSuchPermissionException,
1782: SystemException {
1783: try {
1784: for (int i = 0; i < permissions.size(); i++) {
1785: com.liferay.portal.model.Permission permission = (com.liferay.portal.model.Permission) permissions
1786: .get(i);
1787:
1788: addPermission.add(pk, permission.getPrimaryKey());
1789: }
1790: } catch (DataAccessException dae) {
1791: throw new SystemException(dae);
1792: } finally {
1793: FinderCache.clearCache("Groups_Permissions");
1794: }
1795: }
1796:
1797: public void clearPermissions(long pk) throws NoSuchGroupException,
1798: SystemException {
1799: try {
1800: clearPermissions.clear(pk);
1801: } catch (DataAccessException dae) {
1802: throw new SystemException(dae);
1803: } finally {
1804: FinderCache.clearCache("Groups_Permissions");
1805: }
1806: }
1807:
1808: public void removePermission(long pk, long permissionPK)
1809: throws NoSuchGroupException,
1810: com.liferay.portal.NoSuchPermissionException,
1811: SystemException {
1812: try {
1813: removePermission.remove(pk, permissionPK);
1814: } catch (DataAccessException dae) {
1815: throw new SystemException(dae);
1816: } finally {
1817: FinderCache.clearCache("Groups_Permissions");
1818: }
1819: }
1820:
1821: public void removePermission(long pk,
1822: com.liferay.portal.model.Permission permission)
1823: throws NoSuchGroupException,
1824: com.liferay.portal.NoSuchPermissionException,
1825: SystemException {
1826: try {
1827: removePermission.remove(pk, permission.getPrimaryKey());
1828: } catch (DataAccessException dae) {
1829: throw new SystemException(dae);
1830: } finally {
1831: FinderCache.clearCache("Groups_Permissions");
1832: }
1833: }
1834:
1835: public void removePermissions(long pk, long[] permissionPKs)
1836: throws NoSuchGroupException,
1837: com.liferay.portal.NoSuchPermissionException,
1838: SystemException {
1839: try {
1840: for (int i = 0; i < permissionPKs.length; i++) {
1841: removePermission.remove(pk, permissionPKs[i]);
1842: }
1843: } catch (DataAccessException dae) {
1844: throw new SystemException(dae);
1845: } finally {
1846: FinderCache.clearCache("Groups_Permissions");
1847: }
1848: }
1849:
1850: public void removePermissions(long pk, List permissions)
1851: throws NoSuchGroupException,
1852: com.liferay.portal.NoSuchPermissionException,
1853: SystemException {
1854: try {
1855: for (int i = 0; i < permissions.size(); i++) {
1856: com.liferay.portal.model.Permission permission = (com.liferay.portal.model.Permission) permissions
1857: .get(i);
1858:
1859: removePermission.remove(pk, permission.getPrimaryKey());
1860: }
1861: } catch (DataAccessException dae) {
1862: throw new SystemException(dae);
1863: } finally {
1864: FinderCache.clearCache("Groups_Permissions");
1865: }
1866: }
1867:
1868: public void setPermissions(long pk, long[] permissionPKs)
1869: throws NoSuchGroupException,
1870: com.liferay.portal.NoSuchPermissionException,
1871: SystemException {
1872: try {
1873: clearPermissions.clear(pk);
1874:
1875: for (int i = 0; i < permissionPKs.length; i++) {
1876: addPermission.add(pk, permissionPKs[i]);
1877: }
1878: } catch (DataAccessException dae) {
1879: throw new SystemException(dae);
1880: } finally {
1881: FinderCache.clearCache("Groups_Permissions");
1882: }
1883: }
1884:
1885: public void setPermissions(long pk, List permissions)
1886: throws NoSuchGroupException,
1887: com.liferay.portal.NoSuchPermissionException,
1888: SystemException {
1889: try {
1890: clearPermissions.clear(pk);
1891:
1892: for (int i = 0; i < permissions.size(); i++) {
1893: com.liferay.portal.model.Permission permission = (com.liferay.portal.model.Permission) permissions
1894: .get(i);
1895:
1896: addPermission.add(pk, permission.getPrimaryKey());
1897: }
1898: } catch (DataAccessException dae) {
1899: throw new SystemException(dae);
1900: } finally {
1901: FinderCache.clearCache("Groups_Permissions");
1902: }
1903: }
1904:
1905: public List getRoles(long pk) throws NoSuchGroupException,
1906: SystemException {
1907: return getRoles(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1908: }
1909:
1910: public List getRoles(long pk, int begin, int end)
1911: throws NoSuchGroupException, SystemException {
1912: return getRoles(pk, begin, end, null);
1913: }
1914:
1915: public List getRoles(long pk, int begin, int end,
1916: OrderByComparator obc) throws NoSuchGroupException,
1917: SystemException {
1918: boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED_GROUPS_ROLES;
1919: String finderClassName = "Groups_Roles";
1920: String finderMethodName = "getRoles";
1921: String[] finderParams = new String[] { Long.class.getName(),
1922: "java.lang.Integer", "java.lang.Integer",
1923: "com.liferay.portal.kernel.util.OrderByComparator" };
1924: Object[] finderArgs = new Object[] { new Long(pk),
1925: String.valueOf(begin), String.valueOf(end),
1926: String.valueOf(obc) };
1927:
1928: Object result = null;
1929:
1930: if (finderClassNameCacheEnabled) {
1931: result = FinderCache.getResult(finderClassName,
1932: finderMethodName, finderParams, finderArgs,
1933: getSessionFactory());
1934: }
1935:
1936: if (result == null) {
1937: Session session = null;
1938:
1939: try {
1940: session = HibernateUtil.openSession();
1941:
1942: StringMaker sm = new StringMaker();
1943:
1944: sm.append(_SQL_GETROLES);
1945:
1946: if (obc != null) {
1947: sm.append("ORDER BY ");
1948: sm.append(obc.getOrderBy());
1949: }
1950:
1951: else {
1952: sm.append("ORDER BY ");
1953:
1954: sm.append("Role_.name ASC");
1955: }
1956:
1957: String sql = sm.toString();
1958:
1959: SQLQuery q = session.createSQLQuery(sql);
1960:
1961: q.addEntity("Role_",
1962: com.liferay.portal.model.impl.RoleImpl.class);
1963:
1964: QueryPos qPos = QueryPos.getInstance(q);
1965:
1966: qPos.add(pk);
1967:
1968: List list = QueryUtil.list(q, getDialect(), begin, end);
1969:
1970: FinderCache.putResult(finderClassNameCacheEnabled,
1971: finderClassName, finderMethodName,
1972: finderParams, finderArgs, list);
1973:
1974: return list;
1975: } catch (Exception e) {
1976: throw new SystemException(e);
1977: } finally {
1978: closeSession(session);
1979: }
1980: } else {
1981: return (List) result;
1982: }
1983: }
1984:
1985: public int getRolesSize(long pk) throws SystemException {
1986: boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED_GROUPS_ROLES;
1987: String finderClassName = "Groups_Roles";
1988: String finderMethodName = "getRolesSize";
1989: String[] finderParams = new String[] { Long.class.getName() };
1990: Object[] finderArgs = new Object[] { new Long(pk) };
1991:
1992: Object result = null;
1993:
1994: if (finderClassNameCacheEnabled) {
1995: result = FinderCache.getResult(finderClassName,
1996: finderMethodName, finderParams, finderArgs,
1997: getSessionFactory());
1998: }
1999:
2000: if (result == null) {
2001: Session session = null;
2002:
2003: try {
2004: session = openSession();
2005:
2006: SQLQuery q = session.createSQLQuery(_SQL_GETROLESSIZE);
2007:
2008: q.addScalar(HibernateUtil.getCountColumnName(),
2009: Hibernate.LONG);
2010:
2011: QueryPos qPos = QueryPos.getInstance(q);
2012:
2013: qPos.add(pk);
2014:
2015: Long count = null;
2016:
2017: Iterator itr = q.list().iterator();
2018:
2019: if (itr.hasNext()) {
2020: count = (Long) itr.next();
2021: }
2022:
2023: if (count == null) {
2024: count = new Long(0);
2025: }
2026:
2027: FinderCache.putResult(finderClassNameCacheEnabled,
2028: finderClassName, finderMethodName,
2029: finderParams, finderArgs, count);
2030:
2031: return count.intValue();
2032: } catch (Exception e) {
2033: throw HibernateUtil.processException(e);
2034: } finally {
2035: closeSession(session);
2036: }
2037: } else {
2038: return ((Long) result).intValue();
2039: }
2040: }
2041:
2042: public boolean containsRole(long pk, long rolePK)
2043: throws SystemException {
2044: boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED_GROUPS_ROLES;
2045: String finderClassName = "Groups_Roles";
2046: String finderMethodName = "containsRoles";
2047: String[] finderParams = new String[] { Long.class.getName(),
2048:
2049: Long.class.getName() };
2050: Object[] finderArgs = new Object[] { new Long(pk),
2051: new Long(rolePK) };
2052:
2053: Object result = null;
2054:
2055: if (finderClassNameCacheEnabled) {
2056: result = FinderCache.getResult(finderClassName,
2057: finderMethodName, finderParams, finderArgs,
2058: getSessionFactory());
2059: }
2060:
2061: if (result == null) {
2062: try {
2063: Boolean value = Boolean.valueOf(containsRole.contains(
2064: pk, rolePK));
2065:
2066: FinderCache.putResult(finderClassNameCacheEnabled,
2067: finderClassName, finderMethodName,
2068: finderParams, finderArgs, value);
2069:
2070: return value.booleanValue();
2071: } catch (DataAccessException dae) {
2072: throw new SystemException(dae);
2073: }
2074: } else {
2075: return ((Boolean) result).booleanValue();
2076: }
2077: }
2078:
2079: public boolean containsRoles(long pk) throws SystemException {
2080: if (getRolesSize(pk) > 0) {
2081: return true;
2082: } else {
2083: return false;
2084: }
2085: }
2086:
2087: public void addRole(long pk, long rolePK)
2088: throws NoSuchGroupException,
2089: com.liferay.portal.NoSuchRoleException, SystemException {
2090: try {
2091: addRole.add(pk, rolePK);
2092: } catch (DataAccessException dae) {
2093: throw new SystemException(dae);
2094: } finally {
2095: FinderCache.clearCache("Groups_Roles");
2096: }
2097: }
2098:
2099: public void addRole(long pk, com.liferay.portal.model.Role role)
2100: throws NoSuchGroupException,
2101: com.liferay.portal.NoSuchRoleException, SystemException {
2102: try {
2103: addRole.add(pk, role.getPrimaryKey());
2104: } catch (DataAccessException dae) {
2105: throw new SystemException(dae);
2106: } finally {
2107: FinderCache.clearCache("Groups_Roles");
2108: }
2109: }
2110:
2111: public void addRoles(long pk, long[] rolePKs)
2112: throws NoSuchGroupException,
2113: com.liferay.portal.NoSuchRoleException, SystemException {
2114: try {
2115: for (int i = 0; i < rolePKs.length; i++) {
2116: addRole.add(pk, rolePKs[i]);
2117: }
2118: } catch (DataAccessException dae) {
2119: throw new SystemException(dae);
2120: } finally {
2121: FinderCache.clearCache("Groups_Roles");
2122: }
2123: }
2124:
2125: public void addRoles(long pk, List roles)
2126: throws NoSuchGroupException,
2127: com.liferay.portal.NoSuchRoleException, SystemException {
2128: try {
2129: for (int i = 0; i < roles.size(); i++) {
2130: com.liferay.portal.model.Role role = (com.liferay.portal.model.Role) roles
2131: .get(i);
2132:
2133: addRole.add(pk, role.getPrimaryKey());
2134: }
2135: } catch (DataAccessException dae) {
2136: throw new SystemException(dae);
2137: } finally {
2138: FinderCache.clearCache("Groups_Roles");
2139: }
2140: }
2141:
2142: public void clearRoles(long pk) throws NoSuchGroupException,
2143: SystemException {
2144: try {
2145: clearRoles.clear(pk);
2146: } catch (DataAccessException dae) {
2147: throw new SystemException(dae);
2148: } finally {
2149: FinderCache.clearCache("Groups_Roles");
2150: }
2151: }
2152:
2153: public void removeRole(long pk, long rolePK)
2154: throws NoSuchGroupException,
2155: com.liferay.portal.NoSuchRoleException, SystemException {
2156: try {
2157: removeRole.remove(pk, rolePK);
2158: } catch (DataAccessException dae) {
2159: throw new SystemException(dae);
2160: } finally {
2161: FinderCache.clearCache("Groups_Roles");
2162: }
2163: }
2164:
2165: public void removeRole(long pk, com.liferay.portal.model.Role role)
2166: throws NoSuchGroupException,
2167: com.liferay.portal.NoSuchRoleException, SystemException {
2168: try {
2169: removeRole.remove(pk, role.getPrimaryKey());
2170: } catch (DataAccessException dae) {
2171: throw new SystemException(dae);
2172: } finally {
2173: FinderCache.clearCache("Groups_Roles");
2174: }
2175: }
2176:
2177: public void removeRoles(long pk, long[] rolePKs)
2178: throws NoSuchGroupException,
2179: com.liferay.portal.NoSuchRoleException, SystemException {
2180: try {
2181: for (int i = 0; i < rolePKs.length; i++) {
2182: removeRole.remove(pk, rolePKs[i]);
2183: }
2184: } catch (DataAccessException dae) {
2185: throw new SystemException(dae);
2186: } finally {
2187: FinderCache.clearCache("Groups_Roles");
2188: }
2189: }
2190:
2191: public void removeRoles(long pk, List roles)
2192: throws NoSuchGroupException,
2193: com.liferay.portal.NoSuchRoleException, SystemException {
2194: try {
2195: for (int i = 0; i < roles.size(); i++) {
2196: com.liferay.portal.model.Role role = (com.liferay.portal.model.Role) roles
2197: .get(i);
2198:
2199: removeRole.remove(pk, role.getPrimaryKey());
2200: }
2201: } catch (DataAccessException dae) {
2202: throw new SystemException(dae);
2203: } finally {
2204: FinderCache.clearCache("Groups_Roles");
2205: }
2206: }
2207:
2208: public void setRoles(long pk, long[] rolePKs)
2209: throws NoSuchGroupException,
2210: com.liferay.portal.NoSuchRoleException, SystemException {
2211: try {
2212: clearRoles.clear(pk);
2213:
2214: for (int i = 0; i < rolePKs.length; i++) {
2215: addRole.add(pk, rolePKs[i]);
2216: }
2217: } catch (DataAccessException dae) {
2218: throw new SystemException(dae);
2219: } finally {
2220: FinderCache.clearCache("Groups_Roles");
2221: }
2222: }
2223:
2224: public void setRoles(long pk, List roles)
2225: throws NoSuchGroupException,
2226: com.liferay.portal.NoSuchRoleException, SystemException {
2227: try {
2228: clearRoles.clear(pk);
2229:
2230: for (int i = 0; i < roles.size(); i++) {
2231: com.liferay.portal.model.Role role = (com.liferay.portal.model.Role) roles
2232: .get(i);
2233:
2234: addRole.add(pk, role.getPrimaryKey());
2235: }
2236: } catch (DataAccessException dae) {
2237: throw new SystemException(dae);
2238: } finally {
2239: FinderCache.clearCache("Groups_Roles");
2240: }
2241: }
2242:
2243: public List getUserGroups(long pk) throws NoSuchGroupException,
2244: SystemException {
2245: return getUserGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2246: }
2247:
2248: public List getUserGroups(long pk, int begin, int end)
2249: throws NoSuchGroupException, SystemException {
2250: return getUserGroups(pk, begin, end, null);
2251: }
2252:
2253: public List getUserGroups(long pk, int begin, int end,
2254: OrderByComparator obc) throws NoSuchGroupException,
2255: SystemException {
2256: boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED_GROUPS_USERGROUPS;
2257: String finderClassName = "Groups_UserGroups";
2258: String finderMethodName = "getUserGroups";
2259: String[] finderParams = new String[] { Long.class.getName(),
2260: "java.lang.Integer", "java.lang.Integer",
2261: "com.liferay.portal.kernel.util.OrderByComparator" };
2262: Object[] finderArgs = new Object[] { new Long(pk),
2263: String.valueOf(begin), String.valueOf(end),
2264: String.valueOf(obc) };
2265:
2266: Object result = null;
2267:
2268: if (finderClassNameCacheEnabled) {
2269: result = FinderCache.getResult(finderClassName,
2270: finderMethodName, finderParams, finderArgs,
2271: getSessionFactory());
2272: }
2273:
2274: if (result == null) {
2275: Session session = null;
2276:
2277: try {
2278: session = HibernateUtil.openSession();
2279:
2280: StringMaker sm = new StringMaker();
2281:
2282: sm.append(_SQL_GETUSERGROUPS);
2283:
2284: if (obc != null) {
2285: sm.append("ORDER BY ");
2286: sm.append(obc.getOrderBy());
2287: }
2288:
2289: else {
2290: sm.append("ORDER BY ");
2291:
2292: sm.append("UserGroup.name ASC");
2293: }
2294:
2295: String sql = sm.toString();
2296:
2297: SQLQuery q = session.createSQLQuery(sql);
2298:
2299: q
2300: .addEntity(
2301: "UserGroup",
2302: com.liferay.portal.model.impl.UserGroupImpl.class);
2303:
2304: QueryPos qPos = QueryPos.getInstance(q);
2305:
2306: qPos.add(pk);
2307:
2308: List list = QueryUtil.list(q, getDialect(), begin, end);
2309:
2310: FinderCache.putResult(finderClassNameCacheEnabled,
2311: finderClassName, finderMethodName,
2312: finderParams, finderArgs, list);
2313:
2314: return list;
2315: } catch (Exception e) {
2316: throw new SystemException(e);
2317: } finally {
2318: closeSession(session);
2319: }
2320: } else {
2321: return (List) result;
2322: }
2323: }
2324:
2325: public int getUserGroupsSize(long pk) throws SystemException {
2326: boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED_GROUPS_USERGROUPS;
2327: String finderClassName = "Groups_UserGroups";
2328: String finderMethodName = "getUserGroupsSize";
2329: String[] finderParams = new String[] { Long.class.getName() };
2330: Object[] finderArgs = new Object[] { new Long(pk) };
2331:
2332: Object result = null;
2333:
2334: if (finderClassNameCacheEnabled) {
2335: result = FinderCache.getResult(finderClassName,
2336: finderMethodName, finderParams, finderArgs,
2337: getSessionFactory());
2338: }
2339:
2340: if (result == null) {
2341: Session session = null;
2342:
2343: try {
2344: session = openSession();
2345:
2346: SQLQuery q = session
2347: .createSQLQuery(_SQL_GETUSERGROUPSSIZE);
2348:
2349: q.addScalar(HibernateUtil.getCountColumnName(),
2350: Hibernate.LONG);
2351:
2352: QueryPos qPos = QueryPos.getInstance(q);
2353:
2354: qPos.add(pk);
2355:
2356: Long count = null;
2357:
2358: Iterator itr = q.list().iterator();
2359:
2360: if (itr.hasNext()) {
2361: count = (Long) itr.next();
2362: }
2363:
2364: if (count == null) {
2365: count = new Long(0);
2366: }
2367:
2368: FinderCache.putResult(finderClassNameCacheEnabled,
2369: finderClassName, finderMethodName,
2370: finderParams, finderArgs, count);
2371:
2372: return count.intValue();
2373: } catch (Exception e) {
2374: throw HibernateUtil.processException(e);
2375: } finally {
2376: closeSession(session);
2377: }
2378: } else {
2379: return ((Long) result).intValue();
2380: }
2381: }
2382:
2383: public boolean containsUserGroup(long pk, long userGroupPK)
2384: throws SystemException {
2385: boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED_GROUPS_USERGROUPS;
2386: String finderClassName = "Groups_UserGroups";
2387: String finderMethodName = "containsUserGroups";
2388: String[] finderParams = new String[] { Long.class.getName(),
2389:
2390: Long.class.getName() };
2391: Object[] finderArgs = new Object[] { new Long(pk),
2392: new Long(userGroupPK) };
2393:
2394: Object result = null;
2395:
2396: if (finderClassNameCacheEnabled) {
2397: result = FinderCache.getResult(finderClassName,
2398: finderMethodName, finderParams, finderArgs,
2399: getSessionFactory());
2400: }
2401:
2402: if (result == null) {
2403: try {
2404: Boolean value = Boolean.valueOf(containsUserGroup
2405: .contains(pk, userGroupPK));
2406:
2407: FinderCache.putResult(finderClassNameCacheEnabled,
2408: finderClassName, finderMethodName,
2409: finderParams, finderArgs, value);
2410:
2411: return value.booleanValue();
2412: } catch (DataAccessException dae) {
2413: throw new SystemException(dae);
2414: }
2415: } else {
2416: return ((Boolean) result).booleanValue();
2417: }
2418: }
2419:
2420: public boolean containsUserGroups(long pk) throws SystemException {
2421: if (getUserGroupsSize(pk) > 0) {
2422: return true;
2423: } else {
2424: return false;
2425: }
2426: }
2427:
2428: public void addUserGroup(long pk, long userGroupPK)
2429: throws NoSuchGroupException,
2430: com.liferay.portal.NoSuchUserGroupException,
2431: SystemException {
2432: try {
2433: addUserGroup.add(pk, userGroupPK);
2434: } catch (DataAccessException dae) {
2435: throw new SystemException(dae);
2436: } finally {
2437: FinderCache.clearCache("Groups_UserGroups");
2438: }
2439: }
2440:
2441: public void addUserGroup(long pk,
2442: com.liferay.portal.model.UserGroup userGroup)
2443: throws NoSuchGroupException,
2444: com.liferay.portal.NoSuchUserGroupException,
2445: SystemException {
2446: try {
2447: addUserGroup.add(pk, userGroup.getPrimaryKey());
2448: } catch (DataAccessException dae) {
2449: throw new SystemException(dae);
2450: } finally {
2451: FinderCache.clearCache("Groups_UserGroups");
2452: }
2453: }
2454:
2455: public void addUserGroups(long pk, long[] userGroupPKs)
2456: throws NoSuchGroupException,
2457: com.liferay.portal.NoSuchUserGroupException,
2458: SystemException {
2459: try {
2460: for (int i = 0; i < userGroupPKs.length; i++) {
2461: addUserGroup.add(pk, userGroupPKs[i]);
2462: }
2463: } catch (DataAccessException dae) {
2464: throw new SystemException(dae);
2465: } finally {
2466: FinderCache.clearCache("Groups_UserGroups");
2467: }
2468: }
2469:
2470: public void addUserGroups(long pk, List userGroups)
2471: throws NoSuchGroupException,
2472: com.liferay.portal.NoSuchUserGroupException,
2473: SystemException {
2474: try {
2475: for (int i = 0; i < userGroups.size(); i++) {
2476: com.liferay.portal.model.UserGroup userGroup = (com.liferay.portal.model.UserGroup) userGroups
2477: .get(i);
2478:
2479: addUserGroup.add(pk, userGroup.getPrimaryKey());
2480: }
2481: } catch (DataAccessException dae) {
2482: throw new SystemException(dae);
2483: } finally {
2484: FinderCache.clearCache("Groups_UserGroups");
2485: }
2486: }
2487:
2488: public void clearUserGroups(long pk) throws NoSuchGroupException,
2489: SystemException {
2490: try {
2491: clearUserGroups.clear(pk);
2492: } catch (DataAccessException dae) {
2493: throw new SystemException(dae);
2494: } finally {
2495: FinderCache.clearCache("Groups_UserGroups");
2496: }
2497: }
2498:
2499: public void removeUserGroup(long pk, long userGroupPK)
2500: throws NoSuchGroupException,
2501: com.liferay.portal.NoSuchUserGroupException,
2502: SystemException {
2503: try {
2504: removeUserGroup.remove(pk, userGroupPK);
2505: } catch (DataAccessException dae) {
2506: throw new SystemException(dae);
2507: } finally {
2508: FinderCache.clearCache("Groups_UserGroups");
2509: }
2510: }
2511:
2512: public void removeUserGroup(long pk,
2513: com.liferay.portal.model.UserGroup userGroup)
2514: throws NoSuchGroupException,
2515: com.liferay.portal.NoSuchUserGroupException,
2516: SystemException {
2517: try {
2518: removeUserGroup.remove(pk, userGroup.getPrimaryKey());
2519: } catch (DataAccessException dae) {
2520: throw new SystemException(dae);
2521: } finally {
2522: FinderCache.clearCache("Groups_UserGroups");
2523: }
2524: }
2525:
2526: public void removeUserGroups(long pk, long[] userGroupPKs)
2527: throws NoSuchGroupException,
2528: com.liferay.portal.NoSuchUserGroupException,
2529: SystemException {
2530: try {
2531: for (int i = 0; i < userGroupPKs.length; i++) {
2532: removeUserGroup.remove(pk, userGroupPKs[i]);
2533: }
2534: } catch (DataAccessException dae) {
2535: throw new SystemException(dae);
2536: } finally {
2537: FinderCache.clearCache("Groups_UserGroups");
2538: }
2539: }
2540:
2541: public void removeUserGroups(long pk, List userGroups)
2542: throws NoSuchGroupException,
2543: com.liferay.portal.NoSuchUserGroupException,
2544: SystemException {
2545: try {
2546: for (int i = 0; i < userGroups.size(); i++) {
2547: com.liferay.portal.model.UserGroup userGroup = (com.liferay.portal.model.UserGroup) userGroups
2548: .get(i);
2549:
2550: removeUserGroup.remove(pk, userGroup.getPrimaryKey());
2551: }
2552: } catch (DataAccessException dae) {
2553: throw new SystemException(dae);
2554: } finally {
2555: FinderCache.clearCache("Groups_UserGroups");
2556: }
2557: }
2558:
2559: public void setUserGroups(long pk, long[] userGroupPKs)
2560: throws NoSuchGroupException,
2561: com.liferay.portal.NoSuchUserGroupException,
2562: SystemException {
2563: try {
2564: clearUserGroups.clear(pk);
2565:
2566: for (int i = 0; i < userGroupPKs.length; i++) {
2567: addUserGroup.add(pk, userGroupPKs[i]);
2568: }
2569: } catch (DataAccessException dae) {
2570: throw new SystemException(dae);
2571: } finally {
2572: FinderCache.clearCache("Groups_UserGroups");
2573: }
2574: }
2575:
2576: public void setUserGroups(long pk, List userGroups)
2577: throws NoSuchGroupException,
2578: com.liferay.portal.NoSuchUserGroupException,
2579: SystemException {
2580: try {
2581: clearUserGroups.clear(pk);
2582:
2583: for (int i = 0; i < userGroups.size(); i++) {
2584: com.liferay.portal.model.UserGroup userGroup = (com.liferay.portal.model.UserGroup) userGroups
2585: .get(i);
2586:
2587: addUserGroup.add(pk, userGroup.getPrimaryKey());
2588: }
2589: } catch (DataAccessException dae) {
2590: throw new SystemException(dae);
2591: } finally {
2592: FinderCache.clearCache("Groups_UserGroups");
2593: }
2594: }
2595:
2596: public List getUsers(long pk) throws NoSuchGroupException,
2597: SystemException {
2598: return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2599: }
2600:
2601: public List getUsers(long pk, int begin, int end)
2602: throws NoSuchGroupException, SystemException {
2603: return getUsers(pk, begin, end, null);
2604: }
2605:
2606: public List getUsers(long pk, int begin, int end,
2607: OrderByComparator obc) throws NoSuchGroupException,
2608: SystemException {
2609: boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED_USERS_GROUPS;
2610: String finderClassName = "Users_Groups";
2611: String finderMethodName = "getUsers";
2612: String[] finderParams = new String[] { Long.class.getName(),
2613: "java.lang.Integer", "java.lang.Integer",
2614: "com.liferay.portal.kernel.util.OrderByComparator" };
2615: Object[] finderArgs = new Object[] { new Long(pk),
2616: String.valueOf(begin), String.valueOf(end),
2617: String.valueOf(obc) };
2618:
2619: Object result = null;
2620:
2621: if (finderClassNameCacheEnabled) {
2622: result = FinderCache.getResult(finderClassName,
2623: finderMethodName, finderParams, finderArgs,
2624: getSessionFactory());
2625: }
2626:
2627: if (result == null) {
2628: Session session = null;
2629:
2630: try {
2631: session = HibernateUtil.openSession();
2632:
2633: StringMaker sm = new StringMaker();
2634:
2635: sm.append(_SQL_GETUSERS);
2636:
2637: if (obc != null) {
2638: sm.append("ORDER BY ");
2639: sm.append(obc.getOrderBy());
2640: }
2641:
2642: String sql = sm.toString();
2643:
2644: SQLQuery q = session.createSQLQuery(sql);
2645:
2646: q.addEntity("User_",
2647: com.liferay.portal.model.impl.UserImpl.class);
2648:
2649: QueryPos qPos = QueryPos.getInstance(q);
2650:
2651: qPos.add(pk);
2652:
2653: List list = QueryUtil.list(q, getDialect(), begin, end);
2654:
2655: FinderCache.putResult(finderClassNameCacheEnabled,
2656: finderClassName, finderMethodName,
2657: finderParams, finderArgs, list);
2658:
2659: return list;
2660: } catch (Exception e) {
2661: throw new SystemException(e);
2662: } finally {
2663: closeSession(session);
2664: }
2665: } else {
2666: return (List) result;
2667: }
2668: }
2669:
2670: public int getUsersSize(long pk) throws SystemException {
2671: boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED_USERS_GROUPS;
2672: String finderClassName = "Users_Groups";
2673: String finderMethodName = "getUsersSize";
2674: String[] finderParams = new String[] { Long.class.getName() };
2675: Object[] finderArgs = new Object[] { new Long(pk) };
2676:
2677: Object result = null;
2678:
2679: if (finderClassNameCacheEnabled) {
2680: result = FinderCache.getResult(finderClassName,
2681: finderMethodName, finderParams, finderArgs,
2682: getSessionFactory());
2683: }
2684:
2685: if (result == null) {
2686: Session session = null;
2687:
2688: try {
2689: session = openSession();
2690:
2691: SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
2692:
2693: q.addScalar(HibernateUtil.getCountColumnName(),
2694: Hibernate.LONG);
2695:
2696: QueryPos qPos = QueryPos.getInstance(q);
2697:
2698: qPos.add(pk);
2699:
2700: Long count = null;
2701:
2702: Iterator itr = q.list().iterator();
2703:
2704: if (itr.hasNext()) {
2705: count = (Long) itr.next();
2706: }
2707:
2708: if (count == null) {
2709: count = new Long(0);
2710: }
2711:
2712: FinderCache.putResult(finderClassNameCacheEnabled,
2713: finderClassName, finderMethodName,
2714: finderParams, finderArgs, count);
2715:
2716: return count.intValue();
2717: } catch (Exception e) {
2718: throw HibernateUtil.processException(e);
2719: } finally {
2720: closeSession(session);
2721: }
2722: } else {
2723: return ((Long) result).intValue();
2724: }
2725: }
2726:
2727: public boolean containsUser(long pk, long userPK)
2728: throws SystemException {
2729: boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED_USERS_GROUPS;
2730: String finderClassName = "Users_Groups";
2731: String finderMethodName = "containsUsers";
2732: String[] finderParams = new String[] { Long.class.getName(),
2733:
2734: Long.class.getName() };
2735: Object[] finderArgs = new Object[] { new Long(pk),
2736: new Long(userPK) };
2737:
2738: Object result = null;
2739:
2740: if (finderClassNameCacheEnabled) {
2741: result = FinderCache.getResult(finderClassName,
2742: finderMethodName, finderParams, finderArgs,
2743: getSessionFactory());
2744: }
2745:
2746: if (result == null) {
2747: try {
2748: Boolean value = Boolean.valueOf(containsUser.contains(
2749: pk, userPK));
2750:
2751: FinderCache.putResult(finderClassNameCacheEnabled,
2752: finderClassName, finderMethodName,
2753: finderParams, finderArgs, value);
2754:
2755: return value.booleanValue();
2756: } catch (DataAccessException dae) {
2757: throw new SystemException(dae);
2758: }
2759: } else {
2760: return ((Boolean) result).booleanValue();
2761: }
2762: }
2763:
2764: public boolean containsUsers(long pk) throws SystemException {
2765: if (getUsersSize(pk) > 0) {
2766: return true;
2767: } else {
2768: return false;
2769: }
2770: }
2771:
2772: public void addUser(long pk, long userPK)
2773: throws NoSuchGroupException,
2774: com.liferay.portal.NoSuchUserException, SystemException {
2775: try {
2776: addUser.add(pk, userPK);
2777: } catch (DataAccessException dae) {
2778: throw new SystemException(dae);
2779: } finally {
2780: FinderCache.clearCache("Users_Groups");
2781: }
2782: }
2783:
2784: public void addUser(long pk, com.liferay.portal.model.User user)
2785: throws NoSuchGroupException,
2786: com.liferay.portal.NoSuchUserException, SystemException {
2787: try {
2788: addUser.add(pk, user.getPrimaryKey());
2789: } catch (DataAccessException dae) {
2790: throw new SystemException(dae);
2791: } finally {
2792: FinderCache.clearCache("Users_Groups");
2793: }
2794: }
2795:
2796: public void addUsers(long pk, long[] userPKs)
2797: throws NoSuchGroupException,
2798: com.liferay.portal.NoSuchUserException, SystemException {
2799: try {
2800: for (int i = 0; i < userPKs.length; i++) {
2801: addUser.add(pk, userPKs[i]);
2802: }
2803: } catch (DataAccessException dae) {
2804: throw new SystemException(dae);
2805: } finally {
2806: FinderCache.clearCache("Users_Groups");
2807: }
2808: }
2809:
2810: public void addUsers(long pk, List users)
2811: throws NoSuchGroupException,
2812: com.liferay.portal.NoSuchUserException, SystemException {
2813: try {
2814: for (int i = 0; i < users.size(); i++) {
2815: com.liferay.portal.model.User user = (com.liferay.portal.model.User) users
2816: .get(i);
2817:
2818: addUser.add(pk, user.getPrimaryKey());
2819: }
2820: } catch (DataAccessException dae) {
2821: throw new SystemException(dae);
2822: } finally {
2823: FinderCache.clearCache("Users_Groups");
2824: }
2825: }
2826:
2827: public void clearUsers(long pk) throws NoSuchGroupException,
2828: SystemException {
2829: try {
2830: clearUsers.clear(pk);
2831: } catch (DataAccessException dae) {
2832: throw new SystemException(dae);
2833: } finally {
2834: FinderCache.clearCache("Users_Groups");
2835: }
2836: }
2837:
2838: public void removeUser(long pk, long userPK)
2839: throws NoSuchGroupException,
2840: com.liferay.portal.NoSuchUserException, SystemException {
2841: try {
2842: removeUser.remove(pk, userPK);
2843: } catch (DataAccessException dae) {
2844: throw new SystemException(dae);
2845: } finally {
2846: FinderCache.clearCache("Users_Groups");
2847: }
2848: }
2849:
2850: public void removeUser(long pk, com.liferay.portal.model.User user)
2851: throws NoSuchGroupException,
2852: com.liferay.portal.NoSuchUserException, SystemException {
2853: try {
2854: removeUser.remove(pk, user.getPrimaryKey());
2855: } catch (DataAccessException dae) {
2856: throw new SystemException(dae);
2857: } finally {
2858: FinderCache.clearCache("Users_Groups");
2859: }
2860: }
2861:
2862: public void removeUsers(long pk, long[] userPKs)
2863: throws NoSuchGroupException,
2864: com.liferay.portal.NoSuchUserException, SystemException {
2865: try {
2866: for (int i = 0; i < userPKs.length; i++) {
2867: removeUser.remove(pk, userPKs[i]);
2868: }
2869: } catch (DataAccessException dae) {
2870: throw new SystemException(dae);
2871: } finally {
2872: FinderCache.clearCache("Users_Groups");
2873: }
2874: }
2875:
2876: public void removeUsers(long pk, List users)
2877: throws NoSuchGroupException,
2878: com.liferay.portal.NoSuchUserException, SystemException {
2879: try {
2880: for (int i = 0; i < users.size(); i++) {
2881: com.liferay.portal.model.User user = (com.liferay.portal.model.User) users
2882: .get(i);
2883:
2884: removeUser.remove(pk, user.getPrimaryKey());
2885: }
2886: } catch (DataAccessException dae) {
2887: throw new SystemException(dae);
2888: } finally {
2889: FinderCache.clearCache("Users_Groups");
2890: }
2891: }
2892:
2893: public void setUsers(long pk, long[] userPKs)
2894: throws NoSuchGroupException,
2895: com.liferay.portal.NoSuchUserException, SystemException {
2896: try {
2897: clearUsers.clear(pk);
2898:
2899: for (int i = 0; i < userPKs.length; i++) {
2900: addUser.add(pk, userPKs[i]);
2901: }
2902: } catch (DataAccessException dae) {
2903: throw new SystemException(dae);
2904: } finally {
2905: FinderCache.clearCache("Users_Groups");
2906: }
2907: }
2908:
2909: public void setUsers(long pk, List users)
2910: throws NoSuchGroupException,
2911: com.liferay.portal.NoSuchUserException, SystemException {
2912: try {
2913: clearUsers.clear(pk);
2914:
2915: for (int i = 0; i < users.size(); i++) {
2916: com.liferay.portal.model.User user = (com.liferay.portal.model.User) users
2917: .get(i);
2918:
2919: addUser.add(pk, user.getPrimaryKey());
2920: }
2921: } catch (DataAccessException dae) {
2922: throw new SystemException(dae);
2923: } finally {
2924: FinderCache.clearCache("Users_Groups");
2925: }
2926: }
2927:
2928: protected void initDao() {
2929: containsOrganization = new ContainsOrganization(this );
2930:
2931: addOrganization = new AddOrganization(this );
2932: clearOrganizations = new ClearOrganizations(this );
2933: removeOrganization = new RemoveOrganization(this );
2934:
2935: containsPermission = new ContainsPermission(this );
2936:
2937: addPermission = new AddPermission(this );
2938: clearPermissions = new ClearPermissions(this );
2939: removePermission = new RemovePermission(this );
2940:
2941: containsRole = new ContainsRole(this );
2942:
2943: addRole = new AddRole(this );
2944: clearRoles = new ClearRoles(this );
2945: removeRole = new RemoveRole(this );
2946:
2947: containsUserGroup = new ContainsUserGroup(this );
2948:
2949: addUserGroup = new AddUserGroup(this );
2950: clearUserGroups = new ClearUserGroups(this );
2951: removeUserGroup = new RemoveUserGroup(this );
2952:
2953: containsUser = new ContainsUser(this );
2954:
2955: addUser = new AddUser(this );
2956: clearUsers = new ClearUsers(this );
2957: removeUser = new RemoveUser(this );
2958: }
2959:
2960: protected ContainsOrganization containsOrganization;
2961: protected AddOrganization addOrganization;
2962: protected ClearOrganizations clearOrganizations;
2963: protected RemoveOrganization removeOrganization;
2964: protected ContainsPermission containsPermission;
2965: protected AddPermission addPermission;
2966: protected ClearPermissions clearPermissions;
2967: protected RemovePermission removePermission;
2968: protected ContainsRole containsRole;
2969: protected AddRole addRole;
2970: protected ClearRoles clearRoles;
2971: protected RemoveRole removeRole;
2972: protected ContainsUserGroup containsUserGroup;
2973: protected AddUserGroup addUserGroup;
2974: protected ClearUserGroups clearUserGroups;
2975: protected RemoveUserGroup removeUserGroup;
2976: protected ContainsUser containsUser;
2977: protected AddUser addUser;
2978: protected ClearUsers clearUsers;
2979: protected RemoveUser removeUser;
2980:
2981: protected class ContainsOrganization extends MappingSqlQuery {
2982: protected ContainsOrganization(
2983: GroupPersistenceImpl persistenceImpl) {
2984: super (persistenceImpl.getDataSource(),
2985: _SQL_CONTAINSORGANIZATION);
2986:
2987: declareParameter(new SqlParameter(Types.BIGINT));
2988: declareParameter(new SqlParameter(Types.BIGINT));
2989:
2990: compile();
2991: }
2992:
2993: protected Object mapRow(ResultSet rs, int rowNumber)
2994: throws SQLException {
2995: return new Integer(rs.getInt("COUNT_VALUE"));
2996: }
2997:
2998: protected boolean contains(long groupId, long organizationId) {
2999: List results = execute(new Object[] { new Long(groupId),
3000: new Long(organizationId) });
3001:
3002: if (results.size() > 0) {
3003: Integer count = (Integer) results.get(0);
3004:
3005: if (count.intValue() > 0) {
3006: return true;
3007: }
3008: }
3009:
3010: return false;
3011: }
3012: }
3013:
3014: protected class AddOrganization extends SqlUpdate {
3015: protected AddOrganization(GroupPersistenceImpl persistenceImpl) {
3016: super (persistenceImpl.getDataSource(),
3017: "INSERT INTO Groups_Orgs (groupId, organizationId) VALUES (?, ?)");
3018:
3019: _persistenceImpl = persistenceImpl;
3020:
3021: declareParameter(new SqlParameter(Types.BIGINT));
3022: declareParameter(new SqlParameter(Types.BIGINT));
3023:
3024: compile();
3025: }
3026:
3027: protected void add(long groupId, long organizationId) {
3028: if (!_persistenceImpl.containsOrganization.contains(
3029: groupId, organizationId)) {
3030: update(new Object[] { new Long(groupId),
3031: new Long(organizationId) });
3032: }
3033: }
3034:
3035: private GroupPersistenceImpl _persistenceImpl;
3036: }
3037:
3038: protected class ClearOrganizations extends SqlUpdate {
3039: protected ClearOrganizations(
3040: GroupPersistenceImpl persistenceImpl) {
3041: super (persistenceImpl.getDataSource(),
3042: "DELETE FROM Groups_Orgs WHERE groupId = ?");
3043:
3044: declareParameter(new SqlParameter(Types.BIGINT));
3045:
3046: compile();
3047: }
3048:
3049: protected void clear(long groupId) {
3050: update(new Object[] { new Long(groupId) });
3051: }
3052: }
3053:
3054: protected class RemoveOrganization extends SqlUpdate {
3055: protected RemoveOrganization(
3056: GroupPersistenceImpl persistenceImpl) {
3057: super (persistenceImpl.getDataSource(),
3058: "DELETE FROM Groups_Orgs WHERE groupId = ? AND organizationId = ?");
3059:
3060: declareParameter(new SqlParameter(Types.BIGINT));
3061: declareParameter(new SqlParameter(Types.BIGINT));
3062:
3063: compile();
3064: }
3065:
3066: protected void remove(long groupId, long organizationId) {
3067: update(new Object[] { new Long(groupId),
3068: new Long(organizationId) });
3069: }
3070: }
3071:
3072: protected class ContainsPermission extends MappingSqlQuery {
3073: protected ContainsPermission(
3074: GroupPersistenceImpl persistenceImpl) {
3075: super (persistenceImpl.getDataSource(),
3076: _SQL_CONTAINSPERMISSION);
3077:
3078: declareParameter(new SqlParameter(Types.BIGINT));
3079: declareParameter(new SqlParameter(Types.BIGINT));
3080:
3081: compile();
3082: }
3083:
3084: protected Object mapRow(ResultSet rs, int rowNumber)
3085: throws SQLException {
3086: return new Integer(rs.getInt("COUNT_VALUE"));
3087: }
3088:
3089: protected boolean contains(long groupId, long permissionId) {
3090: List results = execute(new Object[] { new Long(groupId),
3091: new Long(permissionId) });
3092:
3093: if (results.size() > 0) {
3094: Integer count = (Integer) results.get(0);
3095:
3096: if (count.intValue() > 0) {
3097: return true;
3098: }
3099: }
3100:
3101: return false;
3102: }
3103: }
3104:
3105: protected class AddPermission extends SqlUpdate {
3106: protected AddPermission(GroupPersistenceImpl persistenceImpl) {
3107: super (persistenceImpl.getDataSource(),
3108: "INSERT INTO Groups_Permissions (groupId, permissionId) VALUES (?, ?)");
3109:
3110: _persistenceImpl = persistenceImpl;
3111:
3112: declareParameter(new SqlParameter(Types.BIGINT));
3113: declareParameter(new SqlParameter(Types.BIGINT));
3114:
3115: compile();
3116: }
3117:
3118: protected void add(long groupId, long permissionId) {
3119: if (!_persistenceImpl.containsPermission.contains(groupId,
3120: permissionId)) {
3121: update(new Object[] { new Long(groupId),
3122: new Long(permissionId) });
3123: }
3124: }
3125:
3126: private GroupPersistenceImpl _persistenceImpl;
3127: }
3128:
3129: protected class ClearPermissions extends SqlUpdate {
3130: protected ClearPermissions(GroupPersistenceImpl persistenceImpl) {
3131: super (persistenceImpl.getDataSource(),
3132: "DELETE FROM Groups_Permissions WHERE groupId = ?");
3133:
3134: declareParameter(new SqlParameter(Types.BIGINT));
3135:
3136: compile();
3137: }
3138:
3139: protected void clear(long groupId) {
3140: update(new Object[] { new Long(groupId) });
3141: }
3142: }
3143:
3144: protected class RemovePermission extends SqlUpdate {
3145: protected RemovePermission(GroupPersistenceImpl persistenceImpl) {
3146: super (persistenceImpl.getDataSource(),
3147: "DELETE FROM Groups_Permissions WHERE groupId = ? AND permissionId = ?");
3148:
3149: declareParameter(new SqlParameter(Types.BIGINT));
3150: declareParameter(new SqlParameter(Types.BIGINT));
3151:
3152: compile();
3153: }
3154:
3155: protected void remove(long groupId, long permissionId) {
3156: update(new Object[] { new Long(groupId),
3157: new Long(permissionId) });
3158: }
3159: }
3160:
3161: protected class ContainsRole extends MappingSqlQuery {
3162: protected ContainsRole(GroupPersistenceImpl persistenceImpl) {
3163: super (persistenceImpl.getDataSource(), _SQL_CONTAINSROLE);
3164:
3165: declareParameter(new SqlParameter(Types.BIGINT));
3166: declareParameter(new SqlParameter(Types.BIGINT));
3167:
3168: compile();
3169: }
3170:
3171: protected Object mapRow(ResultSet rs, int rowNumber)
3172: throws SQLException {
3173: return new Integer(rs.getInt("COUNT_VALUE"));
3174: }
3175:
3176: protected boolean contains(long groupId, long roleId) {
3177: List results = execute(new Object[] { new Long(groupId),
3178: new Long(roleId) });
3179:
3180: if (results.size() > 0) {
3181: Integer count = (Integer) results.get(0);
3182:
3183: if (count.intValue() > 0) {
3184: return true;
3185: }
3186: }
3187:
3188: return false;
3189: }
3190: }
3191:
3192: protected class AddRole extends SqlUpdate {
3193: protected AddRole(GroupPersistenceImpl persistenceImpl) {
3194: super (persistenceImpl.getDataSource(),
3195: "INSERT INTO Groups_Roles (groupId, roleId) VALUES (?, ?)");
3196:
3197: _persistenceImpl = persistenceImpl;
3198:
3199: declareParameter(new SqlParameter(Types.BIGINT));
3200: declareParameter(new SqlParameter(Types.BIGINT));
3201:
3202: compile();
3203: }
3204:
3205: protected void add(long groupId, long roleId) {
3206: if (!_persistenceImpl.containsRole
3207: .contains(groupId, roleId)) {
3208: update(new Object[] { new Long(groupId),
3209: new Long(roleId) });
3210: }
3211: }
3212:
3213: private GroupPersistenceImpl _persistenceImpl;
3214: }
3215:
3216: protected class ClearRoles extends SqlUpdate {
3217: protected ClearRoles(GroupPersistenceImpl persistenceImpl) {
3218: super (persistenceImpl.getDataSource(),
3219: "DELETE FROM Groups_Roles WHERE groupId = ?");
3220:
3221: declareParameter(new SqlParameter(Types.BIGINT));
3222:
3223: compile();
3224: }
3225:
3226: protected void clear(long groupId) {
3227: update(new Object[] { new Long(groupId) });
3228: }
3229: }
3230:
3231: protected class RemoveRole extends SqlUpdate {
3232: protected RemoveRole(GroupPersistenceImpl persistenceImpl) {
3233: super (persistenceImpl.getDataSource(),
3234: "DELETE FROM Groups_Roles WHERE groupId = ? AND roleId = ?");
3235:
3236: declareParameter(new SqlParameter(Types.BIGINT));
3237: declareParameter(new SqlParameter(Types.BIGINT));
3238:
3239: compile();
3240: }
3241:
3242: protected void remove(long groupId, long roleId) {
3243: update(new Object[] { new Long(groupId), new Long(roleId) });
3244: }
3245: }
3246:
3247: protected class ContainsUserGroup extends MappingSqlQuery {
3248: protected ContainsUserGroup(GroupPersistenceImpl persistenceImpl) {
3249: super (persistenceImpl.getDataSource(),
3250: _SQL_CONTAINSUSERGROUP);
3251:
3252: declareParameter(new SqlParameter(Types.BIGINT));
3253: declareParameter(new SqlParameter(Types.BIGINT));
3254:
3255: compile();
3256: }
3257:
3258: protected Object mapRow(ResultSet rs, int rowNumber)
3259: throws SQLException {
3260: return new Integer(rs.getInt("COUNT_VALUE"));
3261: }
3262:
3263: protected boolean contains(long groupId, long userGroupId) {
3264: List results = execute(new Object[] { new Long(groupId),
3265: new Long(userGroupId) });
3266:
3267: if (results.size() > 0) {
3268: Integer count = (Integer) results.get(0);
3269:
3270: if (count.intValue() > 0) {
3271: return true;
3272: }
3273: }
3274:
3275: return false;
3276: }
3277: }
3278:
3279: protected class AddUserGroup extends SqlUpdate {
3280: protected AddUserGroup(GroupPersistenceImpl persistenceImpl) {
3281: super (persistenceImpl.getDataSource(),
3282: "INSERT INTO Groups_UserGroups (groupId, userGroupId) VALUES (?, ?)");
3283:
3284: _persistenceImpl = persistenceImpl;
3285:
3286: declareParameter(new SqlParameter(Types.BIGINT));
3287: declareParameter(new SqlParameter(Types.BIGINT));
3288:
3289: compile();
3290: }
3291:
3292: protected void add(long groupId, long userGroupId) {
3293: if (!_persistenceImpl.containsUserGroup.contains(groupId,
3294: userGroupId)) {
3295: update(new Object[] { new Long(groupId),
3296: new Long(userGroupId) });
3297: }
3298: }
3299:
3300: private GroupPersistenceImpl _persistenceImpl;
3301: }
3302:
3303: protected class ClearUserGroups extends SqlUpdate {
3304: protected ClearUserGroups(GroupPersistenceImpl persistenceImpl) {
3305: super (persistenceImpl.getDataSource(),
3306: "DELETE FROM Groups_UserGroups WHERE groupId = ?");
3307:
3308: declareParameter(new SqlParameter(Types.BIGINT));
3309:
3310: compile();
3311: }
3312:
3313: protected void clear(long groupId) {
3314: update(new Object[] { new Long(groupId) });
3315: }
3316: }
3317:
3318: protected class RemoveUserGroup extends SqlUpdate {
3319: protected RemoveUserGroup(GroupPersistenceImpl persistenceImpl) {
3320: super (persistenceImpl.getDataSource(),
3321: "DELETE FROM Groups_UserGroups WHERE groupId = ? AND userGroupId = ?");
3322:
3323: declareParameter(new SqlParameter(Types.BIGINT));
3324: declareParameter(new SqlParameter(Types.BIGINT));
3325:
3326: compile();
3327: }
3328:
3329: protected void remove(long groupId, long userGroupId) {
3330: update(new Object[] { new Long(groupId),
3331: new Long(userGroupId) });
3332: }
3333: }
3334:
3335: protected class ContainsUser extends MappingSqlQuery {
3336: protected ContainsUser(GroupPersistenceImpl persistenceImpl) {
3337: super (persistenceImpl.getDataSource(), _SQL_CONTAINSUSER);
3338:
3339: declareParameter(new SqlParameter(Types.BIGINT));
3340: declareParameter(new SqlParameter(Types.BIGINT));
3341:
3342: compile();
3343: }
3344:
3345: protected Object mapRow(ResultSet rs, int rowNumber)
3346: throws SQLException {
3347: return new Integer(rs.getInt("COUNT_VALUE"));
3348: }
3349:
3350: protected boolean contains(long groupId, long userId) {
3351: List results = execute(new Object[] { new Long(groupId),
3352: new Long(userId) });
3353:
3354: if (results.size() > 0) {
3355: Integer count = (Integer) results.get(0);
3356:
3357: if (count.intValue() > 0) {
3358: return true;
3359: }
3360: }
3361:
3362: return false;
3363: }
3364: }
3365:
3366: protected class AddUser extends SqlUpdate {
3367: protected AddUser(GroupPersistenceImpl persistenceImpl) {
3368: super (persistenceImpl.getDataSource(),
3369: "INSERT INTO Users_Groups (groupId, userId) VALUES (?, ?)");
3370:
3371: _persistenceImpl = persistenceImpl;
3372:
3373: declareParameter(new SqlParameter(Types.BIGINT));
3374: declareParameter(new SqlParameter(Types.BIGINT));
3375:
3376: compile();
3377: }
3378:
3379: protected void add(long groupId, long userId) {
3380: if (!_persistenceImpl.containsUser
3381: .contains(groupId, userId)) {
3382: update(new Object[] { new Long(groupId),
3383: new Long(userId) });
3384: }
3385: }
3386:
3387: private GroupPersistenceImpl _persistenceImpl;
3388: }
3389:
3390: protected class ClearUsers extends SqlUpdate {
3391: protected ClearUsers(GroupPersistenceImpl persistenceImpl) {
3392: super (persistenceImpl.getDataSource(),
3393: "DELETE FROM Users_Groups WHERE groupId = ?");
3394:
3395: declareParameter(new SqlParameter(Types.BIGINT));
3396:
3397: compile();
3398: }
3399:
3400: protected void clear(long groupId) {
3401: update(new Object[] { new Long(groupId) });
3402: }
3403: }
3404:
3405: protected class RemoveUser extends SqlUpdate {
3406: protected RemoveUser(GroupPersistenceImpl persistenceImpl) {
3407: super (persistenceImpl.getDataSource(),
3408: "DELETE FROM Users_Groups WHERE groupId = ? AND userId = ?");
3409:
3410: declareParameter(new SqlParameter(Types.BIGINT));
3411: declareParameter(new SqlParameter(Types.BIGINT));
3412:
3413: compile();
3414: }
3415:
3416: protected void remove(long groupId, long userId) {
3417: update(new Object[] { new Long(groupId), new Long(userId) });
3418: }
3419: }
3420:
3421: private static ModelListener _getListener() {
3422: if (Validator.isNotNull(_LISTENER)) {
3423: try {
3424: return (ModelListener) Class.forName(_LISTENER)
3425: .newInstance();
3426: } catch (Exception e) {
3427: _log.error(e);
3428: }
3429: }
3430:
3431: return null;
3432: }
3433:
3434: private static final String _SQL_GETORGANIZATIONS = "SELECT {Organization_.*} FROM Organization_ INNER JOIN Groups_Orgs ON (Groups_Orgs.organizationId = Organization_.organizationId) WHERE (Groups_Orgs.groupId = ?)";
3435: private static final String _SQL_GETORGANIZATIONSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Orgs WHERE groupId = ?";
3436: private static final String _SQL_CONTAINSORGANIZATION = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Orgs WHERE groupId = ? AND organizationId = ?";
3437: private static final String _SQL_GETPERMISSIONS = "SELECT {Permission_.*} FROM Permission_ INNER JOIN Groups_Permissions ON (Groups_Permissions.permissionId = Permission_.permissionId) WHERE (Groups_Permissions.groupId = ?)";
3438: private static final String _SQL_GETPERMISSIONSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Permissions WHERE groupId = ?";
3439: private static final String _SQL_CONTAINSPERMISSION = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Permissions WHERE groupId = ? AND permissionId = ?";
3440: private static final String _SQL_GETROLES = "SELECT {Role_.*} FROM Role_ INNER JOIN Groups_Roles ON (Groups_Roles.roleId = Role_.roleId) WHERE (Groups_Roles.groupId = ?)";
3441: private static final String _SQL_GETROLESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Roles WHERE groupId = ?";
3442: private static final String _SQL_CONTAINSROLE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Roles WHERE groupId = ? AND roleId = ?";
3443: private static final String _SQL_GETUSERGROUPS = "SELECT {UserGroup.*} FROM UserGroup INNER JOIN Groups_UserGroups ON (Groups_UserGroups.userGroupId = UserGroup.userGroupId) WHERE (Groups_UserGroups.groupId = ?)";
3444: private static final String _SQL_GETUSERGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_UserGroups WHERE groupId = ?";
3445: private static final String _SQL_CONTAINSUSERGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_UserGroups WHERE groupId = ? AND userGroupId = ?";
3446: private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_Groups ON (Users_Groups.userId = User_.userId) WHERE (Users_Groups.groupId = ?)";
3447: private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Groups WHERE groupId = ?";
3448: private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Groups WHERE groupId = ? AND userId = ?";
3449: private static final String _LISTENER = GetterUtil
3450: .getString(PropsUtil
3451: .get("value.object.listener.com.liferay.portal.model.Group"));
3452: private static Log _log = LogFactory
3453: .getLog(GroupPersistenceImpl.class);
3454: }
|