branch feature/6714 updated (04a00a9 -> 9469344)
This is an automated email from the git hooks/post-receive script. New change to branch feature/6714 in repository tutti. See http://git.codelutin.com/tutti.git from 04a00a9 creation de la tache de modification des taxon dans les batchs (refs #6714) new 33559fb mise à jour des taxons référents dans les batchs (refs #6714) new 9469344 ajout de logs (fixes #6714) The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 94693440c70cac7f24872285297bbe26b65d3f5c Author: Kevin Morin <morin@codelutin.com> Date: Thu Dec 17 17:11:10 2015 +0100 ajout de logs (fixes #6714) commit 33559fb5b802883ca6ea1af7f53ddfd922a78e89 Author: Kevin Morin <morin@codelutin.com> Date: Thu Dec 17 16:46:18 2015 +0100 mise à jour des taxons référents dans les batchs (refs #6714) Summary of changes: .../referential/synchro/ReferentialUpdateTask.java | 5 +- ...aceReferenceTaxonReferentialUpdateTaskImpl.java | 67 ++++++++++---------- .../TuttiReferentialSynchroServiceImpl.java | 74 ++++++++++++++++++---- 3 files changed, 98 insertions(+), 48 deletions(-) -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/6714 in repository tutti. See http://git.codelutin.com/tutti.git commit 33559fb5b802883ca6ea1af7f53ddfd922a78e89 Author: Kevin Morin <morin@codelutin.com> Date: Thu Dec 17 16:46:18 2015 +0100 mise à jour des taxons référents dans les batchs (refs #6714) --- .../referential/synchro/ReferentialUpdateTask.java | 5 +- ...aceReferenceTaxonReferentialUpdateTaskImpl.java | 56 +++++++--------- .../TuttiReferentialSynchroServiceImpl.java | 74 ++++++++++++++++++---- 3 files changed, 87 insertions(+), 48 deletions(-) diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/synchro/ReferentialUpdateTask.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/synchro/ReferentialUpdateTask.java index f7f7696..3e8049f 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/synchro/ReferentialUpdateTask.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/synchro/ReferentialUpdateTask.java @@ -1,8 +1,8 @@ package fr.ifremer.tutti.persistence.service.referential.synchro; import fr.ifremer.adagio.core.service.technical.synchro.ReferentialSynchroDatabaseMetadata; -import fr.ifremer.adagio.core.service.technical.synchro.ReferentialSynchroTableTool; +import java.sql.Connection; import java.sql.SQLException; import java.sql.Timestamp; @@ -22,7 +22,6 @@ public interface ReferentialUpdateTask { * @return the set of pks to remove * @throws SQLException */ - void update(ReferentialSynchroDatabaseMetadata dbMetas, - ReferentialSynchroTableTool localDao, + void update(Connection localConnection, Timestamp lastUpdate) throws SQLException; } diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/synchro/ReplaceReferenceTaxonReferentialUpdateTaskImpl.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/synchro/ReplaceReferenceTaxonReferentialUpdateTaskImpl.java index 0b59032..43bcfbd 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/synchro/ReplaceReferenceTaxonReferentialUpdateTaskImpl.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/synchro/ReplaceReferenceTaxonReferentialUpdateTaskImpl.java @@ -1,18 +1,9 @@ package fr.ifremer.tutti.persistence.service.referential.synchro; -import fr.ifremer.adagio.core.service.technical.synchro.ReferentialSynchroDatabaseMetadata; -import fr.ifremer.adagio.core.service.technical.synchro.ReferentialSynchroTableTool; -import fr.ifremer.tutti.persistence.entities.referential.Species; -import fr.ifremer.tutti.persistence.service.referential.SpeciesPersistenceService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import javax.annotation.Resource; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Timestamp; -import java.util.HashMap; -import java.util.Map; +import java.sql.*; /** * @author Kevin Morin (Code Lutin) @@ -20,9 +11,6 @@ import java.util.Map; */ public class ReplaceReferenceTaxonReferentialUpdateTaskImpl implements ReferentialUpdateTask { - @Resource(name = "speciesPersistenceService") - private SpeciesPersistenceService speciesService; - /** * Logger. */ @@ -34,35 +22,39 @@ public class ReplaceReferenceTaxonReferentialUpdateTaskImpl implements Referenti } @Override - public void update(ReferentialSynchroDatabaseMetadata dbMetas, - ReferentialSynchroTableTool localDao, + public void update(Connection localConnection, Timestamp lastUpdate) throws SQLException { - int typeId = 61; - Map<String, Integer> reftaxToReplace = new HashMap<>(); + String getReftaxToReplaceQuery = "SELECT object_id, external_code " + + "FROM transcribing_item ti " + + "JOIN transcribing_item_type tit " + + "ON ti.transcribing_item_type_fk = tit.id " + + "AND tit.label = 'TAXINOMIE-COMMUN.REFERENCE_HISTORY' " + + "WHERE (update_date IS NULL OR update_date > ?)"; - ResultSet incomingData = localDao.getDataToUpdate(lastUpdate); + PreparedStatement preparedStatement = localConnection.prepareStatement(getReftaxToReplaceQuery); + preparedStatement.setTimestamp(1, lastUpdate); + ResultSet reftaxToReplace = preparedStatement.executeQuery(); - int typeColumnIndex = incomingData.findColumn("transcribing_item_type_fk"); - int oldReftaxColumnIndex = incomingData.findColumn("external_code"); - int newReftaxColumnIndex = incomingData.findColumn("object_id"); + String replaceReftaxInBatchQuery = "UPDATE batch SET reference_taxon_fk = ? WHERE reference_taxon_fk = ?"; + String replaceReftaxInSampleQuery = "UPDATE sample SET reference_taxon_fk = ? WHERE reference_taxon_fk = ?"; - while (incomingData.next()) { - if (typeId == incomingData.getInt(typeColumnIndex)) { - reftaxToReplace.put(incomingData.getString(oldReftaxColumnIndex), - incomingData.getInt(newReftaxColumnIndex)); - } - } + PreparedStatement replaceReftaxInBatchStatement = localConnection.prepareStatement(replaceReftaxInBatchQuery); + PreparedStatement replaceReftaxInSampleStatement = localConnection.prepareStatement(replaceReftaxInSampleQuery); - for (String oldRefTaxId : reftaxToReplace.keySet()) { + while (reftaxToReplace.next()) { - Integer newRefTaxId = reftaxToReplace.get(oldRefTaxId); + Integer newRefTax = reftaxToReplace.getInt(1); + Integer oldRefTax = reftaxToReplace.getInt(2); - Species source = speciesService.getSpeciesByReferenceTaxonId(Integer.parseInt(oldRefTaxId)); - Species target = speciesService.getSpeciesByReferenceTaxonId(newRefTaxId); + replaceReftaxInBatchStatement.setInt(1, newRefTax); + replaceReftaxInBatchStatement.setInt(2, oldRefTax); + replaceReftaxInBatchStatement.executeUpdate(); - speciesService.replaceSpecies(source, target, false); + replaceReftaxInSampleStatement.setInt(1, newRefTax); + replaceReftaxInSampleStatement.setInt(2, oldRefTax); + replaceReftaxInSampleStatement.executeUpdate(); } diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/synchro/TuttiReferentialSynchroServiceImpl.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/synchro/TuttiReferentialSynchroServiceImpl.java index 39c5817..6d774bb 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/synchro/TuttiReferentialSynchroServiceImpl.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/synchro/TuttiReferentialSynchroServiceImpl.java @@ -7,9 +7,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Timestamp; +import java.sql.*; import java.util.Map; import java.util.ServiceLoader; @@ -41,18 +39,16 @@ public class TuttiReferentialSynchroServiceImpl extends ReferentialSynchroServic */ private static final Log log = LogFactory.getLog(TuttiReferentialSynchroServiceImpl.class); - protected void updateSmallTable( - ReferentialSynchroDatabaseMetadata dbMetas, - ReferentialSynchroTableTool localDao, - ResultSet incomingData, - ReferentialSynchroResult result) throws SQLException { + protected void synchronizeTable(ReferentialSynchroDatabaseMetadata dbMetas, + ReferentialSynchroTableMetadata table, + Connection localConnection, + Connection remoteConnection, + ReferentialSynchroResult result) throws SQLException { + Timestamp lastUpdate = getLastUpdateDate(localConnection, table); - Timestamp lastUpdate = localDao.getLastUpdateDate(); + super.synchronizeTable(dbMetas, table, localConnection, remoteConnection, result); - super.updateSmallTable(dbMetas, localDao, incomingData, result); - - ReferentialSynchroTableMetadata table = localDao.getTable(); String tableName = table.getName(); ReferentialUpdateTask updateTask = getUpdateTasks().get(tableName); @@ -61,7 +57,59 @@ public class TuttiReferentialSynchroServiceImpl extends ReferentialSynchroServic log.info(table.getTableLogPrefix() + " - " + result.getNbRows(tableName) + " Will use specific update task: " + updateTask); } if (updateTask != null) { - updateTask.update(dbMetas, localDao, lastUpdate); + updateTask.update(localConnection, lastUpdate); + } + + } + + /** + * Gets the last updateDate for the given {@code table} using + * the given datasource. + * + * @return the last update date of the given table, or {@code null} if table does not use a updateDate columns or if + * there + * is no data in table. + */ + protected Timestamp getLastUpdateDate(Connection connection, + ReferentialSynchroTableMetadata table) throws SQLException { + Timestamp result = null; + + if (table.isWithUpdateDateColumn()) { + + String sql = table.getSelectMaxUpdateDateQuery(); + + PreparedStatement statement = connection.prepareStatement(sql); + try { + ResultSet resultSet = statement.executeQuery(); + if (resultSet.next()) { + result = resultSet.getTimestamp(1); + } + statement.close(); + } finally { + closeSilently(statement); + } + } + return result; + } + + protected void closeSilently(Statement statement) { + try { + if (statement != null && !statement.isClosed()) { + + statement.close(); + } + } catch (AbstractMethodError e) { + if (log.isDebugEnabled()) { + log.debug("Fix this linkage error, damned hsqlsb 1.8.0.7:("); + } + } catch (IllegalAccessError e) { + if (log.isDebugEnabled()) { + log.debug("Fix this IllegalAccessError error, damned hsqlsb 1.8.0.7:("); + } + } catch (Exception e) { + if (log.isErrorEnabled()) { + log.error("Could not close statement, but do not care", e); + } } } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/6714 in repository tutti. See http://git.codelutin.com/tutti.git commit 94693440c70cac7f24872285297bbe26b65d3f5c Author: Kevin Morin <morin@codelutin.com> Date: Thu Dec 17 17:11:10 2015 +0100 ajout de logs (fixes #6714) --- .../ReplaceReferenceTaxonReferentialUpdateTaskImpl.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/synchro/ReplaceReferenceTaxonReferentialUpdateTaskImpl.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/synchro/ReplaceReferenceTaxonReferentialUpdateTaskImpl.java index 43bcfbd..5aacc56 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/synchro/ReplaceReferenceTaxonReferentialUpdateTaskImpl.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/synchro/ReplaceReferenceTaxonReferentialUpdateTaskImpl.java @@ -48,14 +48,25 @@ public class ReplaceReferenceTaxonReferentialUpdateTaskImpl implements Referenti Integer newRefTax = reftaxToReplace.getInt(1); Integer oldRefTax = reftaxToReplace.getInt(2); + if (log.isInfoEnabled()) { + log.info(String.format("[%s] Remplacement du taxon %s par le taxon %s", getTable(), oldRefTax, newRefTax)); + } + replaceReftaxInBatchStatement.setInt(1, newRefTax); replaceReftaxInBatchStatement.setInt(2, oldRefTax); - replaceReftaxInBatchStatement.executeUpdate(); + int batchUpdated = replaceReftaxInBatchStatement.executeUpdate(); + + if (log.isInfoEnabled()) { + log.info(String.format("[%s] %s batchs mis à jour", getTable(), batchUpdated)); + } replaceReftaxInSampleStatement.setInt(1, newRefTax); replaceReftaxInSampleStatement.setInt(2, oldRefTax); - replaceReftaxInSampleStatement.executeUpdate(); + int sampleUpdated = replaceReftaxInSampleStatement.executeUpdate(); + if (log.isInfoEnabled()) { + log.info(String.format("[%s] %s samples mis à jour", getTable(), sampleUpdated)); + } } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm