Community
Participate
Working Groups
I believe we only need to provide annotation and EclipseLink-ORM.XML support equivalent to the following public API on ClassDescriptor: public void useFactoryInstantiationPolicy(String factoryClassName, String methodName) public void useFactoryInstantiationPolicy(String factoryClassName, String methodName, String factoryMethodName) public void setInstantiationPolicy(InstantiationPolicy instantiationPolicy) If a user has a stateful object they need to use as the factory then they will need to use a DescriptorCustomizer or other call-back mechanism so the factory instance can be provided through Java code. ANNOTATION: Just some rough ideas to start the conversation @InstantiationPolicy("some.package.MyInstantiationPolicy") - EclipseLink will use the default constructor for this object and set the instance on the descriptor @FactoryInstantiationPolicy(factory = "some.package.MyInstantiationPolicy", method="newFactory", factoryMethod="newInstance") - Use the method to create an instance of the factory. If the method is not specified then the default constructor will be used. - Use the factoryMethod each time a new entity instance is required ECLIPSELINK-ORM.XML The instantiation-policy will be configured as a child element of <entity> <instantiation-policy class="some.package.MyPolicy"/> <factory-instantiation-policy class="package.MyFactory" method="createFactory" factoryMethod="newInstance"/>
Allows a user to specify a different mechanism then the default usage of the zero-arg constructor for how TopLink will create new instances. @InstantiationPolicy(method="newInstance") This means instead of using the default constructor a static method with no arguments of the given name should be used on the class. @InstantiationPolicy(method="newInstance", factory="mypackage.MyFactory") This means to use the default constructor to get an instance of MyFactory class and then call its newInstance method whenever a new instance of the class is needed. @InstantiationPolicy(method="newInstance", factory="mypackage.MyFactory", create-factory-method="newFactory") This means to use the newFactory static method on MyFactory to create the factory object and then use newInstance on it whenever a new object is required. All existing rules of the signature and possible args for these methods still applies and should be documented or referenced to in the JavaDocs.
I am concerned that we are defining annotations that match our implementation rather then the general concept. In this case we would typically do the @InstantiationPolicy as I have suggested above. We may want to focus more on what the user is configuring. In this case they are specifying a factory method and/or class for their entity type. @Factory(factory-class="my.Foo", factory-method="getSingelton", method="newInstance") Going this route would deal with everything in the previous XSD (see <xsd:complexType name="instantiation-policy">) but does not enable the configuration of a custom InstantiationPolicy implementor. This case can be easily supported in a Descriptor customizer
Would you also want to support ClassDescriptor.useMethodInstantiationPolicy(String) with this feature? I think Doug mentions this in comment #2, the static method case, but is not accounted for in comment #3
Updating priority due to revised bug categorization process. See the following page for details: http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines#Priority_and_Target_Milestone If you feel the updated priority is incorrect, please send an email to eclipselink-users@eclipse.org.
Closing, this functionality was addressed in bug 211315
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink