solomax commented on code in PR #220:
URL: https://github.com/apache/openjpa/pull/220#discussion_r4345935496


##########
openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java:
##########
@@ -1658,27 +1677,61 @@ public Class getConverterDatabaseType() {
         return dbType;
     }
 
+    /**
+     * Return the attribute type of this converter, i.e. the X type in
+     * AttributeConverter<X,Y>. Returns null if no converter is set.
+     */
+    public Class getConverterAttributeType() {
+        Class converter = _converter;
+        if (converter == null) {
+            return null;
+        }
+        Class attrType = _converterAttrType;
+        if (attrType == null) {
+            attrType = resolveConverterTypeArgument(converter, 0);
+            _converterAttrType = attrType;
+        }
+        return attrType;
+    }
+
     /**
      * Extract the database type (second type argument) from an
      * AttributeConverter implementation class.
      */
     private static Class resolveConverterDatabaseType(Class converterClass) {
+        return resolveConverterTypeArgument(converterClass, 1);
+    }
+
+    /**
+     * Extract one type argument of the AttributeConverter<X,Y> that an
+     * implementation class declares: index 0 for the attribute type, 1 for the
+     * database type. A parameterized argument such as {@code List<Item>}
+     * yields its raw type. Returns {@code Object.class} when the argument is
+     * neither, for instance a type variable.
+     */
+    public static Class resolveConverterTypeArgument(Class converterClass, int 
index) {
         for (Type iface : converterClass.getGenericInterfaces()) {
             if (iface instanceof ParameterizedType pt) {
                 Type rawType = pt.getRawType();
                 if (rawType instanceof Class
                         && "jakarta.persistence.AttributeConverter"
                             .equals(((Class) rawType).getName())) {
-                    Type dbArg = pt.getActualTypeArguments()[1];
-                    if (dbArg instanceof Class<?>)
-                        return (Class) dbArg;
+                    Type arg = pt.getActualTypeArguments()[index];
+                    if (arg instanceof Class<?>) {

Review Comment:
   I guess we can use `if (arg instanceof Class<?> arcCls)` sugar here :)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to