Use AfterLoad instead of AfterSet on Structs (#2628)
* use AfterLoad instead of AfterSet on Structs * fix the comments on AfterLoad * fix the comments on action AfterLoad
This commit is contained in:
parent
1ad902d529
commit
a8717e5e3a
35 changed files with 334 additions and 315 deletions
40
vendor/github.com/go-xorm/xorm/processors.go
generated
vendored
40
vendor/github.com/go-xorm/xorm/processors.go
generated
vendored
|
@ -29,13 +29,6 @@ type AfterSetProcessor interface {
|
|||
AfterSet(string, Cell)
|
||||
}
|
||||
|
||||
// !nashtsai! TODO enable BeforeValidateProcessor when xorm start to support validations
|
||||
//// Executed before an object is validated
|
||||
//type BeforeValidateProcessor interface {
|
||||
// BeforeValidate()
|
||||
//}
|
||||
// --
|
||||
|
||||
// AfterInsertProcessor executed after an object is persisted to the database
|
||||
type AfterInsertProcessor interface {
|
||||
AfterInsert()
|
||||
|
@ -50,3 +43,36 @@ type AfterUpdateProcessor interface {
|
|||
type AfterDeleteProcessor interface {
|
||||
AfterDelete()
|
||||
}
|
||||
|
||||
// AfterLoadProcessor executed after an ojbect has been loaded from database
|
||||
type AfterLoadProcessor interface {
|
||||
AfterLoad()
|
||||
}
|
||||
|
||||
// AfterLoadSessionProcessor executed after an ojbect has been loaded from database with session parameter
|
||||
type AfterLoadSessionProcessor interface {
|
||||
AfterLoad(*Session)
|
||||
}
|
||||
|
||||
type executedProcessorFunc func(*Session, interface{}) error
|
||||
|
||||
type executedProcessor struct {
|
||||
fun executedProcessorFunc
|
||||
session *Session
|
||||
bean interface{}
|
||||
}
|
||||
|
||||
func (executor *executedProcessor) execute() error {
|
||||
return executor.fun(executor.session, executor.bean)
|
||||
}
|
||||
|
||||
func (session *Session) executeProcessors() error {
|
||||
processors := session.afterProcessors
|
||||
session.afterProcessors = make([]executedProcessor, 0)
|
||||
for _, processor := range processors {
|
||||
if err := processor.execute(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue