defalut entityname

[code]
String entityName = node.attributeValue( "entity-name" );
if ( entityName == null ) entityName = getClassName( node.attribute("name"), mappings );
if ( entityName==null ) {
throw new MappingException( "Unable to determine entity name" );
}
persistentClass.setEntityName( entityName );
[/code]

[code]
private static String getClassName(String unqualifiedName, Mappings model) {
if ( unqualifiedName == null ) return null;
if ( unqualifiedName.indexOf( '.' ) < 0 && model.getDefaultPackage() != null ) {
return model.getDefaultPackage() + '.' + unqualifiedName;
}
return unqualifiedName;
}
[/code]

[code]
public String guessEntityName(Object object) throws HibernateException {
errorIfClosed();
String entity = interceptor.getEntityName( object );
if ( entity == null ) {
if ( object instanceof Map ) {
entity = (String) ( (Map) object ).get( DynamicMapInstantiator.KEY );
if ( entity == null ) {
throw new HibernateException( "could not determine type of dynamic entity" );
}
}
else if ( object instanceof Element ) {
// TODO : really need to keep a map of nodeName -> entityName, but that would mean nodeName being distinct
entity = ( (Element) object ).getName();
}
else {
entity = object.getClass().getName();
}
}
return entity;
}
[/code]
[code]
/**
* Return the names of all persistent (mapped) classes that extend or implement the
* given class or interface, accounting for implicit/explicit polymorphism settings
* and excluding mapped subclasses/joined-subclasses of other classes in the result.
*/
public String[] getImplementors(String className) throws MappingException {

final Class clazz;
try {
clazz = ReflectHelper.classForName(className);
}
catch (ClassNotFoundException cnfe) {
return new String[] { className }; //for a dynamic-class
}

ArrayList results = new ArrayList();
Iterator iter = entityPersisters.values().iterator();
while ( iter.hasNext() ) {
//test this entity to see if we must query it
EntityPersister testPersister = (EntityPersister) iter.next();
if ( testPersister instanceof Queryable ) {
Queryable testQueryable = (Queryable) testPersister;
String testClassName = testQueryable.getEntityName();
boolean isMappedClass = className.equals(testClassName);
if ( testQueryable.isExplicitPolymorphism() ) {
if ( isMappedClass ) {
return new String[] {className}; //NOTE EARLY EXIT
}
}
else {
if (isMappedClass) {
results.add(testClassName);
}
else {
final Class mappedClass = testQueryable.getMappedClass( EntityMode.POJO );
if ( mappedClass!=null && clazz.isAssignableFrom( mappedClass ) ) {
final boolean assignableSuperclass;
if ( testQueryable.isInherited() ) {
Class mappedSuperclass = getEntityPersister( testQueryable.getMappedSuperclass() ).getMappedClass( EntityMode.POJO);
assignableSuperclass = clazz.isAssignableFrom(mappedSuperclass);
}
else {
assignableSuperclass = false;
}
if ( !assignableSuperclass ) {
results.add( testClassName );
}
}
}
}
}
}
return (String[]) results.toArray( new String[ results.size() ] );
}[/code]
[code] /**
* 这个方法实际上并不是getClassName,而是getAdaptEntityName
* 它是为了那种偷懒的写法 from A
* 如果都写成from com.A,应该是就不会用到这个方法了。
*/
public String getImportedClassName(String className) {
String result = (String) imports.get(className);
if (result==null) {
try {
ReflectHelper.classForName(className);
return className;
}
catch (ClassNotFoundException cnfe) {
return null;
}
}
else {
return result;
}
}[/code]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值