def dataSource
long id
+ int version
String nom
Date dateDemande
Date dateDebutExecutionTraitement
if (dateFinExecutionTraitement) {
tsdateFinExecution = new Timestamp(dateFinExecutionTraitement.getTime())
}
- sql.executeUpdate("""
+
+ int nbRows = sql.executeUpdate(
+ """
update entdemon.demande_traitement
set
- statut = ${statut.name()} ,
- date_annulation_execution_traitement = $tsdateAnnulationExecution ,
- date_debut_execution_traitement = $tsdateDebutExecution ,
- date_fin_execution_traitement = $tsdateFinExecution ,
- traitement_rapport = $traitementRapport
- where id= $id
- """)
+ statut = ?,
+ date_annulation_execution_traitement = ?,
+ date_debut_execution_traitement = ?,
+ date_fin_execution_traitement = ?,
+ traitement_rapport = ?,
+ version = ?
+ where id = ?
+ and version = ?
+ """,
+ [
+ statut.name(),
+ tsdateAnnulationExecution,
+ tsdateDebutExecution,
+ tsdateFinExecution,
+ traitementRapport,
+ version + 1,
+ id,
+ version
+ ]
+ )
+
+ if (nbRows == 0) {
+ throw new DemandeTraitementLockingException(this)
+ }
+
+ version++
+
sql.close()
}
}
}
+
+ String toString() {
+ return "DefaultDemandeTraitement{id = $id, type = $traitementType}"
+ }
}
nom,
demandeur_autorite_id,
etablissement_id,
- annee_scolaire_id
+ annee_scolaire_id,
+ version
from entdemon.demande_traitement
where id = $id""") { row ->
demandeurAutoriteId: row.demandeur_autorite_id,
etablissementId: row.etablissement_id,
anneeScolaireId: row.annee_scolaire_id,
+ version: row.version,
dataSource: dataSource
)
}
nom,
demandeur_autorite_id,
etablissement_id,
- annee_scolaire_id
+ annee_scolaire_id,
+ version
FROM entdemon.demande_traitement
WHERE traitement_type IN $types
AND statut = '${DemandeTraitementStatut.EN_ATTENTE.name()}'
nom: row.nom,
etablissementId: row.etablissement_id,
anneeScolaireId: row.annee_scolaire_id,
- dataSource: dataSource,
- demandeurAutoriteId: row.demandeur_autorite_id
+ demandeurAutoriteId: row.demandeur_autorite_id,
+ version: row.version,
+ dataSource: dataSource
)
}
return res
nom,
demandeur_autorite_id,
etablissement_id,
- annee_scolaire_id
+ annee_scolaire_id,
+ version,
FROM entdemon.demande_traitement
WHERE NOT statut = '${DemandeTraitementStatut.SUPPRIMEE.name()}'
"""
nom: row.nom,
etablissementId: row.etablissement_id,
anneeScolaireId: row.annee_scolaire_id,
- demandeurAutoriteId: row.demandeur_autorite_id
+ demandeurAutoriteId: row.demandeur_autorite_id,
+ version: row.version
)
})
--- /dev/null
+/*
+ * Copyright © FYLAB and the Conseil Régional d'Île-de-France, 2009
+ * This file is part of L'Interface Libre et Interactive de l'Enseignement (Lilie).
+ *
+ * Lilie is free software. You can redistribute it and/or modify since
+ * you respect the terms of either (at least one of the both license) :
+ * - 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.
+ * - the CeCILL-C as published by CeCILL-C; either version 1 of the
+ * License, or any later version
+ *
+ * There are special exceptions to the terms and conditions of the
+ * licenses as they are applied to this software. View the full text of
+ * the exception in file LICENSE.txt in the directory of this software
+ * distribution.
+ *
+ * Lilie 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
+ * Licenses for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the CeCILL-C along with Lilie. If not, see :
+ * <http://www.gnu.org/licenses/> and
+ * <http://www.cecill.info/licences.fr.html>.
+ */
+
+package org.lilie.services.eliot.demon.impl;
+
+/**
+ * Cette exception est équivalente à HibernateOptimisticLockingFailureException.
+ * Elle est levée si la demande de traitement a changé de version ou a été supprimée
+ * par une autre transaction entre le moment où on l'a chargée en mémoire
+ * et le moment où on effectue la requête de mise à jour.
+ */
+public class DemandeTraitementLockingException extends RuntimeException {
+
+ public DemandeTraitementLockingException(DefaultDemandeTraitement demande) {
+ super("La demande de traitement " + demande.toString() + "a été modifiée ou supprimée par un autre processus");
+ }
+}
--- /dev/null
+<!--
+ ~ Copyright © FYLAB and the Conseil Régional d'Île-de-France, 2009
+ ~ This file is part of L'Interface Libre et Interactive de l'Enseignement (Lilie).
+ ~
+ ~ Lilie is free software. You can redistribute it and/or modify since
+ ~ you respect the terms of either (at least one of the both license) :
+ ~ - 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.
+ ~ - the CeCILL-C as published by CeCILL-C; either version 1 of the
+ ~ License, or any later version
+ ~
+ ~ There are special exceptions to the terms and conditions of the
+ ~ licenses as they are applied to this software. View the full text of
+ ~ the exception in file LICENSE.txt in the directory of this software
+ ~ distribution.
+ ~
+ ~ Lilie 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
+ ~ Licenses for more details.
+ ~
+ ~ You should have received a copy of the GNU General Public License
+ ~ and the CeCILL-C along with Lilie. If not, see :
+ ~ <http://www.gnu.org/licenses/> and
+ ~ <http://www.cecill.info/licences.fr.html>.
+ -->
+
+<databaseChangeLog
+ xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">
+
+ <changeSet id="1" author="bper">
+ <comment>
+ Ajout de la colonne 'version' dans la table 'entdemon.demande_traitement'
+ </comment>
+
+ <addColumn
+ schemaName="entdemon"
+ tableName="demande_traitement">
+
+ <column name="version" defaultValue="0" type="int">
+ <constraints nullable="false"/>
+ </column>
+
+ </addColumn>
+
+ </changeSet>
+
+</databaseChangeLog>
<include file="changelogs/scolarite/2014-11-18-0040768.xml"/>
<include file="changelogs/securite/2014-11-20-0039547.xml"/>
<include file="changelogs/scolarite/2014-12-18-0041650.xml"/>
+ <include file="changelogs/scolarite/2015-01-07-0041917.xml"/>
</databaseChangeLog>