Kenmegne
7 days ago 23a46b4be35277e06ec89f48730eeb694e686be8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.megatim.fdxconsultation.dao.impl.settings;
 
import com.bekosoftware.genericdaolayer.dao.impl.AbstractGenericDAO;
import com.megatim.fdxconsultation.dao.ifaces.settings.DisplayOptionsDAO;
import com.megatim.fdxconsultation.model.settings.DisplayOptions;
import java.util.Optional;
import javax.enterprise.context.Dependent;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.transaction.Transactional;
 
/**
 *
 * @author Gabuntu
 */
@Dependent
public class DisplayOptionsDAOImpl extends AbstractGenericDAO<DisplayOptions, Long> implements DisplayOptionsDAO {
 
    @PersistenceContext(unitName = "fdxConsultationPersistenceUnit")
    protected EntityManager em;
 
    @Override
    public EntityManager getEntityManager() {
        return em;
    }
 
    @Override
    public Class<DisplayOptions> getManagedEntityClass() {
        return DisplayOptions.class;
    }
 
    @Transactional
    @Override
    public DisplayOptions current() {
        Optional<DisplayOptions> optional = em.createQuery("SELECT d from DisplayOptions d")
                .getResultList()
                .stream()
                .findFirst();
        return optional.orElse(null);
    }
 
    @Transactional
    @Override
    synchronized public DisplayOptions edit(DisplayOptions entity) {
 
        DisplayOptions current = current();
        if (current == null) {
            return save(entity);
        }
 
        current.setAuditAPI(entity.getAuditAPI());
        current.setStatParticipantAPI(entity.getStatParticipantAPI());
        current.setStatPathAPI(entity.getStatPathAPI());
        current.setTableauBordAPI(entity.getTableauBordAPI());
 
        current.setSuiviEchangeStandalone(entity.getSuiviEchangeStandalone());
        current.setTableauBordStandalone(entity.getTableauBordStandalone());
 
        return save(current);
    }
 
}