1
22
23 package com.liferay.mail.service.persistence;
24
25 import com.liferay.mail.NoSuchCyrusUserException;
26 import com.liferay.mail.model.CyrusUser;
27 import com.liferay.portal.SystemException;
28 import com.liferay.portal.kernel.dao.orm.ObjectNotFoundException;
29 import com.liferay.portal.kernel.dao.orm.Session;
30 import com.liferay.portal.model.Dummy;
31 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
32
33
38 public class CyrusUserPersistenceImpl
39 extends BasePersistenceImpl<Dummy> implements CyrusUserPersistence {
40
41 public CyrusUser findByPrimaryKey(long userId)
42 throws NoSuchCyrusUserException, SystemException {
43
44 Session session = null;
45
46 try {
47 session = openSession();
48
49 return (CyrusUser)session.load(
50 CyrusUser.class, String.valueOf(userId));
51 }
52 catch (ObjectNotFoundException onfe) {
53 throw new NoSuchCyrusUserException();
54 }
55 catch (Exception e) {
56 throw processException(e);
57 }
58 finally {
59 closeSession(session);
60 }
61 }
62
63 public void remove(long userId)
64 throws NoSuchCyrusUserException, SystemException {
65
66 Session session = null;
67
68 try {
69 session = openSession();
70
71 CyrusUser user = (CyrusUser)session.load(
72 CyrusUser.class, String.valueOf(userId));
73
74 session.delete(user);
75
76 session.flush();
77 }
78 catch (ObjectNotFoundException onfe) {
79 throw new NoSuchCyrusUserException();
80 }
81 catch (Exception e) {
82 throw processException(e);
83 }
84 finally {
85 closeSession(session);
86 }
87 }
88
89 public void update(CyrusUser user) throws SystemException {
90 Session session = null;
91
92 try {
93 session = openSession();
94
95 try {
96 CyrusUser userModel = (CyrusUser)session.load(
97 CyrusUser.class, String.valueOf(user.getUserId()));
98
99 userModel.setPassword(user.getPassword());
100
101 session.flush();
102 }
103 catch (ObjectNotFoundException onfe) {
104 CyrusUser userModel = new CyrusUser(
105 user.getUserId(), user.getPassword());
106
107 session.save(userModel);
108
109 session.flush();
110 }
111 }
112 catch (Exception e) {
113 throw processException(e);
114 }
115 finally {
116 closeSession(session);
117 }
118 }
119
120 }