1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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  public class CyrusUserPersistence extends BasePersistenceImpl {
38  
39      public void remove(long userId)
40          throws NoSuchCyrusUserException, SystemException {
41  
42          Session session = null;
43  
44          try {
45              session = openSession();
46  
47              CyrusUser user = (CyrusUser)session.load(
48                  CyrusUser.class, String.valueOf(userId));
49  
50              session.delete(user);
51  
52              session.flush();
53          }
54          catch (ObjectNotFoundException onfe) {
55              throw new NoSuchCyrusUserException();
56          }
57          catch (Exception e) {
58              throw processException(e);
59          }
60          finally {
61              closeSession(session);
62          }
63      }
64  
65      public void update(CyrusUser user) throws SystemException {
66          Session session = null;
67  
68          try {
69              session = openSession();
70  
71              try {
72                  CyrusUser userModel = (CyrusUser)session.load(
73                      CyrusUser.class, String.valueOf(user.getUserId()));
74  
75                  userModel.setPassword(user.getPassword());
76  
77                  session.flush();
78              }
79              catch (ObjectNotFoundException onfe) {
80                  CyrusUser userModel = new CyrusUser(
81                      user.getUserId(), user.getPassword());
82  
83                  session.save(userModel);
84  
85                  session.flush();
86              }
87          }
88          catch (Exception e) {
89              throw processException(e);
90          }
91          finally {
92              closeSession(session);
93          }
94      }
95  
96      public CyrusUser findByPrimaryKey(long userId)
97          throws NoSuchCyrusUserException, SystemException {
98  
99          Session session = null;
100 
101         try {
102             session = openSession();
103 
104             return (CyrusUser)session.load(
105                 CyrusUser.class, String.valueOf(userId));
106         }
107         catch (ObjectNotFoundException onfe) {
108             throw new NoSuchCyrusUserException();
109         }
110         catch (Exception e) {
111             throw processException(e);
112         }
113         finally {
114             closeSession(session);
115         }
116     }
117 
118 }