Hibernate源碼淺析

來源:互聯網
上載者:User
看了些原始碼,寫了些記錄。發表出來,希望初學者有用。如有不對的地方,請指正。
    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)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.