1 28 29 30 package org.objectweb.jonas_ejb.container.jorm; 31 32 import javax.sql.DataSource ; 33 34 import org.objectweb.jonas_ejb.container.JContainer; 35 import org.objectweb.jonas_ejb.deployment.api.EntityDesc; 36 37 import org.objectweb.jorm.api.PClassMapping; 38 import org.objectweb.jorm.api.PException; 39 import org.objectweb.jorm.lib.MapperJCA; 40 import org.objectweb.jorm.mapper.rdb.genclass.RdbGenClassProp; 41 import org.objectweb.jorm.mapper.rdb.lib.MapperJDBC; 42 import org.objectweb.jorm.mapper.rdb.lib.RdbPrefetchablePCM; 43 44 48 public abstract class RdbFactory extends MedorFactory { 49 50 public RdbFactory() { 51 super(); 52 } 53 54 public void init(EntityDesc dd, JContainer cont, String mapperName) { 55 super.init(dd, cont, mapperName); 56 } 57 58 public Object getConnection(Object hints) throws PException { 59 if (hints == null) { 60 return mapper.getConnection(); 61 } else { 62 return mapper.getConnection(hints); 63 } 64 } 65 66 public void releaseConnection(Object conn) throws PException { 67 mapper.closeConnection(conn); 68 } 69 70 protected void setMapper(String mapperName) throws PException { 71 MapperManager mm = MapperManager.getInstance(); 72 synchronized (mm) { 73 mapper = mm.getMapper(cont, datasource); 74 if (mapper == null) { 75 if (datasource instanceof DataSource ) { 77 mapper = new MapperJDBC(mm.getJormConfigurator()); 78 } else { 79 mapper = new MapperJCA(mm.getJormConfigurator()); 80 } 81 mapper.setMapperName(mapperName); 82 83 mapper.setConnectionFactory(datasource); 85 86 mm.addMapper(mapper, cont, datasource); 88 } 89 } 90 } 91 92 98 protected void initGenClassPrefetch(PClassMapping gcm, PClassMapping targetPCM) { 99 if (gcm instanceof RdbGenClassProp && targetPCM instanceof RdbPrefetchablePCM) { 100 ((RdbGenClassProp) gcm).setPrefetchElementPCM((RdbPrefetchablePCM) targetPCM); 101 } 102 } 103 104 } 105 | Popular Tags |