// creates a new Item if it can
348565
func (p *itemPool) newItem() (*Item, error) {
	if len(p.itemMap) >= p.capacity {
		return nil, ErrItemUnavailable
	}
	i, err := p.itemFactory()
	if err != nil {
		return nil, err
	}

	pItem := &Item{id: p.nextID(), Item: i}
	p.itemMap[pItem.id] = pItem
	return pItem, nil
}
164588
func (i *Item) Init() {
	i.CreatedAt = time.Now().UnixNano()
	i.ExpiredAt = math.MaxInt64
	i.Value = nil
}
295751
func New() ConcurrentMap {
	m := make(ConcurrentMap, SHARD_COUNT)
	for i := 0; i < SHARD_COUNT; i++ {
		m[i] = &ConcurrentMapShared{items: make(map[string]interface{})}
	}
	return m
}
241007
func (r *GormWorkItemRepository) Create(ctx context.Context, spaceID uuid.UUID, typeID uuid.UUID, fields map[string]interface{}, creatorID uuid.UUID) (*WorkItem, *Revision, error) {
	defer goa.MeasureSince([]string{"goa", "db", "workitem", "create"}, time.Now())

	wiType, err := r.witr.Load(ctx, typeID)
	if err != nil {
		return nil, nil, errors.NewBadParameterError("typeID", typeID)
	}

	allowedWIT, err := r.CheckTypeAndSpaceShareTemplate(ctx, wiType, spaceID)
	if err != nil {
		return nil, nil, err

	}
	if !allowedWIT {
		return nil, nil, err
	}

	// The order of workitems are spaced by a factor of 1000.
	pos, err := r.LoadHighestOrder(ctx, spaceID)
	if err != nil {
		return nil, nil, errors.NewInternalError(ctx, err)
	}
	pos = pos + orderValue
	number, err := r.winr.NextVal(ctx, spaceID)
	if err != nil {
		return nil, nil, errors.NewInternalError(ctx, err)
	}
	wi := WorkItemStorage{
		Type:           typeID,
		Fields:         Fields{},
		ExecutionOrder: pos,
		SpaceID:        spaceID,
		Number:         *number,
	}
	fields[SystemCreator] = creatorID.String()
	for fieldName, fieldDef := range wiType.Fields {
		if fieldDef.ReadOnly {
			continue
		}
		fieldValue := fields[fieldName]
		var err error
		wi.Fields[fieldName], err = fieldDef.ConvertToModel(fieldName, fieldValue)
		if err != nil {
			return nil, nil, errors.NewBadParameterError(fieldName, fieldValue) // TODO(kwk): Change errors pkg to consume the original error as well
		}
		if fieldDef.Type.GetKind() == KindList && fieldValue == nil {
			delete(wi.Fields, fieldName)
		}
		if fieldName == SystemDescription && wi.Fields[fieldName] != nil {
			description := rendering.NewMarkupContentFromMap(wi.Fields[fieldName].(map[string]interface{}))
			if !rendering.IsMarkupSupported(description.Markup) {
				return nil, nil, errors.NewBadParameterError(fieldName, fieldValue)
			}
		}
	}
	if err := r.db.Create(&wi).Error; err != nil {
		return nil, nil, errs.Wrapf(err, "failed to create work item")
	}

	witem, err := ConvertWorkItemStorageToModel(wiType, &wi)
	if err != nil {
		return nil, nil, err
	}
	// store a revision of the created work item
	rev, err := r.wirr.Create(context.Background(), creatorID, RevisionTypeCreate, wi)
	if err != nil {
		return nil, nil, errs.Wrapf(err, "error while creating work item")
	}
	log.Debug(ctx, map[string]interface{}{"pkg": "workitem", "wi_id": wi.ID, "number": wi.Number}, "Work item created successfully!")
	return witem, &rev, nil
}
645687
func (r *GormWorkItemLinkRepository) Create(ctx context.Context, sourceID, targetID uuid.UUID, linkTypeID uuid.UUID, creatorID uuid.UUID) (*WorkItemLink, error) {
	defer goa.MeasureSince([]string{"goa", "db", "workitemlink", "create"}, time.Now())
	link := &WorkItemLink{
		SourceID:   sourceID,
		TargetID:   targetID,
		LinkTypeID: linkTypeID,
	}
	if err := link.CheckValidForCreation(); err != nil {
		return nil, errs.WithStack(err)
	}

	// double check only links between the same space are allowed.
	// NOTE(kwk): This is only until we have a proper cross-space
	// cycle detection with locks.
	wiRepo := workitem.NewWorkItemRepository(r.db)
	workItemIDs := []uuid.UUID{sourceID, targetID}
	items, err := wiRepo.LoadBatchByID(ctx, workItemIDs)
	if err != nil {
		return nil, errs.Wrapf(err, "failed to load source and target work items: %+v", workItemIDs)
	}
	spaceID := items[0].SpaceID
	for _, item := range items {
		if item.SpaceID != spaceID {
			return nil, errs.Errorf("cross-space links are not allowed (for now)")
		}
	}

	if err := r.acquireLock(spaceID); err != nil {
		return nil, errs.Wrap(err, "failed to acquire lock during link creation")
	}

	// Fetch the link type
	linkType, err := r.workItemLinkTypeRepo.Load(ctx, linkTypeID)
	if err != nil {
		return nil, errs.Wrap(err, "failed to load link type")
	}

	// Make sure we don't violate the topology when we add the link from source
	// to target.
	if err := r.ValidateTopology(ctx, sourceID, targetID, *linkType); err != nil {
		return nil, errs.Wrapf(err, "failed to create work item due to topology violation")
	}

	db := r.db.Create(link)
	if db.Error != nil {
		if gormsupport.IsUniqueViolation(db.Error, "work_item_links_unique_idx") {
			log.Error(ctx, map[string]interface{}{
				"err":       db.Error,
				"source_id": sourceID,
			}, "unable to create work item link because a link already exists with the same source_id, target_id and type_id")
			return nil, errors.NewDataConflictError(fmt.Sprintf("work item link already exists with data.relationships.source_id: %s; data.relationships.target_id: %s; data.relationships.link_type_id: %s ", sourceID, targetID, linkTypeID))
		}
		if gormsupport.IsForeignKeyViolation(db.Error, "work_item_links_source_id_fkey") {
			return nil, errors.NewNotFoundError("source", sourceID.String())
		}
		if gormsupport.IsForeignKeyViolation(db.Error, "work_item_links_target_id_fkey") {
			return nil, errors.NewNotFoundError("target", targetID.String())
		}
		return nil, errors.NewInternalError(ctx, db.Error)
	}
	// save a revision of the created work item link
	if err := r.revisionRepo.Create(ctx, creatorID, RevisionTypeCreate, *link); err != nil {
		return nil, errs.Wrapf(err, "error while creating work item")
	}
	return link, nil
}
222263
func (c *Client) Create(notes string, keepCopy, noDownload bool) (*params.BackupsMetadataResult, error) {
	var result params.BackupsMetadataResult
	args := params.BackupsCreateArgs{
		Notes:      notes,
		KeepCopy:   keepCopy,
		NoDownload: noDownload,
	}

	if err := c.facade.FacadeCall("Create", args, &result); err != nil {
		return nil, errors.Trace(err)
	}

	return &result, nil
}
472740
func (d *DataBagService) Create(databag *DataBag) (result *DataBagCreateResult, err error) {
	body, err := JSONReader(databag)
	if err != nil {
		return
	}

	err = d.client.magicRequestDecoder("POST", "data", body, &result)
	return
}
1235462
func (w *WebsocketAsynchronousFactory) Create() Asynchronous {
	return newWs(w.parameters.URL, w.parameters.LogTransport, w.parameters.Logger)
}
544068
func (i *Item) addItem(property string, value *Item) {
	i.Properties[property] = append(i.Properties[property], value)
}
560681
func (c *FakeMiddlewares) Create(middleware *v1alpha1.Middleware) (result *v1alpha1.Middleware, err error) {
	obj, err := c.Fake.
		Invokes(testing.NewCreateAction(middlewaresResource, c.ns, middleware), &v1alpha1.Middleware{})

	if obj == nil {
		return nil, err
	}
	return obj.(*v1alpha1.Middleware), err
}
1192292
func (c *FakeWorkflows) Create(workflow *v1alpha1.Workflow) (result *v1alpha1.Workflow, err error) {
	obj, err := c.Fake.
		Invokes(testing.NewCreateAction(workflowsResource, c.ns, workflow), &v1alpha1.Workflow{})

	if obj == nil {
		return nil, err
	}
	return obj.(*v1alpha1.Workflow), err
}
819579
func (c *mutatingWebhookConfigurations) Create(mutatingWebhookConfiguration *v1beta1.MutatingWebhookConfiguration) (result *v1beta1.MutatingWebhookConfiguration, err error) {
	result = &v1beta1.MutatingWebhookConfiguration{}
	err = c.client.Post().
		Resource("mutatingwebhookconfigurations").
		Body(mutatingWebhookConfiguration).
		Do().
		Into(result)
	return
}
31316
func (c *FakeFischers) Create(fischer *v1alpha1.Fischer) (result *v1alpha1.Fischer, err error) {
	obj, err := c.Fake.
		Invokes(testing.NewRootCreateAction(fischersResource, fischer), &v1alpha1.Fischer{})
	if obj == nil {
		return nil, err
	}
	return obj.(*v1alpha1.Fischer), err
}
909078
func (f *FakeCreator) Create(sec *api.Secret) (*api.Secret, error) {
	ret, err := f.CreateFunc(sec)
	if err != nil {
		f.Errs = append(f.Errs, err)
		return nil, err
	}
	f.Created = append(f.Created, ret)
	return ret, nil
}
953897
func NewItem(formats []Formatter, id, prevId string) *Item {
	newItem := new(Item)
	newItem.id = id
	newItem.prevId = prevId
	newItem.formats = formats
	return newItem
}
678416
func (r *GormWorkItemLinkTypeRepository) Create(ctx context.Context, linkType WorkItemLinkType) (*WorkItemLinkType, error) {
	defer goa.MeasureSince([]string{"goa", "db", "workitemlinktype", "create"}, time.Now())
	if err := linkType.CheckValidForCreation(); err != nil {
		log.Error(ctx, map[string]interface{}{
			"wilt_id": linkType.ID.String(),
			"err":     err,
		}, "failed to validate link type")
		return nil, errs.WithStack(err)
	}
	db := r.db.Create(&linkType)
	if db.Error != nil {
		if gormsupport.IsUniqueViolation(db.Error, "work_item_link_types_name_idx") {
			log.Error(ctx, map[string]interface{}{
				"err":               db.Error,
				"space_template_id": linkType.SpaceTemplateID,
				"wilt_name":         linkType.Name,
			}, "unable to create work item link type because a link already exists with the same space_template_id and name")
			return nil, errors.NewDataConflictError(fmt.Sprintf("work item link type already exists with the same space_template_id: %s; name: %s ", linkType.SpaceTemplateID, linkType.Name))
		}
		log.Error(ctx, map[string]interface{}{
			"wilt_id": linkType.ID.String(),
			"err":     db.Error,
		}, "failed to create work item link type")
		return nil, errors.NewInternalError(ctx, errs.Wrap(db.Error, "failed to create link type"))
	}
	log.Info(ctx, map[string]interface{}{
		"wilt_id": linkType.ID.String(),
	}, "created work item link type")
	return &linkType, nil
}
455085
func (b *DynamoDBBackend) Create(ctx context.Context, item backend.Item) (*backend.Lease, error) {
	err := b.create(ctx, item, modeCreate)
	if trace.IsCompareFailed(err) {
		err = trace.AlreadyExists(err.Error())
	}
	if err != nil {
		return nil, trace.Wrap(err)
	}
	return b.newLease(item), nil
}