123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907 |
- 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
- }
|