EMMA Coverage Report (generated Wed Feb 13 07:49:24 ICT 2008)
[all classes][net.sourceforge.hiveboard.dao]

COVERAGE SUMMARY FOR SOURCE FILE [BoardDAOImpl.java]

nameclass, %method, %block, %line, %
BoardDAOImpl.java100% (1/1)100% (19/19)100% (394/394)100% (92/92)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BoardDAOImpl100% (1/1)100% (19/19)100% (394/394)100% (92/92)
BoardDAOImpl (SqlMapClient): void 100% (1/1)100% (4/4)100% (2/2)
deleteParticipant (int): void 100% (1/1)100% (8/8)100% (2/2)
deleteParticipant (int, int): void 100% (1/1)100% (10/10)100% (2/2)
deleteSnapshots (int): void 100% (1/1)100% (15/15)100% (3/3)
getParticipantDTO (int, int): ParticipantDTO 100% (1/1)100% (12/12)100% (4/4)
insertBoard (Board): void 100% (1/1)100% (32/32)100% (7/7)
insertComment (int, int, String, Date): void 100% (1/1)100% (23/23)100% (7/7)
insertParticipant (int, int): void 100% (1/1)100% (10/10)100% (2/2)
insertSnapshot (int, boolean, byte []): int 100% (1/1)100% (33/33)100% (8/8)
selectActiveBoards (): Map 100% (1/1)100% (11/11)100% (3/3)
selectAllBoards (): Map 100% (1/1)100% (11/11)100% (3/3)
selectComments (int, Date, Date): List 100% (1/1)100% (18/18)100% (5/5)
selectCurrentSnapshot (int): int 100% (1/1)100% (15/15)100% (4/4)
selectMaxDiscriminator (): int 100% (1/1)100% (14/14)100% (4/4)
selectSnapshot (int): SnapshotDTO 100% (1/1)100% (8/8)100% (1/1)
selectSnapshots (int): List 100% (1/1)100% (6/6)100% (1/1)
setBoardsParticipants (Map): void 100% (1/1)100% (33/33)100% (7/7)
updateBoard (Board): void 100% (1/1)100% (103/103)100% (20/20)
updateSnapshot (int, byte []): void 100% (1/1)100% (28/28)100% (7/7)

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 
15package net.sourceforge.hiveboard.dao;
16 
17import java.sql.SQLException;
18import java.util.Date;
19import java.util.HashSet;
20import java.util.List;
21import java.util.Map;
22import java.util.Set;
23 
24import net.sourceforge.hiveboard.Board;
25import net.sourceforge.hiveboard.StaleObjectException;
26import net.sourceforge.hivetranse.transaction.ibatis.AbstractSqlMapClientDAO;
27 
28import com.ibatis.sqlmap.client.SqlMapClient;
29 
30public class BoardDAOImpl extends AbstractSqlMapClientDAO
31{
32        public BoardDAOImpl(SqlMapClient client)
33        {
34                super(client);
35        }
36 
37        public Map<Integer, Board>        selectActiveBoards() throws SQLException
38        {
39                Map<Integer, Board> boards = queryForMap("SelectActiveBoards", null, "id");
40                setBoardsParticipants(boards);
41                return boards;
42        }
43        
44        public Map<Integer, Board>        selectAllBoards() throws SQLException
45        {
46                Map<Integer, Board> boards = queryForMap("SelectAllBoards", null, "id");
47                setBoardsParticipants(boards);
48                return boards;
49        }
50 
51        public int                selectMaxDiscriminator() throws SQLException
52        {
53                Integer max = (Integer) _client.queryForObject("SelectMaxBoardDiscriminator", null);
54                if (max != null)
55                {
56                        return max.intValue();
57                }
58                else
59                {
60                        return 0;
61                }
62        }
63        
64        private void        setBoardsParticipants(Map<Integer, Board> boards) throws SQLException
65        {
66                List<ParticipantDTO> participants = queryForList("SelectAllParticipants", null);
67                for (ParticipantDTO dto: participants)
68                {
69                        Board board = boards.get(dto.getBoard());
70                        if (board != null)
71                        {
72                                board.getParticipants().add(dto.getAccount());
73                        }
74                }
75        }
76        
77        public void                insertBoard(Board board) throws SQLException
78        {
79                _client.insert("InsertBoard", board);
80                // Insert all participants (in batch mode)
81                _client.startBatch();
82                for (int id: board.getParticipants())
83                {
84                        insertParticipant(board.getId(), id);
85                }
86                _client.executeBatch();
87        }
88 
89        public void                updateBoard(Board board) throws SQLException
90        {
91                if (_client.update("UpdateBoard", board) == 1)
92                {
93                        board.setVersion(board.getVersion() + 1);
94                }
95                else
96                {
97                        throw new StaleObjectException(
98                                        "Board has been modified by another system [" + board + "]");
99                }
100 
101                // Use batch mode
102                _client.startBatch();
103 
104                // Update participants
105                // - select all participants for board in DB
106                List<Integer> list = queryForList("SelectParticipants", board.getId());
107                Set<Integer> dbParticipants = new HashSet<Integer>(list);
108                Set<Integer> boardParticipants = board.getParticipants();
109                // - calculate difference Memory \ DB => insert
110                Set<Integer> insertedParticipants = new HashSet<Integer>(boardParticipants);
111                insertedParticipants.removeAll(dbParticipants);
112                for (int participant: insertedParticipants)
113                {
114                        insertParticipant(board.getId(), participant);
115                }
116                // - calculate DB \ Memory => delete
117                Set<Integer> deletedParticipants = new HashSet<Integer>(dbParticipants);
118                deletedParticipants.removeAll(boardParticipants);
119                for (int participant: deletedParticipants)
120                {
121                        deleteParticipant(board.getId(), participant);
122                }
123                _client.executeBatch();
124        }
125 
126        public void                insertParticipant(int board, int account) throws SQLException
127        {
128                _client.insert("InsertParticipant", getParticipantDTO(board, account));
129        }
130        
131        public void                deleteParticipant(int board, int account) throws SQLException
132        {
133                _client.delete("DeleteParticipant", getParticipantDTO(board, account));
134        }
135        
136        public void                deleteParticipant(int account) throws SQLException
137        {
138                _client.delete("DeleteAccountParticipant", account);
139        }
140        
141        private ParticipantDTO        getParticipantDTO(int board, int account) 
142                throws SQLException
143        {
144                ParticipantDTO dto = new ParticipantDTO();
145                dto.setAccount(account);
146                dto.setBoard(board);
147                return dto;
148        }
149 
150        public void                insertComment(int board, int author, String comment, Date date)
151                throws SQLException
152        {
153                CommentDTO dto = new CommentDTO();
154                dto.setBoard(board);
155                dto.setAuthor(author);
156                dto.setComment(comment);
157                dto.setDate(date);
158                _client.insert("InsertComment", dto);
159        }
160 
161        public List<CommentDTO>        selectComments(int board, Date after, Date until)
162                throws SQLException
163        {
164                CommentSearchCriteria criteria = new CommentSearchCriteria();
165                criteria.setBoard(board);
166                criteria.setAfter(after);
167                criteria.setUntil(until);
168                return queryForList("SelectComments", criteria);
169        }
170 
171        public int                selectCurrentSnapshot(int board) throws SQLException
172        {
173                Integer id = (Integer) _client.queryForObject("SelectCurrentSnapshot",        board);
174                if (id == null)
175                {
176                        return -1;
177                }
178                else
179                {
180                        return id.intValue();
181                }
182        }
183 
184        public int                insertSnapshot(int board, boolean current, byte[] content)
185                throws SQLException
186        {
187                SnapshotDTO dto = new SnapshotDTO();
188                dto.setBoard(board);
189                dto.setCurrent(current);
190                dto.setDate(new Date());
191                dto.setContent(content);
192                _client.insert("InsertSnapshot", dto);
193                _client.insert("InsertSnapshotContent", dto);
194                return dto.getId();
195        }
196        
197        public void                updateSnapshot(int id, byte[] content) throws SQLException
198        {
199                SnapshotDTO dto = new SnapshotDTO();
200                dto.setId(id);
201                dto.setDate(new Date());
202                dto.setContent(content);
203                _client.update("UpdateSnapshot", dto);
204                _client.update("UpdateSnapshotContent", dto);
205        }
206        
207        public SnapshotDTO        selectSnapshot(int idSnapshot) throws SQLException
208        {
209                return (SnapshotDTO) _client.queryForObject("SelectSnapshot", idSnapshot);
210        }
211        
212 
213        public void                deleteSnapshots(int board) throws SQLException
214        {
215                _client.delete("DeleteSnapshotsContents", board);
216                _client.delete("DeleteSnapshots", board);
217        }
218        
219        public List<SnapshotDTO>                selectSnapshots(int board) throws SQLException
220        {
221                return queryForList("SelectSnapshots", board);
222        }
223}

[all classes][net.sourceforge.hiveboard.dao]
EMMA 2.0.5312 (C) Vladimir Roubtsov