Commit f6c11d8
authored
Database policy support for PUT/PATCH operations - MsSql (#1428)
## Why make this change?
As per the behaviour expected from PUT/PATCH operations with database
policies discussed in
#1430, implement db
policy support for MsSql to fix
#1370.
## What is this change?
1. Prior to this change, there was only one database policy for each
operation. Since now database policies will be supported for both insert
(or create)/update actions via PUT/PATCH operations, these 2 operations
can have 2 database policies defined for them, one for each action.
Hence, the `DbPolicyPredicates` (`string`) property in
`BaseSqlQueryStructure` class is replaced by
`DbPolicyPredicatesForOperations` (dictionary: `Config.Action`,
`string`).
2. The query generated by
`MsSqlQueryBuilder.Build(SqlUpsertQueryStructure structure)` is modified
such that only one (or none) of the insert/update operations execute,
depending on:
- Existence of record in the table/view
- Nature of PK (auto gen, non-auto gen)
Previously, we always used to perform the update operation irrespective
of whether the row existed or not. From now onwards, we would first
determine if the row actually exists or not. We will perform update only
if it exists.
3. The method `IQueryExecutor.GetMultipleResultSetsIfAnyAsync` has been
provided another implementation specific to MsSql in
`MsSqlQueryExecutor`. The DbDataReader instance for the query being
executed for the PUT/PATCH return operation would always contain atleast
1 result set and atmost 2 result sets.
- The first result set will give us the number of records(0/1)
corresponding to given PK
- The second result set will give us the rows affected by the operation
executed. It maybe the case that we were not able to execute either of
the update/insert operations. This happens when we are dealing with auto
gen PK table/view, and there is no record for given PK. So we cannot
perform either of the operations in this case.
- If the first result sets says we have zero records present
corresponding to given PK, we will attempt an insert operation(provided
we are not dealing with auto gen PK table/view for which insert is not
possible).
- If the result set says we have one record present corresponding to
given PK, we go on to perform the update.
- The database policies are not taken into consideration when
determining number of records for given PK in the first result set. They
are only taken into consideration for the actual update/insert query.
4. The property `IS_FIRST_RESULT_SET` in `SqlMutationEngine` is renamed
to `IS_UPDATE_RESULT_SET` to better denote its purpose.
5. Different scenarios are added to the method
`MsSqlQueryExecutor.GetMultipleResultSetsIfAnyAsync` to throw
appropriate exceptions (Forbidden/Authorization failure - 403 and
NotFound - 404). Appropriate comments are added within the code to
demonstrate each case.
## How was this tested?
1. Integration Tests - Done1 parent 8ab6c18 commit f6c11d8
File tree
29 files changed
+666
-122
lines changed- config-generators
- src
- Config
- Service.Tests
- SqlTests
- GraphQLMutationTests
- RestApiTests
- Insert
- Patch
- Put
- Service
- Models
- Resolvers
- Sql Query Structures
- Services
29 files changed
+666
-122
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
| 170 | + | |
| 171 | + | |
170 | 172 | | |
171 | 173 | | |
172 | 174 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
53 | 55 | | |
54 | 56 | | |
55 | 57 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
40 | 45 | | |
41 | 46 | | |
42 | 47 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| |||
873 | 873 | | |
874 | 874 | | |
875 | 875 | | |
876 | | - | |
| 876 | + | |
877 | 877 | | |
878 | 878 | | |
879 | 879 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
664 | 664 | | |
665 | 665 | | |
666 | 666 | | |
667 | | - | |
| 667 | + | |
668 | 668 | | |
669 | 669 | | |
670 | 670 | | |
| |||
693 | 693 | | |
694 | 694 | | |
695 | 695 | | |
696 | | - | |
697 | | - | |
| 696 | + | |
| 697 | + | |
698 | 698 | | |
699 | 699 | | |
700 | 700 | | |
| |||
Lines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
93 | 109 | | |
94 | 110 | | |
95 | 111 | | |
| |||
Lines changed: 22 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
216 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
217 | 238 | | |
218 | 239 | | |
219 | 240 | | |
| |||
Lines changed: 92 additions & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
334 | 334 | | |
335 | 335 | | |
336 | 336 | | |
337 | | - | |
| 337 | + | |
338 | 338 | | |
339 | 339 | | |
340 | 340 | | |
| |||
361 | 361 | | |
362 | 362 | | |
363 | 363 | | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
364 | 416 | | |
365 | 417 | | |
366 | 418 | | |
| |||
424 | 476 | | |
425 | 477 | | |
426 | 478 | | |
427 | | - | |
| 479 | + | |
428 | 480 | | |
429 | 481 | | |
430 | 482 | | |
| |||
589 | 641 | | |
590 | 642 | | |
591 | 643 | | |
592 | | - | |
593 | | - | |
| 644 | + | |
| 645 | + | |
594 | 646 | | |
595 | 647 | | |
596 | | - | |
| 648 | + | |
597 | 649 | | |
598 | | - | |
| 650 | + | |
| 651 | + | |
599 | 652 | | |
600 | 653 | | |
601 | | - | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
602 | 657 | | |
603 | 658 | | |
604 | 659 | | |
605 | | - | |
| 660 | + | |
606 | 661 | | |
607 | | - | |
608 | | - | |
609 | | - | |
| 662 | + | |
| 663 | + | |
610 | 664 | | |
| 665 | + | |
611 | 666 | | |
612 | | - | |
613 | | - | |
614 | | - | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
615 | 670 | | |
616 | 671 | | |
| 672 | + | |
617 | 673 | | |
618 | | - | |
619 | | - | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
620 | 685 | | |
621 | | - | |
622 | | - | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
623 | 690 | | |
624 | 691 | | |
625 | | - | |
| 692 | + | |
626 | 693 | | |
627 | | - | |
628 | | - | |
629 | | - | |
| 694 | + | |
| 695 | + | |
630 | 696 | | |
631 | | - | |
| 697 | + | |
632 | 698 | | |
633 | | - | |
634 | | - | |
635 | | - | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
636 | 702 | | |
637 | 703 | | |
638 | | - | |
639 | 704 | | |
640 | 705 | | |
641 | 706 | | |
| |||
Lines changed: 33 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
117 | 118 | | |
118 | 119 | | |
119 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
120 | 133 | | |
121 | 134 | | |
122 | 135 | | |
| |||
207 | 220 | | |
208 | 221 | | |
209 | 222 | | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
210 | 243 | | |
211 | 244 | | |
212 | 245 | | |
| |||
Lines changed: 13 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | | - | |
35 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
36 | 46 | | |
37 | 47 | | |
38 | 48 | | |
| |||
0 commit comments