9
9
import org .hibernate .annotations .SourceType ;
10
10
import org .hibernate .dialect .Dialect ;
11
11
import org .hibernate .engine .jdbc .spi .JdbcCoordinator ;
12
+ import org .hibernate .engine .jdbc .spi .StatementPreparer ;
12
13
import org .hibernate .engine .spi .SharedSessionContractImplementor ;
13
14
import org .hibernate .generator .EventType ;
14
15
import org .hibernate .generator .EventTypeSets ;
@@ -79,23 +80,21 @@ public EnumSet<EventType> getEventTypes() {
79
80
80
81
@ Override
81
82
public Object generate (SharedSessionContractImplementor session , Object owner , Object currentValue , EventType eventType ) {
82
- if ( valueGenerator == null ) {
83
- return propertyType .wrap ( getCurrentTimestamp ( session ), session );
84
- }
85
- else {
86
- return valueGenerator .generate ();
87
- }
83
+ return valueGenerator == null
84
+ ? propertyType .wrap ( getCurrentTimestamp ( session ), session )
85
+ : valueGenerator .generate ();
88
86
}
89
87
90
88
private Timestamp getCurrentTimestamp (SharedSessionContractImplementor session ) {
91
- Dialect dialect = session .getJdbcServices ().getJdbcEnvironment ().getDialect ();
92
- boolean callable = dialect .isCurrentTimestampSelectStringCallable ();
93
- String timestampSelectString = dialect .getCurrentTimestampSelectString ();
89
+ final Dialect dialect = session .getJdbcServices ().getJdbcEnvironment ().getDialect ();
90
+ final boolean callable = dialect .isCurrentTimestampSelectStringCallable ();
91
+ final String timestampSelectString = dialect .getCurrentTimestampSelectString ();
92
+ final JdbcCoordinator coordinator = session .getJdbcCoordinator ();
93
+ final StatementPreparer statementPreparer = coordinator .getStatementPreparer ();
94
94
PreparedStatement statement = null ;
95
- JdbcCoordinator coordinator = session .getJdbcCoordinator ();
96
95
try {
97
- statement = prepareStatement ( coordinator , timestampSelectString , callable );
98
- Timestamp ts = callable
96
+ statement = statementPreparer . prepareStatement ( timestampSelectString , callable );
97
+ final Timestamp ts = callable
99
98
? extractCalledResult ( statement , coordinator , timestampSelectString )
100
99
: extractResult ( statement , coordinator , timestampSelectString );
101
100
logResult ( ts );
@@ -116,23 +115,16 @@ private Timestamp getCurrentTimestamp(SharedSessionContractImplementor session)
116
115
}
117
116
}
118
117
119
- private static PreparedStatement prepareStatement (
120
- JdbcCoordinator coordinator ,
121
- String timestampSelectString ,
122
- boolean callable ) {
123
- return coordinator .getStatementPreparer ().prepareStatement ( timestampSelectString , callable );
124
- }
125
-
126
118
private static Timestamp extractResult (PreparedStatement statement , JdbcCoordinator coordinator , String sql )
127
119
throws SQLException {
128
- ResultSet resultSet = coordinator .getResultSetReturn ().extract ( statement , sql );
120
+ final ResultSet resultSet = coordinator .getResultSetReturn ().extract ( statement , sql );
129
121
resultSet .next ();
130
122
return resultSet .getTimestamp ( 1 );
131
123
}
132
124
133
125
private static Timestamp extractCalledResult (PreparedStatement statement , JdbcCoordinator coordinator , String sql )
134
126
throws SQLException {
135
- CallableStatement callable = (CallableStatement ) statement ;
127
+ final CallableStatement callable = (CallableStatement ) statement ;
136
128
callable .registerOutParameter ( 1 , TIMESTAMP );
137
129
coordinator .getResultSetReturn ().execute ( callable , sql );
138
130
return callable .getTimestamp ( 1 );
0 commit comments