1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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.kernel.dao.orm.ObjectNotFoundException;
20  import com.liferay.portal.kernel.dao.orm.Session;
21  import com.liferay.portal.kernel.exception.SystemException;
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 }