// prepareDocument checks for an `_id` field and moves it to `id`.
546639
func prepareDocument(msg message.Msg) map[string]interface{} {
	if _, ok := msg.Data()["id"]; ok {
		return msg.Data()
	}

	if _, ok := msg.Data()["_id"]; ok {
		msg.Data().Set("id", msg.ID())
		msg.Data().Delete("_id")
	}
	return msg.Data()
}
1105433
func (c *authenticatedConnection) prepare(ctx context.Context) error {
	c.prepareMutex.Lock()
	defer c.prepareMutex.Unlock()
	if c.prepared == 0 {
		// We need to prepare first
		if err := c.auth.Prepare(ctx, c.conn); err != nil {
			// Authentication failed
			return driver.WithStack(err)
		}
		// We're now prepared
		atomic.StoreInt32(&c.prepared, 1)
	} else {
		// We're already prepared, do nothing
	}
	return nil
}
995636
func (c *Client) PrepareTemplate(p *PrepareTemplateParameter) (*Template, error) {
	obj, err := c.Request("prepareTemplate", convertParamToMap(p))
	if err != nil {
		return nil, err
	}
	return obj.(*Template), err
}
520835
func (m *MySQLLock) prepare(name, query string) error {
	stmt, err := m.in.Prepare(query)
	if err != nil {
		return errwrap.Wrapf(fmt.Sprintf("failed to prepare %q: {{err}}", name), err)
	}
	m.statements[name] = stmt
	return nil
}
794510
func (s *PutGroupPolicyInput) SetPolicyDocument(v string) *PutGroupPolicyInput {
	s.PolicyDocument = &v
	return s
}
1138507
func (doc *Document) updateDocument(oldBody []byte, newBody []byte) ([]byte, error) {

	var oldBodyMap map[string]interface{}
	var newBodyMap map[string]interface{}
	err := json.Unmarshal(oldBody, &oldBodyMap)
	if err != nil {
		return nil, errors.New("Unmarshalling error " + err.Error())
	}

	err = json.Unmarshal(newBody, &newBodyMap)
	if err != nil {
		return nil, errors.New("Unmarshalling error " + err.Error())
	}

	// Update old data with new contents.
	for newKey, newValue := range newBodyMap {
		oldBodyMap[newKey] = newValue
	}

	oldBodyMap["_rev"] = doc.Rev
	// do the update operation.
	newData, err := json.Marshal(oldBodyMap)
	if err != nil {
		return nil, errors.New("Marshalling error of new value in couch " + err.Error())
	}
	return newData, nil
}
1356289
func (s *DocumentStatistics) analyzeDocument(source string, document *openapi.Document) {
	s.Name = source

	s.Title = document.Info.Title
	for _, pair := range document.Paths.Path {
		path := pair.Value
		if path.Get != nil {
			s.analyzeOperation("get", "paths"+pair.Name+"/get", path.Get)
		}
		if path.Post != nil {
			s.analyzeOperation("post", "paths"+pair.Name+"/post", path.Post)
		}
		if path.Put != nil {
			s.analyzeOperation("put", "paths"+pair.Name+"/put", path.Put)
		}
		if path.Delete != nil {
			s.analyzeOperation("delete", "paths"+pair.Name+"/delete", path.Delete)
		}
	}
	if document.Definitions != nil {
		for _, pair := range document.Definitions.AdditionalProperties {
			definition := pair.Value
			s.analyzeDefinition("definitions/"+pair.Name, definition)
		}
	}
}
941279
func (conn *OCI8Conn) Prepare(query string) (driver.Stmt, error) {
	return conn.PrepareContext(context.Background(), query)
}
162495
func (nodeStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
	node := obj.(*api.Node)
	// Nodes allow *all* fields, including status, to be set on create.
	if !utilfeature.DefaultFeatureGate.Enabled(features.DynamicKubeletConfig) {
		node.Spec.ConfigSource = nil
		node.Status.Config = nil
	}
}
281970
func (c *Crawler) Preprocess() (*goquery.Document, error) {
	var err error

	if c.RawHTML == "" {
		if c.RawHTML, err = c.fetchHTML(c.url, c.config.timeout); err != nil {
			return nil, err
		}
	}
	if c.RawHTML == "" {
		return nil, errors.New("cannot process empty HTML content")
	}

	c.RawHTML = c.addSpacesBetweenTags(c.RawHTML)

	reader := strings.NewReader(c.RawHTML)
	document, err := goquery.NewDocumentFromReader(reader)
	if err != nil {
		return nil, err
	}

	cs := c.GetCharset(document)
	//log.Println("-------------------------------------------CHARSET:", cs)
	if "" != cs && "UTF-8" != cs {
		// the net/html parser and goquery require UTF-8 data
		c.RawHTML = UTF8encode(c.RawHTML, cs)
		reader = strings.NewReader(c.RawHTML)
		if document, err = goquery.NewDocumentFromReader(reader); err != nil {
			return nil, err
		}
	}

	return document, nil
}
62490
func (s *ResourcePolicy) SetPolicyDocument(v string) *ResourcePolicy {
	s.PolicyDocument = &v
	return s
}
786862
func (c *CrateDriver) Prepare(query string) (driver.Stmt, error) {
	stmt := &CrateStmt{
		stmt:   query,
		driver: c,
	}

	return stmt, nil
}
989683
func (s *HTTPServer) preparedQueryExplain(id string, resp http.ResponseWriter, req *http.Request) (interface{}, error) {
	args := structs.PreparedQueryExecuteRequest{
		QueryIDOrName: id,
		Agent: structs.QuerySource{
			Node:       s.agent.config.NodeName,
			Datacenter: s.agent.config.Datacenter,
			Segment:    s.agent.config.SegmentName,
		},
	}
	s.parseSource(req, &args.Source)
	if done := s.parse(resp, req, &args.Datacenter, &args.QueryOptions); done {
		return nil, nil
	}
	if err := parseLimit(req, &args.Limit); err != nil {
		return nil, fmt.Errorf("Bad limit: %s", err)
	}

	var reply structs.PreparedQueryExplainResponse
	defer setMeta(resp, &reply.QueryMeta)
RETRY_ONCE:
	if err := s.agent.RPC("PreparedQuery.Explain", &args, &reply); err != nil {
		// We have to check the string since the RPC sheds
		// the specific error type.
		if err.Error() == consul.ErrQueryNotFound.Error() {
			resp.WriteHeader(http.StatusNotFound)
			fmt.Fprint(resp, err.Error())
			return nil, nil
		}
		return nil, err
	}
	if args.QueryOptions.AllowStale && args.MaxStaleDuration > 0 && args.MaxStaleDuration < reply.LastContact {
		args.AllowStale = false
		args.MaxStaleDuration = 0
		goto RETRY_ONCE
	}
	reply.ConsistencyLevel = args.QueryOptions.ConsistencyLevel()
	return reply, nil
}
281005
func (s *DocumentStore) CreateDocument(ctx context.Context, d *influxdb.Document, opts ...influxdb.DocumentOptions) error {
	return s.CreateDocumentFn(ctx, d, opts...)
}
423872
func (c *Page) SetDocumentContent(frameId string, html string) (*gcdmessage.ChromeResponse, error) {
	var v PageSetDocumentContentParams
	v.FrameId = frameId
	v.Html = html
	return c.SetDocumentContentWithParams(&v)
}
501095
func Prepare(schema Schema) Schema {
	job := prepareJob{
		seen: make(map[Schema]Schema),
	}
	return job.prepare(schema)
}
1194828
func (m *RecordCollectionManager) NewRecordDocument(r *common.Record) (string, error) {
	r.RecordID = uuid.NewV4().String()
	_, err := m.manager.col.Upsert(bson.M{"_id": r.RecordID}, r)
	return r.RecordID, err
}