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 org.springframework.dao.DataAccessException;
21 import org.springframework.dao.PermissionDeniedDataAccessException;
22 import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
23
24 import net.sf.mud4j.account.Account;
25 import net.sf.mud4j.dao.AccountDao;
26
27 /**
28 * Account dao implementation for hibernate.
29 *
30 * @author Matthew Purland
31 */
32 public class AccountDaoHibernate extends HibernateDaoSupport implements AccountDao {
33
34 /**
35 * {@inheritDoc}
36 */
37 public List getAccounts() throws DataAccessException {
38 return getHibernateTemplate().find("from Account");
39 }
40
41 /**
42 * {@inheritDoc}
43 */
44 public Account loadAccount(String username) throws DataAccessException {
45 Object account = getHibernateTemplate().load(Account.class, username);
46
47 return (Account) account;
48 }
49
50 /**
51 * {@inheritDoc}
52 */
53 public Account loadAccount(String username, String password) throws DataAccessException, PermissionDeniedDataAccessException {
54 Account account = (Account) getHibernateTemplate().load(Account.class, username);
55
56 if (!account.getPassword().equals(password)) {
57 throw new RuntimeException("Password is incorrect");
58
59 }
60
61 return account;
62 }
63
64
65 }