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


##########
openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java:
##########
@@ -1956,6 +1967,15 @@ public String getTypeName(Column col) {
         if (col.isAutoAssigned() && autoAssignTypeName != null)
             return appendSize(col, autoAssignTypeName);
 
+        if (col.getJavaType() == JavaTypes.UUID_OBJ) {
+            if (supportsUuidType) 
+                return appendSize(col, uuidTypeName);
+            else {
+                //col.setSize(36);

Review Comment:
   this one need to be cleaned up? :)



##########
openjpa-kernel/src/main/java/org/apache/openjpa/abstractstore/AbstractStoreManager.java:
##########
@@ -42,6 +42,7 @@
 import org.apache.openjpa.util.ApplicationIds;
 import org.apache.openjpa.util.Id;
 import org.apache.openjpa.util.ImplHelper;
+import org.apache.openjpa.util.UuidId;

Review Comment:
   Unused import?



##########
openjpa-kernel/src/main/java/org/apache/openjpa/util/UuidId.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.util;
+
+import java.util.UUID;
+
+/**
+ * Identity type appropriate for UUID primary key fields and shared
+ * id classes.
+ *
+ * @author Abe White
+ */
+public final class UuidId
+    extends OpenJPAId {
+
+    
+    private static final long serialVersionUID = 1L;
+    private UUID _key;
+
+    public UuidId(Class<?> cls, UUID key) {
+        super(cls);
+        _key = key;
+    }
+
+    public UuidId(Class<?> cls, UUID key, boolean subs) {
+        super(cls, subs);
+        _key = key;
+    }
+
+    public UUID getId() {
+        return _key;
+    }
+
+    /**
+     * Allow utilities in this package to mutate id.
+     */
+    void setId(UUID id) {
+        _key = id;
+    }
+
+    @Override
+    public Object getIdObject() {
+        return _key;
+    }
+
+    @Override
+    protected int idHash() {
+        return (_key == null) ? 0 : _key.hashCode();
+    }
+
+    @Override
+    protected boolean idEquals(OpenJPAId o) {
+        Object key = ((UuidId) o)._key;

Review Comment:
   this one might throw :(
   
   I would write something like this:
   
   `return (_key == null && o == null) || (_key != null && _key.equals(o)`
   
   :)



##########
openjpa-kernel/src/main/java/org/apache/openjpa/meta/JavaTypes.java:
##########
@@ -417,6 +421,11 @@ public static Object convert(Object val, int typeCode) {
                 if (val instanceof String)
                     return Short.valueOf(val.toString());
                 return val;
+            case UUID_OBJ:
+                if (val instanceof String) {
+                    return UUID.fromString(val.toString());

Review Comment:
   ```suggestion
                       return UUID.fromString((String)val);
   ```
   ?



##########
openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestUuidGeneratedEntity.java:
##########
@@ -0,0 +1,326 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.generationtype;
+
+import jakarta.persistence.EntityManager;
+
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.schema.Column;
+import org.apache.openjpa.jdbc.sql.DBDictionary;
+import org.apache.openjpa.meta.JavaTypes;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestUuidGeneratedEntity extends SingleEMFTestCase {
+    
+    DBDictionary _dict;
+
+    @Override
+    public void setUp() {
+        setUp(UuidGeneratedEntity.class, CLEAR_TABLES);
+        _dict = 
((JDBCConfiguration)emf.getConfiguration()).getDBDictionaryInstance();
+    }
+
+    public void testMapping() {
+        ClassMapping cm = getMapping(UuidGeneratedEntity.class);
+        Column[] cols = cm.getPrimaryKeyColumns();
+        assertEquals(1, cols.length);
+
+        Column col = cols[0];
+        if (_dict.supportsUuidType) {

Review Comment:
   this one might be shortened to
   
   `assertEquals(_dict.supportsUuidType ? JavaTypes.UUID_OBJ : 
JavaTypes.STRING, col.getJavaType());` :))



-- 
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: dev-unsubscr...@openjpa.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to