01: package com.mockrunner.jdbc;
02:
03: import java.util.ArrayList;
04: import java.util.Collections;
05: import java.util.List;
06: import java.util.Map;
07: import java.util.TreeMap;
08:
09: import com.mockrunner.mock.jdbc.MockPreparedStatement;
10:
11: /**
12: * Concrete handler for {@link MockPreparedStatement}.
13: */
14: public class PreparedStatementResultSetHandler extends
15: AbstractParameterResultSetHandler {
16: private List preparedStatements;
17: private Map preparedStatementMap;
18:
19: public PreparedStatementResultSetHandler() {
20: preparedStatements = new ArrayList();
21: preparedStatementMap = new TreeMap();
22: }
23:
24: /**
25: * The <code>Connection</code> adds new statements with
26: * this method.
27: * @param statement the {@link MockPreparedStatement}
28: */
29: public void addPreparedStatement(MockPreparedStatement statement) {
30: statement.setPreparedStatementResultSetHandler(this );
31: List list = (List) preparedStatementMap.get(statement.getSQL());
32: if (null == list) {
33: list = new ArrayList();
34: preparedStatementMap.put(statement.getSQL(), list);
35: }
36: list.add(statement);
37: preparedStatements.add(statement);
38: }
39:
40: /**
41: * Returns a <code>List</code> of all prepared statements.
42: * @return the <code>List</code> of {@link MockPreparedStatement} objects
43: */
44: public List getPreparedStatements() {
45: return Collections.unmodifiableList(preparedStatements);
46: }
47:
48: /**
49: * Returns a <code>Map</code> of all prepared statements.
50: * The SQL strings map to the corresponding {@link MockPreparedStatement}
51: * object.
52: * @return the <code>Map</code> of {@link MockPreparedStatement} objects
53: */
54: public Map getPreparedStatementMap() {
55: return Collections.unmodifiableMap(preparedStatementMap);
56: }
57:
58: /**
59: * Clears all prepared statements
60: */
61: public void clearPreparedStatements() {
62: preparedStatements.clear();
63: preparedStatementMap.clear();
64: }
65: }
|