|
|
@ -5,7 +5,6 @@ package container |
|
|
|
import ( |
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
"reflect" |
|
|
|
) |
|
|
|
|
|
|
|
// 新事务代理创建器
|
|
|
@ -48,48 +47,5 @@ func (builder *NewTransactionBrokerBuilder) Build(session *Session, caller Calle |
|
|
|
if caller == nil { |
|
|
|
return nil, errors.New(fmt.Sprintf("调用器不能为空!")) |
|
|
|
} |
|
|
|
return func(in []reflect.Value) []reflect.Value { |
|
|
|
// 从接口获取方法,Receiver不算作入参
|
|
|
|
if len(in) < 1 { |
|
|
|
// Todo Log
|
|
|
|
return []reflect.Value{reflect.ValueOf(errors.New(fmt.Sprintf("参数长度错误!")))} |
|
|
|
} |
|
|
|
firstParameter := in[0] |
|
|
|
switch firstParameter.Kind() { |
|
|
|
case reflect.Ptr: |
|
|
|
if firstParameter.Type() != xormSessionType { |
|
|
|
// Todo Log
|
|
|
|
return []reflect.Value{reflect.ValueOf(errors.New(fmt.Sprintf("第一个参数类型不正确!")))} |
|
|
|
} |
|
|
|
if !firstParameter.IsNil() { |
|
|
|
// Todo Log
|
|
|
|
return []reflect.Value{reflect.ValueOf(errors.New(fmt.Sprintf("第一个参数已经赋值!")))} |
|
|
|
} |
|
|
|
break |
|
|
|
case reflect.Invalid: |
|
|
|
break |
|
|
|
default: |
|
|
|
// Todo Log
|
|
|
|
return []reflect.Value{reflect.ValueOf(errors.New(fmt.Sprintf("第一个参数类型不正确!")))} |
|
|
|
} |
|
|
|
transactionHandler, err := session.transactionHandlerFactory.Create() |
|
|
|
if err != nil { |
|
|
|
return []reflect.Value{reflect.ValueOf(err)} |
|
|
|
} |
|
|
|
defer transactionHandler.Close() |
|
|
|
in[0] = reflect.ValueOf(transactionHandler.Session()) |
|
|
|
if err := transactionHandler.Begin(); err != nil { |
|
|
|
// Todo Log
|
|
|
|
return []reflect.Value{reflect.ValueOf(err)} |
|
|
|
} |
|
|
|
out := caller(in) |
|
|
|
lastReturnValue := out[len(out)-1] |
|
|
|
if lastReturnValue.Kind() == reflect.Invalid { |
|
|
|
if err := transactionHandler.Commit(); err != nil { |
|
|
|
// Todo Log
|
|
|
|
return []reflect.Value{reflect.ValueOf(err)} |
|
|
|
} |
|
|
|
} |
|
|
|
return out |
|
|
|
}, nil |
|
|
|
return (&NewTransactionBroker{caller, session}).Call, nil |
|
|
|
} |