Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 338822 - Add write-value support
Summary: Add write-value support
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-03 10:37 EST by Doug Clarke CLA
Modified: 2022-06-09 10:02 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Doug Clarke CLA 2011-03-03 10:37:35 EST
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
Comment 1 Eclipse Webmaster CLA 2022-06-09 10:02:47 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink