Package org.hibernate.generator.internal
Class CurrentTimestampGeneration
- java.lang.Object
-
- org.hibernate.generator.internal.CurrentTimestampGeneration
-
- All Implemented Interfaces:
Serializable
,BeforeExecutionGenerator
,Generator
,OnExecutionGenerator
public class CurrentTimestampGeneration extends Object implements BeforeExecutionGenerator, OnExecutionGenerator
Value generation strategy which produces a timestamp using the databasecurrent_timestamp
function or the JVM current instant.Underlies the
CurrentTimestamp
,CreationTimestamp
, andUpdateTimestamp
annotations.- Since:
- 6.0
- See Also:
CurrentTimestamp
,CreationTimestamp
,UpdateTimestamp
, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
CLOCK_SETTING_NAME
Configuration property name to set a customClock
for Hibernate ORM to use when generating VM based timestamp values for e.g.
-
Constructor Summary
Constructors Constructor Description CurrentTimestampGeneration(CreationTimestamp annotation, Member member, GeneratorCreationContext context)
CurrentTimestampGeneration(CurrentTimestamp annotation, Member member, GeneratorCreationContext context)
CurrentTimestampGeneration(UpdateTimestamp annotation, Member member, GeneratorCreationContext context)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Object
generate(SharedSessionContractImplementor session, Object owner, Object currentValue, EventType eventType)
Generate a value.boolean
generatedOnExecution()
Determines if the property value is generated when a row is written to the database, or in Java code that executes before the row is written.static <T extends Clock>
TgetClock(SessionFactory sessionFactory)
EnumSet<EventType>
getEventTypes()
The event types for which this generator should be called to produce a new value.String[]
getReferencedColumnValues(Dialect dialect)
A SQL expression indicating how to calculate the generated values when the mapped columns are included in the SQL statement.boolean
referenceColumnsInSql(Dialect dialect)
Determines if the columns whose values are generated are included in the column list of the SQLinsert
orupdate
statement.boolean
writePropertyValue()
Determines if the property values are written to JDBC as the argument of a JDBC?
parameter.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.hibernate.generator.Generator
allowAssignedIdentifiers, generatedOnExecution, generatesOnInsert, generatesOnUpdate, generatesSometimes
-
Methods inherited from interface org.hibernate.generator.OnExecutionGenerator
getGeneratedIdentifierDelegate, getUniqueKeyPropertyNames
-
-
-
-
Field Detail
-
CLOCK_SETTING_NAME
public static final String CLOCK_SETTING_NAME
Configuration property name to set a customClock
for Hibernate ORM to use when generating VM based timestamp values for e.g.CurrentTimestamp
,CreationTimestamp
,UpdateTimestamp
andVersionJavaType
methods.- Since:
- 6.6
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CurrentTimestampGeneration
public CurrentTimestampGeneration(CurrentTimestamp annotation, Member member, GeneratorCreationContext context)
-
CurrentTimestampGeneration
public CurrentTimestampGeneration(CreationTimestamp annotation, Member member, GeneratorCreationContext context)
-
CurrentTimestampGeneration
public CurrentTimestampGeneration(UpdateTimestamp annotation, Member member, GeneratorCreationContext context)
-
-
Method Detail
-
getClock
public static <T extends Clock> T getClock(SessionFactory sessionFactory)
-
generatedOnExecution
public boolean generatedOnExecution()
Description copied from interface:Generator
Determines if the property value is generated when a row is written to the database, or in Java code that executes before the row is written.- Generators which only implement
BeforeExecutionGenerator
must resultfalse
. - Generators which only implement
OnExecutionGenerator
must resulttrue
. - Generators which implement both subinterfaces may decide at runtime what value to return.
- Specified by:
generatedOnExecution
in interfaceBeforeExecutionGenerator
- Specified by:
generatedOnExecution
in interfaceGenerator
- Specified by:
generatedOnExecution
in interfaceOnExecutionGenerator
- Returns:
true
if the value is generated by the database as a side effect of the execution of aninsert
orupdate
statement, or false if it is generated in Java code before the statement is executed via JDBC.
- Generators which only implement
-
getEventTypes
public EnumSet<EventType> getEventTypes()
Description copied from interface:Generator
The event types for which this generator should be called to produce a new value.Identifier generators must return
EventTypeSets.INSERT_ONLY
.- Specified by:
getEventTypes
in interfaceGenerator
- Returns:
- a set of
EventType
s.
-
generate
public Object generate(SharedSessionContractImplementor session, Object owner, Object currentValue, EventType eventType)
Description copied from interface:BeforeExecutionGenerator
Generate a value.- Specified by:
generate
in interfaceBeforeExecutionGenerator
- Parameters:
session
- The session from which the request originates.owner
- The instance of the object owning the attribute for which we are generating a value.currentValue
- The current value assigned to the property, ornull
eventType
- The type of event that has triggered generation of a new value- Returns:
- The generated value
-
writePropertyValue
public boolean writePropertyValue()
Description copied from interface:OnExecutionGenerator
Determines if the property values are written to JDBC as the argument of a JDBC?
parameter.- Specified by:
writePropertyValue
in interfaceOnExecutionGenerator
-
referenceColumnsInSql
public boolean referenceColumnsInSql(Dialect dialect)
Description copied from interface:OnExecutionGenerator
Determines if the columns whose values are generated are included in the column list of the SQLinsert
orupdate
statement. For example, this method should return:true
if the value is generated by calling a SQL function likecurrent_timestamp
, orfalse
if the value is generated by a trigger, bygenerated always as
, or using a column default value.
- Specified by:
referenceColumnsInSql
in interfaceOnExecutionGenerator
- Returns:
true
if the column is included in the column list of the SQL statement.
-
getReferencedColumnValues
public String[] getReferencedColumnValues(Dialect dialect)
Description copied from interface:OnExecutionGenerator
A SQL expression indicating how to calculate the generated values when the mapped columns are included in the SQL statement. The SQL expressions might be:- function calls like
current_timestamp
ornextval('mysequence')
, or - syntactic markers like
default
.
- Specified by:
getReferencedColumnValues
in interfaceOnExecutionGenerator
- Parameters:
dialect
- The SQL dialect, allowing generation of an expression in dialect-specific SQL.- Returns:
- The column value to be used in the generated SQL statement.
- function calls like
-
-