package proto_gorm import ( context "context" json "encoding/json" fmt "fmt" gorm1 "github.com/infobloxopen/atlas-app-toolkit/gorm" query "github.com/infobloxopen/atlas-app-toolkit/query" errors "github.com/infobloxopen/protoc-gen-gorm/errors" gorm "github.com/jinzhu/gorm" trace "go.opencensus.io/trace" field_mask "google.golang.org/genproto/protobuf/field_mask" ) type IntPointORM struct { Id uint32 X int32 Y int32 } // TableName overrides the default tablename generated by GORM func (IntPointORM) TableName() string { return "int_points" } // ToORM runs the BeforeToORM hook if present, converts the fields of this // object to ORM format, runs the AfterToORM hook, then returns the ORM object func (m *IntPoint) ToORM(ctx context.Context) (IntPointORM, error) { to := IntPointORM{} var err error if prehook, ok := interface{}(m).(IntPointWithBeforeToORM); ok { if err = prehook.BeforeToORM(ctx, &to); err != nil { return to, err } } to.Id = m.Id to.X = m.X to.Y = m.Y if posthook, ok := interface{}(m).(IntPointWithAfterToORM); ok { err = posthook.AfterToORM(ctx, &to) } return to, err } // ToPB runs the BeforeToPB hook if present, converts the fields of this // object to PB format, runs the AfterToPB hook, then returns the PB object func (m *IntPointORM) ToPB(ctx context.Context) (IntPoint, error) { to := IntPoint{} var err error if prehook, ok := interface{}(m).(IntPointWithBeforeToPB); ok { if err = prehook.BeforeToPB(ctx, &to); err != nil { return to, err } } to.Id = m.Id to.X = m.X to.Y = m.Y if posthook, ok := interface{}(m).(IntPointWithAfterToPB); ok { err = posthook.AfterToPB(ctx, &to) } return to, err } // The following are interfaces you can implement for special behavior during ORM/PB conversions // of type IntPoint the arg will be the target, the caller the one being converted from // IntPointBeforeToORM called before default ToORM code type IntPointWithBeforeToORM interface { BeforeToORM(context.Context, *IntPointORM) error } // IntPointAfterToORM called after default ToORM code type IntPointWithAfterToORM interface { AfterToORM(context.Context, *IntPointORM) error } // IntPointBeforeToPB called before default ToPB code type IntPointWithBeforeToPB interface { BeforeToPB(context.Context, *IntPoint) error } // IntPointAfterToPB called after default ToPB code type IntPointWithAfterToPB interface { AfterToPB(context.Context, *IntPoint) error } // DefaultCreateIntPoint executes a basic gorm create call func DefaultCreateIntPoint(ctx context.Context, in *IntPoint, db *gorm.DB) (*IntPoint, error) { if in == nil { return nil, errors.NilArgumentError } ormObj, err := in.ToORM(ctx) if err != nil { return nil, err } if hook, ok := interface{}(&ormObj).(IntPointORMWithBeforeCreate_); ok { if db, err = hook.BeforeCreate_(ctx, db); err != nil { return nil, err } } if err = db.Create(&ormObj).Error; err != nil { return nil, err } if hook, ok := interface{}(&ormObj).(IntPointORMWithAfterCreate_); ok { if err = hook.AfterCreate_(ctx, db); err != nil { return nil, err } } pbResponse, err := ormObj.ToPB(ctx) return &pbResponse, err } type IntPointORMWithBeforeCreate_ interface { BeforeCreate_(context.Context, *gorm.DB) (*gorm.DB, error) } type IntPointORMWithAfterCreate_ interface { AfterCreate_(context.Context, *gorm.DB) error } func DefaultReadIntPoint(ctx context.Context, in *IntPoint, db *gorm.DB, fs *query.FieldSelection) (*IntPoint, error) { if in == nil { return nil, errors.NilArgumentError } ormObj, err := in.ToORM(ctx) if err != nil { return nil, err } if ormObj.Id == 0 { return nil, errors.EmptyIdError } if hook, ok := interface{}(&ormObj).(IntPointORMWithBeforeReadApplyQuery); ok { if db, err = hook.BeforeReadApplyQuery(ctx, db, fs); err != nil { return nil, err } } if db, err = gorm1.ApplyFieldSelection(ctx, db, fs, &IntPointORM{}); err != nil { return nil, err } if hook, ok := interface{}(&ormObj).(IntPointORMWithBeforeReadFind); ok { if db, err = hook.BeforeReadFind(ctx, db, fs); err != nil { return nil, err } } ormResponse := IntPointORM{} if err = db.Where(&ormObj).First(&ormResponse).Error; err != nil { return nil, err } if hook, ok := interface{}(&ormResponse).(IntPointORMWithAfterReadFind); ok { if err = hook.AfterReadFind(ctx, db, fs); err != nil { return nil, err } } pbResponse, err := ormResponse.ToPB(ctx) return &pbResponse, err } type IntPointORMWithBeforeReadApplyQuery interface { BeforeReadApplyQuery(context.Context, *gorm.DB, *query.FieldSelection) (*gorm.DB, error) } type IntPointORMWithBeforeReadFind interface { BeforeReadFind(context.Context, *gorm.DB, *query.FieldSelection) (*gorm.DB, error) } type IntPointORMWithAfterReadFind interface { AfterReadFind(context.Context, *gorm.DB, *query.FieldSelection) error } func DefaultDeleteIntPoint(ctx context.Context, in *IntPoint, db *gorm.DB) error { if in == nil { return errors.NilArgumentError } ormObj, err := in.ToORM(ctx) if err != nil { return err } if ormObj.Id == 0 { return errors.EmptyIdError } if hook, ok := interface{}(&ormObj).(IntPointORMWithBeforeDelete_); ok { if db, err = hook.BeforeDelete_(ctx, db); err != nil { return err } } err = db.Where(&ormObj).Delete(&IntPointORM{}).Error if err != nil { return err } if hook, ok := interface{}(&ormObj).(IntPointORMWithAfterDelete_); ok { err = hook.AfterDelete_(ctx, db) } return err } type IntPointORMWithBeforeDelete_ interface { BeforeDelete_(context.Context, *gorm.DB) (*gorm.DB, error) } type IntPointORMWithAfterDelete_ interface { AfterDelete_(context.Context, *gorm.DB) error } func DefaultDeleteIntPointSet(ctx context.Context, in []*IntPoint, db *gorm.DB) error { if in == nil { return errors.NilArgumentError } var err error keys := []uint32{} for _, obj := range in { ormObj, err := obj.ToORM(ctx) if err != nil { return err } if ormObj.Id == 0 { return errors.EmptyIdError } keys = append(keys, ormObj.Id) } if hook, ok := (interface{}(&IntPointORM{})).(IntPointORMWithBeforeDeleteSet); ok { if db, err = hook.BeforeDeleteSet(ctx, in, db); err != nil { return err } } err = db.Where("id in (?)", keys).Delete(&IntPointORM{}).Error if err != nil { return err } if hook, ok := (interface{}(&IntPointORM{})).(IntPointORMWithAfterDeleteSet); ok { err = hook.AfterDeleteSet(ctx, in, db) } return err } type IntPointORMWithBeforeDeleteSet interface { BeforeDeleteSet(context.Context, []*IntPoint, *gorm.DB) (*gorm.DB, error) } type IntPointORMWithAfterDeleteSet interface { AfterDeleteSet(context.Context, []*IntPoint, *gorm.DB) error } // DefaultStrictUpdateIntPoint clears / replaces / appends first level 1:many children and then executes a gorm update call func DefaultStrictUpdateIntPoint(ctx context.Context, in *IntPoint, db *gorm.DB) (*IntPoint, error) { if in == nil { return nil, fmt.Errorf("Nil argument to DefaultStrictUpdateIntPoint") } ormObj, err := in.ToORM(ctx) if err != nil { return nil, err } lockedRow := &IntPointORM{} db.Model(&ormObj).Set("gorm:query_option", "FOR UPDATE").Where("id=?", ormObj.Id).First(lockedRow) if hook, ok := interface{}(&ormObj).(IntPointORMWithBeforeStrictUpdateCleanup); ok { if db, err = hook.BeforeStrictUpdateCleanup(ctx, db); err != nil { return nil, err } } if hook, ok := interface{}(&ormObj).(IntPointORMWithBeforeStrictUpdateSave); ok { if db, err = hook.BeforeStrictUpdateSave(ctx, db); err != nil { return nil, err } } if err = db.Save(&ormObj).Error; err != nil { return nil, err } if hook, ok := interface{}(&ormObj).(IntPointORMWithAfterStrictUpdateSave); ok { if err = hook.AfterStrictUpdateSave(ctx, db); err != nil { return nil, err } } pbResponse, err := ormObj.ToPB(ctx) if err != nil { return nil, err } return &pbResponse, err } type IntPointORMWithBeforeStrictUpdateCleanup interface { BeforeStrictUpdateCleanup(context.Context, *gorm.DB) (*gorm.DB, error) } type IntPointORMWithBeforeStrictUpdateSave interface { BeforeStrictUpdateSave(context.Context, *gorm.DB) (*gorm.DB, error) } type IntPointORMWithAfterStrictUpdateSave interface { AfterStrictUpdateSave(context.Context, *gorm.DB) error } // DefaultPatchIntPoint executes a basic gorm update call with patch behavior func DefaultPatchIntPoint(ctx context.Context, in *IntPoint, updateMask *field_mask.FieldMask, db *gorm.DB) (*IntPoint, error) { if in == nil { return nil, errors.NilArgumentError } var pbObj IntPoint var err error if hook, ok := interface{}(&pbObj).(IntPointWithBeforePatchRead); ok { if db, err = hook.BeforePatchRead(ctx, in, updateMask, db); err != nil { return nil, err } } pbReadRes, err := DefaultReadIntPoint(ctx, &IntPoint{Id: in.GetId()}, db, nil) if err != nil { return nil, err } pbObj = *pbReadRes if hook, ok := interface{}(&pbObj).(IntPointWithBeforePatchApplyFieldMask); ok { if db, err = hook.BeforePatchApplyFieldMask(ctx, in, updateMask, db); err != nil { return nil, err } } if _, err := DefaultApplyFieldMaskIntPoint(ctx, &pbObj, in, updateMask, "", db); err != nil { return nil, err } if hook, ok := interface{}(&pbObj).(IntPointWithBeforePatchSave); ok { if db, err = hook.BeforePatchSave(ctx, in, updateMask, db); err != nil { return nil, err } } pbResponse, err := DefaultStrictUpdateIntPoint(ctx, &pbObj, db) if err != nil { return nil, err } if hook, ok := interface{}(pbResponse).(IntPointWithAfterPatchSave); ok { if err = hook.AfterPatchSave(ctx, in, updateMask, db); err != nil { return nil, err } } return pbResponse, nil } type IntPointWithBeforePatchRead interface { BeforePatchRead(context.Context, *IntPoint, *field_mask.FieldMask, *gorm.DB) (*gorm.DB, error) } type IntPointWithBeforePatchApplyFieldMask interface { BeforePatchApplyFieldMask(context.Context, *IntPoint, *field_mask.FieldMask, *gorm.DB) (*gorm.DB, error) } type IntPointWithBeforePatchSave interface { BeforePatchSave(context.Context, *IntPoint, *field_mask.FieldMask, *gorm.DB) (*gorm.DB, error) } type IntPointWithAfterPatchSave interface { AfterPatchSave(context.Context, *IntPoint, *field_mask.FieldMask, *gorm.DB) error } // DefaultPatchSetIntPoint executes a bulk gorm update call with patch behavior func DefaultPatchSetIntPoint(ctx context.Context, objects []*IntPoint, updateMasks []*field_mask.FieldMask, db *gorm.DB) ([]*IntPoint, error) { if len(objects) != len(updateMasks) { return nil, fmt.Errorf(errors.BadRepeatedFieldMaskTpl, len(updateMasks), len(objects)) } results := make([]*IntPoint, 0, len(objects)) for i, patcher := range objects { pbResponse, err := DefaultPatchIntPoint(ctx, patcher, updateMasks[i], db) if err != nil { return nil, err } results = append(results, pbResponse) } return results, nil } // DefaultApplyFieldMaskIntPoint patches an pbObject with patcher according to a field mask. func DefaultApplyFieldMaskIntPoint(ctx context.Context, patchee *IntPoint, patcher *IntPoint, updateMask *field_mask.FieldMask, prefix string, db *gorm.DB) (*IntPoint, error) { if patcher == nil { return nil, nil } else if patchee == nil { return nil, errors.NilArgumentError } var err error for _, f := range updateMask.Paths { if f == prefix+"Id" { patchee.Id = patcher.Id continue } if f == prefix+"X" { patchee.X = patcher.X continue } if f == prefix+"Y" { patchee.Y = patcher.Y continue } } if err != nil { return nil, err } return patchee, nil } // DefaultListIntPoint executes a gorm list call func DefaultListIntPoint(ctx context.Context, db *gorm.DB) ([]*IntPoint, error) { in := IntPoint{} ormObj, err := in.ToORM(ctx) if err != nil { return nil, err } if hook, ok := interface{}(&ormObj).(IntPointORMWithBeforeListApplyQuery); ok { if db, err = hook.BeforeListApplyQuery(ctx, db); err != nil { return nil, err } } db, err = gorm1.ApplyCollectionOperators(ctx, db, &IntPointORM{}, &IntPoint{}, nil, nil, nil, nil) if err != nil { return nil, err } if hook, ok := interface{}(&ormObj).(IntPointORMWithBeforeListFind); ok { if db, err = hook.BeforeListFind(ctx, db); err != nil { return nil, err } } db = db.Where(&ormObj) db = db.Order("id") ormResponse := []IntPointORM{} if err := db.Find(&ormResponse).Error; err != nil { return nil, err } if hook, ok := interface{}(&ormObj).(IntPointORMWithAfterListFind); ok { if err = hook.AfterListFind(ctx, db, &ormResponse); err != nil { return nil, err } } pbResponse := []*IntPoint{} for _, responseEntry := range ormResponse { temp, err := responseEntry.ToPB(ctx) if err != nil { return nil, err } pbResponse = append(pbResponse, &temp) } return pbResponse, nil } type IntPointORMWithBeforeListApplyQuery interface { BeforeListApplyQuery(context.Context, *gorm.DB) (*gorm.DB, error) } type IntPointORMWithBeforeListFind interface { BeforeListFind(context.Context, *gorm.DB) (*gorm.DB, error) } type IntPointORMWithAfterListFind interface { AfterListFind(context.Context, *gorm.DB, *[]IntPointORM) error } type IntPointServiceDefaultServer struct { DB *gorm.DB } // Create ... func (m *IntPointServiceDefaultServer) Create(ctx context.Context, in *CreateIntPointRequest) (*CreateIntPointResponse, error) { db := m.DB if custom, ok := interface{}(in).(IntPointServiceIntPointWithBeforeCreate); ok { var err error if db, err = custom.BeforeCreate(ctx, db); err != nil { return nil, err } } res, err := DefaultCreateIntPoint(ctx, in.GetPayload(), db) if err != nil { return nil, err } out := &CreateIntPointResponse{Result: res} if custom, ok := interface{}(in).(IntPointServiceIntPointWithAfterCreate); ok { var err error if err = custom.AfterCreate(ctx, out, db); err != nil { return nil, err } } return out, nil } // IntPointServiceIntPointWithBeforeCreate called before DefaultCreateIntPoint in the default Create handler type IntPointServiceIntPointWithBeforeCreate interface { BeforeCreate(context.Context, *gorm.DB) (*gorm.DB, error) } // IntPointServiceIntPointWithAfterCreate called before DefaultCreateIntPoint in the default Create handler type IntPointServiceIntPointWithAfterCreate interface { AfterCreate(context.Context, *CreateIntPointResponse, *gorm.DB) error } // Read ... func (m *IntPointServiceDefaultServer) Read(ctx context.Context, in *ReadIntPointRequest) (*ReadIntPointResponse, error) { db := m.DB if custom, ok := interface{}(in).(IntPointServiceIntPointWithBeforeRead); ok { var err error if db, err = custom.BeforeRead(ctx, db); err != nil { return nil, err } } res, err := DefaultReadIntPoint(ctx, &IntPoint{Id: in.GetId()}, db, in.Fields) if err != nil { return nil, err } out := &ReadIntPointResponse{Result: res} if custom, ok := interface{}(in).(IntPointServiceIntPointWithAfterRead); ok { var err error if err = custom.AfterRead(ctx, out, db); err != nil { return nil, err } } return out, nil } // IntPointServiceIntPointWithBeforeRead called before DefaultReadIntPoint in the default Read handler type IntPointServiceIntPointWithBeforeRead interface { BeforeRead(context.Context, *gorm.DB) (*gorm.DB, error) } // IntPointServiceIntPointWithAfterRead called before DefaultReadIntPoint in the default Read handler type IntPointServiceIntPointWithAfterRead interface { AfterRead(context.Context, *ReadIntPointResponse, *gorm.DB) error } // Update ... func (m *IntPointServiceDefaultServer) Update(ctx context.Context, in *UpdateIntPointRequest) (*UpdateIntPointResponse, error) { var err error var res *IntPoint db := m.DB if custom, ok := interface{}(in).(IntPointServiceIntPointWithBeforeUpdate); ok { var err error if db, err = custom.BeforeUpdate(ctx, db); err != nil { return nil, err } } if in.GetGerogeriGegege() == nil { res, err = DefaultStrictUpdateIntPoint(ctx, in.GetPayload(), db) } else { res, err = DefaultPatchIntPoint(ctx, in.GetPayload(), in.GetGerogeriGegege(), db) } if err != nil { return nil, err } out := &UpdateIntPointResponse{Result: res} if custom, ok := interface{}(in).(IntPointServiceIntPointWithAfterUpdate); ok { var err error if err = custom.AfterUpdate(ctx, out, db); err != nil { return nil, err } } return out, nil } // IntPointServiceIntPointWithBeforeUpdate called before DefaultUpdateIntPoint in the default Update handler type IntPointServiceIntPointWithBeforeUpdate interface { BeforeUpdate(context.Context, *gorm.DB) (*gorm.DB, error) } // IntPointServiceIntPointWithAfterUpdate called before DefaultUpdateIntPoint in the default Update handler type IntPointServiceIntPointWithAfterUpdate interface { AfterUpdate(context.Context, *UpdateIntPointResponse, *gorm.DB) error } // UpdateSet ... func (m *IntPointServiceDefaultServer) UpdateSet(ctx context.Context, in *UpdateSetIntPointRequest) (*UpdateSetIntPointResponse, error) { if in == nil { return nil, errors.NilArgumentError } db := m.DB if custom, ok := interface{}(in).(IntPointServiceIntPointWithBeforeUpdateSet); ok { var err error if db, err = custom.BeforeUpdateSet(ctx, db); err != nil { return nil, err } } res, err := DefaultPatchSetIntPoint(ctx, in.GetObjects(), in.GetMasks(), db) if err != nil { return nil, err } out := &UpdateSetIntPointResponse{Results: res} if custom, ok := interface{}(in).(IntPointServiceIntPointWithAfterUpdateSet); ok { var err error if err = custom.AfterUpdateSet(ctx, out, db); err != nil { return nil, err } } return out, nil } // IntPointServiceIntPointWithBeforeUpdateSet called before DefaultUpdateSetIntPoint in the default UpdateSet handler type IntPointServiceIntPointWithBeforeUpdateSet interface { BeforeUpdateSet(context.Context, *gorm.DB) (*gorm.DB, error) } // IntPointServiceIntPointWithAfterUpdateSet called before DefaultUpdateSetIntPoint in the default UpdateSet handler type IntPointServiceIntPointWithAfterUpdateSet interface { AfterUpdateSet(context.Context, *UpdateSetIntPointResponse, *gorm.DB) error } // Delete ... func (m *IntPointServiceDefaultServer) Delete(ctx context.Context, in *DeleteIntPointRequest) (*DeleteIntPointResponse, error) { db := m.DB if custom, ok := interface{}(in).(IntPointServiceIntPointWithBeforeDelete); ok { var err error if db, err = custom.BeforeDelete(ctx, db); err != nil { return nil, err } } err := DefaultDeleteIntPoint(ctx, &IntPoint{Id: in.GetId()}, db) if err != nil { return nil, err } out := &DeleteIntPointResponse{} if custom, ok := interface{}(in).(IntPointServiceIntPointWithAfterDelete); ok { var err error if err = custom.AfterDelete(ctx, out, db); err != nil { return nil, err } } return out, nil } // IntPointServiceIntPointWithBeforeDelete called before DefaultDeleteIntPoint in the default Delete handler type IntPointServiceIntPointWithBeforeDelete interface { BeforeDelete(context.Context, *gorm.DB) (*gorm.DB, error) } // IntPointServiceIntPointWithAfterDelete called before DefaultDeleteIntPoint in the default Delete handler type IntPointServiceIntPointWithAfterDelete interface { AfterDelete(context.Context, *DeleteIntPointResponse, *gorm.DB) error } type IntPointTxnDefaultServer struct { } func (m *IntPointTxnDefaultServer) spanCreate(ctx context.Context, in interface{}, methodName string) (*trace.Span, error) { _, span := trace.StartSpan(ctx, fmt.Sprint("IntPointTxnDefaultServer.", methodName)) raw, err := json.Marshal(in) if err != nil { return nil, err } span.Annotate([]trace.Attribute{trace.StringAttribute("in", string(raw))}, "in parameter") return span, nil } // spanError ... func (m *IntPointTxnDefaultServer) spanError(span *trace.Span, err error) error { span.SetStatus(trace.Status{ Code: trace.StatusCodeUnknown, Message: err.Error(), }) return err } // spanResult ... func (m *IntPointTxnDefaultServer) spanResult(span *trace.Span, out interface{}) error { raw, err := json.Marshal(out) if err != nil { return err } span.Annotate([]trace.Attribute{trace.StringAttribute("out", string(raw))}, "out parameter") return nil } // Create ... func (m *IntPointTxnDefaultServer) Create(ctx context.Context, in *CreateIntPointRequest) (*CreateIntPointResponse, error) { span, errSpanCreate := m.spanCreate(ctx, in, "Create") if errSpanCreate != nil { return nil, errSpanCreate } defer span.End() txn, ok := gorm1.FromContext(ctx) if !ok { return nil, errors.NoTransactionError } db := txn.Begin() if db.Error != nil { return nil, db.Error } if custom, ok := interface{}(in).(IntPointTxnIntPointWithBeforeCreate); ok { var err error if db, err = custom.BeforeCreate(ctx, db); err != nil { return nil, m.spanError(span, err) } } res, err := DefaultCreateIntPoint(ctx, in.GetPayload(), db) if err != nil { return nil, m.spanError(span, err) } out := &CreateIntPointResponse{Result: res} if custom, ok := interface{}(in).(IntPointTxnIntPointWithAfterCreate); ok { var err error if err = custom.AfterCreate(ctx, out, db); err != nil { return nil, m.spanError(span, err) } } errSpanResult := m.spanResult(span, out) if errSpanResult != nil { return nil, m.spanError(span, errSpanResult) } return out, nil } // IntPointTxnIntPointWithBeforeCreate called before DefaultCreateIntPoint in the default Create handler type IntPointTxnIntPointWithBeforeCreate interface { BeforeCreate(context.Context, *gorm.DB) (*gorm.DB, error) } // IntPointTxnIntPointWithAfterCreate called before DefaultCreateIntPoint in the default Create handler type IntPointTxnIntPointWithAfterCreate interface { AfterCreate(context.Context, *CreateIntPointResponse, *gorm.DB) error } // Read ... func (m *IntPointTxnDefaultServer) Read(ctx context.Context, in *ReadIntPointRequest) (*ReadIntPointResponse, error) { span, errSpanCreate := m.spanCreate(ctx, in, "Read") if errSpanCreate != nil { return nil, errSpanCreate } defer span.End() txn, ok := gorm1.FromContext(ctx) if !ok { return nil, errors.NoTransactionError } db := txn.Begin() if db.Error != nil { return nil, db.Error } if custom, ok := interface{}(in).(IntPointTxnIntPointWithBeforeRead); ok { var err error if db, err = custom.BeforeRead(ctx, db); err != nil { return nil, m.spanError(span, err) } } res, err := DefaultReadIntPoint(ctx, &IntPoint{Id: in.GetId()}, db, in.Fields) if err != nil { return nil, m.spanError(span, err) } out := &ReadIntPointResponse{Result: res} if custom, ok := interface{}(in).(IntPointTxnIntPointWithAfterRead); ok { var err error if err = custom.AfterRead(ctx, out, db); err != nil { return nil, m.spanError(span, err) } } errSpanResult := m.spanResult(span, out) if errSpanResult != nil { return nil, m.spanError(span, errSpanResult) } return out, nil } // IntPointTxnIntPointWithBeforeRead called before DefaultReadIntPoint in the default Read handler type IntPointTxnIntPointWithBeforeRead interface { BeforeRead(context.Context, *gorm.DB) (*gorm.DB, error) } // IntPointTxnIntPointWithAfterRead called before DefaultReadIntPoint in the default Read handler type IntPointTxnIntPointWithAfterRead interface { AfterRead(context.Context, *ReadIntPointResponse, *gorm.DB) error } // Update ... func (m *IntPointTxnDefaultServer) Update(ctx context.Context, in *UpdateIntPointRequest) (*UpdateIntPointResponse, error) { span, errSpanCreate := m.spanCreate(ctx, in, "Update") if errSpanCreate != nil { return nil, errSpanCreate } defer span.End() var err error var res *IntPoint txn, ok := gorm1.FromContext(ctx) if !ok { return nil, errors.NoTransactionError } db := txn.Begin() if db.Error != nil { return nil, db.Error } if custom, ok := interface{}(in).(IntPointTxnIntPointWithBeforeUpdate); ok { var err error if db, err = custom.BeforeUpdate(ctx, db); err != nil { return nil, m.spanError(span, err) } } if in.GetGerogeriGegege() == nil { res, err = DefaultStrictUpdateIntPoint(ctx, in.GetPayload(), db) } else { res, err = DefaultPatchIntPoint(ctx, in.GetPayload(), in.GetGerogeriGegege(), db) } if err != nil { return nil, m.spanError(span, err) } out := &UpdateIntPointResponse{Result: res} if custom, ok := interface{}(in).(IntPointTxnIntPointWithAfterUpdate); ok { var err error if err = custom.AfterUpdate(ctx, out, db); err != nil { return nil, m.spanError(span, err) } } errSpanResult := m.spanResult(span, out) if errSpanResult != nil { return nil, m.spanError(span, errSpanResult) } return out, nil } // IntPointTxnIntPointWithBeforeUpdate called before DefaultUpdateIntPoint in the default Update handler type IntPointTxnIntPointWithBeforeUpdate interface { BeforeUpdate(context.Context, *gorm.DB) (*gorm.DB, error) } // IntPointTxnIntPointWithAfterUpdate called before DefaultUpdateIntPoint in the default Update handler type IntPointTxnIntPointWithAfterUpdate interface { AfterUpdate(context.Context, *UpdateIntPointResponse, *gorm.DB) error } // Delete ... func (m *IntPointTxnDefaultServer) Delete(ctx context.Context, in *DeleteIntPointRequest) (*DeleteIntPointResponse, error) { span, errSpanCreate := m.spanCreate(ctx, in, "Delete") if errSpanCreate != nil { return nil, errSpanCreate } defer span.End() txn, ok := gorm1.FromContext(ctx) if !ok { return nil, errors.NoTransactionError } db := txn.Begin() if db.Error != nil { return nil, db.Error } if custom, ok := interface{}(in).(IntPointTxnIntPointWithBeforeDelete); ok { var err error if db, err = custom.BeforeDelete(ctx, db); err != nil { return nil, m.spanError(span, err) } } err := DefaultDeleteIntPoint(ctx, &IntPoint{Id: in.GetId()}, db) if err != nil { return nil, m.spanError(span, err) } out := &DeleteIntPointResponse{} if custom, ok := interface{}(in).(IntPointTxnIntPointWithAfterDelete); ok { var err error if err = custom.AfterDelete(ctx, out, db); err != nil { return nil, m.spanError(span, err) } } errSpanResult := m.spanResult(span, out) if errSpanResult != nil { return nil, m.spanError(span, errSpanResult) } return out, nil } // IntPointTxnIntPointWithBeforeDelete called before DefaultDeleteIntPoint in the default Delete handler type IntPointTxnIntPointWithBeforeDelete interface { BeforeDelete(context.Context, *gorm.DB) (*gorm.DB, error) } // IntPointTxnIntPointWithAfterDelete called before DefaultDeleteIntPoint in the default Delete handler type IntPointTxnIntPointWithAfterDelete interface { AfterDelete(context.Context, *DeleteIntPointResponse, *gorm.DB) error } // DeleteSet ... func (m *IntPointTxnDefaultServer) DeleteSet(ctx context.Context, in *DeleteIntPointsRequest) (*DeleteIntPointResponse, error) { span, errSpanCreate := m.spanCreate(ctx, in, "DeleteSet") if errSpanCreate != nil { return nil, errSpanCreate } defer span.End() txn, ok := gorm1.FromContext(ctx) if !ok { return nil, errors.NoTransactionError } db := txn.Begin() if db.Error != nil { return nil, db.Error } objs := []*IntPoint{} for _, id := range in.Ids { objs = append(objs, &IntPoint{Id: id}) } if custom, ok := interface{}(in).(IntPointTxnIntPointWithBeforeDeleteSet); ok { var err error if db, err = custom.BeforeDeleteSet(ctx, db); err != nil { return nil, m.spanError(span, err) } } err := DefaultDeleteIntPointSet(ctx, objs, db) if err != nil { return nil, m.spanError(span, err) } out := &DeleteIntPointResponse{} if custom, ok := interface{}(in).(IntPointTxnIntPointWithAfterDeleteSet); ok { var err error if err = custom.AfterDeleteSet(ctx, out, db); err != nil { return nil, m.spanError(span, err) } } errSpanResult := m.spanResult(span, out) if errSpanResult != nil { return nil, m.spanError(span, errSpanResult) } return out, nil } // IntPointTxnIntPointWithBeforeDeleteSet called before DefaultDeleteSetIntPoint in the default DeleteSet handler type IntPointTxnIntPointWithBeforeDeleteSet interface { BeforeDeleteSet(context.Context, *gorm.DB) (*gorm.DB, error) } // IntPointTxnIntPointWithAfterDeleteSet called before DefaultDeleteSetIntPoint in the default DeleteSet handler type IntPointTxnIntPointWithAfterDeleteSet interface { AfterDeleteSet(context.Context, *DeleteIntPointResponse, *gorm.DB) error }