* @author Erik Brakkee
*
*/
-public class FlushEntityManagerBehavior extends AbstractPageBehavior {
+public abstract class FlushEntityManagerBehavior extends AbstractPageBehavior {
private static final Logger LOGGER = Logger
.getLogger(FlushEntityManagerBehavior.class.getName());
- private EntityManager entityManager;
-
/**
* Constructs the behavior.
*
* @param aEntityManager
* Contextual reference to an entitymanager.
*/
- public FlushEntityManagerBehavior(EntityManager aEntityManager) {
- entityManager = aEntityManager;
+ public FlushEntityManagerBehavior() {
+ // Empty.
}
@Override
public void onAfterRender(WebPage aPage) {
+ EntityManager entityManager = getEntityManager();
try {
if (entityManager.isOpen()) {
entityManager.flush();
LOGGER.log(Level.WARNING, "Could not flush entitymanager", e);
}
}
+
+ /**
+ * Gets the entity mmanager to flush.
+ * @return Entity manager.
+ */
+ public abstract EntityManager getEntityManager();
}
protected WebApplicationBasePage() {
super();
-
+
setEnabled(false);
init();
}
addBehavior(new ExpirePageImmediatelyBehavior());
}
- /**
- * Flushes the entitymanager immedately after rendering to make sure that
- * errors are caught early.
- *
- * @param aEntityManager
- * Contextual reference to an entity manager.
- */
- protected void flushEntityManagerAfterRender(EntityManager aEntityManager) {
- addBehavior(new FlushEntityManagerBehavior(aEntityManager));
- }
-
/**
* Adds a specific behavior to the page.
*
super.onAfterRender();
behaviors.onAfterRender(this);
}
-
+
@Override
protected void onDetach() {
super.onDetach();