package com.commafeed.backend;

import java.util.Date;

import javax.ejb.Schedule;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.commafeed.backend.services.ApplicationSettingsService;
import com.commafeed.backend.services.DatabaseCleaningService;

/**
 * Contains all scheduled tasks
 * 
 */
@Stateless
public class ScheduledTasks {

	@Inject
	ApplicationSettingsService applicationSettingsService;

	@Inject
	DatabaseCleaningService cleaner;

	@PersistenceContext
	EntityManager em;

	/**
	 * clean old read statuses, runs every day at midnight
	 */
	@Schedule(hour = "0", persistent = false)
	private void cleanupOldStatuses() {
		Date threshold = applicationSettingsService.getUnreadThreshold();
		if (threshold != null) {
			cleaner.cleanStatusesOlderThan(threshold);
		}
	}
}

@@ -127,107 +127,106 @@
 vax.
-inject.Inject;%0D%0Aimport javax.persistence.EntityManager;%0D%0Aimport javax.persistence.PersistenceContex
+ejb.TransactionManagement;%0D%0Aimport javax.ejb.TransactionManagementType;%0D%0Aimport javax.inject.Injec
 t;%0D%0A
@@ -420,16 +420,72 @@
 teless%0D%0A
+@TransactionManagement(TransactionManagementType.BEAN)%0D%0A
 public c
@@ -588,16 +588,16 @@
 Inject%0D%0A
+
 %09Databas
@@ -629,52 +629,8 @@
 %0D%0A%0D%0A
-%09@PersistenceContext%0D%0A%09EntityManager em;%0D%0A%0D%0A
 %09/**

create a new transaction for each delete chunk