001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.mail.service.persistence;
022:
023: import com.liferay.mail.NoSuchCyrusUserException;
024: import com.liferay.mail.model.CyrusUser;
025: import com.liferay.portal.SystemException;
026: import com.liferay.portal.service.persistence.BasePersistence;
027: import com.liferay.portal.spring.hibernate.HibernateUtil;
028:
029: import org.hibernate.ObjectNotFoundException;
030: import org.hibernate.Session;
031:
032: /**
033: * <a href="CyrusUserPersistence.java.html"><b><i>View Source</i></b></a>
034: *
035: * @author Brian Wing Shun Chan
036: *
037: */
038: public class CyrusUserPersistence extends BasePersistence {
039:
040: public void remove(long userId) throws NoSuchCyrusUserException,
041: SystemException {
042:
043: Session session = null;
044:
045: try {
046: session = getSessionFactory().openSession();
047:
048: CyrusUser user = (CyrusUser) session.load(CyrusUser.class,
049: String.valueOf(userId));
050:
051: session.delete(user);
052:
053: session.flush();
054: } catch (ObjectNotFoundException onfe) {
055: throw new NoSuchCyrusUserException();
056: } catch (Exception e) {
057: throw HibernateUtil.processException(e);
058: } finally {
059: session.close();
060: }
061: }
062:
063: public void update(CyrusUser user) throws SystemException {
064: Session session = null;
065:
066: try {
067: session = getSessionFactory().openSession();
068:
069: try {
070: CyrusUser userModel = (CyrusUser) session.load(
071: CyrusUser.class, String.valueOf(user
072: .getUserId()));
073:
074: userModel.setPassword(user.getPassword());
075:
076: session.flush();
077: } catch (ObjectNotFoundException onfe) {
078: CyrusUser userModel = new CyrusUser(user.getUserId(),
079: user.getPassword());
080:
081: session.save(userModel);
082:
083: session.flush();
084: }
085: } catch (Exception e) {
086: throw HibernateUtil.processException(e);
087: } finally {
088: session.close();
089: }
090: }
091:
092: public CyrusUser findByPrimaryKey(long userId)
093: throws NoSuchCyrusUserException, SystemException {
094:
095: Session session = null;
096:
097: try {
098: session = getSessionFactory().openSession();
099:
100: return (CyrusUser) session.load(CyrusUser.class, String
101: .valueOf(userId));
102: } catch (ObjectNotFoundException onfe) {
103: throw new NoSuchCyrusUserException();
104: } catch (Exception e) {
105: throw HibernateUtil.processException(e);
106: } finally {
107: session.close();
108: }
109: }
110:
111: }
|