GAAS GFrame项目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.

51 lines
1.6 KiB

// Copyright (c) Shenyang Leading Edge Intelligent Technology Co., Ltd. All rights reserved.
package container
import (
"errors"
"fmt"
)
// 新事务代理创建器
// @Implement LAPP_GAAS_GFrame_BACKEND/container/CallerBrokerBuilder
type NewTransactionBrokerBuilder struct {
}
// 创建新事务代理创建器
// 返回值:
// 1.新事务代理创建器
func NewNewTransactionBrokerBuilder() *NewTransactionBrokerBuilder {
return &NewTransactionBrokerBuilder{}
}
// @Reference LAPP_GAAS_GFrame_BACKEND/container/CallerBrokerBuilder.Check
func (builder *NewTransactionBrokerBuilder) Check(methodType Method) error {
if methodType == nil {
return errors.New(fmt.Sprintf("方法类型不能为空!"))
}
// 从接口类型获取方法类型,Receiver不算作入参
if methodType.NumIn() < 1 {
return errors.New(fmt.Sprintf("参数太少!实际数量:%d", methodType.NumIn()))
}
if methodType.In(0) != xormSessionType {
return errors.New(fmt.Sprintf("第一个参数必须是*xorm.Session"))
}
for i := 1; i < methodType.NumIn(); i++ {
if methodType.In(i) == xormSessionType {
return errors.New(fmt.Sprintf("第%d个参数不能是*xorm.Session", i+1))
}
}
return nil
}
// @Reference LAPP_GAAS_GFrame_BACKEND/container/CallerBrokerBuilder.Build
func (builder *NewTransactionBrokerBuilder) Build(session *Session, caller Caller) (Caller, error) {
if session == nil {
return nil, errors.New(fmt.Sprintf("会话不能为空!"))
}
if caller == nil {
return nil, errors.New(fmt.Sprintf("调用器不能为空!"))
}
return (&NewTransactionBroker{caller, session}).Call, nil
}