Skip to content

Commit 49f17d8

Browse files
Merge branch '239-externaltype-annotation' into 'dev'
Support ExternalType annotation #239 See merge request objectbox/objectbox-java!145
2 parents b5bd9e4 + 6b8ba61 commit 49f17d8

File tree

19 files changed

+645
-96
lines changed

19 files changed

+645
-96
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*
2+
* Copyright 2025 ObjectBox Ltd. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.objectbox.annotation;
18+
19+
20+
/**
21+
* A property type of an external system (e.g. another database) that has no default mapping to an ObjectBox type.
22+
* <p>
23+
* Use with {@link ExternalType @ExternalType}.
24+
*/
25+
public enum ExternalPropertyType {
26+
27+
/**
28+
* Representing type: ByteVector
29+
* <p>
30+
* Encoding: 1:1 binary representation, little endian (16 bytes)
31+
*/
32+
INT_128,
33+
/**
34+
* Representing type: ByteVector
35+
* <p>
36+
* Encoding: 1:1 binary representation (16 bytes)
37+
*/
38+
UUID,
39+
/**
40+
* IEEE 754 decimal128 type, e.g. supported by MongoDB.
41+
* <p>
42+
* Representing type: ByteVector
43+
* <p>
44+
* Encoding: 1:1 binary representation (16 bytes)
45+
*/
46+
DECIMAL_128,
47+
/**
48+
* A key/value map; e.g. corresponds to a JSON object or a MongoDB document (although not keeping the key order).
49+
* Unlike the Flex type, this must contain a map value (e.g. not a vector or a scalar).
50+
* <p>
51+
* Representing type: Flex
52+
* <p>
53+
* Encoding: Flex
54+
*/
55+
FLEX_MAP,
56+
/**
57+
* A vector (aka list or array) of flexible elements; e.g. corresponds to a JSON array or a MongoDB array. Unlike
58+
* the Flex type, this must contain a vector value (e.g. not a map or a scalar).
59+
* <p>
60+
* Representing type: Flex
61+
* <p>
62+
* Encoding: Flex
63+
*/
64+
FLEX_VECTOR,
65+
/**
66+
* Placeholder (not yet used) for a JSON document.
67+
* <p>
68+
* Representing type: String
69+
*/
70+
JSON,
71+
/**
72+
* Placeholder (not yet used) for a BSON document.
73+
* <p>
74+
* Representing type: ByteVector
75+
*/
76+
BSON,
77+
/**
78+
* JavaScript source code.
79+
* <p>
80+
* Representing type: String
81+
*/
82+
JAVASCRIPT,
83+
/**
84+
* A vector (array) of Int128 values.
85+
*/
86+
INT_128_VECTOR,
87+
/**
88+
* A vector (array) of Int128 values.
89+
*/
90+
UUID_VECTOR,
91+
/**
92+
* The 12-byte ObjectId type in MongoDB.
93+
* <p>
94+
* Representing type: ByteVector
95+
* <p>
96+
* Encoding: 1:1 binary representation (12 bytes)
97+
*/
98+
MONGO_ID,
99+
/**
100+
* A vector (array) of MongoId values.
101+
*/
102+
MONGO_ID_VECTOR,
103+
/**
104+
* Representing type: Long
105+
* <p>
106+
* Encoding: Two unsigned 32-bit integers merged into a 64-bit integer.
107+
*/
108+
MONGO_TIMESTAMP,
109+
/**
110+
* Representing type: ByteVector
111+
* <p>
112+
* Encoding: 3 zero bytes (reserved, functions as padding), fourth byte is the sub-type, followed by the binary
113+
* data.
114+
*/
115+
MONGO_BINARY,
116+
/**
117+
* Representing type: string vector with 2 elements (index 0: pattern, index 1: options)
118+
* <p>
119+
* Encoding: 1:1 string representation
120+
*/
121+
MONGO_REGEX
122+
123+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2025 ObjectBox Ltd. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.objectbox.annotation;
18+
19+
20+
import java.lang.annotation.ElementType;
21+
import java.lang.annotation.Retention;
22+
import java.lang.annotation.RetentionPolicy;
23+
import java.lang.annotation.Target;
24+
25+
/**
26+
* Sets the type of a property or the type of object IDs of a ToMany in an external system (like another database).
27+
* <p>
28+
* This is useful if there is no default mapping of the ObjectBox type to the type in the external system.
29+
* <p>
30+
* Carefully look at the documentation of the external type to ensure it is compatible with the ObjectBox type.
31+
*/
32+
@Retention(RetentionPolicy.CLASS)
33+
@Target({ElementType.FIELD})
34+
public @interface ExternalType {
35+
36+
ExternalPropertyType value();
37+
38+
}

0 commit comments

Comments
 (0)