-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow Long as ID type in Entity for Cosmos DB #13321
Changes from all commits
1949d5b
70aa09c
1e42ed2
103ffa2
2aa5b64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -201,8 +201,10 @@ private Field getIdField(Class<?> domainType) { | |
throw new IllegalArgumentException("domain should contain @Id field or field named id"); | ||
} else if (idField.getType() != String.class | ||
&& idField.getType() != Integer.class | ||
&& idField.getType() != int.class) { | ||
throw new IllegalArgumentException("type of id field must be String or Integer"); | ||
&& idField.getType() != int.class | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a unit test for this in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in CosmosEntityInformationUnitTest, please check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. |
||
&& idField.getType() != Long.class | ||
&& idField.getType() != long.class) { | ||
throw new IllegalArgumentException("type of id field must be String, Integer or Long"); | ||
} | ||
|
||
return idField; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
package com.azure.spring.data.cosmos.domain; | ||
|
||
import com.azure.spring.data.cosmos.core.mapping.Document; | ||
import org.springframework.data.annotation.Id; | ||
|
||
import java.util.Objects; | ||
|
||
@Document | ||
public class LongIdDomain { | ||
|
||
@Id | ||
private Long number; | ||
|
||
private String name; | ||
|
||
public LongIdDomain(Long number, String name) { | ||
this.number = number; | ||
this.name = name; | ||
} | ||
|
||
public LongIdDomain() { | ||
} | ||
|
||
public Long getNumber() { | ||
return number; | ||
} | ||
|
||
public void setNumber(Long number) { | ||
this.number = number; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
LongIdDomain that = (LongIdDomain) o; | ||
return Objects.equals(number, that.number) | ||
&& Objects.equals(name, that.name); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(number, name); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "LongIdDomain{" | ||
+ "number=" | ||
+ number | ||
+ ", name='" | ||
+ name | ||
+ '\'' | ||
+ '}'; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
package com.azure.spring.data.cosmos.domain; | ||
|
||
import com.azure.spring.data.cosmos.core.mapping.Document; | ||
import com.azure.spring.data.cosmos.core.mapping.PartitionKey; | ||
import org.springframework.data.annotation.Id; | ||
|
||
import java.util.Objects; | ||
|
||
@Document | ||
public class LongIdDomainPartition { | ||
|
||
@Id | ||
private Long number; | ||
|
||
@PartitionKey | ||
private String name; | ||
|
||
public LongIdDomainPartition(Long number, String name) { | ||
this.number = number; | ||
this.name = name; | ||
} | ||
|
||
public LongIdDomainPartition() { | ||
} | ||
|
||
public Long getNumber() { | ||
return number; | ||
} | ||
|
||
public void setNumber(Long number) { | ||
this.number = number; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
LongIdDomainPartition that = (LongIdDomainPartition) o; | ||
return Objects.equals(number, that.number) | ||
&& Objects.equals(name, that.name); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(number, name); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "LongIdDomain{" | ||
+ "number=" | ||
+ number | ||
+ ", name='" | ||
+ name | ||
+ '\'' | ||
+ '}'; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need this change for
ReactiveCosmosTemplate
as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be, but there's o similar method in ReactiveCosmosTemplate, I unified the procesing of ID type conversion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good, makes sense.