Skip to content

Commit 082609e

Browse files
committed
Merge remote-tracking branch 'upstream/main' into main-perf
2 parents 8213667 + cf65a2d commit 082609e

File tree

26 files changed

+724
-281
lines changed

26 files changed

+724
-281
lines changed

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SybaseASELegacyDialect.java

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -266,56 +266,44 @@ public String currentTimestamp() {
266266
return "current_bigdatetime()";
267267
}
268268

269+
@Override
270+
public long getFractionalSecondPrecisionInNanos() {
271+
// Sybase supports microsecond precision
272+
// but when we use it we just get numerical
273+
// overflows from timestamp arithmetic
274+
return 1_000_000;
275+
}
276+
269277
@Override
270278
public String timestampaddPattern(TemporalUnit unit, TemporalType temporalType, IntervalType intervalType) {
271-
//TODO!!
272279
switch ( unit ) {
273280
case NANOSECOND:
281+
return "dateadd(ms,?2/1000000,?3)";
282+
// return "dateadd(mcs,?2/1000,?3)";
274283
case NATIVE:
275-
// If the driver or database do not support bigdatetime and bigtime types,
276-
// we try to operate on milliseconds instead
277-
if ( getVersion().isBefore( 15, 5 ) || jtdsDriver ) {
278-
return "dateadd(millisecond,?2/1000000,?3)";
279-
}
280-
else {
281-
return "dateadd(mcs,?2/1000,?3)";
282-
}
284+
return "dateadd(ms,?2,?3)";
285+
// return "dateadd(mcs,?2,?3)";
283286
default:
284287
return "dateadd(?1,?2,?3)";
285288
}
286289
}
287290

288-
@Override
289-
public long getFractionalSecondPrecisionInNanos() {
290-
// If the database does not support bigdatetime and bigtime types,
291-
// we try to operate on milliseconds instead
292-
if ( getVersion().isBefore( 15, 5 ) ) {
293-
return 1_000_000;
294-
}
295-
else {
296-
return 1_000;
297-
}
298-
}
299-
300291
@Override
301292
public String timestampdiffPattern(TemporalUnit unit, TemporalType fromTemporalType, TemporalType toTemporalType) {
302-
//TODO!!
303293
switch ( unit ) {
304294
case NANOSECOND:
295+
return "(cast(datediff(ms,?2,?3) as numeric(21))*1000000)";
296+
// return "(cast(datediff(mcs,?2,?3) as numeric(21))*1000)";
297+
// }
305298
case NATIVE:
306-
// If the database does not support bigdatetime and bigtime types,
307-
// we try to operate on milliseconds instead
308-
if ( getVersion().isBefore( 15, 5 ) ) {
309-
return "cast(datediff(ms,?2,?3) as numeric(21))";
310-
}
311-
else {
312-
return "cast(datediff(mcs,cast(?2 as bigdatetime),cast(?3 as bigdatetime)) as numeric(21))";
313-
}
299+
return "cast(datediff(ms,?2,?3) as numeric(21))";
300+
// return "cast(datediff(mcs,cast(?2 as bigdatetime),cast(?3 as bigdatetime)) as numeric(21))";
314301
default:
315302
return "datediff(?1,?2,?3)";
316303
}
317304
}
318305

306+
319307
@Override
320308
protected void registerDefaultKeywords() {
321309
super.registerDefaultKeywords();

hibernate-core/src/main/antlr/org/hibernate/grammars/hql/HqlParser.g4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,15 +902,15 @@ offsetDateTimeLiteral
902902
*/
903903
dateLiteral
904904
: LEFT_BRACE date RIGHT_BRACE
905-
| DATE date
905+
| LOCAL? DATE date
906906
;
907907

908908
/**
909909
* A literal time, in braces, or with the 'time' keyword
910910
*/
911911
timeLiteral
912912
: LEFT_BRACE time RIGHT_BRACE
913-
| TIME time
913+
| LOCAL? TIME time
914914
;
915915

916916
/**

hibernate-core/src/main/java/org/hibernate/cache/spi/entry/StandardCacheEntryImpl.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,11 @@ public Object[] assemble(
144144
.setId( id )
145145
.setPersister( persister );
146146

147-
final EventListenerGroup<PreLoadEventListener> listenerGroup = session
147+
session
148148
.getFactory()
149149
.getFastSessionServices()
150-
.eventListenerGroup_PRE_LOAD;
151-
for ( PreLoadEventListener listener : listenerGroup.listeners() ) {
152-
listener.onPreLoad( preLoadEvent );
153-
}
150+
.eventListenerGroup_PRE_LOAD
151+
.fireEventOnEachListener( preLoadEvent, PreLoadEventListener::onPreLoad );
154152

155153
persister.setPropertyValues( instance, state );
156154

hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,14 +1737,28 @@ public interface AvailableSettings {
17371737
String HBM2DDL_LOAD_SCRIPT_SOURCE = "javax.persistence.sql-load-script-source";
17381738

17391739
/**
1740-
* Reference to the {@link org.hibernate.tool.schema.spi.SqlScriptCommandExtractor} implementation
1741-
* class to use for parsing source/import files as defined by {@link #HBM2DDL_CREATE_SCRIPT_SOURCE},
1742-
* {@link #HBM2DDL_DROP_SCRIPT_SOURCE} or {@link #HBM2DDL_IMPORT_FILES}.
1740+
* The {@link org.hibernate.tool.schema.spi.SqlScriptCommandExtractor} implementation
1741+
* to use for parsing source/import files specified by {@link #HBM2DDL_CREATE_SCRIPT_SOURCE},
1742+
* {@link #HBM2DDL_DROP_SCRIPT_SOURCE} or {@link #HBM2DDL_IMPORT_FILES}. Either:
1743+
* <ul>
1744+
* <li>an instance of {@link org.hibernate.tool.schema.spi.SqlScriptCommandExtractor},
1745+
* <li>a {@link Class} object representing a class that implements {@code SqlScriptCommandExtractor},
1746+
* or
1747+
* <li>the name of a class that implements {@code SqlScriptCommandExtractor}.
1748+
* </ul>
17431749
* <p>
1744-
* Reference may refer to an instance, a {@link Class} object representing a class that implements
1745-
* {@code ImportSqlCommandExtractor}, or the name of a class that implements {@code ImportSqlCommandExtractor}.
1750+
* The correct extractor to use depends on the format of the SQL script:
1751+
* <ul>
1752+
* <li>if the script has one complete SQL statement per line, use
1753+
* {@link org.hibernate.tool.schema.internal.script.SingleLineSqlScriptExtractor}, or
1754+
* <li>if a script contains statements spread over multiple lines, use
1755+
* {@link org.hibernate.tool.schema.internal.script.MultiLineSqlScriptExtractor}.
1756+
* </ul>
17461757
* <p>
1747-
* The default value is {@link org.hibernate.tool.schema.internal.script.SingleLineSqlScriptExtractor}.
1758+
* The default value is {@code org.hibernate.tool.schema.internal.script.SingleLineSqlScriptExtractor}.
1759+
*
1760+
* @see org.hibernate.tool.schema.internal.script.SingleLineSqlScriptExtractor
1761+
* @see org.hibernate.tool.schema.internal.script.MultiLineSqlScriptExtractor
17481762
*/
17491763
String HBM2DDL_IMPORT_FILES_SQL_EXTRACTOR = "hibernate.hbm2ddl.import_files_sql_extractor";
17501764

hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
import java.sql.ResultSet;
1212
import java.sql.SQLException;
1313
import java.sql.Types;
14+
import java.time.temporal.TemporalAccessor;
15+
import java.util.Calendar;
16+
import java.util.Date;
1417
import java.util.List;
18+
import java.util.TimeZone;
1519

1620
import org.hibernate.LockOptions;
1721
import org.hibernate.boot.model.FunctionContributions;
@@ -94,6 +98,10 @@
9498
import static org.hibernate.type.SqlTypes.TINYINT;
9599
import static org.hibernate.type.SqlTypes.VARBINARY;
96100
import static org.hibernate.type.SqlTypes.VARCHAR;
101+
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsDate;
102+
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsLocalTime;
103+
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithMillis;
104+
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithNanos;
97105

98106
/**
99107
* A {@linkplain Dialect SQL dialect} for DB2 for LUW (Linux, Unix, and Windows) version 10.5 and above.
@@ -526,6 +534,83 @@ public String timestampaddPattern(TemporalUnit unit, TemporalType temporalType,
526534
return pattern.toString();
527535
}
528536

537+
@Override
538+
public void appendDateTimeLiteral(
539+
SqlAppender appender,
540+
TemporalAccessor temporalAccessor,
541+
TemporalType precision,
542+
TimeZone jdbcTimeZone) {
543+
switch ( precision ) {
544+
case DATE:
545+
appender.appendSql( "date '" );
546+
appendAsDate( appender, temporalAccessor );
547+
appender.appendSql( '\'' );
548+
break;
549+
case TIME:
550+
appender.appendSql( "time '" );
551+
appendAsLocalTime( appender, temporalAccessor );
552+
appender.appendSql( '\'' );
553+
break;
554+
case TIMESTAMP:
555+
appender.appendSql( "timestamp '" );
556+
appendAsTimestampWithNanos( appender, temporalAccessor, false, jdbcTimeZone );
557+
appender.appendSql( '\'' );
558+
break;
559+
default:
560+
throw new IllegalArgumentException();
561+
}
562+
}
563+
564+
@Override
565+
public void appendDateTimeLiteral(SqlAppender appender, Date date, TemporalType precision, TimeZone jdbcTimeZone) {
566+
switch ( precision ) {
567+
case DATE:
568+
appender.appendSql( "date '" );
569+
appendAsDate( appender, date );
570+
appender.appendSql( '\'' );
571+
break;
572+
case TIME:
573+
appender.appendSql( "time '" );
574+
appendAsLocalTime( appender, date );
575+
appender.appendSql( '\'' );
576+
break;
577+
case TIMESTAMP:
578+
appender.appendSql( "timestamp '" );
579+
appendAsTimestampWithNanos( appender, date, jdbcTimeZone );
580+
appender.appendSql( '\'' );
581+
break;
582+
default:
583+
throw new IllegalArgumentException();
584+
}
585+
}
586+
587+
@Override
588+
public void appendDateTimeLiteral(
589+
SqlAppender appender,
590+
Calendar calendar,
591+
TemporalType precision,
592+
TimeZone jdbcTimeZone) {
593+
switch ( precision ) {
594+
case DATE:
595+
appender.appendSql( "date '" );
596+
appendAsDate( appender, calendar );
597+
appender.appendSql( '\'' );
598+
break;
599+
case TIME:
600+
appender.appendSql( "time '" );
601+
appendAsLocalTime( appender, calendar );
602+
appender.appendSql( '\'' );
603+
break;
604+
case TIMESTAMP:
605+
appender.appendSql( "timestamp '" );
606+
appendAsTimestampWithMillis( appender, calendar, jdbcTimeZone );
607+
appender.appendSql( '\'' );
608+
break;
609+
default:
610+
throw new IllegalArgumentException();
611+
}
612+
}
613+
529614
@Override
530615
public boolean dropConstraints() {
531616
return false;

hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@
239239
import static org.hibernate.type.descriptor.DateTimeUtils.JDBC_ESCAPE_START_TIME;
240240
import static org.hibernate.type.descriptor.DateTimeUtils.JDBC_ESCAPE_START_TIMESTAMP;
241241
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsDate;
242+
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsLocalTime;
242243
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTime;
243244
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithMillis;
244245
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithNanos;
@@ -4621,7 +4622,22 @@ public int getDoublePrecision() {
46214622
*
46224623
* @return the precision, specified as a quantity of
46234624
* nanoseconds
4625+
*
46244626
* @see TemporalUnit#NATIVE
4627+
*
4628+
* @implNote Getting this right is very important. It
4629+
* would be great if all platforms supported
4630+
* datetime arithmetic with nanosecond
4631+
* precision, since that is how we represent
4632+
* {@link Duration}. But they don't, and we
4633+
* don't want to fill up the SQL expression
4634+
* with many conversions to/from nanoseconds.
4635+
* (Not to mention the problems with numeric
4636+
* overflow that this sometimes causes.) So
4637+
* we need to pick the right value here,
4638+
* and implement {@link #timestampaddPattern}
4639+
* and {@link #timestampdiffPattern} consistent
4640+
* with our choice.
46254641
*/
46264642
public long getFractionalSecondPrecisionInNanos() {
46274643
return 1; //default to nanoseconds for now
@@ -5068,7 +5084,7 @@ public void appendDateTimeLiteral(SqlAppender appender, Date date, TemporalType
50685084
break;
50695085
case TIME:
50705086
appender.appendSql( JDBC_ESCAPE_START_TIME );
5071-
appendAsTime( appender, date );
5087+
appendAsLocalTime( appender, date );
50725088
appender.appendSql( JDBC_ESCAPE_END );
50735089
break;
50745090
case TIMESTAMP:
@@ -5098,7 +5114,7 @@ public void appendDateTimeLiteral(
50985114
break;
50995115
case TIME:
51005116
appender.appendSql( JDBC_ESCAPE_START_TIME );
5101-
appendAsTime( appender, calendar );
5117+
appendAsLocalTime( appender, calendar );
51025118
appender.appendSql( JDBC_ESCAPE_END );
51035119
break;
51045120
case TIMESTAMP:

0 commit comments

Comments
 (0)