Skip to content

Commit 80bc419

Browse files
Merge branch '260-support-new-external-id-types-like-uuidv4' into 'dev'
Support new UUID external ID types #260 See merge request objectbox/objectbox-java!155
2 parents 2e91a1f + c6bd0c2 commit 80bc419

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

objectbox-java-api/src/main/java/io/objectbox/annotation/ExternalPropertyType.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ public enum ExternalPropertyType {
3131
*/
3232
INT_128,
3333
/**
34+
* A UUID (Universally Unique Identifier) as defined by RFC 9562.
35+
* <p>
36+
* ObjectBox uses the UUIDv7 scheme (timestamp + random) to create new UUIDs. UUIDv7 is a good choice for database
37+
* keys as it's mostly sequential and encodes a timestamp. However, if keys are used externally, consider
38+
* {@link #UUID_V4} for better privacy by not exposing any time information.
39+
* <p>
3440
* Representing type: ByteVector
3541
* <p>
3642
* Encoding: 1:1 binary representation (16 bytes)
@@ -44,6 +50,32 @@ public enum ExternalPropertyType {
4450
* Encoding: 1:1 binary representation (16 bytes)
4551
*/
4652
DECIMAL_128,
53+
/**
54+
* UUID represented as a string of 36 characters, e.g. "019571b4-80e3-7516-a5c1-5f1053d23fff".
55+
* <p>
56+
* For efficient storage, consider the {@link #UUID} type instead, which occupies only 16 bytes (20 bytes less).
57+
* This type may still be a convenient alternative as the string type is widely supported and more human-readable.
58+
* In accordance to standards, new UUIDs generated by ObjectBox use lowercase hexadecimal digits.
59+
* <p>
60+
* Representing type: String
61+
*/
62+
UUID_STRING,
63+
/**
64+
* A UUID (Universally Unique Identifier) as defined by RFC 9562.
65+
* <p>
66+
* ObjectBox uses the UUIDv4 scheme (completely random) to create new UUIDs.
67+
* <p>
68+
* Representing type: ByteVector
69+
* <p>
70+
* Encoding: 1:1 binary representation (16 bytes)
71+
*/
72+
UUID_V4,
73+
/**
74+
* Like {@link #UUID_STRING}, but using the UUIDv4 scheme (completely random) to create new UUID.
75+
* <p>
76+
* Representing type: String
77+
*/
78+
UUID_V4_STRING,
4779
/**
4880
* A key/value map; e.g. corresponds to a JSON object or a MongoDB document (although not keeping the key order).
4981
* Unlike the Flex type, this must contain a map value (e.g. not a vector or a scalar).

objectbox-java/src/main/java/io/objectbox/model/ExternalPropertyType.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ private ExternalPropertyType() { }
3737
public static final short Int128 = 100;
3838
public static final short Reserved1 = 101;
3939
/**
40+
* A UUID (Universally Unique Identifier) as defined by RFC 9562.
41+
* ObjectBox uses the UUIDv7 scheme (timestamp + random) to create new UUIDs.
42+
* UUIDv7 is a good choice for database keys as it's mostly sequential and encodes a timestamp.
43+
* However, if keys are used externally, consider UuidV4 for better privacy by not exposing any time information.
4044
* Representing type: ByteVector
4145
* Encoding: 1:1 binary representation (16 bytes)
4246
*/
@@ -47,9 +51,26 @@ private ExternalPropertyType() { }
4751
* Encoding: 1:1 binary representation (16 bytes)
4852
*/
4953
public static final short Decimal128 = 103;
50-
public static final short Reserved2 = 104;
51-
public static final short Reserved3 = 105;
52-
public static final short Reserved4 = 106;
54+
/**
55+
* UUID represented as a string of 36 characters, e.g. "019571b4-80e3-7516-a5c1-5f1053d23fff".
56+
* For efficient storage, consider the Uuid type instead, which occupies only 16 bytes (20 bytes less).
57+
* This type may still be a convenient alternative as the string type is widely supported and more human-readable.
58+
* In accordance to standards, new UUIDs generated by ObjectBox use lowercase hexadecimal digits.
59+
* Representing type: String
60+
*/
61+
public static final short UuidString = 104;
62+
/**
63+
* A UUID (Universally Unique Identifier) as defined by RFC 9562.
64+
* ObjectBox uses the UUIDv4 scheme (completely random) to create new UUIDs.
65+
* Representing type: ByteVector
66+
* Encoding: 1:1 binary representation (16 bytes)
67+
*/
68+
public static final short UuidV4 = 105;
69+
/**
70+
* Like UuidString, but using the UUIDv4 scheme (completely random) to create new UUID.
71+
* Representing type: String
72+
*/
73+
public static final short UuidV4String = 106;
5374
/**
5475
* A key/value map; e.g. corresponds to a JSON object or a MongoDB document (although not keeping the key order).
5576
* Unlike the Flex type, this must contain a map value (e.g. not a vector or a scalar).
@@ -123,7 +144,7 @@ private ExternalPropertyType() { }
123144
*/
124145
public static final short MongoRegex = 127;
125146

126-
public static final String[] names = { "Unknown", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "Int128", "Reserved1", "Uuid", "Decimal128", "Reserved2", "Reserved3", "Reserved4", "FlexMap", "FlexVector", "Json", "Bson", "JavaScript", "Reserved5", "Reserved6", "Reserved7", "Reserved8", "Int128Vector", "Reserved9", "UuidVector", "Reserved10", "Reserved11", "Reserved12", "Reserved13", "MongoId", "MongoIdVector", "MongoTimestamp", "MongoBinary", "MongoRegex", };
147+
public static final String[] names = { "Unknown", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "Int128", "Reserved1", "Uuid", "Decimal128", "UuidString", "UuidV4", "UuidV4String", "FlexMap", "FlexVector", "Json", "Bson", "JavaScript", "Reserved5", "Reserved6", "Reserved7", "Reserved8", "Int128Vector", "Reserved9", "UuidVector", "Reserved10", "Reserved11", "Reserved12", "Reserved13", "MongoId", "MongoIdVector", "MongoTimestamp", "MongoBinary", "MongoRegex", };
127148

128149
public static String name(int e) { return names[e]; }
129150
}

0 commit comments

Comments
 (0)