当前位置: 首页 > news >正文

手机网站模板安装方法中国中小企业信息网官网

手机网站模板安装方法,中国中小企业信息网官网,时尚wordpress免费主题下载,有没有可以做翻译的网站吗介绍 在上一篇文章中#xff0c;我宣布了我打算创建个人Hibernate课程的意图。 首先要做的是最小的测试配置。 这些示例与Hibernate 4有关。 您只需要休眠 在实际的生产环境中#xff0c;您不会单独使用Hibernate#xff0c;因为您可以将其集成到JEE或Spring容器中。 要测试… 介绍 在上一篇文章中我宣布了我打算创建个人Hibernate课程的意图。 首先要做的是最小的测试配置。 这些示例与Hibernate 4有关。 您只需要休眠 在实际的生产环境中您不会单独使用Hibernate因为您可以将其集成到JEE或Spring容器中。 要测试Hibernate功能您不需要完整的框架堆栈只需依赖Hibernate灵活的配置选项即可。 情况1基于驱动程序的JDBC配置 我们首先定义一个测试实体 Entity class SecurityId {IdGeneratedValueprivate Long id;private String role;public Long getId() {return id;}public String getRole() {return role;}public void setRole(String role) {this.role role;} } 多亏了Hibernate Transaction抽象层我们不必强迫使用任何外部事务管理器也不必编写任何自制的事务管理代码。 为了进行测试我们可以使用JDBC资源本地事务该事务由默认的JdbcTransactionFactory内部管理。 我们甚至不需要提供外部数据源因为Hibernate提供了一个由DriverManagerConnectionProviderImpl表示的非生产内置连接池。 我们的测试代码如下 Test public void test() {Session session null;Transaction txn null;try {session sf.openSession();txn session.beginTransaction();SecurityId securityId new SecurityId();securityId.setRole(Role);session.persist(securityId);txn.commit();} catch (RuntimeException e) {if ( txn ! null txn.isActive() ) txn.rollback();throw e;} finally {if (session ! null) {session.close();}} } 我们不需要任何外部配置文件因此这是我们可以构建和配置会话工厂的方式 Override protected SessionFactory newSessionFactory() {Properties properties new Properties();properties.put(hibernate.dialect, org.hibernate.dialect.HSQLDialect);//log settingsproperties.put(hibernate.hbm2ddl.auto, update);properties.put(hibernate.show_sql, true);//driver settingsproperties.put(hibernate.connection.driver_class, org.hsqldb.jdbcDriver);properties.put(hibernate.connection.url, jdbc:hsqldb:mem:test);properties.put(hibernate.connection.username, sa);properties.put(hibernate.connection.password, );return new Configuration().addProperties(properties).addAnnotatedClass(SecurityId.class).buildSessionFactory(new StandardServiceRegistryBuilder().applySettings(properties).build()); }情况2使用专业的连接池 如果我们想用专业的连接池来代替内置的连接池Hibernate提供了设置c3p0的选择该设置由C3P0ConnectionProvider在内部处理。 我们只需要更改会话工厂配置属性 protected SessionFactory newSessionFactory() {Properties properties new Properties();properties.put(hibernate.dialect, org.hibernate.dialect.HSQLDialect);//log settingsproperties.put(hibernate.hbm2ddl.auto, update);properties.put(hibernate.show_sql, true);//driver settingsproperties.put(hibernate.connection.driver_class, org.hsqldb.jdbcDriver);properties.put(hibernate.connection.url, jdbc:hsqldb:mem:test);properties.put(hibernate.connection.username, sa);properties.put(hibernate.connection.password, );//c3p0 settingsproperties.put(hibernate.c3p0.min_size, 1);properties.put(hibernate.c3p0.max_size, 5);return new Configuration().addProperties(properties).addAnnotatedClass(SecurityId.class).buildSessionFactory(new StandardServiceRegistryBuilder().applySettings(properties).build()); }情况3使用外部数据源 由于Hibernate不会记录SQL预准备语句参数 o.h.SQL - insert into SecurityId (id, role) values (default, ?) 我们将添加一个datasource-proxy来拦截实际的SQL查询 n.t.d.l.SLF4JQueryLoggingListener - Name: Time:0 Num:1 Query:{[insert into SecurityId (id, role) values (default, ?)][Role]} 配置如下所示 Override protected SessionFactory newSessionFactory() {Properties properties new Properties();properties.put(hibernate.dialect, org.hibernate.dialect.HSQLDialect);//log settingsproperties.put(hibernate.hbm2ddl.auto, update);//data source settingsproperties.put(hibernate.connection.datasource, newDataSource());return new Configuration().addProperties(properties).addAnnotatedClass(SecurityId.class).buildSessionFactory(new StandardServiceRegistryBuilder().applySettings(properties).build()); }private ProxyDataSource newDataSource() {JDBCDataSource actualDataSource new JDBCDataSource();actualDataSource.setUrl(jdbc:hsqldb:mem:test);actualDataSource.setUser(sa);actualDataSource.setPassword();ProxyDataSource proxyDataSource new ProxyDataSource();proxyDataSource.setDataSource(actualDataSource);proxyDataSource.setListener(new SLF4JQueryLoggingListener());return proxyDataSource; }结论 这是测试Hibernate功能所需的最低配置设置。 每当我提交带有复制测试用例的Hibernate错误报告时我也会使用这些配置。 代码可在GitHub上获得 。 翻译自: https://www.javacodegeeks.com/2014/06/the-minimal-configuration-for-testing-hibernate.html
http://www.sadfv.cn/news/297615/

相关文章:

  • 微商网站如何做推广光伏发电国家最新政策
  • 网站建设指导思想短视频赚钱app软件
  • 学生做网站怎么收费男做直播网站好
  • 做动态在网站需要学什么国内外免费域名解析网站
  • 大连网站设计团队wordpress文字采集
  • iis7添加php网站免费的企业建站cms
  • 企业网站的网络营销功能包括windows优化大师自动安装
  • 做多个网站 买vps备案价公示网站
  • 品牌网站建设权威网站怎么做弹幕播放器
  • 爱站关键词查询网页美工设计主要从哪些方面设计
  • 公司做网站有什么好处香河县住房和城乡建设局网站
  • 温州网站制作套餐北京公司摇号中签率
  • 哪个网站可以做自己的网页网站标题堆砌关键词
  • 容县住房和城乡建设局网站河南郑州做网站h汉狮
  • 香奈儿网站建设策划书工程管理咨询公司
  • 360网站seo如何做wordpress 动态特效
  • 网站建设需要哪些书籍整合营销方案案例
  • 北京做网站s百度资源平台链接提交
  • pc网站建设怎么样一级a做爰片阿v祥仔网站
  • 网站设计用户体验软件公司做网站
  • 婴幼儿用品网站开发意义桂林森威建筑工程监理有限责任公司
  • 上海市官方网站财务公司经营范围
  • 汕头网站建设策划百度收录提交申请网站
  • 网站建设与网络编辑综合实训课程指导手册pdf天元建设集团有限公司电话号码
  • 申请网站空间就是申请域名网页微信版官网登录下载
  • 台中网站建设同一个网站可以同时做竞价和优化
  • 在哪找做调查赚钱的网站网站用什么框架
  • wordpress全站登陆可见黄骅港海关
  • 临沂建站公司湛江海田网站建设招聘
  • 关于网站建设的题目开发公司移交给物业资料说明