一、前言
通过dorado.hibernate.jar源码包中的com.bstek.dorado.hibernate.HibernateUtils工具类,获取rg.hibernate.type.Type的类型getHibernateType操作。
二、源码说明
package com.bstek.dorado.hibernate;@b@@b@import org.apache.commons.lang.StringUtils;@b@import org.hibernate.SessionFactory;@b@import org.hibernate.metadata.ClassMetadata;@b@import org.hibernate.type.EntityType;@b@import org.hibernate.type.Type;@b@@b@public abstract class HibernateUtils@b@{@b@ public static Type getHibernateType(String propertyPath, ClassMetadata classMetadata, SessionFactory sessionFactory)@b@ {@b@ String[] tokens = StringUtils.split(propertyPath, '.');@b@ if (tokens.length == 1)@b@ return classMetadata.getPropertyType(propertyPath);@b@ if (tokens.length > 1) {@b@ Type type = null;@b@ ClassMetadata meta = classMetadata;@b@ String[] arr$ = tokens; int len$ = arr$.length; for (int i$ = 0; i$ < len$; ++i$) { String token = arr$[i$];@b@ type = meta.getPropertyType(token);@b@ if (type instanceof EntityType) {@b@ EntityType entityType = (EntityType)type;@b@ String entityName = entityType.getAssociatedEntityName();@b@ meta = sessionFactory.getClassMetadata(entityName);@b@ }@b@ }@b@ return type;@b@ }@b@ return null;@b@ }@b@}