Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
3227569a
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
3227569a
编写于
8月 07, 2014
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
LocalSessionFactoryBean/Builder allows for specifying custom entity type filters
Issue: SPR-12049
上级
0b2c0cfb
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
51 addition
and
9 deletion
+51
-9
spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/LocalSessionFactoryBean.java
...ringframework/orm/hibernate4/LocalSessionFactoryBean.java
+22
-0
spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/LocalSessionFactoryBuilder.java
...gframework/orm/hibernate4/LocalSessionFactoryBuilder.java
+29
-9
未找到文件。
spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/LocalSessionFactoryBean.java
浏览文件 @
3227569a
...
...
@@ -37,6 +37,7 @@ import org.springframework.core.io.ResourceLoader;
import
org.springframework.core.io.support.PathMatchingResourcePatternResolver
;
import
org.springframework.core.io.support.ResourcePatternResolver
;
import
org.springframework.core.io.support.ResourcePatternUtils
;
import
org.springframework.core.type.filter.TypeFilter
;
/**
* {@link org.springframework.beans.factory.FactoryBean} that creates a Hibernate
...
...
@@ -95,6 +96,8 @@ public class LocalSessionFactoryBean extends HibernateExceptionTranslator
private
RegionFactory
cacheRegionFactory
;
private
TypeFilter
[]
entityTypeFilters
;
private
Properties
hibernateProperties
;
private
Class
<?>[]
annotatedClasses
;
...
...
@@ -238,6 +241,7 @@ public class LocalSessionFactoryBean extends HibernateExceptionTranslator
* on to the SessionFactory: as an instance, a Class, or a String class name.
* <p>Note that the package location of the {@code MultiTenantConnectionProvider}
* interface changed between Hibernate 4.2 and 4.3. This method accepts both variants.
* @since 4.0
* @see LocalSessionFactoryBuilder#setMultiTenantConnectionProvider
*/
public
void
setMultiTenantConnectionProvider
(
Object
multiTenantConnectionProvider
)
{
...
...
@@ -247,6 +251,7 @@ public class LocalSessionFactoryBean extends HibernateExceptionTranslator
/**
* Set a Hibernate 4.1/4.2/4.3 {@code CurrentTenantIdentifierResolver} to be passed
* on to the SessionFactory: as an instance, a Class, or a String class name.
* @since 4.0
* @see LocalSessionFactoryBuilder#setCurrentTenantIdentifierResolver
*/
public
void
setCurrentTenantIdentifierResolver
(
Object
currentTenantIdentifierResolver
)
{
...
...
@@ -258,6 +263,7 @@ public class LocalSessionFactoryBean extends HibernateExceptionTranslator
* Allows for using a Spring-managed RegionFactory instance.
* <p>Note: If this is set, the Hibernate settings should not define a
* cache provider to avoid meaningless double configuration.
* @since 4.0
* @see org.hibernate.cache.spi.RegionFactory
* @see LocalSessionFactoryBuilder#setCacheRegionFactory
*/
...
...
@@ -265,6 +271,18 @@ public class LocalSessionFactoryBean extends HibernateExceptionTranslator
this
.
cacheRegionFactory
=
cacheRegionFactory
;
}
/**
* Specify custom type filters for Spring-based scanning for entity classes.
* <p>Default is to search all specified packages for classes annotated with
* {@code @javax.persistence.Entity}, {@code @javax.persistence.Embeddable}
* or {@code @javax.persistence.MappedSuperclass}.
* @since 4.1
* @see #setPackagesToScan
*/
public
void
setEntityTypeFilters
(
TypeFilter
...
entityTypeFilters
)
{
this
.
entityTypeFilters
=
entityTypeFilters
;
}
/**
* Set Hibernate properties, such as "hibernate.dialect".
* <p>Note: Do not specify a transaction provider here when using
...
...
@@ -395,6 +413,10 @@ public class LocalSessionFactoryBean extends HibernateExceptionTranslator
sfb
.
setCacheRegionFactory
(
this
.
cacheRegionFactory
);
}
if
(
this
.
entityTypeFilters
!=
null
)
{
sfb
.
setEntityTypeFilters
(
this
.
entityTypeFilters
);
}
if
(
this
.
hibernateProperties
!=
null
)
{
sfb
.
addProperties
(
this
.
hibernateProperties
);
}
...
...
spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/LocalSessionFactoryBuilder.java
浏览文件 @
3227569a
...
...
@@ -84,18 +84,18 @@ public class LocalSessionFactoryBuilder extends Configuration {
private
static
final
String
PACKAGE_INFO_SUFFIX
=
".package-info"
;
private
static
final
Set
<
TypeFilter
>
entity
TypeFilters
;
private
static
final
Set
<
TypeFilter
>
default
TypeFilters
;
static
{
entity
TypeFilters
=
new
LinkedHashSet
<
TypeFilter
>(
4
);
entity
TypeFilters
.
add
(
new
AnnotationTypeFilter
(
Entity
.
class
,
false
));
entity
TypeFilters
.
add
(
new
AnnotationTypeFilter
(
Embeddable
.
class
,
false
));
entity
TypeFilters
.
add
(
new
AnnotationTypeFilter
(
MappedSuperclass
.
class
,
false
));
default
TypeFilters
=
new
LinkedHashSet
<
TypeFilter
>(
4
);
default
TypeFilters
.
add
(
new
AnnotationTypeFilter
(
Entity
.
class
,
false
));
default
TypeFilters
.
add
(
new
AnnotationTypeFilter
(
Embeddable
.
class
,
false
));
default
TypeFilters
.
add
(
new
AnnotationTypeFilter
(
MappedSuperclass
.
class
,
false
));
try
{
@SuppressWarnings
(
"unchecked"
)
Class
<?
extends
Annotation
>
converterAnnotation
=
(
Class
<?
extends
Annotation
>)
ClassUtils
.
forName
(
"javax.persistence.Converter"
,
LocalSessionFactoryBuilder
.
class
.
getClassLoader
());
entity
TypeFilters
.
add
(
new
AnnotationTypeFilter
(
converterAnnotation
,
false
));
default
TypeFilters
.
add
(
new
AnnotationTypeFilter
(
converterAnnotation
,
false
));
}
catch
(
ClassNotFoundException
ex
)
{
// JPA 2.1 API not available - Hibernate <4.3
...
...
@@ -103,6 +103,8 @@ public class LocalSessionFactoryBuilder extends Configuration {
}
private
TypeFilter
[]
entityTypeFilters
=
defaultTypeFilters
.
toArray
(
new
TypeFilter
[
defaultTypeFilters
.
size
()]);
private
final
ResourcePatternResolver
resourcePatternResolver
;
private
RegionFactory
cacheRegionFactory
;
...
...
@@ -194,6 +196,7 @@ public class LocalSessionFactoryBuilder extends Configuration {
* on to the SessionFactory: as an instance, a Class, or a String class name.
* <p>Note that the package location of the {@code MultiTenantConnectionProvider}
* interface changed between Hibernate 4.2 and 4.3. This method accepts both variants.
* @since 4.0
* @see AvailableSettings#MULTI_TENANT_CONNECTION_PROVIDER
*/
public
LocalSessionFactoryBuilder
setMultiTenantConnectionProvider
(
Object
multiTenantConnectionProvider
)
{
...
...
@@ -204,6 +207,7 @@ public class LocalSessionFactoryBuilder extends Configuration {
/**
* Set a Hibernate 4.1/4.2/4.3 {@code CurrentTenantIdentifierResolver} to be passed
* on to the SessionFactory: as an instance, a Class, or a String class name.
* @since 4.0
* @see AvailableSettings#MULTI_TENANT_IDENTIFIER_RESOLVER
*/
public
LocalSessionFactoryBuilder
setCurrentTenantIdentifierResolver
(
Object
currentTenantIdentifierResolver
)
{
...
...
@@ -216,6 +220,7 @@ public class LocalSessionFactoryBuilder extends Configuration {
* Allows for using a Spring-managed RegionFactory instance.
* <p>Note: If this is set, the Hibernate settings should not define a
* cache provider to avoid meaningless double configuration.
* @since 4.0
* @see org.hibernate.cache.spi.RegionFactory
*/
public
LocalSessionFactoryBuilder
setCacheRegionFactory
(
RegionFactory
cacheRegionFactory
)
{
...
...
@@ -223,6 +228,19 @@ public class LocalSessionFactoryBuilder extends Configuration {
return
this
;
}
/**
* Specify custom type filters for Spring-based scanning for entity classes.
* <p>Default is to search all specified packages for classes annotated with
* {@code @javax.persistence.Entity}, {@code @javax.persistence.Embeddable}
* or {@code @javax.persistence.MappedSuperclass}.
* @since 4.1
* @see #scanPackages
*/
public
LocalSessionFactoryBuilder
setEntityTypeFilters
(
TypeFilter
...
entityTypeFilters
)
{
this
.
entityTypeFilters
=
entityTypeFilters
;
return
this
;
}
/**
* Add the given annotated classes in a batch.
* @see #addAnnotatedClass
...
...
@@ -298,9 +316,11 @@ public class LocalSessionFactoryBuilder extends Configuration {
* the current class descriptor contained in the metadata reader.
*/
private
boolean
matchesEntityTypeFilter
(
MetadataReader
reader
,
MetadataReaderFactory
readerFactory
)
throws
IOException
{
for
(
TypeFilter
filter
:
entityTypeFilters
)
{
if
(
filter
.
match
(
reader
,
readerFactory
))
{
return
true
;
if
(
this
.
entityTypeFilters
!=
null
)
{
for
(
TypeFilter
filter
:
this
.
entityTypeFilters
)
{
if
(
filter
.
match
(
reader
,
readerFactory
))
{
return
true
;
}
}
}
return
false
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录