1 16 17 package org.springframework.jdbc.core.namedparam; 18 19 import java.util.Collections ; 20 import java.util.HashMap ; 21 import java.util.Map ; 22 23 import org.springframework.util.Assert; 24 25 43 public class MapSqlParameterSource extends AbstractSqlParameterSource { 44 45 private final Map values = new HashMap (); 46 47 48 53 public MapSqlParameterSource() { 54 } 55 56 63 public MapSqlParameterSource(String paramName, Object value) { 64 addValue(paramName, value); 65 } 66 67 71 public MapSqlParameterSource(Map values) { 72 addValues(values); 73 } 74 75 76 83 public MapSqlParameterSource addValue(String paramName, Object value) { 84 Assert.notNull(paramName, "Parameter name must not be null"); 85 this.values.put(paramName, value); 86 return this; 87 } 88 89 97 public MapSqlParameterSource addValue(String paramName, Object value, int sqlType) { 98 Assert.notNull(paramName, "Parameter name must not be null"); 99 this.values.put(paramName, value); 100 registerSqlType(paramName, sqlType); 101 return this; 102 } 103 104 110 public MapSqlParameterSource addValues(Map values) { 111 if (values != null) { 112 this.values.putAll(values); 113 } 114 return this; 115 } 116 117 120 public Map getValues() { 121 return Collections.unmodifiableMap(this.values); 122 } 123 124 125 public boolean hasValue(String paramName) { 126 return this.values.containsKey(paramName); 127 } 128 129 public Object getValue(String paramName) { 130 if (!hasValue(paramName)) { 131 throw new IllegalArgumentException ("No value registered for key '" + paramName + "'"); 132 } 133 return this.values.get(paramName); 134 } 135 136 } 137 | Popular Tags |