1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.mail.service.persistence;
21  
22  import com.liferay.mail.NoSuchCyrusUserException;
23  import com.liferay.mail.model.CyrusUser;
24  import com.liferay.portal.SystemException;
25  import com.liferay.portal.kernel.dao.orm.ObjectNotFoundException;
26  import com.liferay.portal.kernel.dao.orm.Session;
27  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
28  
29  /**
30   * <a href="CyrusUserPersistence.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Brian Wing Shun Chan
33   *
34   */
35  public class CyrusUserPersistence extends BasePersistenceImpl {
36  
37      public void remove(long userId)
38          throws NoSuchCyrusUserException, SystemException {
39  
40          Session session = null;
41  
42          try {
43              session = openSession();
44  
45              CyrusUser user = (CyrusUser)session.load(
46                  CyrusUser.class, String.valueOf(userId));
47  
48              session.delete(user);
49  
50              session.flush();
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 update(CyrusUser user) throws SystemException {
64          Session session = null;
65  
66          try {
67              session = openSession();
68  
69              try {
70                  CyrusUser userModel = (CyrusUser)session.load(
71                      CyrusUser.class, String.valueOf(user.getUserId()));
72  
73                  userModel.setPassword(user.getPassword());
74  
75                  session.flush();
76              }
77              catch (ObjectNotFoundException onfe) {
78                  CyrusUser userModel = new CyrusUser(
79                      user.getUserId(), user.getPassword());
80  
81                  session.save(userModel);
82  
83                  session.flush();
84              }
85          }
86          catch (Exception e) {
87              throw processException(e);
88          }
89          finally {
90              closeSession(session);
91          }
92      }
93  
94      public CyrusUser findByPrimaryKey(long userId)
95          throws NoSuchCyrusUserException, SystemException {
96  
97          Session session = null;
98  
99          try {
100             session = openSession();
101 
102             return (CyrusUser)session.load(
103                 CyrusUser.class, String.valueOf(userId));
104         }
105         catch (ObjectNotFoundException onfe) {
106             throw new NoSuchCyrusUserException();
107         }
108         catch (Exception e) {
109             throw processException(e);
110         }
111         finally {
112             closeSession(session);
113         }
114     }
115 
116 }