Author: chatellier Date: 2011-03-17 10:27:19 +0000 (Thu, 17 Mar 2011) New Revision: 3164 Log: Use new topia migration service Added: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/datastore/migration/DatabaseMigrationClass.java isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/datastore/migration/MigrationV0V32.java isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/datastore/migration/MigrationV32V33.java Removed: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/datastore/migration/SwingMigrationCallbackHandler.java isis-fish/branches/3.3.1/src/main/resources/oldmappings/ Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/datastore/migration/package-info.java Added: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/datastore/migration/DatabaseMigrationClass.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/datastore/migration/DatabaseMigrationClass.java (rev 0) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/datastore/migration/DatabaseMigrationClass.java 2011-03-17 10:27:19 UTC (rev 3164) @@ -0,0 +1,113 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package fr.ifremer.isisfish.datastore.migration; + +import static org.nuiton.i18n.I18n._; + +import java.util.List; + +import javax.swing.JOptionPane; + +import org.nuiton.topia.migration.TopiaMigrationCallbackByClass; +import org.nuiton.util.Version; + +import fr.ifremer.isisfish.IsisFishDAOHelper; + +/** + * Migration callback by class for all isis database migration. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class DatabaseMigrationClass extends TopiaMigrationCallbackByClass { + + protected static final Version VERSION_32 = new Version("3.2"); + protected static final Version VERSION_33 = new Version("3.3"); + + public DatabaseMigrationClass() { + super(new MigrationResolver()); + } + + protected static class MigrationResolver implements MigrationCallBackForVersionResolver { + /* + * @see org.nuiton.topia.migration.TopiaMigrationCallbackByClass.MigrationCallBackForVersionResolver#getCallBack(org.nuiton.util.Version) + */ + @Override + public Class<? extends MigrationCallBackForVersion> getCallBack(Version version) { + Class<? extends MigrationCallBackForVersion> result = null; + + if (version.equals(VERSION_32)) { + result = MigrationV0V32.class; + } + else if (version.equals(VERSION_33)) { + result = MigrationV32V33.class; + } + return result; + } + + } + + /* + * @see org.nuiton.topia.migration.AbstractTopiaMigrationCallback#getAvailableVersions() + */ + @Override + public Version[] getAvailableVersions() { + Version[] result = new Version[] { VERSION_32, VERSION_33 }; + return result; + } + + /* + * @see org.nuiton.topia.migration.AbstractTopiaMigrationCallback#getApplicationVersion() + */ + @Override + public Version getApplicationVersion() { + Version appVersion = new Version(IsisFishDAOHelper.getModelVersion()); + return appVersion; + } + + /* + * @see org.nuiton.topia.migration.AbstractTopiaMigrationCallback#askUser(org.nuiton.util.Version, java.util.List) + */ + @Override + public boolean askUser(Version dbVersion, List<Version> versions) { + boolean result = false; + + int answer = JOptionPane.showConfirmDialog( + null, _("isisfish.misc.databasemigration.question", dbVersion, versions.get(versions.size() - 1)), + _("isisfish.misc.databasemigration.title"), + JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); + + if (answer == JOptionPane.YES_OPTION) { + result = true; + } + + return result; + } + +} Property changes on: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/datastore/migration/DatabaseMigrationClass.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/datastore/migration/MigrationV0V32.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/datastore/migration/MigrationV0V32.java (rev 0) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/datastore/migration/MigrationV0V32.java 2011-03-17 10:27:19 UTC (rev 3164) @@ -0,0 +1,70 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package fr.ifremer.isisfish.datastore.migration; + +import java.util.List; + +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaContextImplementor; +import org.nuiton.topia.migration.TopiaMigrationCallbackByClass; +import org.nuiton.topia.migration.TopiaMigrationCallbackByClass.MigrationCallBackForVersion; +import org.nuiton.util.Version; + +/** + * Migration between version 0 and 3.2. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class MigrationV0V32 extends MigrationCallBackForVersion { + + /** + * Constructor. + * + * @param version version + * @param callBack callback + */ + public MigrationV0V32(Version version, TopiaMigrationCallbackByClass callBack) { + super(version, callBack); + } + + /* + * @see org.nuiton.topia.migration.TopiaMigrationCallbackByClass.MigrationCallBackForVersion#prepareMigrationScript(org.nuiton.topia.framework.TopiaContextImplementor, java.util.List, boolean, boolean) + */ + @Override + protected void prepareMigrationScript(TopiaContextImplementor tx, + List<String> queries, boolean showSql, boolean showProgression) + throws TopiaException { + queries.add("alter table SETOFVESSELS add column TECHNICALEFFICIENCYEQUATION VARCHAR(255);"); + queries.add("alter table STRATEGY add column INACTIVITYEQUATIONUSED BIT default false;"); + queries.add("alter table STRATEGY add column INACTIVITYEQUATION VARCHAR(255);"); + queries.add("alter table STRATEGYMONTHINFO alter NUMBEROFTRIPS double;"); + queries.add("alter table STRATEGYMONTHINFO alter MININACTIVITYDAYS double;"); + } +} Property changes on: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/datastore/migration/MigrationV0V32.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/datastore/migration/MigrationV32V33.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/datastore/migration/MigrationV32V33.java (rev 0) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/datastore/migration/MigrationV32V33.java 2011-03-17 10:27:19 UTC (rev 3164) @@ -0,0 +1,80 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package fr.ifremer.isisfish.datastore.migration; + +import java.util.List; + +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaContextImplementor; +import org.nuiton.topia.migration.TopiaMigrationCallbackByClass; +import org.nuiton.topia.migration.TopiaMigrationCallbackByClass.MigrationCallBackForVersion; +import org.nuiton.util.Version; + +/** + * Migration between version 3.2 and 3.3. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class MigrationV32V33 extends MigrationCallBackForVersion { + + /** + * Constructor. + * + * @param version version + * @param callback callback + */ + public MigrationV32V33(Version version, TopiaMigrationCallbackByClass callback) { + super(version, callback); + } + + /* + * @see org.nuiton.topia.migration.TopiaMigrationCallbackByClass.MigrationCallBackForVersion#prepareMigrationScript(org.nuiton.topia.framework.TopiaContextImplementor, java.util.List, boolean, boolean) + */ + @Override + protected void prepareMigrationScript(TopiaContextImplementor tx, + List<String> queries, boolean showSql, boolean showProgression) + throws TopiaException { + // replace in equation + queries.add("update EQUATION set content = replace(content, 'org.codelutin.', 'org.nuiton.');"); + // replace in matrix semantics + queries.add("update POPULATION set recruitmentDistribution_semantics = replace(recruitmentDistribution_semantics, 'org.codelutin.', 'org.nuiton.') where recruitmentDistribution_semantics IS NOT null;"); + queries.add("update POPULATION set mappingZoneReproZoneRecru_semantics = replace(mappingZoneReproZoneRecru_semantics, 'org.codelutin.', 'org.nuiton.') where mappingZoneReproZoneRecru_semantics IS NOT null;"); + queries.add("update POPULATION set capturability_semantics = replace(capturability_semantics, 'org.codelutin.', 'org.nuiton.') where capturability_semantics IS NOT null;"); + queries.add("update POPULATIONSEASONINFO set reproductionDistribution_semantics = replace(reproductionDistribution_semantics, 'org.codelutin.', 'org.nuiton.') where reproductionDistribution_semantics IS NOT null;"); + queries.add("update POPULATIONSEASONINFO set lengthChangeMatrix_semantics = replace(lengthChangeMatrix_semantics, 'org.codelutin.', 'org.nuiton.') where lengthChangeMatrix_semantics IS NOT null;"); + queries.add("update POPULATIONSEASONINFO set migrationMatrix_semantics = replace(migrationMatrix_semantics, 'org.codelutin.', 'org.nuiton.') where migrationMatrix_semantics IS NOT null;"); + queries.add("update POPULATIONSEASONINFO set emigrationMatrix_semantics = replace(emigrationMatrix_semantics, 'org.codelutin.', 'org.nuiton.') where emigrationMatrix_semantics IS NOT null;"); + queries.add("update POPULATIONSEASONINFO set immigrationMatrix_semantics = replace(immigrationMatrix_semantics, 'org.codelutin.', 'org.nuiton.') where immigrationMatrix_semantics IS NOT null;"); + queries.add("update RESULT set matrix_semantics = replace(matrix_semantics, 'org.codelutin.', 'org.nuiton.') where matrix_semantics IS NOT null;"); + queries.add("update STRATEGYMONTHINFO set proportionMetier_semantics = replace(proportionMetier_semantics, 'org.codelutin.', 'org.nuiton.') where proportionMetier_semantics IS NOT null;"); + // add .shp default extension + queries.add("update FISHERYREGION set MAPFILES = regexp_replace(MAPFILES, '(,|$)', '.shp$1') where MAPFILES IS NOT null AND LENGTH(TRIM(MAPFILES)) > 0;"); + } +} Property changes on: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/datastore/migration/MigrationV32V33.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Deleted: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/datastore/migration/SwingMigrationCallbackHandler.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/datastore/migration/SwingMigrationCallbackHandler.java 2011-03-16 17:00:05 UTC (rev 3163) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/datastore/migration/SwingMigrationCallbackHandler.java 2011-03-17 10:27:19 UTC (rev 3164) @@ -1,179 +0,0 @@ -/* - * #%L - * IsisFish - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2007 - 2010 Ifremer, CodeLutin - * %% - * 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 2 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-2.0.html>. - * #L% - */ - -package fr.ifremer.isisfish.datastore.migration; - -import static org.nuiton.i18n.I18n._; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.SQLException; - -import javax.swing.JOptionPane; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.migration.DatabaseManager; -import org.nuiton.topia.migration.callback.MigrationCallbackHandler; -import org.nuiton.util.VersionNumberUtil; - -/** - * MigrationCallbackHandler. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class SwingMigrationCallbackHandler implements MigrationCallbackHandler { - - /** to use log facility, just put in your code: log.info("..."); */ - static private Log log = LogFactory - .getLog(SwingMigrationCallbackHandler.class); - - /* - * @see org.nuiton.topia.migration.callback.MigrationCallbackHandler#doMigration(java.lang.String, java.lang.String) - */ - @Override - public MigrationChoice doMigration(DatabaseManager dbManager, - String dbVersion, String applicationVersion) { - - int answer = JOptionPane.showConfirmDialog( - null, _("isisfish.misc.databasemigration.question", dbVersion, applicationVersion), - _("isisfish.misc.databasemigration.title"), - JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); - - MigrationChoice result = (answer == JOptionPane.YES_OPTION) ? MigrationChoice.MIGRATION - : MigrationChoice.NO_MIGRATION; - - if (result == MigrationChoice.MIGRATION) { - result = migrate(dbManager, dbVersion, applicationVersion); - } - return result; - } - - /** - * Perform real migration. - * - * @param dbManager database manager - * @param dbVersion database version - * @param applicationVersion application version - * @return {@code MigrationChoice.CUSTOM_MIGRATION} if success, {@code MigrationChoice.NO_MIGRATION} otherwise. - */ - protected MigrationChoice migrate(DatabaseManager dbManager, - String dbVersion, String applicationVersion) { - // migration manuel sans l'aide de topia-service - // tant que c pas fait on dit non - MigrationChoice result = MigrationChoice.NO_MIGRATION; - // ouverture d'une connexion direct JDBC sur la base - try { - Connection conn = dbManager.getConnection(); - try { - conn.setAutoCommit(false); - if (VersionNumberUtil.smallerThan(dbVersion, "3.2")) { - // on fait une migration vers 3.2 - migrateTo3_2(conn); - } - - // do same thing for other version - if (VersionNumberUtil.smallerThan(dbVersion, "3.3")) { - // on fait une migration vers 3.2 - migrateTo3_3(conn); - } - - // commit des modifs - conn.commit(); - // la migration a reussi, on dit que c fait - result = MigrationChoice.CUSTOM_MIGRATION; - } catch (Exception eee) { - // en cas d'erreur - log.error("Migration impossible de la base", eee); - // rollback du travail en cours - conn.rollback(); - } finally { - // close database connexion - conn.close(); - } - } catch (Exception eee) { - log.error("Error lors de la tentative de migration", eee); - } - - return result; - } - - protected void migrateTo3_2(Connection conn) throws SQLException { - if (log.isInfoEnabled()) { - log.info("Migrate to version 3.2"); - } - - //alteration du schema - // nouvelles equations dans les tables - - String[] sqls = new String[] { - "alter table SETOFVESSELS add column TECHNICALEFFICIENCYEQUATION VARCHAR(255);", - "alter table STRATEGY add column INACTIVITYEQUATIONUSED BIT default false;", - "alter table STRATEGY add column INACTIVITYEQUATION VARCHAR(255);", - "alter table STRATEGYMONTHINFO alter NUMBEROFTRIPS double;", - "alter table STRATEGYMONTHINFO alter MININACTIVITYDAYS double;" }; - for (String sql : sqls) { - log.info("try " + sql); - PreparedStatement sta = conn.prepareStatement(sql); - sta.executeUpdate(); - log.info("done " + sql); - } - } - - protected void migrateTo3_3(Connection conn) throws SQLException { - if (log.isInfoEnabled()) { - log.info("Migrate to version 3.3"); - } - - String[] sqls = new String[] { - // replace in equation - "update EQUATION set content = replace(content, 'org.codelutin.', 'org.nuiton.');", - // replace in matrix semantics - "update POPULATION set recruitmentDistribution_semantics = replace(recruitmentDistribution_semantics, 'org.codelutin.', 'org.nuiton.') where recruitmentDistribution_semantics IS NOT null;", - "update POPULATION set mappingZoneReproZoneRecru_semantics = replace(mappingZoneReproZoneRecru_semantics, 'org.codelutin.', 'org.nuiton.') where mappingZoneReproZoneRecru_semantics IS NOT null;", - "update POPULATION set capturability_semantics = replace(capturability_semantics, 'org.codelutin.', 'org.nuiton.') where capturability_semantics IS NOT null;", - "update POPULATIONSEASONINFO set reproductionDistribution_semantics = replace(reproductionDistribution_semantics, 'org.codelutin.', 'org.nuiton.') where reproductionDistribution_semantics IS NOT null;", - "update POPULATIONSEASONINFO set lengthChangeMatrix_semantics = replace(lengthChangeMatrix_semantics, 'org.codelutin.', 'org.nuiton.') where lengthChangeMatrix_semantics IS NOT null;", - "update POPULATIONSEASONINFO set migrationMatrix_semantics = replace(migrationMatrix_semantics, 'org.codelutin.', 'org.nuiton.') where migrationMatrix_semantics IS NOT null;", - "update POPULATIONSEASONINFO set emigrationMatrix_semantics = replace(emigrationMatrix_semantics, 'org.codelutin.', 'org.nuiton.') where emigrationMatrix_semantics IS NOT null;", - "update POPULATIONSEASONINFO set immigrationMatrix_semantics = replace(immigrationMatrix_semantics, 'org.codelutin.', 'org.nuiton.') where immigrationMatrix_semantics IS NOT null;", - "update RESULT set matrix_semantics = replace(matrix_semantics, 'org.codelutin.', 'org.nuiton.') where matrix_semantics IS NOT null;", - "update STRATEGYMONTHINFO set proportionMetier_semantics = replace(proportionMetier_semantics, 'org.codelutin.', 'org.nuiton.') where proportionMetier_semantics IS NOT null;", - // add .shp default extension - "update FISHERYREGION set MAPFILES = regexp_replace(MAPFILES, '(,|$)', '.shp$1') where MAPFILES IS NOT null AND LENGTH(TRIM(MAPFILES)) > 0;" - }; - for (String sql : sqls) { - log.info("try " + sql); - PreparedStatement sta = conn.prepareStatement(sql); - sta.executeUpdate(); - log.info("done " + sql); - } - } - -} Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/datastore/migration/package-info.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/datastore/migration/package-info.java 2011-03-16 17:00:05 UTC (rev 3163) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/datastore/migration/package-info.java 2011-03-17 10:27:19 UTC (rev 3164) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 1999 - 2010 Ifremer, CodeLutin + * Copyright (C) 1999 - 2011 Ifremer, 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 @@ -23,7 +23,7 @@ * #L% */ /** - * IsisFish V2 import. + * Database storage migration. */ package fr.ifremer.isisfish.datastore.migration;
participants (1)
-
chatellierï¼ users.labs.libre-entreprise.org