1 18 package org.objectweb.speedo.mapper.jca; 19 20 import org.objectweb.jorm.api.PException; 21 import org.objectweb.jorm.api.JormConfigurator; 22 import org.objectweb.jorm.lib.MapperJCA; 23 import org.objectweb.util.monolog.api.LoggerFactory; 24 import org.objectweb.fractal.api.control.LifeCycleController; 25 import org.objectweb.speedo.api.ExceptionHelper; 26 import org.objectweb.speedo.api.SpeedoProperties; 27 import org.objectweb.speedo.mapper.api.MapperAttributes; 28 import org.objectweb.medor.eval.prefetch.lib.PrefetchCacheImpl; 29 import org.objectweb.perseus.persistence.api.ConnectionHolderFactory; 30 import org.objectweb.perseus.persistence.api.ConnectionHolder; 31 import org.objectweb.perseus.persistence.api.PersistenceException; 32 import org.objectweb.perseus.pool.api.Pool; 33 34 import javax.jdo.JDOUserException; 35 36 public class JCAMapper extends MapperJCA 37 implements MapperAttributes, LifeCycleController, ConnectionHolderFactory { 38 39 public final static String MONOLOG_FACTORY_BINDING = "monolog-factory"; 40 public final static String POOL_BINDING = "pool"; 41 public final static String LOGGER_NAME 42 = SpeedoProperties.LOGGER_NAME + ".rt.mapper.jca"; 43 public final static String RESOUCE_ADAPTER_BINDINNG = "resouce-adapter"; 44 45 private boolean started; 46 47 private boolean initialized = false; 48 49 private boolean checkConnectivityAtStartup = true; 50 51 private Pool pool; 52 53 public JCAMapper() throws PException { 54 } 55 56 public boolean getCheckConnectivityAtStartup() { 57 return checkConnectivityAtStartup; 58 } 59 public void setCheckConnectivityAtStartup(boolean b) { 60 checkConnectivityAtStartup = b; 61 } 62 65 public Object getFcBindings(String s) { 66 if (MONOLOG_FACTORY_BINDING.equals(s)) 67 return getLoggerFactory(); 68 else if (RESOUCE_ADAPTER_BINDINNG.equals(s)) 69 return getConnectionFactory(); 70 else if (POOL_BINDING.equals(s)) 71 return pool; 72 return null; 73 } 74 75 public void addFcBinding(String s, Object o) { 76 if (MONOLOG_FACTORY_BINDING.equals(s)) 77 setLoggerFactory((LoggerFactory) o); 78 else if (POOL_BINDING.equals(s)) 79 pool = (Pool) o; 80 else if (RESOUCE_ADAPTER_BINDINNG.equals(s)) 81 try { 82 setConnectionFactory(o); 83 } catch (PException e) { 84 throw new JDOUserException( 85 "Impossible to assign the connection factory to the mapper", e); 86 } 87 } 88 89 public void removeFcBinding(String s, Object o) { 90 if (MONOLOG_FACTORY_BINDING.equals(s)) 91 setLoggerFactory(null); 92 else if (POOL_BINDING.equals(s)) 93 pool = null; 94 else if (RESOUCE_ADAPTER_BINDINNG.equals(s)) 95 try { 96 setConnectionFactory(null); 97 } catch (PException e) { 98 throw new JDOUserException( 99 "Impossible to remove the connection factory to the mapper", e); 100 } 101 } 102 103 104 public ConnectionHolder createConnectionHolder() throws PersistenceException { 107 return null; 108 } 109 110 113 public String getFcState() { 114 return started ? STARTED : STOPPED; 115 } 116 117 public void startFc() { 118 started = true; 119 if (!initialized) { 120 try { 121 122 JormConfigurator jc = getJormConfigurator(); 123 jc.setLoggerFactory(getLoggerFactory()); 124 setJormConfigurator(jc); 125 PrefetchCacheImpl pc = new PrefetchCacheImpl( 126 getLoggerFactory().getLogger( 127 "org.objectweb.speedo.rt.query.prefetch")); 128 setPrefetchCache(pc); 129 start(); 130 initialized = true; 131 } catch (PException e) { 132 throw new RuntimeException ( 133 "Impossible to configure the mapper: " 134 + ExceptionHelper.getNested(e).getMessage()); 135 } 136 } 137 } 138 139 public void stopFc() { 140 started = false; 141 } 142 143 } 144 | Popular Tags |