[JAVA-81] ObjectId does not follow the BSON ObjectId specification Created: 26/Jan/10 Updated: 01/Mar/10 Resolved: 26/Jan/10 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | None |
| Affects Version/s: | 1.2 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Critical - P2 |
| Reporter: | Dror Bereznitsky | Assignee: | Eliot Horowitz (Inactive) |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
The BSON ObjectId specification declares that the ObjectID is a 12-byte value consisting of a 4-byte timestamp, a 3-byte machine id, a 2-byte process id, and a 3-byte counter (http://www.mongodb.org/display/DOCS/Object+IDs) |
| Comments |
| Comment by Dror Bereznitsky [ 27/Jan/10 ] |
|
1) I would like to be able to get all the 4 parts of the ObjectId - timestamp, machine, process id and inc. Right now ObjectId already have getMachine(), getTime(), getInc() but getMachine() and getInc() returns incorrect values (when ObjectId is initialized from a String). |
| Comment by Eliot Horowitz (Inactive) [ 26/Jan/10 ] |
|
how its stored internally doesn't really matter. do you mean the getMachine() method are you saying you want a |
| Comment by Dror Bereznitsky [ 26/Jan/10 ] |
|
I was referring to a scenario where I am creating an ObjectId from its String representation. ObjectId id = new ObjectId("49902cde5162504500b45c2c"); It this case the following code from the constructor is incorrect since it disregards the process id: _inc = bb.getInt(); Asking for the "inc" or "machine" parts of the ObjectId will return wrong values. |
| Comment by Eliot Horowitz (Inactive) [ 26/Jan/10 ] |
|
Look at the static initializer around line 314. it gets the machine and the process final int machinePiece; machinePiece = sb.toString().hashCode() << 16; final int processPiece = java.lang.management.ManagementFactory.getRuntimeMXBean().getName().hashCode() & 0xFFFF; _genmachine = machinePiece | processPiece; |