use of com.axelor.apps.base.db.SequenceVersion in project axelor-open-suite by axelor.
the class SequenceService method getSequenceNumber.
/**
* Method returning a sequence number from a given generic sequence and a date
*
* @param sequence
* @param refDate
* @return
*/
@Transactional
public String getSequenceNumber(Sequence sequence, LocalDate refDate) {
Sequence seq = JPA.em().createQuery("SELECT self FROM Sequence self WHERE id = :id", Sequence.class).setParameter("id", sequence.getId()).setLockMode(LockModeType.PESSIMISTIC_WRITE).setFlushMode(FlushModeType.COMMIT).getSingleResult();
SequenceVersion sequenceVersion = getVersion(seq, refDate);
String nextSeq = computeNextSeq(sequenceVersion, seq, refDate);
sequenceVersion.setNextNum(sequenceVersion.getNextNum() + seq.getToBeAdded());
if (sequenceVersion.getId() == null) {
sequenceVersionRepository.save(sequenceVersion);
}
return nextSeq;
}
use of com.axelor.apps.base.db.SequenceVersion in project axelor-open-suite by axelor.
the class ImportSequence method importSequence.
@Transactional(rollbackOn = Exception.class)
public Object importSequence(Object bean, Map<String, Object> values) throws AxelorException {
assert bean instanceof Sequence;
Sequence sequence = (Sequence) bean;
sequence.setFullName(sequenceService.computeFullName(sequence));
SequenceVersion seqVersion = sequenceService.getVersion(sequence, LocalDate.now());
sequenceVersionRepository.save(seqVersion);
sequence.setVersion(seqVersion.getId().intValue());
sequenceRepository.save(sequence);
return sequence;
}
Aggregations