Author: tchemit Date: 2009-08-31 15:17:15 +0200 (Mon, 31 Aug 2009) New Revision: 10 Modified: trunk/billy-business/src/main/java/org/chorem/billy/RegisterBillyServices.java Log: [FIX] #31 CLassCastException H2Dialect en Dialect (build hibernate factory at init time) Modified: trunk/billy-business/src/main/java/org/chorem/billy/RegisterBillyServices.java =================================================================== --- trunk/billy-business/src/main/java/org/chorem/billy/RegisterBillyServices.java 2009-08-31 13:09:50 UTC (rev 9) +++ trunk/billy-business/src/main/java/org/chorem/billy/RegisterBillyServices.java 2009-08-31 13:17:15 UTC (rev 10) @@ -28,6 +28,7 @@ import org.chorem.choreg.ChoremRegistry; import org.chorem.choreg.ChoremRegistryImpl; import org.chorem.choreg.ChoremService; +import org.nuiton.topia.framework.TopiaContextImpl; /** * RegisterBillyServices.java @@ -40,30 +41,36 @@ * Last update: $Date$ * by : $Author$ */ -public class RegisterBillyServices implements Runnable, ServletContextListener { +public class RegisterBillyServices implements ServletContextListener { +//public class RegisterBillyServices implements Runnable, ServletContextListener { private static final Log log = LogFactory.getLog(RegisterBillyServices.class); private static final ChoremRegistry registry = ChoremRegistryImpl.getInstance(); - @Override - public void run() { + public static void startup() { if (log.isInfoEnabled()) { - log.info("Cash registration business services"); + log.info("Billy registration business services"); } - //register(ServicePerson.class, new ServicePersonXPIL()); - } + // fix H2Dialect ClassCastException (force load of dialect class) + try { + // force le chargement de la factory hibernate + ((TopiaContextImpl) ContextUtilBilly.getRootContext()).getHibernateFactory(); + } catch (Exception e) { + log.error(e); + } - @Override - public void contextInitialized(ServletContextEvent arg0) { - run(); + } - @Override - public void contextDestroyed(ServletContextEvent arg0) { + /** + * Shutdown ChoReg registration for business services. ToPIA root context is closed after unregistration. + */ + public static void shutdown() { + +// unregister(ServicePerson.class); +// unregister(ServiceOrganization.class); - //unregister(ServicePerson.class); - try { ContextUtilBilly.closeRootContext(); } catch (BillyException eee) { @@ -72,8 +79,36 @@ } } } + +// @Override +// public void run() { +// if (log.isInfoEnabled()) { +// log.info("Cash registration business services"); +// } +// //register(ServicePerson.class, new ServicePersonXPIL()); +// } - private void register(Class serviceClass, ChoremService service) { + @Override + public void contextInitialized(ServletContextEvent arg0) { + startup(); + } + + @Override + public void contextDestroyed(ServletContextEvent arg0) { + + shutdown(); + //unregister(ServicePerson.class); + +// try { +// ContextUtilBilly.closeRootContext(); +// } catch (BillyException eee) { +// if (log.isErrorEnabled()) { +// log.error("Error when closing Root Context", eee); +// } +// } + } + + private void register(Class<?> serviceClass, ChoremService service) { String sid = ChoremConvert.toSid(serviceClass); registry.register(sid, service); if (log.isDebugEnabled()) { @@ -81,7 +116,7 @@ } } - private void unregister(Class serviceClass) { + private void unregister(Class<?> serviceClass) { String sid = ChoremConvert.toSid(serviceClass); registry.unregister(sid); if (log.isDebugEnabled()) {