| CyrusUserPersistence.java |
1 /**
2 * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
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.service.persistence.BasePersistence;
29 import com.liferay.portal.spring.hibernate.HibernateUtil;
30
31 import org.hibernate.ObjectNotFoundException;
32 import org.hibernate.Session;
33
34 /**
35 * <a href="CyrusUserPersistence.java.html"><b><i>View Source</i></b></a>
36 *
37 * @author Brian Wing Shun Chan
38 *
39 */
40 public class CyrusUserPersistence extends BasePersistence {
41
42 public void remove(long userId)
43 throws NoSuchCyrusUserException, SystemException {
44
45 Session session = null;
46
47 try {
48 session = getSessionFactory().openSession();
49
50 CyrusUser user = (CyrusUser)session.load(
51 CyrusUser.class, String.valueOf(userId));
52
53 session.delete(user);
54
55 session.flush();
56 }
57 catch (ObjectNotFoundException onfe) {
58 throw new NoSuchCyrusUserException();
59 }
60 catch (Exception e) {
61 throw HibernateUtil.processException(e);
62 }
63 finally {
64 session.close();
65 }
66 }
67
68 public void update(CyrusUser user) throws SystemException {
69 Session session = null;
70
71 try {
72 session = getSessionFactory().openSession();
73
74 try {
75 CyrusUser userModel = (CyrusUser)session.load(
76 CyrusUser.class, String.valueOf(user.getUserId()));
77
78 userModel.setPassword(user.getPassword());
79
80 session.flush();
81 }
82 catch (ObjectNotFoundException onfe) {
83 CyrusUser userModel = new CyrusUser(
84 user.getUserId(), user.getPassword());
85
86 session.save(userModel);
87
88 session.flush();
89 }
90 }
91 catch (Exception e) {
92 throw HibernateUtil.processException(e);
93 }
94 finally {
95 session.close();
96 }
97 }
98
99 public CyrusUser findByPrimaryKey(long userId)
100 throws NoSuchCyrusUserException, SystemException {
101
102 Session session = null;
103
104 try {
105 session = getSessionFactory().openSession();
106
107 return (CyrusUser)session.load(
108 CyrusUser.class, String.valueOf(userId));
109 }
110 catch (ObjectNotFoundException onfe) {
111 throw new NoSuchCyrusUserException();
112 }
113 catch (Exception e) {
114 throw HibernateUtil.processException(e);
115 }
116 finally {
117 session.close();
118 }
119 }
120
121 }