1 package com.daffodilwoods.rmi; 2 3 import java.rmi.*; 4 import com.daffodilwoods.database.resource.DException; 5 import com.daffodilwoods.daffodildb.server.datadictionarysystem._ColumnCharacteristics; 6 import java.util.HashMap ; 7 import com.daffodilwoods.daffodildb.server.serversystem._PreparedStatement; 8 import com.daffodilwoods.rmi.interfaces.*; 9 import com.daffodilwoods.rmi.server.*; 10 11 import com.daffodilwoods.database.general._ParameterMetaData; 12 import com.daffodilwoods.daffodildb.server.sql99.dql.resultsetmetadata._RowReader; 13 import java.sql.Blob ; 14 import java.sql.Clob ; 15 import java.rmi.server.UnicastRemoteObject ; 16 import java.sql.Time ; 17 import java.sql.Date ; 18 import java.sql.Timestamp ; 19 20 public class RmiPreparedStatement implements _PreparedStatement { 21 22 _RmiPreparedStatement preparedStatement; 23 _ColumnCharacteristics cc; 24 _RowReader rowReader; 25 int queryType = Integer.MIN_VALUE; 26 _RmiSelectIterator selectIterator; 27 28 public RmiPreparedStatement(_RmiPreparedStatement preparedStatement) { 29 this.preparedStatement = preparedStatement; 30 } 31 32 private void initCCandRowReader(_RmiSelectIterator object) throws DException { 33 if (cc == null || rowReader == null) { 34 try { 35 cc = object.getColumnCharacteristics(); 36 rowReader = object.getRowReader(); 37 selectIterator = object; 38 } 39 catch (RemoteException ex) { 40 } 41 } 42 } 43 44 public Object execute(Object [] parameters) throws DException { 45 try { 46 Parameters param = getParametersObjForArrayType(parameters); 47 Object o = getRequiredObjectOfExecute(preparedStatement.execute(param, 0)); 48 unExportBlobCLob(param); 49 return o; 50 } 51 catch (RemoteException ex) { 52 throw new RuntimeException (ex.getMessage()); 53 } 54 } 55 56 private void unExportBlobCLob(Parameters param)throws RemoteException{ 57 if(param.isBlobClobPresent()){ 58 int type = param.getType(); 59 if(type == param.OBJECT_ARRAY){ 60 Object [] oo = (Object [])param.getObjects(); 61 for (int i = 0; i < oo.length; i++) { 62 if(oo[i] instanceof Remote){ 63 boolean b = UnicastRemoteObject.unexportObject( (Remote) oo[i], true); 64 } 65 } 66 } 67 else if(type == param.HASHMAP){ 68 HashMap parm1 = (HashMap )param.getObjects(); 69 Object [] keys = parm1.keySet().toArray(); 70 for (int i = 0; i < keys.length; i++) { 71 Object value = parm1.get(keys[i]); 72 if (value instanceof Remote) { 73 boolean b = UnicastRemoteObject.unexportObject((Remote)value, true); 74 } 75 } 76 } 77 } 78 } 79 80 public int getParameterCount() { 81 try { 82 return preparedStatement.getParameterCount(); 83 } 84 catch (RemoteException ex) { 85 throw new RuntimeException (ex.getMessage()); 86 } 87 } 88 89 public _ColumnCharacteristics getColumnCharacteristics() throws DException { 90 try { 91 if (cc == null) { 92 cc = preparedStatement.getColumnCharacteristics(); 93 } 94 return cc; 95 } 96 catch (RemoteException ex) { 97 throw new RuntimeException (ex.getMessage()); 98 } 99 } 100 101 public Object execute(Object [] parameters, int QueryTimeOut) throws 102 DException { 103 try { 104 Parameters param = getParametersObjForArrayType(parameters); 105 Object o = getRequiredObjectOfExecute(preparedStatement.execute(param, 106 QueryTimeOut)); 107 unExportBlobCLob(param); 108 return o; 109 } 110 catch (RemoteException ex) { 111 throw new RuntimeException (ex.getMessage()); 112 } 113 114 } 115 116 public Object executeUpdate(Object [] parameters, int QueryTimeOut) throws 117 DException { 118 try { 119 Parameters param = getParametersObjForArrayType(parameters); 120 Object o = preparedStatement.execute(param, QueryTimeOut); 121 unExportBlobCLob(param); 122 return o; 123 } 124 catch (RemoteException ex) { 125 throw new RuntimeException (ex.getMessage()); 126 } 127 } 128 129 public Object executeQuery(Object [] parameters, int QueryTimeOut) throws 130 DException { 131 try { 132 Parameters param = getParametersObjForArrayType(parameters); 133 Object o = getRequiredObjectOfExecute(preparedStatement.execute(param, 134 QueryTimeOut)); 135 unExportBlobCLob(param); 136 return o; 137 } 138 catch (RemoteException ex) { 139 throw new RuntimeException (ex.getMessage()); 140 } 141 142 } 143 144 public Object execute(HashMap parameters, int QueryTimeOut) throws DException { 145 try { 146 Parameters param = getParametersObjForHashMap(parameters); 147 return getRequiredObjectOfExecute(preparedStatement.execute(param, 148 QueryTimeOut)); 149 } 150 catch (RemoteException ex) { 151 throw new RuntimeException (ex.getMessage()); 152 } 153 } 154 155 private Object getRequiredObjectOfExecute(Object object) throws DException, 156 RemoteException { 157 if (getQueryType() == queryexpression) { 158 initCCandRowReader( (_RmiSelectIterator) object); 159 return new RmiSelectIterator(selectIterator, cc, rowReader); 160 } 161 return object; 162 163 } 164 165 166 public Object executeForFresh(Object [] parm1) throws com.daffodilwoods. 167 database.resource.DException { 168 try { 169 Parameters param = getParametersObjForArrayType(parm1); 170 Object o = getRequiredObjectOfExecute(preparedStatement.executeForFresh(param)); 171 unExportBlobCLob(param); 172 return o; 173 } 174 catch (RemoteException ex) { 175 throw new RuntimeException (ex.getMessage()); 176 } 177 } 178 179 public _ParameterMetaData getParameterMetaData() throws DException { 180 try { 181 return preparedStatement.getParameterMetaData(); 182 } 183 catch (RemoteException ex) { 184 throw new RuntimeException (ex.getMessage()); 185 } 186 187 } 188 189 public void setQueryType(int parm1) throws DException { 190 throw new UnsupportedOperationException (" not supported "); 191 } 192 193 public int getQueryType() { 194 try { 195 if (queryType == Integer.MIN_VALUE) { 196 queryType = preparedStatement.getQueryType(); 197 } 198 return queryType; 199 } 200 catch (RemoteException ex) { 201 throw new RuntimeException (ex.getMessage()); 202 } 203 } 204 205 RmiConnection rmiConnection; 206 String query; 207 public void setEnv(RmiConnection rmiConnection0, String query0) { 208 this.rmiConnection = rmiConnection0; 209 this.query = query0; 210 } 211 212 public void close() { 213 try { 214 preparedStatement.close(); 215 } 216 catch (RemoteException ex) { 217 throw new RuntimeException (ex.getMessage()); 218 } 219 } 220 221 private Parameters getParametersObjForArrayType(Object [] parm1) throws 222 RemoteException { 223 Parameters param = new Parameters(); 224 if (parm1 != null) { 225 for (int i = 0; i < parm1.length; i++) { 226 if (parm1[i] instanceof Clob ) { 227 parm1[i] = new RmiClobServerSide( (Clob ) parm1[i]); 228 param.setBlobClobPresent(); 229 } 230 else if (parm1[i] instanceof Blob ) { 231 parm1[i] = new RmiBlobServerSide( (Blob ) parm1[i]); 232 param.setBlobClobPresent(); 233 } 234 else if (parm1[i] instanceof Time ) { 235 parm1[i] = new Time (((Time )parm1[i]).getTime()); 236 } 237 else if (parm1[i] instanceof Date ) { 238 parm1[i] = new Date (((Date )parm1[i]).getTime()); 239 } 240 else if (parm1[i] instanceof Timestamp ) { 241 parm1[i] = new Timestamp (((Timestamp )parm1[i]).getTime()); 242 } 243 244 } 245 } 246 param.setObjects(parm1); 247 param.setType(param.OBJECT_ARRAY); 248 return param; 249 } 250 251 private Parameters getParametersObjForHashMap(HashMap parm1) throws 252 RemoteException { 253 Parameters param = new Parameters(); 254 if (parm1 != null) { 255 Object [] keys = parm1.keySet().toArray(); 256 if (keys != null) { 257 for (int i = 0; i < keys.length; i++) { 258 Object value = parm1.get(keys[i]); 259 if (value instanceof Clob ) { 260 parm1.put(keys[i], new RmiClobServerSide( (Clob ) value)); 261 param.setBlobClobPresent(); 262 } 263 else if (value instanceof Blob ) { 264 parm1.put(keys[i], new RmiBlobServerSide( (Blob ) value)); 265 param.setBlobClobPresent(); 266 } 267 else if (value instanceof Time ) { 268 parm1.put(keys[i], new Time ( ( (Time ) value).getTime())); 269 } 270 else if (value instanceof Date ) { 271 parm1.put(keys[i],new Date ( ( (Date ) value).getTime())); 272 } 273 else if (value instanceof Timestamp ) { 274 parm1.put(keys[i], new Timestamp ( ( (Timestamp ) value).getTime())); 275 } 276 277 } 278 } 279 } 280 param.setObjects(parm1); 281 param.setType(param.HASHMAP); 282 return param; 283 } 284 285 } 286 | Popular Tags |