001 package com.mockrunner.jdbc; 002 003 import java.util.ArrayList; 004 import java.util.List; 005 import java.util.Map; 006 007 /** 008 * Encapsulates the parameter sets for an executed 009 * {@link com.mockrunner.mock.jdbc.MockPreparedStatement} or 010 * {@link com.mockrunner.mock.jdbc.MockCallableStatement}. 011 * If the prepared statement is executed multiple times, this 012 * class contains multiple maps with the corresponding parameters. 013 * Each <code>execute</code> call creates a parameter set. 014 * A parameter set is a map, the index or the name of the 015 * parameter maps to the value. 016 */ 017 public class ParameterSets 018 { 019 private List parameterSets; 020 private String sql; 021 022 public ParameterSets(String sql) 023 { 024 parameterSets = new ArrayList(); 025 this.sql = sql; 026 } 027 028 /** 029 * Get the SQL string. 030 * @return the SQL string 031 */ 032 public String getSQLStatement() 033 { 034 return sql; 035 } 036 037 /** 038 * Adds a parameter set. 039 * @param parameterSet the parameter set. 040 */ 041 public void addParameterSet(Map parameterSet) 042 { 043 parameterSets.add(parameterSet); 044 } 045 046 /** 047 * Get the current number of parameter sets. 048 * @return the number of parameter sets 049 */ 050 public int getNumberParameterSets() 051 { 052 return parameterSets.size(); 053 } 054 055 /** 056 * Gets a parameter set for a specified index. 057 * @param indexOfParameterSet the index 058 * @return the parameter set 059 */ 060 public Map getParameterSet(int indexOfParameterSet) 061 { 062 if(indexOfParameterSet >= getNumberParameterSets()) return null; 063 return (Map)parameterSets.get(indexOfParameterSet); 064 } 065 }