// View starts a managed transaction for reading
// the provided function is executed within the transaction
488747
func (c *Cellar) View(fn func(*Tx) error) error {
	t, err := c.Begin(false)
	if err != nil {
		return err
	}

	// Make sure the transaction rolls back in the event of a panic.
	defer func() {
		if t.cellar != nil {
			_ = t.rollback()
		}
	}()

	// Mark as a managed tx so that the inner function cannot manually rollback.
	t.managed = true

	// If an error is returned from the function then pass it through.
	err = fn(t)
	t.managed = false
	if err != nil {
		_ = t.Rollback()
		return err
	}

	if err := t.Rollback(); err != nil {
		return err
	}

	return nil
}
408189
func (v *View) Show() {
	if v.ShowState == nil {
		v.ShowState = &ShowView{}
	}
	v.activeState = v.ShowState
}
8322
func (c *WorkitemtypeController) Show(ctx *app.ShowWorkitemtypeContext) error {
	err := application.Transactional(c.db, func(appl application.Application) error {
		witModel, err := appl.WorkItemTypes().Load(ctx.Context, ctx.WitID)
		if err != nil {
			return err
		}
		return ctx.ConditionalRequest(*witModel, c.config.GetCacheControlWorkItemType, func() error {
			witData := ConvertWorkItemTypeFromModel(ctx.Request, witModel)
			wit := &app.WorkItemTypeSingle{Data: &witData}
			return ctx.OK(wit)
		})
	})
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, err)
	}
	return nil
}
520793
func (v *View) Mount(dom *js.Object) {
	v.dom = dom
	v.events.OffloadDOM()
	v.events.LoadDOM(dom)
	v.Send(true)
	atomic.StoreInt32(&v.loaded, 1)
}
1186501
func (f *Field) viewPath(name string) string {
	return filepath.Join(f.path, "views", name)
}
1158080
func (m *MediaTypeDefinition) ComputeViews() map[string]*ViewDefinition {
	if m.Views != nil {
		return m.Views
	}
	if m.IsArray() {
		if mt, ok := m.ToArray().ElemType.Type.(*MediaTypeDefinition); ok {
			return mt.ComputeViews()
		}
	}
	return nil
}
437093
func (r *View) ReadByte() (byte, error) {
	chunk := r.chunkBytes()
	if len(chunk) == 0 {
		return 0, io.EOF
	}
	r.Skip(1)
	return chunk[0], nil
}
448672
func (f *Field) openViews() error {
	file, err := os.Open(filepath.Join(f.path, "views"))
	if os.IsNotExist(err) {
		return nil
	} else if err != nil {
		return errors.Wrap(err, "opening view directory")
	}
	defer file.Close()

	fis, err := file.Readdir(0)
	if err != nil {
		return errors.Wrap(err, "reading directory")
	}

	for _, fi := range fis {
		if !fi.IsDir() {
			continue
		}

		name := filepath.Base(fi.Name())
		f.logger.Debugf("open index/field/view: %s/%s/%s", f.index, f.name, fi.Name())
		view := f.newView(f.viewPath(name), name)
		if err := view.open(); err != nil {
			return fmt.Errorf("opening view: view=%s, err=%s", view.name, err)
		}
		view.rowAttrStore = f.rowAttrStore
		f.logger.Debugf("add index/field/view to field.viewMap: %s/%s/%s", f.index, f.name, view.name)
		f.viewMap[view.name] = view
	}

	return nil
}
838631
func (b *Bucket) ViewCustom(ddoc, name string, params map[string]interface{},
	vres interface{}) (err error) {
	if SlowServerCallWarningThreshold > 0 {
		defer slowLog(time.Now(), "call to ViewCustom(%q, %q)", ddoc, name)
	}

	if ViewCallback != nil {
		defer func(t time.Time) { ViewCallback(ddoc, name, t, err) }(time.Now())
	}

	u, err := b.ViewURL(ddoc, name, params)
	if err != nil {
		return err
	}

	req, err := http.NewRequest("GET", u, nil)
	if err != nil {
		return err
	}

	ah := b.authHandler(false /* bucket not yet locked */)
	maybeAddAuth(req, ah)

	res, err := doHTTPRequest(req)
	if err != nil {
		return fmt.Errorf("error starting view req at %v: %v", u, err)
	}
	defer res.Body.Close()

	if res.StatusCode != 200 {
		bod := make([]byte, 512)
		l, _ := res.Body.Read(bod)
		return fmt.Errorf("error executing view req at %v: %v - %s",
			u, res.Status, bod[:l])
	}

	body, err := ioutil.ReadAll(res.Body)
	if err := json.Unmarshal(body, vres); err != nil {
		return nil
	}

	return nil
}
106212
func (eng *engine) FindView(view View, keys KeyList, container TableListContainer, opts ...GetOption) error {
	s := eng.newSession()
	defer s.Close()
	action, err := s.recursivelyLoadView(view, keys, container, s.applyGetOption(opts))
	if err != nil {
		return s.catch("FindView: "+action, err)
	}
	return nil
}
574191
func (vv VectorisedView) ToView() View {
	if len(vv.views) == 1 {
		return vv.views[0]
	}
	u := make([]byte, 0, vv.size)
	for _, v := range vv.views {
		u = append(u, v...)
	}
	return u
}
242721
func ScanView(ctx context.Context, view ClearableView, cb func(path string)) error {
	frontier := []string{""}
	for len(frontier) > 0 {
		n := len(frontier)
		current := frontier[n-1]
		frontier = frontier[:n-1]

		// List the contents
		contents, err := view.List(ctx, current)
		if err != nil {
			return errwrap.Wrapf(fmt.Sprintf("list failed at path %q: {{err}}", current), err)
		}

		// Handle the contents in the directory
		for _, c := range contents {
			fullPath := current + c
			if strings.HasSuffix(c, "/") {
				frontier = append(frontier, fullPath)
			} else {
				cb(fullPath)
			}
		}
	}
	return nil
}
1072579
func (a *CellView) Init() {
	a.once.Do(func() {
		a.port = NewViewPort(nil, 0, 0, 0, 0)
		a.style = tcell.StyleDefault
	})
}
1059732
func (c *Client) CreateView(ctx context.Context, d *platform.View) error {
	return c.db.Update(func(tx *bolt.Tx) error {
		if pe := c.createView(ctx, tx, d); pe != nil {
			return &platform.Error{
				Op:  getOp(platform.OpCreateView),
				Err: pe,
			}
		}
		return nil
	})
}
283413
func NewView() *View {
	view := new(View)
	view.templateLoader = make(map[string]*TemplateManager)
	view.FuncMap = make(template.FuncMap)
	view.FuncMap["Html"] = func(s string) template.HTML { return template.HTML(s) }
	return view
}
476691
func (v *view) row(rowID uint64) *Row {
	row := NewRow()
	for _, frag := range v.allFragments() {
		fr := frag.row(rowID)
		if fr == nil {
			continue
		}
		row.Merge(fr)
	}
	return row

}
429441
func (client *QueryClient) ReadTransaction(dtid string) (*querypb.TransactionMetadata, error) {
	return client.server.ReadTransaction(client.ctx, &client.target, dtid)
}