hibernate解析Word文档格式.docx

上传人:b****1 文档编号:1550806 上传时间:2023-04-30 格式:DOCX 页数:21 大小:23.88KB
下载 相关 举报
hibernate解析Word文档格式.docx_第1页
第1页 / 共21页
hibernate解析Word文档格式.docx_第2页
第2页 / 共21页
hibernate解析Word文档格式.docx_第3页
第3页 / 共21页
hibernate解析Word文档格式.docx_第4页
第4页 / 共21页
hibernate解析Word文档格式.docx_第5页
第5页 / 共21页
hibernate解析Word文档格式.docx_第6页
第6页 / 共21页
hibernate解析Word文档格式.docx_第7页
第7页 / 共21页
hibernate解析Word文档格式.docx_第8页
第8页 / 共21页
hibernate解析Word文档格式.docx_第9页
第9页 / 共21页
hibernate解析Word文档格式.docx_第10页
第10页 / 共21页
hibernate解析Word文档格式.docx_第11页
第11页 / 共21页
hibernate解析Word文档格式.docx_第12页
第12页 / 共21页
hibernate解析Word文档格式.docx_第13页
第13页 / 共21页
hibernate解析Word文档格式.docx_第14页
第14页 / 共21页
hibernate解析Word文档格式.docx_第15页
第15页 / 共21页
hibernate解析Word文档格式.docx_第16页
第16页 / 共21页
hibernate解析Word文档格式.docx_第17页
第17页 / 共21页
hibernate解析Word文档格式.docx_第18页
第18页 / 共21页
hibernate解析Word文档格式.docx_第19页
第19页 / 共21页
hibernate解析Word文档格式.docx_第20页
第20页 / 共21页
亲,该文档总共21页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

hibernate解析Word文档格式.docx

《hibernate解析Word文档格式.docx》由会员分享,可在线阅读,更多相关《hibernate解析Word文档格式.docx(21页珍藏版)》请在冰点文库上搜索。

hibernate解析Word文档格式.docx

property"

);

while(itr.hasNext()){

Elementnode=(Element)itr.next();

Stringname=node.attributeValue("

name"

Stringvalue=node.getText().trim();

log.debug(name+"

="

+value);

properties.setProperty(name,value);

if(!

name.startsWith("

hibernate"

)){

properties.setProperty("

hibernate."

+name,value);

}

}

Environment.verifyProperties(properties);

}

///为什么会用verifyProperty()方法不太明白

这些信息最终通过Enviroment.verifyProperties(properties)加入程序中!

然后调用了parseSessionFactory(sfNode,name)//sfNode是session-factory中的节点,name是sfNode的中的属性

部分代码如下:

parseSessionFactory(ElementsfNode,Stringname){

Iteratorelements=sfNode.elementIterator();

while(elements.hasNext()){

Elementsubelement=(Element)elements.next();

StringsubelementName=subelement.getName();

if("

mapping"

.equals(subelementName)){

parseMappingElement(subelement,name);

elseif("

class-cache"

///session-factory中其它节点属性

StringclassName=subelement.attributeValue("

class"

AttributeregionNode=subelement.attribute("

region"

finalStringregion=(regionNode==null)?

className:

regionNode.getValue();

booleanincludeLazy=!

"

non-lazy"

.equals(subelement.attributeValue("

include"

));

setCacheConcurrencyStrategy(className,subelement.attributeValue("

usage"

),region,includeLazy);

collection-cache"

Stringrole=subelement.attributeValue("

collection"

role:

setCollectionCacheConcurrencyStrategy(role,subelement.attributeValue("

),region);

listener"

parseListener(subelement);

event"

parseEvent(subelement);

重点在parseMappingElement(subElement,name);

parseMappingElement(ElementmappingElement,Stringname){

//当我们用xxx.hbm.xml是调用的

finalAttributeresourceAttribute=mappingElement.attribute("

resource"

finalAttributefileAttribute=mappingElement.attribute("

file"

finalAttributejarAttribute=mappingElement.attribute("

jar"

finalAttributepackageAttribute=mappingElement.attribute("

package"

//当我们在class用annotation时用的方法

finalAttributeclassAttribute=mappingElement.attribute("

if(resourceAttribute!

=null){

finalStringresourceName=resourceAttribute.getValue();

log.debug("

session-factoryconfig[{}]namedresource[{}]formapping"

name,resourceName);

addResource(resourceName);

elseif(fileAttribute!

finalStringfileName=fileAttribute.getValue();

session-factoryconfig[{}]namedfile[{}]formapping"

name,fileName);

addFile(fileName);

elseif(jarAttribute!

finalStringjarFileName=jarAttribute.getValue();

session-factoryconfig[{}]namedjarfile[{}]formapping"

name,jarFileName);

addJar(newFile(jarFileName));

elseif(packageAttribute!

finalStringpackageName=packageAttribute.getValue();

session-factoryconfig[{}]namedpackage[{}]formapping"

name,packageName);

addPackage(packageName);

elseif(classAttribute!

finalStringclassName=classAttribute.getValue();

session-factoryconfig[{}]namedclass[{}]formapping"

name,className);

try{

//调用annotationClass进行解析,俱体用法不详addAnnotatedClass(ReflectHelper.classForName(className));

如果是resource配置,进行调用addResource(StringresourceName)进行解释xxx.hbm.xml文件:

调用:

add(resourceInputStream,’’resource”,resourceName);

也就是这个方法:

`

privateXmlDocumentadd(InputSourceinputSource,StringoriginType,StringoriginName){

returnadd(inputSource,newOriginImpl(originType,originName));

下面来看看SessionFactorybuildSessionFactory()方法此方法返回一个sessioFactoy对象:

SessionFactorybuildSessionFactory()throwsHibernateException{

log.debug("

Preparingtobuildsessionfactorywithfilters:

"

+filterDefinitions);

secondPassCompile();

if(!

metadataSourceQueue.isEmpty()){

log.warn("

mappingmetadatacachewasnotcompletelyprocessed"

enableLegacyHibernateValidator();

enableBeanValidation();

enableHibernateSearch();

validate();

Propertiescopy=newProperties();

copy.putAll(properties);

PropertiesHelper.resolvePlaceHolders(copy);

Settingssettings=buildSettings(copy);

returnnewSessionFactoryImpl(

this,

mapping,

settings,

getInitializedEventListeners(),

sessionFactoryObserver

);

settings对象传入sessionFactoryImpl中,而settings对象中含有properties的内容,这就是说sessionFactoryImpl完全可以创建与数据库的连接。

Setting由sessionFactory通过builSettings(Propertiesprops)创建详细代码如下:

从这里可以看出,在buildSettions()中已经与数据库建立了连接。

publicSettingsbuildSettings(Propertiesprops){

Settingssettings=newSettings();

//创建setting对象

//SessionFactoryname:

StringsessionFactoryName=props.getProperty(Environment.SESSION_FACTORY_NAME);

settings.setSessionFactoryName(sessionFactoryName);

//JDBCandconnectionsettings:

ConnectionProviderconnections=createConnectionProvider(props);

/////////////////////////////////////////////////////////////////////

一般我们用url来设定,所以这里用了DriverManagerConnectioniProvider

DriverManagerConnectionProvider通过configure(Propertiesprops)方法来配置sql的连接:

StringdriverManager=props.getProperty(Enviroment.DRIVER);

//来获取数据库驱动

connectionProps=ConnectionProviderFactory.getConnectionProperties(props);

//来设置一个property属性,其中含有username,password等相关内容

最后在ConnectionProviderSessionFactory里面调用configure(Propertyprops)方法实现了Connection的初始化呀

settings.setConnectionProvider(connections);

//InterrogateJDBCmetadata

booleanmetaSupportsScrollable=false;

booleanmetaSupportsGetGeneratedKeys=false;

booleanmetaSupportsBatchUpdates=false;

booleanmetaReportsDDLCausesTxnCommit=false;

booleanmetaReportsDDLInTxnSupported=true;

Dialectdialect=null;

JdbcSupportjdbcSupport=null;

//'

hibernate.temp.use_jdbc_metadata_defaults'

isatemporarymagicvalue.

//Theneedforitisintendedtobealleviatedwithfuturedevelopment,thusitis

//notdefinedasanEnvironmentconstant...

//

//itisusedtocontrolwhetherweshouldconsulttheJDBCmetadatatodetermine

//certainSettingsdefaultvalues;

itisusefulto*not*dothiswhenthedatabase

dialect=DialectFactory.buildDialect(props);

dialect=DialectFactory.buildDialect(props);

jdbcSupport=JdbcSupportLoader.loadJdbcSupport(null);

settings.setJdbcSupport(jdbcSupport);

//Queryparsersettings:

//Second-level/querycache:

booleanuseSecondLevelCache=PropertiesHelper.getBoolean(Environment.USE_SECOND_LEVEL_CACHE,properties,true);

log.info("

Second-levelcache:

+enabledDisabled(useSecondLevelCache));

settings.setSecondLevelCacheEnabled(useSecondLevelCache);

booleanuseQueryCache=PropertiesHelper.getBoolean(Environment.USE_QUERY_CACHE,properties);

Querycache:

+enabledDisabled(useQueryCache));

settings.setQueryCacheEnabled(useQueryCache);

//Thecacheproviderisneededwhenweeitherhavesecond-levelcacheenabled

//orquerycacheenabled.NotethatuseSecondLevelCacheisenabledbydefault

settings.setRegionFactory(createRegionFactory(properties,(useSecondLevelCache||useQueryCache)));

booleanuseMinimalPuts=PropertiesHelper.getBoolean(

Environment.USE_MINIMAL_PUTS,properties,settings.getRegionFactory().isMinimalPutsEnabledByDefault()

);

Optimizecacheforminimalputs:

+enabledDisabled(useMinimalPuts));

settings.setMinimalPutsEnabled(useMinimalPuts);

Stringprefix=properties.getProperty(Environment.CACHE_REGION_PREFIX);

if(StringHelper.isEmpty(prefix))prefix=null;

if(prefix!

=null)log.info("

Cacheregionprefix:

+prefix);

settings.setCacheRegionPrefix(prefix);

booleanuseStructuredCacheEntries=PropertiesHelper.getBoolean(Environment.USE_STRUCTURED_CACHE,properties,false);

Structuredsecond-levelcacheentries:

+enabledDisabled(useStructuredCacheEntries));

settings.setStructuredCacheEntriesEnabled(useStructuredCacheEntries);

if(useQueryCache)settings.setQueryCacheFactory(createQueryCacheFactory(properties));

//SQLExceptionconverter:

SQLExceptionConvertersqlExceptionConverter;

try{

sqlExceptionConverter=SQLExceptionConverterFactory.buildSQLExceptionConverter(dialect,properties);

catch(HibernateExceptione){

log.warn("

ErrorbuildingSQLExceptionConverter;

usingminimalconverter"

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 幼儿教育 > 幼儿读物

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2