forked from Archives/Athou_commafeed
store a copy of the settings in memory
This commit is contained in:
@@ -1,24 +1,31 @@
|
||||
package com.commafeed.backend.services;
|
||||
|
||||
import javax.ejb.Stateless;
|
||||
import javax.ejb.Singleton;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import com.commafeed.backend.dao.ApplicationSettingsDAO;
|
||||
import com.commafeed.backend.model.ApplicationSettings;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
@Stateless
|
||||
@Singleton
|
||||
public class ApplicationSettingsService {
|
||||
|
||||
@Inject
|
||||
ApplicationSettingsDAO applicationSettingsDAO;
|
||||
|
||||
private ApplicationSettings settings;
|
||||
|
||||
public void save(ApplicationSettings settings) {
|
||||
this.settings = settings;
|
||||
applicationSettingsDAO.saveOrUpdate(settings);
|
||||
}
|
||||
|
||||
public ApplicationSettings get() {
|
||||
return Iterables.getFirst(applicationSettingsDAO.findAll(), null);
|
||||
if (settings == null) {
|
||||
settings = Iterables.getFirst(applicationSettingsDAO.findAll(),
|
||||
null);
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user