-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add support for ObjectId
#70
base: main
Are you sure you want to change the base?
Conversation
var expectedDoc = new BsonDocument() | ||
.append("insert", new BsonString("items")) | ||
.append( | ||
"documents", | ||
new BsonArray(List.of(new BsonDocument() | ||
.append("string1", new BsonString("s1")) | ||
.append("string2", new BsonString("s2")) | ||
.append("int32", new BsonInt32(1)) | ||
.append("boolean", BsonBoolean.TRUE) | ||
.append( | ||
"stringAndObjectId", | ||
new BsonArray(List.of( | ||
new BsonString("array element"), | ||
new BsonObjectId(new ObjectId(1, 2))))) | ||
.append("objectId", new BsonObjectId(new ObjectId(2, 0)))))); |
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.
This way it is easier to express what exactly we are expecting than with a string.
Looks great overall. Only some minor comments are left. |
|
||
@Override | ||
public String getVendor() { | ||
return "MongoDB"; |
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.
optional. move it to MongoConstants
?
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.
} | ||
|
||
MqlType(int type) { | ||
this.type = type; |
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.
from my understanding, code
or typeCode
is more accurate. SQLType
or MqlType
is a wrapper of the code or number, but the type per se is not equal to code or number.
We might need to rename the two static methods as well:
maxHibernateSqlType
->maxHibernateSqlTypeCode
minType
->minMqlTypeCode
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 agree. I used type
because that's how java.sql.JDBCType
names it (see JDBCType.type
), and java.sql.JDBCType
is the closest thing to MqlType
. The JDBC naming of this concept is inconsistent:
- The non-API part of the JDBC specification calls it "type code".
java.sql.Types
documents each constant it defines as "type code", yet the class itself is not calledTypeCodes
, butTypes
.- Seemingly, as a result of the previous item,
java.sql.JDBCType
calls its code fieldJDBCType.type
. java.sql.SQLType
documents the same thing as "vendor specific type number", and exposes the methodSQLType.getVendorTypeNumber
.
Done in d0fd672.
@Id | ||
ObjectId id; | ||
|
||
ObjectId v; |
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.
It would be great to add testing case covering such edge case: persisting non-id field with null value.
It might be better orgnaized to create two separate testing case suites, one of which focuses on id and the other focuses on non-id field.
import org.hibernate.type.descriptor.jdbc.BasicExtractor; | ||
import org.hibernate.type.descriptor.jdbc.JdbcType; | ||
|
||
public final class ObjectIdJdbcType implements JdbcType { |
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.
optional. It would be great to implement toString()
if only for better debugging purpose.
Just found an edge case wherein explicit
|
public static final ObjectIdJavaType INSTANCE = new ObjectIdJavaType(); | ||
|
||
private ObjectIdJavaType() { | ||
super(ObjectId.class, ImmutableMutabilityPlan.instance()); |
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.
it doesn't hurt to specify ImmutableMutabilityPlan
above, but given it is default plan, super(ObjectId.class)
seems to suffice.
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.
Done in d11dbcf.
HIBERNATE-23