六月婷婷综合激情-六月婷婷综合-六月婷婷在线观看-六月婷婷在线-亚洲黄色在线网站-亚洲黄色在线观看网站

明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

nhibernate源碼區分之一: 對象映射

[摘要]1. 持久對象映射文件關于持久對象映射文件,這里就不多說了,可參考nhibernate的例子和文檔。在nhibernate源代碼的根目錄里有一個nhibernate-mapping-2.0.xsd文檔,這個文檔是nhibernate用來對映射文件進行驗證的,我們也可以借助相關軟件用這個文檔來驗證映...
1. 持久對象映射文件

關于持久對象映射文件,這里就不多說了,可參考nhibernate的例子和文檔。
在nhibernate源代碼的根目錄里有一個nhibernate-mapping-2.0.xsd文檔,這個文檔是nhibernate用來對映射文件進行驗證的,我們也可以借助相關軟件用這個文檔來驗證映射文件的有效性。

2. 映射信息的讀取

通過Configuration類,可以用多種方式讀取映射信息,一些以Add開頭的方法就是用來加入映射信息的,這些方法最終將調用Add(XmlDocument doc)。

//** Configuration.cs **

private Hashtable classes = new Hashtable();
classes集合用于存放所有的持久對象映射信息,
它的Key為持久類的類型;Value為PermissionClass類的子類。

private void Add(XmlDocument doc) {
try {
Binder.dialect = Dialect.Dialect.GetDialect(properties);
Binder.BindRoot( doc, CreateMappings());
}
catch (MappingException me) {
log.Error("Could not compile the mapping document", me);
throw me;
} // end try/catch
}

AddDocument方法調用Binder的靜態方法BindRoot來綁定持久類映射信息。CreateMappings返回一個Mappings對象,此對象是一個簡單封裝了所有映射信息集合的類。

3. 建立對象映射信息

Binder類的BindRoot用于綁定映射信息中的所有映射內容。

//** Binder.cs **

public static void BindRoot(XmlDocument doc, Mappings model) {
// ...

foreach(XmlNode n in hmNode.SelectNodes(nsPrefix + ":class", nsmgr) ) {
RootClass rootclass = new RootClass();
Binder.BindRootClass(n, rootclass, model);
model.AddClass(rootclass);
}

// ...
}

遍歷所有的類映射節點,然后調用BindRootClass來綁定類映射信息,最后將類映射信息加到集合中。
其中RootClass為PermissionClass的子類。

public static void BindRootClass(XmlNode node, RootClass model, Mappings mappings) {
BindClass(node, model, mappings);

//TABLENAME
XmlAttribute tableNameNode = node.Attributes["table"];
string tableName = (tableNameNode==null)
? StringHelper.Unqualify( model.PersistentClazz.Name )
: tableNameNode.Value;

XmlAttribute schemaNode = node.Attributes["schema"];
string schema = schemaNode==null ? mappings.SchemaName : schemaNode.Value;
Table table = mappings.AddTable(schema, tableName);
model.Table = table;

// ...

PropertiesFromXML(node, model, mappings);
}

BindRootClass首先調用BindClass綁定持久類映射信息,然后調用PropertiesFromXML來綁定類屬性。

public static void BindClass(XmlNode node, PersistentClass model, Mappings mapping) {
string className = node.Attributes["name"] == null ? null : node.Attributes["name"].Value;

// class
try {
model.PersistentClazz = ReflectHelper.ClassForName(className);
}
catch ( Exception cnfe ) {
throw new MappingException( "persistent class not found", cnfe);
}

// ...
}

BindClass通過反射來取得持久對象的類型。

protected static void PropertiesFromXML(XmlNode node, PersistentClass model, Mappings mappings) {
string path = model.Name;
Table table = model.Table;

foreach(XmlNode subnode in node.ChildNodes) {
CollectionType collectType = CollectionType.CollectionTypeFromString(name);
Value value = null;
if (collectType!=null) {
value = new Value(table);
BindValue(subnode, value, true);
}
else if ( "many-to-one".Equals(name) ) {
value = new ManyToOne(table);
BindManyToOne(subnode, (ManyToOne) value, propertyName, true);
}
else if ( "any".Equals(name) ) {
value = new Any(table);
BindAny(subnode, (Any) value, true);
}
else if ( "one-to-one".Equals(name) ) {
value = new OneToOne(table, model.Identifier );
BindOneToOne(subnode, (OneToOne) value, true);
}
else if ( "property".Equals(name) ) {
value = new Value(table);
BindValue(subnode, value, true, propertyName);
}
else if ( "component".Equals(name) ) {
value = new Component(model);
BindComponent(subnode, (Component) value, reflectedClass, subpath, true, mappings);
}
else if ( "subclass".Equals(name) ) {
Subclass subclass = new Subclass(model);
BindSubclass( subnode, subclass, mappings );
}
else if ( "joined-subclass".Equals(name) ) {
Subclass subclass = new Subclass(model);
BindJoinedSubclass( subnode, subclass, mappings);
}
if ( value!=null) {
Property prop = new Property(value);
BindProperty(subnode, prop, mappings);
}
}
}

遍歷所有子節點,然后根據節點類型對進行綁定。(注: 部分內容已刪除)
關于屬性的映射以后有空再詳細研究,只需要知道屬性已加入到RootClass的Properties屬性就行了。




主站蜘蛛池模板: 四虎免费在线播放 | 四虎影视免费观看免费观看 | 色综合久久综合欧美综合 | 天天色综合2 | 亚洲影音| 亚洲 国产精品 日韩 | 中文字幕在线不卡 | 色小妹综合 | 又大又硬又爽又粗又快的视频免费 | 四虎影视免费永久在线观看 | 青草精品在线 | 亚洲国产综合精品中文字幕 | 亚洲高清日韩精品第一区 | 欧美一区二区在线观看 | 日本在线一本 | 青青青青青在线视频播放 | 亚洲欧美在线免费观看 | 日本道高清 | 日韩a在线播放 | 色综合色综合色综合 | 综合色久七七综合七七蜜芽 | 伊人久久大香线蕉观看 | 伊人色综合久久天天人手人停 | 婷婷色天使在线视频观看 | 亚洲人成网男女大片在线播放 | 青草草在线观看 | 日韩视频中文字幕专区 | 亚洲国产欧美在线人成精品一区二区 | 色天天综合网 | 视频精品一区二区 | 色猫咪av在线网址 | 青青青免费高清视频在线 | 中文天堂在线www | 青青草原在线视频免费观看 | 永久免费观看午夜视频在线 | 在线观看h视频播放高清 | 日韩精品视频观看 | 性欧美巨大极品videos | 性亚洲| 香蕉狠狠再啪线视频 | 午夜影院免费在线观看 |