HHH-8962 - Create a set of light reflection classes - initial work on classmate intg
This commit is contained in:
parent
97ee747907
commit
3bb937b83f
|
@ -117,13 +117,17 @@ public class ForeignKeyHelper {
|
|||
}
|
||||
|
||||
final String explicitName = resolutionDelegate.getReferencedAttributeName();
|
||||
final AttributeBinding referencedAttributeBinding = explicitName != null
|
||||
? referencedEntityBinding.locateAttributeBindingByPath( explicitName, true )
|
||||
: referencedEntityBinding.locateAttributeBinding(
|
||||
resolutionDelegate.getReferencedTable( resolutionContext ),
|
||||
resolutionDelegate.getJoinColumns( resolutionContext ),
|
||||
true
|
||||
);
|
||||
final AttributeBinding referencedAttributeBinding;
|
||||
if ( explicitName != null ) {
|
||||
referencedAttributeBinding = referencedEntityBinding.locateAttributeBindingByPath( explicitName, true );
|
||||
}
|
||||
else {
|
||||
referencedAttributeBinding = referencedEntityBinding.locateAttributeBinding(
|
||||
resolutionDelegate.getReferencedTable( resolutionContext ),
|
||||
resolutionDelegate.getJoinColumns( resolutionContext ),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
if ( referencedAttributeBinding == null ) {
|
||||
if ( explicitName != null ) {
|
||||
|
|
|
@ -25,11 +25,13 @@ package org.hibernate.metamodel.reflite.internal;
|
|||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.metamodel.reflite.spi.ClassDescriptor;
|
||||
import org.hibernate.metamodel.reflite.spi.FieldDescriptor;
|
||||
import org.hibernate.metamodel.reflite.spi.InterfaceDescriptor;
|
||||
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
||||
import org.hibernate.metamodel.reflite.spi.MethodDescriptor;
|
||||
import org.hibernate.metamodel.reflite.spi.Name;
|
||||
|
||||
|
@ -53,6 +55,7 @@ public class ClassDescriptorImpl implements ClassDescriptor {
|
|||
|
||||
private Collection<FieldDescriptor> fieldDescriptors;
|
||||
private Collection<MethodDescriptor> methodDescriptors;
|
||||
private List<JavaTypeDescriptor> typeParameters;
|
||||
|
||||
public ClassDescriptorImpl(
|
||||
Name name,
|
||||
|
@ -127,4 +130,13 @@ public class ClassDescriptorImpl implements ClassDescriptor {
|
|||
void setMethods(Collection<MethodDescriptor> methodDescriptors) {
|
||||
this.methodDescriptors = methodDescriptors;
|
||||
}
|
||||
|
||||
public void setTypeParameters(List<JavaTypeDescriptor> typeParameters) {
|
||||
this.typeParameters = typeParameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JavaTypeDescriptor> getTypeParameters() {
|
||||
return typeParameters;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,10 +25,12 @@ package org.hibernate.metamodel.reflite.internal;
|
|||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.metamodel.reflite.spi.FieldDescriptor;
|
||||
import org.hibernate.metamodel.reflite.spi.InterfaceDescriptor;
|
||||
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
|
||||
import org.hibernate.metamodel.reflite.spi.MethodDescriptor;
|
||||
import org.hibernate.metamodel.reflite.spi.Name;
|
||||
|
||||
|
@ -47,6 +49,7 @@ public class InterfaceDescriptorImpl implements InterfaceDescriptor {
|
|||
|
||||
private Collection<FieldDescriptor> fields;
|
||||
private Collection<MethodDescriptor> methods;
|
||||
private List<JavaTypeDescriptor> typeParameters;
|
||||
|
||||
public InterfaceDescriptorImpl(
|
||||
Name name,
|
||||
|
@ -105,4 +108,12 @@ public class InterfaceDescriptorImpl implements InterfaceDescriptor {
|
|||
void setMethods(Collection<MethodDescriptor> methods) {
|
||||
this.methods = methods;
|
||||
}
|
||||
|
||||
public List<JavaTypeDescriptor> getTypeParameters() {
|
||||
return typeParameters;
|
||||
}
|
||||
|
||||
public void setTypeParameters(List<JavaTypeDescriptor> typeParameters) {
|
||||
this.typeParameters = typeParameters;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ package org.hibernate.metamodel.reflite.internal;
|
|||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
@ -53,6 +54,11 @@ import org.jboss.jandex.MethodInfo;
|
|||
import org.jboss.jandex.MethodParameterInfo;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import com.fasterxml.classmate.MemberResolver;
|
||||
import com.fasterxml.classmate.ResolvedType;
|
||||
import com.fasterxml.classmate.ResolvedTypeWithMembers;
|
||||
import com.fasterxml.classmate.TypeResolver;
|
||||
|
||||
/**
|
||||
* This is the "interim" implementation of JavaTypeDescriptorRepository that loads Classes to ascertain this
|
||||
* information. Ultimately the goal is to hand this responsibility off to Jandex once
|
||||
|
@ -63,10 +69,14 @@ import org.jboss.logging.Logger;
|
|||
public class JavaTypeDescriptorRepositoryImpl implements JavaTypeDescriptorRepository {
|
||||
private static final Logger log = Logger.getLogger( JavaTypeDescriptorRepositoryImpl.class );
|
||||
|
||||
private ClassLoader jpaTempClassLoader;
|
||||
private final ClassLoader jpaTempClassLoader;
|
||||
private final ClassLoaderService classLoaderService;
|
||||
|
||||
private final IndexView jandexIndex;
|
||||
|
||||
private final TypeResolver classmateTypeResolver;
|
||||
private final MemberResolver classmateMemberResolver;
|
||||
|
||||
private Map<Name,JavaTypeDescriptor> typeDescriptorMap = new HashMap<Name, JavaTypeDescriptor>();
|
||||
|
||||
public JavaTypeDescriptorRepositoryImpl(
|
||||
|
@ -83,6 +93,9 @@ public class JavaTypeDescriptorRepositoryImpl implements JavaTypeDescriptorRepos
|
|||
this.jandexIndex = jandexIndex;
|
||||
this.jpaTempClassLoader = jpaTempClassLoader;
|
||||
this.classLoaderService = classLoaderService;
|
||||
|
||||
this.classmateTypeResolver = new TypeResolver();
|
||||
this.classmateMemberResolver = new MemberResolver( classmateTypeResolver );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -176,9 +189,15 @@ public class JavaTypeDescriptorRepositoryImpl implements JavaTypeDescriptorRepos
|
|||
typeDescriptorMap.put( typeName, typeDescriptor );
|
||||
|
||||
typeDescriptor.setExtendedInterfaceTypes( extractInterfaces( clazz ) );
|
||||
|
||||
final ResolvedType resolvedType = classmateTypeResolver.resolve( clazz );
|
||||
typeDescriptor.setTypeParameters( extractTypeParameters( resolvedType ) );
|
||||
// final ResolvedTypeWithMembers resolvedTypeWithMembers = classmateMemberResolver.resolve( resolvedType, null, null );
|
||||
|
||||
typeDescriptor.setFields( extractFields( clazz, typeDescriptor, jandexPivot ) );
|
||||
typeDescriptor.setMethods( extractMethods( clazz, typeDescriptor, jandexPivot ) );
|
||||
|
||||
|
||||
return typeDescriptor;
|
||||
}
|
||||
else {
|
||||
|
@ -192,6 +211,10 @@ public class JavaTypeDescriptorRepositoryImpl implements JavaTypeDescriptorRepos
|
|||
|
||||
typeDescriptor.setSuperType( extractSuper( clazz ) );
|
||||
typeDescriptor.setInterfaces( extractInterfaces( clazz ) );
|
||||
|
||||
final ResolvedType resolvedType = classmateTypeResolver.resolve( clazz );
|
||||
typeDescriptor.setTypeParameters( extractTypeParameters( resolvedType ) );
|
||||
|
||||
typeDescriptor.setFields( extractFields( clazz, typeDescriptor, jandexPivot ) );
|
||||
typeDescriptor.setMethods( extractMethods( clazz, typeDescriptor, jandexPivot ) );
|
||||
|
||||
|
@ -199,6 +222,18 @@ public class JavaTypeDescriptorRepositoryImpl implements JavaTypeDescriptorRepos
|
|||
}
|
||||
}
|
||||
|
||||
private List<JavaTypeDescriptor> extractTypeParameters(ResolvedType resolvedType) {
|
||||
if ( resolvedType.getTypeParameters().isEmpty() ) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
final List<JavaTypeDescriptor> result = CollectionHelper.arrayList( resolvedType.getTypeParameters().size() );
|
||||
for ( ResolvedType typeParameter : resolvedType.getTypeParameters() ) {
|
||||
result.add( getType( buildName( typeParameter.getErasedSignature() ) ) );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private DotName toJandexName(Name typeName) {
|
||||
if ( DotNameAdapter.class.isInstance( typeName ) ) {
|
||||
return ( (DotNameAdapter) typeName ).jandexName();
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
package org.hibernate.metamodel.reflite.spi;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jboss.jandex.AnnotationInstance;
|
||||
|
@ -62,4 +63,11 @@ public interface ClassDescriptor extends JavaTypeDescriptor {
|
|||
* @return The annotations.
|
||||
*/
|
||||
public Map<DotName, AnnotationInstance> getAnnotations();
|
||||
|
||||
/**
|
||||
* Get any parameters defined on the type.
|
||||
*
|
||||
* @return Any type parameters.
|
||||
*/
|
||||
public List<JavaTypeDescriptor> getTypeParameters();
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
package org.hibernate.metamodel.reflite.spi;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jboss.jandex.AnnotationInstance;
|
||||
|
@ -48,4 +49,11 @@ public interface InterfaceDescriptor extends JavaTypeDescriptor {
|
|||
* @return The annotations.
|
||||
*/
|
||||
public Map<DotName, AnnotationInstance> getAnnotations();
|
||||
|
||||
/**
|
||||
* Get any parameters defined on the type.
|
||||
*
|
||||
* @return Any type parameters.
|
||||
*/
|
||||
public List<JavaTypeDescriptor> getTypeParameters();
|
||||
}
|
||||
|
|
|
@ -387,8 +387,10 @@ public class ManyToOneTest extends BaseCoreFunctionalTestCase {
|
|||
Ticket.class,
|
||||
Passport.class,
|
||||
Parent.class,
|
||||
ParentPk.class,
|
||||
Child.class,
|
||||
Node.class,
|
||||
NodePk.class,
|
||||
User.class,
|
||||
DistrictUser.class,
|
||||
Order.class,
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
package org.hibernate.test.annotations.manytoone;
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.EmbeddedId;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Id;
|
||||
|
@ -34,7 +35,7 @@ public class Node implements Serializable {
|
|||
return id.hashCode();
|
||||
}
|
||||
|
||||
@Id
|
||||
@EmbeddedId
|
||||
public NodePk getId() {
|
||||
return id;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
//$Id$
|
||||
package org.hibernate.test.annotations.manytoone;
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.EmbeddedId;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
@ -11,7 +12,7 @@ import javax.persistence.Table;
|
|||
@Entity
|
||||
@Table(name = "tbl_parent")
|
||||
public class Parent implements Serializable {
|
||||
@Id
|
||||
@EmbeddedId
|
||||
public ParentPk id;
|
||||
public int age;
|
||||
|
||||
|
|
Loading…
Reference in New Issue