本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.0KB

  1. // Copyright 2015 The Xorm Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package xorm
  5. // BeforeInsertProcessor executed before an object is initially persisted to the database
  6. type BeforeInsertProcessor interface {
  7. BeforeInsert()
  8. }
  9. // BeforeUpdateProcessor executed before an object is updated
  10. type BeforeUpdateProcessor interface {
  11. BeforeUpdate()
  12. }
  13. // BeforeDeleteProcessor executed before an object is deleted
  14. type BeforeDeleteProcessor interface {
  15. BeforeDelete()
  16. }
  17. // BeforeSetProcessor executed before data set to the struct fields
  18. type BeforeSetProcessor interface {
  19. BeforeSet(string, Cell)
  20. }
  21. // AfterSetProcessor executed after data set to the struct fields
  22. type AfterSetProcessor interface {
  23. AfterSet(string, Cell)
  24. }
  25. // AfterInsertProcessor executed after an object is persisted to the database
  26. type AfterInsertProcessor interface {
  27. AfterInsert()
  28. }
  29. // AfterUpdateProcessor executed after an object has been updated
  30. type AfterUpdateProcessor interface {
  31. AfterUpdate()
  32. }
  33. // AfterDeleteProcessor executed after an object has been deleted
  34. type AfterDeleteProcessor interface {
  35. AfterDelete()
  36. }
  37. // AfterLoadProcessor executed after an ojbect has been loaded from database
  38. type AfterLoadProcessor interface {
  39. AfterLoad()
  40. }
  41. // AfterLoadSessionProcessor executed after an ojbect has been loaded from database with session parameter
  42. type AfterLoadSessionProcessor interface {
  43. AfterLoad(*Session)
  44. }
  45. type executedProcessorFunc func(*Session, interface{}) error
  46. type executedProcessor struct {
  47. fun executedProcessorFunc
  48. session *Session
  49. bean interface{}
  50. }
  51. func (executor *executedProcessor) execute() error {
  52. return executor.fun(executor.session, executor.bean)
  53. }
  54. func (session *Session) executeProcessors() error {
  55. processors := session.afterProcessors
  56. session.afterProcessors = make([]executedProcessor, 0)
  57. for _, processor := range processors {
  58. if err := processor.execute(); err != nil {
  59. return err
  60. }
  61. }
  62. return nil
  63. }
上海开阖软件有限公司 沪ICP备12045867号-1