001
014
015 package com.liferay.mail.service.persistence;
016
017 import com.liferay.mail.NoSuchCyrusUserException;
018 import com.liferay.mail.model.CyrusUser;
019 import com.liferay.portal.kernel.dao.orm.ObjectNotFoundException;
020 import com.liferay.portal.kernel.dao.orm.Session;
021 import com.liferay.portal.model.Dummy;
022 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
023
024
027 public class CyrusUserPersistenceImpl
028 extends BasePersistenceImpl<Dummy> implements CyrusUserPersistence {
029
030 @Override
031 public CyrusUser findByPrimaryKey(long userId)
032 throws NoSuchCyrusUserException {
033
034 Session session = null;
035
036 try {
037 session = openSession();
038
039 return (CyrusUser)session.load(
040 CyrusUser.class, String.valueOf(userId));
041 }
042 catch (ObjectNotFoundException onfe) {
043 throw new NoSuchCyrusUserException("{userId=" + userId + "}");
044 }
045 catch (Exception e) {
046 throw processException(e);
047 }
048 finally {
049 closeSession(session);
050 }
051 }
052
053 @Override
054 public void remove(long userId) throws NoSuchCyrusUserException {
055 Session session = null;
056
057 try {
058 session = openSession();
059
060 CyrusUser user = (CyrusUser)session.load(
061 CyrusUser.class, String.valueOf(userId));
062
063 session.delete(user);
064
065 session.flush();
066 }
067 catch (ObjectNotFoundException onfe) {
068 throw new NoSuchCyrusUserException("{userId=" + userId + "}");
069 }
070 catch (Exception e) {
071 throw processException(e);
072 }
073 finally {
074 closeSession(session);
075 }
076 }
077
078 @Override
079 public void update(CyrusUser user) {
080 Session session = null;
081
082 try {
083 session = openSession();
084
085 try {
086 CyrusUser userModel = (CyrusUser)session.load(
087 CyrusUser.class, String.valueOf(user.getUserId()));
088
089 userModel.setPassword(user.getPassword());
090
091 session.flush();
092 }
093 catch (ObjectNotFoundException onfe) {
094 CyrusUser userModel = new CyrusUser(
095 user.getUserId(), user.getPassword());
096
097 session.save(userModel);
098
099 session.flush();
100 }
101 }
102 catch (Exception e) {
103 throw processException(e);
104 }
105 finally {
106 closeSession(session);
107 }
108 }
109
110 }