-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 412391: Add support for hidden mappedsuperclass attributes
Signed-off-by: Will Dazey <[email protected]>
- Loading branch information
Showing
4 changed files
with
173 additions
and
3 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
...ipselink.jpa.test.jse/src/it/java/org/eclipse/persistence/jpa/test/weave/TestWeaving.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright (c) 2021 Oracle, and/or affiliates. All rights reserved. | ||
* Copyright (c) 2021 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: | ||
// IBM - Bug 412391: Add support for weaving hidden variables | ||
package org.eclipse.persistence.jpa.test.weave; | ||
|
||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.EntityManagerFactory; | ||
|
||
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.weave.model.WeavedAbstractMS; | ||
import org.eclipse.persistence.jpa.test.weave.model.WeavedEntityA; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(EmfRunner.class) | ||
public class TestWeaving { | ||
|
||
@Emf(createTables = DDLGen.DROP_CREATE, | ||
classes = { WeavedAbstractMS.class, WeavedEntityA.class }, | ||
properties = { @Property(name = "eclipselink.cache.shared.default", value = "false") }) | ||
private EntityManagerFactory emf; | ||
|
||
private static boolean POPULATED = false; | ||
|
||
@Test | ||
public void testHiddenAttribute() throws Exception { | ||
if (emf == null) | ||
return; | ||
|
||
if(!POPULATED) | ||
populate(); | ||
|
||
EntityManager em = emf.createEntityManager(); | ||
try { | ||
final WeavedEntityA e1 = em.find(WeavedEntityA.class, 123l); | ||
|
||
Assert.assertNotNull(e1); | ||
Assert.assertNotNull(e1.getHiddenAttribute()); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
throw e; | ||
} finally { | ||
if (em != null) { | ||
if (em.getTransaction().isActive()) { | ||
em.getTransaction().rollback(); | ||
} | ||
em.close(); | ||
} | ||
} | ||
} | ||
|
||
private void populate() { | ||
EntityManager em = emf.createEntityManager(); | ||
try { | ||
em.getTransaction().begin(); | ||
|
||
WeavedEntityA tbl1 = new WeavedEntityA(); | ||
tbl1.setId(123l); | ||
tbl1.setHiddenAttribute((short) 1); | ||
em.persist(tbl1); | ||
|
||
em.getTransaction().commit(); | ||
|
||
POPULATED = true; | ||
} finally { | ||
if(em.isOpen()) { | ||
em.clear(); | ||
em.close(); | ||
} | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...a.test.jse/src/it/java/org/eclipse/persistence/jpa/test/weave/model/WeavedAbstractMS.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (c) 2021 Oracle, and/or affiliates. All rights reserved. | ||
* Copyright (c) 2021 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: | ||
// IBM - Bug 412391: Add support for weaving hidden variables | ||
package org.eclipse.persistence.jpa.test.weave.model; | ||
|
||
import jakarta.persistence.MappedSuperclass; | ||
|
||
@MappedSuperclass | ||
public abstract class WeavedAbstractMS { | ||
private String parentOnlyAttribute; | ||
private Short hiddenAttribute; | ||
|
||
public String getParentOnlyAttribute() { | ||
return parentOnlyAttribute; | ||
} | ||
public void setParentOnlyAttribute(String parentOnlyAttribute) { | ||
this.parentOnlyAttribute = parentOnlyAttribute; | ||
} | ||
public Short getHiddenAttribute() { | ||
return hiddenAttribute; | ||
} | ||
public void setHiddenAttribute(Short hiddenAttribute) { | ||
this.hiddenAttribute = hiddenAttribute; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
....jpa.test.jse/src/it/java/org/eclipse/persistence/jpa/test/weave/model/WeavedEntityA.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (c) 2021 Oracle, and/or affiliates. All rights reserved. | ||
* Copyright (c) 2021 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: | ||
// IBM - Bug 412391: Add support for weaving hidden variables | ||
package org.eclipse.persistence.jpa.test.weave.model; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
|
||
@Entity | ||
public class WeavedEntityA extends WeavedAbstractMS { | ||
|
||
@Id private long id; | ||
private Short hiddenAttribute; | ||
|
||
public long getId() { | ||
return id; | ||
} | ||
public void setId(long id) { | ||
this.id = id; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters