Commit b2bd4950 authored by LAVENIER's avatar LAVENIER
Browse files

Merge branch 'develop' into feature/imagine

parents 9bfd1b85 92ed6f32
Subproject commit 3b6e149ac009099f8234c3825cf8bb3bacb01f97 Subproject commit 7a81f76fac53e140fcd83394212b153bc9de24a0
...@@ -125,10 +125,10 @@ public class Daos extends net.sumaris.core.dao.technical.Daos { ...@@ -125,10 +125,10 @@ public class Daos extends net.sumaris.core.dao.technical.Daos {
} }
public static void commitIfHsqldb(DataSource dataSource) { public static void commitIfHsqldbOrPgsql(DataSource dataSource) {
Connection conn = DataSourceUtils.getConnection(dataSource); Connection conn = DataSourceUtils.getConnection(dataSource);
try { try {
if (net.sumaris.core.extraction.dao.technical.Daos.isHsqlDatabase(conn) && DataSourceUtils.isConnectionTransactional(conn, dataSource)) { if ((net.sumaris.core.extraction.dao.technical.Daos.isHsqlDatabase(conn) || net.sumaris.core.extraction.dao.technical.Daos.isPostgresqlDatabase(conn)) && DataSourceUtils.isConnectionTransactional(conn, dataSource)) {
try { try {
conn.commit(); conn.commit();
} catch (SQLException e) { } catch (SQLException e) {
...@@ -146,7 +146,7 @@ public class Daos extends net.sumaris.core.dao.technical.Daos { ...@@ -146,7 +146,7 @@ public class Daos extends net.sumaris.core.dao.technical.Daos {
* @param columnNamesMapping * @param columnNamesMapping
* @return * @return
*/ */
public static String sqlReplaceColumnNames(String sqlQuery, Map<String, String> columnNamesMapping) { public static String sqlReplaceColumnNames(String sqlQuery, Map<String, String> columnNamesMapping, Boolean lowercase) {
if (MapUtils.isEmpty(columnNamesMapping)) return sqlQuery; // Skip if (MapUtils.isEmpty(columnNamesMapping)) return sqlQuery; // Skip
sqlQuery = sqlQuery.toUpperCase(); sqlQuery = sqlQuery.toUpperCase();
...@@ -161,6 +161,20 @@ public class Daos extends net.sumaris.core.dao.technical.Daos { ...@@ -161,6 +161,20 @@ public class Daos extends net.sumaris.core.dao.technical.Daos {
"$1" + targetColumnName + "$2"); "$1" + targetColumnName + "$2");
} }
// for postgresql, lowercase queries are needed.
if (lowercase){
sqlQuery = sqlQuery.toLowerCase();
}
return sqlQuery; return sqlQuery;
} }
/**
* Do column names replacement, but escape sql keyword (e.g. 'DATE' replacement will keep TO_DATE(...) unchanged)
* @param sqlQuery
* @param columnNamesMapping
* @return
*/
public static String sqlReplaceColumnNames(String sqlQuery, Map<String, String> columnNamesMapping) {
return sqlReplaceColumnNames(sqlQuery, columnNamesMapping, false);
}
} }
...@@ -41,12 +41,9 @@ import net.sumaris.core.service.referential.ReferentialService; ...@@ -41,12 +41,9 @@ import net.sumaris.core.service.referential.ReferentialService;
import net.sumaris.core.util.StringUtils; import net.sumaris.core.util.StringUtils;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.query.internal.NativeQueryImpl;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.dao.DataRetrievalFailureException; import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.orm.hibernate5.SessionHolder;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.persistence.Query; import javax.persistence.Query;
...@@ -184,7 +181,7 @@ public abstract class ExtractionBaseDaoImpl extends HibernateDaoSupport { ...@@ -184,7 +181,7 @@ public abstract class ExtractionBaseDaoImpl extends HibernateDaoSupport {
xmlQuery.setXSLFileName(XSL_ORACLE_FILENAME); xmlQuery.setXSLFileName(XSL_ORACLE_FILENAME);
} }
else if (this.databaseType == DatabaseType.postgresql){ else if (this.databaseType == DatabaseType.postgresql){
xmlQuery.setLowercaseAliases(true); xmlQuery.setLowercase(true);
} }
return xmlQuery; return xmlQuery;
} }
......
...@@ -49,18 +49,18 @@ public class XMLQuery extends HSQLDBSingleXMLQuery { ...@@ -49,18 +49,18 @@ public class XMLQuery extends HSQLDBSingleXMLQuery {
private String xslFileName; private String xslFileName;
private boolean lowercaseAliases; private boolean lowercase;
public XMLQuery() { public XMLQuery() {
super(); super();
xslFileName = super.getXSLFileName(); xslFileName = super.getXSLFileName();
this.lowercaseAliases = false; this.lowercase = false;
} }
public XMLQuery(boolean lowercaseAliases) { public XMLQuery(boolean lowercase) {
super(); super();
xslFileName = super.getXSLFileName(); xslFileName = super.getXSLFileName();
this.lowercaseAliases = lowercaseAliases; this.lowercase = lowercase;
} }
@Override @Override
...@@ -74,12 +74,12 @@ public class XMLQuery extends HSQLDBSingleXMLQuery { ...@@ -74,12 +74,12 @@ public class XMLQuery extends HSQLDBSingleXMLQuery {
// let default values here for HSQLDB // let default values here for HSQLDB
public boolean isLowercaseAliases() { public boolean isLowercase() {
return lowercaseAliases; return lowercase;
} }
public void setLowercaseAliases(boolean lowercaseAliases) { public void setLowercase(boolean lowercase) {
this.lowercaseAliases = lowercaseAliases; this.lowercase = lowercase;
} }
/** /**
...@@ -155,7 +155,7 @@ public class XMLQuery extends HSQLDBSingleXMLQuery { ...@@ -155,7 +155,7 @@ public class XMLQuery extends HSQLDBSingleXMLQuery {
public String getSQLQueryAsString(){ public String getSQLQueryAsString(){
String query = super.getSQLQueryAsString(); String query = super.getSQLQueryAsString();
if (this.lowercaseAliases){ if (this.lowercase){
query = query.toLowerCase(); query = query.toLowerCase();
} }
return query; return query;
......
...@@ -196,7 +196,7 @@ public class SumarisTableMetadatas { ...@@ -196,7 +196,7 @@ public class SumarisTableMetadatas {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("SELECT COUNT(*) FROM (") sb.append("SELECT COUNT(*) FROM (")
.append(getSelectGroupByQuery(tableName, columnNames, whereClause, groupByColumnNames, null, null)) .append(getSelectGroupByQuery(tableName, columnNames, whereClause, groupByColumnNames, null, null))
.append(")"); .append(") \"select_group\"");
return sb.toString(); return sb.toString();
} }
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
package net.sumaris.core.extraction.dao.trip.free; package net.sumaris.core.extraction.dao.trip.free;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import net.sumaris.core.dao.technical.DatabaseType;
import net.sumaris.core.extraction.dao.technical.Daos; import net.sumaris.core.extraction.dao.technical.Daos;
import net.sumaris.core.extraction.dao.technical.XMLQuery; import net.sumaris.core.extraction.dao.technical.XMLQuery;
import net.sumaris.core.extraction.dao.trip.rdb.ExtractionRdbTripDaoImpl; import net.sumaris.core.extraction.dao.trip.rdb.ExtractionRdbTripDaoImpl;
...@@ -99,6 +100,10 @@ public class ExtractionFree1TripDaoImpl<C extends ExtractionRdbTripContextVO, F ...@@ -99,6 +100,10 @@ public class ExtractionFree1TripDaoImpl<C extends ExtractionRdbTripContextVO, F
// WIDTH_GEAR Largeur cumulée (drague), missing in SUMARIS // WIDTH_GEAR Largeur cumulée (drague), missing in SUMARIS
// SEINE_LENGTH Longueur de la bolinche ou senne missing in SUMARIS // SEINE_LENGTH Longueur de la bolinche ou senne missing in SUMARIS
xmlQuery.setGroup("hsqldb", this.databaseType == DatabaseType.hsqldb);
xmlQuery.setGroup("pgsql", this.databaseType == DatabaseType.postgresql);
xmlQuery.setGroup("oracle", this.databaseType == DatabaseType.oracle);
return xmlQuery; return xmlQuery;
} }
......
...@@ -24,6 +24,7 @@ package net.sumaris.core.extraction.dao.trip.free2; ...@@ -24,6 +24,7 @@ package net.sumaris.core.extraction.dao.trip.free2;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.sumaris.core.dao.technical.DatabaseType;
import net.sumaris.core.dao.technical.schema.SumarisDatabaseMetadata; import net.sumaris.core.dao.technical.schema.SumarisDatabaseMetadata;
import net.sumaris.core.extraction.dao.technical.Daos; import net.sumaris.core.extraction.dao.technical.Daos;
import net.sumaris.core.extraction.dao.technical.XMLQuery; import net.sumaris.core.extraction.dao.technical.XMLQuery;
...@@ -195,6 +196,10 @@ public class ExtractionFree2TripDaoImpl<C extends ExtractionFree2ContextVO, F ex ...@@ -195,6 +196,10 @@ public class ExtractionFree2TripDaoImpl<C extends ExtractionFree2ContextVO, F ex
xmlQuery.setGroup("vesselFilter", CollectionUtils.isNotEmpty(context.getVesselIds())); xmlQuery.setGroup("vesselFilter", CollectionUtils.isNotEmpty(context.getVesselIds()));
xmlQuery.bind("vesselIds", Daos.getSqlInNumbers(context.getVesselIds())); xmlQuery.bind("vesselIds", Daos.getSqlInNumbers(context.getVesselIds()));
xmlQuery.setGroup("oracle", this.databaseType == DatabaseType.oracle);
xmlQuery.setGroup("hsqldb", this.databaseType == DatabaseType.hsqldb);
xmlQuery.setGroup("pgsql", this.databaseType == DatabaseType.postgresql);
return xmlQuery; return xmlQuery;
} }
......
...@@ -375,6 +375,7 @@ public class AggregationRdbTripDaoImpl< ...@@ -375,6 +375,7 @@ public class AggregationRdbTripDaoImpl<
xmlQuery.setGroup("gearType", rawStationTable.hasColumn(AggRdbSpecification.COLUMN_GEAR_TYPE)); xmlQuery.setGroup("gearType", rawStationTable.hasColumn(AggRdbSpecification.COLUMN_GEAR_TYPE));
xmlQuery.setGroup("hsqldb", this.databaseType == DatabaseType.hsqldb); xmlQuery.setGroup("hsqldb", this.databaseType == DatabaseType.hsqldb);
xmlQuery.setGroup("pgsql", this.databaseType == DatabaseType.postgresql);
xmlQuery.setGroup("oracle", this.databaseType == DatabaseType.oracle); xmlQuery.setGroup("oracle", this.databaseType == DatabaseType.oracle);
return xmlQuery; return xmlQuery;
...@@ -532,6 +533,7 @@ public class AggregationRdbTripDaoImpl< ...@@ -532,6 +533,7 @@ public class AggregationRdbTripDaoImpl<
// Enable/Disable group, on DBMS // Enable/Disable group, on DBMS
xmlQuery.setGroup("hsqldb", this.databaseType == DatabaseType.hsqldb); xmlQuery.setGroup("hsqldb", this.databaseType == DatabaseType.hsqldb);
xmlQuery.setGroup("pgsql", this.databaseType == DatabaseType.postgresql);
xmlQuery.setGroup("oracle", this.databaseType == DatabaseType.oracle); xmlQuery.setGroup("oracle", this.databaseType == DatabaseType.oracle);
// Enable/Disable group, on optional columns // Enable/Disable group, on optional columns
...@@ -708,9 +710,11 @@ public class AggregationRdbTripDaoImpl< ...@@ -708,9 +710,11 @@ public class AggregationRdbTripDaoImpl<
// Enable/Disable group, on DBMS // Enable/Disable group, on DBMS
xmlQuery.setGroup("hasId", hasId); xmlQuery.setGroup("hasId", hasId);
xmlQuery.setGroup("hsqldb-hasId", hasId && this.databaseType == DatabaseType.hsqldb); xmlQuery.setGroup("hsqldb-hasId", hasId && this.databaseType == DatabaseType.hsqldb);
xmlQuery.setGroup("pgsql-hasId", hasId && this.databaseType == DatabaseType.postgresql);
xmlQuery.setGroup("oracle-hasId", hasId && this.databaseType == DatabaseType.oracle); xmlQuery.setGroup("oracle-hasId", hasId && this.databaseType == DatabaseType.oracle);
xmlQuery.setGroup("hasSampleIds", hasSampleIds); xmlQuery.setGroup("hasSampleIds", hasSampleIds);
xmlQuery.setGroup("hsqldb-hasSampleIds", hasSampleIds && this.databaseType == DatabaseType.hsqldb); xmlQuery.setGroup("hsqldb-hasSampleIds", hasSampleIds && this.databaseType == DatabaseType.hsqldb);
xmlQuery.setGroup("pgsql-hasSampleIds", hasSampleIds && this.databaseType == DatabaseType.postgresql);
xmlQuery.setGroup("oracle-hasSampleIds", hasSampleIds && this.databaseType == DatabaseType.oracle); xmlQuery.setGroup("oracle-hasSampleIds", hasSampleIds && this.databaseType == DatabaseType.oracle);
return xmlQuery; return xmlQuery;
...@@ -789,7 +793,7 @@ public class AggregationRdbTripDaoImpl< ...@@ -789,7 +793,7 @@ public class AggregationRdbTripDaoImpl<
String sqlQuery = xmlQuery.getSQLQueryAsString(); String sqlQuery = xmlQuery.getSQLQueryAsString();
// Do column nanes replacement (e.g. see FREE extraction) // Do column nanes replacement (e.g. see FREE extraction)
sqlQuery = Daos.sqlReplaceColumnNames(sqlQuery, context.getColumnNamesMapping()); sqlQuery = Daos.sqlReplaceColumnNames(sqlQuery, context.getColumnNamesMapping(), xmlQuery.isLowercase());
return queryUpdate(sqlQuery); return queryUpdate(sqlQuery);
} }
...@@ -868,7 +872,8 @@ public class AggregationRdbTripDaoImpl< ...@@ -868,7 +872,8 @@ public class AggregationRdbTripDaoImpl<
c -> query( c -> query(
Daos.sqlReplaceColumnNames( Daos.sqlReplaceColumnNames(
String.format("SELECT DISTINCT %s FROM %s where %s IS NOT NULL", c, tableName, c), String.format("SELECT DISTINCT %s FROM %s where %s IS NOT NULL", c, tableName, c),
context.getColumnNamesMapping()), context.getColumnNamesMapping(),
xmlQuery.isLowercase()),
Object.class) Object.class)
.stream() .stream()
.map(String::valueOf) .map(String::valueOf)
......
...@@ -299,6 +299,10 @@ public class ExtractionRdbTripDaoImpl<C extends ExtractionRdbTripContextVO, F ex ...@@ -299,6 +299,10 @@ public class ExtractionRdbTripDaoImpl<C extends ExtractionRdbTripContextVO, F ex
xmlQuery.setGroup("vesselFilter", CollectionUtils.isNotEmpty(context.getVesselIds())); xmlQuery.setGroup("vesselFilter", CollectionUtils.isNotEmpty(context.getVesselIds()));
xmlQuery.bind("vesselIds", Daos.getSqlInNumbers(context.getVesselIds())); xmlQuery.bind("vesselIds", Daos.getSqlInNumbers(context.getVesselIds()));
xmlQuery.setGroup("oracle", this.databaseType == DatabaseType.oracle);
xmlQuery.setGroup("hsqldb", this.databaseType == DatabaseType.hsqldb);
xmlQuery.setGroup("pgsql", this.databaseType == DatabaseType.postgresql);
return xmlQuery; return xmlQuery;
} }
...@@ -424,6 +428,7 @@ public class ExtractionRdbTripDaoImpl<C extends ExtractionRdbTripContextVO, F ex ...@@ -424,6 +428,7 @@ public class ExtractionRdbTripDaoImpl<C extends ExtractionRdbTripContextVO, F ex
xmlQuery.bind("speciesListTableName", context.getSpeciesListTableName()); xmlQuery.bind("speciesListTableName", context.getSpeciesListTableName());
xmlQuery.setGroup("oracle", this.databaseType == DatabaseType.oracle); xmlQuery.setGroup("oracle", this.databaseType == DatabaseType.oracle);
xmlQuery.setGroup("pgsql", this.databaseType == DatabaseType.postgresql);
xmlQuery.setGroup("hsqldb", this.databaseType == DatabaseType.hsqldb); xmlQuery.setGroup("hsqldb", this.databaseType == DatabaseType.hsqldb);
return xmlQuery; return xmlQuery;
......
...@@ -198,6 +198,7 @@ public class AggregationSurvivalTestDaoImpl<C extends AggregationSurvivalTestCon ...@@ -198,6 +198,7 @@ public class AggregationSurvivalTestDaoImpl<C extends AggregationSurvivalTestCon
xmlQuery.setGroup("gearType", stationTable.hasColumn(AggRdbSpecification.COLUMN_GEAR_TYPE)); xmlQuery.setGroup("gearType", stationTable.hasColumn(AggRdbSpecification.COLUMN_GEAR_TYPE));
xmlQuery.setGroup("hsqldb", this.databaseType == DatabaseType.hsqldb); xmlQuery.setGroup("hsqldb", this.databaseType == DatabaseType.hsqldb);
xmlQuery.setGroup("pgsql", this.databaseType == DatabaseType.postgresql);
xmlQuery.setGroup("oracle", this.databaseType == DatabaseType.oracle); xmlQuery.setGroup("oracle", this.databaseType == DatabaseType.oracle);
return xmlQuery; return xmlQuery;
...@@ -264,6 +265,7 @@ public class AggregationSurvivalTestDaoImpl<C extends AggregationSurvivalTestCon ...@@ -264,6 +265,7 @@ public class AggregationSurvivalTestDaoImpl<C extends AggregationSurvivalTestCon
xmlQuery.setGroup("gearType", stationTable.hasColumn(AggRdbSpecification.COLUMN_GEAR_TYPE)); xmlQuery.setGroup("gearType", stationTable.hasColumn(AggRdbSpecification.COLUMN_GEAR_TYPE));
xmlQuery.setGroup("hsqldb", this.databaseType == DatabaseType.hsqldb); xmlQuery.setGroup("hsqldb", this.databaseType == DatabaseType.hsqldb);
xmlQuery.setGroup("pgsql", this.databaseType == DatabaseType.postgresql);
xmlQuery.setGroup("oracle", this.databaseType == DatabaseType.oracle); xmlQuery.setGroup("oracle", this.databaseType == DatabaseType.oracle);
return xmlQuery; return xmlQuery;
......
...@@ -24,6 +24,7 @@ package net.sumaris.core.extraction.dao.trip.survivalTest; ...@@ -24,6 +24,7 @@ package net.sumaris.core.extraction.dao.trip.survivalTest;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.sumaris.core.dao.technical.DatabaseType;
import net.sumaris.core.extraction.dao.technical.XMLQuery; import net.sumaris.core.extraction.dao.technical.XMLQuery;
import net.sumaris.core.extraction.dao.trip.rdb.ExtractionRdbTripDaoImpl; import net.sumaris.core.extraction.dao.trip.rdb.ExtractionRdbTripDaoImpl;
import net.sumaris.core.extraction.format.LiveFormatEnum; import net.sumaris.core.extraction.format.LiveFormatEnum;
...@@ -133,6 +134,10 @@ public class ExtractionSurvivalTestDaoImpl<C extends ExtractionSurvivalTestConte ...@@ -133,6 +134,10 @@ public class ExtractionSurvivalTestDaoImpl<C extends ExtractionSurvivalTestConte
xmlQuery.bind("sortingDateTimePmfmId", String.valueOf(PmfmEnum.SORTING_START_DATE_TIME.getId())); xmlQuery.bind("sortingDateTimePmfmId", String.valueOf(PmfmEnum.SORTING_START_DATE_TIME.getId()));
xmlQuery.bind("sortingEndDateTimePmfmId", String.valueOf(PmfmEnum.SORTING_END_DATE_TIME.getId())); xmlQuery.bind("sortingEndDateTimePmfmId", String.valueOf(PmfmEnum.SORTING_END_DATE_TIME.getId()));
xmlQuery.setGroup("hsqldb", this.databaseType == DatabaseType.hsqldb);
xmlQuery.setGroup("pgsql", this.databaseType == DatabaseType.postgresql);
xmlQuery.setGroup("oracle", this.databaseType == DatabaseType.oracle);
return xmlQuery; return xmlQuery;
} }
...@@ -180,6 +185,10 @@ public class ExtractionSurvivalTestDaoImpl<C extends ExtractionSurvivalTestConte ...@@ -180,6 +185,10 @@ public class ExtractionSurvivalTestDaoImpl<C extends ExtractionSurvivalTestConte
xmlQuery.bind("stationTableName", context.getStationTableName()); xmlQuery.bind("stationTableName", context.getStationTableName());
xmlQuery.bind("survivalTestTableName", context.getSurvivalTestTableName()); xmlQuery.bind("survivalTestTableName", context.getSurvivalTestTableName());
xmlQuery.setGroup("oracle", this.databaseType == DatabaseType.oracle);
xmlQuery.setGroup("hsqldb", this.databaseType == DatabaseType.hsqldb);
xmlQuery.setGroup("pgsql", this.databaseType == DatabaseType.postgresql);
// aggregate insertion // aggregate insertion
execute(xmlQuery); execute(xmlQuery);
long count = countFrom(context.getSurvivalTestTableName()); long count = countFrom(context.getSurvivalTestTableName());
...@@ -210,6 +219,10 @@ public class ExtractionSurvivalTestDaoImpl<C extends ExtractionSurvivalTestConte ...@@ -210,6 +219,10 @@ public class ExtractionSurvivalTestDaoImpl<C extends ExtractionSurvivalTestConte
xmlQuery.bind("stationTableName", context.getStationTableName()); xmlQuery.bind("stationTableName", context.getStationTableName());
xmlQuery.bind("releaseTableName", context.getReleaseTableName()); xmlQuery.bind("releaseTableName", context.getReleaseTableName());
xmlQuery.setGroup("oracle", this.databaseType == DatabaseType.oracle);
xmlQuery.setGroup("hsqldb", this.databaseType == DatabaseType.hsqldb);
xmlQuery.setGroup("pgsql", this.databaseType == DatabaseType.postgresql);
// aggregate insertion // aggregate insertion
execute(xmlQuery); execute(xmlQuery);
long count = countFrom(context.getReleaseTableName()); long count = countFrom(context.getReleaseTableName());
......
...@@ -280,6 +280,7 @@ public class AggregationServiceImpl implements AggregationService { ...@@ -280,6 +280,7 @@ public class AggregationServiceImpl implements AggregationService {
int offset, int size, String sort, SortDirection direction) { int offset, int size, String sort, SortDirection direction) {
// Execute the aggregation // Execute the aggregation
AggregationContextVO context = aggregate(type, filter, strata); AggregationContextVO context = aggregate(type, filter, strata);
Daos.commitIfHsqldbOrPgsql(dataSource);
// Prepare the read filter // Prepare the read filter
ExtractionFilterVO readFilter = null; ExtractionFilterVO readFilter = null;
...@@ -301,7 +302,7 @@ public class AggregationServiceImpl implements AggregationService { ...@@ -301,7 +302,7 @@ public class AggregationServiceImpl implements AggregationService {
public File executeAndDump(AggregationTypeVO type, @Nullable ExtractionFilterVO filter, @Nullable AggregationStrataVO strata) { public File executeAndDump(AggregationTypeVO type, @Nullable ExtractionFilterVO filter, @Nullable AggregationStrataVO strata) {
// Execute the aggregation // Execute the aggregation
AggregationContextVO context = aggregate(type, filter, strata); AggregationContextVO context = aggregate(type, filter, strata);
Daos.commitIfHsqldb(dataSource); Daos.commitIfHsqldbOrPgsql(dataSource);
try { try {
// Dump to files // Dump to files
...@@ -309,7 +310,7 @@ public class AggregationServiceImpl implements AggregationService { ...@@ -309,7 +310,7 @@ public class AggregationServiceImpl implements AggregationService {
} }
finally { finally {
// Delete aggregation tables, after dump // Delete aggregation tables, after dump
clean(context, true); clean(context);
} }
} }
......
...@@ -551,7 +551,7 @@ public class ExtractionServiceImpl implements ExtractionService { ...@@ -551,7 +551,7 @@ public class ExtractionServiceImpl implements ExtractionService {
@Override @Override
public CompletableFuture<Boolean> asyncClean(ExtractionContextVO context) { public CompletableFuture<Boolean> asyncClean(ExtractionContextVO context) {
try { try {
clean(context); clean(context, true);
return CompletableFuture.completedFuture(Boolean.TRUE); return CompletableFuture.completedFuture(Boolean.TRUE);
} catch (Exception e) { } catch (Exception e) {
log.warn(String.format("Error while cleaning extraction #%s: %s", context.getId(), e.getMessage()), e); log.warn(String.format("Error while cleaning extraction #%s: %s", context.getId(), e.getMessage()), e);
...@@ -622,7 +622,7 @@ public class ExtractionServiceImpl implements ExtractionService { ...@@ -622,7 +622,7 @@ public class ExtractionServiceImpl implements ExtractionService {
// Execute live extraction to temp tables // Execute live extraction to temp tables
ExtractionContextVO context = executeLiveDao(format, filter); ExtractionContextVO context = executeLiveDao(format, filter);
Daos.commitIfHsqldb(dataSource); Daos.commitIfHsqldbOrPgsql(dataSource);
try { try {
log.info(String.format("Dumping tables of extraction #%s to files...", context.getId())); log.info(String.format("Dumping tables of extraction #%s to files...", context.getId()));
...@@ -631,7 +631,7 @@ public class ExtractionServiceImpl implements ExtractionService { ...@@ -631,7 +631,7 @@ public class ExtractionServiceImpl implements ExtractionService {
return dumpTablesToFile(context, null /*no filter, because already applied*/); return dumpTablesToFile(context, null /*no filter, because already applied*/);
} }
finally { finally {
clean(context, true); clean(context);
} }
} }
......
...@@ -25,10 +25,9 @@ ...@@ -25,10 +25,9 @@
<query type="create" temp="false" table="&amp;landingTableName"> <query type="create" temp="false" table="&amp;landingTableName">
<!-- PK --> <!-- PK -->
<select alias="RECORD_TYPE" type="text">'CL'</select> <select alias="RECORD_TYPE" type="text">UPPER('CL')</select>
<select alias="VESSEL_FLAG_COUNTRY" type="text">VESSEL_FLAG_COUNTRY</select> <select alias="VESSEL_FLAG_COUNTRY" type="text">VESSEL_FLAG_COUNTRY</select>
<select alias="LANDING_COUNTRY" type="text">LANDING_COUNTRY</select> <select alias="LANDING_COUNTRY" type="text">LANDING_COUNTRY</select>
<!-- <select alias="SPECIES" type="text">MIN(DECODE(TG.LABEL, NULL, CL.SPECIES, TG.LABEL || ' - ' || TG.NAME))</select>-->
<select alias="SPECIES" type="text">MIN(CASE TG.LABEL WHEN NULL THEN CL.SPECIES ELSE TG.LABEL || ' - ' || TG.NAME END)</select> <select alias="SPECIES" type="text">MIN(CASE TG.LABEL WHEN NULL THEN CL.SPECIES ELSE TG.LABEL || ' - ' || TG.NAME END)</select>
<select alias="LANDING_CATEGORY" type="text">LANDING_CATEGORY</select> <select alias="LANDING_CATEGORY" type="text">LANDING_CATEGORY</select>
<select alias="COMMERCIAL_SIZE_CATEGORY_SCALE" type="text">COMMERCIAL_SIZE_CATEGORY_SCALE</select> <select alias="COMMERCIAL_SIZE_CATEGORY_SCALE" type="text">COMMERCIAL_SIZE_CATEGORY_SCALE</select>
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
<query type="create" temp="false" table="&amp;speciesLengthTableName"> <query type="create" temp="false" table="&amp;speciesLengthTableName">
<select alias="RECORD_TYPE" type="text">'HL'</select> <select alias="RECORD_TYPE" type="text">UPPER('HL')</select>
<!-- PK inherited from HH --> <!-- PK inherited from HH -->
<select alias="SAMPLING_TYPE" type="text">SL.SAMPLING_TYPE</select> <select alias="SAMPLING_TYPE" type="text">SL.SAMPLING_TYPE</select>
...@@ -63,13 +63,13 @@ ...@@ -63,13 +63,13 @@