Author: tchemit Date: 2013-12-16 11:40:24 +0100 (Mon, 16 Dec 2013) New Revision: 907 Url: http://forge.codelutin.com/projects/echobase/repository/revisions/907 Log: add more stuff on persistence (for topia 3 migration) Added: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/data/CategoryDAOImpl.java trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/references/CellTypeImpl.java trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/references/DataMetadataImpl.java trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/references/SampleDataTypeImpl.java Modified: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/data/CellDAOImpl.java trunk/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/migration/workingDb/MigrationCallBackForVersion2_5.java Added: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/data/CategoryDAOImpl.java =================================================================== --- trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/data/CategoryDAOImpl.java (rev 0) +++ trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/data/CategoryDAOImpl.java 2013-12-16 10:40:24 UTC (rev 907) @@ -0,0 +1,51 @@ +package fr.ifremer.echobase.entities.data; + +/* + * #%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.EchoBaseTechnicalException; +import org.nuiton.topia.TopiaException; + +import java.util.List; + +public class CategoryDAOImpl<E extends Category> extends CategoryDAOAbstract<E> { + + public List<E> getCategoryUsingEchotype(Voyage voyage) throws TopiaException { + String hql = "SELECT DISTINCT c FROM VoyageImpl v, CategoryImpl c WHERE " + + "v = :voyage AND c.echotype in elements(v.echotype)"; + List<E> result = findAllByQuery(hql, "voyage", voyage); + return result; + } + + public long countCategoryUsingEchotype(Voyage voyage) { + String hql = "SELECT COUNT(DISTINCT c) FROM VoyageImpl v, CategoryImpl c WHERE " + + "v = :voyage AND c.echotype in elements(v.echotype)"; + try { + long result = countByQuery(hql, "voyage", voyage); + return result; + } catch (TopiaException e) { + throw new EchoBaseTechnicalException(e); + } + } + +} //CategoryDAOImpl<E extends Category> Property changes on: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/data/CategoryDAOImpl.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/data/CellDAOImpl.java =================================================================== --- trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/data/CellDAOImpl.java 2013-12-12 14:36:49 UTC (rev 906) +++ trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/data/CellDAOImpl.java 2013-12-16 10:40:24 UTC (rev 907) @@ -26,6 +26,7 @@ import com.google.common.collect.Lists; import fr.ifremer.echobase.entities.references.CellType; import fr.ifremer.echobase.entities.spatial.CellPoint; +import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaSQLQuery; import java.sql.Connection; @@ -51,19 +52,31 @@ return result; } -// public CellPoint getPoint(E cell) { -// -// TopiaSQLQuery<CellPoint> query = null; -// if (EchoBasePredicates.IS_ESDU_CELL.apply(cell)) { -// -// query = newLatLongSqlQuery(cell.getTopiaId(), null); -// } else if (EchoBasePredicates.IS_ELEMENTARY_CELL.apply(cell)) { -// query = newLatLongDepthSqlQuery(cell.getTopiaId(), null); -// } -// CellPoint result = query == null ? null : query.findSingleResult(context); -// return result; -// } + public long countVoyageOrphanCells(Voyage voyage) { + TopiaSQLQuery<Long> query = newCountVoyageOrphanCellsQuery(voyage); + Long result = query.findSingleResult(context); + return result; + } + public long countVoyageCellResults(Voyage voyage) { + TopiaSQLQuery<Long> query = newCountVoyageCellResultsQuery(voyage); + Long result = query.findSingleResult(context); + return result; + } + + public List<String> getVoyageCellIds() throws TopiaException { + TopiaSQLQuery<String> query = newVoyageCellIdsQuery(); + List<String> cellIds = query.findMultipleResult(context); + return cellIds; + } + + public List<String> getVoyageCellIds(Voyage voyage) throws TopiaException { + TopiaSQLQuery<String> query = newVoyageCellIdsQuery(voyage); + + List<String> cellIds = query.findMultipleResult(context); + return cellIds; + } + protected TopiaSQLQuery<CellPoint> newLatLongSqlQuery(final String voyageId, final String cellTypeId) { return new TopiaSQLQuery<CellPoint>() { @Override @@ -106,4 +119,100 @@ } }; } + + protected TopiaSQLQuery<Long> newCountVoyageOrphanCellsQuery(final Voyage voyage) { + return new TopiaSQLQuery<Long>() { + @Override + protected PreparedStatement prepareQuery(Connection connection) throws SQLException { + String hql = "SELECT count(c2.topiaid) FROM Transit ta, " + + " Transect te, " + + " DataAcquisition da, " + + " DataProcessing dp, " + + " Cell c, Cell c2 " + + "WHERE ta.voyage = ? " + + "AND ta.topiaId = te.transit " + + "AND te.topiaId = da.transect " + + "AND da.topiaId = dp.dataacquisition " + + "AND dp.topiaId = c.dataprocessing " + + "AND c.topiaId = c2.cell"; + PreparedStatement result = connection.prepareStatement(hql); + result.setString(1, voyage.getTopiaId()); + return result; + } + + @Override + protected Long prepareResult(ResultSet set) throws SQLException { + return set.getLong(1); + } + }; + } + + protected TopiaSQLQuery<Long> newCountVoyageCellResultsQuery(final Voyage voyage) { + return new TopiaSQLQuery<Long>() { + @Override + protected PreparedStatement prepareQuery(Connection connection) throws SQLException { + String hql = "SELECT count(c.topiaid) FROM Transit ta, " + + " Transect te, " + + " DataAcquisition da, " + + " DataProcessing dp, " + + " Cell c " + + "WHERE ta.voyage = ? " + + "AND ta.topiaId = te.transit " + + "AND te.topiaId = da.transect " + + "AND da.topiaId = dp.dataacquisition " + + "AND dp.topiaId = c.dataprocessing"; + PreparedStatement result = connection.prepareStatement(hql); + result.setString(1, voyage.getTopiaId()); + return result; + } + + @Override + protected Long prepareResult(ResultSet set) throws SQLException { + return set.getLong(1); + } + }; + } + + protected TopiaSQLQuery<String> newVoyageCellIdsQuery() { + return new TopiaSQLQuery<String>() { + @Override + protected PreparedStatement prepareQuery(Connection connection) throws SQLException { + String hql = "SELECT c.topiaid FROM Cell c " + + "WHERE c.cell IS NULL AND c.dataprocessing IS NULL AND c.voyage IS NULL"; + PreparedStatement result = connection.prepareStatement(hql); + return result; + } + + @Override + protected String prepareResult(ResultSet set) throws SQLException { + return set.getString(1); + } + }; + } + + protected TopiaSQLQuery<String> newVoyageCellIdsQuery(final Voyage voyage) { + return new TopiaSQLQuery<String>() { + @Override + protected PreparedStatement prepareQuery(Connection connection) throws SQLException { + String hql = "SELECT c.topiaid FROM Transit ta, " + + " Transect te, " + + " DataAcquisition da, " + + " DataProcessing dp, " + + " Cell c " + + "WHERE ta.voyage = ? " + + "AND ta.topiaId = te.transit " + + "AND te.topiaId = da.transect " + + "AND da.topiaId = dp.dataacquisition " + + "AND dp.topiaId = c.dataprocessing"; + PreparedStatement result = connection.prepareStatement(hql); + result.setString(1, voyage.getTopiaId()); + return result; + } + + @Override + protected String prepareResult(ResultSet set) throws SQLException { + return set.getString(1); + } + }; + } } Added: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/references/CellTypeImpl.java =================================================================== --- trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/references/CellTypeImpl.java (rev 0) +++ trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/references/CellTypeImpl.java 2013-12-16 10:40:24 UTC (rev 907) @@ -0,0 +1,39 @@ +package fr.ifremer.echobase.entities.references; + +/* + * #%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% + */ + +public class CellTypeImpl extends CellTypeAbstract { + + public static final String MAP = "Map"; + + public static final String REGION_SURF = "RegionSURF"; + + public static final String REGION_CLAS = "RegionCLAS"; + + public static final String ELEMENTARY = "Elementary"; + + public static final String ESDU = "Esdu"; + + private static final long serialVersionUID = 3631136258339910497L; +} //CellTypeImpl Property changes on: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/references/CellTypeImpl.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/references/DataMetadataImpl.java =================================================================== --- trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/references/DataMetadataImpl.java (rev 0) +++ trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/references/DataMetadataImpl.java 2013-12-16 10:40:24 UTC (rev 907) @@ -0,0 +1,46 @@ +package fr.ifremer.echobase.entities.references; + +/* + * #%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% + */ + +public class DataMetadataImpl extends DataMetadataAbstract { + + public static final String REGION_ENV_COORDINATES = "RegionEnvCoordinates"; + + public static final String SURFACE = "Surface"; + + public static final String GRID_CELL_LONGITUDE = "GridCellLongitude"; + + public static final String GRID_CELL_LATITUDE = "GridCellLatitude"; + + public static final String GRID_CELL_DEPTH = "GridCellDepth"; + + public static final String GRID_LONGITUDE_LAG = "GridLongitudeLag"; + + public static final String GRID_LATITUDE_LAG = "GridLatitudeLag"; + + public static final String GRID_DEPTH_LAG = "GridDepthLag"; + + private static final long serialVersionUID = 3487302769263981665L; + +} //DataMetadataImpl Property changes on: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/references/DataMetadataImpl.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/references/SampleDataTypeImpl.java =================================================================== --- trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/references/SampleDataTypeImpl.java (rev 0) +++ trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/references/SampleDataTypeImpl.java 2013-12-16 10:40:24 UTC (rev 907) @@ -0,0 +1,43 @@ +package fr.ifremer.echobase.entities.references; + +/* + * #%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% + */ + +public class SampleDataTypeImpl extends SampleDataTypeAbstract { + + public static final String MEAN_LENGTHCM = "MeanLengthcm"; + + public static final String MEAN_WEIGHTG = "MeanWeightg"; + + public static final String NO_PER_KG = "NoPerKg"; + + public static final String WEIGHT_AT_LENGTHKG = "WeightAtLengthkg"; + + public static final String L_TCM_1 = "LTcm1"; + + public static final String LTCM0_5 = "LTcm0.5"; + + public static final String NUMBER_AT_LENGTH = "NumberAtLength"; + + private static final long serialVersionUID = 3486460324380685111L; +} //SampleDataTypeImpl Property changes on: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/references/SampleDataTypeImpl.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: 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-12 14:36:49 UTC (rev 906) +++ trunk/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/migration/workingDb/MigrationCallBackForVersion2_5.java 2013-12-16 10:40:24 UTC (rev 907) @@ -12,12 +12,12 @@ * 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%