| .. | .. |
|---|
| 2 | 2 | |
|---|
| 3 | 3 | import java.util.Date; |
|---|
| 4 | 4 | |
|---|
| 5 | | -import javax.inject.Inject; |
|---|
| 6 | | -import javax.inject.Singleton; |
|---|
| 5 | +import javax.enterprise.context.ApplicationScoped; |
|---|
| 7 | 6 | import javax.persistence.EntityManager; |
|---|
| 7 | +import javax.persistence.PersistenceContext; |
|---|
| 8 | +import javax.transaction.Transactional; |
|---|
| 8 | 9 | |
|---|
| 9 | 10 | import net.curisit.integrity.commons.Utils; |
|---|
| 10 | 11 | import net.curisit.securis.db.Settings; |
|---|
| .. | .. |
|---|
| 12 | 13 | import org.apache.logging.log4j.LogManager; |
|---|
| 13 | 14 | import org.apache.logging.log4j.Logger; |
|---|
| 14 | 15 | |
|---|
| 15 | | -import com.google.inject.Provider; |
|---|
| 16 | | -import com.google.inject.persist.Transactional; |
|---|
| 17 | | - |
|---|
| 18 | | -@Singleton |
|---|
| 16 | +@ApplicationScoped |
|---|
| 19 | 17 | public class SystemParams { |
|---|
| 20 | 18 | |
|---|
| 21 | 19 | @SuppressWarnings("unused") |
|---|
| 22 | 20 | private static final Logger LOG = LogManager.getLogger(SystemParams.class); |
|---|
| 23 | 21 | |
|---|
| 24 | | - @Inject |
|---|
| 25 | | - private Provider<EntityManager> emp; |
|---|
| 22 | + @PersistenceContext(unitName = "localdb") |
|---|
| 23 | + private EntityManager em; |
|---|
| 26 | 24 | |
|---|
| 27 | 25 | /** |
|---|
| 28 | 26 | * Returns the system parameter value for given key |
|---|
| .. | .. |
|---|
| 111 | 109 | * @return |
|---|
| 112 | 110 | */ |
|---|
| 113 | 111 | public String getParam(String key, String defaultValue) { |
|---|
| 114 | | - EntityManager em = emp.get(); |
|---|
| 115 | 112 | Settings p = em.find(Settings.class, key); |
|---|
| 116 | 113 | return p == null ? defaultValue : p.getValue(); |
|---|
| 117 | 114 | } |
|---|
| .. | .. |
|---|
| 125 | 122 | */ |
|---|
| 126 | 123 | @Transactional |
|---|
| 127 | 124 | public void setParam(String key, String value) { |
|---|
| 128 | | - EntityManager em = this.emp.get(); |
|---|
| 129 | 125 | Settings p = em.find(Settings.class, key); |
|---|
| 130 | 126 | if (p == null) { |
|---|
| 131 | 127 | p = new Settings(); |
|---|
| .. | .. |
|---|
| 187 | 183 | */ |
|---|
| 188 | 184 | @Transactional |
|---|
| 189 | 185 | public void removeParam(String key) { |
|---|
| 190 | | - EntityManager em = this.emp.get(); |
|---|
| 191 | 186 | Settings p = em.find(Settings.class, key); |
|---|
| 192 | 187 | if (p != null) { |
|---|
| 193 | 188 | em.remove(p); |
|---|