看了些原始碼,寫了些記錄。發表出來,希望初學者有用。如有不對的地方,請指正。
Setting類:資料庫,串連池設定的Bean,主要是各種參數的set&get方法。
Environment類:環境參數定義。(常量)
NamingStratgy:命名規則定義的介面。
DefaultNamingStrategy:預設命名規則。(實現NamingStratgy介面)
ImprovedNamingStrategy:改善命名規則。(實現NamingStratgy介面)就是加底線。其中有個addUnderscores()方法。
<CCID_NOBR>
<CCID_CODE>private String addUnderscores(String name) {StringBuffer buf = new StringBuffer( name.replace('.', '_') );for (int i=1; i<buf.length()-1; i++) {if ('_'!=buf.charAt(i-1) &&Character.isUpperCase( buf.charAt(i) ) &&!Character.isUpperCase( buf.charAt(i+1) )) {buf.insert(i++, '_');}}return buf.toString().toLowerCase();}</CCID_CODE> |
</CCID_NOBR>
按大寫分開,加上"_",然後返回小寫toString();
SettingFactory類:設定屬性類。其中有buildSettings(Properties properties)方法,設定自訂屬性。
Mapping類:有點不清楚。設定類和表之間的映射。class 進去,table出來。:)(瞭解不清晰。)
Binding類:PO和資料庫中表及其之間的映射的綁定。
Configuration類,配置類Configuration()構建器,調用reset(),重設參數。
還有addClass(),addFile(),add(document.nbsp;doc) ,addDirectory(),addJar(),addInputString(),addResoure()等一系列方法,通過不同的資源進行配置。
還有通過不同參數重構了許多configure()方法。configure()通過hibernate.cfg.xml配置。
<CCID_NOBR>
<CCID_CODE>/*** Use the mappings and properties specified in an application* resource named <tt>hibernate.cfg.xml</tt>.*/public Configuration configure() throws HibernateException {configure("/hibernate.cfg.xml");return this;}然後比較重要的是產生SessionFactory;public SessionFactory buildSessionFactory() throws HibernateException {secondPassCompile();validate();Environment.verifyProperties(properties);Properties copy = new Properties();copy.putAll(properties);Settings settings = buildSettings();configureCaches(settings);return new SessionFactoryImpl(this, settings);}</CCID_CODE> |
</CCID_NOBR>
其他的一些就是通過設定檔設定各種屬性。比如資料庫方言Dialect等。(T111)