1 32 33 package com.mockobjects.eziba.sql; 34 import java.math.BigDecimal ; 35 import java.sql.SQLException ; 36 import java.util.Calendar ; 37 import java.util.Map ; 38 import java.util.Iterator ; 39 import java.util.SortedMap ; 40 import java.util.TreeMap ;public class CallableStatement 41 extends PreparedStatement 42 implements java.sql.CallableStatement 43 { 44 45 CallableStatement(Connection p_connection, String p_sql) 46 { 47 super(p_connection,p_sql); 48 } 49 50 private Object [] m_results; 51 52 private SortedMap m_outs = new TreeMap (); 53 54 public boolean execute() 55 throws SQLException 56 { 57 m_results = connection.getRegisteredCall(sql,getArguments()); 58 return m_results.length > 0; 59 } 60 61 public void registerOutParameter(int parameterIndex, int sqlType) 62 { 63 m_outs.put(new Integer (parameterIndex), new Integer (sqlType)); 64 setArg(parameterIndex,Connection.WILDCARD); 65 } 66 67 private Object getOutParameter(int i) 68 throws SQLException 69 { 70 if (m_results == null) 71 { 72 throw new SQLException ("Attempt to get OUT param before execute"); 73 } 74 if (m_results.length != m_outs.size()) 75 { 76 throw new SQLException ( "# of result values supplied (" 77 + m_results.length 78 + ") not equal to # of OUT parameters (" 79 + m_outs.size() 80 + ")") ; 81 } 82 if (! m_outs.containsKey(new Integer (i))) 83 { 84 throw new SQLException ("No OUT param registered at position " + i); 85 } 86 Iterator keys = m_outs.keySet().iterator(); 87 int k = 0; 88 while (keys.hasNext()) 89 { 90 int j = ((Integer ) keys.next()).intValue(); 91 if (j == i) 92 { 93 return m_results[k]; 94 } 95 k++; 96 } 97 throw new SQLException ("No OUT parameter registered at position " + i); 98 } 99 100 public int getInt(int parameterIndex) 101 throws SQLException 102 { 103 return ((Integer ) getOutParameter(parameterIndex)).intValue(); 104 } 105 106 public BigDecimal getBigDecimal(int parameterIndex) 107 throws SQLException 108 { 109 return (BigDecimal ) getOutParameter(parameterIndex); 110 } 111 112 public String getString(int parameterIndex) 113 throws SQLException 114 { 115 Object o = getOutParameter(parameterIndex); 116 if ( o == null ) 117 { 118 return null; 119 } 120 else 121 { 122 return o.toString(); 123 } 124 } 125 126 129 130 131 132 public java.sql.Array getArray(int i) 133 { 134 throw new NotImplementedException(); 135 } 136 137 140 public BigDecimal getBigDecimal(int parameterIndex, int scale) 141 { 142 throw new NotImplementedException(); 143 } 144 145 public java.sql.Blob getBlob(int i) 146 { 147 throw new NotImplementedException(); 148 } 149 150 public boolean getBoolean(int parameterIndex) 151 { 152 throw new NotImplementedException(); 153 } 154 155 public byte getByte(int parameterIndex) 156 { 157 throw new NotImplementedException(); 158 } 159 160 public byte[] getBytes(int parameterIndex) 161 { 162 throw new NotImplementedException(); 163 } 164 165 public java.sql.Clob getClob(int i) 166 { 167 throw new NotImplementedException(); 168 } 169 170 public java.sql.Date getDate(int parameterIndex) 171 { 172 throw new NotImplementedException(); 173 } 174 175 public java.sql.Date getDate(int parameterIndex, Calendar cal) 176 { 177 throw new NotImplementedException(); 178 } 179 180 public double getDouble(int parameterIndex) 181 { 182 throw new NotImplementedException(); 183 } 184 185 public float getFloat(int parameterIndex) 186 { 187 throw new NotImplementedException(); 188 } 189 190 public long getLong(int parameterIndex) 191 { 192 throw new NotImplementedException(); 193 } 194 195 public Object getObject(int parameterIndex) 196 { 197 throw new NotImplementedException(); 198 } 199 200 public Object getObject(int i, Map map) 201 { 202 throw new NotImplementedException(); 203 } 204 205 public java.sql.Ref getRef(int i) 206 { 207 throw new NotImplementedException(); 208 } 209 210 public short getShort(int parameterIndex) 211 { 212 throw new NotImplementedException(); 213 } 214 215 public java.sql.Time getTime(int parameterIndex) 216 { 217 throw new NotImplementedException(); 218 } 219 220 public java.sql.Time getTime(int parameterIndex, Calendar cal) 221 { 222 throw new NotImplementedException(); 223 } 224 225 public java.sql.Timestamp getTimestamp(int parameterIndex) 226 { 227 throw new NotImplementedException(); 228 } 229 230 public java.sql.Timestamp getTimestamp(int parameterIndex, Calendar cal) 231 { 232 throw new NotImplementedException(); 233 } 234 235 public void registerOutParameter(int parameterIndex, int sqlType, int scale) 236 { 237 throw new NotImplementedException(); 238 } 239 240 public void registerOutParameter(int paramIndex, int sqlType, String typeName) 241 { 242 throw new NotImplementedException(); 243 } 244 245 public boolean wasNull() 246 { 247 throw new NotImplementedException(); 248 } 249 } | Popular Tags |