X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fwamblee%2Fphotos%2Fmodel%2Fplumbing%2FInitializer.java;h=b5ace148c012cb1b953fdacc1d0f22f13cb0a8f9;hb=f3e05888d09a2d39375639b056d8e9093e00668b;hp=250964148edf1b745666fbd7cf83826108f0a64e;hpb=26fbbb5a4350750e3a4f617073ed229e59a37c38;p=photos diff --git a/src/main/java/org/wamblee/photos/model/plumbing/Initializer.java b/src/main/java/org/wamblee/photos/model/plumbing/Initializer.java index 2509641..b5ace14 100644 --- a/src/main/java/org/wamblee/photos/model/plumbing/Initializer.java +++ b/src/main/java/org/wamblee/photos/model/plumbing/Initializer.java @@ -15,11 +15,14 @@ */ package org.wamblee.photos.model.plumbing; +import java.util.logging.Logger; + import javax.annotation.PostConstruct; import javax.ejb.Singleton; import javax.ejb.Startup; import javax.inject.Inject; +import org.wamblee.inject.InjectorBuilder; import org.wamblee.photos.model.Album; import org.wamblee.security.authentication.UserAdministration; @@ -31,18 +34,40 @@ import org.wamblee.security.authentication.UserAdministration; @Startup public class Initializer { - @Inject - private UserAdministration userAdmin; + private static final Logger LOGGER = Logger.getLogger(Initializer.class + .getName()); - @Inject - @AllPhotos - private Album album; + /** + * We need this helper to do initialization of the beans from within the + * post construct method. Injecting these objects into the initializer class + * will lead to initialization outside of a transactional context and this + * is does not work because and entity manager is required. + * + * @author Erik Brakkee + * + */ + public static class Helper { + @Inject + private UserAdministration userAdmin; - @PostConstruct - public void init() { - System.out.println("Photo application initializing"); + @Inject + @AllPhotos + private Album album; - userAdmin.getUserCount(); - album.size(); + public void init() { + userAdmin.getUserCount(); + album.size(); + } + } + + @PostConstruct + public void scheduleInit() { + LOGGER.info("Photo application initializing"); + // timerService.createTimer(1000, 1000, null); + LOGGER.info("Initializing photo application"); + Helper helper = new Helper(); + InjectorBuilder.getInjector().inject(helper); + helper.init(); + LOGGER.info("Initialized photo application"); } }