Search in sources :

Example 1 with TimeZoneStorageType

use of org.hibernate.annotations.TimeZoneStorageType in project hibernate-orm by hibernate.

the class MetadataBuilderImpl method resolveTimeZoneStorageStrategy.

private static TimeZoneStorageStrategy resolveTimeZoneStorageStrategy(StandardServiceRegistry serviceRegistry, ConfigurationService configService) {
    final TimeZoneStorageType configuredTimeZoneStorageType = configService.getSetting(AvailableSettings.TIMEZONE_DEFAULT_STORAGE, TimeZoneStorageType.class, null);
    final TimeZoneStorageStrategy resolvedTimezoneStorage;
    // For now, we default to NORMALIZE as that is the Hibernate 5.x behavior
    if (configuredTimeZoneStorageType == null) {
        resolvedTimezoneStorage = TimeZoneStorageStrategy.NORMALIZE;
    } else {
        final TimeZoneSupport timeZoneSupport = serviceRegistry.getService(JdbcServices.class).getDialect().getTimeZoneSupport();
        switch(configuredTimeZoneStorageType) {
            case NATIVE:
                if (timeZoneSupport != TimeZoneSupport.NATIVE) {
                    throw new HibernateException("The configured time zone storage type NATIVE is not supported with the configured dialect");
                }
                resolvedTimezoneStorage = TimeZoneStorageStrategy.NATIVE;
                break;
            case NORMALIZE:
                resolvedTimezoneStorage = TimeZoneStorageStrategy.NORMALIZE;
                break;
            default:
                throw new HibernateException("Unsupported time zone storage type: " + configuredTimeZoneStorageType);
        }
    }
    return resolvedTimezoneStorage;
}
Also used : TimeZoneStorageStrategy(org.hibernate.TimeZoneStorageStrategy) HibernateException(org.hibernate.HibernateException) TimeZoneStorageType(org.hibernate.annotations.TimeZoneStorageType) TimeZoneSupport(org.hibernate.dialect.TimeZoneSupport)

Aggregations

HibernateException (org.hibernate.HibernateException)1 TimeZoneStorageStrategy (org.hibernate.TimeZoneStorageStrategy)1 TimeZoneStorageType (org.hibernate.annotations.TimeZoneStorageType)1 TimeZoneSupport (org.hibernate.dialect.TimeZoneSupport)1