It adds a new functionality to EntitySequenceDAO to skip repeated code sequences.
If code sequence is added by importation services , this functionality lets skip repeated codes and update the last value of the entity code sequence. FEA :ItEr61S04NavalPlanEntities
This commit is contained in:
parent
5795ccc773
commit
889f42ef64
2 changed files with 49 additions and 2 deletions
|
|
@ -98,10 +98,20 @@ public class EntitySequenceDAO extends
|
|||
public String getNextEntityCode(EntityNameEnum entityName) {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
try {
|
||||
String code;
|
||||
Integer cont = 0;
|
||||
EntitySequence entitySequence = getActiveEntitySequence(entityName);
|
||||
entitySequence.incrementLastValue();
|
||||
|
||||
do {
|
||||
entitySequence.incrementLastValue();
|
||||
code = entitySequence.getCode();
|
||||
cont++;
|
||||
} while (entityName.getIntegrationEntityDAO()
|
||||
.existsByCode(code)
|
||||
&& cont < 100);
|
||||
|
||||
save(entitySequence);
|
||||
return entitySequence.getCode();
|
||||
return code;
|
||||
} catch (HibernateOptimisticLockingFailureException e) {
|
||||
// Do nothing (optimistic approach 5 attempts)
|
||||
} catch (InstanceNotFoundException e) {
|
||||
|
|
|
|||
|
|
@ -22,6 +22,17 @@ package org.navalplanner.business.common.entities;
|
|||
|
||||
import static org.navalplanner.business.i18n.I18nHelper._;
|
||||
|
||||
import org.navalplanner.business.calendars.entities.CalendarData;
|
||||
import org.navalplanner.business.common.IntegrationEntity;
|
||||
import org.navalplanner.business.common.Registry;
|
||||
import org.navalplanner.business.common.daos.IIntegrationEntityDAO;
|
||||
import org.navalplanner.business.labels.entities.LabelType;
|
||||
import org.navalplanner.business.materials.entities.UnitType;
|
||||
import org.navalplanner.business.orders.entities.Order;
|
||||
import org.navalplanner.business.resources.entities.CriterionType;
|
||||
import org.navalplanner.business.resources.entities.Machine;
|
||||
import org.navalplanner.business.resources.entities.Worker;
|
||||
|
||||
/**
|
||||
* It represents the entities which use code generation
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
|
|
@ -40,4 +51,30 @@ public enum EntityNameEnum {
|
|||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public IIntegrationEntityDAO<? extends IntegrationEntity> getIntegrationEntityDAO() {
|
||||
switch (this) {
|
||||
case ORDER:
|
||||
return (IIntegrationEntityDAO<Order>) Registry.getOrderDAO();
|
||||
case CRITERION:
|
||||
return (IIntegrationEntityDAO<CriterionType>) Registry
|
||||
.getCriterionTypeDAO();
|
||||
case LABEL:
|
||||
return (IIntegrationEntityDAO<LabelType>) Registry
|
||||
.getLabelTypeDAO();
|
||||
case MACHINE:
|
||||
return (IIntegrationEntityDAO<Machine>) Registry.getMachineDAO();
|
||||
case WORKER:
|
||||
return (IIntegrationEntityDAO<Worker>) Registry.getWorkerDAO();
|
||||
case UNIT_TYPE:
|
||||
return (IIntegrationEntityDAO<UnitType>) Registry.getUnitTypeDAO();
|
||||
case CALENDAR:
|
||||
return (IIntegrationEntityDAO<CalendarData>) Registry
|
||||
.getCalendarDataDAO();
|
||||
default:
|
||||
throw new RuntimeException("can't handle the code sequence of the "
|
||||
+ description);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue