1 26 27 package org.objectweb.openccm.pss.runtime.hibernate.lib; 28 29 import org.objectweb.openccm.pss.runtime.common.lib.PIDHelper; 30 31 32 39 40 public abstract class StorageHomeBase 41 extends org.objectweb.openccm.pss.runtime.common.lib.StorageHomeBase 42 implements org.objectweb.openccm.pss.runtime.hibernate.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 String sshort_pid = new String (short_pid); 95 Integer identifier = null; 97 try { 98 identifier = new Integer (sshort_pid); 99 } catch (NumberFormatException ex) { 100 ex.printStackTrace(); 101 throw new org.omg.CosPersistentState.NotFound(); 102 } 103 104 java.util.Iterator it = _storage_type_incarnations.iterator(); 106 org.omg.CosPersistentState.StorageObject so = null; 107 108 while(it.hasNext()) 109 { 110 so = (org.omg.CosPersistentState.StorageObject) it.next(); 111 if ( java.util.Arrays.equals(so.get_short_pid(), short_pid) ) 112 { 113 return so; 114 } 115 } 116 117 java.lang.Object obj = null; 119 net.sf.hibernate.Session session = null; 120 org.objectweb.openccm.pss.runtime.common.api.CatalogBase catalog = null; 121 java.lang.Class clazz = null; 122 123 session = ((org.objectweb.openccm.pss.runtime.hibernate.api.CatalogBase) get_catalog()). 124 get_hibernate_session(); 125 126 catalog = (org.objectweb.openccm.pss.runtime.common.api.CatalogBase) get_catalog(); 127 clazz = catalog.get_connector().get_storage_object_factory( get_st_rid() ); 128 129 try { 130 obj = session.load(clazz, identifier); 131 _storage_type_incarnations.add(obj); 132 ((org.objectweb.openccm.pss.runtime.common.api.StorageObject) obj).initialize(this); 133 } catch (net.sf.hibernate.HibernateException ex) { 134 ex.printStackTrace(); 135 throw new org.omg.CosPersistentState.NotFound(); 136 } 137 return obj; 138 } 139 140 146 152 159 public byte[] 160 create_pid(String short_pid) 161 { 162 return PIDHelper.encode(get_rid(), short_pid); 163 } 164 165 168 public void 169 before_create() 170 { 171 ((org.objectweb.openccm.pss.runtime.hibernate.api.CatalogBase) get_catalog()).begin_tx(); 172 } 173 174 179 public void 180 after_create(org.objectweb.openccm.pss.runtime.hibernate.api.StorageObject st) 181 { 182 org.objectweb.openccm.pss.runtime.hibernate.api.CatalogBase catalog = null; 183 net.sf.hibernate.Session session = null; 184 st.initialize(this); 185 186 catalog = (org.objectweb.openccm.pss.runtime.hibernate.api.CatalogBase) get_catalog(); 188 session = catalog.get_hibernate_session(); 189 190 try { 191 session.save(st); 192 } catch (net.sf.hibernate.HibernateException ex) { 193 throw new RuntimeException (ex); 194 } 195 196 catalog.commit_tx(); 197 198 } 199 200 205 public Object 206 find_by_key(String [] fields_names, String [] fields_types, java.lang.Object [] key_values) 207 { 208 net.sf.hibernate.Session session = null; 209 String query = null; 210 java.lang.Class clazz = null; 211 java.util.List l = null; 212 org.objectweb.openccm.pss.runtime.common.api.StorageObject so; 213 net.sf.hibernate.type.Type[] types = TypeMapping.toTypes(fields_types); 214 215 session = ((org.objectweb.openccm.pss.runtime.hibernate.api.CatalogBase) get_catalog()). 217 get_hibernate_session(); 218 219 clazz = ((org.objectweb.openccm.pss.runtime.hibernate.api.CatalogBase) get_catalog()). 221 get_connector().get_storage_object_factory(get_st_rid()); 222 223 query = "from " + clazz.getName() + " where "; 225 for (int i=0; i<fields_names.length; i++) { 226 query += fields_names[i] + "=?"; 227 if (i < fields_names.length-1) { 228 query += " and "; 229 } 230 } 231 232 try { 233 l = session.find(query, key_values, types); 234 } catch (net.sf.hibernate.HibernateException ex) { 235 throw new RuntimeException (ex); 236 } 237 238 if ( 1 == l.size() ) { 239 so = (org.objectweb.openccm.pss.runtime.common.api.StorageObject) l.get(0); 240 so.initialize(this); 241 return so; 242 } 243 return null; 244 } 245 } 246 | Popular Tags |