cristof commented on code in PR #124: URL: https://github.com/apache/openjpa/pull/124#discussion_r1958325412
########## 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: Fixed as suggested. ########## 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: Fixed as suggested. -- 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