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