|
almost all hibernate extensions (for example, hibernate.tenant_identifier_resolver) which user can provide a custom api implementation take three form values:
- full qualify class name set in hibernate configuration file, or using org.hibernate.cfg.Configuration#setProperty api.
- initialized instance using org.hibernate.cfg.Configuration#getProperties().put(String key, Object value)
- passing a Class instance of the impl
so, the logic here is:
1. check if there is a configuration extension set by user
2. if the configuration value is the target type instance, then cast it and return
3. if the configuration value is the target type class, then create a new instance of this type
4. assume this value is a string value of qualified impl class name, loading it and create a new instance.
this logic was separated everywhere within hibernate, we need a better way to deal with this.
I'm adding two methods here to address this problem:
- org.hibernate.service.config.spi.ConfigurationService#getSetting
- org.hibernate.service.config.spi.ConfigurationService#cast
The first one simply get the configuration value from settings and calling the second one to cast it to expected type.
|