Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
logwire-bo-persistence
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
薛涛 Toby Xue
logwire-bo-persistence
Commits
c84c7a72
Commit
c84c7a72
authored
Jan 06, 2021
by
姜逸青 Jameson Jiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#1971 建表clear,BO字段调整
parent
5cc73854
Pipeline
#4710
canceled with stages
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
18 deletions
+45
-18
BoModelBeanLoader.java
src/main/java/logwire/web/bo/loader/BoModelBeanLoader.java
+29
-10
BoRelationBeanDefinitionLoader.java
...logwire/web/bo/loader/BoRelationBeanDefinitionLoader.java
+16
-8
No files found.
src/main/java/logwire/web/bo/loader/BoModelBeanLoader.java
View file @
c84c7a72
...
...
@@ -24,6 +24,7 @@ import org.springframework.beans.factory.config.BeanDefinition;
import
org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider
;
import
org.springframework.core.io.DefaultResourceLoader
;
import
org.springframework.core.io.ResourceLoader
;
import
org.springframework.stereotype.Component
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.ParameterizedType
;
...
...
@@ -32,6 +33,7 @@ import java.util.*;
import
java.util.function.Consumer
;
import
java.util.stream.Collectors
;
@Component
public
class
BoModelBeanLoader
extends
BeanLoader
<
IQuery
,
TenantProject
>
implements
JavaModelBeanLoader
{
@Autowired
...
...
@@ -97,9 +99,20 @@ public class BoModelBeanLoader extends BeanLoader<IQuery, TenantProject> impleme
model
.
setIncludeAuditFields
(
true
);
model
.
setIncludeVersionField
(
true
);
model
.
setIncludeDomainField
(
true
);
initField
(
clazz
,
model
,
consumer
);
//todo 补充子类和拓展字段
//字段名去重
Set
<
String
>
fieldNames
=
new
HashSet
<>();
//是否没有大文本字段,当一个表有多个大文本字段,只需要建一次表,将多个大文本字段的值放在一张表中
Boolean
isFirstText
=
true
;
//根据字段建表
isFirstText
=
initField
(
clazz
,
model
,
fieldNames
,
isFirstText
,
consumer
);
//补充子类
for
(
Class
childClazz:
beanDefinition
.
getChildrenBo
())
{
isFirstText
=
initField
(
childClazz
,
model
,
fieldNames
,
isFirstText
,
consumer
);
}
//补充拓展字段
for
(
Class
expandoClazz:
beanDefinition
.
getExpando
())
{
isFirstText
=
initField
(
expandoClazz
,
model
,
fieldNames
,
isFirstText
,
consumer
);
}
consumer
.
accept
(
model
);
}
}
...
...
@@ -110,12 +123,17 @@ public class BoModelBeanLoader extends BeanLoader<IQuery, TenantProject> impleme
* @param model model
* @param consumer
*/
private
void
initField
(
Class
<?>
clazz
,
Model
model
,
Consumer
<
IQuery
>
consumer
)
{
Field
[]
fields
=
clazz
.
getDeclaredFields
();
//当一个表有多个大文本字段,只需要建一次表,将多个大文本字段的值放在一张表中
boolean
isFirstText
=
true
;
private
Boolean
initField
(
Class
<?>
clazz
,
Model
model
,
Set
<
String
>
fieldNames
,
Boolean
isFirstText
,
Consumer
<
IQuery
>
consumer
)
{
List
<
Field
>
fieldList
=
new
ArrayList
<>();
while
(
clazz
!=
null
){
fieldList
.
addAll
(
Arrays
.
asList
(
clazz
.
getDeclaredFields
()));
clazz
=
clazz
.
getSuperclass
();
}
//遍历所有字段
for
(
Field
f
:
fields
)
{
for
(
Field
f
:
fieldList
)
{
//如果已经加过此字段,则跳过
if
(!
fieldNames
.
add
(
f
.
getName
()))
continue
;
if
(
f
.
getAnnotation
(
Column
.
class
)
!=
null
)
{
//带有Column注解的字段
FieldParser
parser
=
FieldParserUtil
.
getParser
(
f
);
...
...
@@ -145,6 +163,7 @@ public class BoModelBeanLoader extends BeanLoader<IQuery, TenantProject> impleme
newManyModel
(
model
,
f
,
consumer
);
}
}
return
isFirstText
;
}
...
...
@@ -310,7 +329,7 @@ public class BoModelBeanLoader extends BeanLoader<IQuery, TenantProject> impleme
Class
<?>
childClazz
=
classLoader
.
loadClass
(
e
.
getBeanClassName
());
boModel_relation
.
entrySet
()
.
stream
()
.
filter
(
f
->
childClazz
.
isAssignableFrom
(
f
.
getKey
()))
.
filter
(
f
->
childClazz
.
isAssignableFrom
(
f
.
getKey
())
||
f
.
getKey
().
isAssignableFrom
(
childClazz
)
)
.
forEach
(
f
->
f
.
getValue
().
addChildBo
(
childClazz
));
}
catch
(
ClassNotFoundException
classNotFoundException
)
{
}
...
...
@@ -325,7 +344,7 @@ public class BoModelBeanLoader extends BeanLoader<IQuery, TenantProject> impleme
if
(
type
instanceof
ParameterizedType
){
ParameterizedType
paramterizedType
=
(
ParameterizedType
)
type
;
//找到BizExpando接口
if
(
paramterizedType
.
getRawType
()
.
equals
(
"logwire.core.bo.field.BizExpando"
)
){
if
(
paramterizedType
.
getRawType
()
==
BizExpando
.
class
){
//找到泛型
Class
clazz
=
(
Class
)
paramterizedType
.
getActualTypeArguments
()[
0
];
//通过泛型去找对应的boRelation
...
...
src/main/java/logwire/web/bo/loader/BoRelationBeanDefinitionLoader.java
View file @
c84c7a72
...
...
@@ -68,11 +68,11 @@ public class BoRelationBeanDefinitionLoader extends BeanLoader<BoRelationDefinit
*/
@Override
public
void
load
(
TenantProject
project
,
TenantProject
input
,
Consumer
<
BoRelationDefinition
>
consumer
)
throws
Exception
{
Map
<
String
,
BoRelationDefinition
>
boRelationBeanDefinitions
=
loadBeanDefinition
(
projec
t
);
/*Map<String, BoRelationDefinition> boRelationBeanDefinitions = loadBeanDefinition(project, inpu
t);
boRelationBeanDefinitions.values().forEach(boRelationDefinition -> {
initializeService(boRelationDefinition, boRelationBeanDefinitions);
consumer.accept(boRelationDefinition);
});
});
*/
}
/**
...
...
@@ -107,7 +107,9 @@ public class BoRelationBeanDefinitionLoader extends BeanLoader<BoRelationDefinit
* @return
* @throws Exception
*/
private
Map
<
String
,
BoRelationDefinition
>
loadBeanDefinition
(
TenantProject
project
)
throws
Exception
{
private
Map
<
String
,
BoRelationDefinition
>
loadBeanDefinition
(
TenantProject
project
,
TenantProject
input
)
throws
Exception
{
input
.
getBeansOfType
(
BizObject
.
class
);
//加载bo类
Map
<
String
,
BoRelationDefinition
>
boRelationBeanDefinitions
=
Maps
.
newHashMap
();
TenantClassLoader
classLoader
=
project
.
getTenantBeanContext
().
getTenantClassLoader
();
ClassPathScanningCandidateComponentProvider
provider
=
loaderUtil
.
getScanningBeanProvider
();
...
...
@@ -159,11 +161,14 @@ public class BoRelationBeanDefinitionLoader extends BeanLoader<BoRelationDefinit
}
private
void
registerBeanDefinition
(
Map
<
String
,
BoRelationDefinition
>
boRelationBeanDefinitions
,
Map
<
String
,
List
<
Class
<?>>>
beanClassMap
)
{
//如果没有使用bo,则不会报错
if
(
beanClassMap
.
get
(
BIZ_OBJECT
)!=
null
)
{
beanClassMap
.
get
(
BIZ_OBJECT
).
forEach
(
clazz
->
{
BoRelationDefinition
boRelationDefinition
=
doRegisterBeanDefinition
((
Class
<?
extends
BizObject
>)
clazz
);
boRelationBeanDefinitions
.
put
(
boRelationDefinition
.
getId
(),
boRelationDefinition
);
});
}
}
private
void
addOperationProvider
(
Map
<
String
,
BoRelationDefinition
>
boRelationBeanDefinitions
,
Map
<
String
,
List
<
Class
<?>>>
beanClassMap
)
{
beanClassMap
.
get
(
TYPE_OPERATION_PROVIDER
).
forEach
(
clazz
->
{
...
...
@@ -262,7 +267,10 @@ public class BoRelationBeanDefinitionLoader extends BeanLoader<BoRelationDefinit
return
boRelationDefinition
;
}
/**
* 扫描bo相关类
* @param provider
*/
private
void
addIncludeFilters
(
ClassPathScanningCandidateComponentProvider
provider
)
{
provider
.
addIncludeFilter
(
loaderUtil
.
getAbstractTypeFilter
(
BizObject
.
class
));
provider
.
addIncludeFilter
(
new
AssignableTypeFilter
(
OperationHandler
.
class
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment