Author: echatellier Date: 2012-04-18 16:24:21 +0200 (Wed, 18 Apr 2012) New Revision: 3380 Url: http://chorem.org/repositories/revision/lima/3380 Log: Refactor clear service to be part of ejb transaction Removed: trunk/lima-business/src/test/java/org/chorem/lima/business/ejb/ClearServiceLocal.java trunk/lima-business/src/test/java/org/chorem/lima/business/ejb/ClearServiceMonitorable.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaInterceptor.java trunk/lima-business/src/main/java/org/chorem/lima/service/LimaServiceFactory.java trunk/lima-business/src/test/java/org/chorem/lima/business/ejb/ClearService.java trunk/lima-business/src/test/java/org/chorem/lima/business/ejb/ClearServiceImpl.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaInterceptor.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/LimaInterceptor.java 2012-04-18 09:44:39 UTC (rev 3379) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/LimaInterceptor.java 2012-04-18 14:24:21 UTC (rev 3380) @@ -54,30 +54,13 @@ @Stateless public class LimaInterceptor { - private final Log log = LogFactory.getLog(LimaInterceptor.class); + private static final Log log = LogFactory.getLog(LimaInterceptor.class); public static final ThreadLocal<TopiaContext> TOPIA_CONTEXT = new ThreadLocal<TopiaContext>(); @Resource private TransactionManager transactionManager; - protected TopiaContext rootContext; - - public LimaInterceptor() { - if (log.isInfoEnabled()) { - log.info("Init root context"); - } - - LimaConfig config = LimaConfig.getInstance(); - try { - rootContext = TopiaContextFactory.getContext(config.getFlatOptions()); - } catch (TopiaNotFoundException ex) { - if (log.isErrorEnabled()) { - log.error("Can't init root context", ex); - } - } - } - @AroundInvoke public Object invoke(InvocationContext context) throws Exception { @@ -97,6 +80,8 @@ context.getTarget().getClass() + "#" + context.getMethod().getName()); } + LimaConfig config = LimaConfig.getInstance(); + TopiaContext rootContext = TopiaContextFactory.getContext(config.getFlatOptions()); TopiaContext tx = rootContext.beginTransaction(); TOPIA_CONTEXT.set(tx); @@ -107,8 +92,11 @@ // by container tr.enlistResource(new LimaXAResource(tx)); - result = context.proceed(); - TOPIA_CONTEXT.remove(); + try { + result = context.proceed(); + } finally { + TOPIA_CONTEXT.remove(); + } } else { result = context.proceed(); } Modified: trunk/lima-business/src/main/java/org/chorem/lima/service/LimaServiceFactory.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/service/LimaServiceFactory.java 2012-04-18 09:44:39 UTC (rev 3379) +++ trunk/lima-business/src/main/java/org/chorem/lima/service/LimaServiceFactory.java 2012-04-18 14:24:21 UTC (rev 3380) @@ -127,7 +127,9 @@ * Close openejb container. */ public static void destroy() { - container.close(); + if (container != null) { + container.close(); + } } /** Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/ejb/ClearService.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/ejb/ClearService.java 2012-04-18 09:44:39 UTC (rev 3379) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/ejb/ClearService.java 2012-04-18 14:24:21 UTC (rev 3380) @@ -41,6 +41,8 @@ /** * Clear database. + * + * @throws LimaException */ void clearDatabase() throws LimaException; } Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/ejb/ClearServiceImpl.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/ejb/ClearServiceImpl.java 2012-04-18 09:44:39 UTC (rev 3379) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/ejb/ClearServiceImpl.java 2012-04-18 14:24:21 UTC (rev 3380) @@ -24,10 +24,12 @@ package org.chorem.lima.business.ejb; import org.chorem.lima.business.LimaException; +import org.chorem.lima.business.LimaInterceptor; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; import javax.ejb.Stateless; +import javax.ejb.TransactionAttribute; /** * Clear database service. @@ -39,7 +41,8 @@ * By : $Author$ */ @Stateless -public class ClearServiceImpl extends AbstractLimaService implements ClearServiceLocal, ClearService { +@TransactionAttribute +public class ClearServiceImpl extends AbstractLimaService implements ClearService { /* * @see org.chorem.lima.business.ejb.ClearService#clearDatabase() @@ -47,15 +50,11 @@ @Override public void clearDatabase() throws LimaException { try { - TopiaContext rootContext = acquireRootContext(); - TopiaContext transaction = rootContext.beginTransaction(); + + TopiaContext transaction = LimaInterceptor.TOPIA_CONTEXT.get(); transaction.createSchema(); - transaction.commitTransaction(); - transaction.closeContext(); } catch (TopiaException ex) { throw new LimaException("Can't clear database", ex); } - } - } Deleted: trunk/lima-business/src/test/java/org/chorem/lima/business/ejb/ClearServiceLocal.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/ejb/ClearServiceLocal.java 2012-04-18 09:44:39 UTC (rev 3379) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/ejb/ClearServiceLocal.java 2012-04-18 14:24:21 UTC (rev 3380) @@ -1,40 +0,0 @@ -/* - * #%L - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 Codelutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.lima.business.ejb; - -import javax.ejb.Local; - -/** - * Clear database service. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -@Local -public interface ClearServiceLocal extends ClearService { - -} Deleted: trunk/lima-business/src/test/java/org/chorem/lima/business/ejb/ClearServiceMonitorable.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/ejb/ClearServiceMonitorable.java 2012-04-18 09:44:39 UTC (rev 3379) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/ejb/ClearServiceMonitorable.java 2012-04-18 14:24:21 UTC (rev 3380) @@ -1,39 +0,0 @@ -/* - * #%L - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 Codelutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.lima.business.ejb; - -import org.chorem.lima.business.ServiceMonitorable; - -/** - * Clear database service. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public interface ClearServiceMonitorable extends ClearService, ServiceMonitorable { - -}