Skip to content

PR for 7.6 Beta by making Patchhandler and related classes internal#2606

Open
Sreejithpin wants to merge 38 commits into
masterfrom
BulkOps_Serializers
Open

PR for 7.6 Beta by making Patchhandler and related classes internal#2606
Sreejithpin wants to merge 38 commits into
masterfrom
BulkOps_Serializers

Conversation

@Sreejithpin

@Sreejithpin Sreejithpin commented Dec 2, 2021

Copy link
Copy Markdown
Contributor

Issues

This pull request fixes #xxx.

Description

PR for 7.6 Beta by making Patchhandler and related classes internal

Changes:

DeltaOfT
internal void Patch(

DeltaSetOfT
internal DeltaSet Patch(IC
internal DeltaSet Patch(

EdmChangedObjectcollection
internal EdmChangedObjectCollection Patch(OD

EdmODataAPIHandler
internal abstract class EdmODataAPIHandler

IODataAPIHandler
internal interface IODataAPIHandler

ODataAPIHandler
internal abstract class ODataAPIHandler: IO

ODataAPIHandlerFactory
internal abstract class ODataAPIHandlerFactory

ODataAPIResponseStatus
internal enum ODataAPIResponseStatus

ODataEdmAPIHandlerFactory
internal abstract class ODataEdmAPIHandlerFactory

ODataIDResolver
internal abstract class ODataIDResolver

Checklist (Uncheck if it is not completed)

  • Test cases added
  • Build and test with one-click build and test script passed

Additional work necessary

If documentation update is needed, please add "Docs Needed" label to the issue and provide details about the required document change in the issue.

Sreejithpin and others added 27 commits October 28, 2021 14:49
* Bulk operations6 (#2)

* BulkInsert1 draft

* Bulk insert changes

* deleted old test

* updates

* Update ODataResourceSetWrapper.cs

* updates

* Updated addressing  comments

* updates

* updates

updates

* Updates

* Updates

* Minor updates

* comments

* updates

* update publicapi for core

* Address comments

* Cleanup and additional tests

Cleanup and additional tests

* Updated code

* BulkInsert1 draft

* Bulk insert changes

* deleted old test

* updates

* updates

* Updated addressing  comments

* updates

* updates

updates

* Updates

* Updates

* Minor updates

* updates

* Address comments

* Cleanup and additional tests

Cleanup and additional tests

* DataAnnotationException updates

* comments

* small updates

* updates

* small update

* updates

* Updates

* Update DeltaSetOfT.cs

* Updates with Patch

* updates

* updates

* Update WebHostTestFixture.cs

* updates

* Update DeltaOfTStructuralType.cs

* Updates

* Updates for serializer etc

* Update WebHostTestFixture.cs

* updates

* updates

* updates

* Bulk Operations Updates

* Review comments addressed

* Updates

* updated for deltaentity

* Update Microsoft.AspNet.OData.Test.csproj

* Update Microsoft.AspNet.OData.PublicApi.bsl

* update public api

* test fix

* Update EdmStructuredObject.cs

* Update EdmStructuredObject.cs

* Update BulkInsertTest.cs

* update

* public api

* review comments

* Review comments updates

* smalll update

* updates

* updates

* updates
* support for odata.bind

* support for odata.bind
* Bulk operations6 (#2)

* BulkInsert1 draft

* Bulk insert changes

* deleted old test

* updates

* Update ODataResourceSetWrapper.cs

* updates

* Updated addressing  comments

* updates

* updates

updates

* Updates

* Updates

* Minor updates

* comments

* updates

* update publicapi for core

* Address comments

* Cleanup and additional tests

Cleanup and additional tests

* Updated code

* BulkInsert1 draft

* Bulk insert changes

* deleted old test

* updates

* updates

* Updated addressing  comments

* updates

* updates

updates

* Updates

* Updates

* Minor updates

* updates

* Address comments

* Cleanup and additional tests

Cleanup and additional tests

* DataAnnotationException updates

* comments

* small updates

* updates

* small update

* updates

* Updates

* Update DeltaSetOfT.cs

* Updates with Patch

* updates

* updates

* Update WebHostTestFixture.cs

* updates

* Update DeltaOfTStructuralType.cs

* Updates

* Updates for serializer etc

* Update WebHostTestFixture.cs

* updates

* updates

* updates

* Bulk Operations Updates

* Review comments addressed

* Updates

* updated for deltaentity

* Update Microsoft.AspNet.OData.Test.csproj

* Update Microsoft.AspNet.OData.PublicApi.bsl

* update public api

* test fix

* Update EdmStructuredObject.cs

* Update EdmStructuredObject.cs

* Update BulkInsertTest.cs

* update

* public api

* review comments

* Review comments updates

* smalll update

* updates

* updates

* updates
* support for odata.bind

* support for odata.bind
Squashing Commits
Update DeltaOfTStructuralType.cs

test change

Update Microsoft.AspNetCore.OData.Test.csproj

Update Microsoft.Test.E2E.AspNetCore3x.OData.csproj

updates

Update WebStack.versions.settings.targets

Update WebStack.versions.settings.targets

Update GetNugetPackageMetadata.proj

Update WebStack.versions.settings.targets

For testing

update

Update BulkInsertController.cs

Updates

updates

updates

Update NuGet.Config

Update BulkOperationPatchHandlersEF.cs

updates
@@ -0,0 +1,115 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

@xuzhg xuzhg Dec 3, 2021

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change all copyrights using existing one. #Resolved

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for other new added files.

/// <param name="resourceWrapper">The resource wrapper.</param>
/// <param name="readContext">The read context.</param>
/// <returns>The resource wrapper.</returns>
private ODataResourceWrapper UpdateResourceWrapper(ODataResourceWrapper resourceWrapper, ODataDeserializerContext readContext)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UpdateResourceWrapper

This method name and description are vague; they don't tell me how the resource wrapper is updated. Maybe rename "SetKeyProperties"?


foreach (string key in keyValues.Keys)
{
propertyInfos.Add(key, _clrType.GetProperty(key));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to populate this dictionary? In the for loop below, can't we just call _clrType.GetProperty(keyValue.Key).GetValue(item)? This would prevent use from having to enumerate keyValues twice, and we don't have to call GetProperty on keys that might come after we find the matching keyValue.Value

/// <param name="keys">List of key names for the type</param>
public DeltaSet(IList<string> keys)
{
_keys = keys;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that later on we assume that _keys is not null; since this is a public API, it's probably best to throw if keys is null.

public DeltaSet(IList<string> keys)
{
_keys = keys;
_clrType = typeof(TStructuralType);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not certain if there's any perf impact, but it might make more sense to have _clrType be static so that we don't have to call typeof as often. At the very least, it seems like good practice to follow DRY.


private DeltaSet<TStructuralType> CreateDeltaSet()
{
Type type = typeof(DeltaSet<>).MakeGenericType(_clrType);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not legal to just write typeof(DeltaSet<TStructuralType>)?


if (hasnullKeys)
{
edmDeletedObject.Id = new Uri(string.Empty);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small optimization, I think that Uri is immutable (or functionally immutable), so we can reduce object allocations if we have a singleton definition of new Uri(string.Empty)

internal EdmChangedObjectCollection CopyChangedValues(EdmODataAPIHandler apiHandler, ODataEdmAPIHandlerFactory apiHandlerFactory = null)
{
EdmChangedObjectCollection changedObjectCollection = new EdmChangedObjectCollection(_entityType);
IEdmStructuralProperty[] keys = _entityType.Key().ToArray();

@corranrogue9 corranrogue9 Mar 2, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there must be a better approach than this. I was initially suspicious because of the ToArray call, but then I saw it makes sense because it is possible for keys to be enumerated multiple times. However, at least for the failed case, we are doing the same .Name deference for the keys. Maybe here we should do _entityType.Key().Select(key => key.Name).ToArray() so that we don't have to deference the name so many times? #Resolved

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good one

/// <param name="createdObject">The created object (Typeless)</param>
/// <param name="errorMessage">Any error message in case of an exception</param>
/// <returns>The status of the TryCreate Method, statuses are <see cref="ODataAPIResponseStatus"/></returns>
public abstract ODataAPIResponseStatus TryCreate(IEdmChangedObject changedObject, out IEdmStructuredObject createdObject, out string errorMessage);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer the return type be a structure that has both ODataAPIResponseStatus and errorMessage as properties. I think it makes the pattern of having both return values clearer. Do you have any thoughts on this?

Comment thread src/Microsoft.AspNet.OData.Shared/EdmODataAPIHandler.cs
{

bool hasDefaultConstructor = (!clrType.IsClass) || clrType.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static).
Any(x => x.GetParameters().Count() == 0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetParameters returns an array, so calling Length instead of Count() should save us a cast


if (keySegment != null)
{
foreach (KeyValuePair<string, object> key in keySegment.Keys)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really see the value of doing this over keySegment.Keys.Select(key => new ODataProperty { Name = key.Key, Value = key.Value }).ToList(). If KeySegment has a count on it, then maybe it makes sense to initialize a new list with that capacity, but otherwise this just seems verbose.

if (property == null && !readContext.DisableCaseInsensitiveRequestPropertyBinding)
{
//try case insensitive
List<ODataProperty> candidates = resourceWrapper.ResourceBase.Properties.Where(p => String.Equals(p.Name, keyName, StringComparison.InvariantCultureIgnoreCase)).ToList();

@corranrogue9 corranrogue9 Mar 2, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I strongly suggest implementing an extension method on IEnumerable for this. I always thought it was weird that this wasn't the functionality for SingleOrDefault in the first place.


if (deletedResource != null)
{
await writer.WriteStartAsync(deletedResource);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to continue execution on the same thread that awaited? I wonder if we want to call ConfigureAwait(false) here

Comment thread src/Microsoft.AspNet.OData.Shared/IDeltaDeletedEntityObject.cs
/// <summary>
/// Navigation Path of an OData ID
/// </summary>
public class NavigationPath : List<PathItem>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't realize understand the need for the NavigationPath type in the first place, but we always seems to be operating on the end of the sequence, so maybe a stack makes more sense than list here?

/// Handler Class to handle users methods for create, delete and update.
/// This is the handler for data modification where there is a CLR type.
/// </summary>
internal abstract class ODataAPIHandler<TStructuralType>: IODataAPIHandler where TStructuralType : class

@corranrogue9 corranrogue9 Mar 2, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems weird that we are constraining the generic type parameter to just class. Why is that restriction necessary? #ByDesign

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used to handle delta request and it should be only for class types

/// </summary>
/// <param name="navigationPath">Navigation path corresponding to an odataid</param>
/// <returns></returns>
public abstract EdmODataAPIHandler GetHandler(NavigationPath navigationPath);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense for GetHandler to be able to add new PathItems to navigationPath?

"\"Author@odata.bind\":\"Authors(1)\"}";

string Uri = BaseAddress + "/odata/Books";
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, Uri);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implements IDisposable. Please wrap it in a using block

request.Content.Headers.ContentType = MediaTypeWithQualityHeaderValue.Parse("application/json");

// Act
HttpResponseMessage response = await Client.SendAsync(request);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also implements IDisposable. Please check for other types in the tests as well

@pull-request-quantifier-deprecated

Copy link
Copy Markdown

This PR has 5787 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Extra Large
Size       : +5285 -502
Percentile : 100%

Total files changed: 111

Change summary by file extension:
.csproj : +114 -43
.config : +103 -100
.cs : +4735 -333
.resx : +18 -0
.projitems : +25 -0
.bsl : +285 -24
.proj : +3 -0
.targets : +2 -2

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detetcted.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

@microsoft-github-policy-service

Copy link
Copy Markdown

@Sreejithpin please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"
Contributor License Agreement

Contribution License Agreement

This Contribution License Agreement ( “Agreement” ) is agreed to by the party signing below ( “You” ),
and conveys certain license rights to the .NET Foundation ( “.NET Foundation” ) for Your contributions to
.NET Foundation open source projects. This Agreement is effective as of the latest signature date below.

1. Definitions.

“Code” means the computer software code, whether in human-readable or machine-executable form,
that is delivered by You to .NET Foundation under this Agreement.

“Project” means any of the projects owned or managed by .NET Foundation and offered under a license
approved by the Open Source Initiative (www.opensource.org).

“Submit” is the act of uploading, submitting, transmitting, or distributing code or other content to any
Project, including but not limited to communication on electronic mailing lists, source code control
systems, and issue tracking systems that are managed by, or on behalf of, the Project for the purpose of
discussing and improving that Project, but excluding communication that is conspicuously marked or
otherwise designated in writing by You as “Not a Submission.”

“Submission” means the Code and any other copyrightable material Submitted by You, including any
associated comments and documentation.

2. Your Submission. You must agree to the terms of this Agreement before making a Submission to any
Project. This Agreement covers any and all Submissions that You, now or in the future (except as
described in Section 4 below), Submit to any Project.

3. Originality of Work. You represent that each of Your Submissions is entirely Your
original work. Should You wish to Submit materials that are not Your original work,
You may Submit them separately to the Project if You (a) retain all copyright and
license information that was in the materials as you received them, (b) in the
description accompanying your Submission, include the phrase "Submission
containing materials of a third party:" followed by the names of the third party and any
licenses or other restrictions of which You are aware, and (c) follow any other
instructions in the Project's written guidelines concerning Submissions.

4. Your Employer. References to “employer” in this Agreement include Your employer or anyone else
for whom You are acting in making Your Submission, e.g. as a contractor, vendor, or agent. If Your
Submission is made in the course of Your work for an employer or Your employer has intellectual
property rights in Your Submission by contract or applicable law, You must secure permission from Your
employer to make the Submission before signing this Agreement. In that case, the term “You” in this
Agreement will refer to You and the employer collectively. If You change employers in the future and
desire to Submit additional Submissions for the new employer, then You agree to sign a new Agreement
and secure permission from the new employer before Submitting those Submissions.

5. Licenses.

a. Copyright License. You grant .NET Foundation, and those who receive the Submission directly
or indirectly from .NET Foundation, a perpetual, worldwide, non-exclusive, royalty-free, irrevocable
license in the Submission to reproduce, prepare derivative works of, publicly display, publicly perform,
and distribute the Submission and such derivative works, and to sublicense any or all of the foregoing
rights to third parties.

b. Patent License. You grant .NET Foundation, and those who receive the Submission directly or
indirectly from .NET Foundation, a perpetual, worldwide, non-exclusive, royalty-free, irrevocable license
under Your patent claims that are necessarily infringed by the Submission or the combination of the
Submission with the Project to which it was Submitted to make, have made, use, offer to sell, sell and
import or otherwise dispose of the Submission alone or with the Project.

c. Other Rights Reserved. Each party reserves all rights not expressly granted in this Agreement.
No additional licenses or rights whatsoever (including, without limitation, any implied licenses) are
granted by implication, exhaustion, estoppel or otherwise.

6. Representations and Warranties. You represent that You are legally entitled to grant the above
licenses. You represent that each of Your Submissions is entirely Your original work (except as You may
have disclosed under Section 3 ). You represent that You have secured permission from Your employer to
make the Submission in cases where Your Submission is made in the course of Your work for Your
employer or Your employer has intellectual property rights in Your Submission by contract or applicable
law. If You are signing this Agreement on behalf of Your employer, You represent and warrant that You
have the necessary authority to bind the listed employer to the obligations contained in this Agreement.
You are not expected to provide support for Your Submission, unless You choose to do so. UNLESS
REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING, AND EXCEPT FOR THE WARRANTIES
EXPRESSLY STATED IN SECTIONS 3, 4, AND 6 , THE SUBMISSION PROVIDED UNDER THIS AGREEMENT IS
PROVIDED WITHOUT WARRANTY OF ANY KIND, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY OF
NONINFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.

7. Notice to .NET Foundation. You agree to notify .NET Foundation in writing of any facts or
circumstances of which You later become aware that would make Your representations in this
Agreement inaccurate in any respect.

8. Information about Submissions. You agree that contributions to Projects and information about
contributions may be maintained indefinitely and disclosed publicly, including Your name and other
information that You submit with Your Submission.

9. Governing Law/Jurisdiction. This Agreement is governed by the laws of the State of Washington, and
the parties consent to exclusive jurisdiction and venue in the federal courts sitting in King County,
Washington, unless no federal subject matter jurisdiction exists, in which case the parties consent to
exclusive jurisdiction and venue in the Superior Court of King County, Washington. The parties waive all
defenses of lack of personal jurisdiction and forum non-conveniens.

10. Entire Agreement/Assignment. This Agreement is the entire agreement between the parties, and
supersedes any and all prior agreements, understandings or communications, written or oral, between
the parties relating to the subject matter hereof. This Agreement may be assigned by .NET Foundation.

.NET Foundation dedicates this Contribution License Agreement to the public domain according to the Creative Commons CC0 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants