View Javadoc

1   /*
2    * Copyright 2002-2004 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */ 
16  
17  package net.sf.fridaymvc.sample.hibernate.dao.impl;
18  
19  import java.io.Serializable;
20  
21  import net.sf.fridaymvc.sample.hibernate.HibernateRole;
22  import net.sf.fridaymvc.sample.hibernate.dao.RoleDao;
23  import net.sf.hibernate.HibernateException;
24  import net.sf.hibernate.Session;
25  
26  import org.springframework.orm.hibernate.HibernateCallback;
27  import org.springframework.orm.hibernate.support.HibernateDaoSupport;
28  
29  /***
30   * @author <a href="mailto:arto.pastinen@ofw.fi">Arto Pastinen</a>
31   * @version $Id: RoleDaoImpl.java,v 1.1 2004/11/23 20:36:57 artsi Exp $
32   * 
33   * @@org.springframework.transaction.interceptor.DefaultTransactionAttribute()
34   */
35  
36  public class RoleDaoImpl extends HibernateDaoSupport implements RoleDao {
37  
38      /***
39       * @param hr
40       * @return
41       */
42      public HibernateRole saveOrUpdateCopy(HibernateRole hr) {
43          return (HibernateRole) getHibernateTemplate().saveOrUpdateCopy(hr);
44      }
45  
46      /***
47       * @param hr
48       */
49      public void update(HibernateRole hr) {
50          getHibernateTemplate().update(hr);
51      }
52  
53      public Serializable save(HibernateRole hr) {
54          return getHibernateTemplate().save(hr);        
55      }
56  
57      /***
58       * @param string
59       * @return
60       */
61      public HibernateRole findRoleByName(final String name) {
62          return (HibernateRole) getHibernateTemplate().execute(new HibernateCallback() {
63              /* (non-Javadoc)
64               * @see org.springframework.orm.hibernate.HibernateCallback#doInHibernate(net.sf.hibernate.Session)
65               */
66              public Object doInHibernate(Session session) throws HibernateException {
67                  return session.createQuery("from HibernateRole as hr where hr.name = :name")
68                  		.setString("name", name)
69                  		.uniqueResult();
70              }
71          });
72      }
73   }