1 32 33 package com.mockobjects.eziba.sql; 34 35 import java.io.ByteArrayOutputStream ; 36 import java.io.IOException ; 37 import java.io.InputStream ; 38 import java.io.Reader ; 39 import java.math.BigDecimal ; 40 import java.sql.SQLException ; 41 import java.util.Calendar ; 42 import java.util.Vector ; 43 44 public class PreparedStatement 45 extends Statement 46 implements java.sql.PreparedStatement { 47 48 protected final Vector m_args = new Vector (); 49 50 protected void setArg(int p_pos, Object p_arg) { 51 p_pos--; 52 if(m_args.size() <= p_pos) { 53 int size = m_args.size(); 54 m_args.setSize(p_pos + 1); 55 for(int i = size; i < m_args.size(); ++i) { 56 m_args.set(i, Connection.WILDCARD); 57 } 58 } 59 m_args.set(p_pos, p_arg); 60 } 61 62 protected final Object [] getArguments() { 63 m_args.trimToSize(); 64 return m_args.toArray(); 65 } 66 67 PreparedStatement(Connection p_connection, String p_sql) { 68 super(p_connection, p_sql); 69 } 70 71 public void addBatch() { 72 throw new NotImplementedException(); 73 } 74 75 public void clearParameters() { 76 throw new NotImplementedException(); 77 } 78 79 public boolean execute() 80 throws SQLException { 81 m_returnValue = -1; 82 m_resultSet = null; 83 try { 84 m_returnValue = executeUpdate(); 85 return false; 86 } catch(SQLException e) { 87 m_resultSet = executeQuery(); 88 return true; 89 } 90 } 91 92 public java.sql.ResultSet getResultSet() { 93 return m_resultSet; 94 } 95 96 public int getUpdateCount() { 97 return m_returnValue; 98 } 99 100 public java.sql.ResultSet executeQuery() 101 throws SQLException { 102 return connection.getRegisteredResult(sql, getArguments()); 103 } 104 105 public int executeUpdate() 106 throws SQLException { 107 return connection.getRegisteredUpdate(sql, getArguments()); 108 } 109 110 public void setInt(int parameterIndex, int x) { 111 setArg(parameterIndex, new Integer (x)); 112 } 113 114 public void setString(int parameterIndex, String x) { 115 setArg(parameterIndex, x); 116 } 117 118 public void setBigDecimal(int parameterIndex, BigDecimal x) { 119 setArg(parameterIndex, x); 120 } 121 122 public void setBinaryStream(int parameterIndex, InputStream x, int length) 123 throws SQLException { 124 try { 125 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 126 int c = 0; 127 while(((c = x.read()) != -1)) { 128 baos.write(c); 129 } 130 setArg(parameterIndex, baos.toByteArray()); 131 } catch(IOException e) { 132 throw new SQLException ("IOException reading stream"); 133 } 134 } 135 136 public void setNull(int parameterIndex, int sqlType) { 137 setArg(parameterIndex, null); 138 } 139 140 private int m_returnValue; 141 private java.sql.ResultSet m_resultSet; 142 143 146 147 148 public java.sql.ResultSetMetaData getMetaData() { 149 throw new NotImplementedException(); 150 } 151 152 public void setArray(int i, java.sql.Array x) { 153 throw new NotImplementedException(); 154 } 155 156 public void setAsciiStream(int parameterIndex, InputStream x, int length) { 157 throw new NotImplementedException(); 158 } 159 160 public void setBlob(int i, java.sql.Blob x) { 161 throw new NotImplementedException(); 162 } 163 164 public void setBoolean(int parameterIndex, boolean x) { 165 throw new NotImplementedException(); 166 } 167 168 public void setByte(int parameterIndex, byte x) { 169 throw new NotImplementedException(); 170 } 171 172 public void setBytes(int parameterIndex, byte[] x) { 173 throw new NotImplementedException(); 174 } 175 176 public void setCharacterStream(int parameterIndex, Reader reader, int length) { 177 throw new NotImplementedException(); 178 } 179 180 public void setClob(int i, java.sql.Clob x) { 181 throw new NotImplementedException(); 182 } 183 184 public void setDate(int parameterIndex, java.sql.Date x) { 185 throw new NotImplementedException(); 186 } 187 188 public void setDate(int parameterIndex, java.sql.Date x, Calendar cal) { 189 throw new NotImplementedException(); 190 } 191 192 public void setDouble(int parameterIndex, double x) { 193 throw new NotImplementedException(); 194 } 195 196 public void setFloat(int parameterIndex, float x) { 197 throw new NotImplementedException(); 198 } 199 200 public void setLong(int parameterIndex, long x) { 201 throw new NotImplementedException(); 202 } 203 204 public void setNull(int paramIndex, int sqlType, String typeName) { 205 throw new NotImplementedException(); 206 } 207 208 public void setObject(int parameterIndex, Object x) { 209 throw new NotImplementedException(); 210 } 211 212 public void setObject(int parameterIndex, Object x, int targetSqlType) { 213 throw new NotImplementedException(); 214 } 215 216 public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) { 217 throw new NotImplementedException(); 218 } 219 220 public void setRef(int i, java.sql.Ref x) { 221 throw new NotImplementedException(); 222 } 223 224 public void setShort(int parameterIndex, short x) { 225 throw new NotImplementedException(); 226 } 227 228 public void setTime(int parameterIndex, java.sql.Time x) { 229 throw new NotImplementedException(); 230 } 231 232 public void setTime(int parameterIndex, java.sql.Time x, Calendar cal) { 233 throw new NotImplementedException(); 234 } 235 236 public void setTimestamp(int parameterIndex, java.sql.Timestamp x) { 237 throw new NotImplementedException(); 238 } 239 240 public void setTimestamp(int parameterIndex, java.sql.Timestamp x, Calendar cal) { 241 throw new NotImplementedException(); 242 } 243 244 247 public void setUnicodeStream(int parameterIndex, InputStream x, int length) { 248 throw new NotImplementedException(); 249 } 250 } | Popular Tags |