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.NoSuchUserIdMapperException;
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.UserIdMapper;
0034: import com.liferay.portal.model.impl.UserIdMapperImpl;
0035: import com.liferay.portal.model.impl.UserIdMapperModelImpl;
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="UserIdMapperPersistenceImpl.java.html"><b><i>View Source</i></b></a>
0054: *
0055: * @author Brian Wing Shun Chan
0056: *
0057: */
0058: public class UserIdMapperPersistenceImpl extends BasePersistence
0059: implements UserIdMapperPersistence {
0060: public UserIdMapper create(long userIdMapperId) {
0061: UserIdMapper userIdMapper = new UserIdMapperImpl();
0062:
0063: userIdMapper.setNew(true);
0064: userIdMapper.setPrimaryKey(userIdMapperId);
0065:
0066: return userIdMapper;
0067: }
0068:
0069: public UserIdMapper remove(long userIdMapperId)
0070: throws NoSuchUserIdMapperException, SystemException {
0071: Session session = null;
0072:
0073: try {
0074: session = openSession();
0075:
0076: UserIdMapper userIdMapper = (UserIdMapper) session.get(
0077: UserIdMapperImpl.class, new Long(userIdMapperId));
0078:
0079: if (userIdMapper == null) {
0080: if (_log.isWarnEnabled()) {
0081: _log
0082: .warn("No UserIdMapper exists with the primary key "
0083: + userIdMapperId);
0084: }
0085:
0086: throw new NoSuchUserIdMapperException(
0087: "No UserIdMapper exists with the primary key "
0088: + userIdMapperId);
0089: }
0090:
0091: return remove(userIdMapper);
0092: } catch (NoSuchUserIdMapperException nsee) {
0093: throw nsee;
0094: } catch (Exception e) {
0095: throw HibernateUtil.processException(e);
0096: } finally {
0097: closeSession(session);
0098: }
0099: }
0100:
0101: public UserIdMapper remove(UserIdMapper userIdMapper)
0102: throws SystemException {
0103: ModelListener listener = _getListener();
0104:
0105: if (listener != null) {
0106: listener.onBeforeRemove(userIdMapper);
0107: }
0108:
0109: userIdMapper = removeImpl(userIdMapper);
0110:
0111: if (listener != null) {
0112: listener.onAfterRemove(userIdMapper);
0113: }
0114:
0115: return userIdMapper;
0116: }
0117:
0118: protected UserIdMapper removeImpl(UserIdMapper userIdMapper)
0119: throws SystemException {
0120: Session session = null;
0121:
0122: try {
0123: session = openSession();
0124:
0125: session.delete(userIdMapper);
0126:
0127: session.flush();
0128:
0129: return userIdMapper;
0130: } catch (Exception e) {
0131: throw HibernateUtil.processException(e);
0132: } finally {
0133: closeSession(session);
0134:
0135: FinderCache.clearCache(UserIdMapper.class.getName());
0136: }
0137: }
0138:
0139: public UserIdMapper update(UserIdMapper userIdMapper)
0140: throws SystemException {
0141: return update(userIdMapper, false);
0142: }
0143:
0144: public UserIdMapper update(UserIdMapper userIdMapper, boolean merge)
0145: throws SystemException {
0146: ModelListener listener = _getListener();
0147:
0148: boolean isNew = userIdMapper.isNew();
0149:
0150: if (listener != null) {
0151: if (isNew) {
0152: listener.onBeforeCreate(userIdMapper);
0153: } else {
0154: listener.onBeforeUpdate(userIdMapper);
0155: }
0156: }
0157:
0158: userIdMapper = updateImpl(userIdMapper, merge);
0159:
0160: if (listener != null) {
0161: if (isNew) {
0162: listener.onAfterCreate(userIdMapper);
0163: } else {
0164: listener.onAfterUpdate(userIdMapper);
0165: }
0166: }
0167:
0168: return userIdMapper;
0169: }
0170:
0171: public UserIdMapper updateImpl(
0172: com.liferay.portal.model.UserIdMapper userIdMapper,
0173: boolean merge) throws SystemException {
0174: Session session = null;
0175:
0176: try {
0177: session = openSession();
0178:
0179: if (merge) {
0180: session.merge(userIdMapper);
0181: } else {
0182: if (userIdMapper.isNew()) {
0183: session.save(userIdMapper);
0184: }
0185: }
0186:
0187: session.flush();
0188:
0189: userIdMapper.setNew(false);
0190:
0191: return userIdMapper;
0192: } catch (Exception e) {
0193: throw HibernateUtil.processException(e);
0194: } finally {
0195: closeSession(session);
0196:
0197: FinderCache.clearCache(UserIdMapper.class.getName());
0198: }
0199: }
0200:
0201: public UserIdMapper findByPrimaryKey(long userIdMapperId)
0202: throws NoSuchUserIdMapperException, SystemException {
0203: UserIdMapper userIdMapper = fetchByPrimaryKey(userIdMapperId);
0204:
0205: if (userIdMapper == null) {
0206: if (_log.isWarnEnabled()) {
0207: _log
0208: .warn("No UserIdMapper exists with the primary key "
0209: + userIdMapperId);
0210: }
0211:
0212: throw new NoSuchUserIdMapperException(
0213: "No UserIdMapper exists with the primary key "
0214: + userIdMapperId);
0215: }
0216:
0217: return userIdMapper;
0218: }
0219:
0220: public UserIdMapper fetchByPrimaryKey(long userIdMapperId)
0221: throws SystemException {
0222: Session session = null;
0223:
0224: try {
0225: session = openSession();
0226:
0227: return (UserIdMapper) session.get(UserIdMapperImpl.class,
0228: new Long(userIdMapperId));
0229: } catch (Exception e) {
0230: throw HibernateUtil.processException(e);
0231: } finally {
0232: closeSession(session);
0233: }
0234: }
0235:
0236: public List findByUserId(long userId) throws SystemException {
0237: boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
0238: String finderClassName = UserIdMapper.class.getName();
0239: String finderMethodName = "findByUserId";
0240: String[] finderParams = new String[] { Long.class.getName() };
0241: Object[] finderArgs = new Object[] { new Long(userId) };
0242:
0243: Object result = null;
0244:
0245: if (finderClassNameCacheEnabled) {
0246: result = FinderCache.getResult(finderClassName,
0247: finderMethodName, finderParams, finderArgs,
0248: getSessionFactory());
0249: }
0250:
0251: if (result == null) {
0252: Session session = null;
0253:
0254: try {
0255: session = openSession();
0256:
0257: StringMaker query = new StringMaker();
0258:
0259: query
0260: .append("FROM com.liferay.portal.model.UserIdMapper WHERE ");
0261:
0262: query.append("userId = ?");
0263:
0264: query.append(" ");
0265:
0266: Query q = session.createQuery(query.toString());
0267:
0268: int queryPos = 0;
0269:
0270: q.setLong(queryPos++, userId);
0271:
0272: List list = q.list();
0273:
0274: FinderCache.putResult(finderClassNameCacheEnabled,
0275: finderClassName, finderMethodName,
0276: finderParams, finderArgs, list);
0277:
0278: return list;
0279: } catch (Exception e) {
0280: throw HibernateUtil.processException(e);
0281: } finally {
0282: closeSession(session);
0283: }
0284: } else {
0285: return (List) result;
0286: }
0287: }
0288:
0289: public List findByUserId(long userId, int begin, int end)
0290: throws SystemException {
0291: return findByUserId(userId, begin, end, null);
0292: }
0293:
0294: public List findByUserId(long userId, int begin, int end,
0295: OrderByComparator obc) throws SystemException {
0296: boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
0297: String finderClassName = UserIdMapper.class.getName();
0298: String finderMethodName = "findByUserId";
0299: String[] finderParams = new String[] { Long.class.getName(),
0300:
0301: "java.lang.Integer", "java.lang.Integer",
0302: "com.liferay.portal.kernel.util.OrderByComparator" };
0303: Object[] finderArgs = new Object[] { new Long(userId),
0304:
0305: String.valueOf(begin), String.valueOf(end), String.valueOf(obc) };
0306:
0307: Object result = null;
0308:
0309: if (finderClassNameCacheEnabled) {
0310: result = FinderCache.getResult(finderClassName,
0311: finderMethodName, finderParams, finderArgs,
0312: getSessionFactory());
0313: }
0314:
0315: if (result == null) {
0316: Session session = null;
0317:
0318: try {
0319: session = openSession();
0320:
0321: StringMaker query = new StringMaker();
0322:
0323: query
0324: .append("FROM com.liferay.portal.model.UserIdMapper WHERE ");
0325:
0326: query.append("userId = ?");
0327:
0328: query.append(" ");
0329:
0330: if (obc != null) {
0331: query.append("ORDER BY ");
0332: query.append(obc.getOrderBy());
0333: }
0334:
0335: Query q = session.createQuery(query.toString());
0336:
0337: int queryPos = 0;
0338:
0339: q.setLong(queryPos++, userId);
0340:
0341: List list = QueryUtil.list(q, getDialect(), begin, end);
0342:
0343: FinderCache.putResult(finderClassNameCacheEnabled,
0344: finderClassName, finderMethodName,
0345: finderParams, finderArgs, list);
0346:
0347: return list;
0348: } catch (Exception e) {
0349: throw HibernateUtil.processException(e);
0350: } finally {
0351: closeSession(session);
0352: }
0353: } else {
0354: return (List) result;
0355: }
0356: }
0357:
0358: public UserIdMapper findByUserId_First(long userId,
0359: OrderByComparator obc) throws NoSuchUserIdMapperException,
0360: SystemException {
0361: List list = findByUserId(userId, 0, 1, obc);
0362:
0363: if (list.size() == 0) {
0364: StringMaker msg = new StringMaker();
0365:
0366: msg.append("No UserIdMapper exists with the key {");
0367:
0368: msg.append("userId=" + userId);
0369:
0370: msg.append(StringPool.CLOSE_CURLY_BRACE);
0371:
0372: throw new NoSuchUserIdMapperException(msg.toString());
0373: } else {
0374: return (UserIdMapper) list.get(0);
0375: }
0376: }
0377:
0378: public UserIdMapper findByUserId_Last(long userId,
0379: OrderByComparator obc) throws NoSuchUserIdMapperException,
0380: SystemException {
0381: int count = countByUserId(userId);
0382:
0383: List list = findByUserId(userId, count - 1, count, obc);
0384:
0385: if (list.size() == 0) {
0386: StringMaker msg = new StringMaker();
0387:
0388: msg.append("No UserIdMapper exists with the key {");
0389:
0390: msg.append("userId=" + userId);
0391:
0392: msg.append(StringPool.CLOSE_CURLY_BRACE);
0393:
0394: throw new NoSuchUserIdMapperException(msg.toString());
0395: } else {
0396: return (UserIdMapper) list.get(0);
0397: }
0398: }
0399:
0400: public UserIdMapper[] findByUserId_PrevAndNext(long userIdMapperId,
0401: long userId, OrderByComparator obc)
0402: throws NoSuchUserIdMapperException, SystemException {
0403: UserIdMapper userIdMapper = findByPrimaryKey(userIdMapperId);
0404:
0405: int count = countByUserId(userId);
0406:
0407: Session session = null;
0408:
0409: try {
0410: session = openSession();
0411:
0412: StringMaker query = new StringMaker();
0413:
0414: query
0415: .append("FROM com.liferay.portal.model.UserIdMapper WHERE ");
0416:
0417: query.append("userId = ?");
0418:
0419: query.append(" ");
0420:
0421: if (obc != null) {
0422: query.append("ORDER BY ");
0423: query.append(obc.getOrderBy());
0424: }
0425:
0426: Query q = session.createQuery(query.toString());
0427:
0428: int queryPos = 0;
0429:
0430: q.setLong(queryPos++, userId);
0431:
0432: Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
0433: userIdMapper);
0434:
0435: UserIdMapper[] array = new UserIdMapperImpl[3];
0436:
0437: array[0] = (UserIdMapper) objArray[0];
0438: array[1] = (UserIdMapper) objArray[1];
0439: array[2] = (UserIdMapper) objArray[2];
0440:
0441: return array;
0442: } catch (Exception e) {
0443: throw HibernateUtil.processException(e);
0444: } finally {
0445: closeSession(session);
0446: }
0447: }
0448:
0449: public UserIdMapper findByU_T(long userId, String type)
0450: throws NoSuchUserIdMapperException, SystemException {
0451: UserIdMapper userIdMapper = fetchByU_T(userId, type);
0452:
0453: if (userIdMapper == null) {
0454: StringMaker msg = new StringMaker();
0455:
0456: msg.append("No UserIdMapper exists with the key {");
0457:
0458: msg.append("userId=" + userId);
0459:
0460: msg.append(", ");
0461: msg.append("type=" + type);
0462:
0463: msg.append(StringPool.CLOSE_CURLY_BRACE);
0464:
0465: if (_log.isWarnEnabled()) {
0466: _log.warn(msg.toString());
0467: }
0468:
0469: throw new NoSuchUserIdMapperException(msg.toString());
0470: }
0471:
0472: return userIdMapper;
0473: }
0474:
0475: public UserIdMapper fetchByU_T(long userId, String type)
0476: throws SystemException {
0477: boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
0478: String finderClassName = UserIdMapper.class.getName();
0479: String finderMethodName = "fetchByU_T";
0480: String[] finderParams = new String[] { Long.class.getName(),
0481: String.class.getName() };
0482: Object[] finderArgs = new Object[] { new Long(userId), type };
0483:
0484: Object result = null;
0485:
0486: if (finderClassNameCacheEnabled) {
0487: result = FinderCache.getResult(finderClassName,
0488: finderMethodName, finderParams, finderArgs,
0489: getSessionFactory());
0490: }
0491:
0492: if (result == null) {
0493: Session session = null;
0494:
0495: try {
0496: session = openSession();
0497:
0498: StringMaker query = new StringMaker();
0499:
0500: query
0501: .append("FROM com.liferay.portal.model.UserIdMapper WHERE ");
0502:
0503: query.append("userId = ?");
0504:
0505: query.append(" AND ");
0506:
0507: if (type == null) {
0508: query.append("type_ IS NULL");
0509: } else {
0510: query.append("type_ = ?");
0511: }
0512:
0513: query.append(" ");
0514:
0515: Query q = session.createQuery(query.toString());
0516:
0517: int queryPos = 0;
0518:
0519: q.setLong(queryPos++, userId);
0520:
0521: if (type != null) {
0522: q.setString(queryPos++, type);
0523: }
0524:
0525: List list = q.list();
0526:
0527: FinderCache.putResult(finderClassNameCacheEnabled,
0528: finderClassName, finderMethodName,
0529: finderParams, finderArgs, list);
0530:
0531: if (list.size() == 0) {
0532: return null;
0533: } else {
0534: return (UserIdMapper) list.get(0);
0535: }
0536: } catch (Exception e) {
0537: throw HibernateUtil.processException(e);
0538: } finally {
0539: closeSession(session);
0540: }
0541: } else {
0542: List list = (List) result;
0543:
0544: if (list.size() == 0) {
0545: return null;
0546: } else {
0547: return (UserIdMapper) list.get(0);
0548: }
0549: }
0550: }
0551:
0552: public UserIdMapper findByT_E(String type, String externalUserId)
0553: throws NoSuchUserIdMapperException, SystemException {
0554: UserIdMapper userIdMapper = fetchByT_E(type, externalUserId);
0555:
0556: if (userIdMapper == null) {
0557: StringMaker msg = new StringMaker();
0558:
0559: msg.append("No UserIdMapper exists with the key {");
0560:
0561: msg.append("type=" + type);
0562:
0563: msg.append(", ");
0564: msg.append("externalUserId=" + externalUserId);
0565:
0566: msg.append(StringPool.CLOSE_CURLY_BRACE);
0567:
0568: if (_log.isWarnEnabled()) {
0569: _log.warn(msg.toString());
0570: }
0571:
0572: throw new NoSuchUserIdMapperException(msg.toString());
0573: }
0574:
0575: return userIdMapper;
0576: }
0577:
0578: public UserIdMapper fetchByT_E(String type, String externalUserId)
0579: throws SystemException {
0580: boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
0581: String finderClassName = UserIdMapper.class.getName();
0582: String finderMethodName = "fetchByT_E";
0583: String[] finderParams = new String[] { String.class.getName(),
0584: String.class.getName() };
0585: Object[] finderArgs = new Object[] { type, externalUserId };
0586:
0587: Object result = null;
0588:
0589: if (finderClassNameCacheEnabled) {
0590: result = FinderCache.getResult(finderClassName,
0591: finderMethodName, finderParams, finderArgs,
0592: getSessionFactory());
0593: }
0594:
0595: if (result == null) {
0596: Session session = null;
0597:
0598: try {
0599: session = openSession();
0600:
0601: StringMaker query = new StringMaker();
0602:
0603: query
0604: .append("FROM com.liferay.portal.model.UserIdMapper WHERE ");
0605:
0606: if (type == null) {
0607: query.append("type_ IS NULL");
0608: } else {
0609: query.append("type_ = ?");
0610: }
0611:
0612: query.append(" AND ");
0613:
0614: if (externalUserId == null) {
0615: query.append("externalUserId IS NULL");
0616: } else {
0617: query.append("externalUserId = ?");
0618: }
0619:
0620: query.append(" ");
0621:
0622: Query q = session.createQuery(query.toString());
0623:
0624: int queryPos = 0;
0625:
0626: if (type != null) {
0627: q.setString(queryPos++, type);
0628: }
0629:
0630: if (externalUserId != null) {
0631: q.setString(queryPos++, externalUserId);
0632: }
0633:
0634: List list = q.list();
0635:
0636: FinderCache.putResult(finderClassNameCacheEnabled,
0637: finderClassName, finderMethodName,
0638: finderParams, finderArgs, list);
0639:
0640: if (list.size() == 0) {
0641: return null;
0642: } else {
0643: return (UserIdMapper) list.get(0);
0644: }
0645: } catch (Exception e) {
0646: throw HibernateUtil.processException(e);
0647: } finally {
0648: closeSession(session);
0649: }
0650: } else {
0651: List list = (List) result;
0652:
0653: if (list.size() == 0) {
0654: return null;
0655: } else {
0656: return (UserIdMapper) list.get(0);
0657: }
0658: }
0659: }
0660:
0661: public List findWithDynamicQuery(
0662: DynamicQueryInitializer queryInitializer)
0663: throws SystemException {
0664: Session session = null;
0665:
0666: try {
0667: session = openSession();
0668:
0669: DynamicQuery query = queryInitializer.initialize(session);
0670:
0671: return query.list();
0672: } catch (Exception e) {
0673: throw HibernateUtil.processException(e);
0674: } finally {
0675: closeSession(session);
0676: }
0677: }
0678:
0679: public List findWithDynamicQuery(
0680: DynamicQueryInitializer queryInitializer, int begin, int end)
0681: throws SystemException {
0682: Session session = null;
0683:
0684: try {
0685: session = openSession();
0686:
0687: DynamicQuery query = queryInitializer.initialize(session);
0688:
0689: query.setLimit(begin, end);
0690:
0691: return query.list();
0692: } catch (Exception e) {
0693: throw HibernateUtil.processException(e);
0694: } finally {
0695: closeSession(session);
0696: }
0697: }
0698:
0699: public List findAll() throws SystemException {
0700: return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
0701: }
0702:
0703: public List findAll(int begin, int end) throws SystemException {
0704: return findAll(begin, end, null);
0705: }
0706:
0707: public List findAll(int begin, int end, OrderByComparator obc)
0708: throws SystemException {
0709: boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
0710: String finderClassName = UserIdMapper.class.getName();
0711: String finderMethodName = "findAll";
0712: String[] finderParams = new String[] { "java.lang.Integer",
0713: "java.lang.Integer",
0714: "com.liferay.portal.kernel.util.OrderByComparator" };
0715: Object[] finderArgs = new Object[] { String.valueOf(begin),
0716: String.valueOf(end), String.valueOf(obc) };
0717:
0718: Object result = null;
0719:
0720: if (finderClassNameCacheEnabled) {
0721: result = FinderCache.getResult(finderClassName,
0722: finderMethodName, finderParams, finderArgs,
0723: getSessionFactory());
0724: }
0725:
0726: if (result == null) {
0727: Session session = null;
0728:
0729: try {
0730: session = openSession();
0731:
0732: StringMaker query = new StringMaker();
0733:
0734: query
0735: .append("FROM com.liferay.portal.model.UserIdMapper ");
0736:
0737: if (obc != null) {
0738: query.append("ORDER BY ");
0739: query.append(obc.getOrderBy());
0740: }
0741:
0742: Query q = session.createQuery(query.toString());
0743:
0744: List list = QueryUtil.list(q, getDialect(), begin, end);
0745:
0746: if (obc == null) {
0747: Collections.sort(list);
0748: }
0749:
0750: FinderCache.putResult(finderClassNameCacheEnabled,
0751: finderClassName, finderMethodName,
0752: finderParams, finderArgs, list);
0753:
0754: return list;
0755: } catch (Exception e) {
0756: throw HibernateUtil.processException(e);
0757: } finally {
0758: closeSession(session);
0759: }
0760: } else {
0761: return (List) result;
0762: }
0763: }
0764:
0765: public void removeByUserId(long userId) throws SystemException {
0766: Iterator itr = findByUserId(userId).iterator();
0767:
0768: while (itr.hasNext()) {
0769: UserIdMapper userIdMapper = (UserIdMapper) itr.next();
0770:
0771: remove(userIdMapper);
0772: }
0773: }
0774:
0775: public void removeByU_T(long userId, String type)
0776: throws NoSuchUserIdMapperException, SystemException {
0777: UserIdMapper userIdMapper = findByU_T(userId, type);
0778:
0779: remove(userIdMapper);
0780: }
0781:
0782: public void removeByT_E(String type, String externalUserId)
0783: throws NoSuchUserIdMapperException, SystemException {
0784: UserIdMapper userIdMapper = findByT_E(type, externalUserId);
0785:
0786: remove(userIdMapper);
0787: }
0788:
0789: public void removeAll() throws SystemException {
0790: Iterator itr = findAll().iterator();
0791:
0792: while (itr.hasNext()) {
0793: remove((UserIdMapper) itr.next());
0794: }
0795: }
0796:
0797: public int countByUserId(long userId) throws SystemException {
0798: boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
0799: String finderClassName = UserIdMapper.class.getName();
0800: String finderMethodName = "countByUserId";
0801: String[] finderParams = new String[] { Long.class.getName() };
0802: Object[] finderArgs = new Object[] { new Long(userId) };
0803:
0804: Object result = null;
0805:
0806: if (finderClassNameCacheEnabled) {
0807: result = FinderCache.getResult(finderClassName,
0808: finderMethodName, finderParams, finderArgs,
0809: getSessionFactory());
0810: }
0811:
0812: if (result == null) {
0813: Session session = null;
0814:
0815: try {
0816: session = openSession();
0817:
0818: StringMaker query = new StringMaker();
0819:
0820: query.append("SELECT COUNT(*) ");
0821: query
0822: .append("FROM com.liferay.portal.model.UserIdMapper WHERE ");
0823:
0824: query.append("userId = ?");
0825:
0826: query.append(" ");
0827:
0828: Query q = session.createQuery(query.toString());
0829:
0830: int queryPos = 0;
0831:
0832: q.setLong(queryPos++, userId);
0833:
0834: Long count = null;
0835:
0836: Iterator itr = q.list().iterator();
0837:
0838: if (itr.hasNext()) {
0839: count = (Long) itr.next();
0840: }
0841:
0842: if (count == null) {
0843: count = new Long(0);
0844: }
0845:
0846: FinderCache.putResult(finderClassNameCacheEnabled,
0847: finderClassName, finderMethodName,
0848: finderParams, finderArgs, count);
0849:
0850: return count.intValue();
0851: } catch (Exception e) {
0852: throw HibernateUtil.processException(e);
0853: } finally {
0854: closeSession(session);
0855: }
0856: } else {
0857: return ((Long) result).intValue();
0858: }
0859: }
0860:
0861: public int countByU_T(long userId, String type)
0862: throws SystemException {
0863: boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
0864: String finderClassName = UserIdMapper.class.getName();
0865: String finderMethodName = "countByU_T";
0866: String[] finderParams = new String[] { Long.class.getName(),
0867: String.class.getName() };
0868: Object[] finderArgs = new Object[] { new Long(userId), type };
0869:
0870: Object result = null;
0871:
0872: if (finderClassNameCacheEnabled) {
0873: result = FinderCache.getResult(finderClassName,
0874: finderMethodName, finderParams, finderArgs,
0875: getSessionFactory());
0876: }
0877:
0878: if (result == null) {
0879: Session session = null;
0880:
0881: try {
0882: session = openSession();
0883:
0884: StringMaker query = new StringMaker();
0885:
0886: query.append("SELECT COUNT(*) ");
0887: query
0888: .append("FROM com.liferay.portal.model.UserIdMapper WHERE ");
0889:
0890: query.append("userId = ?");
0891:
0892: query.append(" AND ");
0893:
0894: if (type == null) {
0895: query.append("type_ IS NULL");
0896: } else {
0897: query.append("type_ = ?");
0898: }
0899:
0900: query.append(" ");
0901:
0902: Query q = session.createQuery(query.toString());
0903:
0904: int queryPos = 0;
0905:
0906: q.setLong(queryPos++, userId);
0907:
0908: if (type != null) {
0909: q.setString(queryPos++, type);
0910: }
0911:
0912: Long count = null;
0913:
0914: Iterator itr = q.list().iterator();
0915:
0916: if (itr.hasNext()) {
0917: count = (Long) itr.next();
0918: }
0919:
0920: if (count == null) {
0921: count = new Long(0);
0922: }
0923:
0924: FinderCache.putResult(finderClassNameCacheEnabled,
0925: finderClassName, finderMethodName,
0926: finderParams, finderArgs, count);
0927:
0928: return count.intValue();
0929: } catch (Exception e) {
0930: throw HibernateUtil.processException(e);
0931: } finally {
0932: closeSession(session);
0933: }
0934: } else {
0935: return ((Long) result).intValue();
0936: }
0937: }
0938:
0939: public int countByT_E(String type, String externalUserId)
0940: throws SystemException {
0941: boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
0942: String finderClassName = UserIdMapper.class.getName();
0943: String finderMethodName = "countByT_E";
0944: String[] finderParams = new String[] { String.class.getName(),
0945: String.class.getName() };
0946: Object[] finderArgs = new Object[] { type, externalUserId };
0947:
0948: Object result = null;
0949:
0950: if (finderClassNameCacheEnabled) {
0951: result = FinderCache.getResult(finderClassName,
0952: finderMethodName, finderParams, finderArgs,
0953: getSessionFactory());
0954: }
0955:
0956: if (result == null) {
0957: Session session = null;
0958:
0959: try {
0960: session = openSession();
0961:
0962: StringMaker query = new StringMaker();
0963:
0964: query.append("SELECT COUNT(*) ");
0965: query
0966: .append("FROM com.liferay.portal.model.UserIdMapper WHERE ");
0967:
0968: if (type == null) {
0969: query.append("type_ IS NULL");
0970: } else {
0971: query.append("type_ = ?");
0972: }
0973:
0974: query.append(" AND ");
0975:
0976: if (externalUserId == null) {
0977: query.append("externalUserId IS NULL");
0978: } else {
0979: query.append("externalUserId = ?");
0980: }
0981:
0982: query.append(" ");
0983:
0984: Query q = session.createQuery(query.toString());
0985:
0986: int queryPos = 0;
0987:
0988: if (type != null) {
0989: q.setString(queryPos++, type);
0990: }
0991:
0992: if (externalUserId != null) {
0993: q.setString(queryPos++, externalUserId);
0994: }
0995:
0996: Long count = null;
0997:
0998: Iterator itr = q.list().iterator();
0999:
1000: if (itr.hasNext()) {
1001: count = (Long) itr.next();
1002: }
1003:
1004: if (count == null) {
1005: count = new Long(0);
1006: }
1007:
1008: FinderCache.putResult(finderClassNameCacheEnabled,
1009: finderClassName, finderMethodName,
1010: finderParams, finderArgs, count);
1011:
1012: return count.intValue();
1013: } catch (Exception e) {
1014: throw HibernateUtil.processException(e);
1015: } finally {
1016: closeSession(session);
1017: }
1018: } else {
1019: return ((Long) result).intValue();
1020: }
1021: }
1022:
1023: public int countAll() throws SystemException {
1024: boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
1025: String finderClassName = UserIdMapper.class.getName();
1026: String finderMethodName = "countAll";
1027: String[] finderParams = new String[] {};
1028: Object[] finderArgs = new Object[] {};
1029:
1030: Object result = null;
1031:
1032: if (finderClassNameCacheEnabled) {
1033: result = FinderCache.getResult(finderClassName,
1034: finderMethodName, finderParams, finderArgs,
1035: getSessionFactory());
1036: }
1037:
1038: if (result == null) {
1039: Session session = null;
1040:
1041: try {
1042: session = openSession();
1043:
1044: Query q = session
1045: .createQuery("SELECT COUNT(*) FROM com.liferay.portal.model.UserIdMapper");
1046:
1047: Long count = null;
1048:
1049: Iterator itr = q.list().iterator();
1050:
1051: if (itr.hasNext()) {
1052: count = (Long) itr.next();
1053: }
1054:
1055: if (count == null) {
1056: count = new Long(0);
1057: }
1058:
1059: FinderCache.putResult(finderClassNameCacheEnabled,
1060: finderClassName, finderMethodName,
1061: finderParams, finderArgs, count);
1062:
1063: return count.intValue();
1064: } catch (Exception e) {
1065: throw HibernateUtil.processException(e);
1066: } finally {
1067: closeSession(session);
1068: }
1069: } else {
1070: return ((Long) result).intValue();
1071: }
1072: }
1073:
1074: protected void initDao() {
1075: }
1076:
1077: private static ModelListener _getListener() {
1078: if (Validator.isNotNull(_LISTENER)) {
1079: try {
1080: return (ModelListener) Class.forName(_LISTENER)
1081: .newInstance();
1082: } catch (Exception e) {
1083: _log.error(e);
1084: }
1085: }
1086:
1087: return null;
1088: }
1089:
1090: private static final String _LISTENER = GetterUtil
1091: .getString(PropsUtil
1092: .get("value.object.listener.com.liferay.portal.model.UserIdMapper"));
1093: private static Log _log = LogFactory
1094: .getLog(UserIdMapperPersistenceImpl.class);
1095: }
|