Username: Password:

Hibernate源码浅析
来源:linux宝库作者:linux宝库 发布时间:2007-09-30 00:00:00


  Setting类:数据库,连接池配置的Bean,主要是各种参数的set&get方法。

  Environment类:环境参数定义。(常量)

  NamingStratgy:命名规则定义的接口。

  DefaultNamingStrategy:默认命名规则。(实现NamingStratgy接口)

  ImprovedNamingStrategy:改善命名规则。(实现NamingStratgy接口)

  就是加下划线。其中有个addUnderscores()方法。

  private String addUnderscores(String name) {

  StringBuffer buf = new StringBuffer( name.replace(’.’, ’_’) );

  for (int i=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();

  }

  按大写分开,加上"_",然后返回小写的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配置。

  /**

  * Use the mappings and properties specified in an application

  * resource named hibernate.cfg.xml.

  */

  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);

  }

  其他的一些就是通过配置文档配置各种属性。比如数据库方言Dialect等。

  

喜欢本文,那就收藏到:

    Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪ViVi 365Key网摘 天极网摘 和讯网摘 博拉网 POCO网摘 添加到饭否 QQ书签 Digbuzz我挖网
相关评论  我也要评论
还没有关于此文章的相关评论!
  • 昵称: (为空则显示guest)
  • 评论分数: ★ ★ ★★★ ★★★★ ★★★★★
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
  • 导航
    赞助商
    文章类别
    订阅