Search in sources :

Example 1 with SequenceVersion

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;
}
Also used : SequenceVersion(com.axelor.apps.base.db.SequenceVersion) Sequence(com.axelor.apps.base.db.Sequence) Transactional(com.google.inject.persist.Transactional)

Example 2 with SequenceVersion

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;
}
Also used : SequenceVersion(com.axelor.apps.base.db.SequenceVersion) Sequence(com.axelor.apps.base.db.Sequence) Transactional(com.google.inject.persist.Transactional)

Aggregations

Sequence (com.axelor.apps.base.db.Sequence)2 SequenceVersion (com.axelor.apps.base.db.SequenceVersion)2 Transactional (com.google.inject.persist.Transactional)2