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
e46f9d26
Commit
e46f9d26
authored
Nov 30, 2020
by
薛涛 Toby Xue
🆒
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commit
parents
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
776 additions
and
0 deletions
+776
-0
pom.xml
pom.xml
+62
-0
BoRelationDefinition.java
src/main/java/logwire/web/bo/BoRelationDefinition.java
+129
-0
TypeOperationHandlerBean.java
...in/java/logwire/web/bo/bean/TypeOperationHandlerBean.java
+31
-0
BoBeanContainer.java
src/main/java/logwire/web/bo/container/BoBeanContainer.java
+9
-0
BoRelationBeanContainerBuilder.java
...wire/web/bo/container/BoRelationBeanContainerBuilder.java
+29
-0
OperationHandlerContainer.java
...a/logwire/web/bo/container/OperationHandlerContainer.java
+23
-0
BoModelBeanLoader.java
src/main/java/logwire/web/bo/loader/BoModelBeanLoader.java
+94
-0
BoRelationBeanDefinitionLoader.java
...logwire/web/bo/loader/BoRelationBeanDefinitionLoader.java
+170
-0
LoaderUtil.java
src/main/java/logwire/web/bo/loader/LoaderUtil.java
+61
-0
DefaultTypeOperationProvider.java
...logwire/web/bo/provider/DefaultTypeOperationProvider.java
+71
-0
Proxy.java
src/main/java/logwire/web/bo/proxy/Proxy.java
+39
-0
TypeOperationInterceptor.java
...n/java/logwire/web/bo/proxy/TypeOperationInterceptor.java
+58
-0
No files found.
pom.xml
0 → 100644
View file @
e46f9d26
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
logwire
</groupId>
<artifactId>
logwire-bo-persistence
</artifactId>
<version>
1.0.0
</version>
<parent>
<groupId>
logwire
</groupId>
<artifactId>
logwire-parent
</artifactId>
<version>
1.4.0
</version>
</parent>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<java.version>
1.8
</java.version>
<maven.compiler.target>
1.8
</maven.compiler.target>
<maven.compiler.source>
1.8
</maven.compiler.source>
</properties>
<dependencies>
<dependency>
<groupId>
logwire
</groupId>
<artifactId>
logwire-bo-sdk
</artifactId>
<version>
1.0.0
</version>
</dependency>
<dependency>
<groupId>
logwire
</groupId>
<artifactId>
logwire-web
</artifactId>
<version>
1.4.1
</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>
nexus.grea.releases
</id>
<name>
Releases Repository
</name>
<url>
http://nexus.logwire.cn/nexus/content/repositories/releases/
</url>
<layout>
default
</layout>
<releases>
<enabled>
true
</enabled>
<updatePolicy>
always
</updatePolicy>
<checksumPolicy>
fail
</checksumPolicy>
</releases>
</repository>
<repository>
<id>
nexus.grea.snapshots
</id>
<url>
http://nexus.logwire.cn/nexus/content/repositories/snapshots/
</url>
<layout>
default
</layout>
<snapshots>
<enabled>
true
</enabled>
<checksumPolicy>
fail
</checksumPolicy>
<updatePolicy>
always
</updatePolicy>
</snapshots>
</repository>
</repositories>
</project>
\ No newline at end of file
src/main/java/logwire/web/bo/BoRelationDefinition.java
0 → 100644
View file @
e46f9d26
package
logwire
.
web
.
bo
;
import
logwire.core.bo.handler.OperationHandler
;
import
logwire.core.bo.object.BizObject
;
import
logwire.core.meta.Config
;
import
logwire.core.resource.bean.BeanAdapter
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
BoRelationDefinition
extends
BeanAdapter
{
public
BoRelationDefinition
(){
}
private
boolean
boServiceInitialized
;
@Config
boolean
isBizModel
=
false
;
@Config
private
Class
<?
extends
BizObject
>
boClass
;
@Config
private
List
<
Class
>
typeOperationProviders
=
new
ArrayList
<>();
@Config
private
List
<
Class
>
objectOperationProviders
=
new
ArrayList
<>();
@Config
private
List
<
Class
>
listOperationProviders
=
new
ArrayList
<>();
@Config
private
List
<
OperationHandler
>
typeOperationHandlers
=
new
ArrayList
<>();
@Config
private
List
<
Class
>
objectOperationHandlers
=
new
ArrayList
<>();
@Config
private
List
<
Class
>
listOperationHandlers
=
new
ArrayList
<>();
public
List
<
Class
>
getTypeOperationProviders
()
{
return
typeOperationProviders
;
}
public
void
setTypeOperationProviders
(
List
<
Class
>
typeOperationProviders
)
{
this
.
typeOperationProviders
=
typeOperationProviders
;
}
public
void
addTypeOperationProvider
(
Class
typeOperationProvider
)
{
this
.
typeOperationProviders
.
add
(
typeOperationProvider
);
}
public
List
<
Class
>
getObjectOperationProviders
()
{
return
objectOperationProviders
;
}
public
void
setObjectOperationProviders
(
List
<
Class
>
objectOperationProviders
)
{
this
.
objectOperationProviders
=
objectOperationProviders
;
}
public
void
addObjectOperationProvider
(
Class
objectOperationProvider
)
{
this
.
objectOperationProviders
.
add
(
objectOperationProvider
);
}
public
List
<
Class
>
getListOperationProviders
()
{
return
listOperationProviders
;
}
public
void
setListOperationProviders
(
List
<
Class
>
listOperationProviders
)
{
this
.
listOperationProviders
=
listOperationProviders
;
}
public
void
addListOperationProvider
(
Class
listOperationProvider
)
{
this
.
listOperationProviders
.
add
(
listOperationProvider
);
}
public
List
<
OperationHandler
>
getTypeOperationHandlers
()
{
return
typeOperationHandlers
;
}
public
void
setTypeOperationHandlers
(
List
<
OperationHandler
>
typeOperationHandlers
)
{
this
.
typeOperationHandlers
=
typeOperationHandlers
;
}
public
List
<
Class
>
getObjectOperationHandlers
()
{
return
objectOperationHandlers
;
}
public
void
setObjectOperationHandlers
(
List
<
Class
>
objectOperationHandlers
)
{
this
.
objectOperationHandlers
=
objectOperationHandlers
;
}
public
List
<
Class
>
getListOperationHandlers
()
{
return
listOperationHandlers
;
}
public
void
setListOperationHandlers
(
List
<
Class
>
listOperationHandlers
)
{
this
.
listOperationHandlers
=
listOperationHandlers
;
}
public
boolean
isBizModel
()
{
return
isBizModel
;
}
public
void
setBizModel
(
boolean
bizModel
)
{
isBizModel
=
bizModel
;
}
public
Class
<?
extends
BizObject
>
getBoClass
()
{
return
boClass
;
}
public
void
setBoClass
(
Class
<?
extends
BizObject
>
boClass
)
{
this
.
boClass
=
boClass
;
}
public
boolean
isBoServiceInitialized
()
{
return
boServiceInitialized
;
}
public
void
setBoServiceInitialized
(
boolean
boServiceInitialized
)
{
this
.
boServiceInitialized
=
boServiceInitialized
;
}
}
src/main/java/logwire/web/bo/bean/TypeOperationHandlerBean.java
0 → 100644
View file @
e46f9d26
package
logwire
.
web
.
bo
.
bean
;
import
logwire.core.bo.handler.OperationHandler
;
import
logwire.core.bo.object.BizObject
;
public
class
TypeOperationHandlerBean
{
public
TypeOperationHandlerBean
(
Class
<?
extends
BizObject
>
bizObject
,
Class
<?
extends
OperationHandler
>
handler
)
{
this
.
bizObject
=
bizObject
;
this
.
handler
=
handler
;
}
private
Class
<?
extends
BizObject
>
bizObject
;
private
Class
<?
extends
OperationHandler
>
handler
;
public
Class
getBizObject
()
{
return
bizObject
;
}
public
void
setBizObject
(
Class
<?
extends
BizObject
>
bizObject
)
{
this
.
bizObject
=
bizObject
;
}
public
Class
getHandler
()
{
return
handler
;
}
public
void
setHandler
(
Class
<?
extends
OperationHandler
>
handler
)
{
this
.
handler
=
handler
;
}
}
src/main/java/logwire/web/bo/container/BoBeanContainer.java
0 → 100644
View file @
e46f9d26
package
logwire
.
web
.
bo
.
container
;
public
abstract
class
BoBeanContainer
<
T
>
{
public
abstract
T
getBean
(
String
id
);
}
src/main/java/logwire/web/bo/container/BoRelationBeanContainerBuilder.java
0 → 100644
View file @
e46f9d26
package
logwire
.
web
.
bo
.
container
;
import
logwire.core.resource.*
;
import
logwire.web.bo.loader.BoRelationBeanDefinitionLoader
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.stereotype.Component
;
@Component
public
class
BoRelationBeanContainerBuilder
implements
JavaBeanContainerBuilder
{
@Override
public
JavaBeanContainer
build
(
ApplicationContext
applicationContext
)
{
return
newContainer
(
applicationContext
,
BoRelationBeanDefinitionLoader
.
class
);
}
@Override
public
String
getContainerName
()
{
return
"BO_RELATION"
;
}
private
JavaBeanContainer
newContainer
(
ApplicationContext
ctx
,
Class
...
classes
)
{
BeanLoader
[]
loaders
=
new
BeanLoader
[
classes
.
length
];
for
(
int
i
=
0
;
i
<
loaders
.
length
;
i
++)
{
loaders
[
i
]
=
(
BeanLoader
)
Util
.
getExactBean
(
ctx
,
classes
[
i
]);
}
JavaBeanContainer
container
=
new
JavaBeanContainer
(
loaders
);
return
container
;
}
}
src/main/java/logwire/web/bo/container/OperationHandlerContainer.java
0 → 100644
View file @
e46f9d26
package
logwire
.
web
.
bo
.
container
;
import
logwire.web.bo.bean.TypeOperationHandlerBean
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
OperationHandlerContainer
{
private
List
<
TypeOperationHandlerBean
>
typeOperationHandlerBeanList
=
new
ArrayList
<>();
public
List
<
TypeOperationHandlerBean
>
getTypeOperationHandlerBeanList
()
{
return
typeOperationHandlerBeanList
;
}
public
void
setTypeOperationHandlerBeanList
(
List
<
TypeOperationHandlerBean
>
typeOperationHandlerBeanList
)
{
this
.
typeOperationHandlerBeanList
=
typeOperationHandlerBeanList
;
}
public
void
addTypeOperationHandlerBean
(
TypeOperationHandlerBean
typeOperationHandlerBean
)
{
this
.
typeOperationHandlerBeanList
.
add
(
typeOperationHandlerBean
);
}
}
src/main/java/logwire/web/bo/loader/BoModelBeanLoader.java
0 → 100644
View file @
e46f9d26
package
logwire
.
web
.
bo
.
loader
;
import
logwire.core.bo.annotation.BizModel
;
import
logwire.core.bo.annotation.Column
;
import
logwire.core.bo.object.BizObject
;
import
logwire.core.exceptions.ApplicationException
;
import
logwire.core.meta.model.Model
;
import
logwire.core.meta.query.IQuery
;
import
logwire.core.resource.BeanLoader
;
import
logwire.core.resource.loader.JavaModelBeanLoader
;
import
logwire.core.tenant.TenantClassLoader
;
import
logwire.core.tenant.TenantProject
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.config.BeanDefinition
;
import
org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider
;
import
org.springframework.core.io.DefaultResourceLoader
;
import
java.lang.reflect.Field
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.function.Consumer
;
import
java.util.stream.Collectors
;
public
class
BoModelBeanLoader
extends
BeanLoader
<
IQuery
,
TenantProject
>
implements
JavaModelBeanLoader
{
@Autowired
LoaderUtil
loaderUtil
;
@Override
public
void
load
(
TenantProject
project
,
TenantProject
input
,
Consumer
<
IQuery
>
consumer
)
throws
Exception
{
TenantClassLoader
classLoader
=
project
.
getTenantBeanContext
().
getTenantClassLoader
();
ClassPathScanningCandidateComponentProvider
provider
=
loaderUtil
.
getScanningBeanProvider
();
provider
.
setResourceLoader
(
new
DefaultResourceLoader
(
classLoader
));
provider
.
addIncludeFilter
(
loaderUtil
.
getAbstractTypeFilter
(
BizObject
.
class
));
Set
<
BeanDefinition
>
beans
=
provider
.
findCandidateComponents
(
"logwire.web.bo"
);
List
<
BeanDefinition
>
bizModelList
=
beans
.
stream
().
filter
(
beanDefinition
->
{
try
{
Class
<?>
clazz
=
classLoader
.
loadClass
(
beanDefinition
.
getBeanClassName
());
BizModel
bizModelAnnotation
=
clazz
.
getAnnotation
(
BizModel
.
class
);
return
bizModelAnnotation
!=
null
;
}
catch
(
ClassNotFoundException
e
)
{
throw
new
ApplicationException
(
""
);
}
}).
collect
(
Collectors
.
toList
());
for
(
BeanDefinition
beanDefinition
:
beans
)
{
Class
<?>
clazz
=
classLoader
.
loadClass
(
beanDefinition
.
getBeanClassName
());
//判断是否独立model
BizModel
bizModelAnnotation
=
clazz
.
getAnnotation
(
BizModel
.
class
);
if
(
bizModelAnnotation
!=
null
)
{
//独立model
Model
model
=
new
Model
();
model
.
setName
(
clazz
.
getSimpleName
());
model
.
setName
(
clazz
.
getSimpleName
());
model
.
setVerboseName
(
bizModelAnnotation
.
label
());
model
.
setIncludeAuditFields
(
true
);
model
.
setIncludeVersionField
(
true
);
model
.
setIncludeDomainField
(
true
);
initField
(
clazz
,
model
);
}
else
{
//判断父类是否包含 @BizModel ,若包含则
}
/* this.initModel(clazz, model);
this.initFields(clazz, model);
this.initIndex(clazz, model);
this.initSign(model);
consumer.accept(model);*/
}
}
private
void
initField
(
Class
<?>
clazz
,
Model
model
)
{
Field
[]
fields
=
clazz
.
getDeclaredFields
();
for
(
Field
f
:
fields
)
{
Column
column
=
f
.
getAnnotation
(
Column
.
class
);
if
(
column
!=
null
)
{
/* model.*/
}
}
}
@Override
public
boolean
accept
(
TenantProject
input
)
{
return
true
;
}
}
src/main/java/logwire/web/bo/loader/BoRelationBeanDefinitionLoader.java
0 → 100644
View file @
e46f9d26
package
logwire
.
web
.
bo
.
loader
;
import
com.google.common.collect.Maps
;
import
logwire.core.bo.annotation.BizModel
;
import
logwire.core.bo.annotation.ListOperationProvider
;
import
logwire.core.bo.annotation.ObjectOperationProvider
;
import
logwire.core.bo.annotation.TypeOperationProvider
;
import
logwire.core.bo.eventhandler.OperationEventHandler
;
import
logwire.core.bo.handler.OperationHandler
;
import
logwire.core.bo.handler.TypeOperationHandler
;
import
logwire.core.bo.object.BizObject
;
import
logwire.core.resource.BeanLoader
;
import
logwire.core.tenant.TenantClassLoader
;
import
logwire.core.tenant.TenantProject
;
import
logwire.web.bo.BoRelationDefinition
;
import
logwire.web.bo.proxy.Proxy
;
import
logwire.web.service.query.QueryService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.config.BeanDefinition
;
import
org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider
;
import
org.springframework.context.annotation.ScannedGenericBeanDefinition
;
import
org.springframework.core.io.DefaultResourceLoader
;
import
org.springframework.core.type.filter.AnnotationTypeFilter
;
import
org.springframework.core.type.filter.AssignableTypeFilter
;
import
org.springframework.stereotype.Component
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.ParameterizedType
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.function.Consumer
;
@Component
public
class
BoRelationBeanDefinitionLoader
extends
BeanLoader
<
BoRelationDefinition
,
TenantProject
>
{
@Autowired
QueryService
queryService
;
@Autowired
LoaderUtil
loaderUtil
;
@Override
public
void
load
(
TenantProject
project
,
TenantProject
input
,
Consumer
<
BoRelationDefinition
>
consumer
)
throws
Exception
{
Map
<
String
,
BoRelationDefinition
>
boRelationBeanDefinitions
=
loadBeanDefinition
(
project
);
boRelationBeanDefinitions
.
values
().
forEach
(
boRelationDefinition
->
{
initializeService
(
boRelationDefinition
,
boRelationBeanDefinitions
);
});
}
/**
* 初始化
* 需先初始化 直接继承BizObject的BO的service
*
* @param boRelationDefinition
* @param boRelationBeanDefinitions
*/
public
void
initializeService
(
BoRelationDefinition
boRelationDefinition
,
Map
<
String
,
BoRelationDefinition
>
boRelationBeanDefinitions
)
{
if
(!
boRelationDefinition
.
isBoServiceInitialized
())
{
Class
superClass
=
boRelationDefinition
.
getBoClass
().
getSuperclass
();
if
(
superClass
!=
BizObject
.
class
)
{
//若非直接继承 先初始化父类
initializeService
(
boRelationBeanDefinitions
.
get
(
superClass
.
getSimpleName
()),
boRelationBeanDefinitions
);
}
try
{
//create proxy typeOperationProvider
Object
o
=
Proxy
.
createTypeOperationProvider
(
boRelationDefinition
);
Field
field
=
boRelationDefinition
.
getBoClass
().
getField
(
"service"
);
field
.
setAccessible
(
true
);
field
.
set
(
null
,
o
);
boRelationDefinition
.
setBoServiceInitialized
(
true
);
}
catch
(
NoSuchFieldException
|
IllegalAccessException
|
InstantiationException
e
)
{
e
.
printStackTrace
();
}
}
}
private
Map
<
String
,
BoRelationDefinition
>
loadBeanDefinition
(
TenantProject
project
)
throws
ClassNotFoundException
{
Map
<
String
,
BoRelationDefinition
>
boRelationBeanDefinitions
=
Maps
.
newHashMap
();
TenantClassLoader
classLoader
=
project
.
getTenantBeanContext
().
getTenantClassLoader
();
ClassPathScanningCandidateComponentProvider
provider
=
loaderUtil
.
getScanningBeanProvider
();
provider
.
setResourceLoader
(
new
DefaultResourceLoader
(
classLoader
));
addIncludeFilters
(
provider
);
Set
<
BeanDefinition
>
boClassDefinitions
=
provider
.
findCandidateComponents
(
"logwire.web.bo"
);
//beans 是有序的
for
(
BeanDefinition
boClassDefinition
:
boClassDefinitions
)
{
Class
<?>
clazz
=
Class
.
forName
(
boClassDefinition
.
getBeanClassName
(),
true
,
classLoader
);
if
(
loaderUtil
.
isBizObject
(
clazz
))
{
BoRelationDefinition
boRelationDefinition
=
doRegisterBeanDefinition
((
Class
<?
extends
BizObject
>)
clazz
);
boRelationBeanDefinitions
.
put
(
boRelationDefinition
.
getId
(),
boRelationDefinition
);
}
else
{
//handler
if
(
loaderUtil
.
isOperationHandler
(
clazz
))
{
if
(!
isConcrete
((
ScannedGenericBeanDefinition
)
boClassDefinition
))
continue
;
addOperationHandlerBeanDefinition
(
boRelationBeanDefinitions
,
(
Class
<
OperationHandler
>)
clazz
);
}
//event_handler
else
if
(
OperationEventHandler
.
class
.
isAssignableFrom
(
clazz
))
{
if
(!
isConcrete
((
ScannedGenericBeanDefinition
)
boClassDefinition
))
continue
;
//TODO
addOperationEventHandler
(
boRelationBeanDefinitions
,
clazz
);
}
//operation
else
if
(
clazz
.
getAnnotation
(
TypeOperationProvider
.
class
)
!=
null
)
{
Class
<?
extends
BizObject
>
type
=
clazz
.
getAnnotation
(
TypeOperationProvider
.
class
).
type
();
boRelationBeanDefinitions
.
get
(
type
.
getSimpleName
()).
addTypeOperationProvider
(
clazz
);
}
else
if
(
clazz
.
getAnnotation
(
ObjectOperationProvider
.
class
)
!=
null
)
{
Class
<?
extends
BizObject
>
type
=
clazz
.
getAnnotation
(
ObjectOperationProvider
.
class
).
type
();
boRelationBeanDefinitions
.
get
(
type
.
getSimpleName
()).
addObjectOperationProvider
(
clazz
);
}
else
if
(
clazz
.
getAnnotation
(
ListOperationProvider
.
class
)
!=
null
)
{
Class
<?
extends
BizObject
>
type
=
clazz
.
getAnnotation
(
ListOperationProvider
.
class
).
type
();
boRelationBeanDefinitions
.
get
(
type
.
getSimpleName
()).
addListOperationProvider
(
clazz
);
}
}
}
return
boRelationBeanDefinitions
;
}
private
BoRelationDefinition
doRegisterBeanDefinition
(
Class
<?
extends
BizObject
>
beanClass
)
{
BoRelationDefinition
boRelationDefinition
=
new
BoRelationDefinition
();
boRelationDefinition
.
setId
(
beanClass
.
getSimpleName
());
boRelationDefinition
.
setName
(
beanClass
.
getSimpleName
());
boRelationDefinition
.
setBoClass
(
beanClass
);
boRelationDefinition
.
setBizModel
(
beanClass
.
isAnnotationPresent
(
BizModel
.
class
));
return
boRelationDefinition
;
}
private
void
addIncludeFilters
(
ClassPathScanningCandidateComponentProvider
provider
)
{
provider
.
addIncludeFilter
(
loaderUtil
.
getAbstractTypeFilter
(
BizObject
.
class
));
provider
.
addIncludeFilter
(
new
AssignableTypeFilter
(
OperationHandler
.
class
));
provider
.
addIncludeFilter
(
new
AssignableTypeFilter
(
OperationEventHandler
.
class
));
provider
.
addIncludeFilter
(
new
AnnotationTypeFilter
(
TypeOperationProvider
.
class
));
provider
.
addIncludeFilter
(
new
AnnotationTypeFilter
(
ObjectOperationProvider
.
class
));
provider
.
addIncludeFilter
(
new
AnnotationTypeFilter
(
ListOperationProvider
.
class
));
}
private
void
addOperationEventHandler
(
Map
<
String
,
BoRelationDefinition
>
bizObjectBeanMap
,
Class
<?>
beanClass
)
{
//TODO
}
private
void
addOperationHandlerBeanDefinition
(
Map
<
String
,
BoRelationDefinition
>
bizObjectBeanMap
,
Class
<
OperationHandler
>
clazz
)
{
if
(
TypeOperationHandler
.
class
.
isAssignableFrom
(
clazz
))
{
Class
<?
extends
BizObject
>
bizObject
=
(
Class
<?
extends
BizObject
>)
((
ParameterizedType
)
clazz
.
getGenericInterfaces
()[
0
]).
getActualTypeArguments
()[
0
];
BoRelationDefinition
boRelationDefinition
=
bizObjectBeanMap
.
get
(
bizObject
.
getSimpleName
());
try
{
boRelationDefinition
.
getTypeOperationHandlers
().
add
(
clazz
.
newInstance
());
}
catch
(
InstantiationException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
}
}
private
boolean
isConcrete
(
ScannedGenericBeanDefinition
beanDefinition
)
{
return
beanDefinition
.
getMetadata
().
isConcrete
();
}
@Override
public
boolean
accept
(
TenantProject
input
)
{
return
true
;
}
}
src/main/java/logwire/web/bo/loader/LoaderUtil.java
0 → 100644
View file @
e46f9d26
package
logwire
.
web
.
bo
.
loader
;
import
logwire.core.bo.handler.OperationHandler
;
import
logwire.core.bo.object.BizObject
;
import
org.springframework.beans.factory.annotation.AnnotatedBeanDefinition
;
import
org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider
;
import
org.springframework.core.type.AnnotationMetadata
;
import
org.springframework.core.type.classreading.MetadataReader
;
import
org.springframework.core.type.classreading.MetadataReaderFactory
;
import
org.springframework.core.type.filter.AssignableTypeFilter
;
import
org.springframework.core.type.filter.TypeFilter
;
import
org.springframework.stereotype.Component
;
import
java.io.IOException
;
@Component
public
class
LoaderUtil
{
public
LogwireClassPathScanningCandidateComponentProvider
getScanningBeanProvider
()
{
return
new
LogwireClassPathScanningCandidateComponentProvider
(
false
);
}
public
TypeFilter
getAbstractTypeFilter
(
Class
targetType
)
{
return
new
AbstractTypeFilter
(
targetType
);
}
public
boolean
isBizObject
(
Class
<?>
beanClass
)
{
return
BizObject
.
class
.
isAssignableFrom
(
beanClass
);
}
public
boolean
isOperationHandler
(
Class
<?>
beanClass
)
{
return
OperationHandler
.
class
.
isAssignableFrom
(
beanClass
);
}
private
class
AbstractTypeFilter
extends
AssignableTypeFilter
{
public
AbstractTypeFilter
(
Class
<?>
targetType
)
{
super
(
targetType
);
}
public
boolean
match
(
MetadataReader
metadataReader
,
MetadataReaderFactory
metadataReaderFactory
)
throws
IOException
{
return
metadataReader
.
getClassMetadata
().
isAbstract
()
// 重写父类,增加判断,排除掉指定的接口 (targetType) 本身
&&
!
metadataReader
.
getClassMetadata
().
getClassName
().
equals
(
getTargetType
().
getName
())
&&
super
.
match
(
metadataReader
,
metadataReaderFactory
);
}
}
private
class
LogwireClassPathScanningCandidateComponentProvider
extends
ClassPathScanningCandidateComponentProvider
{
public
LogwireClassPathScanningCandidateComponentProvider
(
boolean
useDefaultFilters
)
{
super
(
useDefaultFilters
);
}
@Override
protected
boolean
isCandidateComponent
(
AnnotatedBeanDefinition
beanDefinition
)
{
AnnotationMetadata
metadata
=
beanDefinition
.
getMetadata
();
return
metadata
.
isIndependent
();
}
}
}
src/main/java/logwire/web/bo/provider/DefaultTypeOperationProvider.java
0 → 100644
View file @
e46f9d26
package
logwire
.
web
.
bo
.
provider
;
import
logwire.core.bo.annotation.Operation
;
import
logwire.core.bo.annotation.TypeOperationProvider
;
import
logwire.core.bo.list.BizList
;
import
logwire.core.bo.object.BizObject
;
import
logwire.core.bo.select.BizSelect
;
import
java.util.List
;
import
java.util.Map
;
@TypeOperationProvider
(
type
=
BizObject
.
class
)
public
interface
DefaultTypeOperationProvider
{
@Operation
(
label
=
"创建BO对象"
)
<
X
>
X
create
();
@Operation
()
<
X
>
X
create
(
Map
defaultValues
);
@Operation
()
<
X
>
X
create
(
String
query
);
@Operation
()
<
X
>
X
find
(
Long
id
);
@Operation
()
<
X
>
X
find
(
Map
fields
);
@Operation
()
<
X
>
X
find
(
String
query
);
@Operation
()
<
X
>
X
find
(
String
query
,
List
fieldValues
);
@Operation
()
<
X
extends
BizObject
>
BizList
<
X
>
createList
();
@Operation
()
<
X
extends
BizObject
>
BizList
<
X
>
createList
(
String
query
);
@Operation
()
<
X
extends
BizObject
>
BizList
<
X
>
createList
(
Map
fields
);
@Operation
()
<
X
extends
BizObject
>
BizList
<
X
>
findAll
(
Map
fields
);
@Operation
()
<
X
extends
BizObject
>
BizList
<
X
>
findAll
(
String
query
);
@Operation
()
<
X
extends
BizObject
>
BizList
<
X
>
findAll
(
String
query
,
List
fieldValues
);
@Operation
()
BizSelect
select
();
@Operation
()
BizSelect
select
(
Map
fields
);
@Operation
()
BizSelect
select
(
String
query
);
@Operation
()
<
X
>
X
delete
(
Long
id
);
@Operation
()
List
<
Object
>
findField
(
String
query
,
String
field
);
@Operation
()
List
<
Map
>
findFields
(
String
query
,
String
...
fields
);
// 更多Operation
}
src/main/java/logwire/web/bo/proxy/Proxy.java
0 → 100644
View file @
e46f9d26
package
logwire
.
web
.
bo
.
proxy
;
import
logwire.core.bo.object.BizObject
;
import
logwire.web.bo.BoRelationDefinition
;
import
logwire.web.bo.provider.DefaultTypeOperationProvider
;
import
net.bytebuddy.ByteBuddy
;
import
net.bytebuddy.implementation.MethodDelegation
;
import
net.bytebuddy.matcher.ElementMatchers
;
public
class
Proxy
{
/**
*
* 初始化 BO的 service : TypeOperationProvider
*
* @param boRelationDefinition
* @return
* @throws IllegalAccessException
* @throws InstantiationException
* @throws NoSuchFieldException
*/
public
static
Object
createTypeOperationProvider
(
BoRelationDefinition
boRelationDefinition
)
throws
IllegalAccessException
,
InstantiationException
,
NoSuchFieldException
{
Class
<?
extends
BizObject
>
beanClass
=
boRelationDefinition
.
getBoClass
();
// 动态生成service
// 若直接继承了BizObject,则动态代理继承DefaultTypeOperationProvider,否则继承父类中的service对应的TypeOperationProvider
Class
superClass
=
DefaultTypeOperationProvider
.
class
;
if
(
beanClass
.
getSuperclass
()
!=
BizObject
.
class
)
{
// parent TypeOperationProvider
superClass
=
beanClass
.
getSuperclass
().
getField
(
"serivce"
).
getClass
();
}
return
new
ByteBuddy
().
subclass
(
superClass
)
.
implement
(
boRelationDefinition
.
getTypeOperationProviders
())
.
method
(
ElementMatchers
.
any
())
.
intercept
(
MethodDelegation
.
to
(
new
TypeOperationInterceptor
(
boRelationDefinition
)))
.
make
()
.
load
(
beanClass
.
getClassLoader
())
.
getLoaded
().
newInstance
();
}
}
src/main/java/logwire/web/bo/proxy/TypeOperationInterceptor.java
0 → 100644
View file @
e46f9d26
package
logwire
.
web
.
bo
.
proxy
;
import
logwire.core.bo.handler.OperationHandler
;
import
logwire.core.bo.handler.TypeOperationHandler
;
import
logwire.web.bo.BoRelationDefinition
;
import
logwire.web.security.SecurityUtil
;
import
logwire.web.security.TenantUser
;
import
net.bytebuddy.implementation.bind.annotation.AllArguments
;
import
net.bytebuddy.implementation.bind.annotation.Origin
;
import
net.bytebuddy.implementation.bind.annotation.SuperMethod
;
import
net.bytebuddy.implementation.bind.annotation.This
;
import
java.lang.reflect.Method
;
import
java.util.Comparator
;
import
java.util.List
;
public
class
TypeOperationInterceptor
{
private
BoRelationDefinition
boRelationDefinition
;
public
TypeOperationInterceptor
(
BoRelationDefinition
boRelationDefinition
)
{
this
.
boRelationDefinition
=
boRelationDefinition
;
}
public
Object
interceptor
(
@This
Object
proxy
,
@Origin
Method
method
,
@SuperMethod
Method
superMethod
,
@AllArguments
Object
[]
args
)
throws
Exception
{
if
(
superMethod
!=
null
)
{
return
superMethod
.
invoke
(
proxy
,
args
);
}
return
doHandler
(
method
,
args
);
}
/**
* 根据methodName找到对应的handler
*/
private
Object
doHandler
(
Method
method
,
Object
[]
args
)
{
List
<
OperationHandler
>
typeOperationHandlers
=
boRelationDefinition
.
getTypeOperationHandlers
();
OperationHandler
operationHandler
=
typeOperationHandlers
.
stream
()
.
filter
(
typeOperationHandler
->
{
return
method
.
getName
().
equals
(
typeOperationHandler
.
getOperation
());
})
.
max
(
Comparator
.
comparing
(
OperationHandler:
:
getOrder
)).
get
();
TenantUser
currentUser
=
SecurityUtil
.
currentUser
();
/* logger.debug("Execute operation {} start", new Object[]{operationName});
String namespace = logwire.core.resource.Util.operationName(thisOperable.getOperableName(), operationName);
actionContext.emit(namespace, BuiltinEventNames.OPERATION_BEFORE.name(), currentUser.getDomain(), new OperationEventData(thisOperable, inputArgs, null));
*/
return
((
TypeOperationHandler
)
operationHandler
).
execute
(
boRelationDefinition
.
getBoClass
(),
args
);
}
}
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