// UpsertJobTxn is used to register a job or update a job definition, like UpsertJob,
// but in a transaction.  Useful for when making multiple modifications atomically
171227
func (s *StateStore) UpsertJobTxn(index uint64, job *structs.Job, txn Txn) error {
	return s.upsertJobImpl(index, job, false, txn)
}
808078
func (db *DB) Upsert(list ...interface{}) error {
	return insertObjects(db.Context(), db, db, getUpsert, list, opUpsert)
}
808604
func (m ConcurrentMap) Upsert(key string, value interface{}, cb UpsertCb) (res interface{}) {
	shard := m.GetShard(key)
	shard.Lock()
	v, ok := shard.items[key]
	res = cb(ok, v, value)
	shard.items[key] = res
	shard.Unlock()
	return res
}
280417
func (j *Jenkins) RenameJob(job string, name string) *Job {
	jobObj := Job{Jenkins: j, Raw: new(JobResponse), Base: "/job/" + job}
	jobObj.Rename(name)
	return &jobObj
}
1301111
func (s *StateStore) UpsertPeriodicLaunch(index uint64, launch *structs.PeriodicLaunch) error {
	txn := s.db.Txn(true)
	defer txn.Abort()

	// COMPAT 0.7: Upgrade old objects that do not have namespaces
	if launch.Namespace == "" {
		launch.Namespace = structs.DefaultNamespace
	}

	// Check if the job already exists
	existing, err := txn.First("periodic_launch", "id", launch.Namespace, launch.ID)
	if err != nil {
		return fmt.Errorf("periodic launch lookup failed: %v", err)
	}

	// Setup the indexes correctly
	if existing != nil {
		launch.CreateIndex = existing.(*structs.PeriodicLaunch).CreateIndex
		launch.ModifyIndex = index
	} else {
		launch.CreateIndex = index
		launch.ModifyIndex = index
	}

	// Insert the job
	if err := txn.Insert("periodic_launch", launch); err != nil {
		return fmt.Errorf("launch insert failed: %v", err)
	}
	if err := txn.Insert("index", &IndexEntry{"periodic_launch", index}); err != nil {
		return fmt.Errorf("index update failed: %v", err)
	}

	txn.Commit()
	return nil
}
118599
func (c *FakeJobs) Update(job *batchv1.Job) (result *batchv1.Job, err error) {
	obj, err := c.Fake.
		Invokes(testing.NewUpdateAction(jobsResource, c.ns, job), &batchv1.Job{})

	if obj == nil {
		return nil, err
	}
	return obj.(*batchv1.Job), err
}
981906
func (dct *DjangoContentType) Upsert(db XODB) error {
	var err error

	// if already exist, bail
	if dct._exists {
		return errors.New("insert failed: already exists")
	}

	// sql query
	const sqlstr = `INSERT INTO public.django_content_type (` +
		`id, app_label, model` +
		`) VALUES (` +
		`$1, $2, $3` +
		`) ON CONFLICT (id) DO UPDATE SET (` +
		`id, app_label, model` +
		`) = (` +
		`EXCLUDED.id, EXCLUDED.app_label, EXCLUDED.model` +
		`)`

	// run query
	XOLog(sqlstr, dct.ID, dct.AppLabel, dct.Model)
	_, err = db.Exec(sqlstr, dct.ID, dct.AppLabel, dct.Model)
	if err != nil {
		return err
	}

	// set existence
	dct._exists = true

	return nil
}
561063
func (dm *DjangoMigration) Upsert(db XODB) error {
	var err error

	// if already exist, bail
	if dm._exists {
		return errors.New("insert failed: already exists")
	}

	// sql query
	const sqlstr = `INSERT INTO public.django_migrations (` +
		`id, app, name, applied` +
		`) VALUES (` +
		`$1, $2, $3, $4` +
		`) ON CONFLICT (id) DO UPDATE SET (` +
		`id, app, name, applied` +
		`) = (` +
		`EXCLUDED.id, EXCLUDED.app, EXCLUDED.name, EXCLUDED.applied` +
		`)`

	// run query
	XOLog(sqlstr, dm.ID, dm.App, dm.Name, dm.Applied)
	_, err = db.Exec(sqlstr, dm.ID, dm.App, dm.Name, dm.Applied)
	if err != nil {
		return err
	}

	// set existence
	dm._exists = true

	return nil
}
524395
func (w *Wrapper) UpsertTunnelConnection(conn services.TunnelConnection) error {
	return w.Write.UpsertTunnelConnection(conn)
}
883027
func (api *Client) UpdateImportJobState(ctx context.Context, jobID string, newState string) error {
	path := api.url + "/jobs/" + jobID
	jsonUpload := []byte(`{"state":"` + newState + `"}`)

	jsonResult, httpCode, err := api.putJSON(ctx, path, 0, jsonUpload)
	logData := log.Data{
		"path":        path,
		"importJobID": jobID,
		"jsonUpload":  jsonUpload,
		"httpCode":    httpCode,
		"jsonResult":  jsonResult,
	}
	if err == nil && httpCode != http.StatusOK {
		err = errors.New("Bad HTTP response")
	}
	if err != nil {
		log.ErrorC("UpdateImportJobState", err, logData)
		return err
	}
	return nil
}
221934
func (m *Monitor) JobUpdate(updateKey aurora.JobUpdateKey, interval int, timeout int) (bool, error) {

	status, err := m.JobUpdateStatus(updateKey,
		map[aurora.JobUpdateStatus]bool{
			aurora.JobUpdateStatus_ROLLED_FORWARD: true,
			aurora.JobUpdateStatus_ROLLED_BACK:    true,
			aurora.JobUpdateStatus_ABORTED:        true,
			aurora.JobUpdateStatus_ERROR:          true,
			aurora.JobUpdateStatus_FAILED:         true,
		},
		time.Duration(interval)*time.Second,
		time.Duration(timeout)*time.Second)

	if err != nil {
		return false, err
	}

	m.Client.RealisConfig().logger.Printf("job update status: %v\n", status)

	// Rolled forward is the only state in which an update has been successfully updated
	// if we encounter an inactive state and it is not at rolled forward, update failed
	switch status {
	case aurora.JobUpdateStatus_ROLLED_FORWARD:
		return true, nil
	case aurora.JobUpdateStatus_ROLLED_BACK, aurora.JobUpdateStatus_ABORTED, aurora.JobUpdateStatus_ERROR, aurora.JobUpdateStatus_FAILED:
		return false, errors.Errorf("bad terminal state for update: %v", status)
	default:
		return false, errors.Errorf("unexpected update state: %v", status)
	}
}
633612
func newJobs(c *BatchV1Client, namespace string) *jobs {
	return &jobs{
		client: c.RESTClient(),
		ns:     namespace,
	}
}
1167990
func InsertVoutsDbTxn(dbTx *sql.Tx, dbVouts []*dbtypes.Vout, checked bool, doUpsert bool) ([]uint64, []dbtypes.AddressRow, error) {
	stmt, err := dbTx.Prepare(internal.MakeVoutInsertStatement(checked, doUpsert))
	if err != nil {
		return nil, nil, err
	}

	ids, addressRows, err := InsertVoutsStmt(stmt, dbVouts, checked, doUpsert)
	errClose := stmt.Close()
	if err != nil {
		return nil, nil, err
	}
	if errClose != nil {
		return nil, nil, err
	}

	return ids, addressRows, stmt.Close()
}
1225569
func rollbackModifyColumnJob(t *meta.Meta, tblInfo *model.TableInfo, job *model.Job, oldCol *model.ColumnInfo, modifyColumnTp byte) (ver int64, _ error) {
	var err error
	if modifyColumnTp == mysql.TypeNull {
		// field NotNullFlag flag reset.
		tblInfo.Columns[oldCol.Offset].Flag = oldCol.Flag &^ mysql.NotNullFlag
		// field PreventNullInsertFlag flag reset.
		tblInfo.Columns[oldCol.Offset].Flag = oldCol.Flag &^ mysql.PreventNullInsertFlag
		ver, err = updateVersionAndTableInfo(t, job, tblInfo, true)
		if err != nil {
			return ver, errors.Trace(err)
		}
	}
	return ver, nil
}
312499
func (tc *TiDBContext) CommitTxn(ctx context.Context) error {
	return tc.session.CommitTxn(ctx)
}
462830
func NewBatchJob(id, name, region string, pri int) *Job {
	return newJob(id, name, region, JobTypeBatch, pri)
}
947074
func (c *Host) AddJob(job *host.Job) error {
	return c.c.Put(fmt.Sprintf("/host/jobs/%s", job.ID), job, nil)
}