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.MockPreparedStatement; 010 011 /** 012 * Concrete handler for {@link MockPreparedStatement}. 013 */ 014 public class PreparedStatementResultSetHandler extends AbstractParameterResultSetHandler 015 { 016 private List preparedStatements; 017 private Map preparedStatementMap; 018 019 public PreparedStatementResultSetHandler() 020 { 021 preparedStatements = new ArrayList(); 022 preparedStatementMap = new TreeMap(); 023 } 024 025 /** 026 * The <code>Connection</code> adds new statements with 027 * this method. 028 * @param statement the {@link MockPreparedStatement} 029 */ 030 public void addPreparedStatement(MockPreparedStatement statement) 031 { 032 statement.setPreparedStatementResultSetHandler(this); 033 List list = (List)preparedStatementMap.get(statement.getSQL()); 034 if(null == list) 035 { 036 list = new ArrayList(); 037 preparedStatementMap.put(statement.getSQL(), list); 038 } 039 list.add(statement); 040 preparedStatements.add(statement); 041 } 042 043 /** 044 * Returns a <code>List</code> of all prepared statements. 045 * @return the <code>List</code> of {@link MockPreparedStatement} objects 046 */ 047 public List getPreparedStatements() 048 { 049 return Collections.unmodifiableList(preparedStatements); 050 } 051 052 /** 053 * Returns a <code>Map</code> of all prepared statements. 054 * The SQL strings map to the corresponding {@link MockPreparedStatement} 055 * object. 056 * @return the <code>Map</code> of {@link MockPreparedStatement} objects 057 */ 058 public Map getPreparedStatementMap() 059 { 060 return Collections.unmodifiableMap(preparedStatementMap); 061 } 062 063 /** 064 * Clears all prepared statements 065 */ 066 public void clearPreparedStatements() 067 { 068 preparedStatements.clear(); 069 preparedStatementMap.clear(); 070 } 071 }