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.NoSuchUserGroupRoleException;
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.ModelListener;
0033: import com.liferay.portal.model.UserGroupRole;
0034: import com.liferay.portal.model.impl.UserGroupRoleImpl;
0035: import com.liferay.portal.model.impl.UserGroupRoleModelImpl;
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.QueryUtil;
0041:
0042: import org.apache.commons.logging.Log;
0043: import org.apache.commons.logging.LogFactory;
0044:
0045: import org.hibernate.Query;
0046: import org.hibernate.Session;
0047:
0048: import java.util.Collections;
0049: import java.util.Iterator;
0050: import java.util.List;
0051:
0052: /**
0053: * <a href="UserGroupRolePersistenceImpl.java.html"><b><i>View Source</i></b></a>
0054: *
0055: * @author Brian Wing Shun Chan
0056: *
0057: */
0058: public class UserGroupRolePersistenceImpl extends BasePersistence
0059: implements UserGroupRolePersistence {
0060: public UserGroupRole create(UserGroupRolePK userGroupRolePK) {
0061: UserGroupRole userGroupRole = new UserGroupRoleImpl();
0062:
0063: userGroupRole.setNew(true);
0064: userGroupRole.setPrimaryKey(userGroupRolePK);
0065:
0066: return userGroupRole;
0067: }
0068:
0069: public UserGroupRole remove(UserGroupRolePK userGroupRolePK)
0070: throws NoSuchUserGroupRoleException, SystemException {
0071: Session session = null;
0072:
0073: try {
0074: session = openSession();
0075:
0076: UserGroupRole userGroupRole = (UserGroupRole) session.get(
0077: UserGroupRoleImpl.class, userGroupRolePK);
0078:
0079: if (userGroupRole == null) {
0080: if (_log.isWarnEnabled()) {
0081: _log
0082: .warn("No UserGroupRole exists with the primary key "
0083: + userGroupRolePK);
0084: }
0085:
0086: throw new NoSuchUserGroupRoleException(
0087: "No UserGroupRole exists with the primary key "
0088: + userGroupRolePK);
0089: }
0090:
0091: return remove(userGroupRole);
0092: } catch (NoSuchUserGroupRoleException nsee) {
0093: throw nsee;
0094: } catch (Exception e) {
0095: throw HibernateUtil.processException(e);
0096: } finally {
0097: closeSession(session);
0098: }
0099: }
0100:
0101: public UserGroupRole remove(UserGroupRole userGroupRole)
0102: throws SystemException {
0103: ModelListener listener = _getListener();
0104:
0105: if (listener != null) {
0106: listener.onBeforeRemove(userGroupRole);
0107: }
0108:
0109: userGroupRole = removeImpl(userGroupRole);
0110:
0111: if (listener != null) {
0112: listener.onAfterRemove(userGroupRole);
0113: }
0114:
0115: return userGroupRole;
0116: }
0117:
0118: protected UserGroupRole removeImpl(UserGroupRole userGroupRole)
0119: throws SystemException {
0120: Session session = null;
0121:
0122: try {
0123: session = openSession();
0124:
0125: session.delete(userGroupRole);
0126:
0127: session.flush();
0128:
0129: return userGroupRole;
0130: } catch (Exception e) {
0131: throw HibernateUtil.processException(e);
0132: } finally {
0133: closeSession(session);
0134:
0135: FinderCache.clearCache(UserGroupRole.class.getName());
0136: }
0137: }
0138:
0139: public UserGroupRole update(UserGroupRole userGroupRole)
0140: throws SystemException {
0141: return update(userGroupRole, false);
0142: }
0143:
0144: public UserGroupRole update(UserGroupRole userGroupRole,
0145: boolean merge) throws SystemException {
0146: ModelListener listener = _getListener();
0147:
0148: boolean isNew = userGroupRole.isNew();
0149:
0150: if (listener != null) {
0151: if (isNew) {
0152: listener.onBeforeCreate(userGroupRole);
0153: } else {
0154: listener.onBeforeUpdate(userGroupRole);
0155: }
0156: }
0157:
0158: userGroupRole = updateImpl(userGroupRole, merge);
0159:
0160: if (listener != null) {
0161: if (isNew) {
0162: listener.onAfterCreate(userGroupRole);
0163: } else {
0164: listener.onAfterUpdate(userGroupRole);
0165: }
0166: }
0167:
0168: return userGroupRole;
0169: }
0170:
0171: public UserGroupRole updateImpl(
0172: com.liferay.portal.model.UserGroupRole userGroupRole,
0173: boolean merge) throws SystemException {
0174: Session session = null;
0175:
0176: try {
0177: session = openSession();
0178:
0179: if (merge) {
0180: session.merge(userGroupRole);
0181: } else {
0182: if (userGroupRole.isNew()) {
0183: session.save(userGroupRole);
0184: }
0185: }
0186:
0187: session.flush();
0188:
0189: userGroupRole.setNew(false);
0190:
0191: return userGroupRole;
0192: } catch (Exception e) {
0193: throw HibernateUtil.processException(e);
0194: } finally {
0195: closeSession(session);
0196:
0197: FinderCache.clearCache(UserGroupRole.class.getName());
0198: }
0199: }
0200:
0201: public UserGroupRole findByPrimaryKey(
0202: UserGroupRolePK userGroupRolePK)
0203: throws NoSuchUserGroupRoleException, SystemException {
0204: UserGroupRole userGroupRole = fetchByPrimaryKey(userGroupRolePK);
0205:
0206: if (userGroupRole == null) {
0207: if (_log.isWarnEnabled()) {
0208: _log
0209: .warn("No UserGroupRole exists with the primary key "
0210: + userGroupRolePK);
0211: }
0212:
0213: throw new NoSuchUserGroupRoleException(
0214: "No UserGroupRole exists with the primary key "
0215: + userGroupRolePK);
0216: }
0217:
0218: return userGroupRole;
0219: }
0220:
0221: public UserGroupRole fetchByPrimaryKey(
0222: UserGroupRolePK userGroupRolePK) throws SystemException {
0223: Session session = null;
0224:
0225: try {
0226: session = openSession();
0227:
0228: return (UserGroupRole) session.get(UserGroupRoleImpl.class,
0229: userGroupRolePK);
0230: } catch (Exception e) {
0231: throw HibernateUtil.processException(e);
0232: } finally {
0233: closeSession(session);
0234: }
0235: }
0236:
0237: public List findByUserId(long userId) throws SystemException {
0238: boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
0239: String finderClassName = UserGroupRole.class.getName();
0240: String finderMethodName = "findByUserId";
0241: String[] finderParams = new String[] { Long.class.getName() };
0242: Object[] finderArgs = new Object[] { new Long(userId) };
0243:
0244: Object result = null;
0245:
0246: if (finderClassNameCacheEnabled) {
0247: result = FinderCache.getResult(finderClassName,
0248: finderMethodName, finderParams, finderArgs,
0249: getSessionFactory());
0250: }
0251:
0252: if (result == null) {
0253: Session session = null;
0254:
0255: try {
0256: session = openSession();
0257:
0258: StringMaker query = new StringMaker();
0259:
0260: query
0261: .append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
0262:
0263: query.append("userId = ?");
0264:
0265: query.append(" ");
0266:
0267: Query q = session.createQuery(query.toString());
0268:
0269: int queryPos = 0;
0270:
0271: q.setLong(queryPos++, userId);
0272:
0273: List list = q.list();
0274:
0275: FinderCache.putResult(finderClassNameCacheEnabled,
0276: finderClassName, finderMethodName,
0277: finderParams, finderArgs, list);
0278:
0279: return list;
0280: } catch (Exception e) {
0281: throw HibernateUtil.processException(e);
0282: } finally {
0283: closeSession(session);
0284: }
0285: } else {
0286: return (List) result;
0287: }
0288: }
0289:
0290: public List findByUserId(long userId, int begin, int end)
0291: throws SystemException {
0292: return findByUserId(userId, begin, end, null);
0293: }
0294:
0295: public List findByUserId(long userId, int begin, int end,
0296: OrderByComparator obc) throws SystemException {
0297: boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
0298: String finderClassName = UserGroupRole.class.getName();
0299: String finderMethodName = "findByUserId";
0300: String[] finderParams = new String[] { Long.class.getName(),
0301:
0302: "java.lang.Integer", "java.lang.Integer",
0303: "com.liferay.portal.kernel.util.OrderByComparator" };
0304: Object[] finderArgs = new Object[] { new Long(userId),
0305:
0306: String.valueOf(begin), String.valueOf(end), String.valueOf(obc) };
0307:
0308: Object result = null;
0309:
0310: if (finderClassNameCacheEnabled) {
0311: result = FinderCache.getResult(finderClassName,
0312: finderMethodName, finderParams, finderArgs,
0313: getSessionFactory());
0314: }
0315:
0316: if (result == null) {
0317: Session session = null;
0318:
0319: try {
0320: session = openSession();
0321:
0322: StringMaker query = new StringMaker();
0323:
0324: query
0325: .append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
0326:
0327: query.append("userId = ?");
0328:
0329: query.append(" ");
0330:
0331: if (obc != null) {
0332: query.append("ORDER BY ");
0333: query.append(obc.getOrderBy());
0334: }
0335:
0336: Query q = session.createQuery(query.toString());
0337:
0338: int queryPos = 0;
0339:
0340: q.setLong(queryPos++, userId);
0341:
0342: List list = QueryUtil.list(q, getDialect(), begin, end);
0343:
0344: FinderCache.putResult(finderClassNameCacheEnabled,
0345: finderClassName, finderMethodName,
0346: finderParams, finderArgs, list);
0347:
0348: return list;
0349: } catch (Exception e) {
0350: throw HibernateUtil.processException(e);
0351: } finally {
0352: closeSession(session);
0353: }
0354: } else {
0355: return (List) result;
0356: }
0357: }
0358:
0359: public UserGroupRole findByUserId_First(long userId,
0360: OrderByComparator obc) throws NoSuchUserGroupRoleException,
0361: SystemException {
0362: List list = findByUserId(userId, 0, 1, obc);
0363:
0364: if (list.size() == 0) {
0365: StringMaker msg = new StringMaker();
0366:
0367: msg.append("No UserGroupRole exists with the key {");
0368:
0369: msg.append("userId=" + userId);
0370:
0371: msg.append(StringPool.CLOSE_CURLY_BRACE);
0372:
0373: throw new NoSuchUserGroupRoleException(msg.toString());
0374: } else {
0375: return (UserGroupRole) list.get(0);
0376: }
0377: }
0378:
0379: public UserGroupRole findByUserId_Last(long userId,
0380: OrderByComparator obc) throws NoSuchUserGroupRoleException,
0381: SystemException {
0382: int count = countByUserId(userId);
0383:
0384: List list = findByUserId(userId, count - 1, count, obc);
0385:
0386: if (list.size() == 0) {
0387: StringMaker msg = new StringMaker();
0388:
0389: msg.append("No UserGroupRole exists with the key {");
0390:
0391: msg.append("userId=" + userId);
0392:
0393: msg.append(StringPool.CLOSE_CURLY_BRACE);
0394:
0395: throw new NoSuchUserGroupRoleException(msg.toString());
0396: } else {
0397: return (UserGroupRole) list.get(0);
0398: }
0399: }
0400:
0401: public UserGroupRole[] findByUserId_PrevAndNext(
0402: UserGroupRolePK userGroupRolePK, long userId,
0403: OrderByComparator obc) throws NoSuchUserGroupRoleException,
0404: SystemException {
0405: UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
0406:
0407: int count = countByUserId(userId);
0408:
0409: Session session = null;
0410:
0411: try {
0412: session = openSession();
0413:
0414: StringMaker query = new StringMaker();
0415:
0416: query
0417: .append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
0418:
0419: query.append("userId = ?");
0420:
0421: query.append(" ");
0422:
0423: if (obc != null) {
0424: query.append("ORDER BY ");
0425: query.append(obc.getOrderBy());
0426: }
0427:
0428: Query q = session.createQuery(query.toString());
0429:
0430: int queryPos = 0;
0431:
0432: q.setLong(queryPos++, userId);
0433:
0434: Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
0435: userGroupRole);
0436:
0437: UserGroupRole[] array = new UserGroupRoleImpl[3];
0438:
0439: array[0] = (UserGroupRole) objArray[0];
0440: array[1] = (UserGroupRole) objArray[1];
0441: array[2] = (UserGroupRole) objArray[2];
0442:
0443: return array;
0444: } catch (Exception e) {
0445: throw HibernateUtil.processException(e);
0446: } finally {
0447: closeSession(session);
0448: }
0449: }
0450:
0451: public List findByGroupId(long groupId) throws SystemException {
0452: boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
0453: String finderClassName = UserGroupRole.class.getName();
0454: String finderMethodName = "findByGroupId";
0455: String[] finderParams = new String[] { Long.class.getName() };
0456: Object[] finderArgs = new Object[] { new Long(groupId) };
0457:
0458: Object result = null;
0459:
0460: if (finderClassNameCacheEnabled) {
0461: result = FinderCache.getResult(finderClassName,
0462: finderMethodName, finderParams, finderArgs,
0463: getSessionFactory());
0464: }
0465:
0466: if (result == null) {
0467: Session session = null;
0468:
0469: try {
0470: session = openSession();
0471:
0472: StringMaker query = new StringMaker();
0473:
0474: query
0475: .append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
0476:
0477: query.append("groupId = ?");
0478:
0479: query.append(" ");
0480:
0481: Query q = session.createQuery(query.toString());
0482:
0483: int queryPos = 0;
0484:
0485: q.setLong(queryPos++, groupId);
0486:
0487: List list = q.list();
0488:
0489: FinderCache.putResult(finderClassNameCacheEnabled,
0490: finderClassName, finderMethodName,
0491: finderParams, finderArgs, list);
0492:
0493: return list;
0494: } catch (Exception e) {
0495: throw HibernateUtil.processException(e);
0496: } finally {
0497: closeSession(session);
0498: }
0499: } else {
0500: return (List) result;
0501: }
0502: }
0503:
0504: public List findByGroupId(long groupId, int begin, int end)
0505: throws SystemException {
0506: return findByGroupId(groupId, begin, end, null);
0507: }
0508:
0509: public List findByGroupId(long groupId, int begin, int end,
0510: OrderByComparator obc) throws SystemException {
0511: boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
0512: String finderClassName = UserGroupRole.class.getName();
0513: String finderMethodName = "findByGroupId";
0514: String[] finderParams = new String[] { Long.class.getName(),
0515:
0516: "java.lang.Integer", "java.lang.Integer",
0517: "com.liferay.portal.kernel.util.OrderByComparator" };
0518: Object[] finderArgs = new Object[] { new Long(groupId),
0519:
0520: String.valueOf(begin), String.valueOf(end), String.valueOf(obc) };
0521:
0522: Object result = null;
0523:
0524: if (finderClassNameCacheEnabled) {
0525: result = FinderCache.getResult(finderClassName,
0526: finderMethodName, finderParams, finderArgs,
0527: getSessionFactory());
0528: }
0529:
0530: if (result == null) {
0531: Session session = null;
0532:
0533: try {
0534: session = openSession();
0535:
0536: StringMaker query = new StringMaker();
0537:
0538: query
0539: .append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
0540:
0541: query.append("groupId = ?");
0542:
0543: query.append(" ");
0544:
0545: if (obc != null) {
0546: query.append("ORDER BY ");
0547: query.append(obc.getOrderBy());
0548: }
0549:
0550: Query q = session.createQuery(query.toString());
0551:
0552: int queryPos = 0;
0553:
0554: q.setLong(queryPos++, groupId);
0555:
0556: List list = QueryUtil.list(q, getDialect(), begin, end);
0557:
0558: FinderCache.putResult(finderClassNameCacheEnabled,
0559: finderClassName, finderMethodName,
0560: finderParams, finderArgs, list);
0561:
0562: return list;
0563: } catch (Exception e) {
0564: throw HibernateUtil.processException(e);
0565: } finally {
0566: closeSession(session);
0567: }
0568: } else {
0569: return (List) result;
0570: }
0571: }
0572:
0573: public UserGroupRole findByGroupId_First(long groupId,
0574: OrderByComparator obc) throws NoSuchUserGroupRoleException,
0575: SystemException {
0576: List list = findByGroupId(groupId, 0, 1, obc);
0577:
0578: if (list.size() == 0) {
0579: StringMaker msg = new StringMaker();
0580:
0581: msg.append("No UserGroupRole exists with the key {");
0582:
0583: msg.append("groupId=" + groupId);
0584:
0585: msg.append(StringPool.CLOSE_CURLY_BRACE);
0586:
0587: throw new NoSuchUserGroupRoleException(msg.toString());
0588: } else {
0589: return (UserGroupRole) list.get(0);
0590: }
0591: }
0592:
0593: public UserGroupRole findByGroupId_Last(long groupId,
0594: OrderByComparator obc) throws NoSuchUserGroupRoleException,
0595: SystemException {
0596: int count = countByGroupId(groupId);
0597:
0598: List list = findByGroupId(groupId, count - 1, count, obc);
0599:
0600: if (list.size() == 0) {
0601: StringMaker msg = new StringMaker();
0602:
0603: msg.append("No UserGroupRole exists with the key {");
0604:
0605: msg.append("groupId=" + groupId);
0606:
0607: msg.append(StringPool.CLOSE_CURLY_BRACE);
0608:
0609: throw new NoSuchUserGroupRoleException(msg.toString());
0610: } else {
0611: return (UserGroupRole) list.get(0);
0612: }
0613: }
0614:
0615: public UserGroupRole[] findByGroupId_PrevAndNext(
0616: UserGroupRolePK userGroupRolePK, long groupId,
0617: OrderByComparator obc) throws NoSuchUserGroupRoleException,
0618: SystemException {
0619: UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
0620:
0621: int count = countByGroupId(groupId);
0622:
0623: Session session = null;
0624:
0625: try {
0626: session = openSession();
0627:
0628: StringMaker query = new StringMaker();
0629:
0630: query
0631: .append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
0632:
0633: query.append("groupId = ?");
0634:
0635: query.append(" ");
0636:
0637: if (obc != null) {
0638: query.append("ORDER BY ");
0639: query.append(obc.getOrderBy());
0640: }
0641:
0642: Query q = session.createQuery(query.toString());
0643:
0644: int queryPos = 0;
0645:
0646: q.setLong(queryPos++, groupId);
0647:
0648: Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
0649: userGroupRole);
0650:
0651: UserGroupRole[] array = new UserGroupRoleImpl[3];
0652:
0653: array[0] = (UserGroupRole) objArray[0];
0654: array[1] = (UserGroupRole) objArray[1];
0655: array[2] = (UserGroupRole) objArray[2];
0656:
0657: return array;
0658: } catch (Exception e) {
0659: throw HibernateUtil.processException(e);
0660: } finally {
0661: closeSession(session);
0662: }
0663: }
0664:
0665: public List findByRoleId(long roleId) throws SystemException {
0666: boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
0667: String finderClassName = UserGroupRole.class.getName();
0668: String finderMethodName = "findByRoleId";
0669: String[] finderParams = new String[] { Long.class.getName() };
0670: Object[] finderArgs = new Object[] { new Long(roleId) };
0671:
0672: Object result = null;
0673:
0674: if (finderClassNameCacheEnabled) {
0675: result = FinderCache.getResult(finderClassName,
0676: finderMethodName, finderParams, finderArgs,
0677: getSessionFactory());
0678: }
0679:
0680: if (result == null) {
0681: Session session = null;
0682:
0683: try {
0684: session = openSession();
0685:
0686: StringMaker query = new StringMaker();
0687:
0688: query
0689: .append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
0690:
0691: query.append("roleId = ?");
0692:
0693: query.append(" ");
0694:
0695: Query q = session.createQuery(query.toString());
0696:
0697: int queryPos = 0;
0698:
0699: q.setLong(queryPos++, roleId);
0700:
0701: List list = q.list();
0702:
0703: FinderCache.putResult(finderClassNameCacheEnabled,
0704: finderClassName, finderMethodName,
0705: finderParams, finderArgs, list);
0706:
0707: return list;
0708: } catch (Exception e) {
0709: throw HibernateUtil.processException(e);
0710: } finally {
0711: closeSession(session);
0712: }
0713: } else {
0714: return (List) result;
0715: }
0716: }
0717:
0718: public List findByRoleId(long roleId, int begin, int end)
0719: throws SystemException {
0720: return findByRoleId(roleId, begin, end, null);
0721: }
0722:
0723: public List findByRoleId(long roleId, int begin, int end,
0724: OrderByComparator obc) throws SystemException {
0725: boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
0726: String finderClassName = UserGroupRole.class.getName();
0727: String finderMethodName = "findByRoleId";
0728: String[] finderParams = new String[] { Long.class.getName(),
0729:
0730: "java.lang.Integer", "java.lang.Integer",
0731: "com.liferay.portal.kernel.util.OrderByComparator" };
0732: Object[] finderArgs = new Object[] { new Long(roleId),
0733:
0734: String.valueOf(begin), String.valueOf(end), String.valueOf(obc) };
0735:
0736: Object result = null;
0737:
0738: if (finderClassNameCacheEnabled) {
0739: result = FinderCache.getResult(finderClassName,
0740: finderMethodName, finderParams, finderArgs,
0741: getSessionFactory());
0742: }
0743:
0744: if (result == null) {
0745: Session session = null;
0746:
0747: try {
0748: session = openSession();
0749:
0750: StringMaker query = new StringMaker();
0751:
0752: query
0753: .append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
0754:
0755: query.append("roleId = ?");
0756:
0757: query.append(" ");
0758:
0759: if (obc != null) {
0760: query.append("ORDER BY ");
0761: query.append(obc.getOrderBy());
0762: }
0763:
0764: Query q = session.createQuery(query.toString());
0765:
0766: int queryPos = 0;
0767:
0768: q.setLong(queryPos++, roleId);
0769:
0770: List list = QueryUtil.list(q, getDialect(), begin, end);
0771:
0772: FinderCache.putResult(finderClassNameCacheEnabled,
0773: finderClassName, finderMethodName,
0774: finderParams, finderArgs, list);
0775:
0776: return list;
0777: } catch (Exception e) {
0778: throw HibernateUtil.processException(e);
0779: } finally {
0780: closeSession(session);
0781: }
0782: } else {
0783: return (List) result;
0784: }
0785: }
0786:
0787: public UserGroupRole findByRoleId_First(long roleId,
0788: OrderByComparator obc) throws NoSuchUserGroupRoleException,
0789: SystemException {
0790: List list = findByRoleId(roleId, 0, 1, obc);
0791:
0792: if (list.size() == 0) {
0793: StringMaker msg = new StringMaker();
0794:
0795: msg.append("No UserGroupRole exists with the key {");
0796:
0797: msg.append("roleId=" + roleId);
0798:
0799: msg.append(StringPool.CLOSE_CURLY_BRACE);
0800:
0801: throw new NoSuchUserGroupRoleException(msg.toString());
0802: } else {
0803: return (UserGroupRole) list.get(0);
0804: }
0805: }
0806:
0807: public UserGroupRole findByRoleId_Last(long roleId,
0808: OrderByComparator obc) throws NoSuchUserGroupRoleException,
0809: SystemException {
0810: int count = countByRoleId(roleId);
0811:
0812: List list = findByRoleId(roleId, count - 1, count, obc);
0813:
0814: if (list.size() == 0) {
0815: StringMaker msg = new StringMaker();
0816:
0817: msg.append("No UserGroupRole exists with the key {");
0818:
0819: msg.append("roleId=" + roleId);
0820:
0821: msg.append(StringPool.CLOSE_CURLY_BRACE);
0822:
0823: throw new NoSuchUserGroupRoleException(msg.toString());
0824: } else {
0825: return (UserGroupRole) list.get(0);
0826: }
0827: }
0828:
0829: public UserGroupRole[] findByRoleId_PrevAndNext(
0830: UserGroupRolePK userGroupRolePK, long roleId,
0831: OrderByComparator obc) throws NoSuchUserGroupRoleException,
0832: SystemException {
0833: UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
0834:
0835: int count = countByRoleId(roleId);
0836:
0837: Session session = null;
0838:
0839: try {
0840: session = openSession();
0841:
0842: StringMaker query = new StringMaker();
0843:
0844: query
0845: .append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
0846:
0847: query.append("roleId = ?");
0848:
0849: query.append(" ");
0850:
0851: if (obc != null) {
0852: query.append("ORDER BY ");
0853: query.append(obc.getOrderBy());
0854: }
0855:
0856: Query q = session.createQuery(query.toString());
0857:
0858: int queryPos = 0;
0859:
0860: q.setLong(queryPos++, roleId);
0861:
0862: Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
0863: userGroupRole);
0864:
0865: UserGroupRole[] array = new UserGroupRoleImpl[3];
0866:
0867: array[0] = (UserGroupRole) objArray[0];
0868: array[1] = (UserGroupRole) objArray[1];
0869: array[2] = (UserGroupRole) objArray[2];
0870:
0871: return array;
0872: } catch (Exception e) {
0873: throw HibernateUtil.processException(e);
0874: } finally {
0875: closeSession(session);
0876: }
0877: }
0878:
0879: public List findByU_G(long userId, long groupId)
0880: throws SystemException {
0881: boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
0882: String finderClassName = UserGroupRole.class.getName();
0883: String finderMethodName = "findByU_G";
0884: String[] finderParams = new String[] { Long.class.getName(),
0885: Long.class.getName() };
0886: Object[] finderArgs = new Object[] { new Long(userId),
0887: new Long(groupId) };
0888:
0889: Object result = null;
0890:
0891: if (finderClassNameCacheEnabled) {
0892: result = FinderCache.getResult(finderClassName,
0893: finderMethodName, finderParams, finderArgs,
0894: getSessionFactory());
0895: }
0896:
0897: if (result == null) {
0898: Session session = null;
0899:
0900: try {
0901: session = openSession();
0902:
0903: StringMaker query = new StringMaker();
0904:
0905: query
0906: .append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
0907:
0908: query.append("userId = ?");
0909:
0910: query.append(" AND ");
0911:
0912: query.append("groupId = ?");
0913:
0914: query.append(" ");
0915:
0916: Query q = session.createQuery(query.toString());
0917:
0918: int queryPos = 0;
0919:
0920: q.setLong(queryPos++, userId);
0921:
0922: q.setLong(queryPos++, groupId);
0923:
0924: List list = q.list();
0925:
0926: FinderCache.putResult(finderClassNameCacheEnabled,
0927: finderClassName, finderMethodName,
0928: finderParams, finderArgs, list);
0929:
0930: return list;
0931: } catch (Exception e) {
0932: throw HibernateUtil.processException(e);
0933: } finally {
0934: closeSession(session);
0935: }
0936: } else {
0937: return (List) result;
0938: }
0939: }
0940:
0941: public List findByU_G(long userId, long groupId, int begin, int end)
0942: throws SystemException {
0943: return findByU_G(userId, groupId, begin, end, null);
0944: }
0945:
0946: public List findByU_G(long userId, long groupId, int begin,
0947: int end, OrderByComparator obc) throws SystemException {
0948: boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
0949: String finderClassName = UserGroupRole.class.getName();
0950: String finderMethodName = "findByU_G";
0951: String[] finderParams = new String[] { Long.class.getName(),
0952: Long.class.getName(),
0953:
0954: "java.lang.Integer", "java.lang.Integer",
0955: "com.liferay.portal.kernel.util.OrderByComparator" };
0956: Object[] finderArgs = new Object[] { new Long(userId),
0957: new Long(groupId),
0958:
0959: String.valueOf(begin), String.valueOf(end),
0960: String.valueOf(obc) };
0961:
0962: Object result = null;
0963:
0964: if (finderClassNameCacheEnabled) {
0965: result = FinderCache.getResult(finderClassName,
0966: finderMethodName, finderParams, finderArgs,
0967: getSessionFactory());
0968: }
0969:
0970: if (result == null) {
0971: Session session = null;
0972:
0973: try {
0974: session = openSession();
0975:
0976: StringMaker query = new StringMaker();
0977:
0978: query
0979: .append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
0980:
0981: query.append("userId = ?");
0982:
0983: query.append(" AND ");
0984:
0985: query.append("groupId = ?");
0986:
0987: query.append(" ");
0988:
0989: if (obc != null) {
0990: query.append("ORDER BY ");
0991: query.append(obc.getOrderBy());
0992: }
0993:
0994: Query q = session.createQuery(query.toString());
0995:
0996: int queryPos = 0;
0997:
0998: q.setLong(queryPos++, userId);
0999:
1000: q.setLong(queryPos++, groupId);
1001:
1002: List list = QueryUtil.list(q, getDialect(), begin, end);
1003:
1004: FinderCache.putResult(finderClassNameCacheEnabled,
1005: finderClassName, finderMethodName,
1006: finderParams, finderArgs, list);
1007:
1008: return list;
1009: } catch (Exception e) {
1010: throw HibernateUtil.processException(e);
1011: } finally {
1012: closeSession(session);
1013: }
1014: } else {
1015: return (List) result;
1016: }
1017: }
1018:
1019: public UserGroupRole findByU_G_First(long userId, long groupId,
1020: OrderByComparator obc) throws NoSuchUserGroupRoleException,
1021: SystemException {
1022: List list = findByU_G(userId, groupId, 0, 1, obc);
1023:
1024: if (list.size() == 0) {
1025: StringMaker msg = new StringMaker();
1026:
1027: msg.append("No UserGroupRole exists with the key {");
1028:
1029: msg.append("userId=" + userId);
1030:
1031: msg.append(", ");
1032: msg.append("groupId=" + groupId);
1033:
1034: msg.append(StringPool.CLOSE_CURLY_BRACE);
1035:
1036: throw new NoSuchUserGroupRoleException(msg.toString());
1037: } else {
1038: return (UserGroupRole) list.get(0);
1039: }
1040: }
1041:
1042: public UserGroupRole findByU_G_Last(long userId, long groupId,
1043: OrderByComparator obc) throws NoSuchUserGroupRoleException,
1044: SystemException {
1045: int count = countByU_G(userId, groupId);
1046:
1047: List list = findByU_G(userId, groupId, count - 1, count, obc);
1048:
1049: if (list.size() == 0) {
1050: StringMaker msg = new StringMaker();
1051:
1052: msg.append("No UserGroupRole exists with the key {");
1053:
1054: msg.append("userId=" + userId);
1055:
1056: msg.append(", ");
1057: msg.append("groupId=" + groupId);
1058:
1059: msg.append(StringPool.CLOSE_CURLY_BRACE);
1060:
1061: throw new NoSuchUserGroupRoleException(msg.toString());
1062: } else {
1063: return (UserGroupRole) list.get(0);
1064: }
1065: }
1066:
1067: public UserGroupRole[] findByU_G_PrevAndNext(
1068: UserGroupRolePK userGroupRolePK, long userId, long groupId,
1069: OrderByComparator obc) throws NoSuchUserGroupRoleException,
1070: SystemException {
1071: UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
1072:
1073: int count = countByU_G(userId, groupId);
1074:
1075: Session session = null;
1076:
1077: try {
1078: session = openSession();
1079:
1080: StringMaker query = new StringMaker();
1081:
1082: query
1083: .append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
1084:
1085: query.append("userId = ?");
1086:
1087: query.append(" AND ");
1088:
1089: query.append("groupId = ?");
1090:
1091: query.append(" ");
1092:
1093: if (obc != null) {
1094: query.append("ORDER BY ");
1095: query.append(obc.getOrderBy());
1096: }
1097:
1098: Query q = session.createQuery(query.toString());
1099:
1100: int queryPos = 0;
1101:
1102: q.setLong(queryPos++, userId);
1103:
1104: q.setLong(queryPos++, groupId);
1105:
1106: Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1107: userGroupRole);
1108:
1109: UserGroupRole[] array = new UserGroupRoleImpl[3];
1110:
1111: array[0] = (UserGroupRole) objArray[0];
1112: array[1] = (UserGroupRole) objArray[1];
1113: array[2] = (UserGroupRole) objArray[2];
1114:
1115: return array;
1116: } catch (Exception e) {
1117: throw HibernateUtil.processException(e);
1118: } finally {
1119: closeSession(session);
1120: }
1121: }
1122:
1123: public List findByG_R(long groupId, long roleId)
1124: throws SystemException {
1125: boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1126: String finderClassName = UserGroupRole.class.getName();
1127: String finderMethodName = "findByG_R";
1128: String[] finderParams = new String[] { Long.class.getName(),
1129: Long.class.getName() };
1130: Object[] finderArgs = new Object[] { new Long(groupId),
1131: new Long(roleId) };
1132:
1133: Object result = null;
1134:
1135: if (finderClassNameCacheEnabled) {
1136: result = FinderCache.getResult(finderClassName,
1137: finderMethodName, finderParams, finderArgs,
1138: getSessionFactory());
1139: }
1140:
1141: if (result == null) {
1142: Session session = null;
1143:
1144: try {
1145: session = openSession();
1146:
1147: StringMaker query = new StringMaker();
1148:
1149: query
1150: .append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
1151:
1152: query.append("groupId = ?");
1153:
1154: query.append(" AND ");
1155:
1156: query.append("roleId = ?");
1157:
1158: query.append(" ");
1159:
1160: Query q = session.createQuery(query.toString());
1161:
1162: int queryPos = 0;
1163:
1164: q.setLong(queryPos++, groupId);
1165:
1166: q.setLong(queryPos++, roleId);
1167:
1168: List list = q.list();
1169:
1170: FinderCache.putResult(finderClassNameCacheEnabled,
1171: finderClassName, finderMethodName,
1172: finderParams, finderArgs, list);
1173:
1174: return list;
1175: } catch (Exception e) {
1176: throw HibernateUtil.processException(e);
1177: } finally {
1178: closeSession(session);
1179: }
1180: } else {
1181: return (List) result;
1182: }
1183: }
1184:
1185: public List findByG_R(long groupId, long roleId, int begin, int end)
1186: throws SystemException {
1187: return findByG_R(groupId, roleId, begin, end, null);
1188: }
1189:
1190: public List findByG_R(long groupId, long roleId, int begin,
1191: int end, OrderByComparator obc) throws SystemException {
1192: boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1193: String finderClassName = UserGroupRole.class.getName();
1194: String finderMethodName = "findByG_R";
1195: String[] finderParams = new String[] { Long.class.getName(),
1196: Long.class.getName(),
1197:
1198: "java.lang.Integer", "java.lang.Integer",
1199: "com.liferay.portal.kernel.util.OrderByComparator" };
1200: Object[] finderArgs = new Object[] { new Long(groupId),
1201: new Long(roleId),
1202:
1203: String.valueOf(begin), String.valueOf(end),
1204: String.valueOf(obc) };
1205:
1206: Object result = null;
1207:
1208: if (finderClassNameCacheEnabled) {
1209: result = FinderCache.getResult(finderClassName,
1210: finderMethodName, finderParams, finderArgs,
1211: getSessionFactory());
1212: }
1213:
1214: if (result == null) {
1215: Session session = null;
1216:
1217: try {
1218: session = openSession();
1219:
1220: StringMaker query = new StringMaker();
1221:
1222: query
1223: .append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
1224:
1225: query.append("groupId = ?");
1226:
1227: query.append(" AND ");
1228:
1229: query.append("roleId = ?");
1230:
1231: query.append(" ");
1232:
1233: if (obc != null) {
1234: query.append("ORDER BY ");
1235: query.append(obc.getOrderBy());
1236: }
1237:
1238: Query q = session.createQuery(query.toString());
1239:
1240: int queryPos = 0;
1241:
1242: q.setLong(queryPos++, groupId);
1243:
1244: q.setLong(queryPos++, roleId);
1245:
1246: List list = QueryUtil.list(q, getDialect(), begin, end);
1247:
1248: FinderCache.putResult(finderClassNameCacheEnabled,
1249: finderClassName, finderMethodName,
1250: finderParams, finderArgs, list);
1251:
1252: return list;
1253: } catch (Exception e) {
1254: throw HibernateUtil.processException(e);
1255: } finally {
1256: closeSession(session);
1257: }
1258: } else {
1259: return (List) result;
1260: }
1261: }
1262:
1263: public UserGroupRole findByG_R_First(long groupId, long roleId,
1264: OrderByComparator obc) throws NoSuchUserGroupRoleException,
1265: SystemException {
1266: List list = findByG_R(groupId, roleId, 0, 1, obc);
1267:
1268: if (list.size() == 0) {
1269: StringMaker msg = new StringMaker();
1270:
1271: msg.append("No UserGroupRole exists with the key {");
1272:
1273: msg.append("groupId=" + groupId);
1274:
1275: msg.append(", ");
1276: msg.append("roleId=" + roleId);
1277:
1278: msg.append(StringPool.CLOSE_CURLY_BRACE);
1279:
1280: throw new NoSuchUserGroupRoleException(msg.toString());
1281: } else {
1282: return (UserGroupRole) list.get(0);
1283: }
1284: }
1285:
1286: public UserGroupRole findByG_R_Last(long groupId, long roleId,
1287: OrderByComparator obc) throws NoSuchUserGroupRoleException,
1288: SystemException {
1289: int count = countByG_R(groupId, roleId);
1290:
1291: List list = findByG_R(groupId, roleId, count - 1, count, obc);
1292:
1293: if (list.size() == 0) {
1294: StringMaker msg = new StringMaker();
1295:
1296: msg.append("No UserGroupRole exists with the key {");
1297:
1298: msg.append("groupId=" + groupId);
1299:
1300: msg.append(", ");
1301: msg.append("roleId=" + roleId);
1302:
1303: msg.append(StringPool.CLOSE_CURLY_BRACE);
1304:
1305: throw new NoSuchUserGroupRoleException(msg.toString());
1306: } else {
1307: return (UserGroupRole) list.get(0);
1308: }
1309: }
1310:
1311: public UserGroupRole[] findByG_R_PrevAndNext(
1312: UserGroupRolePK userGroupRolePK, long groupId, long roleId,
1313: OrderByComparator obc) throws NoSuchUserGroupRoleException,
1314: SystemException {
1315: UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
1316:
1317: int count = countByG_R(groupId, roleId);
1318:
1319: Session session = null;
1320:
1321: try {
1322: session = openSession();
1323:
1324: StringMaker query = new StringMaker();
1325:
1326: query
1327: .append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
1328:
1329: query.append("groupId = ?");
1330:
1331: query.append(" AND ");
1332:
1333: query.append("roleId = ?");
1334:
1335: query.append(" ");
1336:
1337: if (obc != null) {
1338: query.append("ORDER BY ");
1339: query.append(obc.getOrderBy());
1340: }
1341:
1342: Query q = session.createQuery(query.toString());
1343:
1344: int queryPos = 0;
1345:
1346: q.setLong(queryPos++, groupId);
1347:
1348: q.setLong(queryPos++, roleId);
1349:
1350: Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1351: userGroupRole);
1352:
1353: UserGroupRole[] array = new UserGroupRoleImpl[3];
1354:
1355: array[0] = (UserGroupRole) objArray[0];
1356: array[1] = (UserGroupRole) objArray[1];
1357: array[2] = (UserGroupRole) objArray[2];
1358:
1359: return array;
1360: } catch (Exception e) {
1361: throw HibernateUtil.processException(e);
1362: } finally {
1363: closeSession(session);
1364: }
1365: }
1366:
1367: public List findWithDynamicQuery(
1368: DynamicQueryInitializer queryInitializer)
1369: throws SystemException {
1370: Session session = null;
1371:
1372: try {
1373: session = openSession();
1374:
1375: DynamicQuery query = queryInitializer.initialize(session);
1376:
1377: return query.list();
1378: } catch (Exception e) {
1379: throw HibernateUtil.processException(e);
1380: } finally {
1381: closeSession(session);
1382: }
1383: }
1384:
1385: public List findWithDynamicQuery(
1386: DynamicQueryInitializer queryInitializer, int begin, int end)
1387: throws SystemException {
1388: Session session = null;
1389:
1390: try {
1391: session = openSession();
1392:
1393: DynamicQuery query = queryInitializer.initialize(session);
1394:
1395: query.setLimit(begin, end);
1396:
1397: return query.list();
1398: } catch (Exception e) {
1399: throw HibernateUtil.processException(e);
1400: } finally {
1401: closeSession(session);
1402: }
1403: }
1404:
1405: public List findAll() throws SystemException {
1406: return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1407: }
1408:
1409: public List findAll(int begin, int end) throws SystemException {
1410: return findAll(begin, end, null);
1411: }
1412:
1413: public List findAll(int begin, int end, OrderByComparator obc)
1414: throws SystemException {
1415: boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1416: String finderClassName = UserGroupRole.class.getName();
1417: String finderMethodName = "findAll";
1418: String[] finderParams = new String[] { "java.lang.Integer",
1419: "java.lang.Integer",
1420: "com.liferay.portal.kernel.util.OrderByComparator" };
1421: Object[] finderArgs = new Object[] { String.valueOf(begin),
1422: String.valueOf(end), String.valueOf(obc) };
1423:
1424: Object result = null;
1425:
1426: if (finderClassNameCacheEnabled) {
1427: result = FinderCache.getResult(finderClassName,
1428: finderMethodName, finderParams, finderArgs,
1429: getSessionFactory());
1430: }
1431:
1432: if (result == null) {
1433: Session session = null;
1434:
1435: try {
1436: session = openSession();
1437:
1438: StringMaker query = new StringMaker();
1439:
1440: query
1441: .append("FROM com.liferay.portal.model.UserGroupRole ");
1442:
1443: if (obc != null) {
1444: query.append("ORDER BY ");
1445: query.append(obc.getOrderBy());
1446: }
1447:
1448: Query q = session.createQuery(query.toString());
1449:
1450: List list = QueryUtil.list(q, getDialect(), begin, end);
1451:
1452: if (obc == null) {
1453: Collections.sort(list);
1454: }
1455:
1456: FinderCache.putResult(finderClassNameCacheEnabled,
1457: finderClassName, finderMethodName,
1458: finderParams, finderArgs, list);
1459:
1460: return list;
1461: } catch (Exception e) {
1462: throw HibernateUtil.processException(e);
1463: } finally {
1464: closeSession(session);
1465: }
1466: } else {
1467: return (List) result;
1468: }
1469: }
1470:
1471: public void removeByUserId(long userId) throws SystemException {
1472: Iterator itr = findByUserId(userId).iterator();
1473:
1474: while (itr.hasNext()) {
1475: UserGroupRole userGroupRole = (UserGroupRole) itr.next();
1476:
1477: remove(userGroupRole);
1478: }
1479: }
1480:
1481: public void removeByGroupId(long groupId) throws SystemException {
1482: Iterator itr = findByGroupId(groupId).iterator();
1483:
1484: while (itr.hasNext()) {
1485: UserGroupRole userGroupRole = (UserGroupRole) itr.next();
1486:
1487: remove(userGroupRole);
1488: }
1489: }
1490:
1491: public void removeByRoleId(long roleId) throws SystemException {
1492: Iterator itr = findByRoleId(roleId).iterator();
1493:
1494: while (itr.hasNext()) {
1495: UserGroupRole userGroupRole = (UserGroupRole) itr.next();
1496:
1497: remove(userGroupRole);
1498: }
1499: }
1500:
1501: public void removeByU_G(long userId, long groupId)
1502: throws SystemException {
1503: Iterator itr = findByU_G(userId, groupId).iterator();
1504:
1505: while (itr.hasNext()) {
1506: UserGroupRole userGroupRole = (UserGroupRole) itr.next();
1507:
1508: remove(userGroupRole);
1509: }
1510: }
1511:
1512: public void removeByG_R(long groupId, long roleId)
1513: throws SystemException {
1514: Iterator itr = findByG_R(groupId, roleId).iterator();
1515:
1516: while (itr.hasNext()) {
1517: UserGroupRole userGroupRole = (UserGroupRole) itr.next();
1518:
1519: remove(userGroupRole);
1520: }
1521: }
1522:
1523: public void removeAll() throws SystemException {
1524: Iterator itr = findAll().iterator();
1525:
1526: while (itr.hasNext()) {
1527: remove((UserGroupRole) itr.next());
1528: }
1529: }
1530:
1531: public int countByUserId(long userId) throws SystemException {
1532: boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1533: String finderClassName = UserGroupRole.class.getName();
1534: String finderMethodName = "countByUserId";
1535: String[] finderParams = new String[] { Long.class.getName() };
1536: Object[] finderArgs = new Object[] { new Long(userId) };
1537:
1538: Object result = null;
1539:
1540: if (finderClassNameCacheEnabled) {
1541: result = FinderCache.getResult(finderClassName,
1542: finderMethodName, finderParams, finderArgs,
1543: getSessionFactory());
1544: }
1545:
1546: if (result == null) {
1547: Session session = null;
1548:
1549: try {
1550: session = openSession();
1551:
1552: StringMaker query = new StringMaker();
1553:
1554: query.append("SELECT COUNT(*) ");
1555: query
1556: .append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
1557:
1558: query.append("userId = ?");
1559:
1560: query.append(" ");
1561:
1562: Query q = session.createQuery(query.toString());
1563:
1564: int queryPos = 0;
1565:
1566: q.setLong(queryPos++, userId);
1567:
1568: Long count = null;
1569:
1570: Iterator itr = q.list().iterator();
1571:
1572: if (itr.hasNext()) {
1573: count = (Long) itr.next();
1574: }
1575:
1576: if (count == null) {
1577: count = new Long(0);
1578: }
1579:
1580: FinderCache.putResult(finderClassNameCacheEnabled,
1581: finderClassName, finderMethodName,
1582: finderParams, finderArgs, count);
1583:
1584: return count.intValue();
1585: } catch (Exception e) {
1586: throw HibernateUtil.processException(e);
1587: } finally {
1588: closeSession(session);
1589: }
1590: } else {
1591: return ((Long) result).intValue();
1592: }
1593: }
1594:
1595: public int countByGroupId(long groupId) throws SystemException {
1596: boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1597: String finderClassName = UserGroupRole.class.getName();
1598: String finderMethodName = "countByGroupId";
1599: String[] finderParams = new String[] { Long.class.getName() };
1600: Object[] finderArgs = new Object[] { new Long(groupId) };
1601:
1602: Object result = null;
1603:
1604: if (finderClassNameCacheEnabled) {
1605: result = FinderCache.getResult(finderClassName,
1606: finderMethodName, finderParams, finderArgs,
1607: getSessionFactory());
1608: }
1609:
1610: if (result == null) {
1611: Session session = null;
1612:
1613: try {
1614: session = openSession();
1615:
1616: StringMaker query = new StringMaker();
1617:
1618: query.append("SELECT COUNT(*) ");
1619: query
1620: .append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
1621:
1622: query.append("groupId = ?");
1623:
1624: query.append(" ");
1625:
1626: Query q = session.createQuery(query.toString());
1627:
1628: int queryPos = 0;
1629:
1630: q.setLong(queryPos++, groupId);
1631:
1632: Long count = null;
1633:
1634: Iterator itr = q.list().iterator();
1635:
1636: if (itr.hasNext()) {
1637: count = (Long) itr.next();
1638: }
1639:
1640: if (count == null) {
1641: count = new Long(0);
1642: }
1643:
1644: FinderCache.putResult(finderClassNameCacheEnabled,
1645: finderClassName, finderMethodName,
1646: finderParams, finderArgs, count);
1647:
1648: return count.intValue();
1649: } catch (Exception e) {
1650: throw HibernateUtil.processException(e);
1651: } finally {
1652: closeSession(session);
1653: }
1654: } else {
1655: return ((Long) result).intValue();
1656: }
1657: }
1658:
1659: public int countByRoleId(long roleId) throws SystemException {
1660: boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1661: String finderClassName = UserGroupRole.class.getName();
1662: String finderMethodName = "countByRoleId";
1663: String[] finderParams = new String[] { Long.class.getName() };
1664: Object[] finderArgs = new Object[] { new Long(roleId) };
1665:
1666: Object result = null;
1667:
1668: if (finderClassNameCacheEnabled) {
1669: result = FinderCache.getResult(finderClassName,
1670: finderMethodName, finderParams, finderArgs,
1671: getSessionFactory());
1672: }
1673:
1674: if (result == null) {
1675: Session session = null;
1676:
1677: try {
1678: session = openSession();
1679:
1680: StringMaker query = new StringMaker();
1681:
1682: query.append("SELECT COUNT(*) ");
1683: query
1684: .append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
1685:
1686: query.append("roleId = ?");
1687:
1688: query.append(" ");
1689:
1690: Query q = session.createQuery(query.toString());
1691:
1692: int queryPos = 0;
1693:
1694: q.setLong(queryPos++, roleId);
1695:
1696: Long count = null;
1697:
1698: Iterator itr = q.list().iterator();
1699:
1700: if (itr.hasNext()) {
1701: count = (Long) itr.next();
1702: }
1703:
1704: if (count == null) {
1705: count = new Long(0);
1706: }
1707:
1708: FinderCache.putResult(finderClassNameCacheEnabled,
1709: finderClassName, finderMethodName,
1710: finderParams, finderArgs, count);
1711:
1712: return count.intValue();
1713: } catch (Exception e) {
1714: throw HibernateUtil.processException(e);
1715: } finally {
1716: closeSession(session);
1717: }
1718: } else {
1719: return ((Long) result).intValue();
1720: }
1721: }
1722:
1723: public int countByU_G(long userId, long groupId)
1724: throws SystemException {
1725: boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1726: String finderClassName = UserGroupRole.class.getName();
1727: String finderMethodName = "countByU_G";
1728: String[] finderParams = new String[] { Long.class.getName(),
1729: Long.class.getName() };
1730: Object[] finderArgs = new Object[] { new Long(userId),
1731: new Long(groupId) };
1732:
1733: Object result = null;
1734:
1735: if (finderClassNameCacheEnabled) {
1736: result = FinderCache.getResult(finderClassName,
1737: finderMethodName, finderParams, finderArgs,
1738: getSessionFactory());
1739: }
1740:
1741: if (result == null) {
1742: Session session = null;
1743:
1744: try {
1745: session = openSession();
1746:
1747: StringMaker query = new StringMaker();
1748:
1749: query.append("SELECT COUNT(*) ");
1750: query
1751: .append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
1752:
1753: query.append("userId = ?");
1754:
1755: query.append(" AND ");
1756:
1757: query.append("groupId = ?");
1758:
1759: query.append(" ");
1760:
1761: Query q = session.createQuery(query.toString());
1762:
1763: int queryPos = 0;
1764:
1765: q.setLong(queryPos++, userId);
1766:
1767: q.setLong(queryPos++, groupId);
1768:
1769: Long count = null;
1770:
1771: Iterator itr = q.list().iterator();
1772:
1773: if (itr.hasNext()) {
1774: count = (Long) itr.next();
1775: }
1776:
1777: if (count == null) {
1778: count = new Long(0);
1779: }
1780:
1781: FinderCache.putResult(finderClassNameCacheEnabled,
1782: finderClassName, finderMethodName,
1783: finderParams, finderArgs, count);
1784:
1785: return count.intValue();
1786: } catch (Exception e) {
1787: throw HibernateUtil.processException(e);
1788: } finally {
1789: closeSession(session);
1790: }
1791: } else {
1792: return ((Long) result).intValue();
1793: }
1794: }
1795:
1796: public int countByG_R(long groupId, long roleId)
1797: throws SystemException {
1798: boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1799: String finderClassName = UserGroupRole.class.getName();
1800: String finderMethodName = "countByG_R";
1801: String[] finderParams = new String[] { Long.class.getName(),
1802: Long.class.getName() };
1803: Object[] finderArgs = new Object[] { new Long(groupId),
1804: new Long(roleId) };
1805:
1806: Object result = null;
1807:
1808: if (finderClassNameCacheEnabled) {
1809: result = FinderCache.getResult(finderClassName,
1810: finderMethodName, finderParams, finderArgs,
1811: getSessionFactory());
1812: }
1813:
1814: if (result == null) {
1815: Session session = null;
1816:
1817: try {
1818: session = openSession();
1819:
1820: StringMaker query = new StringMaker();
1821:
1822: query.append("SELECT COUNT(*) ");
1823: query
1824: .append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
1825:
1826: query.append("groupId = ?");
1827:
1828: query.append(" AND ");
1829:
1830: query.append("roleId = ?");
1831:
1832: query.append(" ");
1833:
1834: Query q = session.createQuery(query.toString());
1835:
1836: int queryPos = 0;
1837:
1838: q.setLong(queryPos++, groupId);
1839:
1840: q.setLong(queryPos++, roleId);
1841:
1842: Long count = null;
1843:
1844: Iterator itr = q.list().iterator();
1845:
1846: if (itr.hasNext()) {
1847: count = (Long) itr.next();
1848: }
1849:
1850: if (count == null) {
1851: count = new Long(0);
1852: }
1853:
1854: FinderCache.putResult(finderClassNameCacheEnabled,
1855: finderClassName, finderMethodName,
1856: finderParams, finderArgs, count);
1857:
1858: return count.intValue();
1859: } catch (Exception e) {
1860: throw HibernateUtil.processException(e);
1861: } finally {
1862: closeSession(session);
1863: }
1864: } else {
1865: return ((Long) result).intValue();
1866: }
1867: }
1868:
1869: public int countAll() throws SystemException {
1870: boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1871: String finderClassName = UserGroupRole.class.getName();
1872: String finderMethodName = "countAll";
1873: String[] finderParams = new String[] {};
1874: Object[] finderArgs = new Object[] {};
1875:
1876: Object result = null;
1877:
1878: if (finderClassNameCacheEnabled) {
1879: result = FinderCache.getResult(finderClassName,
1880: finderMethodName, finderParams, finderArgs,
1881: getSessionFactory());
1882: }
1883:
1884: if (result == null) {
1885: Session session = null;
1886:
1887: try {
1888: session = openSession();
1889:
1890: Query q = session
1891: .createQuery("SELECT COUNT(*) FROM com.liferay.portal.model.UserGroupRole");
1892:
1893: Long count = null;
1894:
1895: Iterator itr = q.list().iterator();
1896:
1897: if (itr.hasNext()) {
1898: count = (Long) itr.next();
1899: }
1900:
1901: if (count == null) {
1902: count = new Long(0);
1903: }
1904:
1905: FinderCache.putResult(finderClassNameCacheEnabled,
1906: finderClassName, finderMethodName,
1907: finderParams, finderArgs, count);
1908:
1909: return count.intValue();
1910: } catch (Exception e) {
1911: throw HibernateUtil.processException(e);
1912: } finally {
1913: closeSession(session);
1914: }
1915: } else {
1916: return ((Long) result).intValue();
1917: }
1918: }
1919:
1920: protected void initDao() {
1921: }
1922:
1923: private static ModelListener _getListener() {
1924: if (Validator.isNotNull(_LISTENER)) {
1925: try {
1926: return (ModelListener) Class.forName(_LISTENER)
1927: .newInstance();
1928: } catch (Exception e) {
1929: _log.error(e);
1930: }
1931: }
1932:
1933: return null;
1934: }
1935:
1936: private static final String _LISTENER = GetterUtil
1937: .getString(PropsUtil
1938: .get("value.object.listener.com.liferay.portal.model.UserGroupRole"));
1939: private static Log _log = LogFactory
1940: .getLog(UserGroupRolePersistenceImpl.class);
1941: }
|