001 package com.mockrunner.jdbc;
002
003 import java.util.ArrayList;
004 import java.util.Collections;
005 import java.util.List;
006 import java.util.Map;
007 import java.util.TreeMap;
008
009 import com.mockrunner.mock.jdbc.MockCallableStatement;
010
011 /**
012 * Concrete handler for {@link MockCallableStatement}.
013 */
014 public class CallableStatementResultSetHandler extends AbstractOutParameterResultSetHandler
015 {
016 private List callableStatements;
017 private Map callbaleStatementMap;
018
019 public CallableStatementResultSetHandler()
020 {
021 callableStatements = new ArrayList();
022 callbaleStatementMap = new TreeMap();
023 }
024
025 /**
026 * The <code>Connection</code> adds new statements with
027 * this method.
028 * @param statement the {@link MockCallableStatement}
029 */
030 public void addCallableStatement(MockCallableStatement statement)
031 {
032 statement.setCallableStatementResultSetHandler(this);
033 List list = (List)callbaleStatementMap.get(statement.getSQL());
034 if(null == list)
035 {
036 list = new ArrayList();
037 callbaleStatementMap.put(statement.getSQL(), list);
038 }
039 list.add(statement);
040 callableStatements.add(statement);
041 }
042
043 /**
044 * Returns a <code>List</code> of all callable statements.
045 * @return the <code>List</code> of {@link MockCallableStatement} objects
046 */
047 public List getCallableStatements()
048 {
049 return Collections.unmodifiableList(callableStatements);
050 }
051
052 /**
053 * Returns a <code>Map</code> of all callable statements.
054 * The SQL strings map to the corresponding {@link MockCallableStatement}
055 * object.
056 * @return the <code>Map</code> of {@link MockCallableStatement} objects
057 */
058 public Map getCallableStatementMap()
059 {
060 return Collections.unmodifiableMap(callbaleStatementMap);
061 }
062
063 /**
064 * Clears all callable statements
065 */
066 public void clearCallableStatements()
067 {
068 callableStatements.clear();
069 callbaleStatementMap.clear();
070 }
071 }