package com.commafeed.backend.services;

import javax.ejb.Stateless;
import javax.inject.Inject;

import com.commafeed.backend.dao.ApplicationSettingsDAO;
import com.commafeed.backend.model.ApplicationSettings;
import com.google.common.collect.Iterables;

@Stateless
public class ApplicationSettingsService {

	@Inject
	ApplicationSettingsDAO applicationSettingsDAO;

	public void save(ApplicationSettings settings) {
		applicationSettingsDAO.saveOrUpdate(settings);
	}

	public ApplicationSettings get() {
		return Iterables.getFirst(applicationSettingsDAO.findAll(), null);
	}

}

@@ -54,24 +54,24 @@
 ax.ejb.S
-tateless
+ingleton
 ;%0D%0Aimpor
@@ -264,16 +264,16 @@
 %0D%0A@S
-tateless
+ingleton
 %0D%0Apu
@@ -372,24 +372,66 @@
 ingsDAO;%0D%0A%0D%0A
+%09private ApplicationSettings settings;%0D%0A%0D%0A
 %09public void
@@ -469,16 +469,45 @@
 ngs) %7B%0D%0A
+%09%09this.settings = settings;%0D%0A
 %09%09applic
@@ -597,14 +597,46 @@
 %0D%0A%09%09
-return
+if (settings == null) %7B%0D%0A%09%09%09settings =
  Ite
@@ -684,22 +684,53 @@
 ndAll(),
- null)
+%0D%0A%09%09%09%09%09null);%0D%0A%09%09%7D%0D%0A%09%09return settings
 ;%0D%0A%09%7D%0D%0A%0D

store a copy of the settings in memory