1 26 27 package org.objectweb.openccm.pss.runtime.jdo.lib; 28 29 import org.objectweb.openccm.pss.runtime.common.lib.PIDHelper; 31 32 33 40 public abstract class StorageHomeBase 41 extends org.objectweb.openccm.pss.runtime.common.lib.StorageHomeBase 42 implements org.objectweb.openccm.pss.runtime.jdo.api.StorageHomeBase 43 { 44 50 56 59 public StorageHomeBase() 60 { 61 } 62 63 69 75 81 90 public java.lang.Object 91 find_by_short_pid(byte[] short_pid) 92 throws org.omg.CosPersistentState.NotFound 93 { 94 java.util.Iterator it = _storage_type_incarnations.iterator(); 96 org.omg.CosPersistentState.StorageObject so = null; 97 98 while(it.hasNext()) 99 { 100 so = (org.omg.CosPersistentState.StorageObject) it.next(); 101 if ( java.util.Arrays.equals(so.get_short_pid(), short_pid) ) 102 { 103 return so; 104 } 105 } 106 107 java.lang.Object oid = null, 109 obj = null; 110 javax.jdo.PersistenceManager pm = null; 111 org.objectweb.openccm.pss.runtime.common.api.CatalogBase catalog = null; 112 java.lang.Class clazz = null; 113 114 pm = ((org.objectweb.openccm.pss.runtime.jdo.api.CatalogBase) get_catalog()). 115 get_persistence_manager(); 116 117 catalog = (org.objectweb.openccm.pss.runtime.common.api.CatalogBase) get_catalog(); 118 clazz = catalog.get_connector().get_storage_object_factory( get_st_rid() ); 119 120 oid = pm.newObjectIdInstance 121 ( 122 clazz, 123 new String (short_pid) 124 ); 125 try 126 { 127 obj = pm.getObjectById(oid, true); 128 ((org.objectweb.openccm.pss.runtime.common.api.StorageObject) obj).initialize(this); 129 _storage_type_incarnations.add(obj); 131 }catch(javax.jdo.JDODataStoreException ex){ 132 throw new org.omg.CosPersistentState.NotFound(); 133 } 134 return obj; 135 } 136 137 143 149 156 public byte[] 157 create_pid(String short_pid) 158 { 159 return PIDHelper.encode(get_rid(), short_pid); 160 } 161 162 165 public void 166 before_create() 167 { 168 ((org.objectweb.openccm.pss.runtime.jdo.api.CatalogBase) get_catalog()).begin_tx(); 169 } 170 171 176 public void 177 after_create(org.objectweb.openccm.pss.runtime.jdo.api.StorageObject st) 178 { 179 org.objectweb.openccm.pss.runtime.jdo.api.CatalogBase catalog = null; 180 javax.jdo.PersistenceManager pm = null; 181 182 st.initialize(this); 183 184 catalog = (org.objectweb.openccm.pss.runtime.jdo.api.CatalogBase) get_catalog(); 186 pm = catalog.get_persistence_manager(); 187 pm.makePersistent(st); 188 189 catalog.commit_tx(); 190 } 191 192 203 public Object 204 find_by_key(String [] fields_names, 205 String [] fields_types, 206 java.lang.Object [] key_values) 207 throws org.omg.CosPersistentState.NotFound 208 { 209 javax.jdo.PersistenceManager pm = null; 210 javax.jdo.Extent ext = null; 211 javax.jdo.Query q = null; 212 String filter = null, 213 params = null; 214 java.util.Collection c = null; 215 java.lang.Class clazz = null; 216 java.lang.Object [] query_values = null; 217 218 pm = ((org.objectweb.openccm.pss.runtime.jdo.api.CatalogBase) get_catalog()). 220 get_persistence_manager(); 221 222 ((org.objectweb.openccm.pss.runtime.jdo.api.CatalogBase) get_catalog()).begin_tx(); 223 224 clazz = ((org.objectweb.openccm.pss.runtime.jdo.api.CatalogBase) get_catalog()). 226 get_connector().get_storage_object_factory(get_st_rid()); 227 ext = pm.getExtent(clazz, false); 228 229 filter = "sh_rid == sh_rid_param & "; 231 params = "String sh_rid_param, "; 232 for (int i=0; i<fields_names.length; i++) 233 { 234 filter += fields_names[i] + "==" + fields_names[i] + "_param"; 235 params += fields_types[i] +" " + fields_names[i] + "_param"; 236 if (i < fields_names.length-1) 237 { 238 filter += " & "; 239 params += ", "; 240 } 241 } 242 q = pm.newQuery(ext, filter); 243 q.declareParameters(params); 244 245 query_values = new java.lang.Object [key_values.length+1]; 247 query_values[0] = get_rid(); 248 for (int i=0; i<key_values.length; i++) 249 { 250 query_values[i+1] = key_values[i]; 251 } 252 c = (java.util.Collection ) q.executeWithArray(query_values); 254 255 if (c.size() == 1) 256 { 257 java.util.Iterator it = c.iterator(); 258 org.objectweb.openccm.pss.runtime.common.api.StorageObject so = null; 259 260 so = (org.objectweb.openccm.pss.runtime.common.api.StorageObject) it.next(); 261 so.initialize(this); 262 return so; 263 } 264 265 throw new org.omg.CosPersistentState.NotFound(); 266 } 267 } 268 | Popular Tags |