use of org.hibernate.type.descriptor.java.JavaTypeDescriptor in project hibernate-orm by hibernate.
the class RegistryHelper method resolveDescriptor.
@SuppressWarnings("unchecked")
public <J> JavaTypeDescriptor<J> resolveDescriptor(Map<Class, JavaTypeDescriptor> descriptorsByClass, Class<J> cls, Supplier<JavaTypeDescriptor<J>> defaultValueSupplier) {
if (cls == null) {
throw new IllegalArgumentException("Class passed to locate JavaTypeDescriptor cannot be null");
}
JavaTypeDescriptor<J> descriptor = descriptorsByClass.get(cls);
if (descriptor != null) {
return descriptor;
}
if (cls.isEnum()) {
descriptor = new EnumJavaTypeDescriptor(cls);
descriptorsByClass.put(cls, descriptor);
return descriptor;
}
// find the first "assignable" match
for (Map.Entry<Class, JavaTypeDescriptor> entry : descriptorsByClass.entrySet()) {
if (entry.getKey().isAssignableFrom(cls)) {
log.debugf("Using cached JavaTypeDescriptor instance for Java class [%s]", cls.getName());
return entry.getValue();
}
}
return defaultValueSupplier.get();
}
use of org.hibernate.type.descriptor.java.JavaTypeDescriptor in project hibernate-orm by hibernate.
the class Java8DateTimeTests method dump.
private void dump(PersistentClass entityBinding, TheEntity theEntity) {
final Iterator propertyBindingIterator = entityBinding.getPropertyClosureIterator();
while (propertyBindingIterator.hasNext()) {
final Property propertyBinding = (Property) propertyBindingIterator.next();
final JavaTypeDescriptor javaTypeDescriptor = ((AbstractStandardBasicType) propertyBinding.getType()).getJavaTypeDescriptor();
System.out.println(String.format("%s (%s) -> %s", propertyBinding.getName(), javaTypeDescriptor.getJavaType().getSimpleName(), javaTypeDescriptor.toString(propertyBinding.getGetter(TheEntity.class).get(theEntity))));
}
}
use of org.hibernate.type.descriptor.java.JavaTypeDescriptor in project hibernate-orm by hibernate.
the class JavaTypeDescriptorRegistryTest method testRegisterJavaTypeDescriptorRegistry.
@Test
public void testRegisterJavaTypeDescriptorRegistry() {
TypeConfiguration typeConfiguration = new TypeConfiguration();
typeConfiguration.getJavaTypeDescriptorRegistry().addDescriptor(new CustomJavaTypeDescriptor());
JavaTypeDescriptor descriptor = typeConfiguration.getJavaTypeDescriptorRegistry().getDescriptor(CustomType.class);
assertThat(descriptor, instanceOf(CustomJavaTypeDescriptor.class));
}
use of org.hibernate.type.descriptor.java.JavaTypeDescriptor in project hibernate-orm by hibernate.
the class JavaTypeDescriptorRegistryTest method testAddDirectlyToJavaTypeDescriptorRegistry.
@Test
public void testAddDirectlyToJavaTypeDescriptorRegistry() {
TypeConfiguration typeConfiguration = new TypeConfiguration();
org.hibernate.type.descriptor.java.JavaTypeDescriptorRegistry.INSTANCE.addDescriptor(new CustomJavaTypeDescriptor());
JavaTypeDescriptor descriptor = typeConfiguration.getJavaTypeDescriptorRegistry().getDescriptor(CustomType.class);
assertThat(descriptor, instanceOf(CustomJavaTypeDescriptor.class));
}
use of org.hibernate.type.descriptor.java.JavaTypeDescriptor in project hibernate-orm by hibernate.
the class MetadataBuildingProcess method handleTypes.
// todo (7.0) : buildJandexInitializer
// private static JandexInitManager buildJandexInitializer(
// MetadataBuildingOptions options,
// ClassLoaderAccess classLoaderAccess) {
// final boolean autoIndexMembers = ConfigurationHelper.getBoolean(
// org.hibernate.cfg.AvailableSettings.ENABLE_AUTO_INDEX_MEMBER_TYPES,
// options.getServiceRegistry().getService( ConfigurationService.class ).getSettings(),
// false
// );
//
// return new JandexInitManager( options.getJandexView(), classLoaderAccess, autoIndexMembers );
// }
private static void handleTypes(BootstrapContext bootstrapContext, MetadataBuildingOptions options) {
final ClassLoaderService classLoaderService = options.getServiceRegistry().getService(ClassLoaderService.class);
final TypeContributions typeContributions = new TypeContributions() {
@Override
public void contributeType(org.hibernate.type.BasicType type) {
getBasicTypeRegistry().register(type);
}
@Override
public void contributeType(BasicType type, String... keys) {
getBasicTypeRegistry().register(type, keys);
}
@Override
public void contributeType(UserType type, String[] keys) {
getBasicTypeRegistry().register(type, keys);
}
@Override
public void contributeType(CompositeUserType type, String[] keys) {
getBasicTypeRegistry().register(type, keys);
}
@Override
public void contributeJavaTypeDescriptor(JavaTypeDescriptor descriptor) {
bootstrapContext.getTypeConfiguration().getJavaTypeDescriptorRegistry().addDescriptor(descriptor);
}
@Override
public void contributeSqlTypeDescriptor(SqlTypeDescriptor descriptor) {
bootstrapContext.getTypeConfiguration().getSqlTypeDescriptorRegistry().addDescriptor(descriptor);
}
@Override
public TypeConfiguration getTypeConfiguration() {
return bootstrapContext.getTypeConfiguration();
}
final BasicTypeRegistry getBasicTypeRegistry() {
return bootstrapContext.getTypeConfiguration().getBasicTypeRegistry();
}
};
// add Dialect contributed types
final Dialect dialect = options.getServiceRegistry().getService(JdbcServices.class).getDialect();
dialect.contributeTypes(typeContributions, options.getServiceRegistry());
// add TypeContributor contributed types.
for (TypeContributor contributor : classLoaderService.loadJavaServices(TypeContributor.class)) {
contributor.contribute(typeContributions, options.getServiceRegistry());
}
// add explicit application registered types
for (BasicTypeRegistration basicTypeRegistration : options.getBasicTypeRegistrations()) {
bootstrapContext.getTypeConfiguration().getBasicTypeRegistry().register(basicTypeRegistration.getBasicType(), basicTypeRegistration.getRegistrationKeys());
}
}
Aggregations