// update gets a writable bolt db transaction either from the context
// or starts a new one with the provided bolt database.
357394
func update(ctx context.Context, db transactor, fn func(*bolt.Tx) error) error {
	tx, ok := ctx.Value(transactionKey{}).(*bolt.Tx)
	if !ok {
		return db.Update(fn)
	} else if !tx.Writable() {
		return errors.Wrap(bolt.ErrTxNotWritable, "unable to use transaction from context")
	}
	return fn(tx)
}
100840
func (t *KVMsTable) update(c context.Context) error {
	// Avoid using the database connection to prepare unnecessary statements.
	if len(t.updates) == 0 {
		return nil
	}

	db := database.Get(c)
	// TODO(smut): Update IP address.
	stmt, err := db.PrepareContext(c, `
		UPDATE kvms
		SET description = ?, mac_address = ?, state = ?, platform_id = ?, rack_id = ?
		WHERE id = ?
	`)
	if err != nil {
		return errors.Annotate(err, "failed to prepare statement").Err()
	}
	defer stmt.Close()

	// Update each KVM in the table. It's more efficient to update the slice of
	// KVMs once at the end rather than for each update, so use a defer.
	updated := make(map[int64]*KVM, len(t.updates))
	defer func() {
		for _, kvm := range t.current {
			if u, ok := updated[kvm.Id]; ok {
				kvm.MacAddress = u.MacAddress
				kvm.Description = u.Description
				kvm.State = u.State
				kvm.PlatformId = u.PlatformId
				kvm.RackId = u.RackId
			}
		}
	}()
	for len(t.updates) > 0 {
		kvm := t.updates[0]
		if _, err := stmt.ExecContext(c, kvm.Description, kvm.MacAddress, kvm.State, kvm.PlatformId, kvm.RackId, kvm.Id); err != nil {
			return errors.Annotate(err, "failed to update KVM %q", kvm.Name).Err()
		}
		updated[kvm.Id] = kvm
		t.updates = t.updates[1:]
		logging.Infof(c, "Updated KVM %q", kvm.Name)
	}
	return nil
}
75078
func (t *DatacentersTable) update(c context.Context) error {
	// Avoid using the database connection to prepare unnecessary statements.
	if len(t.updates) == 0 {
		return nil
	}

	db := database.Get(c)
	stmt, err := db.PrepareContext(c, `
		UPDATE datacenters
		SET description = ?, state = ?
		WHERE id = ?
	`)
	if err != nil {
		return errors.Annotate(err, "failed to prepare statement").Err()
	}
	defer stmt.Close()

	// Update each datacenter in the table. It's more efficient to update the slice of
	// datacenters once at the end rather than for each update, so use a defer.
	updated := make(map[int64]*Datacenter, len(t.updates))
	defer func() {
		for _, dc := range t.current {
			if u, ok := updated[dc.Id]; ok {
				dc.Description = u.Description
				dc.State = u.State
			}
		}
	}()
	for len(t.updates) > 0 {
		dc := t.updates[0]
		if _, err := stmt.ExecContext(c, dc.Description, dc.State, dc.Id); err != nil {
			return errors.Annotate(err, "failed to update datacenter %q", dc.Name).Err()
		}
		updated[dc.Id] = dc
		t.updates = t.updates[1:]
		logging.Infof(c, "Updated datacenter %q", dc.Name)
	}
	return nil
}
337872
func (s *Store) Update(key interface{}, data interface{}) error {
	return s.Bolt().Update(func(tx *bolt.Tx) error {
		return s.TxUpdate(tx, key, data)
	})
}
1369279
func (s *KVStore) Update(ctx context.Context, fn func(kv.Tx) error) error {
	s.mu.Lock()
	defer s.mu.Unlock()
	if s.buckets == nil {
		s.buckets = map[string]*Bucket{}
	}

	return fn(&Tx{
		kv:       s,
		writable: true,
		ctx:      ctx,
	})
}
1126334
func (vrsConnection VRSConnection) Update(context interface{}, tableUpdates libovsdb.TableUpdates) {
	vrsConnection.updatesChan <- &tableUpdates
}
26869
func (batch *UpdateBatch) Update(ns string, key string, vv *VersionedValue) {
	batch.getOrCreateNsUpdates(ns).m[key] = vv
}
442251
func (c *FakeBrokerTemplateInstances) Update(brokerTemplateInstance *template.BrokerTemplateInstance) (result *template.BrokerTemplateInstance, err error) {
	obj, err := c.Fake.
		Invokes(testing.NewRootUpdateAction(brokertemplateinstancesResource, brokerTemplateInstance), &template.BrokerTemplateInstance{})
	if obj == nil {
		return nil, err
	}
	return obj.(*template.BrokerTemplateInstance), err
}
48691
func (c *TrackerController) Update(ctx *app.UpdateTrackerContext) error {
	_, err := login.ContextIdentity(ctx)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(err.Error()))
	}
	err = validateUpdateTrackerPayload(ctx)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, err)
	}
	var trkr *remoteworkitem.Tracker
	err = application.Transactional(c.db, func(appl application.Application) error {
		trkr, err = appl.Trackers().Load(ctx.Context, *ctx.Payload.Data.ID)
		if err != nil {
			return err
		}
		if &ctx.Payload.Data.Attributes.URL != nil {
			trkr.URL = ctx.Payload.Data.Attributes.URL
		}
		if &ctx.Payload.Data.Attributes.Type != nil {
			trkr.Type = ctx.Payload.Data.Attributes.Type
		}
		_, err = appl.Trackers().Save(ctx.Context, trkr)
		return err
	})
	accessTokens := GetAccessTokens(c.configuration) //configuration.GetGithubAuthToken()
	c.scheduler.ScheduleAllQueries(ctx, accessTokens)
	res := &app.TrackerSingle{
		Data: ConvertTracker(ctx.Request, *trkr),
	}
	return ctx.OK(res)
}
224880
func (c *PreparedQuery) Update(query *PreparedQueryDefinition, q *WriteOptions) (*WriteMeta, error) {
	return c.c.write("/v1/query/"+query.ID, query, nil, q)
}
756951
func (m *Msg) Update(db *sqlx.DB) error {
	q := `UPDATE messages SET needstraining=$1 WHERE id=$2`
	if _, err := db.Exec(q, m.NeedsTraining, m.ID); err != nil {
		return err
	}
	return nil
}
952324
func (s *BoltStateDB) Upgrade() error {
	// Check to see if the underlying DB needs upgrading.
	upgrade, err := NeedsUpgrade(s.db.BoltDB())
	if err != nil {
		return err
	}
	if !upgrade {
		// No upgrade needed!
		return nil
	}

	// Upgraded needed. Backup the boltdb first.
	backupFileName := filepath.Join(s.stateDir, "state.db.backup")
	if err := backupDB(s.db.BoltDB(), backupFileName); err != nil {
		return fmt.Errorf("error backing up state db: %v", err)
	}

	// Perform the upgrade
	if err := s.db.Update(func(tx *boltdd.Tx) error {
		if err := UpgradeAllocs(s.logger, tx); err != nil {
			return err
		}

		// Add standard metadata
		if err := addMeta(tx.BoltTx()); err != nil {
			return err
		}

		// Write the time the upgrade was done
		bkt, err := tx.CreateBucketIfNotExists(metaBucketName)
		if err != nil {
			return err
		}
		return bkt.Put(metaUpgradedKey, time.Now().Format(time.RFC3339))
	}); err != nil {
		return err
	}

	s.logger.Info("successfully upgraded state")
	return nil
}
1135684
func (o *Object) Update() {
	o.mut.Lock()
	o.checked = false
	o.mut.Unlock()
}
291441
func (c Context) Update(other Context) Context {
	for k, v := range other {
		c[k] = v
	}
	return c
}
1033431
func (f *Frees) Update() {
	f.m.Lock()
	defer f.m.Unlock()

	runtime.ReadMemStats(&f.mem)
	f.d.Update(int64(f.mem.Frees))
}
757114
func (c *Cellar) Update(fn func(*Tx) error) error {
	t, err := c.Begin(true)
	if err != nil {
		return fmt.Errorf("cellar Update Begin: %v", 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 rollback and return error.
	err = fn(t)
	t.managed = false
	if err != nil {
		_ = t.Rollback()
		return fmt.Errorf("cellar Update Rollback: %v", err)
	}

	err = t.Commit()
	if err != nil {
		return fmt.Errorf("cellar Update Commit: %v", err)
	}
	return nil
}
707857
func (s *OrganizationsStore) Update(ctx context.Context, o *chronograf.Organization) error {
	org, err := s.get(ctx, o.ID)
	if err != nil {
		return err
	}
	if o.Name != org.Name && !s.nameIsUnique(ctx, o.Name) {
		return chronograf.ErrOrganizationAlreadyExists
	}
	return s.client.db.Update(func(tx *bolt.Tx) error {
		if v, err := internal.MarshalOrganization(o); err != nil {
			return err
		} else if err := tx.Bucket(OrganizationsBucket).Put([]byte(o.ID), v); err != nil {
			return err
		}
		return nil
	})
}