This site is maintained for archival purposes only. Eclipse projects have transitioned to GitHub and Eclipse GitLab. Use the Projects search tool to locate your project and access its latest code and issue tracker.
Bug 211316 - Add instantiation-policy support to the EclipseLink-ORM.XML Schema
Summary: Add instantiation-policy support to the EclipseLink-ORM.XML Schema
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P5 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 227219
  Show dependency tree
 
Reported: 2007-11-28 14:38 EST by Guy Pelletier CLA
Modified: 2022-06-09 10:27 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Guy Pelletier CLA 2007-11-28 14:38:58 EST
 
Comment 1 Doug Clarke CLA 2008-01-29 14:05:22 EST
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"/>

Comment 2 Doug Clarke CLA 2008-01-31 13:13:15 EST
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.
Comment 3 Doug Clarke CLA 2008-04-10 22:48:55 EDT
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
Comment 4 Karen Butzke CLA 2008-07-16 16:08:20 EDT
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
Comment 5 Tom Ware CLA 2009-04-16 10:59:41 EDT
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.
Comment 6 Guy Pelletier CLA 2009-12-08 09:10:44 EST
Closing, this functionality was addressed in bug 211315
Comment 7 Eclipse Webmaster CLA 2022-06-09 10:27:21 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink