r921 - trunk/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/migration/workingDb
Author: tchemit Date: 2013-12-17 08:50:53 +0100 (Tue, 17 Dec 2013) New Revision: 921 Url: http://forge.codelutin.com/projects/echobase/repository/revisions/921 Log: remvoe old migration Removed: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/migration/workingDb/MigrationCallBackForVersion2_5.java Deleted: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/migration/workingDb/MigrationCallBackForVersion2_5.java =================================================================== --- trunk/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/migration/workingDb/MigrationCallBackForVersion2_5.java 2013-12-17 02:03:00 UTC (rev 920) +++ trunk/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/migration/workingDb/MigrationCallBackForVersion2_5.java 2013-12-17 07:50:53 UTC (rev 921) @@ -1,371 +0,0 @@ -package fr.ifremer.echobase.persistence.migration.workingDb; - -/* - * #%L - * EchoBase :: Domain - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 - 2013 Ifremer, 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% - */ - -import fr.ifremer.echobase.entities.TopiaEchoBasePersistenceContext; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.util.Version; - -import java.util.List; - -/** - * Migrate workgin db to version {@code 2.5}. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 2.5 - */ -public class MigrationCallBackForVersion2_5 extends MigrationCallBackForVersion { - - @Override - public Version getVersion() { - return new Version("2.5"); - } - - @Override - protected void prepareMigrationScript(TopiaContext tx, - List<String> queries, - boolean showSql, - boolean showProgression) throws TopiaException { - - boolean spatialAware; - - TopiaEchoBasePersistenceContext persistenceContext = - new TopiaEchoBasePersistenceContext(tx); - try { - - spatialAware = persistenceContext.isSpatialAware(); - } finally { - persistenceContext.rollbackTransaction(); - } - - if (spatialAware) { - - // add spatial view (http://forge.codelutin.com/issues/3672) - addPostgisView(queries); - - // fix http://forge.codelutin.com/issues/3856 - fixechobase_fill_cell_spatial_tableFunction(queries); - - // fix http://forge.codelutin.com/issues/3973 - fixOperationNameNotFilled(queries); - } - } - - private void fixOperationNameNotFilled(List<String> queries) { - - // fix http://forge.codelutin.com/issues/3973 - queries.add("update echobase_operation_spatial set operationname = (select op.id from operation op where op.topiaid = operationid);"); - } - - private void fixechobase_fill_cell_spatial_tableFunction(List<String> queries) { - - queries.add("CREATE OR REPLACE FUNCTION echobase_fill_cell_spatial_row(cell_id VARCHAR)\n" + - " RETURNS VOID AS $$\n" + - " DECLARE cell_type VARCHAR;\n" + - "BEGIN\n" + - "\n" + - " cell_type = echobase_get_cell_type(cell_id);\n" + - "\n" + - " RAISE DEBUG 'Treat spatial cell % [type %] ...', cell_id, cell_type;\n" + - " CASE cell_type\n" + - " WHEN 'ESDU'\n" + - " THEN\n" + - " EXECUTE echobase_fill_esdu_cell_spatial_table(cell_id);\n" + - " WHEN 'ELEMENTARY'\n" + - " THEN\n" + - " EXECUTE echobase_fill_elementary_cell_spatial_table(cell_id);\n" + - " WHEN 'REGION'\n" + - " THEN\n" + - " EXECUTE echobase_fill_region_cell_spatial_table(cell_id);\n" + - " WHEN 'MAP'\n" + - " THEN\n" + - " EXECUTE echobase_fill_map_cell_spatial_table(cell_id);\n" + - " ELSE\n" + - " RAISE LOG 'Can not deal with celltype % (cell %)', cell_type, cell_id;\n" + - " END CASE;\n" + - "END\n" + - "$$\n" + - "LANGUAGE plpgsql;"); - - queries.add("CREATE OR REPLACE FUNCTION echobase_fill_cell_spatial_table()\n" + - " RETURNS VOID AS $$\n" + - "DECLARE\n" + - " cellRow RECORD;\n" + - "BEGIN\n" + - " FOR cellRow IN SELECT\n" + - " *\n" + - " FROM echobase_cell_spatial_temp LOOP\n" + - "\n" + - " PERFORM echobase_fill_cell_spatial_row(cellRow.cellid);\n" + - "\n" + - " END LOOP;\n" + - "\n" + - " DELETE FROM echobase_cell_spatial_temp;\n" + - "\n" + - "END\n" + - "$$\n" + - "LANGUAGE plpgsql;"); - } - - private void addPostgisView(List<String> queries) { - - // add cell data view - queries.add("DROP VIEW IF EXISTS echobase_cell_spatial_data CASCADE;"); - queries.add("CREATE OR REPLACE VIEW echobase_cell_spatial_data AS\n" + - "SELECT\n" + - " s.*,\n" + - " m.topiaId as metaDataId,\n" + - " m.name as metaDataName,\n" + - " d.datavalue as dataValue,\n" + - " d.topiaid as dataId\n" + - "FROM\n" + - " echobase_cell_spatial s,\n" + - " data d,\n" + - " datametadata m\n" + - "WHERE\n" + - " s.cellid = d.cell AND\n" + - " d.datametadata = m.topiaid;"); - - // add cell result view - queries.add("DROP VIEW IF EXISTS echobase_cell_spatial_result CASCADE;"); - queries.add("CREATE OR REPLACE VIEW echobase_cell_spatial_result AS\n" + - "SELECT\n" + - " s.*,\n" + - " m.topiaId as metaDataId,\n" + - " m.name as metaDataName,\n" + - " r.resultvalue as resultValue,\n" + - " r.topiaid as resultId\n" + - "FROM\n" + - " echobase_cell_spatial s,\n" + - " result r,\n" + - " datametadata m\n" + - "WHERE\n" + - " s.cellid = r.cell AND\n" + - " r.datametadata = m.topiaid;"); - - // add operation data view - queries.add("DROP VIEW IF EXISTS TotalSampleEngrEnc CASCADE;"); - queries.add("CREATE OR REPLACE VIEW TotalSampleEngrEnc AS\n" + - "\n" + - "SELECT \n" + - " echobase_operation_spatial.voyageid, \n" + - " operation.id AS operation_id, \n" + - " echobase_operation_spatial.coordinate, \n" + - " sampletype.name AS sampletype_name, \n" + - " sample.sampleweight, \n" + - " sizecategory.name AS sizecategory_name, \n" + - " species.baracoudacode, \n" + - " sample.topiaid\n" + - "FROM\n" + - " public.echobase_operation_spatial, \n" + - " public.operation, \n" + - " public.sample, \n" + - " public.speciescategory, \n" + - " public.sizecategory, \n" + - " public.species, \n" + - " public.sampletype\n" + - "WHERE \n" + - " echobase_operation_spatial.operationid = operation.topiaid AND\n" + - " operation.topiaid = sample.operation AND\n" + - " sample.speciescategory = speciescategory.topiaid AND\n" + - " sample.sampletype = sampletype.topiaid AND\n" + - " speciescategory.sizecategory = sizecategory.topiaid AND\n" + - " speciescategory.species = species.topiaid AND\n" + - " sampletype.name = 'Total' AND\n" + - " species.baracoudacode='ENGR-ENC';\n"); - - queries.add("DROP VIEW IF EXISTS TotalSampleSardPil CASCADE;"); - queries.add("CREATE OR REPLACE VIEW TotalSampleSardPil AS\n" + - "\n" + - "SELECT \n" + - " echobase_operation_spatial.voyageid, \n" + - " operation.id AS operation_id, \n" + - " echobase_operation_spatial.coordinate, \n" + - " sampletype.name AS sampletype_name, \n" + - " sample.sampleweight, \n" + - " sizecategory.name AS sizecategory_name, \n" + - " species.baracoudacode, \n" + - " sample.topiaid\n" + - "FROM \n" + - " public.echobase_operation_spatial, \n" + - " public.operation, \n" + - " public.sample, \n" + - " public.speciescategory, \n" + - " public.sizecategory, \n" + - " public.species, \n" + - " public.sampletype\n" + - "WHERE \n" + - " echobase_operation_spatial.operationid = operation.topiaid AND\n" + - " operation.topiaid = sample.operation AND\n" + - " sample.speciescategory = speciescategory.topiaid AND\n" + - " sample.sampletype = sampletype.topiaid AND\n" + - " speciescategory.sizecategory = sizecategory.topiaid AND\n" + - " speciescategory.species = species.topiaid AND\n" + - " sampletype.name = 'Total' AND\n" + - " species.baracoudacode='SARD-PIL';"); - - queries.add("DROP VIEW IF EXISTS TotalSampleTracTru CASCADE;"); - queries.add("CREATE OR REPLACE VIEW TotalSampleTracTru AS\n" + - "\n" + - "SELECT \n" + - " echobase_operation_spatial.voyageid, \n" + - " operation.id AS operation_id, \n" + - " echobase_operation_spatial.coordinate, \n" + - " sampletype.name AS sampletype_name, \n" + - " sample.sampleweight, \n" + - " sizecategory.name AS sizecategory_name, \n" + - " species.baracoudacode, \n" + - " sample.topiaid\n" + - "FROM \n" + - " public.echobase_operation_spatial, \n" + - " public.operation, \n" + - " public.sample, \n" + - " public.speciescategory, \n" + - " public.sizecategory, \n" + - " public.species, \n" + - " public.sampletype\n" + - "WHERE \n" + - " echobase_operation_spatial.operationid = operation.topiaid AND\n" + - " operation.topiaid = sample.operation AND\n" + - " sample.speciescategory = speciescategory.topiaid AND\n" + - " sample.sampletype = sampletype.topiaid AND\n" + - " speciescategory.sizecategory = sizecategory.topiaid AND\n" + - " speciescategory.species = species.topiaid AND\n" + - " sampletype.name = 'Total' AND\n" + - " species.baracoudacode='TRAC-TRU';"); - - queries.add("DROP VIEW IF EXISTS TotalSampleSpraSpr CASCADE;"); - queries.add("CREATE OR REPLACE VIEW TotalSampleSpraSpr AS\n" + - "\n" + - "SELECT \n" + - " echobase_operation_spatial.voyageid, \n" + - " operation.id AS operation_id, \n" + - " echobase_operation_spatial.coordinate, \n" + - " sampletype.name AS sampletype_name, \n" + - " sample.sampleweight, \n" + - " sizecategory.name AS sizecategory_name, \n" + - " species.baracoudacode, \n" + - " sample.topiaid\n" + - "FROM \n" + - " public.echobase_operation_spatial, \n" + - " public.operation, \n" + - " public.sample, \n" + - " public.speciescategory, \n" + - " public.sizecategory, \n" + - " public.species, \n" + - " public.sampletype\n" + - "WHERE \n" + - " echobase_operation_spatial.operationid = operation.topiaid AND\n" + - " operation.topiaid = sample.operation AND\n" + - " sample.speciescategory = speciescategory.topiaid AND\n" + - " sample.sampletype = sampletype.topiaid AND\n" + - " speciescategory.sizecategory = sizecategory.topiaid AND\n" + - " speciescategory.species = species.topiaid AND\n" + - " sampletype.name = 'Total' AND\n" + - " species.baracoudacode='SPRA-SPR';"); - - queries.add("DROP VIEW IF EXISTS TotalSampleScomSco CASCADE;"); - queries.add("CREATE OR REPLACE VIEW TotalSampleScomSco AS\n" + - "\n" + - "SELECT \n" + - " echobase_operation_spatial.voyageid, \n" + - " operation.id AS operation_id, \n" + - " echobase_operation_spatial.coordinate, \n" + - " sampletype.name AS sampletype_name, \n" + - " sample.sampleweight, \n" + - " sizecategory.name AS sizecategory_name, \n" + - " species.baracoudacode, \n" + - " sample.topiaid\n" + - "FROM \n" + - " public.echobase_operation_spatial, \n" + - " public.operation, \n" + - " public.sample, \n" + - " public.speciescategory, \n" + - " public.sizecategory, \n" + - " public.species, \n" + - " public.sampletype\n" + - "WHERE \n" + - " echobase_operation_spatial.operationid = operation.topiaid AND\n" + - " operation.topiaid = sample.operation AND\n" + - " sample.speciescategory = speciescategory.topiaid AND\n" + - " sample.sampletype = sampletype.topiaid AND\n" + - " speciescategory.sizecategory = sizecategory.topiaid AND\n" + - " speciescategory.species = species.topiaid AND\n" + - " sampletype.name = 'Total' AND\n" + - " species.baracoudacode='SCOM-SCO';"); - - queries.add("DROP VIEW IF EXISTS TotalSampleMicrPou CASCADE;"); - queries.add("CREATE OR REPLACE VIEW TotalSampleMicrPou AS\n" + - "\n" + - "SELECT \n" + - " echobase_operation_spatial.voyageid, \n" + - " operation.id AS operation_id, \n" + - " echobase_operation_spatial.coordinate, \n" + - " sampletype.name AS sampletype_name, \n" + - " sample.sampleweight, \n" + - " sizecategory.name AS sizecategory_name, \n" + - " species.baracoudacode, \n" + - " sample.topiaid\n" + - "FROM \n" + - " public.echobase_operation_spatial, \n" + - " public.operation, \n" + - " public.sample, \n" + - " public.speciescategory, \n" + - " public.sizecategory, \n" + - " public.species, \n" + - " public.sampletype\n" + - "WHERE \n" + - " echobase_operation_spatial.operationid = operation.topiaid AND\n" + - " operation.topiaid = sample.operation AND\n" + - " sample.speciescategory = speciescategory.topiaid AND\n" + - " sample.sampletype = sampletype.topiaid AND\n" + - " speciescategory.sizecategory = sizecategory.topiaid AND\n" + - " speciescategory.species = species.topiaid AND\n" + - " sampletype.name = 'Total' AND\n" + - " species.baracoudacode='MICR-POU';"); - - queries.add("DROP VIEW IF EXISTS TotalCatchSpOpWide CASCADE;"); - queries.add("CREATE OR REPLACE VIEW TotalCatchSpOpWide AS\n" + - "\n" + - "SELECT\n" + - " echobase_operation_spatial.voyagename,\n" + - " echobase_operation_spatial.operationname,\n" + - " echobase_operation_spatial.coordinate,\n" + - " (Select SUM(totalsampleengrenc.sampleweight) From totalsampleengrenc Where totalsampleengrenc.operation_id = echobase_operation_spatial.operationname) as TotalCatchENGRENC,\n" + - " (Select SUM(totalsamplesardpil.sampleweight) From totalsamplesardpil Where totalsamplesardpil.operation_id = echobase_operation_spatial.operationname) as TotalCatchSARDPIL,\n" + - " (Select SUM(totalsamplespraspr.sampleweight) From totalsamplespraspr Where totalsamplespraspr.operation_id = echobase_operation_spatial.operationname) as TotalCatchSPRASPR,\n" + - " (Select SUM(totalsamplemicrpou.sampleweight) From totalsamplemicrpou Where totalsamplemicrpou.operation_id = echobase_operation_spatial.operationname) as TotalCatchMICRPOU,\n" + - " (Select SUM(totalsamplescomsco.sampleweight) From totalsamplescomsco Where totalsamplescomsco.operation_id = echobase_operation_spatial.operationname) as TotalCatchSCOMSCO,\n" + - " (Select SUM(totalsampletractru.sampleweight) From totalsampletractru Where totalsampletractru.operation_id = echobase_operation_spatial.operationname) as TotalCatchTRACTRU,\n" + - " echobase_operation_spatial.operationid\n" + - "From echobase_operation_spatial;"); - - queries.add("DROP VIEW IF EXISTS cellmapview CASCADE;"); - queries.add("CREATE OR REPLACE VIEW cellmapview AS \n" + - " SELECT echobase_cell_spatial.voyagename, echobase_cell_spatial.coordinate, echobase_cell_spatial.shape, datametadata.name, result.resultvalue, species.baracoudacode, echobase_cell_spatial.cellname, result.topiaid AS resultid\n" + - " FROM echobase_cell_spatial, result, datametadata, category, speciescategory, species\n" + - " WHERE echobase_cell_spatial.cellid::text = result.cell::text AND result.datametadata::text = datametadata.topiaid::text AND result.category::text = category.topiaid::text AND category.speciescategory::text = speciescategory.topiaid::text AND speciescategory.species::text = species.topiaid::text AND echobase_cell_spatial.celltypename::text = 'Map cell'::text;"); - } -}
participants (1)
-
tchemit@users.forge.codelutin.com