コード例 #1
0
ファイル: db.go プロジェクト: sore0159/overpower
func (d *DB) Transact(f func(*Manager) (error, error)) (logErr, failed error) {
	g := func(d db.DBer) error {
		m := NewManager(d)
		var revertE error
		logErr, revertE = f(m)
		if my, bad := Check(revertE, "manager transaction failure on execution"); bad {
			return my
		}
		revertE = m.Close()
		if my, bad := Check(revertE, "manager transaction failure on closure"); bad {
			return my
		}
		return nil
	}
	err := db.Transact(d.DB, g)
	if my, bad := Check(err, "managar transaction failed on db transact"); bad {
		return logErr, my
	}
	return logErr, nil
}
コード例 #2
0
ファイル: db.go プロジェクト: sore0159/overpower
func (d *DB) SourceTransact(gid int, f func(overpower.Source) (logE, revertE error)) (logErr, failErr error) {
	g := func(d db.DBer) error {
		m := NewManager(d)
		s := NewSource(m, gid)
		var revertE error
		logErr, revertE = f(s)
		if my, bad := Check(revertE, "source transaction failure on execution"); bad {
			return my
		}
		revertE = m.Close()
		if my, bad := Check(revertE, "source transaction failure on closure"); bad {
			return my
		}
		return nil
	}
	err := db.Transact(d.DB, g)
	if my, bad := Check(err, "source transaction failed on db transact"); bad {
		return logErr, my
	}
	return logErr, nil
}