25
25
public enum FieldValueType {
26
26
/**
27
27
* Integer value.
28
- * Java-side <strong>must</strong> either be a numeric primitive, or extend {@link Number java.lang.Number} and
29
- * implement {@link Comparable java.lang.Comparable }.
28
+ * Java-side <strong>must</strong> be a {@code long}, {@code int}, {@code short} or {@code byte},
29
+ * or an instance of their wrapper classes {@code Long}, {@code Integer}, {@code Short} or {@code Byte }.
30
30
*/
31
31
INTEGER ,
32
32
/**
33
33
* Real (floating-point) number value.
34
- * Java-side <strong>must</strong> either be a numeric primitive, or extend {@link Number java.lang.Number} and
35
- * implement {@link Comparable java.lang.Comparable }.
34
+ * Java-side <strong>must</strong> be a {@code double} or a {@code float}, or an instance of their
35
+ * wrapper classes {@code Double} or {@code Float }.
36
36
*/
37
37
REAL ,
38
38
/**
39
39
* String value.
40
- * Java-side <strong>must</strong> be serialized to simple string value .
40
+ * Java-side <strong>must</strong> be a {@code String} .
41
41
*/
42
42
STRING ,
43
43
/**
44
44
* Boolean value.
45
- * Java-side <strong>must</strong> either be an instance of {@link Boolean java.lang.Boolean} or a {@code boolean}
46
- * primitive .
45
+ * Java-side <strong>must</strong> either be a {@code boolean} primitive, or an instance of its
46
+ * wrapper class {@code Boolean} .
47
47
*/
48
48
BOOLEAN ,
49
49
/**
50
- * Enum value. Java-side <strong>must</strong> be an instance of {@link Enum java.lang.Enum}.<br>
51
- * Typically stored as {@link Enum#name() enum constant name} or its {@link Enum#ordinal() ordinal}.
50
+ * Enum value. Java-side <strong>must</strong> be a concrete subclass of {@link Enum java.lang.Enum}.
52
51
*/
53
52
ENUM ,
54
53
/**
@@ -61,12 +60,14 @@ public enum FieldValueType {
61
60
INTERVAL ,
62
61
/**
63
62
* Binary value: just a stream of uninterpreted bytes.
64
- * Java-side <strong>must</strong> be a byte array .
63
+ * Java-side <strong>must</strong> be a {@code byte[]} .
65
64
* <p>
66
- * @deprecated It is strongly recommended to use a {@link ByteArray} that is properly {@code Comparable}
67
- * and has a sane {@code equals()}.
65
+ *
66
+ * @deprecated Support for mapping raw {@code byte[]} will be removed in YOJ 3.0.0.
67
+ * Even now, it is strongly recommended to use a {@link ByteArray}: it is properly {@code Comparable}
68
+ * and has a sane {@code equals()}, which ensures that queries will work the same for in-memory database and YDB.
68
69
*/
69
- @ Deprecated
70
+ @ Deprecated ( forRemoval = true )
70
71
BINARY ,
71
72
/**
72
73
* Binary value: just a stream of uninterpreted bytes.
@@ -75,19 +76,24 @@ public enum FieldValueType {
75
76
BYTE_ARRAY ,
76
77
/**
77
78
* Composite value. Can contain any other values, including other composite values.<br>
78
- * Java-side must be an immutable POJO with all-args constructor, e.g. a Lombok {@code @Value}-annotated
79
- * class.
79
+ * Java-side must be an immutable value reflectable by YOJ: a Java {@code Record},
80
+ * a Kotlin {@code data class}, an immutable POJO with all-args constructor annotated with
81
+ * {@code @ConstructorProperties} etc.
80
82
*/
81
83
COMPOSITE ,
82
84
/**
83
85
* Polymorphic object stored in an opaque form (i.e., individual fields cannot be accessed by data binding).<br>
84
- * Serialized form strongly depends on the the marshalling mechanism (<em>e.g.</em>, JSON, YAML, ...).<br>
86
+ * Serialized form strongly depends on the the marshalling mechanism (<em>e.g.</em>, JSON, YAML, ...).
85
87
*/
86
88
OBJECT ,
87
89
/**
90
+ * @deprecated This enum constant will be removed in YOJ 3.0.0; {@link #forJavaType(Type, Column)} will instead
91
+ * throw an {@code IllegalArgumentException} if an unmappable type is encountered.
92
+ * <p>
88
93
* Value type is unknown.<br>
89
94
* It <em>might</em> be supported by the data binding implementation, but relying on that fact is not recommended.
90
95
*/
96
+ @ Deprecated (forRemoval = true )
91
97
UNKNOWN ;
92
98
93
99
private static final Set <FieldValueType > SORTABLE_VALUE_TYPES = Set .of (
@@ -107,16 +113,13 @@ public enum FieldValueType {
107
113
));
108
114
109
115
/**
110
- * @deprecated It is recommended to use the {@link CustomValueType} annotation with a {@link StringValueConverter}
111
- * instead of calling this method.
112
- * <p>
113
- * To register a class <em>not in your code</em> (e.g., {@code UUID} from the JDK) as a string-value type, use
114
- * a {@link Column @Column(customValueType=@CustomValueType(...))} annotation on the specific field.
115
- * <p>
116
- * Future versions of YOJ might remove this method entirely.
117
- *
118
116
* @param clazz class to register as string-value. Must either be final or sealed with permissible final-only implementations.
119
117
* All permissible implementations of a sealed class will be registered automatically.
118
+ * @deprecated This method will be removed in YOJ 3.0.0.
119
+ * Use the {@link CustomValueType} annotation with a {@link StringValueConverter} instead of calling this method.
120
+ * <p>
121
+ * To register a class <em>not in your code</em> (e.g., {@code UUID} from the JDK) as a string-value type, use
122
+ * a {@link Column @Column(customValueType=@CustomValueType(...))} annotation on a specific field.
120
123
*/
121
124
@ Deprecated (forRemoval = true )
122
125
@ ExperimentalApi (issue = "https://github.com/ydb-platform/yoj-project/issues/24" )
@@ -145,7 +148,7 @@ public static void registerStringValueType(@NonNull Class<?> clazz) {
145
148
public static FieldValueType forJavaType (Type type , Column columnAnnotation ) {
146
149
var cvt = CustomValueTypes .getCustomValueType (type , columnAnnotation );
147
150
if (cvt != null ) {
148
- return cvt .columnValueType ();
151
+ type = cvt .columnClass ();
149
152
}
150
153
151
154
boolean flatten = columnAnnotation == null || columnAnnotation .flatten ();
@@ -158,11 +161,6 @@ private static FieldValueType forJavaType(@NonNull Type type) {
158
161
if (type instanceof ParameterizedType || type instanceof TypeVariable ) {
159
162
return OBJECT ;
160
163
} else if (type instanceof Class <?> clazz ) {
161
- var cvt = CustomValueTypes .getCustomValueType (clazz , null );
162
- if (cvt != null ) {
163
- return cvt .columnValueType ();
164
- }
165
-
166
164
if (isStringValueType (clazz )) {
167
165
return STRING ;
168
166
} else if (INTEGER_NUMERIC_TYPES .contains (clazz )) {
@@ -206,10 +204,13 @@ private static boolean isStringValueType(Class<?> clazz) {
206
204
* Checks whether Java object of type {@code type} is mapped to a composite database value
207
205
* (i.e. > 1 database field)
208
206
*
209
- * @deprecated This method does not properly take into account the customizations specified in the
210
- * {@link Column @Column} annotation on the field. Please do not call it directly, instead use
211
- * {@code FieldValueType.forJavaType(type, column).isComposite()} where {@code column} is the
212
- * {@link Column @Column} annotation's value.
207
+ * @deprecated This method will be removed in YOJ 3.0.0.
208
+ * This method does not properly take into account the customizations specified in the
209
+ * {@link Column @Column} annotation on the field.
210
+ * <br>Please do not call this method directly, instead use
211
+ * {@link #forJavaType(Type, Column) FieldValueType.forJavaType(type, column).isComposite()}
212
+ * where {@code column} is the {@link Column @Column} annotation's value or {@code null} if
213
+ * there is no annotation/you explicitly don't care.
213
214
*
214
215
* @param type Java object type
215
216
* @return {@code true} if {@code type} maps to a composite database value; {@code false} otherwise
@@ -229,12 +230,28 @@ public boolean isComposite() {
229
230
}
230
231
231
232
/**
233
+ * @deprecated This method will be removed in YOJ 3.0.0 along with the {@link #UNKNOWN} enum constant.
234
+ *
232
235
* @return {@code true} if there is no fitting database value type for the type provided; {@code false} otherwise
233
236
*/
237
+ @ Deprecated (forRemoval = true )
234
238
public boolean isUnknown () {
235
239
return this == UNKNOWN ;
236
240
}
237
241
242
+ /**
243
+ * @deprecated This method will be removed in YOJ 3.0.0. This method is misleadingly named and is not generally useful.
244
+ * <ul>
245
+ * <li>It does not return the list of all Comparable single-column value types (INTERVAL and BOOLEAN are missing).
246
+ * In fact, all single-column value types except for BINARY are Comparable.</li>
247
+ * <li>What is considered <em>sortable</em> generally depends on your business logic.
248
+ * <br>E.g.: Are boolean values sortable or not? They're certainly Comparable.
249
+ * <br>E.g.: How do you sort columns with FieldValueType.STRING? Depends on your Locale for in-memory DB and your locale+collation+phase of the moon
250
+ * for a real database
251
+ * <br><em>etc.</em></li>
252
+ * </ul>
253
+ */
254
+ @ Deprecated (forRemoval = true )
238
255
public boolean isSortable () {
239
256
return SORTABLE_VALUE_TYPES .contains (this );
240
257
}
0 commit comments