View Javadoc

1   /**
2    * Copyright 2006 Matthew Purland (m.purland@gmail.com)
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  package net.sf.mud4j.dao.hibernate;
17  
18  import java.util.List;
19  
20  import net.sf.mud4j.dao.CharacterDao;
21  
22  import org.springframework.dao.DataAccessException;
23  import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
24  
25  /**
26   * Character dao for hibernate support.
27   * 
28   * @author Matthew Purland
29   */
30  public class CharacterDaoHibernate extends HibernateDaoSupport implements CharacterDao {
31  
32      /**
33       * {@inheritDoc}
34       */
35      public Character getCharacter(String characterId) throws DataAccessException {
36          return (Character) getHibernateTemplate().get(Character.class, characterId);
37      }
38  
39      /**
40       * {@inheritDoc}
41       */
42      public List getCharacters() throws DataAccessException {
43          return getHibernateTemplate().find("from Character");
44      }
45  
46      /**
47       * {@inheritDoc}
48       */
49      public void removeCharacter(String characterId) throws DataAccessException {
50          Object character = getHibernateTemplate().load(Character.class, characterId);
51          getHibernateTemplate().delete(character);
52      }
53  
54      /**
55       * {@inheritDoc}
56       */
57      public void saveCharacter(Character character) throws DataAccessException {
58          getHibernateTemplate().save(character);
59      }
60  }