r3800 - in trunk: lima-business/src/main/java/org/chorem/lima lima-business/src/main/java/org/chorem/lima/business lima-business/src/test/java/org/chorem/lima/business lima-callao/src/main/java/org/chorem/lima/entity
Author: athimel Date: 2014-05-16 15:43:25 +0200 (Fri, 16 May 2014) New Revision: 3800 Url: http://forge.chorem.org/projects/lima/repository/revisions/3800 Log: refs #934 Migrate LimaInterceptor and LimaXAResource Added: trunk/lima-callao/src/main/java/org/chorem/lima/entity/LimaCallaoTopiaPersistenceContext.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/LimaXAResource.java trunk/lima-business/src/main/java/org/chorem/lima/business/LimaInterceptor.java trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialStatementImpl.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/LimaXAResource.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/LimaXAResource.java 2014-05-16 13:27:34 UTC (rev 3799) +++ trunk/lima-business/src/main/java/org/chorem/lima/LimaXAResource.java 2014-05-16 13:43:25 UTC (rev 3800) @@ -30,7 +30,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.topia.persistence.TopiaException; -import org.nuiton.topia.persistence.internal.AbstractTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaTransaction; /** * Topia XA ressource containing TopiaContext to commit or rollback. @@ -45,12 +45,12 @@ private static Log log = LogFactory.getLog(LimaXAResource.class); - protected AbstractTopiaPersistenceContext context; + protected TopiaTransaction transaction; protected int timeout; - public LimaXAResource(AbstractTopiaPersistenceContext context) { - this.context = context; + public LimaXAResource(TopiaTransaction transaction) { + this.transaction = transaction; } /* @@ -59,7 +59,7 @@ @Override public void commit(Xid arg0, boolean arg1) throws XAException { try { - context.commit(); + transaction.commit(); } catch (TopiaException ex) { if (log.isErrorEnabled()) { log.error("Error", ex); @@ -126,7 +126,7 @@ @Override public void rollback(Xid arg0) throws XAException { try { - context.rollback(); + transaction.rollback(); } catch (TopiaException ex) { throw new XAException(XAException.XA_HEURCOM); } 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 2014-05-16 13:27:34 UTC (rev 3799) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/LimaInterceptor.java 2014-05-16 13:43:25 UTC (rev 3800) @@ -23,6 +23,8 @@ package org.chorem.lima.business; +import java.util.Properties; + import javax.annotation.Resource; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; @@ -35,8 +37,15 @@ import org.apache.commons.logging.LogFactory; import org.chorem.lima.LimaXAResource; import org.chorem.lima.entity.AccountImpl; +import org.chorem.lima.entity.LimaCallaoTopiaApplicationContext; +import org.chorem.lima.entity.LimaCallaoTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaApplicationContextCache; import org.nuiton.topia.persistence.TopiaException; +import com.google.common.base.Function; + +import sun.security.krb5.internal.ccache.CCacheInputStream; + /** * Interceptor for topia context transaction. * @@ -55,6 +64,15 @@ public static final ThreadLocal<LimaDaoHelper> DAO_HELPER = new ThreadLocal<LimaDaoHelper>(); + protected static final Function<Properties, LimaCallaoTopiaApplicationContext> CREATE_CONTEXT_FUNCTION = new Function<Properties, LimaCallaoTopiaApplicationContext>() { + @Override + public LimaCallaoTopiaApplicationContext apply(Properties input) { + return new LimaCallaoTopiaApplicationContext(input); + } + }; + + protected static boolean schemaExistChecked = false; + @Resource private TransactionManager transactionManager; @@ -78,20 +96,24 @@ } LimaConfig config = LimaConfig.getInstance(); - // TODO DCossé 16/05/14 -// TopiaContext rootContext = TopiaContextFactory.getContext(config.getFlatOptions()); -// TopiaContext tx = rootContext.beginTransaction(); -// -// createShemaIfNeeded(tx); -// -// LimaDaoHelper helper = new LimaDaoHelper(tx); -// DAO_HELPER.set(helper); + LimaCallaoTopiaApplicationContext rootContext = TopiaApplicationContextCache.getContext(config.getFlatOptions(), CREATE_CONTEXT_FUNCTION); + + if (!schemaExistChecked && rootContext.isSchemaEmpty()) { + rootContext.createSchema(); + schemaExistChecked = true; + } + + LimaCallaoTopiaPersistenceContext tx = rootContext.newPersistenceContext(); + + LimaDaoHelper helper = new LimaDaoHelper(tx); + DAO_HELPER.set(helper); + Transaction tr = transactionManager.getTransaction(); // enlist topia xaresource, will will commited or rollback // by container -// tr.enlistResource(new LimaXAResource(tx)); + tr.enlistResource(new LimaXAResource(tx)); try { result = context.proceed(); @@ -109,27 +131,4 @@ return result; } - protected static boolean schemaExistChecked = false; - - /** - * Test if schema do not already exists and create it if not found. - * - * @param tx transaction - * @throws TopiaException - */ -// protected void createShemaIfNeeded(TopiaContext tx) throws TopiaException { -// -// if (!schemaExistChecked) { -// boolean exist = TopiaUtil.isSchemaExist(tx, AccountImpl.class.getName()); -// if (!exist) { -// -// if (log.isInfoEnabled()) { -// log.info("Creating to schema in database"); -// } -// tx.createSchema(); -// } -// -// schemaExistChecked = true; -// } -// } } Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java 2014-05-16 13:27:34 UTC (rev 3799) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java 2014-05-16 13:43:25 UTC (rev 3800) @@ -56,17 +56,18 @@ import org.chorem.lima.entity.FinancialTransactionImpl; import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.entity.FiscalPeriodImpl; -import org.chorem.lima.entity.LimaCallaoDAOHelper; +import org.chorem.lima.entity.LimaCallaoEntityEnum; +import org.chorem.lima.entity.LimaCallaoTopiaApplicationContext; import org.chorem.lima.service.LimaServiceFactory; import org.junit.After; import org.junit.BeforeClass; import org.nuiton.i18n.I18n; import org.nuiton.i18n.init.ClassPathI18nInitializer; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.persistence.TopiaConfigurationConstants; +import org.nuiton.topia.persistence.TopiaApplicationContextCache; import org.nuiton.topia.persistence.TopiaNotFoundException; -import org.nuiton.topia.TopiaRuntimeException; +import com.google.common.base.Function; + /** * Common initialization code for all lima tests. * @@ -79,6 +80,12 @@ public abstract class AbstractLimaTest { private static final Log log = LogFactory.getLog(AbstractLimaTest.class); + protected static final Function<Properties, LimaCallaoTopiaApplicationContext> CREATE_CONTEXT_FUNCTION = new Function<Properties, LimaCallaoTopiaApplicationContext>() { + @Override + public LimaCallaoTopiaApplicationContext apply(Properties input) { + return new LimaCallaoTopiaApplicationContext(input); + } + }; protected static DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.ENGLISH); @@ -147,7 +154,7 @@ streamTest = AbstractLimaTest.class.getResourceAsStream("/lima-test.properties"); testProperties.load(streamTest); streamTest.close(); - } catch (IOException ex) {org.nuiton.topia.persistence.TopiaNotFoundException + } catch (IOException ex) { throw new RuntimeException("Can't init test configuration", ex); } finally { IOUtils.closeQuietly(streamMain); @@ -161,7 +168,7 @@ //testProperties.setProperty("hibernate.hbm2ddl.auto", "update"); instance.setOptions(testProperties); - instance.setOption("topia.persistence.classes", LimaCallaoDAOHelper.getImplementationClassesAsString()); + instance.setOption("topia.persistence.classes", LimaCallaoEntityEnum.getImplementationClassesAsString()); if (log.isDebugEnabled()) { log.debug("Using test configuration" + instance.getFlatOptions()); @@ -308,17 +315,14 @@ * * @return a topia context */ - protected static TopiaContext getTestContext() { - try { - LimaConfig config = LimaConfig.getInstance(); - Properties options = config.getFlatOptions(); - - if (log.isDebugEnabled()) { - log.debug("Opening context to database : " + options.getProperty("hibernate.connection.url")); - } - return TopiaContextFactory.getContext(options); - } catch (TopiaNotFoundException ex) { - throw new TopiaRuntimeException("Could not acquire root context", ex); + protected static LimaCallaoTopiaApplicationContext getTestContext() { + LimaConfig config = LimaConfig.getInstance(); + Properties options = config.getFlatOptions(); + + if (log.isDebugEnabled()) { + log.debug("Opening context to database : " + options.getProperty("hibernate.connection.url")); } + LimaCallaoTopiaApplicationContext result = TopiaApplicationContextCache.getContext(options, CREATE_CONTEXT_FUNCTION); + return result; } } Modified: trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialStatementImpl.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialStatementImpl.java 2014-05-16 13:27:34 UTC (rev 3799) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/FinancialStatementImpl.java 2014-05-16 13:43:25 UTC (rev 3800) @@ -42,4 +42,15 @@ } return level; } + + @Override + public boolean getHeaderAmount() { + return isHeaderAmount(); + } + + @Override + public boolean getSubAmount() { + return isSubAmount(); + } + } Added: trunk/lima-callao/src/main/java/org/chorem/lima/entity/LimaCallaoTopiaPersistenceContext.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/LimaCallaoTopiaPersistenceContext.java (rev 0) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/LimaCallaoTopiaPersistenceContext.java 2014-05-16 13:43:25 UTC (rev 3800) @@ -0,0 +1,59 @@ +package org.chorem.lima.entity; + +import java.util.List; + +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.cfg.Configuration; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.TopiaIdFactory; +import org.nuiton.topia.persistence.internal.HibernateProvider; +import org.nuiton.topia.persistence.internal.TopiaHibernateSessionRegistry; +import org.nuiton.topia.persistence.support.TopiaHibernateSupport; +import org.nuiton.topia.persistence.support.TopiaListenableSupport; +import org.nuiton.topia.persistence.support.TopiaSqlQuery; +import org.nuiton.topia.persistence.support.TopiaSqlSupport; +import org.nuiton.topia.persistence.support.TopiaSqlWork; + +public class LimaCallaoTopiaPersistenceContext extends AbstractLimaCallaoTopiaPersistenceContext implements TopiaHibernateSupport, TopiaSqlSupport { + + public LimaCallaoTopiaPersistenceContext(HibernateProvider hibernateProvider, TopiaListenableSupport listenableSupport, TopiaIdFactory topiaIdFactory, TopiaHibernateSessionRegistry sessionRegistry) { + super(hibernateProvider, listenableSupport, topiaIdFactory, sessionRegistry); + } + + @Override + public Session getHibernateSession() { + return getHibernateSupport().getHibernateSession(); + } + + @Override + public SessionFactory getHibernateFactory() { + return getHibernateSupport().getHibernateFactory(); + } + + @Override + public Configuration getHibernateConfiguration() { + return getHibernateSupport().getHibernateConfiguration(); + } + + @Override + public void executeSql(String sqlScript) { + getSqlSupport().executeSql(sqlScript); + } + + @Override + public void doSqlWork(TopiaSqlWork sqlWork) { + getSqlSupport().doSqlWork(sqlWork); + } + + @Override + public <O> O findSingleResult(TopiaSqlQuery<O> query) throws TopiaException { + return getSqlSupport().findSingleResult(query); + } + + @Override + public <O> List<O> findMultipleResult(TopiaSqlQuery<O> query) throws TopiaException { + return getSqlSupport().findMultipleResult(query); + } + +} //LimaCallaoTopiaPersistenceContext
participants (1)
-
athimel@users.chorem.org