package something;
import java.io.Serializable;
import java.util.Collections;
import java.util.Set;
import java.util.stream.Collectors;
import org.hibernate.envers.DefaultRevisionEntity;
import org.hibernate.envers.EntityTrackingRevisionListener;
import org.hibernate.envers.RevisionType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.inject.Inject;
...
public class AuditListener implements EntityTrackingRevisionListener {
private static final Logger log = LoggerFactory.getLogger(AuditListener.class);
@Inject
private RevMasterChangeDAO revMasterChangeDAO;
public AuditListener() {
super();
// this is not created by guice but somehow instatiated by hibernate envers
// therefore injection does not work out of the box
// the following statement injects manually all members in this.
// TODO find a better way to integrate this in guice
try {
InjectorHolder.getInjector()
.injectMembers(this);
} catch (Exception e) {
log.warn(e.getMessage(), e);
}
}
public AuditListener(boolean dontInject) {
super();
// use this constructor for tests, if mocks are injected with and via mockito
}
snip
/**
* Holds instance of the Guice injector. Should be filled after initialization
* of Injector (after calling createInjector())
*/
public final class InjectorHolder {
private static Injector staticInjector;
private InjectorHolder() {
}
public static void setInjector(Injector injector) {
staticInjector = injector;
}
public static Injector getInjector() {
return staticInjector;
}
--
You received this message because you are subscribed to a topic in the Google Groups "google-guice" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-guice/Yp1xbCM37jY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-guice...@googlegroups.com.
To post to this group, send email to google...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/3925d1c3-f452-4719-9803-aa402c84840d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.