Closed aslakknutsen closed 11 years ago
Could be implemented as a Decorator. One problem is we don't separate between Create/Update in Repository.
package org.cedj.geekseek.domain;
import javax.decorator.Decorator;
import javax.decorator.Delegate;
import javax.enterprise.event.Event;
import javax.enterprise.inject.Any;
import javax.inject.Inject;
import org.cedj.geekseek.domain.model.Identifiable;
@Decorator
public abstract class EventRepositoryDecorator<T extends Identifiable> implements Repository<T> {
@Inject
private Event<T> event;
@Inject @Any @Delegate
private Repository<T> delegate;
@Override
public T store(T entity) {
T stored = delegate.store(entity);
event.select(new Created.Literal()).fire(entity);
return stored;
}
@Override
public void remove(T entity) {
delegate.remove(entity);
event.select(new Removed.Literal()).fire(entity);
}
}
Fire CDI Events on Create/Update/Delete