r890 - in trunk: echobase-domain/src/main/java/fr/ifremer/echobase/persistence/migration/workingDb echobase-domain/src/main/resources/META-INF/services echobase-domain/src/main/xmi echobase-services/src/main/resources
Author: tchemit Date: 2013-11-10 09:22:52 +0100 (Sun, 10 Nov 2013) New Revision: 890 Url: http://forge.codelutin.com/projects/echobase/repository/revisions/890 Log: refs #3672: Ajout de vues spatiales Added: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/migration/workingDb/MigrationCallBackForVersion2_5.java Modified: trunk/echobase-domain/src/main/resources/META-INF/services/fr.ifremer.echobase.persistence.migration.workingDb.MigrationCallBackForVersion trunk/echobase-domain/src/main/xmi/echobase.properties trunk/echobase-services/src/main/resources/postgis-structure.sql Added: 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 (rev 0) +++ trunk/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/migration/workingDb/MigrationCallBackForVersion2_5.java 2013-11-10 08:22:52 UTC (rev 890) @@ -0,0 +1,107 @@ +package fr.ifremer.echobase.persistence.migration.workingDb; + +/* + * #%L + * EchoBase :: Domain + * $Id$ + * $HeadURL: http://svn.forge.codelutin.com/svn/echobase/trunk/echobase-domain/src/main/j... $ + * %% + * 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 { + + // add spatial view (http://forge.codelutin.com/issues/3672) + updatePostgis(tx, queries); + } + + protected void updatePostgis(TopiaContext tx, List<String> queries) { + TopiaEchoBasePersistenceContext persistenceContext = + new TopiaEchoBasePersistenceContext(tx); + boolean spatialAware = + persistenceContext.isSpatialAware(); + + try { + if (spatialAware) { + + // add cell data view + queries.add("DROP VIEW IF EXISTS echobase_cell_spatial_data;"); + 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;"); + 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 echobase_operation_spatial_data;"); + //TODO Add spatial table + } + } finally { + persistenceContext.rollbackTransaction(); + } + } +} Property changes on: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/migration/workingDb/MigrationCallBackForVersion2_5.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/echobase-domain/src/main/resources/META-INF/services/fr.ifremer.echobase.persistence.migration.workingDb.MigrationCallBackForVersion =================================================================== --- trunk/echobase-domain/src/main/resources/META-INF/services/fr.ifremer.echobase.persistence.migration.workingDb.MigrationCallBackForVersion 2013-11-10 08:20:40 UTC (rev 889) +++ trunk/echobase-domain/src/main/resources/META-INF/services/fr.ifremer.echobase.persistence.migration.workingDb.MigrationCallBackForVersion 2013-11-10 08:22:52 UTC (rev 890) @@ -1 +1,2 @@ -fr.ifremer.echobase.persistence.migration.workingDb.MigrationCallBackForVersion2_2 \ No newline at end of file +fr.ifremer.echobase.persistence.migration.workingDb.MigrationCallBackForVersion2_2 +fr.ifremer.echobase.persistence.migration.workingDb.MigrationCallBackForVersion2_5 \ No newline at end of file Modified: trunk/echobase-domain/src/main/xmi/echobase.properties =================================================================== --- trunk/echobase-domain/src/main/xmi/echobase.properties 2013-11-10 08:20:40 UTC (rev 889) +++ trunk/echobase-domain/src/main/xmi/echobase.properties 2013-11-10 08:22:52 UTC (rev 890) @@ -25,7 +25,7 @@ model.tagValue.generateOperatorForDAOHelper=true model.tagValue.generateStandaloneEnumForDAOHelper=true model.tagValue.constantPrefix=PROPERTY_ -model.tagValue.version=2.2 +model.tagValue.version=2.5 model.tagValue.noPCS=true model.tagValue.doNotGenerateBooleanGetMethods=true model.tagValue.indexForeignKeys=true Modified: trunk/echobase-services/src/main/resources/postgis-structure.sql =================================================================== --- trunk/echobase-services/src/main/resources/postgis-structure.sql 2013-11-10 08:20:40 UTC (rev 889) +++ trunk/echobase-services/src/main/resources/postgis-structure.sql 2013-11-10 08:22:52 UTC (rev 890) @@ -60,6 +60,40 @@ CREATE INDEX echobase_cell_spatial_coordinate3D_gix ON echobase_cell_spatial USING GIST (coordinate3d); CREATE INDEX echobase_cell_spatial_shape_gix ON echobase_cell_spatial USING GIST (shape); +-- ajout de vues + +DROP VIEW IF EXISTS echobase_spatial_cell_result; +CREATE OR REPLACE VIEW echobase_spatial_cell_result AS +SELECT + s.*, + m.topiaId as metaDataId, + m.name as metaDataName, + r.resultvalue as resultValue, + r.topiaid as resultId +FROM + echobase_cell_spatial s, + result r, + datametadata m +WHERE + s.cellid = r.cell AND + r.datametadata = m.topiaid; + +DROP VIEW IF EXISTS echobase_spatial_cell_data; +CREATE OR REPLACE VIEW echobase_spatial_cell_data AS +SELECT + s.*, + m.topiaId as metaDataId, + m.name as metaDataName, + d.datavalue as dataValue, + d.topiaid as dataId +FROM + echobase_cell_spatial s, + data d, + datametadata m +WHERE + s.cellid = d.cell AND + d.datametadata = m.topiaid; + -- pour stoquer les traitements spatiaux a effectuer DROP TABLE IF EXISTS echobase_cell_spatial_temp; CREATE TABLE echobase_cell_spatial_temp ( @@ -862,6 +896,24 @@ CREATE INDEX echobase_operation_spatial_coordinate_gix ON echobase_operation_spatial USING GIST (coordinate); +-- ajout de vues + +DROP VIEW IF EXISTS echobase_spatial_operation_data; + +--CREATE OR REPLACE VIEW echobase_spatial_operation_data AS +--SELECT +-- echobase_cell_spatial.*, +-- datametadata.name, +-- data.dataValue +-- data.topiaid as dataId +--FROM +-- echobase_cell_spatial, +-- data, +-- datametadata +--WHERE +-- echobase_cell_spatial.cellid = data.cell AND +-- data.datametadata = datametadata.topiaid; + -- pour stoquer les traitements spatiaux a effectuer DROP TABLE IF EXISTS echobase_operation_spatial_temp; CREATE TABLE echobase_operation_spatial_temp (
participants (1)
-
tchemit@users.forge.codelutin.com