| Summary: | Add write-value support | ||
|---|---|---|---|
| Product: | z_Archived | Reporter: | Doug Clarke <douglas.clarke> |
| Component: | Eclipselink | Assignee: | Project Inbox <eclipselink.foundation-inbox> |
| Status: | NEW --- | QA Contact: | |
| Severity: | enhancement | ||
| Priority: | P3 | ||
| Version: | unspecified | ||
| Target Milestone: | --- | ||
| Hardware: | All | ||
| OS: | All | ||
| Whiteboard: | |||
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink |
Add support for specifying a value that will be written into a row when it is inserted/updated/deleted. The value to be written can be a specific value, retrieved from the application context (EM property, EMF property, or context property), or can be a calculated value. Use Cases: - Last Update Timestamp - Last Update user - Calculated value based on other attributes and/or context - Virtual Delete - Multi-Tenancy Configuration: I would like to propose we allow configuration of this using an EclipseLink specific annotation as well as eclipselink-orm.xml support. EXAMPLE: Write Value From Context @WriteValue(column=@Column(name="MY_COL"), insertable=true, updateable=false, property="my-value") This would indicate that when doing an INSERT of the entity this annotation is created on a property value named 'my-value' would be looked up in EM, then EMF, then InitialContext and included in the INSERT statement. EXAMPLE: Last Update User & Timestamp @WriteValues({ @WriteValue(column=@Column(name="LAST_USER"), insertable=true, updateable=true, property="current-user"), @WriteValue(column=@Column(name="LST_UPDATE_TS"), insertable=true, updateable=false, calculate="mypackage.TSCalculator") }) This will mean that both columns are populated on INSERTs and UPDATEs with the user name coming from the context properties and the current TS being calculated by the class name provided. public class TSCalculator<T> implements ValueCalculator { public Object calculate(DatabaseSession session, T entity) { return new Timestamp(System.currentTimeMillis()); } } EXAMPLE: Virtual Delete @AdditionalCriteria("IS_DEL = 'N'") @WriteValue(column=@Column(name="IS_DEL"), insert='N', delete='Y') This last example obviously has some challenges. The @AdditionalCriteria support will need to be enhanced to reference un-mapped columns. The @WriteValue will need to be designed to handle these simple static values per operation as well as properties and calculated values. NOTE: An alternative is to develop separate annotations/XML for each operation type: @WriteValue - static values specified for the operation types @CalculateValue - allow developer defined calculator to determine the value @PropertyValue - allow value to be provided through context properties