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

parent c2477866
Pipeline #5689 canceled with stages
...@@ -8,10 +8,10 @@ import java.lang.annotation.RetentionPolicy; ...@@ -8,10 +8,10 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
/** /**
* Type级Operation声明注解 * BO工厂类,用来创建BO或找到BO
*/ */
@Target({ElementType.TYPE}) @Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface TypeOperationProvider { public @interface BizObjectFactory {
Class<? extends BizObject> type(); Class<? extends BizObject> type();
} }
...@@ -12,6 +12,8 @@ import java.lang.annotation.Target; ...@@ -12,6 +12,8 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface Operation { public @interface Operation {
String name();
String label() default ""; String label() default "";
OperationArg[] args() default {}; OperationArg[] args() default {};
......
package logwire.core.bo.eventhandler;
import logwire.core.bo.object.BizObject;
public interface TypeOperationEventHandler<X extends BizObject> extends OperationEventHandler {
default void doBefore(Class<X> xClass, Object... args) {
//调用行为同名方法
}
default void doAfter(Class<X> xClass, Object result, Object... args) {
//调用行为同名方法
}
}
\ No newline at end of file
package logwire.core.bo.factory;
import logwire.core.bo.object.BizObject;
public interface BizObjectFactoryEventHandler<X extends BizObject> {
String getOperationName();
void doBefore(Class<X> xClass, Object... args);
void doAfter(Class<X> xClass, Object result, Object... args);
}
\ No newline at end of file
package logwire.core.bo.factory;
import logwire.core.bo.object.BizObject;
public interface BizObjectFactoryHandler<X extends BizObject> {
String getOperationName();
// 取消enable这个参数,配置文件和程序里都有配置会导致混淆
// 只会从配置文件中读取,只有在配置文件中配置的,才会进行加载
//boolean isEnabled();
//取消order参数,按照配置文件中的顺序来执行
//default int getOrder(){return 1000;}
default boolean accept(Class<X> xClass, Object... args) {
return true;
}
Object execute(Class<X> xClass, Object... args);
}
package logwire.core.bo.factory;
import logwire.core.bo.annotation.Operation;
import logwire.core.bo.list.BizList;
import logwire.core.bo.object.BizObject;
import java.util.Map;
/**
* BOFactory默认实现的接口
* @param <X> BO类
*/
public interface DefaultBizObjectFactory<X extends BizObject> {
@Operation(name = "create",label="创建BO对象")
X create();
@Operation(name = "createByDefault")
X createByDefault(Map defaultValues);
@Operation(name = "findById")
X findById(Long id);
@Operation(name = "findOne")
X findOne(Map fields);
/* 暂不支持lql
@Operation()
X find(String query);
@Operation()
X find(String query, List fieldValues);
*/
@Operation(name = "createList")
BizList<X> createList();
@Operation(name = "createListByDefault")
BizList<X> createListByDefault(Map fields);
@Operation(name = "find")
BizList<X> find(Map fields);
/* 暂不支持lql
@Operation()
BizList<X> find(String query);
@Operation()
BizList<X> find(String query, List fieldValues);
*/
@Operation(name = "findAll")
BizList<X> findAll();
/* 暂不支持lql
@Operation()
List<Object> findField(String query, String field);
@Operation()
List<Map> findFields(String query, String...fields);
*/
// 更多Operation
}
package logwire.core.bo.factory;
import logwire.core.bo.object.BizObject;
public interface SmartBizObjectFactoryHandler<X extends BizObject> extends BizObjectFactoryHandler<X> {
default Object execute(Class<X> xClass, Object...args) {
//调用与Operation同名方法
//目的增加代码可读性
return null;
}
}
...@@ -6,18 +6,24 @@ import logwire.core.bo.list.BizList; ...@@ -6,18 +6,24 @@ import logwire.core.bo.list.BizList;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.Map; import java.util.Map;
/**
* 一对多关系字段
* @param <X>
*/
public interface BizItem<X extends BizObject> extends Iterable<X> { public interface BizItem<X extends BizObject> extends Iterable<X> {
boolean isChanged(); boolean isChanged();
X find(String field, Object value); X findOne(String field, Object value);
X find(Map<String, Field> fields); X findOne(Map<String, Field> fields);
X create(); X create();
X create(Map<String, Field> fields); X create(Map<String, Field> fields);
BizList<X> findAll(String field, Object value); BizList<X> find(String field, Object value);
BizList<X> findAll(Map fields); BizList<X> find(Map fields);
BizList<X> findAll();
} }
...@@ -3,7 +3,7 @@ package logwire.core.bo.field; ...@@ -3,7 +3,7 @@ package logwire.core.bo.field;
import logwire.core.bo.object.BizObject; import logwire.core.bo.object.BizObject;
import logwire.core.bo.list.BizList; import logwire.core.bo.list.BizList;
public interface BizMany<X extends BizObject> extends Iterable<Object> { public interface BizMany<X extends BizObject> extends Iterable<X> {
void add(Long id); void add(Long id);
void remove(Long id); void remove(Long id);
...@@ -12,5 +12,7 @@ public interface BizMany<X extends BizObject> extends Iterable<Object> { ...@@ -12,5 +12,7 @@ public interface BizMany<X extends BizObject> extends Iterable<Object> {
void remove(X object); void remove(X object);
void allAll(BizList<X> list); void addAll(BizList<X> list);
BizList<X> findAll();
} }
...@@ -2,10 +2,14 @@ package logwire.core.bo.field; ...@@ -2,10 +2,14 @@ package logwire.core.bo.field;
import logwire.core.bo.object.ModelObject; import logwire.core.bo.object.ModelObject;
/**
* 多对一关系字段
* @param <X>
*/
public interface BizOne<X extends ModelObject> { public interface BizOne<X extends ModelObject> {
Long getValue(); Long getId();
void setValue(Long value); void setId(Long id);
X getObject(); X getObject();
} }
package logwire.core.bo.handler;
import logwire.core.bo.object.BizObject;
public interface ObjectOperationHandler<X extends BizObject> extends OperationHandler {
default String getQuery() {
return "";
}
default boolean accept(X x, Object... args) {
return true;
}
Object execute(X x, Object... args);
}
package logwire.core.bo.handler;
import logwire.core.bo.object.BizObject;
public interface TypeOperationHandler<X extends BizObject> extends OperationHandler {
default boolean accept(Class<X> xClass, Object... args) {
return true;
}
Object execute(Class<X> xClass, Object... args);
}
...@@ -6,21 +6,27 @@ import java.util.Map; ...@@ -6,21 +6,27 @@ import java.util.Map;
public interface BizList<X extends BizObject> extends Iterable<X> { public interface BizList<X extends BizObject> extends Iterable<X> {
X find(String field, Object value); De
X find(Map fields); X findOne(String field, Object value);
X findOne(Map fields);
/* 暂不支持lql
X find(String query); X find(String query);
*/
X create(); X create();
X create(Map fields); X create(Map fields);
X create(String query); BizList<X> find(String field, Object value);
BizList<X> findAll(String field, Object value); BizList<X> find(Map fields);
BizList<X> findAll(Map fields); /* 暂不支持lql
BizList<X> find(String query);
*/
BizList<X> findAll(String query); BizList<X> findAll();
} }
\ No newline at end of file
...@@ -13,34 +13,36 @@ import java.util.Map; ...@@ -13,34 +13,36 @@ import java.util.Map;
* BO 子表字段(多对多、数组、大文本)生成的Model,audit/version/domain都为false * BO 子表字段(多对多、数组、大文本)生成的Model,audit/version/domain都为false
*/ */
public abstract class BizObject extends ModelObject { public abstract class BizObject extends ModelObject {
/**
* 事务类型 insert/update/delete
*/
String txCode;
/** String txCode; //事务类型 insert/update/delete
* 当事务类型为update时,记录修改过的字段
*/
Map<String, Object> updatedFields;
Map updatedFields; //当事务类型为update时,记录修改过的字段
@Column(label="主键")
Long id;// BO 的ID全部为雪花ID Long id;// BO 的ID全部为雪花ID
@Column(label="版本号")
int version; int version;
@Column(label = "BO名称") @Column(label = "BO名称")
String boName; String boName = this.getClass().getSimpleName();
@Column(label="创建用户")
BizOne<User> insert_user; BizOne<User> insert_user;
@Column(label="创建时间")
OffsetDateTime insert_date; OffsetDateTime insert_date;
@Column(label="最后修改用户")
BizOne<User> update_user; BizOne<User> update_user;
@Column(label="最后修改时间")
OffsetDateTime update_date; OffsetDateTime update_date;
@Composite(label = "项目扩展字段", prefix = "exp_") @Composite(label = "项目扩展字段", prefix = "exp_")
BizExpando exps; BizExpando exps;
@Column(label="域")
String domain_name; String domain_name;
......
...@@ -10,6 +10,7 @@ public abstract class User extends ModelObject { ...@@ -10,6 +10,7 @@ public abstract class User extends ModelObject {
@Column(label = "xid") @Column(label = "xid")
String userXid; String userXid;
@Override
public Object getId() { public Object getId() {
return userGid; return userGid;
} }
......
package logwire.core.bo.operation.list;
import logwire.core.bo.annotation.ListOperationProvider;
import logwire.core.bo.annotation.Operation;
import logwire.core.bo.object.BizObject;
//所有BO Object 默认ListOperation定义
@ListOperationProvider(type = BizObject.class)
public interface DefaultListOperationProvider<X extends BizObject> {
@Operation(name = "getProvider")
DefaultListOperationProvider<X> getProvider();
@Operation(name = "save")
void save();
@Operation(name = "delete")
void delete();
@Operation(name = "insert")
void insert();
@Operation(name = "update")
void update(String ...fields);
}
\ No newline at end of file
package logwire.core.bo.operation.object;
import logwire.core.bo.annotation.ObjectOperationProvider;
import logwire.core.bo.annotation.Operation;
import logwire.core.bo.object.BizObject;
import java.util.Map;
//所有BO Object 默认Operation定义
@ObjectOperationProvider(type = BizObject.class)
public interface DefaultObjectOperationProvider<X extends BizObject> {
@Operation(name = "save")
void save();
@Operation(name = "delete")
void delete();
@Operation(name = "update")
void update(Map fields);
// 更多操作定义
}
\ No newline at end of file
package logwire.core.bo.eventhandler; package logwire.core.bo.operation.object;
import logwire.core.bo.object.BizObject; import logwire.core.bo.object.BizObject;
public interface ObjectOperationEventHandler<X extends BizObject> extends OperationEventHandler { public interface ObjectOperationEventHandler<X extends BizObject> {
String getOperationName();
default String getQuery() { default boolean isAfter() {return true;}
return ""; default void doBefore(X x, Object...args){
}
default void doBefore(X x, Object... args) {
//调用行为同名方法 //调用行为同名方法
} }
default void doAfter(X x, Object result, Object...args){
default void doAfter(X x, Object result, Object... args) {
//调用行为同名方法 //调用行为同名方法
} }
} }
package logwire.core.bo.operation.object;
import logwire.core.bo.object.BizObject;
public interface ObjectOperationHandler<X extends BizObject> {
String getOperationName();
/*boolean isEnabled();
default int getOrder(){return 1000;}*/
default boolean accept(X x, Object...args){return true;}
Object execute(X x, Object...args);
}
package logwire.core.bo.operation.object;
import logwire.core.bo.object.BizObject;
public interface SmartObjectOperationHandler<X extends BizObject> extends ObjectOperationHandler<X> {
default Object execute(X x, Object...args) {
//调用与Operation同名方法
//目的增加代码可读性
return null;
}
}
package logwire.core.bo.select;
public interface BizChildSelect extends BizSelect {
}
package logwire.core.bo.select;
public interface BizSelect {
}
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