1 18 package org.objectweb.speedo.genclass; 19 20 import org.objectweb.jorm.api.PAccessor; 21 import org.objectweb.jorm.api.PBinding; 22 import org.objectweb.jorm.api.PClassMapping; 23 import org.objectweb.jorm.api.PException; 24 import org.objectweb.jorm.api.PMapper; 25 import org.objectweb.jorm.api.PMappingCallback; 26 import org.objectweb.jorm.api.PMappingStructuresManager; 27 import org.objectweb.jorm.api.PNameIterator; 28 import org.objectweb.jorm.mapper.rdb.genclass.RdbGenClassMapping; 29 import org.objectweb.jorm.metainfo.api.MetaObject; 30 import org.objectweb.jorm.naming.api.PBinder; 31 import org.objectweb.jorm.naming.api.PName; 32 import org.objectweb.jorm.naming.api.PNameCoder; 33 import org.objectweb.jorm.type.api.PType; 34 import org.objectweb.jorm.util.api.Loggable; 35 import org.objectweb.medor.tuple.api.TupleCollection; 36 import org.objectweb.perseus.persistence.api.TransactionalPersistenceManager; 37 import org.objectweb.speedo.genclass.api.SpeedoGenClassProxy; 38 import org.objectweb.speedo.mim.api.SpeedoProxy; 39 import org.objectweb.speedo.mim.lib.SpeedoHomeImpl; 40 import org.objectweb.speedo.pm.api.ProxyManager; 41 import org.objectweb.speedo.pm.api.ProxyManagerFactory; 42 import org.objectweb.util.monolog.api.Logger; 43 import org.objectweb.util.monolog.api.LoggerFactory; 44 45 import java.util.HashMap ; 46 import java.util.Iterator ; 47 import java.util.Properties ; 48 49 import javax.jdo.JDOUserException; 50 51 57 public class SpeedoGenClassHome extends SpeedoHomeImpl { 58 59 PClassMapping pcm; 60 String path; 61 62 public SpeedoGenClassHome(PClassMapping _pcm, 63 TransactionalPersistenceManager _tpm, 64 ProxyManagerFactory _pmf, 65 String p) { 66 super(_tpm, _pmf); 67 this.pcm = _pcm; 68 this.path = p; 69 } 70 71 public void makePersistent(ProxyManager pm, SpeedoProxy sp, SpeedoGenClassProxy jdoProxy) { 72 if (!sp.jdoIsActive()) { 73 if (sp instanceof SpeedoGenClassProxy) { 74 SpeedoGenClassProxy sgcp = (SpeedoGenClassProxy) sp; 76 if (sgcp.jdoGetPType() == null) { 77 sgcp.jdoSetPType(jdoProxy.jdoGetPType().getNestedPType()); 79 } 80 sgcp.jdoSetLinkedField(jdoProxy.jdoGetGenClassId()); 81 sgcp.jdoSetPNameHints(jdoProxy.getPName()); 82 } 83 if (pm == null) { 84 pm = (ProxyManager) jdoProxy.jdoGetPersistenceManager(); 85 } 86 if (pm == null) { 87 throw new JDOUserException( 88 "When a persistent object is used (read or write), " + 89 "a PersistenceManager is needed"); 90 } 91 pm.speedoMakePersistent(sp, true); 92 } 93 } 94 95 public void makePersistent(ProxyManager pm, Iterator it, SpeedoGenClassProxy jdoProxy) { 96 if (it == null) { 97 return; 98 } 99 while(it.hasNext()) { 100 Object o = it.next(); 101 if (o instanceof SpeedoProxy) { 102 makePersistent(pm, (SpeedoProxy) o, jdoProxy); 103 } else { 104 return; 108 } 109 } 110 } 111 112 115 public boolean isDetachable() { 116 return false; 117 } 118 119 public byte getVersioningStrategy() { 120 return 0; 121 } 122 123 public Properties getClassProperties() { 124 return null; 125 } 126 127 public String getPath() { 128 return path; 129 } 130 131 public void setPrefetchOnGenClass(boolean prefetch) { 132 super.setPrefetchOnGenClass(prefetch); 133 if (pcm instanceof RdbGenClassMapping) { 134 ((RdbGenClassMapping) pcm).setPrefetchActivated(prefetch); 135 } 136 } 137 138 141 public String getProjectName() { 142 return pcm.getProjectName(); 143 } 144 145 public PBinding createPBinding() throws PException { 146 PBinding pb = pcm.createPBinding(); 147 pb.init(this); 148 return pb; 149 150 } 151 152 public void init(PMappingCallback mapper, MetaObject metaclass) 153 throws PException { 154 pcm.init(mapper, metaclass); 155 } 156 157 public String getClassName() { 158 return pcm.getClassName(); 159 } 160 161 public PClassMapping getGenClassMapping() 162 throws UnsupportedOperationException { 163 return pcm.getGenClassMapping(); 164 } 165 166 public PClassMapping getGenClassMapping(String fn) 167 throws UnsupportedOperationException { 168 return pcm.getGenClassMapping(fn); 169 } 170 171 public MetaObject getMetaInfo() { 172 return pcm.getMetaInfo(); 173 } 174 175 public PBinder getPBinder() { 176 return pcm.getPBinder(); 177 } 178 179 public PMapper getPMapper() { 180 return pcm.getPMapper(); 181 } 182 183 public PNameCoder getPNameCoder() throws UnsupportedOperationException { 184 return pcm.getPNameCoder(); 185 } 186 187 public PNameCoder getPNameCoder(String fn) 188 throws UnsupportedOperationException { 189 return pcm.getPNameCoder(fn); 190 } 191 192 public PNameCoder getClassPNameCoder() { 193 return pcm.getClassPNameCoder(); 194 } 195 196 public PNameIterator getPNameIterator(Object conn, boolean withSubType, 197 boolean prefetching, Object txctx) throws PException { 198 return pcm.getPNameIterator(conn, withSubType, prefetching, txctx); 199 } 200 201 public Iterator getPNameIterator(Object conn) throws PException { 202 return pcm.getPNameIterator(conn, false, false, null); 203 } 204 205 public PType getPType() { 206 return pcm.getPType(); 207 } 208 209 public boolean isConform(String mappername) { 210 return pcm.isConform(mappername); 211 } 212 213 public void setPBinder(PBinder pb) throws PException { 214 pcm.setPBinder(pb); 215 } 216 217 public void configureRefFields(ReferenceConfigurator rc) throws PException, 218 UnsupportedOperationException { 219 pcm.configureRefFields(rc); 220 } 221 222 public boolean exist(PBinding pb, Object conn) throws PException { 223 return pcm.exist(pb, conn); 224 } 225 226 public void read(PBinding pb, Object conn, PAccessor pa) throws PException { 227 pcm.read(pb, conn, pa); 228 } 229 230 public void read(PBinding pb, Object conn, PAccessor pa, Object txctx) 231 throws PException { 232 pcm.read(pb, conn, pa, txctx); 233 } 234 235 public void write(PBinding pb, Object conn, PAccessor pa) throws PException { 236 pcm.write(pb, conn, pa); 237 } 238 239 240 243 public Logger getLogger() { 244 return ((Loggable) pcm).getLogger(); 245 } 246 247 public LoggerFactory getLoggerFactory() { 248 return ((Loggable) pcm).getLoggerFactory(); 249 } 250 251 public void setLogger(Logger logger) { 252 ((Loggable) pcm).setLogger(logger); 253 } 254 255 public void setLoggerFactory(LoggerFactory loggerfactory) { 256 ((Loggable) pcm).setLoggerFactory(loggerfactory); 257 } 258 259 public PClassMapping[] getSubPCMs() throws PException { 260 return pcm.getSubPCMs(); 261 } 262 263 public HashMap getAssociationTable() { 264 return pcm.getAssociationTable(); 265 } 266 267 public void addAssociation(PClassMapping targetClass, int[] indexes) { 268 pcm.addAssociation(targetClass, indexes); 269 } 270 271 public int[] getIndexesTable(PClassMapping targetClass) { 272 return pcm.getIndexesTable(targetClass); 273 } 274 275 public PName resolve(Object conn, PName pname) throws PException{ 276 return pcm.resolve(conn, pname); 277 } 278 279 public boolean match(Object obj, boolean b) throws PException{ 280 return pcm.match(obj, b); 281 } 282 283 public PName getDecodedPName(TupleCollection tc, PName pname, boolean intermediaryTuple) throws PException { 284 return pcm.getDecodedPName(tc, pname, intermediaryTuple); 285 } 286 287 public void init(PMappingStructuresManager pmsm) throws PException { 288 pcm.init(pmsm); 289 } 290 291 public void classDefined(PMappingStructuresManager pmsm) throws PException { 292 pcm.classDefined(pmsm); 293 } 294 } 295 | Popular Tags |