1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.mail.service.persistence;
16  
17  import com.liferay.mail.NoSuchCyrusUserException;
18  import com.liferay.mail.model.CyrusUser;
19  import com.liferay.portal.SystemException;
20  import com.liferay.portal.kernel.dao.orm.ObjectNotFoundException;
21  import com.liferay.portal.kernel.dao.orm.Session;
22  import com.liferay.portal.model.Dummy;
23  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
24  
25  /**
26   * <a href="CyrusUserPersistenceImpl.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Brian Wing Shun Chan
29   */
30  public class CyrusUserPersistenceImpl
31      extends BasePersistenceImpl<Dummy> implements CyrusUserPersistence {
32  
33      public CyrusUser findByPrimaryKey(long userId)
34          throws NoSuchCyrusUserException, SystemException {
35  
36          Session session = null;
37  
38          try {
39              session = openSession();
40  
41              return (CyrusUser)session.load(
42                  CyrusUser.class, String.valueOf(userId));
43          }
44          catch (ObjectNotFoundException onfe) {
45              throw new NoSuchCyrusUserException();
46          }
47          catch (Exception e) {
48              throw processException(e);
49          }
50          finally {
51              closeSession(session);
52          }
53      }
54  
55      public void remove(long userId)
56          throws NoSuchCyrusUserException, SystemException {
57  
58          Session session = null;
59  
60          try {
61              session = openSession();
62  
63              CyrusUser user = (CyrusUser)session.load(
64                  CyrusUser.class, String.valueOf(userId));
65  
66              session.delete(user);
67  
68              session.flush();
69          }
70          catch (ObjectNotFoundException onfe) {
71              throw new NoSuchCyrusUserException();
72          }
73          catch (Exception e) {
74              throw processException(e);
75          }
76          finally {
77              closeSession(session);
78          }
79      }
80  
81      public void update(CyrusUser user) throws SystemException {
82          Session session = null;
83  
84          try {
85              session = openSession();
86  
87              try {
88                  CyrusUser userModel = (CyrusUser)session.load(
89                      CyrusUser.class, String.valueOf(user.getUserId()));
90  
91                  userModel.setPassword(user.getPassword());
92  
93                  session.flush();
94              }
95              catch (ObjectNotFoundException onfe) {
96                  CyrusUser userModel = new CyrusUser(
97                      user.getUserId(), user.getPassword());
98  
99                  session.save(userModel);
100 
101                 session.flush();
102             }
103         }
104         catch (Exception e) {
105             throw processException(e);
106         }
107         finally {
108             closeSession(session);
109         }
110     }
111 
112 }