From fcf5fbf6c8895bbe79c20e5134d973a2c09da493 Mon Sep 17 00:00:00 2001 From: Will Dazey Date: Mon, 6 Mar 2023 11:53:08 -0600 Subject: [PATCH] Issue 1815: Add testing Signed-off-by: Will Dazey --- .../test/collection/TestBasicCollection.java | 87 +++++++++++++++++++ .../jpa/test/collection/model/CityEntity.java | 39 +++++++++ 2 files changed, 126 insertions(+) create mode 100644 jpa/eclipselink.jpa.test.jse/src/it/java/org/eclipse/persistence/jpa/test/collection/TestBasicCollection.java create mode 100644 jpa/eclipselink.jpa.test.jse/src/it/java/org/eclipse/persistence/jpa/test/collection/model/CityEntity.java diff --git a/jpa/eclipselink.jpa.test.jse/src/it/java/org/eclipse/persistence/jpa/test/collection/TestBasicCollection.java b/jpa/eclipselink.jpa.test.jse/src/it/java/org/eclipse/persistence/jpa/test/collection/TestBasicCollection.java new file mode 100644 index 00000000000..c621d2f7a39 --- /dev/null +++ b/jpa/eclipselink.jpa.test.jse/src/it/java/org/eclipse/persistence/jpa/test/collection/TestBasicCollection.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2023 IBM Corporation. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, + * or the Eclipse Distribution License v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ + +// Contributors: +package org.eclipse.persistence.jpa.test.collection; + +import jakarta.persistence.EntityManager; +import jakarta.persistence.EntityManagerFactory; +import jakarta.persistence.Query; + +import java.util.Set; + +import org.eclipse.persistence.jpa.test.framework.DDLGen; +import org.eclipse.persistence.jpa.test.framework.Emf; +import org.eclipse.persistence.jpa.test.framework.EmfRunner; +import org.eclipse.persistence.jpa.test.framework.Property; +import org.eclipse.persistence.jpa.test.collection.model.CityEntity; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(EmfRunner.class) +public class TestBasicCollection { + + @Emf(createTables = DDLGen.DROP_CREATE, + classes = { CityEntity.class }, + properties = { @Property(name = "eclipselink.logging.level", value = "ALL"), + @Property(name = "eclipselink.logging.level.sql", value = "FINE"), + @Property(name = "eclipselink.logging.parameters", value = "true")}) + private EntityManagerFactory emf; + + @Test + public void testUpdateBasicCollectionWithQuery() { + EntityManager em = emf.createEntityManager(); + try { + em.getTransaction().begin(); + em.persist(new CityEntity("Minneapolis", Set.of(608))); + em.getTransaction().commit(); + } finally { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + if(em.isOpen()) { + em.close(); + } + } + + em = emf.createEntityManager(); + try { + em.getTransaction().begin(); + Query q = em.createQuery("UPDATE City o SET o.areaCodes=?1 WHERE o.name=?2"); + q.setParameter(1, Set.of(563)); + q.setParameter(2, "Minneapolis"); + q.executeUpdate(); + em.getTransaction().commit(); + } finally { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + if(em.isOpen()) { + em.close(); + } + } + + em = emf.createEntityManager(); + try { + em.getTransaction().begin(); + CityEntity find2 = em.find(CityEntity.class, "Minneapolis"); + em.getTransaction().commit(); + } finally { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + if(em.isOpen()) { + em.close(); + } + } + } +} diff --git a/jpa/eclipselink.jpa.test.jse/src/it/java/org/eclipse/persistence/jpa/test/collection/model/CityEntity.java b/jpa/eclipselink.jpa.test.jse/src/it/java/org/eclipse/persistence/jpa/test/collection/model/CityEntity.java new file mode 100644 index 00000000000..bf46da83685 --- /dev/null +++ b/jpa/eclipselink.jpa.test.jse/src/it/java/org/eclipse/persistence/jpa/test/collection/model/CityEntity.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023 IBM Corporation. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, + * or the Eclipse Distribution License v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ + +// Contributors: +package org.eclipse.persistence.jpa.test.collection.model; + +import java.util.Collections; +import java.util.Set; + +import jakarta.persistence.CollectionTable; +import jakarta.persistence.ElementCollection; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; + +@Entity +public class CityEntity { + + @Id + public String name; + + public Set areaCodes; + + public CityEntity() {} + + public CityEntity(String name, Set areaCodes) { + this.name = name; + this.areaCodes = areaCodes; + } +}