proto-gorm.pb.gorm.go 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907
  1. package proto_gorm
  2. import (
  3. context "context"
  4. json "encoding/json"
  5. fmt "fmt"
  6. gorm1 "github.com/infobloxopen/atlas-app-toolkit/gorm"
  7. query "github.com/infobloxopen/atlas-app-toolkit/query"
  8. errors "github.com/infobloxopen/protoc-gen-gorm/errors"
  9. gorm "github.com/jinzhu/gorm"
  10. trace "go.opencensus.io/trace"
  11. field_mask "google.golang.org/genproto/protobuf/field_mask"
  12. )
  13. type IntPointORM struct {
  14. Id uint32
  15. X int32
  16. Y int32
  17. }
  18. // TableName overrides the default tablename generated by GORM
  19. func (IntPointORM) TableName() string {
  20. return "int_points"
  21. }
  22. // ToORM runs the BeforeToORM hook if present, converts the fields of this
  23. // object to ORM format, runs the AfterToORM hook, then returns the ORM object
  24. func (m *IntPoint) ToORM(ctx context.Context) (IntPointORM, error) {
  25. to := IntPointORM{}
  26. var err error
  27. if prehook, ok := interface{}(m).(IntPointWithBeforeToORM); ok {
  28. if err = prehook.BeforeToORM(ctx, &to); err != nil {
  29. return to, err
  30. }
  31. }
  32. to.Id = m.Id
  33. to.X = m.X
  34. to.Y = m.Y
  35. if posthook, ok := interface{}(m).(IntPointWithAfterToORM); ok {
  36. err = posthook.AfterToORM(ctx, &to)
  37. }
  38. return to, err
  39. }
  40. // ToPB runs the BeforeToPB hook if present, converts the fields of this
  41. // object to PB format, runs the AfterToPB hook, then returns the PB object
  42. func (m *IntPointORM) ToPB(ctx context.Context) (IntPoint, error) {
  43. to := IntPoint{}
  44. var err error
  45. if prehook, ok := interface{}(m).(IntPointWithBeforeToPB); ok {
  46. if err = prehook.BeforeToPB(ctx, &to); err != nil {
  47. return to, err
  48. }
  49. }
  50. to.Id = m.Id
  51. to.X = m.X
  52. to.Y = m.Y
  53. if posthook, ok := interface{}(m).(IntPointWithAfterToPB); ok {
  54. err = posthook.AfterToPB(ctx, &to)
  55. }
  56. return to, err
  57. }
  58. // The following are interfaces you can implement for special behavior during ORM/PB conversions
  59. // of type IntPoint the arg will be the target, the caller the one being converted from
  60. // IntPointBeforeToORM called before default ToORM code
  61. type IntPointWithBeforeToORM interface {
  62. BeforeToORM(context.Context, *IntPointORM) error
  63. }
  64. // IntPointAfterToORM called after default ToORM code
  65. type IntPointWithAfterToORM interface {
  66. AfterToORM(context.Context, *IntPointORM) error
  67. }
  68. // IntPointBeforeToPB called before default ToPB code
  69. type IntPointWithBeforeToPB interface {
  70. BeforeToPB(context.Context, *IntPoint) error
  71. }
  72. // IntPointAfterToPB called after default ToPB code
  73. type IntPointWithAfterToPB interface {
  74. AfterToPB(context.Context, *IntPoint) error
  75. }
  76. // DefaultCreateIntPoint executes a basic gorm create call
  77. func DefaultCreateIntPoint(ctx context.Context, in *IntPoint, db *gorm.DB) (*IntPoint, error) {
  78. if in == nil {
  79. return nil, errors.NilArgumentError
  80. }
  81. ormObj, err := in.ToORM(ctx)
  82. if err != nil {
  83. return nil, err
  84. }
  85. if hook, ok := interface{}(&ormObj).(IntPointORMWithBeforeCreate_); ok {
  86. if db, err = hook.BeforeCreate_(ctx, db); err != nil {
  87. return nil, err
  88. }
  89. }
  90. if err = db.Create(&ormObj).Error; err != nil {
  91. return nil, err
  92. }
  93. if hook, ok := interface{}(&ormObj).(IntPointORMWithAfterCreate_); ok {
  94. if err = hook.AfterCreate_(ctx, db); err != nil {
  95. return nil, err
  96. }
  97. }
  98. pbResponse, err := ormObj.ToPB(ctx)
  99. return &pbResponse, err
  100. }
  101. type IntPointORMWithBeforeCreate_ interface {
  102. BeforeCreate_(context.Context, *gorm.DB) (*gorm.DB, error)
  103. }
  104. type IntPointORMWithAfterCreate_ interface {
  105. AfterCreate_(context.Context, *gorm.DB) error
  106. }
  107. func DefaultReadIntPoint(ctx context.Context, in *IntPoint, db *gorm.DB, fs *query.FieldSelection) (*IntPoint, error) {
  108. if in == nil {
  109. return nil, errors.NilArgumentError
  110. }
  111. ormObj, err := in.ToORM(ctx)
  112. if err != nil {
  113. return nil, err
  114. }
  115. if ormObj.Id == 0 {
  116. return nil, errors.EmptyIdError
  117. }
  118. if hook, ok := interface{}(&ormObj).(IntPointORMWithBeforeReadApplyQuery); ok {
  119. if db, err = hook.BeforeReadApplyQuery(ctx, db, fs); err != nil {
  120. return nil, err
  121. }
  122. }
  123. if db, err = gorm1.ApplyFieldSelection(ctx, db, fs, &IntPointORM{}); err != nil {
  124. return nil, err
  125. }
  126. if hook, ok := interface{}(&ormObj).(IntPointORMWithBeforeReadFind); ok {
  127. if db, err = hook.BeforeReadFind(ctx, db, fs); err != nil {
  128. return nil, err
  129. }
  130. }
  131. ormResponse := IntPointORM{}
  132. if err = db.Where(&ormObj).First(&ormResponse).Error; err != nil {
  133. return nil, err
  134. }
  135. if hook, ok := interface{}(&ormResponse).(IntPointORMWithAfterReadFind); ok {
  136. if err = hook.AfterReadFind(ctx, db, fs); err != nil {
  137. return nil, err
  138. }
  139. }
  140. pbResponse, err := ormResponse.ToPB(ctx)
  141. return &pbResponse, err
  142. }
  143. type IntPointORMWithBeforeReadApplyQuery interface {
  144. BeforeReadApplyQuery(context.Context, *gorm.DB, *query.FieldSelection) (*gorm.DB, error)
  145. }
  146. type IntPointORMWithBeforeReadFind interface {
  147. BeforeReadFind(context.Context, *gorm.DB, *query.FieldSelection) (*gorm.DB, error)
  148. }
  149. type IntPointORMWithAfterReadFind interface {
  150. AfterReadFind(context.Context, *gorm.DB, *query.FieldSelection) error
  151. }
  152. func DefaultDeleteIntPoint(ctx context.Context, in *IntPoint, db *gorm.DB) error {
  153. if in == nil {
  154. return errors.NilArgumentError
  155. }
  156. ormObj, err := in.ToORM(ctx)
  157. if err != nil {
  158. return err
  159. }
  160. if ormObj.Id == 0 {
  161. return errors.EmptyIdError
  162. }
  163. if hook, ok := interface{}(&ormObj).(IntPointORMWithBeforeDelete_); ok {
  164. if db, err = hook.BeforeDelete_(ctx, db); err != nil {
  165. return err
  166. }
  167. }
  168. err = db.Where(&ormObj).Delete(&IntPointORM{}).Error
  169. if err != nil {
  170. return err
  171. }
  172. if hook, ok := interface{}(&ormObj).(IntPointORMWithAfterDelete_); ok {
  173. err = hook.AfterDelete_(ctx, db)
  174. }
  175. return err
  176. }
  177. type IntPointORMWithBeforeDelete_ interface {
  178. BeforeDelete_(context.Context, *gorm.DB) (*gorm.DB, error)
  179. }
  180. type IntPointORMWithAfterDelete_ interface {
  181. AfterDelete_(context.Context, *gorm.DB) error
  182. }
  183. func DefaultDeleteIntPointSet(ctx context.Context, in []*IntPoint, db *gorm.DB) error {
  184. if in == nil {
  185. return errors.NilArgumentError
  186. }
  187. var err error
  188. keys := []uint32{}
  189. for _, obj := range in {
  190. ormObj, err := obj.ToORM(ctx)
  191. if err != nil {
  192. return err
  193. }
  194. if ormObj.Id == 0 {
  195. return errors.EmptyIdError
  196. }
  197. keys = append(keys, ormObj.Id)
  198. }
  199. if hook, ok := (interface{}(&IntPointORM{})).(IntPointORMWithBeforeDeleteSet); ok {
  200. if db, err = hook.BeforeDeleteSet(ctx, in, db); err != nil {
  201. return err
  202. }
  203. }
  204. err = db.Where("id in (?)", keys).Delete(&IntPointORM{}).Error
  205. if err != nil {
  206. return err
  207. }
  208. if hook, ok := (interface{}(&IntPointORM{})).(IntPointORMWithAfterDeleteSet); ok {
  209. err = hook.AfterDeleteSet(ctx, in, db)
  210. }
  211. return err
  212. }
  213. type IntPointORMWithBeforeDeleteSet interface {
  214. BeforeDeleteSet(context.Context, []*IntPoint, *gorm.DB) (*gorm.DB, error)
  215. }
  216. type IntPointORMWithAfterDeleteSet interface {
  217. AfterDeleteSet(context.Context, []*IntPoint, *gorm.DB) error
  218. }
  219. // DefaultStrictUpdateIntPoint clears / replaces / appends first level 1:many children and then executes a gorm update call
  220. func DefaultStrictUpdateIntPoint(ctx context.Context, in *IntPoint, db *gorm.DB) (*IntPoint, error) {
  221. if in == nil {
  222. return nil, fmt.Errorf("Nil argument to DefaultStrictUpdateIntPoint")
  223. }
  224. ormObj, err := in.ToORM(ctx)
  225. if err != nil {
  226. return nil, err
  227. }
  228. lockedRow := &IntPointORM{}
  229. db.Model(&ormObj).Set("gorm:query_option", "FOR UPDATE").Where("id=?", ormObj.Id).First(lockedRow)
  230. if hook, ok := interface{}(&ormObj).(IntPointORMWithBeforeStrictUpdateCleanup); ok {
  231. if db, err = hook.BeforeStrictUpdateCleanup(ctx, db); err != nil {
  232. return nil, err
  233. }
  234. }
  235. if hook, ok := interface{}(&ormObj).(IntPointORMWithBeforeStrictUpdateSave); ok {
  236. if db, err = hook.BeforeStrictUpdateSave(ctx, db); err != nil {
  237. return nil, err
  238. }
  239. }
  240. if err = db.Save(&ormObj).Error; err != nil {
  241. return nil, err
  242. }
  243. if hook, ok := interface{}(&ormObj).(IntPointORMWithAfterStrictUpdateSave); ok {
  244. if err = hook.AfterStrictUpdateSave(ctx, db); err != nil {
  245. return nil, err
  246. }
  247. }
  248. pbResponse, err := ormObj.ToPB(ctx)
  249. if err != nil {
  250. return nil, err
  251. }
  252. return &pbResponse, err
  253. }
  254. type IntPointORMWithBeforeStrictUpdateCleanup interface {
  255. BeforeStrictUpdateCleanup(context.Context, *gorm.DB) (*gorm.DB, error)
  256. }
  257. type IntPointORMWithBeforeStrictUpdateSave interface {
  258. BeforeStrictUpdateSave(context.Context, *gorm.DB) (*gorm.DB, error)
  259. }
  260. type IntPointORMWithAfterStrictUpdateSave interface {
  261. AfterStrictUpdateSave(context.Context, *gorm.DB) error
  262. }
  263. // DefaultPatchIntPoint executes a basic gorm update call with patch behavior
  264. func DefaultPatchIntPoint(ctx context.Context, in *IntPoint, updateMask *field_mask.FieldMask, db *gorm.DB) (*IntPoint, error) {
  265. if in == nil {
  266. return nil, errors.NilArgumentError
  267. }
  268. var pbObj IntPoint
  269. var err error
  270. if hook, ok := interface{}(&pbObj).(IntPointWithBeforePatchRead); ok {
  271. if db, err = hook.BeforePatchRead(ctx, in, updateMask, db); err != nil {
  272. return nil, err
  273. }
  274. }
  275. pbReadRes, err := DefaultReadIntPoint(ctx, &IntPoint{Id: in.GetId()}, db, nil)
  276. if err != nil {
  277. return nil, err
  278. }
  279. pbObj = *pbReadRes
  280. if hook, ok := interface{}(&pbObj).(IntPointWithBeforePatchApplyFieldMask); ok {
  281. if db, err = hook.BeforePatchApplyFieldMask(ctx, in, updateMask, db); err != nil {
  282. return nil, err
  283. }
  284. }
  285. if _, err := DefaultApplyFieldMaskIntPoint(ctx, &pbObj, in, updateMask, "", db); err != nil {
  286. return nil, err
  287. }
  288. if hook, ok := interface{}(&pbObj).(IntPointWithBeforePatchSave); ok {
  289. if db, err = hook.BeforePatchSave(ctx, in, updateMask, db); err != nil {
  290. return nil, err
  291. }
  292. }
  293. pbResponse, err := DefaultStrictUpdateIntPoint(ctx, &pbObj, db)
  294. if err != nil {
  295. return nil, err
  296. }
  297. if hook, ok := interface{}(pbResponse).(IntPointWithAfterPatchSave); ok {
  298. if err = hook.AfterPatchSave(ctx, in, updateMask, db); err != nil {
  299. return nil, err
  300. }
  301. }
  302. return pbResponse, nil
  303. }
  304. type IntPointWithBeforePatchRead interface {
  305. BeforePatchRead(context.Context, *IntPoint, *field_mask.FieldMask, *gorm.DB) (*gorm.DB, error)
  306. }
  307. type IntPointWithBeforePatchApplyFieldMask interface {
  308. BeforePatchApplyFieldMask(context.Context, *IntPoint, *field_mask.FieldMask, *gorm.DB) (*gorm.DB, error)
  309. }
  310. type IntPointWithBeforePatchSave interface {
  311. BeforePatchSave(context.Context, *IntPoint, *field_mask.FieldMask, *gorm.DB) (*gorm.DB, error)
  312. }
  313. type IntPointWithAfterPatchSave interface {
  314. AfterPatchSave(context.Context, *IntPoint, *field_mask.FieldMask, *gorm.DB) error
  315. }
  316. // DefaultPatchSetIntPoint executes a bulk gorm update call with patch behavior
  317. func DefaultPatchSetIntPoint(ctx context.Context, objects []*IntPoint, updateMasks []*field_mask.FieldMask, db *gorm.DB) ([]*IntPoint, error) {
  318. if len(objects) != len(updateMasks) {
  319. return nil, fmt.Errorf(errors.BadRepeatedFieldMaskTpl, len(updateMasks), len(objects))
  320. }
  321. results := make([]*IntPoint, 0, len(objects))
  322. for i, patcher := range objects {
  323. pbResponse, err := DefaultPatchIntPoint(ctx, patcher, updateMasks[i], db)
  324. if err != nil {
  325. return nil, err
  326. }
  327. results = append(results, pbResponse)
  328. }
  329. return results, nil
  330. }
  331. // DefaultApplyFieldMaskIntPoint patches an pbObject with patcher according to a field mask.
  332. func DefaultApplyFieldMaskIntPoint(ctx context.Context, patchee *IntPoint, patcher *IntPoint, updateMask *field_mask.FieldMask, prefix string, db *gorm.DB) (*IntPoint, error) {
  333. if patcher == nil {
  334. return nil, nil
  335. } else if patchee == nil {
  336. return nil, errors.NilArgumentError
  337. }
  338. var err error
  339. for _, f := range updateMask.Paths {
  340. if f == prefix+"Id" {
  341. patchee.Id = patcher.Id
  342. continue
  343. }
  344. if f == prefix+"X" {
  345. patchee.X = patcher.X
  346. continue
  347. }
  348. if f == prefix+"Y" {
  349. patchee.Y = patcher.Y
  350. continue
  351. }
  352. }
  353. if err != nil {
  354. return nil, err
  355. }
  356. return patchee, nil
  357. }
  358. // DefaultListIntPoint executes a gorm list call
  359. func DefaultListIntPoint(ctx context.Context, db *gorm.DB) ([]*IntPoint, error) {
  360. in := IntPoint{}
  361. ormObj, err := in.ToORM(ctx)
  362. if err != nil {
  363. return nil, err
  364. }
  365. if hook, ok := interface{}(&ormObj).(IntPointORMWithBeforeListApplyQuery); ok {
  366. if db, err = hook.BeforeListApplyQuery(ctx, db); err != nil {
  367. return nil, err
  368. }
  369. }
  370. db, err = gorm1.ApplyCollectionOperators(ctx, db, &IntPointORM{}, &IntPoint{}, nil, nil, nil, nil)
  371. if err != nil {
  372. return nil, err
  373. }
  374. if hook, ok := interface{}(&ormObj).(IntPointORMWithBeforeListFind); ok {
  375. if db, err = hook.BeforeListFind(ctx, db); err != nil {
  376. return nil, err
  377. }
  378. }
  379. db = db.Where(&ormObj)
  380. db = db.Order("id")
  381. ormResponse := []IntPointORM{}
  382. if err := db.Find(&ormResponse).Error; err != nil {
  383. return nil, err
  384. }
  385. if hook, ok := interface{}(&ormObj).(IntPointORMWithAfterListFind); ok {
  386. if err = hook.AfterListFind(ctx, db, &ormResponse); err != nil {
  387. return nil, err
  388. }
  389. }
  390. pbResponse := []*IntPoint{}
  391. for _, responseEntry := range ormResponse {
  392. temp, err := responseEntry.ToPB(ctx)
  393. if err != nil {
  394. return nil, err
  395. }
  396. pbResponse = append(pbResponse, &temp)
  397. }
  398. return pbResponse, nil
  399. }
  400. type IntPointORMWithBeforeListApplyQuery interface {
  401. BeforeListApplyQuery(context.Context, *gorm.DB) (*gorm.DB, error)
  402. }
  403. type IntPointORMWithBeforeListFind interface {
  404. BeforeListFind(context.Context, *gorm.DB) (*gorm.DB, error)
  405. }
  406. type IntPointORMWithAfterListFind interface {
  407. AfterListFind(context.Context, *gorm.DB, *[]IntPointORM) error
  408. }
  409. type IntPointServiceDefaultServer struct {
  410. DB *gorm.DB
  411. }
  412. // Create ...
  413. func (m *IntPointServiceDefaultServer) Create(ctx context.Context, in *CreateIntPointRequest) (*CreateIntPointResponse, error) {
  414. db := m.DB
  415. if custom, ok := interface{}(in).(IntPointServiceIntPointWithBeforeCreate); ok {
  416. var err error
  417. if db, err = custom.BeforeCreate(ctx, db); err != nil {
  418. return nil, err
  419. }
  420. }
  421. res, err := DefaultCreateIntPoint(ctx, in.GetPayload(), db)
  422. if err != nil {
  423. return nil, err
  424. }
  425. out := &CreateIntPointResponse{Result: res}
  426. if custom, ok := interface{}(in).(IntPointServiceIntPointWithAfterCreate); ok {
  427. var err error
  428. if err = custom.AfterCreate(ctx, out, db); err != nil {
  429. return nil, err
  430. }
  431. }
  432. return out, nil
  433. }
  434. // IntPointServiceIntPointWithBeforeCreate called before DefaultCreateIntPoint in the default Create handler
  435. type IntPointServiceIntPointWithBeforeCreate interface {
  436. BeforeCreate(context.Context, *gorm.DB) (*gorm.DB, error)
  437. }
  438. // IntPointServiceIntPointWithAfterCreate called before DefaultCreateIntPoint in the default Create handler
  439. type IntPointServiceIntPointWithAfterCreate interface {
  440. AfterCreate(context.Context, *CreateIntPointResponse, *gorm.DB) error
  441. }
  442. // Read ...
  443. func (m *IntPointServiceDefaultServer) Read(ctx context.Context, in *ReadIntPointRequest) (*ReadIntPointResponse, error) {
  444. db := m.DB
  445. if custom, ok := interface{}(in).(IntPointServiceIntPointWithBeforeRead); ok {
  446. var err error
  447. if db, err = custom.BeforeRead(ctx, db); err != nil {
  448. return nil, err
  449. }
  450. }
  451. res, err := DefaultReadIntPoint(ctx, &IntPoint{Id: in.GetId()}, db, in.Fields)
  452. if err != nil {
  453. return nil, err
  454. }
  455. out := &ReadIntPointResponse{Result: res}
  456. if custom, ok := interface{}(in).(IntPointServiceIntPointWithAfterRead); ok {
  457. var err error
  458. if err = custom.AfterRead(ctx, out, db); err != nil {
  459. return nil, err
  460. }
  461. }
  462. return out, nil
  463. }
  464. // IntPointServiceIntPointWithBeforeRead called before DefaultReadIntPoint in the default Read handler
  465. type IntPointServiceIntPointWithBeforeRead interface {
  466. BeforeRead(context.Context, *gorm.DB) (*gorm.DB, error)
  467. }
  468. // IntPointServiceIntPointWithAfterRead called before DefaultReadIntPoint in the default Read handler
  469. type IntPointServiceIntPointWithAfterRead interface {
  470. AfterRead(context.Context, *ReadIntPointResponse, *gorm.DB) error
  471. }
  472. // Update ...
  473. func (m *IntPointServiceDefaultServer) Update(ctx context.Context, in *UpdateIntPointRequest) (*UpdateIntPointResponse, error) {
  474. var err error
  475. var res *IntPoint
  476. db := m.DB
  477. if custom, ok := interface{}(in).(IntPointServiceIntPointWithBeforeUpdate); ok {
  478. var err error
  479. if db, err = custom.BeforeUpdate(ctx, db); err != nil {
  480. return nil, err
  481. }
  482. }
  483. if in.GetGerogeriGegege() == nil {
  484. res, err = DefaultStrictUpdateIntPoint(ctx, in.GetPayload(), db)
  485. } else {
  486. res, err = DefaultPatchIntPoint(ctx, in.GetPayload(), in.GetGerogeriGegege(), db)
  487. }
  488. if err != nil {
  489. return nil, err
  490. }
  491. out := &UpdateIntPointResponse{Result: res}
  492. if custom, ok := interface{}(in).(IntPointServiceIntPointWithAfterUpdate); ok {
  493. var err error
  494. if err = custom.AfterUpdate(ctx, out, db); err != nil {
  495. return nil, err
  496. }
  497. }
  498. return out, nil
  499. }
  500. // IntPointServiceIntPointWithBeforeUpdate called before DefaultUpdateIntPoint in the default Update handler
  501. type IntPointServiceIntPointWithBeforeUpdate interface {
  502. BeforeUpdate(context.Context, *gorm.DB) (*gorm.DB, error)
  503. }
  504. // IntPointServiceIntPointWithAfterUpdate called before DefaultUpdateIntPoint in the default Update handler
  505. type IntPointServiceIntPointWithAfterUpdate interface {
  506. AfterUpdate(context.Context, *UpdateIntPointResponse, *gorm.DB) error
  507. }
  508. // UpdateSet ...
  509. func (m *IntPointServiceDefaultServer) UpdateSet(ctx context.Context, in *UpdateSetIntPointRequest) (*UpdateSetIntPointResponse, error) {
  510. if in == nil {
  511. return nil, errors.NilArgumentError
  512. }
  513. db := m.DB
  514. if custom, ok := interface{}(in).(IntPointServiceIntPointWithBeforeUpdateSet); ok {
  515. var err error
  516. if db, err = custom.BeforeUpdateSet(ctx, db); err != nil {
  517. return nil, err
  518. }
  519. }
  520. res, err := DefaultPatchSetIntPoint(ctx, in.GetObjects(), in.GetMasks(), db)
  521. if err != nil {
  522. return nil, err
  523. }
  524. out := &UpdateSetIntPointResponse{Results: res}
  525. if custom, ok := interface{}(in).(IntPointServiceIntPointWithAfterUpdateSet); ok {
  526. var err error
  527. if err = custom.AfterUpdateSet(ctx, out, db); err != nil {
  528. return nil, err
  529. }
  530. }
  531. return out, nil
  532. }
  533. // IntPointServiceIntPointWithBeforeUpdateSet called before DefaultUpdateSetIntPoint in the default UpdateSet handler
  534. type IntPointServiceIntPointWithBeforeUpdateSet interface {
  535. BeforeUpdateSet(context.Context, *gorm.DB) (*gorm.DB, error)
  536. }
  537. // IntPointServiceIntPointWithAfterUpdateSet called before DefaultUpdateSetIntPoint in the default UpdateSet handler
  538. type IntPointServiceIntPointWithAfterUpdateSet interface {
  539. AfterUpdateSet(context.Context, *UpdateSetIntPointResponse, *gorm.DB) error
  540. }
  541. // Delete ...
  542. func (m *IntPointServiceDefaultServer) Delete(ctx context.Context, in *DeleteIntPointRequest) (*DeleteIntPointResponse, error) {
  543. db := m.DB
  544. if custom, ok := interface{}(in).(IntPointServiceIntPointWithBeforeDelete); ok {
  545. var err error
  546. if db, err = custom.BeforeDelete(ctx, db); err != nil {
  547. return nil, err
  548. }
  549. }
  550. err := DefaultDeleteIntPoint(ctx, &IntPoint{Id: in.GetId()}, db)
  551. if err != nil {
  552. return nil, err
  553. }
  554. out := &DeleteIntPointResponse{}
  555. if custom, ok := interface{}(in).(IntPointServiceIntPointWithAfterDelete); ok {
  556. var err error
  557. if err = custom.AfterDelete(ctx, out, db); err != nil {
  558. return nil, err
  559. }
  560. }
  561. return out, nil
  562. }
  563. // IntPointServiceIntPointWithBeforeDelete called before DefaultDeleteIntPoint in the default Delete handler
  564. type IntPointServiceIntPointWithBeforeDelete interface {
  565. BeforeDelete(context.Context, *gorm.DB) (*gorm.DB, error)
  566. }
  567. // IntPointServiceIntPointWithAfterDelete called before DefaultDeleteIntPoint in the default Delete handler
  568. type IntPointServiceIntPointWithAfterDelete interface {
  569. AfterDelete(context.Context, *DeleteIntPointResponse, *gorm.DB) error
  570. }
  571. type IntPointTxnDefaultServer struct {
  572. }
  573. func (m *IntPointTxnDefaultServer) spanCreate(ctx context.Context, in interface{}, methodName string) (*trace.Span, error) {
  574. _, span := trace.StartSpan(ctx, fmt.Sprint("IntPointTxnDefaultServer.", methodName))
  575. raw, err := json.Marshal(in)
  576. if err != nil {
  577. return nil, err
  578. }
  579. span.Annotate([]trace.Attribute{trace.StringAttribute("in", string(raw))}, "in parameter")
  580. return span, nil
  581. }
  582. // spanError ...
  583. func (m *IntPointTxnDefaultServer) spanError(span *trace.Span, err error) error {
  584. span.SetStatus(trace.Status{
  585. Code: trace.StatusCodeUnknown,
  586. Message: err.Error(),
  587. })
  588. return err
  589. }
  590. // spanResult ...
  591. func (m *IntPointTxnDefaultServer) spanResult(span *trace.Span, out interface{}) error {
  592. raw, err := json.Marshal(out)
  593. if err != nil {
  594. return err
  595. }
  596. span.Annotate([]trace.Attribute{trace.StringAttribute("out", string(raw))}, "out parameter")
  597. return nil
  598. }
  599. // Create ...
  600. func (m *IntPointTxnDefaultServer) Create(ctx context.Context, in *CreateIntPointRequest) (*CreateIntPointResponse, error) {
  601. span, errSpanCreate := m.spanCreate(ctx, in, "Create")
  602. if errSpanCreate != nil {
  603. return nil, errSpanCreate
  604. }
  605. defer span.End()
  606. txn, ok := gorm1.FromContext(ctx)
  607. if !ok {
  608. return nil, errors.NoTransactionError
  609. }
  610. db := txn.Begin()
  611. if db.Error != nil {
  612. return nil, db.Error
  613. }
  614. if custom, ok := interface{}(in).(IntPointTxnIntPointWithBeforeCreate); ok {
  615. var err error
  616. if db, err = custom.BeforeCreate(ctx, db); err != nil {
  617. return nil, m.spanError(span, err)
  618. }
  619. }
  620. res, err := DefaultCreateIntPoint(ctx, in.GetPayload(), db)
  621. if err != nil {
  622. return nil, m.spanError(span, err)
  623. }
  624. out := &CreateIntPointResponse{Result: res}
  625. if custom, ok := interface{}(in).(IntPointTxnIntPointWithAfterCreate); ok {
  626. var err error
  627. if err = custom.AfterCreate(ctx, out, db); err != nil {
  628. return nil, m.spanError(span, err)
  629. }
  630. }
  631. errSpanResult := m.spanResult(span, out)
  632. if errSpanResult != nil {
  633. return nil, m.spanError(span, errSpanResult)
  634. }
  635. return out, nil
  636. }
  637. // IntPointTxnIntPointWithBeforeCreate called before DefaultCreateIntPoint in the default Create handler
  638. type IntPointTxnIntPointWithBeforeCreate interface {
  639. BeforeCreate(context.Context, *gorm.DB) (*gorm.DB, error)
  640. }
  641. // IntPointTxnIntPointWithAfterCreate called before DefaultCreateIntPoint in the default Create handler
  642. type IntPointTxnIntPointWithAfterCreate interface {
  643. AfterCreate(context.Context, *CreateIntPointResponse, *gorm.DB) error
  644. }
  645. // Read ...
  646. func (m *IntPointTxnDefaultServer) Read(ctx context.Context, in *ReadIntPointRequest) (*ReadIntPointResponse, error) {
  647. span, errSpanCreate := m.spanCreate(ctx, in, "Read")
  648. if errSpanCreate != nil {
  649. return nil, errSpanCreate
  650. }
  651. defer span.End()
  652. txn, ok := gorm1.FromContext(ctx)
  653. if !ok {
  654. return nil, errors.NoTransactionError
  655. }
  656. db := txn.Begin()
  657. if db.Error != nil {
  658. return nil, db.Error
  659. }
  660. if custom, ok := interface{}(in).(IntPointTxnIntPointWithBeforeRead); ok {
  661. var err error
  662. if db, err = custom.BeforeRead(ctx, db); err != nil {
  663. return nil, m.spanError(span, err)
  664. }
  665. }
  666. res, err := DefaultReadIntPoint(ctx, &IntPoint{Id: in.GetId()}, db, in.Fields)
  667. if err != nil {
  668. return nil, m.spanError(span, err)
  669. }
  670. out := &ReadIntPointResponse{Result: res}
  671. if custom, ok := interface{}(in).(IntPointTxnIntPointWithAfterRead); ok {
  672. var err error
  673. if err = custom.AfterRead(ctx, out, db); err != nil {
  674. return nil, m.spanError(span, err)
  675. }
  676. }
  677. errSpanResult := m.spanResult(span, out)
  678. if errSpanResult != nil {
  679. return nil, m.spanError(span, errSpanResult)
  680. }
  681. return out, nil
  682. }
  683. // IntPointTxnIntPointWithBeforeRead called before DefaultReadIntPoint in the default Read handler
  684. type IntPointTxnIntPointWithBeforeRead interface {
  685. BeforeRead(context.Context, *gorm.DB) (*gorm.DB, error)
  686. }
  687. // IntPointTxnIntPointWithAfterRead called before DefaultReadIntPoint in the default Read handler
  688. type IntPointTxnIntPointWithAfterRead interface {
  689. AfterRead(context.Context, *ReadIntPointResponse, *gorm.DB) error
  690. }
  691. // Update ...
  692. func (m *IntPointTxnDefaultServer) Update(ctx context.Context, in *UpdateIntPointRequest) (*UpdateIntPointResponse, error) {
  693. span, errSpanCreate := m.spanCreate(ctx, in, "Update")
  694. if errSpanCreate != nil {
  695. return nil, errSpanCreate
  696. }
  697. defer span.End()
  698. var err error
  699. var res *IntPoint
  700. txn, ok := gorm1.FromContext(ctx)
  701. if !ok {
  702. return nil, errors.NoTransactionError
  703. }
  704. db := txn.Begin()
  705. if db.Error != nil {
  706. return nil, db.Error
  707. }
  708. if custom, ok := interface{}(in).(IntPointTxnIntPointWithBeforeUpdate); ok {
  709. var err error
  710. if db, err = custom.BeforeUpdate(ctx, db); err != nil {
  711. return nil, m.spanError(span, err)
  712. }
  713. }
  714. if in.GetGerogeriGegege() == nil {
  715. res, err = DefaultStrictUpdateIntPoint(ctx, in.GetPayload(), db)
  716. } else {
  717. res, err = DefaultPatchIntPoint(ctx, in.GetPayload(), in.GetGerogeriGegege(), db)
  718. }
  719. if err != nil {
  720. return nil, m.spanError(span, err)
  721. }
  722. out := &UpdateIntPointResponse{Result: res}
  723. if custom, ok := interface{}(in).(IntPointTxnIntPointWithAfterUpdate); ok {
  724. var err error
  725. if err = custom.AfterUpdate(ctx, out, db); err != nil {
  726. return nil, m.spanError(span, err)
  727. }
  728. }
  729. errSpanResult := m.spanResult(span, out)
  730. if errSpanResult != nil {
  731. return nil, m.spanError(span, errSpanResult)
  732. }
  733. return out, nil
  734. }
  735. // IntPointTxnIntPointWithBeforeUpdate called before DefaultUpdateIntPoint in the default Update handler
  736. type IntPointTxnIntPointWithBeforeUpdate interface {
  737. BeforeUpdate(context.Context, *gorm.DB) (*gorm.DB, error)
  738. }
  739. // IntPointTxnIntPointWithAfterUpdate called before DefaultUpdateIntPoint in the default Update handler
  740. type IntPointTxnIntPointWithAfterUpdate interface {
  741. AfterUpdate(context.Context, *UpdateIntPointResponse, *gorm.DB) error
  742. }
  743. // Delete ...
  744. func (m *IntPointTxnDefaultServer) Delete(ctx context.Context, in *DeleteIntPointRequest) (*DeleteIntPointResponse, error) {
  745. span, errSpanCreate := m.spanCreate(ctx, in, "Delete")
  746. if errSpanCreate != nil {
  747. return nil, errSpanCreate
  748. }
  749. defer span.End()
  750. txn, ok := gorm1.FromContext(ctx)
  751. if !ok {
  752. return nil, errors.NoTransactionError
  753. }
  754. db := txn.Begin()
  755. if db.Error != nil {
  756. return nil, db.Error
  757. }
  758. if custom, ok := interface{}(in).(IntPointTxnIntPointWithBeforeDelete); ok {
  759. var err error
  760. if db, err = custom.BeforeDelete(ctx, db); err != nil {
  761. return nil, m.spanError(span, err)
  762. }
  763. }
  764. err := DefaultDeleteIntPoint(ctx, &IntPoint{Id: in.GetId()}, db)
  765. if err != nil {
  766. return nil, m.spanError(span, err)
  767. }
  768. out := &DeleteIntPointResponse{}
  769. if custom, ok := interface{}(in).(IntPointTxnIntPointWithAfterDelete); ok {
  770. var err error
  771. if err = custom.AfterDelete(ctx, out, db); err != nil {
  772. return nil, m.spanError(span, err)
  773. }
  774. }
  775. errSpanResult := m.spanResult(span, out)
  776. if errSpanResult != nil {
  777. return nil, m.spanError(span, errSpanResult)
  778. }
  779. return out, nil
  780. }
  781. // IntPointTxnIntPointWithBeforeDelete called before DefaultDeleteIntPoint in the default Delete handler
  782. type IntPointTxnIntPointWithBeforeDelete interface {
  783. BeforeDelete(context.Context, *gorm.DB) (*gorm.DB, error)
  784. }
  785. // IntPointTxnIntPointWithAfterDelete called before DefaultDeleteIntPoint in the default Delete handler
  786. type IntPointTxnIntPointWithAfterDelete interface {
  787. AfterDelete(context.Context, *DeleteIntPointResponse, *gorm.DB) error
  788. }
  789. // DeleteSet ...
  790. func (m *IntPointTxnDefaultServer) DeleteSet(ctx context.Context, in *DeleteIntPointsRequest) (*DeleteIntPointResponse, error) {
  791. span, errSpanCreate := m.spanCreate(ctx, in, "DeleteSet")
  792. if errSpanCreate != nil {
  793. return nil, errSpanCreate
  794. }
  795. defer span.End()
  796. txn, ok := gorm1.FromContext(ctx)
  797. if !ok {
  798. return nil, errors.NoTransactionError
  799. }
  800. db := txn.Begin()
  801. if db.Error != nil {
  802. return nil, db.Error
  803. }
  804. objs := []*IntPoint{}
  805. for _, id := range in.Ids {
  806. objs = append(objs, &IntPoint{Id: id})
  807. }
  808. if custom, ok := interface{}(in).(IntPointTxnIntPointWithBeforeDeleteSet); ok {
  809. var err error
  810. if db, err = custom.BeforeDeleteSet(ctx, db); err != nil {
  811. return nil, m.spanError(span, err)
  812. }
  813. }
  814. err := DefaultDeleteIntPointSet(ctx, objs, db)
  815. if err != nil {
  816. return nil, m.spanError(span, err)
  817. }
  818. out := &DeleteIntPointResponse{}
  819. if custom, ok := interface{}(in).(IntPointTxnIntPointWithAfterDeleteSet); ok {
  820. var err error
  821. if err = custom.AfterDeleteSet(ctx, out, db); err != nil {
  822. return nil, m.spanError(span, err)
  823. }
  824. }
  825. errSpanResult := m.spanResult(span, out)
  826. if errSpanResult != nil {
  827. return nil, m.spanError(span, errSpanResult)
  828. }
  829. return out, nil
  830. }
  831. // IntPointTxnIntPointWithBeforeDeleteSet called before DefaultDeleteSetIntPoint in the default DeleteSet handler
  832. type IntPointTxnIntPointWithBeforeDeleteSet interface {
  833. BeforeDeleteSet(context.Context, *gorm.DB) (*gorm.DB, error)
  834. }
  835. // IntPointTxnIntPointWithAfterDeleteSet called before DefaultDeleteSetIntPoint in the default DeleteSet handler
  836. type IntPointTxnIntPointWithAfterDeleteSet interface {
  837. AfterDeleteSet(context.Context, *DeleteIntPointResponse, *gorm.DB) error
  838. }