Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

有没有对外接口,可以自定义实现对象字段填充 #88

Open
JasonWong-ZS opened this issue Dec 17, 2020 · 3 comments
Open

有没有对外接口,可以自定义实现对象字段填充 #88

JasonWong-ZS opened this issue Dec 17, 2020 · 3 comments
Assignees
Labels
enhancement New feature or request extensions

Comments

@JasonWong-ZS
Copy link

有没有对外接口,可以自定义实现对象字段填充,
比如:
我要在插入一条记录的时候,将创建时间赋值为当前时间,创建人取当前线程的用户ID,
在更新记录时候,可以将更新时间赋值为当前时间,更新人取当前线程的用户ID

@catchex catchex self-assigned this Dec 17, 2020
@catchex catchex added enhancement New feature or request extensions labels Dec 17, 2020
@catchex
Copy link
Member

catchex commented Dec 17, 2020

好想法,这种扩展特性可以通过扩展SQLExecutor 实现,然后通过Databases.installSQLExecutor 方法将自定义类注入ObjectiveSQL。

SQLExecutor 中insert 对应SQL 语句中的INSERT,execute 方法对应UPDATE 和DELETE。

在insert 和execute 方法中,需要获取业务上下文,例如:current_user 等,通过ThreadLocal 的方式进行传递,并及时清空,具体可以参考:Databases.java 中的 connectionThreadLocal 的使用方法

@catchex
Copy link
Member

catchex commented Dec 17, 2020

1)通过扩展SQLExecutor 是在SQL 结构已经固定,只需要补充相关参数的值的时候使用。
2)如果SQL 结构跟随业务特性变化,则需要扩展Persistence ,在内部调整SQL 结构和相关参数

@JasonWong-ZS
Copy link
Author

我是这样实现的
image
image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request extensions
Projects
None yet
Development

No branches or pull requests

2 participants