| 1 | // Copyright 2004-2007 Jean-Francois Poilpret |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package net.sourceforge.hiveboard.dao; |
| 16 | |
| 17 | import java.sql.SQLException; |
| 18 | import java.util.List; |
| 19 | |
| 20 | import net.sourceforge.hiveboard.Account; |
| 21 | import net.sourceforge.hiveboard.StaleObjectException; |
| 22 | import net.sourceforge.hivetranse.transaction.ibatis.AbstractSqlMapClientDAO; |
| 23 | |
| 24 | import com.ibatis.sqlmap.client.SqlMapClient; |
| 25 | |
| 26 | public class AccountDAOImpl extends AbstractSqlMapClientDAO |
| 27 | { |
| 28 | public AccountDAOImpl(SqlMapClient client) |
| 29 | { |
| 30 | super(client); |
| 31 | } |
| 32 | |
| 33 | public List<Account> selectActiveAccounts() throws SQLException |
| 34 | { |
| 35 | return queryForList("SelectActiveAccounts", null); |
| 36 | } |
| 37 | |
| 38 | public List<Account> selectAllAccounts() throws SQLException |
| 39 | { |
| 40 | return queryForList("SelectAllAccounts", null); |
| 41 | } |
| 42 | |
| 43 | public int selectMaxDiscriminator() throws SQLException |
| 44 | { |
| 45 | Integer max = (Integer) _client.queryForObject("SelectMaxAccountDiscriminator", null); |
| 46 | if (max != null) |
| 47 | { |
| 48 | return max.intValue(); |
| 49 | } |
| 50 | else |
| 51 | { |
| 52 | return 0; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | public void insertAccount(Account account) throws SQLException |
| 57 | { |
| 58 | _client.insert("InsertAccount", account); |
| 59 | } |
| 60 | |
| 61 | public void updateAccount(Account account) throws SQLException |
| 62 | { |
| 63 | if (_client.update("UpdateAccount", account) == 1) |
| 64 | { |
| 65 | account.setVersion(account.getVersion() + 1); |
| 66 | } |
| 67 | else |
| 68 | { |
| 69 | throw new StaleObjectException( |
| 70 | "Account has been modified by another system [" + account + "]"); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | public void updatePassword(int id, String password) throws SQLException |
| 75 | { |
| 76 | Account account = new Account(); |
| 77 | account.setId(id); |
| 78 | account.setPassword(password); |
| 79 | _client.update("UpdateAccountPassword", account); |
| 80 | } |
| 81 | } |