use of org.hibernate.type.CustomType in project hibernate-orm by hibernate.
the class BasicTypeRegistryTest method testRegisteringUserTypes.
@Test
public void testRegisteringUserTypes() {
BasicTypeRegistry registry = new BasicTypeRegistry();
registry.register(new TotallyIrrelevantUserType(), new String[] { "key" });
BasicType type = registry.getRegisteredType("key");
assertNotNull(type);
assertEquals(CustomType.class, type.getClass());
assertEquals(TotallyIrrelevantUserType.class, ((CustomType) type).getUserType().getClass());
registry.register(new TotallyIrrelevantCompositeUserType(), new String[] { "key" });
type = registry.getRegisteredType("key");
assertNotNull(type);
assertEquals(CompositeCustomType.class, type.getClass());
assertEquals(TotallyIrrelevantCompositeUserType.class, ((CompositeCustomType) type).getUserType().getClass());
type = registry.getRegisteredType(UUID.class.getName());
assertSame(UUIDBinaryType.INSTANCE, type);
registry.register(new TotallyIrrelevantUserType(), new String[] { UUID.class.getName() });
type = registry.getRegisteredType(UUID.class.getName());
assertNotSame(UUIDBinaryType.INSTANCE, type);
assertEquals(CustomType.class, type.getClass());
}
use of org.hibernate.type.CustomType in project hibernate-orm by hibernate.
the class EnumeratedWithMappedSuperclassTest method testHHH10128.
@Test
public void testHHH10128() {
final Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(Entity.class).addAnnotatedClass(DescriptionEntity.class).addAnnotatedClass(AddressLevel.class).buildMetadata();
final PersistentClass addressLevelBinding = metadata.getEntityBinding(AddressLevel.class.getName());
final Property natureProperty = addressLevelBinding.getProperty("nature");
CustomType customType = assertTyping(CustomType.class, natureProperty.getType());
EnumType enumType = assertTyping(EnumType.class, customType.getUserType());
assertEquals(Types.VARCHAR, enumType.sqlTypes()[0]);
SessionFactoryImplementor sf = (SessionFactoryImplementor) metadata.buildSessionFactory();
try {
EntityPersister p = sf.getEntityPersister(AddressLevel.class.getName());
CustomType runtimeType = assertTyping(CustomType.class, p.getPropertyType("nature"));
EnumType runtimeEnumType = assertTyping(EnumType.class, runtimeType.getUserType());
assertEquals(Types.VARCHAR, runtimeEnumType.sqlTypes()[0]);
} finally {
sf.close();
}
}
use of org.hibernate.type.CustomType in project hibernate-orm by hibernate.
the class OrmXmlEnumTypeTest method testOrmXmlDefinedEnumType.
@Test
public void testOrmXmlDefinedEnumType() {
StandardServiceRegistry ssr = ServiceRegistryBuilder.buildServiceRegistry();
try {
MetadataSources ms = new MetadataSources(ssr);
ms.addResource("org/hibernate/test/annotations/enumerated/ormXml/orm.xml");
Metadata metadata = ms.buildMetadata();
Type bindingPropertyType = metadata.getEntityBinding(BookWithOrmEnum.class.getName()).getProperty("bindingStringEnum").getType();
CustomType customType = ExtraAssertions.assertTyping(CustomType.class, bindingPropertyType);
EnumType enumType = ExtraAssertions.assertTyping(EnumType.class, customType.getUserType());
assertFalse(enumType.isOrdinal());
} finally {
ServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.type.CustomType in project hibernate-orm by hibernate.
the class EnumeratedSmokeTest method validateEnumMapping.
private void validateEnumMapping(Property property, EnumType expectedJpaEnumType) {
assertThat(property.getType(), instanceOf(CustomType.class));
final CustomType customType = (CustomType) property.getType();
assertThat(customType.getUserType(), instanceOf(org.hibernate.type.EnumType.class));
final org.hibernate.type.EnumType hibernateMappingEnumType = (org.hibernate.type.EnumType) customType.getUserType();
assertThat(hibernateMappingEnumType.isOrdinal(), is(expectedJpaEnumType == EnumType.ORDINAL));
assertThat(hibernateMappingEnumType.sqlTypes().length, is(1));
assertThat(hibernateMappingEnumType.sqlTypes()[0], is(expectedJpaEnumType == EnumType.ORDINAL ? Types.INTEGER : Types.VARCHAR));
}
use of org.hibernate.type.CustomType in project dhis2-core by dhis2.
the class HibernatePropertyIntrospector method createProperty.
private Property createProperty(Class<?> klass, org.hibernate.mapping.Property hibernateProperty, MetamodelImplementor metamodelImplementor) {
Property property = new Property(klass);
property.setRequired(false);
property.setPersisted(true);
property.setWritable(true);
property.setOwner(true);
Type type = hibernateProperty.getType();
property.setName(hibernateProperty.getName());
property.setFieldName(hibernateProperty.getName());
property.setCascade(hibernateProperty.getCascade());
property.setCollection(type.isCollectionType());
property.setSetterMethod(hibernateProperty.getSetter(klass).getMethod());
property.setGetterMethod(hibernateProperty.getGetter(klass).getMethod());
if (property.isCollection()) {
initCollectionProperty(metamodelImplementor, property, (CollectionType) type);
}
if (type instanceof SingleColumnType || type instanceof CustomType || type instanceof ManyToOneType) {
Column column = (Column) hibernateProperty.getColumnIterator().next();
property.setUnique(column.isUnique());
property.setRequired(!column.isNullable());
property.setMin(0d);
property.setMax((double) column.getLength());
property.setLength(column.getLength());
if (type instanceof TextType) {
property.setMin(0d);
property.setMax((double) Integer.MAX_VALUE);
property.setLength(Integer.MAX_VALUE);
} else if (type instanceof IntegerType) {
property.setMin((double) Integer.MIN_VALUE);
property.setMax((double) Integer.MAX_VALUE);
property.setLength(Integer.MAX_VALUE);
} else if (type instanceof LongType) {
property.setMin((double) Long.MIN_VALUE);
property.setMax((double) Long.MAX_VALUE);
property.setLength(Integer.MAX_VALUE);
} else if (type instanceof DoubleType) {
property.setMin(-Double.MAX_VALUE);
property.setMax(Double.MAX_VALUE);
property.setLength(Integer.MAX_VALUE);
}
}
if (type instanceof ManyToOneType) {
property.setManyToOne(true);
property.setRequired(property.isRequired() && !property.isCollection());
if (property.isOwner()) {
property.setOwningRole(klass.getName() + "." + property.getName());
} else {
property.setInverseRole(klass.getName() + "." + property.getName());
}
} else if (type instanceof OneToOneType) {
property.setOneToOne(true);
} else if (type instanceof OneToMany) {
property.setOneToMany(true);
}
return property;
}
Aggregations