1 21 22 package org.apache.derby.impl.sql; 23 24 import org.apache.derby.iapi.services.monitor.ModuleFactory; 25 import org.apache.derby.iapi.services.monitor.Monitor; 26 27 import org.apache.derby.iapi.services.sanity.SanityManager; 28 29 import org.apache.derby.catalog.UUID; 30 import org.apache.derby.iapi.services.uuid.UUIDFactory; 31 import org.apache.derby.iapi.util.ByteArray; 32 33 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 34 35 import org.apache.derby.iapi.sql.Activation; 36 import org.apache.derby.iapi.sql.ResultColumnDescriptor; 37 import org.apache.derby.iapi.sql.ResultDescription; 38 import org.apache.derby.iapi.sql.ResultSet; 39 import org.apache.derby.iapi.sql.PreparedStatement; 40 import org.apache.derby.iapi.sql.Statement; 41 import org.apache.derby.iapi.sql.StorablePreparedStatement; 42 43 import org.apache.derby.iapi.sql.execute.ConstantAction; 44 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 45 46 import org.apache.derby.iapi.error.StandardException; 47 48 import org.apache.derby.iapi.reference.SQLState; 49 50 import org.apache.derby.iapi.services.loader.GeneratedClass; 51 import org.apache.derby.iapi.services.loader.ClassFactory; 52 import org.apache.derby.iapi.services.context.ContextService; 53 54 import org.apache.derby.iapi.services.io.StoredFormatIds; 55 import org.apache.derby.iapi.services.io.FormatIdUtil; 56 import org.apache.derby.iapi.services.io.ArrayUtil; 57 import org.apache.derby.iapi.services.io.Formatable; 58 59 import org.apache.derby.iapi.services.monitor.Monitor; 60 61 import java.sql.Timestamp ; 62 import java.io.ObjectOutput ; 63 import java.io.ObjectInput ; 64 import java.io.IOException ; 65 66 import org.apache.derby.iapi.services.loader.ClassFactory; 67 import org.apache.derby.iapi.services.loader.GeneratedClass; 68 import org.apache.derby.iapi.services.loader.GeneratedMethod; 69 73 public class GenericStorablePreparedStatement 74 extends GenericPreparedStatement implements Formatable, StorablePreparedStatement 75 { 76 77 private ByteArray byteCode; 79 private String className; 80 81 85 public GenericStorablePreparedStatement() 86 { 87 super(); 88 } 89 90 GenericStorablePreparedStatement(Statement stmt) 91 { 92 super(stmt); 93 } 94 95 102 ByteArray getByteCodeSaver() 103 { 104 if (byteCode == null) { 105 byteCode = new ByteArray(); 106 } 107 return byteCode; 108 } 109 110 120 public GeneratedClass getActivationClass() 121 throws StandardException 122 { 123 if (activationClass == null) 124 loadGeneratedClass(); 125 126 return activationClass; 127 } 128 129 void setActivationClass(GeneratedClass ac) { 130 131 super.setActivationClass(ac); 132 if (ac != null) { 133 className = ac.getName(); 134 135 if (byteCode != null && byteCode.getArray() == null) 137 byteCode = null; 138 } 139 } 140 141 147 152 public void loadGeneratedClass() 153 throws StandardException 154 { 155 LanguageConnectionContext lcc = 156 (LanguageConnectionContext) ContextService.getContext 157 (LanguageConnectionContext.CONTEXT_ID); 158 ClassFactory classFactory = lcc.getLanguageConnectionFactory().getClassFactory(); 159 160 GeneratedClass gc = classFactory.loadGeneratedClass(className, byteCode); 161 162 168 setActivationClass(gc); 169 } 170 171 172 181 public void writeExternal(ObjectOutput out) throws IOException 182 { 183 out.writeObject(getCursorInfo()); 184 out.writeBoolean(needsSavepoint()); 185 out.writeBoolean(isAtomic); 186 out.writeObject(executionConstants); 187 out.writeObject(resultDesc); 188 189 if (savedObjects == null) 191 { 192 out.writeBoolean(false); 193 } 194 else 195 { 196 out.writeBoolean(true); 197 ArrayUtil.writeArrayLength(out, savedObjects); 198 ArrayUtil.writeArrayItems(out, savedObjects); 199 } 200 201 208 out.writeObject(className); 209 out.writeBoolean(byteCode != null); 210 if (byteCode != null) 211 byteCode.writeExternal(out); 212 } 213 214 215 221 public void readExternal(ObjectInput in) 222 throws IOException , ClassNotFoundException 223 { 224 setCursorInfo((CursorInfo)in.readObject()); 225 setNeedsSavepoint(in.readBoolean()); 226 isAtomic = (in.readBoolean()); 227 executionConstants = (ConstantAction) in.readObject(); 228 resultDesc = (ResultDescription) in.readObject(); 229 230 if (in.readBoolean()) 231 { 232 savedObjects = new Object [ArrayUtil.readArrayLength(in)]; 233 ArrayUtil.readArrayItems(in, savedObjects); 234 } 235 236 className = (String )in.readObject(); 237 if (in.readBoolean()) { 238 byteCode = new ByteArray(); 239 byteCode.readExternal(in); 240 } 241 else 242 byteCode = null; 243 } 244 245 255 public int getTypeFormatId() { return StoredFormatIds.STORABLE_PREPARED_STATEMENT_V01_ID; } 256 257 public boolean isStorable() { 263 return true; 264 } 265 public String toString() 266 { 267 if (SanityManager.DEBUG) 268 { 269 String acn; 270 if (activationClass ==null) 271 acn = "null"; 272 else 273 acn = activationClass.getName(); 274 275 return "GSPS " + System.identityHashCode(this) + " activationClassName="+acn+" className="+className; 276 } 277 else 278 { 279 return ""; 280 } 281 } 282 } 283 | Popular Tags |