|
I've pushed a quick prototype for the annotation design to my GH fork.
The idea is to leave 3) (value generation via default value/trigger) to @Generated as it is today. 1) and 2) would be provided by the design presented in that commit. The main SPI is ValueGenerator which basically can be implemented by invoking a Java routine for determining the value or an SQL function.
An implementation also specifies when the value generation takes place (INSERT, ALWAYS) and the strategy to choose (VM, DB (selects a value from a function and passes it to the SQL) or DM_EMBED (selects a function inline within the SQL). Note that these values could be taken from the generator's annotation and thus be specified by the user if feasible. For pure Java-based generators there is one implementation of that general SPI which delegates to another simpler SPI type VmValueGenerator which just returns a value.
Some usage examples:
public class Giraffe {
@GeneratedValue(type = MyNameGenerator.class, when = GenerationTime.ALWAYS)
private String name;
@FunctionValue(function = "MY_CUSTOM_FUNCTION", when = GenerationTime.INSERT, embed = false)
private Date customCreated;
@CreationTimestamp(strategy = ValueGenerationStrategy.DB)
private Date created;
}
|