configuration接口
- 格式:doc
- 大小:36.50 KB
- 文档页数:3
typec接口cc脚工作原理
Type-C接口的CC脚(Connection Configuration)是用于检测和识别连接设备的一组引脚。
CC脚有两个:CC1和CC2,分别用于发送和接收信号。
当两个设备连接时,它们会互相发送探测信号并进行握手操作,以便识别连接的设备类型和角色。
CC1和CC2可以承载的信号包括两种:初始VBus电压(5V或12V)和Type-C协议。
连接双方通过协商确定一方扮演Source角色,即提供电源或Sink角色,即消耗电源。
Source角色提供的电源通过VBus 引脚输出给Sink角色。
在协商角色和电压之前,连接双方会进行初步探测,例如识别连接的设备类型和确定通信速率等。
这些操作通过CC引脚发送和接收电压来实现。
当设备连接时,Type-C接口会先发送5V的电压,如果连接的设备是支持Type-C协议的设备,则会返回应答信号并进行进一步的握手协商。
如果连接的设备不支持Type-C协议,则会继续使用5V电源供电,而不进行任何握手操作。
总之,Type-C接口的CC脚通过发送和接收信号,实现设备类型识别、电压协商、角色切换等操作,为连接设备提供了更智能化和高效的数据传输方式。
SV中的configuration是一种非常重要的概念,它的使用在系统Verilog中起着至关重要的作用。
在本文中,我们将探讨SV中configuration的用法,希望对读者有所帮助。
一、什么是configuration?在开始探讨SV中的configuration用法之前,我们首先需要了解configuration是什么。
在系统Verilog中,configuration用于描述模块的连接和实例化方式,可以理解为一种实例化模板,用于定义各个模块之间的连接关系和实例化方式。
二、configuration的语法在SV中,一个configuration包含了一系列的实例化语句和端口连接语句,其基本语法如下:```systemverilogconfiguration config_name of entity_name is// 实例化语句// 端口连接语句endconfig;```其中,config_name是配置的名称,entity_name是被配置的实体名称。
在configuration中,通过实例化语句和端口连接语句,可以灵活地配置各个模块之间的连接关系和实例化方式。
三、configuration的作用配置的关键是根据不同的需求,实例化和连接各个模块。
当需要对同一个模块进行不同的实例化和连接时,就可以通过配置来实现。
配置还可以用于隐藏某些模块的实例化和连接细节,使得代码更加清晰和模块化。
四、配置的使用场景在实际的项目开发中,配置的使用场景非常丰富。
其中,最常见的使用场景包括:1. 仿真和验证环境配置:在仿真和验证环境中,经常需要配置不同的测试组合来验证设计的功能和性能。
通过配置,可以灵活地实例化和连接各个测试组合,从而方便地进行验证和调试工作。
2. IP的多次实例化:在实际的IP设计中,经常需要对同一个IP进行多次实例化。
通过配置,可以定义不同的实例化方式和连接关系,并通过参数化的方式灵活地配置各个实例。
简述gpio_configuration 函数的功能GPIOConfiguration函数是用于配置GPIO(通用输入/输出)的函数,它在嵌入式系统中具有重要作用。
GPIO接口是硬件设备与外部电路之间进行数据传输的关键接口。
通过对GPIO进行配置,可以使硬件设备与外部电路实现正确的数据交互。
在本文中,我们将详细介绍GPIOConfiguration函数的功能、实现步骤以及在实际应用中的重要性。
GPIOConfiguration函数的主要功能如下:1.初始化GPIO引脚:根据预先设定的GPIO模式(输入、输出等),配置引脚的电平状态。
2.设置GPIO引脚的驱动模式:根据实际需求,设置GPIO引脚的驱动模式,如浮空、上拉、下拉等。
3.设置GPIO引脚的速度:根据信号传输速度的要求,设置GPIO引脚的速度。
4.配置GPIO引脚的相关参数:如输入滤波器、输出缓冲器等。
GPIOConfiguration函数的主要实现步骤如下:1.定义GPIOInitStructure结构体变量,用于存储GPIO引脚的配置参数。
2.设置GPIOInitStructure中的GPIOPin字段,指定要配置的GPIO引脚。
3.设置GPIOInitStructure中的GPIOMode字段,指定GPIO引脚的模式(输入、输出等)。
4.设置GPIOInitStructure中的GPIOSpeed字段,指定GPIO引脚的传输速度。
5.使用GPIOInit函数,将配置好的GPIOInitStructure传递给相应的GPIO端口,完成GPIO引脚的配置。
GPIOConfiguration函数在实际应用中的重要性体现在:1.确保硬件设备与外部电路的正常通信:通过配置GPIO,可以使硬件设备与外部电路之间实现正确、高效的数据传输。
2.提高系统的灵活性和可扩展性:通过对GPIO进行配置,可以灵活地实现多种功能,满足不同应用场景的需求。
3.简化系统设计:GPIOConfiguration函数提供了一种统一、简化的配置方法,有利于降低系统设计的复杂度。
简述gpio_configuration 函数的功能gpio_configuration函数是一个用于配置GPIO(General Purpose Input/Output)接口的函数。
GPIO接口是现代电子设备中常见的一种通用的数字输入输出接口,可以可编程的控制外部设备的各种操作和状态。
GPIO接口包括一组数字引脚,可以通过读取和写入引脚的电平状态来实现输入和输出功能。
配置这些引脚通常需要在软件层面进行设置,而gpio_configuration函数就提供了一种方便快速配置GPIO接口的方法。
下面将详细介绍gpio_configuration函数的功能,并逐步阐述它的工作原理和使用方法。
1. 引入gpio_configuration函数gpio_configuration函数通常是在驱动程序或应用程序中使用的,需要根据具体的应用需求进行引入。
2. 函数定义gpio_configuration函数的定义类似于下面的形式:void gpio_configuration(int pin, int mode, int pull_up_down)其中,pin代表要配置的GPIO引脚编号,mode表示引脚的工作模式,pull_up_down表示上下拉电阻的设置。
3. 引脚编号GPIO引脚通常是通过一个数字进行标识,具体的编号规则要根据硬件平台和硬件设计而定。
不同的开发板或芯片可能会有不同的GPIO引脚编号方式,例如树莓派上的GPIO引脚编号是基于BCM(Broadcom)的标号系统,而Arduino则使用的是数字引脚编号。
在使用gpio_configuration函数时,需要根据实际情况传入正确的GPIO 引脚编号参数,否则可能无法正确配置GPIO接口。
4. 工作模式GPIO引脚的工作模式通常有输入和输出两种。
输入模式用于读取外部设备的状态或传感器的数据,而输出模式可以控制外部设备的开关状态或输出相关信号。
hibernate4学习笔记Hibernate4学习笔记本⼈全部以⾃学为主,在⽹上收集各种学习资料,总结归纳学习经验,现将学习路径给予⼤家分享。
此次学习的hibernate的版本是:hibernate-release-4.2.4.Final(截⽌2015年7⽉31⽇最新版),JAVA的版本是:java8.0,使⽤的开发⼯具是:Eclipse Mars Release (4.5.0)。
第⼀天:Hibernate4基础知识和HelloWorld简单编程Hibernate是⼀种半成品ORM框架,对数据库持久化操作,程序员对数据库的操作转换成对对象的操作。
ORM 采⽤元数据来描述对象-关系映射细节, 元数据通常采⽤XML 格式, 并且存放在专门的对象-关系映射⽂件中。
HelloWorld简单编程1、准备Hibernate环境(1)导⼊Hibernate的Jar包,如下:(2)导⼊Mysql驱动包,我⽤的数据库是:Mysql 5.0,数据库驱动包如下:以上所有Jar加完毕之后,需要加⼊到Eclipse⾃⾝系统⾥⾯,具体如下:以上操作完毕之后,Hibernate的环境就算搭建完毕,下⾯就可以进⼀步操作。
2、配置hibernate.cfg.xml⽂件,主要是对数据库的连接,具体如下:"-//Hibernate/Hibernate Configuration DTD 3.0//EN""/doc/63fa364d5022aaea998f0fde.html /hibernate-configuration-3.0.dtd ">rootmysqlname="connection.driver_class">com.mysql.jdbc.Driver jdbc:mysql:///Test(或者:jdbc:mysql://localhost:3306/Test)name="dialect">org.hibernate.dialect.MySQLInnoDBDialecttruetrueupdate3、编写⼀个实例类News.java,具体代码如下:package com.hibernate.helloworld;import java.sql.Date;public class News {private Integer id;private String title;private Date date;public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getTitle() {return title;}public void setTitle(String title) {this.title = title;}public String getAuthor() {return author;}public void setAuthor(String author) {this.author = author;}public Date getDate() {return date;}public void setDate(Date date) {this.date = date;}public News(String title, String author, Date date) { super();this.title = title;this.author = author;this.date = date;}public News(){}@Overridereturn"News [id="+ id+ ", title="+ title+ ", author="+ author + ", date=" + date + "]";}}4、创建News.hbm.xml配置映射⽂件,具体代码如下:"/doc/63fa364d5022aaea998f0fde.html /hibernate-mapping-3.0.dtd">5、将映射⽂件News.hbm.xml指定到hibernate.cfg.xml配置⽂件⾥⾯,即在hibernate.cfg.xml⽂件⾥加⼊⼀⾏映射代码,具体如下:6、创建hibernate API操作测试类(Juit测试),验证hibernate的优势效果,具体代码如下:package com.hibernate.helloworld;import java.sql.Date;import org.hibernate.Session;import org.hibernate.SessionFactory;import org.hibernate.Transaction;import org.hibernate.cfg.Configuration;import org.hibernate.service.ServiceRegistry;import org.hibernate.service.ServiceRegistryBuilder;import org.junit.Test;public class HibernateTest {@Testpublic void test() {//1. 创建⼀个 SessionFactory 对象SessionFactory sessionFactory=null;//1). 创建 Configuration 对象: 对应 hibernate 的基本配置信息和对象关系映射信息Configuration configuration=new Configuration().configure();//4.0 之前这样创建//sessionFactory=configuration.buildSessionFactory();//2). 4.0以后创建⼀个 ServiceRegistry 对象: hibernate 4.x 新添加的对象//hibernate 的任何配置和服务都需要在该对象中注册后才能有效.ServiceRegistry serviceRegistry=newServiceRegistryBuilder().applySettings(configuration.getProperties() ).buildServiceRegistry();sessionFactory=configuration.buildSessionFactory(serviceRegistry) ;//2. 创建⼀个 Session 对象Session session=sessionFactory.openSession();//3. 开启事务Transaction transaction=session.beginTransaction();//4. 执⾏保存操作News news = new News("Java12345", "ATGUIGU", new Date(new java.util.Date().getTime()));session.save(news);//5. 提交事务/doc/63fa364d5022aaea998f0fde.html mit();//6. 关闭 Sessionsession.close();//7. 关闭 SessionFactory 对象sessionFactory.close();}}7、测试结果如下:(1)数据库⾥⾯的结果如下:(2)Eclipse下的语句⽣成如下:以上就是简单Hibernate的测试,总结:1、不需要在数据库⾥⾯创建任何数据,由hibernate ⾃动⽣成;2、代码简单易理解,不复杂,测试数据只需要先创建以下⼏个步骤:SessionFactory-→Session-→Transaction-→session操作数据库-→提交-→关闭;3、不需要写SQL 语句,从头到尾没有写⼀条SQL语句,反⽽Hibernate帮我们⽣成SQL语句。
configuration和component区别从上⾯链接,可以看到,虽然Component注解也会当做配置类,但是并不会为其⽣成CGLIB代理Class,所以在⽣成Driver对象时和⽣成Car对象时调⽤car()⽅法执⾏了两次new操作,所以是不同的对象。
(1)、此处⽤component,对sSOInterceptor来说,采⽤⾃动注⼊的⽅式,那么上图的ssoConfig,userAuthTokenRequest,也会被注⼊(2)、此处⽤component,对sSOInterceptor来说,采⽤新建的⽅式,那么上图的ssoConfig,userAuthTokenRequest,就不会被⾃动注⼊,全为空(3)、此处⽤configuration,对sSOInterceptor来说,采⽤新建的⽅式,那么上图的ssoConfig,userAuthTokenRequest,也会被⾃动注⼊(//(1)在此处的bean,已经实例化成单例了,所以不会再进⼊到SSOInterceptor类⾥⾯进⾏操作了(此处,实际上应该是对Configuration注解的bean,即使是new,也是同⼀个对象实例,前提是不设置⽣命的周期的话))总结:对configuration来说,对new新建也会采⽤cgLib的⽅式实现注⼊。
通俗点讲,就是,对congfiguration来说,即使new,也是同⼀个实例(如果不设置⽣命周期,即默认是单例的模式)。
对component来说,如果使⽤new进⾏实例化,那么此对象中的属性不会⾃动注⼊,如此⽂章的第(2)条所描述的。
但⽆论configuration或者component来说,都可以⽤@Scope控制bean的⽣命周期例如:@Scope(value= WebApplicationContext.SCOPE_REQUEST,proxyMode = ScopedProxyMode.TARGET_CLASS)。
E1接口配置(E1 interface configuration)The E1 interface can have two configurations:L is used as a channelized (Channelized) E1 interface.In the physical interface is divided into 31 time slots, all the slots can be arbitrarily divided into several groups, each time slot after use bundled as an interface, the logic is the same as the synchronous serial port, support PPP, LAPB, frame relay and X.25 link layer protocol.L is used as a non channelized (Unchannelized) E1 interface.The interface acts as a G.703 synchronous serial port of 2M at physical rate, and supports link layer protocols such as PPP, frame relay, LAPB and X.25.E1 interface configurationTo configure the E1 interface, you must first enter the controller E1 command in the global configuration state.commandEffectController E1 <slot>/<group>Configuring the E1 interfaceSlot is the slot number at which the E1 controller is located,Group is the link number for the E1 controller.Note: the E1 controller in the 3700 series router is "controller E1 0/0", and the 5000 Series router has an E1 controller, the link number range is 0-0, and for the four port E1 controller, the link number range is 0-3. The E1 controller slot number is 1-4.Give an example:Router_config#controller E1 0/0Router_config_controller_E1_0/0#The configuration tasks for the E1 interface include:L configure the physical parameters of the E1 interface, including frame check mode, line codec format and line clock, loopback transmission mode, and so on. The default parameter is generally used.L channelization (Channelized) E1 interface requires configuration of channel-group parameters and determination of slot binding methods.The L non channelized (Unchannelized) E1 interface does not need to configure the channel-group parameter.L configuration interface (Interface) parameter,Configure how the E1 interface worksThe E1 interface defaults to channelized (Channelized) mode. It can be set to non channelized (Unchannelized) mode via the unframed command.commandEffectUnframedConfigured as non channelized (Unchannelized) modeNo unframedConfigured as channelized (Channelized) modeGive an example:Router_config#controller E1 0/0Router_config_controller_E1_0/0# unframedRouter_config_controller_E1_0/0# no unframedConfigure the frame check mode of the E1 interfaceThe E1 interface supports the CRC32 checksum of the physical frame, which is not checked by default.commandEffectFraming crc4The frame check mode for configuring the E1 interface is 4 bytes CRC checksumNo, framing, orFraming no-crc4No frame checks are configured for the E1 interfaceLine codec format for configuring the E1 interfaceThe E1 interface supports two line codec formats: AMI format and HDB3 formatThe default is HDB3 format.commandEffectLinecode AMIThe line encoding format for configuring the E1 interface is AMI formatNo, linecode, orLinecode HDB3The line encoding format for configuring the E1 interface is HDB3 formatConfigure the clock mode of the E1 interfaceWhen E1 is used as a synchronous interface, there are two modes of operation, DTE and DCE, as well as the choice of the line clock. The E1 interface when the two router is directly connected, must make both ends at DTE and DCE; when the E1 interface router and switch connection, the switch for the DCE device, and E1 interface router needs to work in the DTE way.The E1 interface defaults to DTE mode.commandEffectClock internalConfigure the E1 interface to work in DCE mode using the chip internal sync signalClock externalNo clockConfiguring the E1 interface operates in DTE mode using line synchronization signalsLoopback transfer mode configured with the E1 interfaceIn the remote loopback transport mode, E1 sends messages received from the port back from the received channel.commandEffectLoopback localConfigure the E1 interface to work in the remote loopback modeNo loopCancel the remote loopback settingsConfigure the transmit pulse mode of E1Select Send pulse mode. When the cable type is 120 twisted pair, the Cable 120 should be executed. By default, the default is 75 copper axle cable (no cable), comply with the ITU-T G.703 standard. Both send pulses differently.commandEffectCable 120Configure the E1 interface cable type 120 UTPNo cableThe default is 75 coaxial cable.E1 interface link is prohibitedYou can disable the use of a E1 interface. The line status of all interface on the port is down.commandEffectShutdownThe E1 interface link is prohibitedNo shutdownRestore the use of the E1 interface linkGive an example:Router_config#controller E1 0/0Router_config_controller_E1_0/0#shutdownRouter_config_controller_E1_0/0#no shutdownConfigure the channel-group parameters of the E1 interfaceChannel-group is the E1 channel number, the range is 0-30, the timeslot is E1, and the slot number is 1-31. The channel can occupy any unallocated slot and can combine any time slots. After the E1 channel configuration is successful, a new interface is generated.The no channel-group clears the channel-group slot binding, and the corresponding interface is also deleted.commandEffectChannel-group channel-group timeslots {number number1-number2} | [number, number1-number2] |...The time slot for the E1 interface is bundled to channel-group No channel-group channel-groupCancel channel-group slot bindingGive an example:Router_config#controller E1 0/0Router_config_controller_E1_0/0#channel 5, timeslots 18,11-13, 20,, 22, 30-28, 24-25Router_config_controller_E1_0/0#interface s0/0:5Router_config_interface_s0/0:5#Configure the interface parameters of the E1 interfaceE1 interface, in a channelized (Channelized) manner, when the channel-group parameter is configured, the system generates new interface. Its logic characteristics are the same as that of synchronous serial ports. The name is serial<slot>/<group>: <channel-group>, where <slot> is consistent with <group> and controller E1 <slot>/<group>.The E1 interface generates a new interface in a non channelized (Unchannelized) manner. The name is serial<slot>/<group>: 0The link layer protocol for PPP, frame relay, HDLC and X.25 can be packaged on the interface.Give an example:Channelized (Channelized) mode:Router_config#controller E1 0/0Router_config_controller_E1_0/0#channel 1 timeslots 1-31Router_config_controller_E1_0/0#int s0/0:1Router_config_controller_s0/0:1#enca frRouter_config_controller_s0/0:1#ip add 130.130.0.1 255.255.255.0Non channelized (Unchannelized) mode:Router_config#controller E1 0/0Router_config_controller_E1_0/0#unframedRouter_config_controller_E1_0/0#int s0/0:0Router_config_controller_s0/0:0#enca frRouter_config_controller_s0/0:0#ip add 130.130.0.1 255.255.255.0。
Type-C (二),Configuration Channel (cc)什么是 Configuration Channel (cc) ?它是位于 Type-C connector 中的两个 pin,是 Host 和 Device 之间重要的配置通道。
主要功能是,Detection Device Insert,Check Positive and negative,Control vconn,Configure Data Bus,Negotiate Power For Vbus,Discover and Configure Alternate Mode。
以上功能都是基于 Type-C Connector 的物理设计,以及 PD Message。
典型的三种 Type-C Port 线路设计A. Source Configuration Channel Functional Model作为一个 Source Port,有如下功能:1. Source 端的 PD Controller 使用 FET 去控制 Vbus 的 Power,未连接 Sink 时,Vbus 关闭2. Source 端分别在 cc1/2 上连接 Rp 电阻,当测检到 Rd 时,则认为 Sink 接入。
Rp 的值向 Sink 端声明了 Source 端的 Current Level。
3. Source 端根据 cc pin 拉低的情况,侦测并建立正确的 USB3.0 Data Path,控制 MUX 保证USB3.0 data path 处于导通状态。
同时判断哪个 cc pin 作为 Vconn4. Source 端一旦检测到 Sink 接入,就会提供 Vbus 和 Vconn Power5. Source 端能够动态调整 Rp 的值,改变提供给 Sink 的 Current Level6. Source 端会持续检测 Rd 状态,以判断 Sink 是否处于接入状态。
详解配置类为什么要添加@Configuration注解不加@Configuration导致的问题我们先来看看如果不在配置类上添加@Configuration注解会有什么问题,代码⽰例如下:@ComponentScan("com.dmz.source.code")//@Configurationpublic class Config{@Beanpublic A a(){return new A(dmzService());}@Beanpublic DmzService dmzService(){return new DmzService();}}public class A {public A(DmzService dmzService){System.out.println("create A by dmzService");}}@Componentpublic class DmzService {public DmzService(){System.out.println("create dmzService");}}不添加@Configuration注解运⾏结果:create dmzServicecreate A by dmzServicecreate dmzService添加@Configuration注解运⾏结果:create dmzServicecreate A by dmzService在上⾯的例⼦中,我们会发现没有添加@Configuraion注解时dmzService被创建了两次,这是因为第⼀次创建是被Spring容器所创建的,Spring调⽤这个dmzService()创建了⼀个Bean被放⼊了单例池中(没有添加其它配置默认是单例的),第⼆次创建是Spring容器在创建a时调⽤了a(),⽽a()⼜调⽤了dmzService()⽅法。
configuration接口Configuration对象用于配置并且启动Hibernate.Hibernate应用通过Configuration实例指定对象-关系映射文件的位置或者动态配置Hibernate的属性.然后创建SessionFactory实例.2>SessionFactory接口一个SesssionFactory实例对一个数据存储源,应用从SessionFactory中获得Session实例.它是线程安全的,这意味着它的同一个实例可以被应用的多个线程共享它是重量级的,这意味着不能随意创建或销毁它的实例,如果应用只访问一个数据库;只需要创建一个SessionFactory实例,在应用初始化的时候创建该实例.如果应用同时访问多个数据库,而需要为每个数据库创建一个单独的SessionFactory实例.之所以称SessionFactory是重量级的,是因为它需要一个很大的缓存,用来存放预定义的SQL语句以及映射元数据等.用户还可以为SessionFacotry配置一个缓存插件,这个缓存插件被称为Hibernate的第二级缓存,该缓存用来存放被工作单元读过的数据,将来其他工作单元可能会重用这些数据,因为这个缓存中的数据能够被所有工作单元共享.一个工作单元通过对应一个数据库事务.3>Session接口Session接口是Hibernate应用使用最广泛的接口,Session也被称为持久化管理器,它提供了和持久化相关的操作,如添加,更新,删除,加载和查询对象.不是线程安全的,因此在设计软件架构时,应该避免多个线程共享同一个Session实例.Session实例是轻量级的,所谓轻量级,是指它的创建和销毁不需要消耗太多资源,这意味着在程序中可以经常创建或销毁Session对象.Session有一个缓存,被称为Hibernate的第一级缓存,它存放被当前工作单元加载的对象.每个Session实例都有自己的缓存,这个Session实例的缓存只能被当前工作单元访问.4>Transaction接口Transaction接口是hibernate的数据库事务接口,它对底层的事务接口做了封装,底层事务接口包括JDBC API,JTA,CORBA.5>Query和Criteria接口Query和Criteria接口是Hibernate的查询接口,用于向数据库查询对象,以及控制执行查询的过程.Query实例包装了一个HQL(Hibernate Query Language)查询语句,HQL查询语句与SQL 查询语句有些相似,但HQL查询语句是面向对象的,它引用类名及类的属性名,而不是表名及表的字段名.Criteria接口完全封装了基于字符串形式的查询语句比Query接口更加面向对象,Criteria接口擅长于执行动态查询.6>回调接口当一个对象发生了特定的事件,例如对象被加载,保存,更新或删除,Hibernate应用可以通过回调接口来响应这一事件.回调接口按实现方式可分为两类.Lifecycle和V alidatable接口:由持久化类来实现这两个接口.Lifecycle接口使持久化类的实例能响应被加载,保存或删除的事件.V alidatable接口使持久化类的实例在被保存之前进行数据验证这种方式强迫持久化类必须实现Hibernate的特定接口,使Hibernate AIP渗透到持久化类中,会影响持久化的的可移植性,因此不值得推荐.Interceptor接口:不必由持久化类来实现Interceptor接口.应用程序可以定义专门实现Interceptor接口的类,Interceptor实现类负责响应持久化类的实例被加载,保存,更新或删除的事件.7>hibernate映射类型接口Type接口表示Hibernate映射类型,用于把域对象映射为数据库关系数据.Hibernate为Type接口提供了各种实现类,它们代表具体的Hibernate映射类型.8>可扩展借口定制主键的生成策略:IdentifierGenerator接口定制本地SQL方言:Dialect抽象类定制缓存机制:Cache和CacheProvider接口定制事务管理:TransactionFactory,Transaction和TransactionManagerLookup接口定制ORM策略:ClassPersister接口定制属性访问策略:PropertyAccessor接口.创建代理:ProxyFactory接口.////////////////////////////////////////////////////////////最佳答案Hibernate的5个核心类或接口:(1)Configuration:用于解析hibernate.cfg.xml文件和XXXXX.hbm.xml文件,并创建SessionFactory对象。
Configuration对象用于配置并且启动Hibernate。
Hibernate应用通过Configuration实例来指定对象--关系映射文件的位置或者动态配置Hibernate的属性,然后创建SessionFactory实例。
(2)SessionFactory:初始化Hibernate,充当数据存储源的代理,创建Session对象。
一个SessinFactory实例对应一个数据存储源,应用从SessionFactory中获得Session实例。
如果应用同时访问多个DB,怎需要为每个数据库创建一个单独的SessionFactory实例。
(3)Session:也被称为持久化管理器,对象级数据库操作。
特点:1)不是线程安全的,因此在设计软件架构时,应该避免多个线程共享同一个Session实例。
2)Session实例是轻量级的,所谓轻量级,是指它的创建和销毁不需要消耗太多的资源。
这意味着在程序中可以经常创建或销毁Session对象,例如为每个客户请求分配单独的Session 实例,或者为每个工作单位分配单独的Session实例。
3)通常将每一个Session实例和一个DB事务邦定,也就是说,每执行一个DB事务,都应该先创建一个新的Session实例,不论事务执行成功与否,最后都应该调用Session的close ()方法,从而释放Session实例占用的资源。
注:每个Session实例都有自己的缓存,这个Session实例的缓存只能被当前的工作单元访问。
(4)Query:执行数据库查询操作。
要使用HQL(HibernateQueryLanguage)查询语句,HQL 查询语句是面向对象的,它引用类名及类的属性名。
(5)Transaction:用于管理操作事务。
它对底层的事务接口做了封装,底层事务接口包括:JDBC API、JTA(JavaTransactionAPI)、CORBA(CommonObjectRequestBroker Architecture)API。
3.Hibernate的5个核心类或接口:(1)Configuration:用于解析hibernate.cfg.xml文件和XXXXX.hbm.xml文件,并创建SessionFactory对象。
Configuration对象用于配置并且启动Hibernate。
Hibernate应用通过Configuration实例来指定对象--关系映射文件的位置或者动态配置Hibernate的属性,然后创建SessionFactory实例。
(2)SessionFactory:初始化Hibernate,充当数据存储源的代理,创建Session对象。
一个SessinFactory实例对应一个数据存储源,应用从SessionFactory中获得Session实例。
如果应用同时访问多个DB,怎需要为每个数据库创建一个单独的SessionFactory实例。
(3)Session:也被称为持久化管理器,对象级数据库操作。
特点:1)不是线程安全的,因此在设计软件架构时,应该避免多个线程共享同一个Session实例。
2)Session实例是轻量级的,所谓轻量级,是指它的创建和销毁不需要消耗太多的资源。
这意味着在程序中可以经常创建或销毁Session对象,例如为每个客户请求分配单独的Session 实例,或者为每个工作单位分配单独的Session实例。
3)通常将每一个Session实例和一个DB事务邦定,也就是说,每执行一个DB事务,都应该先创建一个新的Session实例,不论事务执行成功与否,最后都应该调用Session的close ()方法,从而释放Session实例占用的资源。
注:每个Session实例都有自己的缓存,这个Session实例的缓存只能被当前的工作单元访问。
(4)Query:执行数据库查询操作。
要使用HQL(HibernateQueryLanguage)查询语句,HQL 查询语句是面向对象的,它引用类名及类的属性名。
(5)Transaction:用于管理操作事务。
它对底层的事务接口做了封装,底层事务接口包括:JDBC API、JTA(JavaTransactionAPI)、CORBA(CommonObjectRequestBroker Architecture)API。
二、工作原理1.Hibernate 的初始化.读取Hibernate 的配置信息-〉创建Session Factory1)创建Configeration类的实例。
它的构造方法:将配置信息(Hibernate config.xml)读入到内存。
一个Configeration 实例代表Hibernate 所有Java类到Sql数据库映射的集合。
2)创建SessionFactory实例把Configeration 对象中的所有配置信息拷贝到SessionFactory的缓存中。
SessionFactory的实例代表一个数据库存储员源,创建后不再与Configeration 对象关联。
缓存(cache):指Java对象的属性(通常是一些集合类型的属性--占用内存空间。
SessionFactory的缓存中:Hibernate 配置信息。
OR映射元数据。
缓存-大:重量级对象小:轻量级对象3)调用SessionFactory创建Session的方法1】用户自行提供JDBC连接。
Connection con=dataSource.getConnection();Session s=sessionFactory.openSession(con);2】让SessionFactory提供连接Session s=sessionFactory.openSession();。