Author: bleny Date: 2013-06-25 10:58:09 +0200 (Tue, 25 Jun 2013) New Revision: 252 Url: http://forge.codelutin.com/projects/franciaflex-magalie/repository/revisions... Log: in Oracle, persist double as 'float' sql type Added: trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/MagalieOracleHibernateDialect.java Removed: trunk/magalie-web/src/main/resources/magalie-production.properties Modified: trunk/magalie-persistence/pom.xml trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/MagalieApplicationConfig.java trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/MagalieConfigOption.java trunk/magalie-persistence/src/main/resources/magalie.properties Modified: trunk/magalie-persistence/pom.xml =================================================================== --- trunk/magalie-persistence/pom.xml 2013-06-21 16:11:19 UTC (rev 251) +++ trunk/magalie-persistence/pom.xml 2013-06-25 08:58:09 UTC (rev 252) @@ -37,6 +37,7 @@ <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> + <scope>compile</scope> <!-- to override hibernate dialect --> </dependency> <dependency> Modified: trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/MagalieApplicationConfig.java =================================================================== --- trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/MagalieApplicationConfig.java 2013-06-21 16:11:19 UTC (rev 251) +++ trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/MagalieApplicationConfig.java 2013-06-25 08:58:09 UTC (rev 252) @@ -23,6 +23,8 @@ * #L% */ +import com.franciaflex.magalie.persistence.MagalieOracleHibernateDialect; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import org.apache.commons.logging.Log; @@ -40,6 +42,12 @@ protected ApplicationConfig applicationConfig; + protected ImmutableMap<String, String> oracleCompatibilityModeJpaParameters = + ImmutableMap.of( + "hibernate.ejb.naming_strategy", org.nuiton.jpa.hibernate.OracleCompliantImprovedNamingStrategy.class.getCanonicalName(), + "hibernate.dialect", MagalieOracleHibernateDialect.class.getCanonicalName() + ); + public MagalieApplicationConfig() { applicationConfig = new ApplicationConfig(); applicationConfig.loadDefaultOptions(MagalieConfigOption.values()); @@ -67,6 +75,12 @@ jpaParameters.putAll((Map) hibernateProperties); Properties jpaProperties = applicationConfig.getOptionStartsWith("javax.persistence"); jpaParameters.putAll((Map) jpaProperties); + if (isOracleCompatibilityMode()) { + if (log.isInfoEnabled()) { + log.info("oracle compatibility mode enabled: overriding settings with " + oracleCompatibilityModeJpaParameters); + } + jpaParameters.putAll(oracleCompatibilityModeJpaParameters); + } return jpaParameters; } @@ -74,4 +88,10 @@ boolean isDevMode = applicationConfig.getOptionAsBoolean(MagalieConfigOption.DEV_MODE.key); return isDevMode; } + + public boolean isOracleCompatibilityMode() { + boolean isOracleCompatibilityMode = applicationConfig.getOptionAsBoolean(MagalieConfigOption.ORACLE_COMPATIBILITY_MODE.key); + return isOracleCompatibilityMode; + } + } Modified: trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/MagalieConfigOption.java =================================================================== --- trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/MagalieConfigOption.java 2013-06-21 16:11:19 UTC (rev 251) +++ trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/MagalieConfigOption.java 2013-06-25 08:58:09 UTC (rev 252) @@ -45,6 +45,11 @@ "L'adresse d'expéditeur pour les mails de notifications", "", String.class), + ORACLE_COMPATIBILITY_MODE( + "oracleCompatibilityMode", + "Empêche la création de noms d'identifiants de plus de 30 caractères, utilise Float pour persister les doubles", + "false", Boolean.class), + DEV_MODE( "devMode", "Mode développement, court-circuite l'envoi de mail", Added: trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/MagalieOracleHibernateDialect.java =================================================================== --- trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/MagalieOracleHibernateDialect.java (rev 0) +++ trunk/magalie-persistence/src/main/java/com/franciaflex/magalie/persistence/MagalieOracleHibernateDialect.java 2013-06-25 08:58:09 UTC (rev 252) @@ -0,0 +1,23 @@ +package com.franciaflex.magalie.persistence; + +import org.hibernate.dialect.Oracle10gDialect; + +import java.sql.Types; + +/** + * In the actual database, we are unable to create some views with columns + * typed as "double precision", so we map all double in the entities + * to "float" in database. + * + * @link http://stackoverflow.com/questions/2524966/hibernate-found-float-expected-do... + * @link http://docs.oracle.com/cd/B28359_01/server.111/b28285/sqlqr06.htm#CHDJJEEA show that + * SQL type DOUBLE PRECISION is actually implemented as FLOAT(126) + */ +public class MagalieOracleHibernateDialect extends Oracle10gDialect { + + public MagalieOracleHibernateDialect() { + super(); + registerColumnType(Types.DOUBLE, "float"); + } + +} Modified: trunk/magalie-persistence/src/main/resources/magalie.properties =================================================================== --- trunk/magalie-persistence/src/main/resources/magalie.properties 2013-06-21 16:11:19 UTC (rev 251) +++ trunk/magalie-persistence/src/main/resources/magalie.properties 2013-06-25 08:58:09 UTC (rev 252) @@ -28,7 +28,7 @@ hibernate.hbm2ddl.auto=update hibernate.show_sql=false hibernate.format_sql=true -hibernate.ejb.naming_strategy=org.nuiton.jpa.hibernate.OracleCompliantImprovedNamingStrategy +hibernate.ejb.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy hibernate.c3p0.min_size=3 hibernate.c3p0.max_size=5 Deleted: trunk/magalie-web/src/main/resources/magalie-production.properties =================================================================== --- trunk/magalie-web/src/main/resources/magalie-production.properties 2013-06-21 16:11:19 UTC (rev 251) +++ trunk/magalie-web/src/main/resources/magalie-production.properties 2013-06-25 08:58:09 UTC (rev 252) @@ -1,34 +0,0 @@ -### -# #%L -# MagaLiE :: UI -# $Id:$ -# $HeadURL:$ -# %% -# Copyright (C) 2013 CodeLutin -# %% -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero 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 Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# #L% -### - -hibernate.hbm2ddl.auto=validate -hibernate.show_sql=false -hibernate.format_sql=true -hibernate.ejb.naming_strategy=org.nuiton.jpa.hibernate.OracleCompliantImprovedNamingStrategy - -magalie.devMode=${devMode} - -hibernate.c3p0.min_size=3 -hibernate.c3p0.max_size=5 -hibernate.c3p0.timeout=1800 -hibernate.c3p0.max_statements=50