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