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 );
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;
}
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;
}
/**
* 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() ] );
}
/**
* 这个方法实际上并不是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;
}
}
分享到:
相关推荐
ATTLIST elementname attrname atttype default>`定义了一个属性,其中`attrname`是属性名,`atttype`是属性类型,`default`是默认值。 3. 命名空间:虽然不在DTD的直接范畴内,但与XML紧密相关。命名空间允许在...
ATTLIST elementName attributeName attributeType defaultValue>`声明了一个属性,如`<!ATTLIST book id ID #REQUIRED>`,表示`book`元素必须有一个名为`id`的ID类型属性。 5. **实体声明**:实体是XML中的一个...
ATTLIST elementname attribute name type default>`:定义元素的属性,包括属性名、类型和默认值。 3. `<!NOTATION notationname PUBLIC|SYSTEM identifier>`:定义notation,用于指定外部实体的类型。 4. `<!...
ATTLIST elementName attributeName attributeType defaultValue>`,用于指定元素可以拥有的属性,属性的类型以及默认值。 3. 实体声明:`<!ENTITY entityName "entityValue">`用于定义一个实体,可以是文本字符串...
ENTITY entityName "entityValue"> ``` 参数实体以`%`开头,常用于引入外部文件: ```xml <!ENTITY % entities SYSTEM "entities.ent"> ``` 七、总结 了解XML的外部DTD和内部DTD有助于创建结构清晰、易于维护的...
ATTLIST elementName attributeName attributeType defaultValue>`,定义元素的属性及其类型和默认值。 - **实体声明**:例如`<!ENTITY entityName "entityValue">`,用于定义可重用的文本块或数据。 - **注释**:...
let entity = NSEntityDescription.entity(forEntityName: "EntityName", in: context)! let newObject = NSManagedObject(entity: entity, insertInto: context) newObject.setValue("Hello, Core Data!", ...
ATTLIST elementName attributeName attributeType defaultValue>`来定义。例如,`<!ATTLIST author name CDATA #REQUIRED>`定义了author元素有一个名为name的属性,类型为CDATA(未解析的字符数据),并且是必需的...
- **EntityName**:实体的名称。 - **AttributeCode**:属性的代码或标识。 ### 工具支持的对象语言 - **BMS Object Language**:数据库管理系统的对象语言,支持数据库对象的定义、操作等。 ### 通用操作 - **...