服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

hibernate源码浅析


  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等。

扫描关注微信公众号