00001
00030 package org.objectweb.jonas_ejb.container.jorm;
00031
00032 import javax.sql.DataSource;
00033
00034 import org.objectweb.jonas_ejb.container.JContainer;
00035 import org.objectweb.jonas_ejb.deployment.api.EntityDesc;
00036
00037 import org.objectweb.jorm.api.PException;
00038 import org.objectweb.jorm.lib.MapperJCA;
00039 import org.objectweb.jorm.mapper.rdb.lib.MapperJDBC;
00040
00045 public abstract class RdbFactory extends MedorFactory {
00046
00047 public RdbFactory() {
00048 super();
00049 }
00050
00051 public void init(EntityDesc dd, JContainer cont, String mapperName) {
00052 super.init(dd, cont, mapperName);
00053 }
00054
00055 public Object getConnection(Object hints) throws PException {
00056 if (hints == null) {
00057 return mapper.getConnection();
00058 } else {
00059 return mapper.getConnection(hints);
00060 }
00061 }
00062
00063 public void releaseConnection(Object conn) throws PException {
00064 mapper.closeConnection(conn);
00065 }
00066
00067 protected void setMapper(String mapperName) throws PException {
00068 MapperManager mm = MapperManager.getInstance();
00069 synchronized (mm) {
00070 mapper = mm.getMapper(cont, datasource);
00071 if (mapper == null) {
00072
00073 if (datasource instanceof DataSource) {
00074 mapper = new MapperJDBC(mm.getJormConfigurator());
00075 } else {
00076 mapper = new MapperJCA(mm.getJormConfigurator());
00077 }
00078 mapper.setMapperName(mapperName);
00079
00080
00081 mapper.setConnectionFactory(datasource);
00082
00083
00084 mm.addMapper(mapper, cont, datasource);
00085 }
00086 }
00087 }
00088 }