苏州瑞玛APS项目web后台
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.

53 lines
1.5 KiB

  1. package container
  2. import (
  3. "errors"
  4. "fmt"
  5. "reflect"
  6. )
  7. type NewSessionBroker struct {
  8. // 调用器
  9. caller Caller
  10. // 会话
  11. sessionContext *SessionContext
  12. }
  13. func (broker *NewSessionBroker) Call(in []reflect.Value) []reflect.Value {
  14. // 从接口获取方法,Receiver不算作入参
  15. if len(in) < 1 {
  16. // Todo Log
  17. return []reflect.Value{reflect.ValueOf(errors.New(fmt.Sprintf("参数长度错误!")))}
  18. }
  19. firstParameter := in[0]
  20. switch firstParameter.Kind() {
  21. case reflect.Ptr:
  22. if firstParameter.Type() != RequestContextType {
  23. // Todo Log
  24. return []reflect.Value{reflect.ValueOf(errors.New(fmt.Sprintf("第一个参数类型不正确!")))}
  25. }
  26. if firstParameter.IsNil() {
  27. // Todo Log
  28. return []reflect.Value{reflect.ValueOf(errors.New(fmt.Sprintf("第一个参数必须赋值!")))}
  29. }
  30. break
  31. case reflect.Invalid:
  32. return []reflect.Value{reflect.ValueOf(errors.New(fmt.Sprintf("第一个参数不能为空!")))}
  33. break
  34. default:
  35. // Todo Log
  36. return []reflect.Value{reflect.ValueOf(errors.New(fmt.Sprintf("第一个参数类型错误!")))}
  37. }
  38. requestContext := firstParameter.Interface().(*RequestContext)
  39. if requestContext.session != nil {
  40. // Todo Log
  41. return []reflect.Value{reflect.ValueOf(errors.New(fmt.Sprintf("上下文的会话应当为空!")))}
  42. }
  43. transactionHandler, err := broker.sessionContext.transactionHandlerFactory.Create()
  44. if err != nil {
  45. return []reflect.Value{reflect.ValueOf(err)}
  46. }
  47. defer transactionHandler.Close()
  48. requestContext.session = transactionHandler.Session()
  49. return broker.caller(in)
  50. }