// RollbackAll aborts all of transactions
func (xse *XormSessionManager) RollbackAll(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.Rollback()
		if err != nil {
			errList = append(errList, err)
		}
		s.Init()
	}

	sl.clearTransactions()
	if len(errList) > 0 {
		return errors.NewErrRollbackAll(errList)
	}
	return nil
}
Example #2
0
// RollbackAll aborts all of transactions
func (xtx *XormTransaction) RollbackAll() error {
	if xtx.orm.IsReadOnly() {
		return nil
	}
	var errList []error
	for _, s := range xtx.transactions {
		err := s.Rollback()
		if err != nil {
			errList = append(errList, err)
		}
	}

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