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