package container

import (
	"errors"
	"fmt"
	"github.com/go-xorm/xorm"
)

type DefaultTransactionHandler struct {
	// 会话
	session *xorm.Session
}

func NewDefaultTransactionHandler(session *xorm.Session) (*DefaultTransactionHandler, error) {

	if session == nil {
		return nil, errors.New(fmt.Sprintf("会话不能为空!"))
	}
	return &DefaultTransactionHandler{session}, nil
}

func (handler DefaultTransactionHandler) Close() {
	handler.session.Close()
}

func (handler DefaultTransactionHandler) Begin() error {
	return handler.session.Begin()
}

func (handler DefaultTransactionHandler) Commit() error {
	return handler.session.Commit()
}

func (handler DefaultTransactionHandler) Session() *xorm.Session {
	return handler.session
}
