r3422 - in trunk/lima-business/src/main: java/org/chorem/lima/business resources
Author: echatellier Date: 2012-05-15 14:48:56 +0200 (Tue, 15 May 2012) New Revision: 3422 Url: http://chorem.org/repositories/revision/lima/3422 Log: fixes #408 : Modify hibernate database creation mecanism Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaInterceptor.java trunk/lima-business/src/main/resources/lima.properties 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-05-15 09:53:13 UTC (rev 3421) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/LimaInterceptor.java 2012-05-15 12:48:56 UTC (rev 3422) @@ -36,8 +36,11 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.LimaXAResource; +import org.chorem.lima.entity.AccountImpl; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaContextFactory; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaUtil; /** * Interceptor for topia context transaction. @@ -83,6 +86,8 @@ TopiaContext rootContext = TopiaContextFactory.getContext(config.getFlatOptions()); TopiaContext tx = rootContext.beginTransaction(); + createShemaIfNeeded(tx); + LimaDaoHelper helper = new LimaDaoHelper(tx); DAO_HELPER.set(helper); @@ -107,4 +112,28 @@ 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/main/resources/lima.properties =================================================================== --- trunk/lima-business/src/main/resources/lima.properties 2012-05-15 09:53:13 UTC (rev 3421) +++ trunk/lima-business/src/main/resources/lima.properties 2012-05-15 12:48:56 UTC (rev 3422) @@ -23,11 +23,6 @@ # #L% ### -# Proprietes par defaut pour une base de donnees de type H2 -# FIXME echatellier remove this (currently active only for test, and creation) -hibernate.hbm2ddl.auto=update -#hibernate.show_sql=true - hibernate.dialect=org.hibernate.dialect.H2Dialect hibernate.connection.username=sa hibernate.connection.password=
participants (1)
-
echatellier@users.chorem.org