Uploaded image for project: 'Cayenne'
  1. Cayenne
  2. CAY-949

Factory for lifecycle listeners

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0
    • 3.0M3, 3.0
    • None
    • None

    Description

      So far we've followed the JPA spec in Cayenne classic callbacks/listeners implementation. I am using listeners extensively and till now I used to install them in the code. Now that Modeler supports listeners, I discovered that the default mechanism of listener instantiation (Class.forName("listenerClass").newInstance()) is inadequate when a listener has dependencies on its environment. I guess in the J2EE world the dependencies are obtained via JNDI, but I wanted to use injection as a cleaner approach (and to avoid setting up JNDI).

      So... I wrote an extension point that would allow users to register a factory object for creating the listeners:

      public interface EntityListenerFactory {

      <T> T createListener(Class<T> listenerClass, ObjEntity entity);
      }

      This would support dependency injection (or any other environment specific customization) of the listener objects, as well as using interfaces for the listeners - something JPA does not support. So the same listener configuration may be used with different implementations depending on some app logic.

      Attachments

        Activity

          People

            andrus Andrus Adamchik
            andrus Andrus Adamchik
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: