1   /**
2    * Copyright (c) 2000-2009 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.kernel.dao.orm.ObjectNotFoundException;
29  import com.liferay.portal.kernel.dao.orm.Session;
30  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
31  
32  /**
33   * <a href="CyrusUserPersistence.java.html"><b><i>View Source</i></b></a>
34   *
35   * @author Brian Wing Shun Chan
36   *
37   */
38  public class CyrusUserPersistence extends BasePersistenceImpl {
39  
40      public void remove(long userId)
41          throws NoSuchCyrusUserException, SystemException {
42  
43          Session session = null;
44  
45          try {
46              session = openSession();
47  
48              CyrusUser user = (CyrusUser)session.load(
49                  CyrusUser.class, String.valueOf(userId));
50  
51              session.delete(user);
52  
53              session.flush();
54          }
55          catch (ObjectNotFoundException onfe) {
56              throw new NoSuchCyrusUserException();
57          }
58          catch (Exception e) {
59              throw processException(e);
60          }
61          finally {
62              closeSession(session);
63          }
64      }
65  
66      public void update(CyrusUser user) throws SystemException {
67          Session session = null;
68  
69          try {
70              session = openSession();
71  
72              try {
73                  CyrusUser userModel = (CyrusUser)session.load(
74                      CyrusUser.class, String.valueOf(user.getUserId()));
75  
76                  userModel.setPassword(user.getPassword());
77  
78                  session.flush();
79              }
80              catch (ObjectNotFoundException onfe) {
81                  CyrusUser userModel = new CyrusUser(
82                      user.getUserId(), user.getPassword());
83  
84                  session.save(userModel);
85  
86                  session.flush();
87              }
88          }
89          catch (Exception e) {
90              throw processException(e);
91          }
92          finally {
93              closeSession(session);
94          }
95      }
96  
97      public CyrusUser findByPrimaryKey(long userId)
98          throws NoSuchCyrusUserException, SystemException {
99  
100         Session session = null;
101 
102         try {
103             session = openSession();
104 
105             return (CyrusUser)session.load(
106                 CyrusUser.class, String.valueOf(userId));
107         }
108         catch (ObjectNotFoundException onfe) {
109             throw new NoSuchCyrusUserException();
110         }
111         catch (Exception e) {
112             throw processException(e);
113         }
114         finally {
115             closeSession(session);
116         }
117     }
118 
119 }