// CommitAll commits all of transactions
func (xse *XormSessionManager) CommitAll(id Identifier) error {
	if !xse.hasSessionList(id) {
		return nil
	}

	sl := xse.getOrCreateSessionList(id)
	switch {
	case sl == nil:
		return nil
	case sl.IsReadOnly():
		return nil
	}

	var errList []error
	for _, s := range sl.getTransactions() {
		err := s.Commit()
		if err != nil {
			errList = append(errList, err)
		}
		s.Init()
	}

	sl.clearTransactions()
	if len(errList) > 0 {
		return errors.NewErrCommitAll(errList)
	}
	return nil
}
示例#2
0
// CommitAll commits all of transactions
func (xtx *XormTransaction) CommitAll() error {
	if xtx.orm.IsReadOnly() {
		return nil
	}
	var errList []error
	for _, s := range xtx.transactions {
		err := s.Commit()
		if err != nil {
			errList = append(errList, err)
		}
	}

	xtx.transactions = make(map[interface{}]Session)
	if len(errList) > 0 {
		return errors.NewErrCommitAll(errList)
	}
	return nil
}