#1971 bo重新编写文档和demo,确保文档上的demo没有基本错误

parent f5fa3ac2
Pipeline #5687 canceled with stages
...@@ -2,10 +2,7 @@ package logwire.web.bo; ...@@ -2,10 +2,7 @@ package logwire.web.bo;
import logwire.core.bo.eventhandler.ListOperationEventHandler; import logwire.core.bo.eventhandler.ListOperationEventHandler;
import logwire.core.bo.eventhandler.ObjectOperationEventHandler; import logwire.core.bo.eventhandler.ObjectOperationEventHandler;
import logwire.core.bo.eventhandler.TypeOperationEventHandler;
import logwire.core.bo.handler.ListOperationHandler; import logwire.core.bo.handler.ListOperationHandler;
import logwire.core.bo.handler.ObjectOperationHandler;
import logwire.core.bo.handler.TypeOperationHandler;
import logwire.core.bo.object.BizObject; import logwire.core.bo.object.BizObject;
import logwire.core.meta.Config; import logwire.core.meta.Config;
import logwire.core.resource.bean.BeanAdapter; import logwire.core.resource.bean.BeanAdapter;
......
package logwire.web.bo.handler; package logwire.web.bo.handler;
import logwire.core.bo.handler.TypeOperationHandler;
import logwire.web.bo.BoService; import logwire.web.bo.BoService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
......
...@@ -24,7 +24,6 @@ import org.springframework.beans.factory.config.BeanDefinition; ...@@ -24,7 +24,6 @@ import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Component;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType; import java.lang.reflect.ParameterizedType;
...@@ -33,7 +32,11 @@ import java.util.*; ...@@ -33,7 +32,11 @@ import java.util.*;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Component /**
* todo bobean加载需要集成AbstractModelBeanLoader,从配置文件中读取是否加载bean
* 仍需要讨论bo建表的必要性,bo目前建表太过简单,需要打model-patch
*/
//@Component
public class BoModelBeanLoader extends BeanLoader<IQuery, TenantProject> implements JavaModelBeanLoader { public class BoModelBeanLoader extends BeanLoader<IQuery, TenantProject> implements JavaModelBeanLoader {
@Autowired @Autowired
......
...@@ -2,17 +2,14 @@ package logwire.web.bo.loader; ...@@ -2,17 +2,14 @@ package logwire.web.bo.loader;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import logwire.core.bo.annotation.BizModel; import logwire.core.bo.annotation.BizModel;
import logwire.core.bo.annotation.BizObjectFactory;
import logwire.core.bo.annotation.ListOperationProvider; import logwire.core.bo.annotation.ListOperationProvider;
import logwire.core.bo.annotation.ObjectOperationProvider; import logwire.core.bo.annotation.ObjectOperationProvider;
import logwire.core.bo.annotation.TypeOperationProvider;
import logwire.core.bo.eventhandler.ListOperationEventHandler; import logwire.core.bo.eventhandler.ListOperationEventHandler;
import logwire.core.bo.eventhandler.ObjectOperationEventHandler; import logwire.core.bo.eventhandler.ObjectOperationEventHandler;
import logwire.core.bo.eventhandler.OperationEventHandler; import logwire.core.bo.eventhandler.OperationEventHandler;
import logwire.core.bo.eventhandler.TypeOperationEventHandler;
import logwire.core.bo.handler.ListOperationHandler; import logwire.core.bo.handler.ListOperationHandler;
import logwire.core.bo.handler.ObjectOperationHandler;
import logwire.core.bo.handler.OperationHandler; import logwire.core.bo.handler.OperationHandler;
import logwire.core.bo.handler.TypeOperationHandler;
import logwire.core.bo.object.BizObject; import logwire.core.bo.object.BizObject;
import logwire.core.exceptions.ApplicationException; import logwire.core.exceptions.ApplicationException;
import logwire.core.resource.BeanLoader; import logwire.core.resource.BeanLoader;
...@@ -137,7 +134,7 @@ public class BoRelationBeanDefinitionLoader extends BeanLoader<BoRelationDefinit ...@@ -137,7 +134,7 @@ public class BoRelationBeanDefinitionLoader extends BeanLoader<BoRelationDefinit
}).collect(Collectors.groupingBy(clazz -> { }).collect(Collectors.groupingBy(clazz -> {
if (BizObject.class.isAssignableFrom(clazz)) { if (BizObject.class.isAssignableFrom(clazz)) {
return BIZ_OBJECT; return BIZ_OBJECT;
} else if (TypeOperationProvider.class.isAssignableFrom(clazz)) { } else if (BizObjectFactory.class.isAssignableFrom(clazz)) {
return TYPE_OPERATION_PROVIDER; return TYPE_OPERATION_PROVIDER;
} else if (ObjectOperationProvider.class.isAssignableFrom(clazz)) { } else if (ObjectOperationProvider.class.isAssignableFrom(clazz)) {
return OBJECT_OPERATION_PROVIDER; return OBJECT_OPERATION_PROVIDER;
...@@ -172,7 +169,7 @@ public class BoRelationBeanDefinitionLoader extends BeanLoader<BoRelationDefinit ...@@ -172,7 +169,7 @@ public class BoRelationBeanDefinitionLoader extends BeanLoader<BoRelationDefinit
private void addOperationProvider(Map<String, BoRelationDefinition> boRelationBeanDefinitions, Map<String, List<Class<?>>> beanClassMap) { private void addOperationProvider(Map<String, BoRelationDefinition> boRelationBeanDefinitions, Map<String, List<Class<?>>> beanClassMap) {
beanClassMap.get(TYPE_OPERATION_PROVIDER).forEach(clazz -> { beanClassMap.get(TYPE_OPERATION_PROVIDER).forEach(clazz -> {
Class<? extends BizObject> type = clazz.getAnnotation(TypeOperationProvider.class).type(); Class<? extends BizObject> type = clazz.getAnnotation(BizObjectFactory.class).type();
boRelationBeanDefinitions.get(type.getSimpleName()).addTypeOperationProvider(clazz); boRelationBeanDefinitions.get(type.getSimpleName()).addTypeOperationProvider(clazz);
}); });
beanClassMap.get(OBJECT_OPERATION_PROVIDER).forEach(clazz -> { beanClassMap.get(OBJECT_OPERATION_PROVIDER).forEach(clazz -> {
...@@ -275,7 +272,7 @@ public class BoRelationBeanDefinitionLoader extends BeanLoader<BoRelationDefinit ...@@ -275,7 +272,7 @@ public class BoRelationBeanDefinitionLoader extends BeanLoader<BoRelationDefinit
provider.addIncludeFilter(loaderUtil.getAbstractTypeFilter(BizObject.class)); provider.addIncludeFilter(loaderUtil.getAbstractTypeFilter(BizObject.class));
provider.addIncludeFilter(new AssignableTypeFilter(OperationHandler.class)); provider.addIncludeFilter(new AssignableTypeFilter(OperationHandler.class));
provider.addIncludeFilter(new AssignableTypeFilter(OperationEventHandler.class)); provider.addIncludeFilter(new AssignableTypeFilter(OperationEventHandler.class));
provider.addIncludeFilter(new AnnotationTypeFilter(TypeOperationProvider.class)); provider.addIncludeFilter(new AnnotationTypeFilter(BizObjectFactory.class));
provider.addIncludeFilter(new AnnotationTypeFilter(ObjectOperationProvider.class)); provider.addIncludeFilter(new AnnotationTypeFilter(ObjectOperationProvider.class));
provider.addIncludeFilter(new AnnotationTypeFilter(ListOperationProvider.class)); provider.addIncludeFilter(new AnnotationTypeFilter(ListOperationProvider.class));
} }
......
package logwire.web.bo.loader;
import logwire.core.bo.factory.DefaultBizObjectFactory;
import logwire.core.bo.object.BizObject;
import java.util.Map;
public class FactoryBuilder {
private static Map<Class, DefaultBizObjectFactory> map;
public static <X extends DefaultBizObjectFactory> X build(Class<? extends BizObject> clazz){
return (X)map.get(clazz);
}
}
...@@ -2,7 +2,6 @@ package logwire.web.bo.loader; ...@@ -2,7 +2,6 @@ package logwire.web.bo.loader;
import logwire.core.bo.eventhandler.OperationEventHandler; import logwire.core.bo.eventhandler.OperationEventHandler;
import logwire.core.bo.handler.OperationHandler; import logwire.core.bo.handler.OperationHandler;
import logwire.core.bo.handler.TypeOperationHandler;
import logwire.core.bo.object.BizObject; import logwire.core.bo.object.BizObject;
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
......
package logwire.web.bo.provider;
import logwire.core.bo.annotation.ObjectOperationProvider;
import logwire.core.bo.annotation.Operation;
import logwire.core.bo.object.BizObject;
//所有BO Object 默认Operation定义
@ObjectOperationProvider(type = BizObject.class)
public interface DefaultObjectOperationProvider {
@Operation()
void save();
@Operation()
void delete();
@Operation()
void update(String... fields);
// 更多操作定义
}
\ No newline at end of file
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 createWithDefault(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, T extends BizList<X>> T 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
}
package logwire.web.bo.proxy; package logwire.web.bo.proxy;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import logwire.core.bo.handler.ObjectOperationHandler; import logwire.core.bo.factory.DefaultBizObjectFactory;
import logwire.core.bo.object.BizObject; import logwire.core.bo.object.BizObject;
import logwire.web.bo.BoRelationDefinition; import logwire.web.bo.BoRelationDefinition;
import logwire.web.bo.provider.DefaultTypeOperationProvider;
import net.bytebuddy.ByteBuddy; import net.bytebuddy.ByteBuddy;
import net.bytebuddy.implementation.MethodDelegation; import net.bytebuddy.implementation.MethodDelegation;
import net.bytebuddy.matcher.ElementMatchers; import net.bytebuddy.matcher.ElementMatchers;
...@@ -28,7 +27,7 @@ public class Proxy { ...@@ -28,7 +27,7 @@ public class Proxy {
// 动态生成service // 动态生成service
// 若直接继承了BizObject,则动态代理继承DefaultTypeOperationProvider, // 若直接继承了BizObject,则动态代理继承DefaultTypeOperationProvider,
// 否则继承父类中的service对应的TypeOperationProvider // 否则继承父类中的service对应的TypeOperationProvider
Class superClass = DefaultTypeOperationProvider.class; Class superClass = DefaultBizObjectFactory.class;
if (boClass.getSuperclass() != BizObject.class) { if (boClass.getSuperclass() != BizObject.class) {
// parent TypeOperationProvider // parent TypeOperationProvider
superClass = boClass.getSuperclass().getField("service").getClass(); superClass = boClass.getSuperclass().getField("service").getClass();
......
package logwire.web.bo.util;
public class ClassUtil {
/**
* 校验是否实现了某个类是否实现了这个接口
* @param orign
* @param interfaceClass
* @return
*/
public static boolean isInterfaceClass(Class<?> orign,Class<?> interfaceClass){
for (Class<?> clazz:orign.getInterfaces()) {
if (clazz==interfaceClass)
return true;
}
return false;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment