iworkh-springboot-jpa-源码分析
2020-02-21 10:12:04 0 举报
iworkh整理的springboot对于jpa整合源码分析图
作者其他创作
大纲/内容
JpaRepositoryFactory
如何初始化?
AbstractEntityManagerFactoryBean
afterPropertiesSet()
TomcatDataSourcePool
构造方法很关键,定义了后面用到的translators
初始化
HikariDataSourcePool
SessionImpl#list(...)
extends
basePackages
build()
implements
BlogDao
EntityManager
JpaRepository#findAll()
step1
cache
三八分割线
JPA初始化过程
DataSourceAutoConfiguration
createNativeEntityManagerFactory
EntityManagerFactoryBuilderImpl
RepositoryFactorySupport
listIgnoreQueryCache()➡doList➡doQueryAndInitializeNonLazyCollection➡doQuery
@PersistenceContext
@Bean
不同数据
LocalContainerEntityManagerFactoryBean
this.targetFactory.createEntityManager()
配置
QueryTranslatorImpl#list()
JpaRepositoriesRegistrar
emf
Query#getResultList()
entityManagerFactoryRef
本图是iworkh整理springboot手册时,分析spring-jpa源码所画。直接看图,可能一脸懵逼,可以配套对应的手册来看,可能就容易多了。手册去 https://www.iworkh.com/里查找。
createEntityManager()
JpaBaseConfiguration
QueryLoader#list()
AbstractProducedQuery#doList()
em.getDelegate()
DataSourcePoolMetadataProvidersConfiguration
doCreateRepositoryFactory
PreparedStatement执行sql,返回ResultSet
connection
db1/student
Loader#executeQueryStatement
$Proxy:LocalContainerEntityManagerFactoryBean
AbstractRepositoryConfigurationSourceSupport
对返回的restultSet处理塞值,最后转化为需要的返回类型
SimpleJpaRepository#getQuery(...)
PersistenceProvider
findAll的执行过程
implement
@EnableJpaRepositories
repositoryFactoryBeanClass
Poxy
@EnableConfigurationProperties
em
springboot手册-jpa多数据源
1. em.getCriteriaBuilder方法返回builder2. builder.createQuery创建CriteriaQuery对象3. em.createQuery方法创建TypedQuery对象
默认值:JpaRepositoryFactoryBean
EntityManagerFactory
SharedEntityManagerInvocationHandler#invoke
EnableJpaRepositoriesConfiguration
CriteriaQueryTypeQueryAdapter#getResultList()
step2
ThreadPoolTaskExecutor
方法
Xxxservice
provider#createContainerEntityManagerFactory()方法
spring.datasource
JpaRepositoriesAutoConfiguration
PersistenceProvider.fromEntityManager()
buildEntityManager()
Loader#processResultSet
DataSourceInitializationConfiguration
db2/blog
HQLQueryPlan#performList()
DataSourceProperties
buildNativeEntityManagerFactory()
HibernateJpaConfiguration
HibernateJpaAutoConfiguration
SessionFactoryImpl
TaskExecutionAutoConfiguration
EntityManagerFactoryBuilderCustomizer
@Import
SessionBuilderImpl#openSession
默认值:entityManagerFactory
spring.jpa
默认值:transactionManager
默认线程池
JPA/JDBC/...
SimpleJpaRepository#findAll()
EntityManagerFactoryBuilder
Factory
QueryLoader
Loader(调用一系列方法)
transactionManagerRef
JpaRepositoryFactoryBean
TaskExecutionProperties
createContainerEntityManagerFactory
SessionImpl
StudentDao
Object: getDelegate()CriteriaBuilder: getCriteriaBuilder()TypedQuery: createQuery()....
SpringHibernateJpaPersistenceProvider
createEntityManagerFactoryProxy()
SessionFactoryBuilder
配置属性
JpaTransactionManager
CommonsDbcp2DataSourcePool
JpaProperties
JpaVendorAdapter
0 条评论
下一页