Search in sources :

Example 1 with ClassmateContext

use of org.hibernate.boot.internal.ClassmateContext in project hibernate-orm by hibernate.

the class AttributeConverterTest method testBasicOperation.

@Test
public void testBasicOperation() {
    SimpleValue simpleValue = new SimpleValue(new MetadataBuildingContextTestingImpl());
    simpleValue.setJpaAttributeConverterDescriptor(new InstanceBasedConverterDescriptor(new StringClobConverter(), new ClassmateContext()));
    simpleValue.setTypeUsingReflection(IrrelevantEntity.class.getName(), "name");
    Type type = simpleValue.getType();
    assertNotNull(type);
    if (!AttributeConverterTypeAdapter.class.isInstance(type)) {
        fail("AttributeConverter not applied");
    }
    AbstractStandardBasicType basicType = assertTyping(AbstractStandardBasicType.class, type);
    assertSame(StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor());
    assertEquals(Types.CLOB, basicType.getSqlTypeDescriptor().getSqlType());
}
Also used : MetadataBuildingContextTestingImpl(org.hibernate.testing.boot.MetadataBuildingContextTestingImpl) BasicType(org.hibernate.type.BasicType) AbstractStandardBasicType(org.hibernate.type.AbstractStandardBasicType) Type(org.hibernate.type.Type) IrrelevantEntity(org.hibernate.IrrelevantEntity) AttributeConverterTypeAdapter(org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter) InstanceBasedConverterDescriptor(org.hibernate.boot.model.convert.internal.InstanceBasedConverterDescriptor) AbstractStandardBasicType(org.hibernate.type.AbstractStandardBasicType) SimpleValue(org.hibernate.mapping.SimpleValue) ClassmateContext(org.hibernate.boot.internal.ClassmateContext) Test(org.junit.Test)

Example 2 with ClassmateContext

use of org.hibernate.boot.internal.ClassmateContext in project hibernate-orm by hibernate.

the class AutoApplicableConverterDescriptorStandardImpl method resolveMember.

private ResolvedMember resolveMember(XProperty xProperty, MetadataBuildingContext buildingContext) {
    final ClassmateContext classmateContext = buildingContext.getBootstrapContext().getClassmateContext();
    final ReflectionManager reflectionManager = buildingContext.getBootstrapContext().getReflectionManager();
    final ResolvedType declaringClassType = classmateContext.getTypeResolver().resolve(reflectionManager.toClass(xProperty.getDeclaringClass()));
    final ResolvedTypeWithMembers declaringClassWithMembers = classmateContext.getMemberResolver().resolve(declaringClassType, null, null);
    final Member member = toMember(xProperty);
    if (member instanceof Method) {
        for (ResolvedMethod resolvedMember : declaringClassWithMembers.getMemberMethods()) {
            if (resolvedMember.getName().equals(member.getName())) {
                return resolvedMember;
            }
        }
    } else if (member instanceof Field) {
        for (ResolvedField resolvedMember : declaringClassWithMembers.getMemberFields()) {
            if (resolvedMember.getName().equals(member.getName())) {
                return resolvedMember;
            }
        }
    } else {
        throw new HibernateException("Unexpected java.lang.reflect.Member type from org.hibernate.annotations.common.reflection.java.JavaXMember : " + member);
    }
    throw new HibernateException("Could not locate resolved type information for attribute [" + member.getName() + "] from Classmate");
}
Also used : Field(java.lang.reflect.Field) ResolvedField(com.fasterxml.classmate.members.ResolvedField) ResolvedMethod(com.fasterxml.classmate.members.ResolvedMethod) ResolvedField(com.fasterxml.classmate.members.ResolvedField) ReflectionManager(org.hibernate.annotations.common.reflection.ReflectionManager) HibernateException(org.hibernate.HibernateException) ResolvedMethod(com.fasterxml.classmate.members.ResolvedMethod) Method(java.lang.reflect.Method) Member(java.lang.reflect.Member) ResolvedMember(com.fasterxml.classmate.members.ResolvedMember) ResolvedType(com.fasterxml.classmate.ResolvedType) ClassmateContext(org.hibernate.boot.internal.ClassmateContext) ResolvedTypeWithMembers(com.fasterxml.classmate.ResolvedTypeWithMembers)

Aggregations

ClassmateContext (org.hibernate.boot.internal.ClassmateContext)2 ResolvedType (com.fasterxml.classmate.ResolvedType)1 ResolvedTypeWithMembers (com.fasterxml.classmate.ResolvedTypeWithMembers)1 ResolvedField (com.fasterxml.classmate.members.ResolvedField)1 ResolvedMember (com.fasterxml.classmate.members.ResolvedMember)1 ResolvedMethod (com.fasterxml.classmate.members.ResolvedMethod)1 Field (java.lang.reflect.Field)1 Member (java.lang.reflect.Member)1 Method (java.lang.reflect.Method)1 HibernateException (org.hibernate.HibernateException)1 IrrelevantEntity (org.hibernate.IrrelevantEntity)1 ReflectionManager (org.hibernate.annotations.common.reflection.ReflectionManager)1 InstanceBasedConverterDescriptor (org.hibernate.boot.model.convert.internal.InstanceBasedConverterDescriptor)1 SimpleValue (org.hibernate.mapping.SimpleValue)1 MetadataBuildingContextTestingImpl (org.hibernate.testing.boot.MetadataBuildingContextTestingImpl)1 AbstractStandardBasicType (org.hibernate.type.AbstractStandardBasicType)1 BasicType (org.hibernate.type.BasicType)1 Type (org.hibernate.type.Type)1 AttributeConverterTypeAdapter (org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter)1 Test (org.junit.Test)1