use of com.blazebit.persistence.spi.DbmsDialect in project blaze-persistence by Blazebit.
the class CriteriaBuilderConfigurationImpl method loadFunctions.
// NOTE: When adding a function here, you might want to also add it in AbstractCoreTest so it is recognized
@SuppressWarnings("checkstyle:methodlength")
private void loadFunctions() {
JpqlFunctionGroup jpqlFunctionGroup;
// limit
jpqlFunctionGroup = new JpqlFunctionGroup(LimitFunction.FUNCTION_NAME, false);
jpqlFunctionGroup.add(null, new LimitFunction(dbmsDialects.get(null)));
jpqlFunctionGroup.add("mysql", new LimitFunction(dbmsDialects.get("mysql")));
jpqlFunctionGroup.add("mysql8", new LimitFunction(dbmsDialects.get("mysql8")));
jpqlFunctionGroup.add("oracle", new LimitFunction(dbmsDialects.get("oracle")));
jpqlFunctionGroup.add("db2", new LimitFunction(dbmsDialects.get("db2")));
// Does not support limit
jpqlFunctionGroup.add("sybase", null);
jpqlFunctionGroup.add("microsoft", new LimitFunction(dbmsDialects.get("microsoft")));
registerFunction(jpqlFunctionGroup);
// page_position
jpqlFunctionGroup = new JpqlFunctionGroup(PagePositionFunction.FUNCTION_NAME, false);
jpqlFunctionGroup.add(null, new PagePositionFunction());
jpqlFunctionGroup.add("mysql", new MySQLPagePositionFunction());
jpqlFunctionGroup.add("mysql8", new MySQLPagePositionFunction());
jpqlFunctionGroup.add("oracle", new OraclePagePositionFunction());
jpqlFunctionGroup.add("sybase", new TransactSQLPagePositionFunction());
jpqlFunctionGroup.add("microsoft", new TransactSQLPagePositionFunction());
registerFunction(jpqlFunctionGroup);
// entity_function
registerFunction(EntityFunction.FUNCTION_NAME, new EntityFunction());
// nullfn
registerFunction(NullfnFunction.FUNCTION_NAME, new NullfnFunction());
// collection_dml_support
registerFunction(CollectionDmlSupportFunction.FUNCTION_NAME, new CollectionDmlSupportFunction());
// param
registerFunction(ParamFunction.FUNCTION_NAME, new ParamFunction());
// exist
registerFunction(ExistFunction.FUNCTION_NAME, new ExistFunction());
// replace
registerFunction(ReplaceFunction.FUNCTION_NAME, new ReplaceFunction());
// chr
jpqlFunctionGroup = new JpqlFunctionGroup(ChrFunction.FUNCTION_NAME, false);
jpqlFunctionGroup.add(null, new ChrFunction());
jpqlFunctionGroup.add("mysql", new CharChrFunction());
jpqlFunctionGroup.add("mysql8", new CharChrFunction());
jpqlFunctionGroup.add("microsoft", new CharChrFunction());
jpqlFunctionGroup.add("sybase", new CharChrFunction());
registerFunction(jpqlFunctionGroup);
// base64
jpqlFunctionGroup = new JpqlFunctionGroup(Base64Function.FUNCTION_NAME, false);
jpqlFunctionGroup.add(null, new Base64Function());
jpqlFunctionGroup.add("postgresql", new PostgreSQLBase64Function());
registerFunction(jpqlFunctionGroup);
for (SetOperationType setType : SetOperationType.values()) {
// Use a prefix because hibernate uses UNION as keyword
jpqlFunctionGroup = new JpqlFunctionGroup("set_" + setType.name().toLowerCase(), false);
for (Map.Entry<String, DbmsDialect> dbmsDialectEntry : dbmsDialects.entrySet()) {
jpqlFunctionGroup.add(dbmsDialectEntry.getKey(), new SetFunction(setType, dbmsDialectEntry.getValue()));
}
registerFunction(jpqlFunctionGroup);
}
// temporal literals
registerFunction(LiteralTimeFunction.FUNCTION_NAME, new LiteralTimeFunction());
registerFunction(LiteralDateFunction.FUNCTION_NAME, new LiteralDateFunction());
registerFunction(LiteralTimestampFunction.FUNCTION_NAME, new LiteralTimestampFunction());
registerFunction(LiteralDateTimestampFunction.FUNCTION_NAME, new LiteralDateTimestampFunction());
registerFunction(LiteralCalendarFunction.FUNCTION_NAME, new LiteralCalendarFunction());
// treat
registerNamedType("Boolean", Boolean.class);
registerNamedType("Byte", Byte.class);
registerNamedType("Short", Short.class);
registerNamedType("Integer", Integer.class);
registerNamedType("Long", Long.class);
registerNamedType("Float", Float.class);
registerNamedType("Double", Double.class);
registerNamedType("Character", Character.class);
registerNamedType("String", String.class);
registerNamedType("BigInteger", BigInteger.class);
registerNamedType("BigDecimal", BigDecimal.class);
registerNamedType("Time", Time.class);
registerNamedType("Date", java.sql.Date.class);
registerNamedType("Timestamp", Timestamp.class);
registerNamedType("TimeZone", TimeZone.class);
registerNamedType("Calendar", Calendar.class);
registerNamedType("GregorianCalendar", GregorianCalendar.class);
registerNamedType("Class", java.lang.Class.class);
registerNamedType("Currency", java.util.Currency.class);
registerNamedType("Locale", java.util.Locale.class);
registerNamedType("UUID", java.util.UUID.class);
registerNamedType("URL", java.net.URL.class);
// Java 8 time types
try {
registerNamedType("LocalDate", Class.forName("java.time.LocalDate"));
registerNamedType("LocalTime", Class.forName("java.time.LocalTime"));
registerNamedType("LocalDateTime", Class.forName("java.time.LocalDateTime"));
registerNamedType("OffsetTime", Class.forName("java.time.OffsetTime"));
registerNamedType("OffsetDateTime", Class.forName("java.time.OffsetDateTime"));
registerNamedType("ZonedDateTime", Class.forName("java.time.ZonedDateTime"));
registerNamedType("Duration", Class.forName("java.time.Duration"));
registerNamedType("Instant", Class.forName("java.time.Instant"));
registerNamedType("MonthDay", Class.forName("java.time.MonthDay"));
registerNamedType("Year", Class.forName("java.time.Year"));
registerNamedType("YearMonth", Class.forName("java.time.YearMonth"));
registerNamedType("Period", Class.forName("java.time.Period"));
registerNamedType("ZoneId", Class.forName("java.time.ZoneId"));
registerNamedType("ZoneOffset", Class.forName("java.time.ZoneOffset"));
registerFunction(LiteralLocalDateFunction.FUNCTION_NAME, new LiteralLocalDateFunction());
registerFunction(LiteralLocalTimeFunction.FUNCTION_NAME, new LiteralLocalTimeFunction());
registerFunction(LiteralLocalDateTimeFunction.FUNCTION_NAME, new LiteralLocalDateTimeFunction());
registerFunction(LiteralInstantFunction.FUNCTION_NAME, new LiteralInstantFunction());
registerFunction(LiteralZonedDateTimeFunction.FUNCTION_NAME, new LiteralZonedDateTimeFunction());
registerFunction(LiteralOffsetTimeFunction.FUNCTION_NAME, new LiteralOffsetTimeFunction());
registerFunction(LiteralOffsetDateTimeFunction.FUNCTION_NAME, new LiteralOffsetDateTimeFunction());
} catch (ClassNotFoundException ex) {
// If they aren't found, we ignore them
}
// cast
registerFunction(new JpqlFunctionGroup("cast_boolean"));
registerFunction(new JpqlFunctionGroup("cast_byte"));
registerFunction(new JpqlFunctionGroup("cast_short"));
registerFunction(new JpqlFunctionGroup("cast_integer"));
registerFunction(new JpqlFunctionGroup("cast_long"));
registerFunction(new JpqlFunctionGroup("cast_float"));
registerFunction(new JpqlFunctionGroup("cast_double"));
registerFunction(new JpqlFunctionGroup("cast_character"));
registerFunction(new JpqlFunctionGroup("cast_string"));
registerFunction(new JpqlFunctionGroup("cast_biginteger"));
registerFunction(new JpqlFunctionGroup("cast_bigdecimal"));
registerFunction(new JpqlFunctionGroup("cast_time"));
registerFunction(new JpqlFunctionGroup("cast_date"));
registerFunction(new JpqlFunctionGroup("cast_timestamp"));
registerFunction(new JpqlFunctionGroup("cast_calendar"));
for (Map.Entry<String, DbmsDialect> dbmsDialectEntry : dbmsDialects.entrySet()) {
for (Class<?> type : BasicCastTypes.TYPES) {
CastFunction castFunction;
if ("db2".equals(dbmsDialectEntry.getKey())) {
castFunction = new DB2CastFunction(type, dbmsDialectEntry.getValue());
} else {
castFunction = new CastFunction(type, dbmsDialectEntry.getValue());
}
functions.get("cast_" + type.getSimpleName().toLowerCase()).add(dbmsDialectEntry.getKey(), castFunction);
}
}
// concat
jpqlFunctionGroup = new JpqlFunctionGroup(ConcatFunction.FUNCTION_NAME, false);
jpqlFunctionGroup.add(null, PipeBasedConcatFunction.INSTANCE);
jpqlFunctionGroup.add("mysql", ConcatFunction.INSTANCE);
jpqlFunctionGroup.add("mysql8", ConcatFunction.INSTANCE);
jpqlFunctionGroup.add("microsoft", PlusBasedConcatFunction.INSTANCE);
jpqlFunctionGroup.add("sybase", PlusBasedConcatFunction.INSTANCE);
registerFunction(jpqlFunctionGroup);
// group_concat
jpqlFunctionGroup = new JpqlFunctionGroup(AbstractGroupConcatFunction.FUNCTION_NAME, true);
jpqlFunctionGroup.add("db2", new DB2GroupConcatFunction());
jpqlFunctionGroup.add("oracle", new OracleListaggGroupConcatFunction());
jpqlFunctionGroup.add("h2", new H2GroupConcatFunction());
jpqlFunctionGroup.add("mysql", new MySQLGroupConcatFunction());
jpqlFunctionGroup.add("mysql8", new MySQLGroupConcatFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLGroupConcatFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLGroupConcatFunction());
registerFunction(jpqlFunctionGroup);
// listagg
jpqlFunctionGroup = new JpqlFunctionGroup("listagg", JpqlFunctionKind.ORDERED_SET_AGGREGATE);
jpqlFunctionGroup.add("db2", new DB2GroupConcatWindowFunction(dbmsDialects.get("db2")));
jpqlFunctionGroup.add("oracle", new OracleListaggGroupConcatWindowFunction(dbmsDialects.get("oracle")));
jpqlFunctionGroup.add("h2", new H2GroupConcatWindowFunction(dbmsDialects.get("h2")));
jpqlFunctionGroup.add("mysql", new MySQLGroupConcatWindowFunction(dbmsDialects.get("mysql")));
jpqlFunctionGroup.add("mysql8", new MySQLGroupConcatWindowFunction(dbmsDialects.get("mysql8")));
jpqlFunctionGroup.add("microsoft", new MSSQLGroupConcatFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLGroupConcatWindowFunction(dbmsDialects.get("postgresql")));
registerFunction(jpqlFunctionGroup);
// window_group_concat
jpqlFunctionGroup = new JpqlFunctionGroup("window_group_concat", JpqlFunctionKind.WINDOW);
jpqlFunctionGroup.add("db2", new DB2GroupConcatWindowFunction(dbmsDialects.get("db2")));
jpqlFunctionGroup.add("oracle", new OracleListaggGroupConcatWindowFunction(dbmsDialects.get("oracle")));
jpqlFunctionGroup.add("h2", new H2GroupConcatWindowFunction(dbmsDialects.get("h2")));
jpqlFunctionGroup.add("mysql", new MySQLGroupConcatWindowFunction(dbmsDialects.get("mysql")));
jpqlFunctionGroup.add("mysql8", new MySQLGroupConcatWindowFunction(dbmsDialects.get("mysql8")));
jpqlFunctionGroup.add("postgresql", new PostgreSQLGroupConcatWindowFunction(dbmsDialects.get("postgresql")));
registerFunction(jpqlFunctionGroup);
// datetime
jpqlFunctionGroup = new JpqlFunctionGroup("year", false);
jpqlFunctionGroup.add(null, new YearFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLYearFunction());
jpqlFunctionGroup.add("access", new AccessYearFunction());
jpqlFunctionGroup.add("db2", new DB2YearFunction());
jpqlFunctionGroup.add("derby", new DerbyYearFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLYearFunction());
jpqlFunctionGroup.add("sybase", new SybaseYearFunction());
jpqlFunctionGroup.add("sqlite", new SqliteYearFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("year_of_week", false);
jpqlFunctionGroup.add(null, new YearOfWeekFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLYearOfWeekFunction());
jpqlFunctionGroup.add("db2", new DB2YearOfWeekFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLYearOfWeekFunction());
jpqlFunctionGroup.add("mysql", new MySQLYearOfWeekFunction());
jpqlFunctionGroup.add("mysql8", new MySQLYearOfWeekFunction());
jpqlFunctionGroup.add("oracle", new OracleYearOfWeekFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("year_week", false);
jpqlFunctionGroup.add(null, new YearWeekFunction());
jpqlFunctionGroup.add("mysql", new MySQLYearWeekFunction());
jpqlFunctionGroup.add("mysql8", new MySQLYearWeekFunction());
jpqlFunctionGroup.add("db2", new DB2YearWeekFunction());
jpqlFunctionGroup.add("oracle", new OracleYearWeekFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLYearWeekFunction());
jpqlFunctionGroup.add("h2", new H2YearWeekFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLYearWeekFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("month", false);
jpqlFunctionGroup.add(null, new MonthFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLMonthFunction());
jpqlFunctionGroup.add("access", new AccessMonthFunction());
jpqlFunctionGroup.add("db2", new DB2MonthFunction());
jpqlFunctionGroup.add("derby", new DerbyMonthFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLMonthFunction());
jpqlFunctionGroup.add("sybase", new SybaseMonthFunction());
jpqlFunctionGroup.add("sqlite", new SqliteMonthFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("week", false);
jpqlFunctionGroup.add(null, new IsoWeekFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLIsoWeekFunction());
jpqlFunctionGroup.add("access", new AccessIsoWeekFunction());
jpqlFunctionGroup.add("db2", new DB2IsoWeekFunction());
jpqlFunctionGroup.add("h2", new H2IsoWeekFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLIsoWeekFunction());
jpqlFunctionGroup.add("sybase", new SybaseIsoWeekFunction());
jpqlFunctionGroup.add("sqlite", new SqliteIsoWeekFunction());
jpqlFunctionGroup.add("mysql", new MySQLIsoWeekFunction());
jpqlFunctionGroup.add("mysql8", new MySQLIsoWeekFunction());
jpqlFunctionGroup.add("oracle", new OracleIsoWeekFunction());
jpqlFunctionGroup.add("sqlite", new SqliteIsoWeekFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("iso_week", false);
jpqlFunctionGroup.add(null, new IsoWeekFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLIsoWeekFunction());
jpqlFunctionGroup.add("access", new AccessIsoWeekFunction());
jpqlFunctionGroup.add("db2", new DB2IsoWeekFunction());
jpqlFunctionGroup.add("h2", new H2IsoWeekFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLIsoWeekFunction());
jpqlFunctionGroup.add("sybase", new SybaseIsoWeekFunction());
jpqlFunctionGroup.add("sqlite", new SqliteIsoWeekFunction());
jpqlFunctionGroup.add("mysql", new MySQLIsoWeekFunction());
jpqlFunctionGroup.add("mysql8", new MySQLIsoWeekFunction());
jpqlFunctionGroup.add("oracle", new OracleIsoWeekFunction());
jpqlFunctionGroup.add("sqlite", new SqliteIsoWeekFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("week_in_year", false);
jpqlFunctionGroup.add(null, new WeekInYearFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLWeekInYearFunction());
jpqlFunctionGroup.add("db2", new DB2WeekInYearFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLWeekInYearFunction());
jpqlFunctionGroup.add("mysql", new MySQLWeekInYearFunction());
jpqlFunctionGroup.add("mysql8", new MySQLWeekInYearFunction());
jpqlFunctionGroup.add("oracle", new OracleWeekInYearFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("quarter", false);
jpqlFunctionGroup.add(null, new QuarterFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLQuarterFunction());
jpqlFunctionGroup.add("access", new AccessQuarterFunction());
jpqlFunctionGroup.add("db2", new DB2QuarterFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLQuarterFunction());
jpqlFunctionGroup.add("sybase", new SybaseQuarterFunction());
jpqlFunctionGroup.add("sqlite", new SqliteQuarterFunction());
jpqlFunctionGroup.add("oracle", new OracleQuarterFunction());
jpqlFunctionGroup.add("sqlite", new SqliteQuarterFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("day", false);
jpqlFunctionGroup.add(null, new DayFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLDayFunction());
jpqlFunctionGroup.add("access", new AccessDayFunction());
jpqlFunctionGroup.add("db2", new DB2DayFunction());
jpqlFunctionGroup.add("derby", new DerbyDayFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLDayFunction());
jpqlFunctionGroup.add("sybase", new SybaseDayFunction());
jpqlFunctionGroup.add("sqlite", new SqliteDayFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("dayofyear", false);
jpqlFunctionGroup.add(null, new DayOfYearFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLDayOfYearFunction());
jpqlFunctionGroup.add("access", new AccessDayOfYearFunction());
jpqlFunctionGroup.add("db2", new DB2DayOfYearFunction());
jpqlFunctionGroup.add("mysql", new MySQLDayOfYearFunction());
jpqlFunctionGroup.add("mysql8", new MySQLDayOfYearFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLDayOfYearFunction());
jpqlFunctionGroup.add("sybase", new SybaseDayOfYearFunction());
jpqlFunctionGroup.add("oracle", new OracleDayOfYearFunction());
jpqlFunctionGroup.add("sqlite", new SqliteDayOfYearFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("dayofweek", false);
jpqlFunctionGroup.add(null, new DayOfWeekFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLDayOfWeekFunction());
jpqlFunctionGroup.add("access", new AccessDayOfWeekFunction());
jpqlFunctionGroup.add("db2", new DB2DayOfWeekFunction());
jpqlFunctionGroup.add("mysql", new MySQLDayOfWeekFunction());
jpqlFunctionGroup.add("mysql8", new MySQLDayOfWeekFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLDayOfWeekFunction());
jpqlFunctionGroup.add("sybase", new SybaseDayOfWeekFunction());
jpqlFunctionGroup.add("oracle", new OracleDayOfWeekFunction());
jpqlFunctionGroup.add("sqlite", new SqliteDayOfWeekFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("isodayofweek", false);
jpqlFunctionGroup.add(null, new IsoDayOfWeekFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLIsoDayOfWeekFunction());
jpqlFunctionGroup.add("access", new AccessIsoDayOfWeekFunction());
jpqlFunctionGroup.add("db2", new DB2IsoDayOfWeekFunction());
jpqlFunctionGroup.add("mysql", new MySQLIsoDayOfWeekFunction());
jpqlFunctionGroup.add("mysql8", new MySQLIsoDayOfWeekFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLIsoDayOfWeekFunction());
jpqlFunctionGroup.add("sybase", new SybaseIsoDayOfWeekFunction());
jpqlFunctionGroup.add("oracle", new OracleIsoDayOfWeekFunction());
jpqlFunctionGroup.add("sqlite", new SqliteIsoDayOfWeekFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("hour", false);
jpqlFunctionGroup.add(null, new HourFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLHourFunction());
jpqlFunctionGroup.add("access", new AccessHourFunction());
jpqlFunctionGroup.add("db2", new DB2HourFunction());
jpqlFunctionGroup.add("derby", new DerbyHourFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLHourFunction());
jpqlFunctionGroup.add("sybase", new SybaseHourFunction());
jpqlFunctionGroup.add("oracle", new OracleHourFunction());
jpqlFunctionGroup.add("sqlite", new SqliteHourFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("minute", false);
jpqlFunctionGroup.add(null, new MinuteFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLMinuteFunction());
jpqlFunctionGroup.add("access", new AccessMinuteFunction());
jpqlFunctionGroup.add("db2", new DB2MinuteFunction());
jpqlFunctionGroup.add("derby", new DerbyMinuteFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLMinuteFunction());
jpqlFunctionGroup.add("sybase", new SybaseMinuteFunction());
jpqlFunctionGroup.add("oracle", new OracleMinuteFunction());
jpqlFunctionGroup.add("sqlite", new SqliteMinuteFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("second", false);
jpqlFunctionGroup.add(null, new SecondFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLSecondFunction());
jpqlFunctionGroup.add("access", new AccessSecondFunction());
jpqlFunctionGroup.add("db2", new DB2SecondFunction());
jpqlFunctionGroup.add("derby", new DerbySecondFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLSecondFunction());
jpqlFunctionGroup.add("sybase", new SybaseSecondFunction());
jpqlFunctionGroup.add("oracle", new OracleSecondFunction());
jpqlFunctionGroup.add("sqlite", new SqliteSecondFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("millisecond", false);
jpqlFunctionGroup.add(null, new MillisecondFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLMillisecondFunction());
jpqlFunctionGroup.add("db2", new DB2MillisecondFunction());
jpqlFunctionGroup.add("mysql", new MySQLMillisecondFunction());
jpqlFunctionGroup.add("mysql8", new MySQLMillisecondFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLMillisecondFunction());
jpqlFunctionGroup.add("sybase", new SybaseMillisecondFunction());
jpqlFunctionGroup.add("oracle", new OracleMillisecondFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("microsecond", false);
jpqlFunctionGroup.add(null, new MicrosecondFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLMicrosecondFunction());
jpqlFunctionGroup.add("db2", new DB2MicrosecondFunction());
jpqlFunctionGroup.add("mysql", new MySQLMicrosecondFunction());
jpqlFunctionGroup.add("mysql8", new MySQLMicrosecondFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLMicrosecondFunction());
jpqlFunctionGroup.add("sybase", new SybaseMicrosecondFunction());
jpqlFunctionGroup.add("oracle", new OracleMicrosecondFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("epoch", false);
jpqlFunctionGroup.add(null, new DefaultEpochFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLEpochFunction());
jpqlFunctionGroup.add("oracle", new OracleEpochFunction());
jpqlFunctionGroup.add("db2", new DB2EpochFunction());
jpqlFunctionGroup.add("mysql", new MySQLEpochFunction());
jpqlFunctionGroup.add("mysql8", new MySQLEpochFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("epoch_seconds", false);
jpqlFunctionGroup.add(null, new DefaultEpochFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLEpochFunction());
jpqlFunctionGroup.add("oracle", new OracleEpochFunction());
jpqlFunctionGroup.add("db2", new DB2EpochFunction());
jpqlFunctionGroup.add("mysql", new MySQLEpochFunction());
jpqlFunctionGroup.add("mysql8", new MySQLEpochFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("epoch_days", false);
jpqlFunctionGroup.add(null, new DefaultEpochDayFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLEpochDayFunction());
jpqlFunctionGroup.add("oracle", new OracleEpochDayFunction());
jpqlFunctionGroup.add("db2", new DB2EpochDayFunction());
jpqlFunctionGroup.add("mysql", new MySQLEpochDayFunction());
jpqlFunctionGroup.add("mysql8", new MySQLEpochDayFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("epoch_milliseconds", false);
jpqlFunctionGroup.add(null, new DefaultEpochMillisecondFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLEpochMillisecondFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLEpochMillisecondFunction());
jpqlFunctionGroup.add("oracle", new OracleEpochMillisecondFunction());
jpqlFunctionGroup.add("db2", new DB2EpochMillisecondFunction());
jpqlFunctionGroup.add("mysql", new MySQLEpochMillisecondFunction());
jpqlFunctionGroup.add("mysql8", new MySQLEpochMillisecondFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("epoch_microseconds", false);
jpqlFunctionGroup.add(null, new DefaultEpochMicrosecondFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLEpochMicrosecondFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLEpochMicrosecondFunction());
jpqlFunctionGroup.add("oracle", new OracleEpochMicrosecondFunction());
jpqlFunctionGroup.add("db2", new DB2EpochMicrosecondFunction());
jpqlFunctionGroup.add("mysql", new MySQLEpochMicrosecondFunction());
jpqlFunctionGroup.add("mysql8", new MySQLEpochMicrosecondFunction());
registerFunction(jpqlFunctionGroup);
// dateadd
jpqlFunctionGroup = new JpqlFunctionGroup(DayAddFunction.NAME, false);
jpqlFunctionGroup.add(null, new DayAddFunction());
jpqlFunctionGroup.add("db2", new DB2DayAddFunction());
jpqlFunctionGroup.add("h2", new H2DayAddFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLDayAddFunction());
jpqlFunctionGroup.add("mysql", new MySQLDayAddFunction());
jpqlFunctionGroup.add("mysql8", new MySQLDayAddFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLDayAddFunction());
jpqlFunctionGroup.add("oracle", new OracleDayAddFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup(HourAddFunction.NAME, false);
jpqlFunctionGroup.add(null, new HourAddFunction());
jpqlFunctionGroup.add("db2", new DB2HourAddFunction());
jpqlFunctionGroup.add("h2", new H2HourAddFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLHourAddFunction());
jpqlFunctionGroup.add("mysql", new MySQLHourAddFunction());
jpqlFunctionGroup.add("mysql8", new MySQLHourAddFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLHourAddFunction());
jpqlFunctionGroup.add("oracle", new OracleHourAddFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup(MicrosecondsAddFunction.NAME, false);
jpqlFunctionGroup.add(null, new MicrosecondsAddFunction());
jpqlFunctionGroup.add("db2", new DB2MicrosecondsAddFunction());
jpqlFunctionGroup.add("h2", new H2MicrosecondsAddFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLMicrosecondsAddFunction());
jpqlFunctionGroup.add("mysql", new MySQLMicrosecondsAddFunction());
jpqlFunctionGroup.add("mysql8", new MySQLMicrosecondsAddFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLMicrosecondsAddFunction());
jpqlFunctionGroup.add("oracle", new OracleMicrosecondsAddFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup(MillisecondsAddFunction.NAME, false);
jpqlFunctionGroup.add(null, new MillisecondsAddFunction());
jpqlFunctionGroup.add("db2", new DB2MillisecondsAddFunction());
jpqlFunctionGroup.add("h2", new H2MillisecondsAddFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLMillisecondsAddFunction());
jpqlFunctionGroup.add("mysql", new MySQLMillisecondsAddFunction());
jpqlFunctionGroup.add("mysql8", new MySQLMillisecondsAddFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLMillisecondsAddFunction());
jpqlFunctionGroup.add("oracle", new OracleMillisecondsAddFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup(MinuteAddFunction.NAME, false);
jpqlFunctionGroup.add(null, new MinuteAddFunction());
jpqlFunctionGroup.add("db2", new DB2MinuteAddFunction());
jpqlFunctionGroup.add("h2", new H2MinuteAddFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLMinuteAddFunction());
jpqlFunctionGroup.add("mysql", new MySQLMinuteAddFunction());
jpqlFunctionGroup.add("mysql8", new MySQLMinuteAddFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLMinuteAddFunction());
jpqlFunctionGroup.add("oracle", new OracleMinuteAddFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup(MonthAddFunction.NAME, false);
jpqlFunctionGroup.add(null, new MonthAddFunction());
jpqlFunctionGroup.add("db2", new DB2MonthAddFunction());
jpqlFunctionGroup.add("h2", new H2MonthAddFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLMonthAddFunction());
jpqlFunctionGroup.add("mysql", new MySQLMonthAddFunction());
jpqlFunctionGroup.add("mysql8", new MySQLMonthAddFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLMonthAddFunction());
jpqlFunctionGroup.add("oracle", new OracleMonthAddFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup(QuarterAddFunction.NAME, false);
jpqlFunctionGroup.add(null, new QuarterAddFunction());
jpqlFunctionGroup.add("db2", new DB2QuarterAddFunction());
jpqlFunctionGroup.add("h2", new H2QuarterAddFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLQuarterAddFunction());
jpqlFunctionGroup.add("mysql", new MySQLQuarterAddFunction());
jpqlFunctionGroup.add("mysql8", new MySQLQuarterAddFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLQuarterAddFunction());
jpqlFunctionGroup.add("oracle", new OracleQuarterAddFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup(SecondAddFunction.NAME, false);
jpqlFunctionGroup.add(null, new SecondAddFunction());
jpqlFunctionGroup.add("db2", new DB2SecondAddFunction());
jpqlFunctionGroup.add("h2", new H2SecondAddFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLSecondAddFunction());
jpqlFunctionGroup.add("mysql", new MySQLSecondAddFunction());
jpqlFunctionGroup.add("mysql8", new MySQLSecondAddFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLSecondAddFunction());
jpqlFunctionGroup.add("oracle", new OracleSecondAddFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup(WeekAddFunction.NAME, false);
jpqlFunctionGroup.add(null, new WeekAddFunction());
jpqlFunctionGroup.add("db2", new DB2WeekAddFunction());
jpqlFunctionGroup.add("h2", new H2WeekAddFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLWeekAddFunction());
jpqlFunctionGroup.add("mysql", new MySQLWeekAddFunction());
jpqlFunctionGroup.add("mysql8", new MySQLWeekAddFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLWeekAddFunction());
jpqlFunctionGroup.add("oracle", new OracleWeekAddFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup(YearAddFunction.NAME, false);
jpqlFunctionGroup.add(null, new YearAddFunction());
jpqlFunctionGroup.add("db2", new DB2YearAddFunction());
jpqlFunctionGroup.add("h2", new H2YearAddFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLYearAddFunction());
jpqlFunctionGroup.add("mysql", new MySQLYearAddFunction());
jpqlFunctionGroup.add("mysql8", new MySQLYearAddFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLYearAddFunction());
jpqlFunctionGroup.add("oracle", new OracleYearAddFunction());
registerFunction(jpqlFunctionGroup);
// datediff
jpqlFunctionGroup = new JpqlFunctionGroup("year_diff", false);
jpqlFunctionGroup.add("access", new AccessYearDiffFunction());
jpqlFunctionGroup.add("db2", new DB2YearDiffFunction());
jpqlFunctionGroup.add("h2", new DefaultYearDiffFunction());
jpqlFunctionGroup.add("microsoft", new DefaultYearDiffFunction());
jpqlFunctionGroup.add("mysql", new MySQLYearDiffFunction());
jpqlFunctionGroup.add("mysql8", new MySQLYearDiffFunction());
jpqlFunctionGroup.add("sybase", new DefaultYearDiffFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLYearDiffFunction());
jpqlFunctionGroup.add("oracle", new OracleYearDiffFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("month_diff", false);
jpqlFunctionGroup.add("access", new AccessMonthDiffFunction());
jpqlFunctionGroup.add("db2", new DB2MonthDiffFunction());
jpqlFunctionGroup.add("h2", new DefaultMonthDiffFunction());
jpqlFunctionGroup.add("microsoft", new DefaultMonthDiffFunction());
jpqlFunctionGroup.add("mysql", new MySQLMonthDiffFunction());
jpqlFunctionGroup.add("mysql8", new MySQLMonthDiffFunction());
jpqlFunctionGroup.add("sybase", new DefaultMonthDiffFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLMonthDiffFunction());
jpqlFunctionGroup.add("oracle", new OracleMonthDiffFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("day_diff", false);
jpqlFunctionGroup.add("access", new AccessDayDiffFunction());
jpqlFunctionGroup.add("db2", new DB2DayDiffFunction());
jpqlFunctionGroup.add("h2", new DefaultDayDiffFunction());
jpqlFunctionGroup.add("microsoft", new DefaultDayDiffFunction());
jpqlFunctionGroup.add("mysql", new MySQLDayDiffFunction());
jpqlFunctionGroup.add("mysql8", new MySQLDayDiffFunction());
jpqlFunctionGroup.add("sybase", new DefaultDayDiffFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLDayDiffFunction());
jpqlFunctionGroup.add("oracle", new OracleDayDiffFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("hour_diff", false);
jpqlFunctionGroup.add("access", new AccessHourDiffFunction());
jpqlFunctionGroup.add("db2", new DB2HourDiffFunction());
jpqlFunctionGroup.add("h2", new DefaultHourDiffFunction());
jpqlFunctionGroup.add("microsoft", new DefaultHourDiffFunction());
jpqlFunctionGroup.add("mysql", new MySQLHourDiffFunction());
jpqlFunctionGroup.add("mysql8", new MySQLHourDiffFunction());
jpqlFunctionGroup.add("sybase", new DefaultHourDiffFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLHourDiffFunction());
jpqlFunctionGroup.add("oracle", new OracleHourDiffFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("minute_diff", false);
jpqlFunctionGroup.add("access", new AccessMinuteDiffFunction());
jpqlFunctionGroup.add("db2", new DB2MinuteDiffFunction());
jpqlFunctionGroup.add("h2", new DefaultMinuteDiffFunction());
jpqlFunctionGroup.add("microsoft", new DefaultMinuteDiffFunction());
jpqlFunctionGroup.add("mysql", new MySQLMinuteDiffFunction());
jpqlFunctionGroup.add("mysql8", new MySQLMinuteDiffFunction());
jpqlFunctionGroup.add("sybase", new DefaultMinuteDiffFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLMinuteDiffFunction());
jpqlFunctionGroup.add("oracle", new OracleMinuteDiffFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("second_diff", false);
jpqlFunctionGroup.add(null, new DefaultSecondDiffFunction());
jpqlFunctionGroup.add("access", new AccessSecondDiffFunction());
jpqlFunctionGroup.add("db2", new DB2SecondDiffFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLSecondDiffFunction());
jpqlFunctionGroup.add("mysql", new MySQLSecondDiffFunction());
jpqlFunctionGroup.add("mysql8", new MySQLSecondDiffFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLSecondDiffFunction());
jpqlFunctionGroup.add("oracle", new OracleSecondDiffFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("epoch_diff", false);
jpqlFunctionGroup.add(null, new DefaultSecondDiffFunction());
jpqlFunctionGroup.add("access", new AccessSecondDiffFunction());
jpqlFunctionGroup.add("db2", new DB2SecondDiffFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLSecondDiffFunction());
jpqlFunctionGroup.add("mysql", new MySQLSecondDiffFunction());
jpqlFunctionGroup.add("mysql8", new MySQLSecondDiffFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLSecondDiffFunction());
jpqlFunctionGroup.add("oracle", new OracleSecondDiffFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("millisecond_diff", false);
jpqlFunctionGroup.add(null, new DefaultMillisecondDiffFunction());
jpqlFunctionGroup.add("access", new AccessMillisecondDiffFunction());
jpqlFunctionGroup.add("db2", new DB2MillisecondDiffFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLMillisecondDiffFunction());
jpqlFunctionGroup.add("mysql", new MySQLMillisecondDiffFunction());
jpqlFunctionGroup.add("mysql8", new MySQLMillisecondDiffFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLMillisecondDiffFunction());
jpqlFunctionGroup.add("oracle", new OracleMillisecondDiffFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("microsecond_diff", false);
jpqlFunctionGroup.add(null, new DefaultMicrosecondDiffFunction());
jpqlFunctionGroup.add("access", new AccessMicrosecondDiffFunction());
jpqlFunctionGroup.add("db2", new DB2MicrosecondDiffFunction());
jpqlFunctionGroup.add("mysql", new MySQLMicrosecondDiffFunction());
jpqlFunctionGroup.add("mysql8", new MySQLMicrosecondDiffFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLMicrosecondDiffFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLMicrosecondDiffFunction());
jpqlFunctionGroup.add("oracle", new OracleMicrosecondDiffFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("week_diff", false);
jpqlFunctionGroup.add(null, new DefaultWeekDiffFunction());
jpqlFunctionGroup.add("h2", new H2WeekDiffFunction());
jpqlFunctionGroup.add("db2", new DB2WeekDiffFunction());
jpqlFunctionGroup.add("mysql", new MySQLWeekDiffFunction());
jpqlFunctionGroup.add("mysql8", new MySQLWeekDiffFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLWeekDiffFunction());
jpqlFunctionGroup.add("oracle", new OracleWeekDiffFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLWeekDiffFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("quarter_diff", false);
jpqlFunctionGroup.add(null, new DefaultQuarterDiffFunction());
jpqlFunctionGroup.add("access", new AccessQuarterDiffFunction());
jpqlFunctionGroup.add("h2", new H2QuarterDiffFunction());
jpqlFunctionGroup.add("db2", new DB2QuarterDiffFunction());
jpqlFunctionGroup.add("mysql", new MySQLQuarterDiffFunction());
jpqlFunctionGroup.add("mysql8", new MySQLQuarterDiffFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLQuarterDiffFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLQuarterDiffFunction());
jpqlFunctionGroup.add("oracle", new OracleQuarterDiffFunction());
registerFunction(jpqlFunctionGroup);
// date trunc
jpqlFunctionGroup = new JpqlFunctionGroup(TruncDayFunction.NAME, false);
jpqlFunctionGroup.add(null, new PostgreSQLTruncDayFunction());
jpqlFunctionGroup.add("db2", new DB2TruncDayFunction());
jpqlFunctionGroup.add("h2", new H2TruncDayFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLTruncDayFunction());
jpqlFunctionGroup.add("mysql", new MySQLTruncDayFunction());
jpqlFunctionGroup.add("mysql8", new MySQLTruncDayFunction());
jpqlFunctionGroup.add("oracle", new OracleTruncDayFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLTruncDayFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup(TruncHourFunction.NAME, false);
jpqlFunctionGroup.add(null, new PostgreSQLTruncHourFunction());
jpqlFunctionGroup.add("db2", new DB2TruncHourFunction());
jpqlFunctionGroup.add("h2", new H2TruncHourFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLTruncHourFunction());
jpqlFunctionGroup.add("mysql", new MySQLTruncHourFunction());
jpqlFunctionGroup.add("mysql8", new MySQLTruncHourFunction());
jpqlFunctionGroup.add("oracle", new OracleTruncHourFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLTruncHourFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup(TruncMicrosecondsFunction.NAME, false);
jpqlFunctionGroup.add(null, new PostgreSQLTruncMicrosecondsFunction());
jpqlFunctionGroup.add("db2", new DB2TruncMicrosecondsFunction());
jpqlFunctionGroup.add("h2", new H2TruncMicrosecondsFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLTruncMicrosecondsFunction());
jpqlFunctionGroup.add("mysql", new MySQLTruncMicrosecondsFunction());
jpqlFunctionGroup.add("mysql8", new MySQLTruncMicrosecondsFunction());
jpqlFunctionGroup.add("oracle", new OracleTruncMicrosecondsFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLTruncMicrosecondsFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup(TruncMillisecondsFunction.NAME, false);
jpqlFunctionGroup.add(null, new PostgreSQLTruncMillisecondsFunction());
jpqlFunctionGroup.add("db2", new DB2TruncMillisecondsFunction());
jpqlFunctionGroup.add("h2", new H2TruncMillisecondsFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLTruncMillisecondsFunction());
jpqlFunctionGroup.add("mysql", new MySQLTruncMillisecondsFunction());
jpqlFunctionGroup.add("mysql8", new MySQLTruncMillisecondsFunction());
jpqlFunctionGroup.add("oracle", new OracleTruncMillisecondsFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLTruncMillisecondsFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup(TruncMinuteFunction.NAME, false);
jpqlFunctionGroup.add(null, new PostgreSQLTruncMinuteFunction());
jpqlFunctionGroup.add("db2", new DB2TruncMinuteFunction());
jpqlFunctionGroup.add("h2", new H2TruncMinuteFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLTruncMinuteFunction());
jpqlFunctionGroup.add("mysql", new MySQLTruncMinuteFunction());
jpqlFunctionGroup.add("mysql8", new MySQLTruncMinuteFunction());
jpqlFunctionGroup.add("oracle", new OracleTruncMinuteFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLTruncMinuteFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup(TruncMonthFunction.NAME, false);
jpqlFunctionGroup.add(null, new PostgreSQLTruncMonthFunction());
jpqlFunctionGroup.add("db2", new DB2TruncMonthFunction());
jpqlFunctionGroup.add("h2", new H2TruncMonthFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLTruncMonthFunction());
jpqlFunctionGroup.add("mysql", new MySQLTruncMonthFunction());
jpqlFunctionGroup.add("mysql8", new MySQLTruncMonthFunction());
jpqlFunctionGroup.add("oracle", new OracleTruncMonthFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLTruncMonthFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup(TruncQuarterFunction.NAME, false);
jpqlFunctionGroup.add(null, new PostgreSQLTruncQuarterFunction());
jpqlFunctionGroup.add("db2", new DB2TruncQuarterFunction());
jpqlFunctionGroup.add("h2", new H2TruncQuarterFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLTruncQuarterFunction());
jpqlFunctionGroup.add("mysql", new MySQLTruncQuarterFunction());
jpqlFunctionGroup.add("mysql8", new MySQLTruncQuarterFunction());
jpqlFunctionGroup.add("oracle", new OracleTruncQuarterFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLTruncQuarterFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup(TruncSecondFunction.NAME, false);
jpqlFunctionGroup.add(null, new PostgreSQLTruncSecondFunction());
jpqlFunctionGroup.add("db2", new DB2TruncSecondFunction());
jpqlFunctionGroup.add("h2", new H2TruncSecondFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLTruncSecondFunction());
jpqlFunctionGroup.add("mysql", new MySQLTruncSecondFunction());
jpqlFunctionGroup.add("mysql8", new MySQLTruncSecondFunction());
jpqlFunctionGroup.add("oracle", new OracleTruncSecondFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLTruncSecondFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup(TruncWeekFunction.NAME, false);
jpqlFunctionGroup.add(null, new TruncWeekFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLTruncWeekFunction());
jpqlFunctionGroup.add("mysql", new MySQLTruncWeekFunction());
jpqlFunctionGroup.add("mysql8", new MySQLTruncWeekFunction());
jpqlFunctionGroup.add("oracle", new OracleTruncWeekFunction());
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup(TruncYearFunction.NAME, false);
jpqlFunctionGroup.add(null, new PostgreSQLTruncYearFunction());
jpqlFunctionGroup.add("db2", new DB2TruncYearFunction());
jpqlFunctionGroup.add("h2", new H2TruncYearFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLTruncYearFunction());
jpqlFunctionGroup.add("mysql", new MySQLTruncYearFunction());
jpqlFunctionGroup.add("mysql8", new MySQLTruncYearFunction());
jpqlFunctionGroup.add("oracle", new OracleTruncYearFunction());
jpqlFunctionGroup.add("postgresql", new PostgreSQLTruncYearFunction());
registerFunction(jpqlFunctionGroup);
// count
jpqlFunctionGroup = new JpqlFunctionGroup(AbstractCountFunction.FUNCTION_NAME, true);
jpqlFunctionGroup.add(null, new CountTupleFunction());
jpqlFunctionGroup.add("mysql", new MySQLCountTupleFunction());
jpqlFunctionGroup.add("mysql8", new MySQLCountTupleFunction());
jpqlFunctionGroup.add("db2", new CountTupleEmulationFunction());
jpqlFunctionGroup.add("microsoft", new CountTupleEmulationFunction("+", "varchar(max)"));
jpqlFunctionGroup.add("oracle", new CountTupleEmulationFunction());
jpqlFunctionGroup.add("hsql", new CountTupleEmulationFunction());
registerFunction(jpqlFunctionGroup);
// row values
jpqlFunctionGroup = new JpqlFunctionGroup(RowValueComparisonFunction.FUNCTION_NAME, false);
jpqlFunctionGroup.add(null, new RowValueComparisonFunction());
registerFunction(jpqlFunctionGroup);
// row values subquery
jpqlFunctionGroup = new JpqlFunctionGroup(RowValueSubqueryComparisonFunction.FUNCTION_NAME, false);
jpqlFunctionGroup.add(null, new RowValueSubqueryComparisonFunction());
registerFunction(jpqlFunctionGroup);
// alias function
jpqlFunctionGroup = new JpqlFunctionGroup(AliasFunction.FUNCTION_NAME, false);
jpqlFunctionGroup.add(null, new AliasFunction());
registerFunction(jpqlFunctionGroup);
// column trunc function
jpqlFunctionGroup = new JpqlFunctionGroup(ColumnTruncFunction.FUNCTION_NAME, false);
jpqlFunctionGroup.add(null, new ColumnTruncFunction());
registerFunction(jpqlFunctionGroup);
// count wrapper function
jpqlFunctionGroup = new JpqlFunctionGroup(CountWrapperFunction.FUNCTION_NAME, false);
jpqlFunctionGroup.add(null, new CountWrapperFunction());
registerFunction(jpqlFunctionGroup);
// query wrapper function
jpqlFunctionGroup = new JpqlFunctionGroup(QueryWrapperFunction.FUNCTION_NAME, false);
jpqlFunctionGroup.add(null, new QueryWrapperFunction());
registerFunction(jpqlFunctionGroup);
// null subquery function
jpqlFunctionGroup = new JpqlFunctionGroup(NullSubqueryFunction.FUNCTION_NAME, false);
jpqlFunctionGroup.add(null, new NullSubqueryFunction());
registerFunction(jpqlFunctionGroup);
// greatest
jpqlFunctionGroup = new JpqlFunctionGroup(AbstractGreatestFunction.FUNCTION_NAME, false);
jpqlFunctionGroup.add(null, new DefaultGreatestFunction());
jpqlFunctionGroup.add("db2", new MaxGreatestFunction());
jpqlFunctionGroup.add("microsoft", new SelectMaxUnionGreatestFunction());
registerFunction(jpqlFunctionGroup);
// least
jpqlFunctionGroup = new JpqlFunctionGroup(AbstractLeastFunction.FUNCTION_NAME, false);
jpqlFunctionGroup.add(null, new DefaultLeastFunction());
jpqlFunctionGroup.add("db2", new MinLeastFunction());
jpqlFunctionGroup.add("microsoft", new SelectMinUnionLeastFunction());
registerFunction(jpqlFunctionGroup);
// repeat
jpqlFunctionGroup = new JpqlFunctionGroup(AbstractRepeatFunction.FUNCTION_NAME, false);
jpqlFunctionGroup.add(null, new DefaultRepeatFunction());
jpqlFunctionGroup.add("oracle", new LpadRepeatFunction());
jpqlFunctionGroup.add("microsoft", new ReplicateRepeatFunction());
registerFunction(jpqlFunctionGroup);
// subquery
jpqlFunctionGroup = new JpqlFunctionGroup(SubqueryFunction.FUNCTION_NAME, false);
jpqlFunctionGroup.add(null, new SubqueryFunction());
registerFunction(jpqlFunctionGroup);
// every
jpqlFunctionGroup = new JpqlFunctionGroup(EveryFunction.FUNCTION_NAME, true);
jpqlFunctionGroup.add(null, EveryFunction.INSTANCE);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
jpqlFunctionGroup.add(dialectEntry.getKey(), dialectEntry.getValue().supportsBooleanAggregation() ? EveryFunction.INSTANCE : FallbackEveryFunction.INSTANCE);
}
registerFunction(jpqlFunctionGroup);
// andagg
jpqlFunctionGroup = new JpqlFunctionGroup("AND_AGG", true);
jpqlFunctionGroup.add(null, EveryFunction.INSTANCE);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
jpqlFunctionGroup.add(dialectEntry.getKey(), dialectEntry.getValue().supportsBooleanAggregation() ? EveryFunction.INSTANCE : FallbackEveryFunction.INSTANCE);
}
registerFunction(jpqlFunctionGroup);
// oragg
jpqlFunctionGroup = new JpqlFunctionGroup(OrAggFunction.FUNCTION_NAME, true);
jpqlFunctionGroup.add(null, OrAggFunction.INSTANCE);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
jpqlFunctionGroup.add(dialectEntry.getKey(), dialectEntry.getValue().supportsBooleanAggregation() ? OrAggFunction.INSTANCE : FallbackOrAggFunction.INSTANCE);
}
registerFunction(jpqlFunctionGroup);
jpqlFunctionGroup = new JpqlFunctionGroup("OR_AGG", true);
jpqlFunctionGroup.add(null, OrAggFunction.INSTANCE);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
jpqlFunctionGroup.add(dialectEntry.getKey(), dialectEntry.getValue().supportsBooleanAggregation() ? OrAggFunction.INSTANCE : FallbackOrAggFunction.INSTANCE);
}
registerFunction(jpqlFunctionGroup);
// string_json_agg
jpqlFunctionGroup = new JpqlFunctionGroup(AbstractStringJsonAggFunction.FUNCTION_NAME, true);
{
JpqlFunctionGroup chrFunctionGroup = functions.get(ChrFunction.FUNCTION_NAME);
JpqlFunctionGroup replaceFunctionGroup = functions.get(ReplaceFunction.FUNCTION_NAME);
JpqlFunctionGroup concatFunctionGroup = functions.get(ConcatFunction.FUNCTION_NAME);
JpqlFunctionGroup groupConcatFunctionGroup = functions.get(AbstractGroupConcatFunction.FUNCTION_NAME);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
ChrFunction chrFunction = (ChrFunction) chrFunctionGroup.get(dialectEntry.getKey());
if (chrFunction == null) {
chrFunction = (ChrFunction) chrFunctionGroup.get(null);
}
ReplaceFunction replaceFunction = (ReplaceFunction) replaceFunctionGroup.get(dialectEntry.getKey());
if (replaceFunction == null) {
replaceFunction = (ReplaceFunction) replaceFunctionGroup.get(null);
}
ConcatFunction concatFunction = (ConcatFunction) concatFunctionGroup.get(dialectEntry.getKey());
if (concatFunction == null) {
concatFunction = (ConcatFunction) concatFunctionGroup.get(null);
}
jpqlFunctionGroup.add(dialectEntry.getKey(), new GroupConcatBasedStringJsonAggFunction((AbstractGroupConcatFunction) groupConcatFunctionGroup.get(dialectEntry.getKey()), chrFunction, replaceFunction, concatFunction));
}
}
jpqlFunctionGroup.add("postgresql", new PostgreSQLStringJsonAggFunction());
jpqlFunctionGroup.add("oracle", new OracleStringJsonAggFunction((AbstractGroupConcatFunction) findFunction(AbstractGroupConcatFunction.FUNCTION_NAME, "oracle"), (ChrFunction) findFunction(ChrFunction.FUNCTION_NAME, "oracle"), (ReplaceFunction) findFunction(ReplaceFunction.FUNCTION_NAME, "oracle"), (ConcatFunction) findFunction(ConcatFunction.FUNCTION_NAME, "oracle")));
jpqlFunctionGroup.add("mysql", new MySQLStringJsonAggFunction());
jpqlFunctionGroup.add("mysql8", new MySQLStringJsonAggFunction());
registerFunction(jpqlFunctionGroup);
// string_xml_agg
jpqlFunctionGroup = new JpqlFunctionGroup(AbstractStringXmlAggFunction.FUNCTION_NAME, true);
{
JpqlFunctionGroup replaceFunctionGroup = functions.get(ReplaceFunction.FUNCTION_NAME);
JpqlFunctionGroup concatFunctionGroup = functions.get(ConcatFunction.FUNCTION_NAME);
JpqlFunctionGroup groupConcatFunctionGroup = functions.get(AbstractGroupConcatFunction.FUNCTION_NAME);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
ReplaceFunction replaceFunction = (ReplaceFunction) replaceFunctionGroup.get(dialectEntry.getKey());
if (replaceFunction == null) {
replaceFunction = (ReplaceFunction) replaceFunctionGroup.get(null);
}
ConcatFunction concatFunction = (ConcatFunction) concatFunctionGroup.get(dialectEntry.getKey());
if (concatFunction == null) {
concatFunction = (ConcatFunction) concatFunctionGroup.get(null);
}
jpqlFunctionGroup.add(dialectEntry.getKey(), new GroupConcatBasedStringXmlAggFunction((AbstractGroupConcatFunction) groupConcatFunctionGroup.get(dialectEntry.getKey()), replaceFunction, concatFunction));
}
}
jpqlFunctionGroup.add("postgresql", new PostgreSQLStringXmlAggFunction());
jpqlFunctionGroup.add("oracle", new OracleGroupConcatBasedStringXmlAggFunction((AbstractGroupConcatFunction) findFunction(AbstractGroupConcatFunction.FUNCTION_NAME, "oracle"), (ReplaceFunction) findFunction(ReplaceFunction.FUNCTION_NAME, "oracle"), (ConcatFunction) findFunction(ConcatFunction.FUNCTION_NAME, "oracle")));
registerFunction(jpqlFunctionGroup);
// to_string_json
jpqlFunctionGroup = new JpqlFunctionGroup(AbstractToStringJsonFunction.FUNCTION_NAME, false);
{
JpqlFunctionGroup chrFunctionGroup = functions.get(ChrFunction.FUNCTION_NAME);
JpqlFunctionGroup replaceFunctionGroup = functions.get(ReplaceFunction.FUNCTION_NAME);
JpqlFunctionGroup concatFunctionGroup = functions.get(ConcatFunction.FUNCTION_NAME);
JpqlFunctionGroup groupConcatFunctionGroup = functions.get(AbstractGroupConcatFunction.FUNCTION_NAME);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
ChrFunction chrFunction = (ChrFunction) chrFunctionGroup.get(dialectEntry.getKey());
if (chrFunction == null) {
chrFunction = (ChrFunction) chrFunctionGroup.get(null);
}
ReplaceFunction replaceFunction = (ReplaceFunction) replaceFunctionGroup.get(dialectEntry.getKey());
if (replaceFunction == null) {
replaceFunction = (ReplaceFunction) replaceFunctionGroup.get(null);
}
ConcatFunction concatFunction = (ConcatFunction) concatFunctionGroup.get(dialectEntry.getKey());
if (concatFunction == null) {
concatFunction = (ConcatFunction) concatFunctionGroup.get(null);
}
jpqlFunctionGroup.add(dialectEntry.getKey(), new GroupConcatBasedToStringJsonFunction((AbstractGroupConcatFunction) groupConcatFunctionGroup.get(dialectEntry.getKey()), chrFunction, replaceFunction, concatFunction, dialectEntry.getValue().getLateralStyle()));
}
}
jpqlFunctionGroup.add("postgresql", new PostgreSQLToStringJsonFunction());
jpqlFunctionGroup.add("microsoft", new ForJsonPathToStringJsonFunction((CastFunction) findFunction("cast_string", "microsoft")));
jpqlFunctionGroup.add("oracle", new OracleToStringJsonFunction((AbstractGroupConcatFunction) findFunction(AbstractGroupConcatFunction.FUNCTION_NAME, "oracle"), (ChrFunction) findFunction(ChrFunction.FUNCTION_NAME, "oracle"), (ReplaceFunction) findFunction(ReplaceFunction.FUNCTION_NAME, "oracle"), (ConcatFunction) findFunction(ConcatFunction.FUNCTION_NAME, "oracle")));
jpqlFunctionGroup.add("mysql", new MySQLToStringJsonFunction());
jpqlFunctionGroup.add("mysql8", new MySQLToStringJsonFunction());
registerFunction(jpqlFunctionGroup);
// to_string_xml
jpqlFunctionGroup = new JpqlFunctionGroup(AbstractToStringXmlFunction.FUNCTION_NAME, false);
{
JpqlFunctionGroup replaceFunctionGroup = functions.get(ReplaceFunction.FUNCTION_NAME);
JpqlFunctionGroup concatFunctionGroup = functions.get(ConcatFunction.FUNCTION_NAME);
JpqlFunctionGroup groupConcatFunctionGroup = functions.get(AbstractGroupConcatFunction.FUNCTION_NAME);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
ReplaceFunction replaceFunction = (ReplaceFunction) replaceFunctionGroup.get(dialectEntry.getKey());
if (replaceFunction == null) {
replaceFunction = (ReplaceFunction) replaceFunctionGroup.get(null);
}
ConcatFunction concatFunction = (ConcatFunction) concatFunctionGroup.get(dialectEntry.getKey());
if (concatFunction == null) {
concatFunction = (ConcatFunction) concatFunctionGroup.get(null);
}
jpqlFunctionGroup.add(dialectEntry.getKey(), new GroupConcatBasedToStringXmlFunction((AbstractGroupConcatFunction) groupConcatFunctionGroup.get(dialectEntry.getKey()), replaceFunction, concatFunction, dialectEntry.getValue().getLateralStyle()));
}
}
jpqlFunctionGroup.add("postgresql", new PostgreSQLToStringXmlFunction());
jpqlFunctionGroup.add("microsoft", new ForXmlPathToStringXmlFunction((CastFunction) findFunction("cast_string", "microsoft")));
jpqlFunctionGroup.add("oracle", new OracleGroupConcatBasedToStringXmlFunction((AbstractGroupConcatFunction) findFunction(AbstractGroupConcatFunction.FUNCTION_NAME, "oracle"), (ReplaceFunction) findFunction(ReplaceFunction.FUNCTION_NAME, "oracle"), (ConcatFunction) findFunction(ConcatFunction.FUNCTION_NAME, "oracle"), LateralStyle.LATERAL));
registerFunction(jpqlFunctionGroup);
// to_multiset
jpqlFunctionGroup = new JpqlFunctionGroup(ToMultisetFunction.FUNCTION_NAME, false);
{
JpqlFunctionGroup jsonFunctionGroup = functions.get(AbstractToStringJsonFunction.FUNCTION_NAME);
JpqlFunctionGroup xmlFunctionGroup = functions.get(AbstractToStringXmlFunction.FUNCTION_NAME);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
AbstractToStringJsonFunction jsonFunction = (AbstractToStringJsonFunction) jsonFunctionGroup.get(dialectEntry.getKey());
AbstractToStringXmlFunction xmlFunction = (AbstractToStringXmlFunction) xmlFunctionGroup.get(dialectEntry.getKey());
jpqlFunctionGroup.add(dialectEntry.getKey(), new ToMultisetFunction(jsonFunction, xmlFunction));
}
}
registerFunction(jpqlFunctionGroup);
// window every
jpqlFunctionGroup = new JpqlFunctionGroup(WindowEveryFunction.FUNCTION_NAME, JpqlFunctionKind.WINDOW);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
jpqlFunctionGroup.add(dialectEntry.getKey(), dialectEntry.getValue().supportsBooleanAggregation() ? new WindowEveryFunction(dialectEntry.getValue()) : new FallbackWindowEveryFunction(dialectEntry.getValue()));
}
registerFunction(jpqlFunctionGroup);
// window andagg
jpqlFunctionGroup = new JpqlFunctionGroup("AND_AGG", JpqlFunctionKind.WINDOW);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
jpqlFunctionGroup.add(dialectEntry.getKey(), dialectEntry.getValue().supportsBooleanAggregation() ? new WindowEveryFunction(dialectEntry.getValue()) : new FallbackWindowEveryFunction(dialectEntry.getValue()));
}
registerFunction(jpqlFunctionGroup);
// window oragg
jpqlFunctionGroup = new JpqlFunctionGroup(WindowOrAggFunction.FUNCTION_NAME, JpqlFunctionKind.WINDOW);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
jpqlFunctionGroup.add(dialectEntry.getKey(), dialectEntry.getValue().supportsBooleanAggregation() ? new WindowOrAggFunction(dialectEntry.getValue()) : new FallbackWindowOrAggFunction(dialectEntry.getValue()));
}
registerFunction(jpqlFunctionGroup);
// window sum
jpqlFunctionGroup = new JpqlFunctionGroup(SumFunction.FUNCTION_NAME, JpqlFunctionKind.WINDOW);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
jpqlFunctionGroup.add(dialectEntry.getKey(), new SumFunction(dialectEntry.getValue()));
}
registerFunction(jpqlFunctionGroup);
// window avg
jpqlFunctionGroup = new JpqlFunctionGroup(AvgFunction.FUNCTION_NAME, JpqlFunctionKind.WINDOW);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
jpqlFunctionGroup.add(dialectEntry.getKey(), new AvgFunction(dialectEntry.getValue()));
}
registerFunction(jpqlFunctionGroup);
// window min
jpqlFunctionGroup = new JpqlFunctionGroup(MinFunction.FUNCTION_NAME, JpqlFunctionKind.WINDOW);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
jpqlFunctionGroup.add(dialectEntry.getKey(), new MinFunction(dialectEntry.getValue()));
}
registerFunction(jpqlFunctionGroup);
// window max
jpqlFunctionGroup = new JpqlFunctionGroup(MaxFunction.FUNCTION_NAME, JpqlFunctionKind.WINDOW);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
jpqlFunctionGroup.add(dialectEntry.getKey(), new MaxFunction(dialectEntry.getValue()));
}
registerFunction(jpqlFunctionGroup);
// window count
jpqlFunctionGroup = new JpqlFunctionGroup(CountFunction.FUNCTION_NAME, JpqlFunctionKind.WINDOW);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
jpqlFunctionGroup.add(dialectEntry.getKey(), new CountFunction(dialectEntry.getValue()));
}
registerFunction(jpqlFunctionGroup);
// row number
jpqlFunctionGroup = new JpqlFunctionGroup(RowNumberFunction.FUNCTION_NAME, JpqlFunctionKind.WINDOW);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
jpqlFunctionGroup.add(dialectEntry.getKey(), new RowNumberFunction(dialectEntry.getValue()));
}
registerFunction(jpqlFunctionGroup);
// rank
jpqlFunctionGroup = new JpqlFunctionGroup(RankFunction.FUNCTION_NAME, JpqlFunctionKind.ORDERED_SET_AGGREGATE);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
jpqlFunctionGroup.add(dialectEntry.getKey(), new RankFunction(dialectEntry.getValue()));
}
registerFunction(jpqlFunctionGroup);
// dense_rank
jpqlFunctionGroup = new JpqlFunctionGroup(DenseRankFunction.FUNCTION_NAME, JpqlFunctionKind.ORDERED_SET_AGGREGATE);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
jpqlFunctionGroup.add(dialectEntry.getKey(), new DenseRankFunction(dialectEntry.getValue()));
}
registerFunction(jpqlFunctionGroup);
// PERCENT_RANK
jpqlFunctionGroup = new JpqlFunctionGroup(PercentRankFunction.FUNCTION_NAME, JpqlFunctionKind.ORDERED_SET_AGGREGATE);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
jpqlFunctionGroup.add(dialectEntry.getKey(), new PercentRankFunction(dialectEntry.getValue()));
}
registerFunction(jpqlFunctionGroup);
// CUME_DIST
jpqlFunctionGroup = new JpqlFunctionGroup(CumeDistFunction.FUNCTION_NAME, JpqlFunctionKind.ORDERED_SET_AGGREGATE);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
jpqlFunctionGroup.add(dialectEntry.getKey(), new CumeDistFunction(dialectEntry.getValue()));
}
registerFunction(jpqlFunctionGroup);
// NTILE
jpqlFunctionGroup = new JpqlFunctionGroup(NtileFunction.FUNCTION_NAME, JpqlFunctionKind.WINDOW);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
jpqlFunctionGroup.add(dialectEntry.getKey(), new NtileFunction(dialectEntry.getValue()));
}
registerFunction(jpqlFunctionGroup);
// LAG
jpqlFunctionGroup = new JpqlFunctionGroup(LagFunction.FUNCTION_NAME, JpqlFunctionKind.WINDOW);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
jpqlFunctionGroup.add(dialectEntry.getKey(), new LagFunction(dialectEntry.getValue()));
}
registerFunction(jpqlFunctionGroup);
// LEAD
jpqlFunctionGroup = new JpqlFunctionGroup(LeadFunction.FUNCTION_NAME, JpqlFunctionKind.WINDOW);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
jpqlFunctionGroup.add(dialectEntry.getKey(), new LeadFunction(dialectEntry.getValue()));
}
registerFunction(jpqlFunctionGroup);
// FIRST_VALUE
jpqlFunctionGroup = new JpqlFunctionGroup(FirstValueFunction.FUNCTION_NAME, JpqlFunctionKind.WINDOW);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
jpqlFunctionGroup.add(dialectEntry.getKey(), new FirstValueFunction(dialectEntry.getValue()));
}
registerFunction(jpqlFunctionGroup);
// LAST_VALUE
jpqlFunctionGroup = new JpqlFunctionGroup(LastValueFunction.FUNCTION_NAME, JpqlFunctionKind.WINDOW);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
jpqlFunctionGroup.add(dialectEntry.getKey(), new LastValueFunction(dialectEntry.getValue()));
}
registerFunction(jpqlFunctionGroup);
// NTH_VALUE
jpqlFunctionGroup = new JpqlFunctionGroup(NthValueFunction.FUNCTION_NAME, JpqlFunctionKind.WINDOW);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
jpqlFunctionGroup.add(dialectEntry.getKey(), new NthValueFunction(dialectEntry.getValue()));
}
registerFunction(jpqlFunctionGroup);
// JSON_GET
jpqlFunctionGroup = new JpqlFunctionGroup(AbstractJsonGetFunction.FUNCTION_NAME, false);
jpqlFunctionGroup.add("postgresql", new PostgreSQLJsonGetFunction());
jpqlFunctionGroup.add("mysql8", new MySQL8JsonGetFunction());
jpqlFunctionGroup.add("oracle", new OracleJsonGetFunction());
jpqlFunctionGroup.add("db2", new DB2JsonGetFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLJsonGetFunction());
registerFunction(jpqlFunctionGroup);
// JSON_SET
jpqlFunctionGroup = new JpqlFunctionGroup(AbstractJsonSetFunction.FUNCTION_NAME, false);
jpqlFunctionGroup.add("postgresql", new PostgreSQLJsonSetFunction());
jpqlFunctionGroup.add("mysql8", new MySQL8JsonSetFunction());
jpqlFunctionGroup.add("oracle", new OracleJsonSetFunction());
jpqlFunctionGroup.add("db2", new DB2JsonSetFunction());
jpqlFunctionGroup.add("microsoft", new MSSQLJsonSetFunction());
registerFunction(jpqlFunctionGroup);
// grouping
registerFunction(GroupingFunction.FUNCTION_NAME, new GroupingFunction());
registerFunction(GroupingSetFunction.FUNCTION_NAME, new GroupingSetFunction());
registerFunction(GroupingSetsFunction.FUNCTION_NAME, new GroupingSetsFunction());
registerFunction(CubeFunction.FUNCTION_NAME, new CubeFunction());
registerFunction(RollupFunction.FUNCTION_NAME, new RollupFunction());
// MODE
jpqlFunctionGroup = new JpqlFunctionGroup(ModeFunction.FUNCTION_NAME, JpqlFunctionKind.ORDERED_SET_AGGREGATE);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
jpqlFunctionGroup.add(dialectEntry.getKey(), new ModeFunction(dialectEntry.getValue()));
}
registerFunction(jpqlFunctionGroup);
// PERCENTILE_CONT
jpqlFunctionGroup = new JpqlFunctionGroup(PercentileContFunction.FUNCTION_NAME, JpqlFunctionKind.ORDERED_SET_AGGREGATE);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
jpqlFunctionGroup.add(dialectEntry.getKey(), new PercentileContFunction(dialectEntry.getValue()));
}
registerFunction(jpqlFunctionGroup);
// PERCENTILE_DISC
jpqlFunctionGroup = new JpqlFunctionGroup(PercentileDiscFunction.FUNCTION_NAME, JpqlFunctionKind.ORDERED_SET_AGGREGATE);
for (Map.Entry<String, DbmsDialect> dialectEntry : this.dbmsDialects.entrySet()) {
jpqlFunctionGroup.add(dialectEntry.getKey(), new PercentileDiscFunction(dialectEntry.getValue()));
}
registerFunction(jpqlFunctionGroup);
}
use of com.blazebit.persistence.spi.DbmsDialect in project blaze-persistence by Blazebit.
the class HibernateExtendedQuerySupport method executeReturning.
@Override
@SuppressWarnings("unchecked")
public ReturningResult<Object[]> executeReturning(com.blazebit.persistence.spi.ServiceProvider serviceProvider, List<Query> participatingQueries, Query modificationBaseQuery, Query exampleQuery, String sqlOverride, boolean queryPlanCacheEnabled) {
DbmsDialect dbmsDialect = serviceProvider.getService(DbmsDialect.class);
EntityManager em = serviceProvider.getService(EntityManager.class);
SessionImplementor session = em.unwrap(SessionImplementor.class);
SessionFactoryImplementor sfi = session.getFactory();
if (session.isClosed()) {
throw new PersistenceException("Entity manager is closed!");
}
// Create combined query parameters
List<String> queryStrings = new ArrayList<>(participatingQueries.size());
Set<String> querySpaces = new HashSet<>();
QueryParamEntry queryParametersEntry = createQueryParameters(em, modificationBaseQuery, participatingQueries, queryStrings, querySpaces);
QueryParameters queryParameters = queryParametersEntry.queryParameters;
// Create plan for example query
QueryPlanCacheKey cacheKey = queryPlanCacheEnabled ? createCacheKey(sqlOverride, participatingQueries, queryStrings) : null;
CacheEntry<QueryPlanCacheValue> queryPlanEntry = getQueryPlan(sfi, exampleQuery, cacheKey);
QueryPlanCacheValue queryPlanCacheValue = queryPlanEntry.getValue();
HQLQueryPlan queryPlan = queryPlanCacheValue.getQueryPlan();
String[][] returningColumns;
int[] returningColumnTypes;
if (queryPlanEntry.isFromCache()) {
returningColumns = queryPlanCacheValue.getReturningColumns();
returningColumnTypes = queryPlanCacheValue.getReturningColumnTypes();
} else {
String exampleQuerySql = queryPlan.getSqlStrings()[0];
boolean caseInsensitive = !Boolean.valueOf(serviceProvider.getService(ConfigurationSource.class).getProperty(ConfigurationProperties.RETURNING_CLAUSE_CASE_SENSITIVE));
returningColumns = getReturningColumns(caseInsensitive, exampleQuerySql);
returningColumnTypes = dbmsDialect.needsReturningSqlTypes() ? getReturningColumnTypes(queryPlan, sfi) : null;
}
StringBuilder sqlSb = new StringBuilder(sqlOverride.length() + 100);
sqlSb.append(sqlOverride);
String finalSql = sqlSb.toString();
try {
HibernateReturningResult<Object[]> returningResult = new HibernateReturningResult<Object[]>();
if (!queryPlanEntry.isFromCache()) {
prepareQueryPlan(queryPlan, queryParametersEntry.specifications, finalSql, session, modificationBaseQuery, true, dbmsDialect);
if (queryPlanCacheEnabled) {
putQueryPlanIfAbsent(sfi, cacheKey, new QueryPlanCacheValue(queryPlan, returningColumns, returningColumnTypes));
}
}
if (queryPlan.getTranslators().length > 1) {
throw new IllegalArgumentException("No support for multiple translators yet!");
}
QueryTranslator queryTranslator = queryPlan.getTranslators()[0];
// If the DBMS doesn't support inclusion of cascading deletes in a with clause, we have to execute them manually
StatementExecutor executor = getExecutor(queryTranslator, session, modificationBaseQuery);
List<String> originalDeletes = Collections.emptyList();
if (executor != null && executor instanceof DeleteExecutor) {
originalDeletes = getField(executor, "deletes");
}
// Extract query loader for native listing
QueryLoader queryLoader = getField(queryTranslator, "queryLoader");
// Do the native list operation with custom session and combined parameters
/*
* NATIVE LIST START
*/
hibernateAccess.checkTransactionSynchStatus(session);
queryParameters.validateParameters();
autoFlush(querySpaces, session);
List<Object[]> results = Collections.EMPTY_LIST;
boolean success = false;
try {
for (String delete : originalDeletes) {
hibernateAccess.doExecute(executor, delete, queryParameters, session, queryParametersEntry.specifications);
}
results = hibernateAccess.list(queryLoader, wrapSession(session, dbmsDialect, returningColumns, returningColumnTypes, returningResult), queryParameters);
success = true;
} catch (QueryExecutionRequestException he) {
LOG.severe("Could not execute the following SQL query: " + finalSql);
throw new IllegalStateException(he);
} catch (TypeMismatchException e) {
LOG.severe("Could not execute the following SQL query: " + finalSql);
throw new IllegalArgumentException(e);
} catch (HibernateException he) {
LOG.severe("Could not execute the following SQL query: " + finalSql);
throw hibernateAccess.convert(em, he);
} finally {
hibernateAccess.afterTransaction(session, success);
}
/*
* NATIVE LIST END
*/
returningResult.setResultList(results);
return returningResult;
} catch (Exception e1) {
throw new RuntimeException(e1);
}
}
use of com.blazebit.persistence.spi.DbmsDialect in project blaze-persistence by Blazebit.
the class HibernateExtendedQuerySupport method executeUpdate.
@Override
public int executeUpdate(com.blazebit.persistence.spi.ServiceProvider serviceProvider, List<Query> participatingQueries, Query baseQuery, Query query, String finalSql, boolean queryPlanCacheEnabled) {
DbmsDialect dbmsDialect = serviceProvider.getService(DbmsDialect.class);
EntityManager em = serviceProvider.getService(EntityManager.class);
SessionImplementor session = em.unwrap(SessionImplementor.class);
SessionFactoryImplementor sfi = session.getFactory();
if (session.isClosed()) {
throw new PersistenceException("Entity manager is closed!");
}
Integer firstResult = null;
Integer maxResults = null;
if (query.getFirstResult() > 0) {
firstResult = query.getFirstResult();
}
if (query.getMaxResults() != Integer.MAX_VALUE) {
maxResults = query.getMaxResults();
}
// Create combined query parameters
List<String> queryStrings = new ArrayList<>(participatingQueries.size());
Set<String> querySpaces = new HashSet<>();
QueryParamEntry queryParametersEntry = createQueryParameters(em, baseQuery, participatingQueries, queryStrings, querySpaces);
QueryParameters queryParameters = queryParametersEntry.queryParameters;
QueryPlanCacheKey cacheKey = queryPlanCacheEnabled ? createCacheKey(finalSql, participatingQueries, queryStrings, firstResult, maxResults) : null;
CacheEntry<QueryPlanCacheValue> queryPlanEntry = getQueryPlan(sfi, query, cacheKey);
QueryPlanCacheValue queryPlanCacheValue = queryPlanEntry.getValue();
HQLQueryPlan queryPlan = queryPlanCacheValue.getQueryPlan();
String[][] returningColumns;
int[] returningColumnTypes;
if (queryPlan.getReturnMetadata() == null) {
returningColumns = null;
returningColumnTypes = null;
} else {
if (queryPlanEntry.isFromCache()) {
returningColumns = queryPlanCacheValue.getReturningColumns();
returningColumnTypes = queryPlanCacheValue.getReturningColumnTypes();
} else {
String exampleQuerySql = queryPlanCacheValue.getQueryPlan().getSqlStrings()[0];
boolean caseInsensitive = !Boolean.valueOf(serviceProvider.getService(ConfigurationSource.class).getProperty(ConfigurationProperties.RETURNING_CLAUSE_CASE_SENSITIVE));
returningColumns = getReturningColumns(caseInsensitive, exampleQuerySql);
returningColumnTypes = dbmsDialect.needsReturningSqlTypes() ? getReturningColumnTypes(queryPlan, sfi) : null;
}
}
if (!queryPlanEntry.isFromCache()) {
prepareQueryPlan(queryPlan, queryParametersEntry.specifications, finalSql, session, baseQuery, true, dbmsDialect);
if (queryPlanCacheEnabled) {
putQueryPlanIfAbsent(sfi, cacheKey, new QueryPlanCacheValue(queryPlan, returningColumns, returningColumnTypes));
}
}
autoFlush(querySpaces, session);
if (queryPlan.getReturnMetadata() == null) {
return hibernateAccess.performExecuteUpdate(queryPlan, session, queryParameters);
}
try {
@SuppressWarnings("unchecked") List<Object> results = hibernateAccess.performList(queryPlan, wrapSession(session, dbmsDialect, returningColumns, returningColumnTypes, null), queryParameters);
if (results.size() != 1) {
throw new IllegalArgumentException("Expected size 1 but was: " + results.size());
}
Number count = (Number) results.get(0);
return count.intValue();
} catch (QueryExecutionRequestException he) {
LOG.severe("Could not execute the following SQL query: " + finalSql);
throw new IllegalStateException(he);
} catch (TypeMismatchException e) {
LOG.severe("Could not execute the following SQL query: " + finalSql);
throw new IllegalArgumentException(e);
} catch (HibernateException he) {
LOG.severe("Could not execute the following SQL query: " + finalSql);
hibernateAccess.throwPersistenceException(em, he);
return 0;
}
}
use of com.blazebit.persistence.spi.DbmsDialect in project blaze-persistence by Blazebit.
the class AbstractJpaPersistenceTest method init.
@Before
public void init() {
boolean firstTest = lastTestClass != getClass();
boolean veryFirstTest = lastTestClass == null;
boolean schemaChanged;
lastTestClass = getClass();
// If a previous test run resolved the no-op cleaner, we won't be able to resolve any other cleaner
if (resolvedNoop) {
databaseCleaner = null;
schemaChanged = true;
} else {
databaseCleaner = getLastDatabaseCleaner();
schemaChanged = databaseCleaner == null || !Objects.equals(lastTargetSchema, getTargetSchema());
}
lastTargetSchema = getTargetSchema();
SchemaMode schemaMode = getSchemaMode();
if (dataSource != null && lastSchemaMode != schemaMode) {
dataSource.close();
dataSource = null;
closeEmf();
}
lastSchemaMode = schemaMode;
// Nothing to delete if the schema changed
databaseClean = schemaChanged;
if (dataSource != null && recreateDataSource()) {
recreateTestClass = getClass();
dataSource.close();
dataSource = null;
closeEmf();
} else if (recreateTestClass != null && recreateTestClass != getClass()) {
recreateTestClass = null;
if (dataSource != null) {
dataSource.close();
dataSource = null;
}
closeEmf();
}
// Disable query collecting
QueryInspectorListener.enabled = false;
QueryInspectorListener.collectSequences = false;
if (!resolvedNoop && databaseCleaner == null) {
if (bootstrapDataSource == null) {
getBootstrapDataSource();
}
try (Connection c = bootstrapDataSource.getConnection()) {
DatabaseCleaner applicableCleaner = getDatabaseCleaner(c);
if (applicableCleaner == null) {
// If none was found, we use the default cleaner
Logger.getLogger(getClass().getName()).warning("Could not resolve database cleaner for the database, falling back to drop-and-create strategy.");
resolvedNoop = true;
}
String targetDatabase = getTargetDatabase();
String targetSchema = getTargetSchema();
if (targetDatabase != null) {
databaseCleaner.createDatabaseIfNotExists(c, targetDatabase);
}
if (targetSchema != null) {
createSchemaIfNotExists(c, targetSchema);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
if (databaseCleaner == null) {
// The default cleaner which recreates the schema
setLastDatabaseCleaner(getDefaultDatabaseCleaner());
}
EntityManagerFactory emfBefore = emf;
if (veryFirstTest || schemaChanged) {
getDataSource(createProperties("none"));
emf = repopulateSchema();
if (emf == null) {
emf = createEntityManagerFactory("TestsuiteBase", createProperties("none"));
}
} else if (emf == null || !emf.isOpen()) {
emf = createEntityManagerFactory("TestsuiteBase", createProperties("none"));
}
if (activeCriteriaBuilderConfiguration == null) {
if (requiresCriteriaBuilderConfigurationCustomization()) {
activeCriteriaBuilderConfiguration = Criteria.getDefault();
configure(activeCriteriaBuilderConfiguration);
} else {
if (defaultCbConfiguration == null) {
// We cannot initialize this statically due to static initializer in
// com.blazebit.persistence.testsuite.base.AbstractPersistenceTest (Hibernate)
defaultCbConfiguration = Criteria.getDefault();
}
activeCriteriaBuilderConfiguration = defaultCbConfiguration;
}
}
CriteriaBuilderConfigurationEqualityWrapper cfgEqualityWrapper = new CriteriaBuilderConfigurationEqualityWrapper((CriteriaBuilderConfigurationImpl) activeCriteriaBuilderConfiguration);
if (cbf == null || emfBefore != emf || !cfgEqualityWrapper.equals(lastCriteriaBuilderConfigurationEqualityWrapper)) {
cbf = activeCriteriaBuilderConfiguration.createCriteriaBuilderFactory(emf);
lastCriteriaBuilderConfigurationEqualityWrapper = cfgEqualityWrapper;
jpaProvider = cbf.getService(JpaProvider.class);
dbmsDialect = cbf.getService(DbmsDialect.class);
}
getEm();
if (firstTest) {
setUpOnce();
}
if (runTestInTransaction() && !getEm().getTransaction().isActive()) {
getEm().getTransaction().begin();
}
}
use of com.blazebit.persistence.spi.DbmsDialect in project blaze-persistence by Blazebit.
the class AbstractCommonQueryBuilder method getEntityFunctionNodes.
protected List<EntityFunctionNode> getEntityFunctionNodes(Query baseQuery, List<JoinNode> valuesNodes, List<JoinNode> lateInlineNodes, boolean filterNulls) {
List<EntityFunctionNode> entityFunctionNodes = new ArrayList<>();
DbmsDialect dbmsDialect = mainQuery.dbmsDialect;
ValuesStrategy strategy = dbmsDialect.getValuesStrategy();
String dummyTable = dbmsDialect.getDummyTable();
for (JoinNode node : valuesNodes) {
Class<?> clazz = node.getInternalEntityType().getJavaType();
String valueClazzAttributeName = node.getValuesLikeAttribute();
int valueCount = node.getValueCount();
boolean identifiableReference = node.getNodeType() instanceof EntityType<?> && node.getValuesIdNames() != null;
String rootAlias = node.getAlias();
String castedParameter = node.getValuesCastedParameter();
String[] attributes = node.getValuesAttributes();
// We construct an example query representing the values clause with a SELECT clause that selects the fields in the right order which we need to construct SQL
// that uses proper aliases and filters null values which are there in the first place to pad up parameters in case we don't reach the desired value count
StringBuilder valuesSb = new StringBuilder(20 + valueCount * attributes.length * 3);
Query valuesExampleQuery = getValuesExampleQuery(clazz, valueCount, identifiableReference, valueClazzAttributeName, rootAlias, castedParameter, attributes, valuesSb, strategy, dummyTable, node);
String exampleQuerySql = mainQuery.cbf.getExtendedQuerySupport().getSql(mainQuery.em, valuesExampleQuery);
String exampleQuerySqlAlias = mainQuery.cbf.getExtendedQuerySupport().getSqlAlias(mainQuery.em, valuesExampleQuery, "e");
String exampleQueryCollectionSqlAlias = null;
if (!node.isValueClazzAttributeSingular()) {
exampleQueryCollectionSqlAlias = mainQuery.cbf.getExtendedQuerySupport().getSqlAlias(mainQuery.em, valuesExampleQuery, node.getValueClazzAlias("e_"));
}
StringBuilder whereClauseSb = new StringBuilder(exampleQuerySql.length());
String filterNullsTableAlias = "fltr_nulls_tbl_als_";
String valuesAliases = getValuesAliases(exampleQuerySqlAlias, attributes.length, exampleQuerySql, whereClauseSb, filterNullsTableAlias, strategy, dummyTable);
if (strategy == ValuesStrategy.SELECT_VALUES) {
valuesSb.insert(0, valuesAliases);
valuesSb.append(')');
valuesAliases = null;
} else if (strategy == ValuesStrategy.SELECT_UNION) {
valuesSb.insert(0, valuesAliases);
if (!filterNulls) {
// We must order by all values and use a limit in such a case
valuesSb.insert(0, "(select * from ");
valuesSb.append(") val_tmp_ order by ");
if (dbmsDialect.isNullSmallest()) {
for (int i = 0; i < attributes.length; i++) {
valuesSb.append(i + 1);
valuesSb.append(',');
}
} else {
for (int i = 0; i < attributes.length; i++) {
dbmsDialect.appendOrderByElement(valuesSb, new DefaultOrderByElement(null, i + 1, true, true, true), null);
valuesSb.append(',');
}
}
valuesSb.setCharAt(valuesSb.length() - 1, ' ');
dbmsDialect.appendExtendedSql(valuesSb, DbmsStatementType.SELECT, false, true, null, Integer.toString(valueCount + 1), "1", null, null, null);
}
valuesSb.append(')');
valuesAliases = null;
}
if (filterNulls) {
valuesSb.insert(0, "(select * from ");
valuesSb.append(' ');
valuesSb.append(filterNullsTableAlias);
if (valuesAliases != null) {
valuesSb.append(valuesAliases);
valuesAliases = null;
}
valuesSb.append(whereClauseSb);
valuesSb.append(')');
}
String valuesClause = valuesSb.toString();
String valuesTableSqlAlias = exampleQuerySqlAlias;
String valuesTableJoin = null;
String pluralCollectionTableAlias = null;
String pluralTableAlias = null;
String syntheticPredicate = exampleQuerySql.substring(SqlUtils.indexOfWhere(exampleQuerySql) + " where ".length());
if (baseQuery != null) {
valuesTableSqlAlias = cbf.getExtendedQuerySupport().getSqlAlias(em, baseQuery, node.getAlias());
syntheticPredicate = syntheticPredicate.replace(exampleQuerySqlAlias, valuesTableSqlAlias);
if (exampleQueryCollectionSqlAlias != null) {
pluralTableAlias = cbf.getExtendedQuerySupport().getSqlAlias(em, baseQuery, node.getValueClazzAlias(node.getAlias() + "_"));
syntheticPredicate = syntheticPredicate.replace(exampleQueryCollectionSqlAlias, pluralTableAlias);
String baseQuerySql = cbf.getExtendedQuerySupport().getSql(em, baseQuery);
int[] indexRange = SqlUtils.indexOfFullJoin(baseQuerySql, pluralTableAlias);
String baseTableAlias = " " + valuesTableSqlAlias + " ";
int baseTableAliasIndex = baseQuerySql.indexOf(baseTableAlias);
int fullJoinStartIndex = baseTableAliasIndex + baseTableAlias.length();
if (fullJoinStartIndex != indexRange[0]) {
// TODO: find out pluralCollectionTableAlias
String onClause = " on ";
int onClauseIndex = baseQuerySql.indexOf(onClause, fullJoinStartIndex);
int[] collectionTableIndexRange = SqlUtils.rtrimBackwardsToFirstWhitespace(baseQuerySql, onClauseIndex);
pluralCollectionTableAlias = baseQuerySql.substring(collectionTableIndexRange[0], collectionTableIndexRange[1]);
}
valuesTableJoin = baseQuerySql.substring(fullJoinStartIndex, indexRange[1]);
}
}
entityFunctionNodes.add(new EntityFunctionNode(valuesClause, valuesAliases, node.getInternalEntityType().getName(), valuesTableSqlAlias, pluralCollectionTableAlias, pluralTableAlias, valuesTableJoin, syntheticPredicate, false));
}
// We assume to have to select via a union to apply aliases correctly when the values strategy requires that
boolean selectUnion = strategy == ValuesStrategy.SELECT_UNION;
boolean lateralStyle = dbmsDialect.getLateralStyle() == LateralStyle.LATERAL;
for (JoinNode lateInlineNode : lateInlineNodes) {
CTEInfo cteInfo = lateInlineNode.getInlineCte();
String aliases;
StringBuilder aliasesSb = new StringBuilder();
if (selectUnion) {
aliasesSb.append("select ");
for (int i = 0; i < cteInfo.columnNames.size(); i++) {
aliasesSb.append("null ");
aliasesSb.append(cteInfo.columnNames.get(i)).append(',');
}
aliasesSb.setCharAt(aliasesSb.length() - 1, ' ');
aliasesSb.append(" from ").append(dummyTable).append(" where 1=0 union all ");
aliases = null;
} else {
aliasesSb.append('(');
for (int i = 0; i < cteInfo.columnNames.size(); i++) {
aliasesSb.append(cteInfo.columnNames.get(i)).append(',');
}
aliasesSb.setCharAt(aliasesSb.length() - 1, ')');
aliases = aliasesSb.toString();
aliasesSb = null;
}
String subquery;
if (lateInlineNode.isLateral()) {
// We need to wrap the lateral subquery into a temporary HQL subquery to fake the correlation
// Then, we extract the sql part of the actual subquery
StringBuilder lateralExampleQueryString = new StringBuilder();
buildLateralExampleQueryString(lateralExampleQueryString);
String sql = getQuerySpecification(cteInfo.nonRecursiveCriteriaBuilder.getLateralQuery(lateralExampleQueryString, lateralStyle ? null : lateInlineNode)).getSql();
int start = SqlUtils.indexOfWhere(sql);
while (sql.charAt(start) != '(') {
start++;
}
String prefix;
if (dbmsDialect.getLateralStyle() == LateralStyle.LATERAL) {
prefix = "lateral (";
} else if (lateInlineNode.getJoinType() == JoinType.INNER) {
prefix = "cross apply (";
} else {
prefix = "outer apply (";
}
if (aliasesSb == null) {
subquery = prefix + sql.substring(start + 1, sql.lastIndexOf(')')) + ")";
} else {
aliasesSb.insert(0, prefix).append('(').append(sql, start + 1, sql.lastIndexOf(')')).append(')').append(')');
subquery = aliasesSb.toString();
}
} else {
if (aliasesSb == null) {
subquery = "(" + getQuerySpecification(cteInfo.nonRecursiveCriteriaBuilder.getQuery()).getSql() + ")";
} else {
aliasesSb.insert(0, "(").append('(').append(getQuerySpecification(cteInfo.nonRecursiveCriteriaBuilder.getQuery()).getSql()).append(')').append(')');
subquery = aliasesSb.toString();
}
}
String cteTableSqlAlias = baseQuery == null ? "" : cbf.getExtendedQuerySupport().getSqlAlias(em, baseQuery, lateInlineNode.getAlias());
entityFunctionNodes.add(new EntityFunctionNode(subquery, aliases, cteInfo.cteType.getName(), cteTableSqlAlias, null, null, null, null, lateInlineNode.isLateral()));
}
return entityFunctionNodes;
}
Aggregations