Author: nrannou Date: 2009-08-18 16:15:45 +0200 (Tue, 18 Aug 2009) New Revision: 2733 Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/migration/PollenMigrationCallbackHandler.java Log: migration Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/migration/PollenMigrationCallbackHandler.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/migration/PollenMigrationCallbackHandler.java 2009-08-18 12:26:50 UTC (rev 2732) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/migration/PollenMigrationCallbackHandler.java 2009-08-18 14:15:45 UTC (rev 2733) @@ -19,11 +19,8 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; -import java.util.Properties; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.business.utils.ContextUtil; import org.nuiton.topia.migration.DatabaseManager; import org.nuiton.topia.migration.callback.MigrationCallbackHandler; import org.nuiton.util.VersionUtil; @@ -59,7 +56,7 @@ conn.setAutoCommit(false); if (VersionUtil.valueOf(dbVersion).before( VersionUtil.valueOf("1.1"))) { - migrateTo1_1_test(conn); + migrateTo1_1(conn); } conn.commit(); result = MigrationChoice.CUSTOM_MIGRATION; @@ -75,17 +72,16 @@ return result; } - /** Migration de la version de test (0 to 1.1) */ - private void migrateTo1_1_test(Connection conn) throws SQLException { - log.info("Migrate to version 1_1_test"); + /** Migration de la version 0 à 1.1 */ + private void migrateTo1_1(Connection conn) throws SQLException { + log.info("Migrate to version 1_1"); String[] sqls = null; - // Récupération du dialect Hibernate - Properties conf = ContextUtil.getInstance().getConf(); - String dialect = conf.getProperty("hibernate.dialect"); + // Récupération du nom de la base de données + String product = conn.getMetaData().getDatabaseProductName(); // Script de migration - if ("org.hibernate.dialect.PostgreSQLDialect".equals(dialect)) { + if ("PostgreSQL".equals(product)) { sqls = new String[] { "alter table useraccount rename langage to language;", "alter table pollaccount add accountid varchar;", @@ -95,11 +91,11 @@ "alter table vote add anonymous boolean default false;", "alter table preventrule add active boolean default true;", "alter table preventrule add onetime boolean default false;", }; - } else if ("org.hibernate.dialect.H2Dialect".equals(dialect)) { + } else if ("H2".equals(product)) { sqls = new String[] { "alter table useraccount alter column langage rename to language;", "alter table pollaccount add accountid varchar;", - "update pollaccount set accountid=call hash('sha256', topiaid, 1000);", + "update pollaccount set accountid=hash('sha256', stringtoutf8(topiaid), 1000);", "alter table persontolist drop column hasvoted;", "alter table persontolist add hasvoted boolean default false;", "alter table vote add anonymous boolean default false;", @@ -108,8 +104,8 @@ } else { if (log.isErrorEnabled()) { log - .error("Migration non prise en charge pour ce type de dialect : " - + dialect); + .error("Migration non prise en charge pour ce type de base : " + + product); } }