Skip to content

Commit

Permalink
eclipse-ee4j#1678: Canonical processor fails on entities shared acros…
Browse files Browse the repository at this point in the history
…s persistence units

Signed-off-by: Lukas Jungmann <[email protected]>
  • Loading branch information
lukasj committed Sep 8, 2022
1 parent 8c7893d commit 90d9115
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,10 @@
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence persistence_1_0.xsd" version="1.0">
<persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

<!-- &lt;!&ndash; mapping files that are packaged in xml-only-model-tests.jar. &ndash;&gt;-->
<!-- <mapping-file>META-INF/advanced-entity-mappings.xml</mapping-file>-->
<!-- &lt;!&ndash; inheritance-entity-mappings.xml is packaged as META-INF/orm.xml-->
<!-- to test default listeners are added only once (GF #589) as well as-->
<!-- to test that we can read orm.xml from referenced jar(GF #1131)-->
<!-- See build.xml for more details.-->
<!-- <mapping-file>META-INF/inheritance-entity-mappings.xml</mapping-file&ndash;&gt;-->
<!-- <mapping-file>META-INF/inherited-entity-mappings.xml</mapping-file>-->
<!-- <mapping-file>META-INF/relationships-entity-mappings.xml</mapping-file>-->
<!-- <mapping-file>META-INF/unidirectional-relationships-entity-mappings.xml</mapping-file>-->

<!-- &lt;!&ndash; mapping files that are packaged in xml-merge-model-tests.jar&ndash;&gt;-->
<!-- <mapping-file>META-INF/orm-annotation-merge-advanced-entity-mappings.xml</mapping-file>-->

<!-- this is here for testing purposes - ensures a persistence unit can load even with a file that does not exist. Please do not add an xml file called: META-INF/non-existant-orm-file.xml -->
<mapping-file>META-INF/non-existant-orm-file.xml</mapping-file>

<!-- <jar-file>eclipselink-xml-only-model.jar</jar-file>-->
<!-- <jar-file>eclipselink-xml-merge-model.jar</jar-file>-->

<!-- this is here for testing purposes GF #588, do not remove. -->
<!-- <class>org.eclipse.persistence.testing.models.jpa.xml.inherited.Beer</class>-->
<exclude-unlisted-classes>false</exclude-unlisted-classes>
Expand Down Expand Up @@ -84,59 +67,17 @@
</persistence-unit>

<!-- see https://github.com/eclipse-ee4j/eclipselink/issues/1678 -->
<!-- <persistence-unit name="default1">-->
<!-- <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>-->
<!-- <exclude-unlisted-classes>false</exclude-unlisted-classes>-->
<!-- <properties>-->
<!-- <property name="eclipselink.logging.level" value="OFF"/>-->
<!-- &lt;!&ndash; Since we don't exclude unlisted classes here, we will &ndash;&gt;-->
<!-- &lt;!&ndash; eventually hit the multitenant entities which turn native &ndash;&gt;-->
<!-- &lt;!&ndash; sql queries off by default, so we need to be explicit here &ndash;&gt;-->
<!-- &lt;!&ndash; and turn them on &ndash;&gt;-->
<!-- <property name="eclipselink.jdbc.allow-native-sql-queries" value="true"/>-->
<!-- </properties>-->
<!-- </persistence-unit>-->

<!-- &lt;!&ndash; following persistence unit is for CASE_SENSITIVITY testing&ndash;&gt;-->
<!-- <persistence-unit name="case_sensitivity_pu">-->
<!-- <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>-->
<!-- <mapping-file>META-INF/case-sensitive-advanced-entity-mappings.xml</mapping-file>-->
<!-- <exclude-unlisted-classes>false</exclude-unlisted-classes>-->
<!-- <properties>-->
<!-- <property name="eclipselink.jpa.uppercase-column-names" value="true"/>-->
<!-- &lt;!&ndash; Since we don't exclude unlisted classes here, we will &ndash;&gt;-->
<!-- &lt;!&ndash; eventually hit the multitenant entities which turn native &ndash;&gt;-->
<!-- &lt;!&ndash; sql queries off by default, so we need to be explicit here &ndash;&gt;-->
<!-- &lt;!&ndash; and turn them on &ndash;&gt;-->
<!-- <property name="eclipselink.jdbc.allow-native-sql-queries" value="true"/>-->
<!-- </properties>-->
<!-- </persistence-unit>-->

<!-- <persistence-unit name="customizeAddTarget">-->
<!-- <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>-->
<!-- <exclude-unlisted-classes>false</exclude-unlisted-classes>-->
<!-- <properties>-->
<!-- <property name="eclipselink.logging.level" value="OFF"/>-->
<!-- <property name="eclipselink.descriptor.customizer.Employee" value="org.eclipse.persistence.testing.models.jpa.advanced.AddTargetCustomizer"/>-->
<!-- &lt;!&ndash; Since we don't exclude unlisted classes here, we will &ndash;&gt;-->
<!-- &lt;!&ndash; eventually hit the multitenant entities which turn native &ndash;&gt;-->
<!-- &lt;!&ndash; sql queries off by default, so we need to be explicit here &ndash;&gt;-->
<!-- &lt;!&ndash; and turn them on &ndash;&gt;-->
<!-- <property name="eclipselink.jdbc.allow-native-sql-queries" value="true"/>-->
<!-- </properties>-->
<!-- </persistence-unit>-->
<persistence-unit name="default1">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="eclipselink.logging.level" value="OFF"/>
<!-- Since we don't exclude unlisted classes here, we will -->
<!-- eventually hit the multitenant entities which turn native -->
<!-- sql queries off by default, so we need to be explicit here -->
<!-- and turn them on -->
<property name="eclipselink.jdbc.allow-native-sql-queries" value="true"/>
</properties>
</persistence-unit>

<!-- <persistence-unit name="additional-criteria">-->
<!-- <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>-->
<!-- <class>org.eclipse.persistence.testing.models.jpa.advanced.additionalcriteria.Person</class>-->
<!-- <class>org.eclipse.persistence.testing.models.jpa.advanced.additionalcriteria.Eater</class>-->
<!-- <class>org.eclipse.persistence.testing.models.jpa.advanced.additionalcriteria.Food</class>-->
<!-- <class>org.eclipse.persistence.testing.models.jpa.advanced.additionalcriteria.Sandwich</class>-->
<!-- <class>org.eclipse.persistence.testing.models.jpa.advanced.additionalcriteria.Rabbit</class>-->
<!-- <class>org.eclipse.persistence.testing.models.jpa.advanced.additionalcriteria.RabbitFoot</class>-->
<!-- <exclude-unlisted-classes>true</exclude-unlisted-classes>-->
<!-- <properties>-->
<!-- <property name="eclipselink.session-name" value="additional-criteria"/>-->
<!-- </properties>-->
<!-- </persistence-unit>-->
</persistence>
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public static Test suiteSpring() {
suite.addTest(new AdvancedJPAJunitTest("testEmployeeFetchWithAlias"));

suite.addTest(new AdvancedJPAJunitTest("testJoinFetchAnnotation"));
// suite.addTest(new AdvancedJPAJunitTest("testVerifyEmployeeCacheSettings")); // see https://github.com/eclipse-ee4j/eclipselink/issues/1678
suite.addTest(new AdvancedJPAJunitTest("testVerifyEmployeeCacheSettings"));
suite.addTest(new AdvancedJPAJunitTest("testVerifyEmployeeCustomizerSettings"));

suite.addTest(new AdvancedJPAJunitTest("testUpdateEmployee"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ protected void generateCanonicalModelClass(MetadataClass metadataClass, Element
writer.append(")\n");
}
writer.append("@StaticMetamodel(").append(className).append(".class)\n");
writer.append("@SuppressWarnings({\"rawtypes\", \"deprecation\"})\n");

int modifier = accessor.getAccessibleObject().getModifiers();
writer.append(java.lang.reflect.Modifier.toString(modifier)).append(" class ").append(canonicalName);
Expand Down Expand Up @@ -427,9 +428,10 @@ protected void generateCanonicalModelClasses(MetadataMirrorFactory factory, Pers
for (Element roundElement : roundElements.keySet()) {
MetadataClass roundClass = roundElements.get(roundElement);

if (persistenceUnit.containsClass(roundClass)) {
if (persistenceUnit.containsClass(roundClass) && !factory.isProcessed(roundElement)) {
log(SessionLog.FINEST, "Generating class: {0}", roundClass.getName());
generateCanonicalModelClass(roundClass, roundElement, persistenceUnit);
factory.addProcessed(roundElement);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2022 Oracle and/or its affiliates. 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
Expand Down Expand Up @@ -32,6 +32,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.RoundEnvironment;
Expand Down Expand Up @@ -69,16 +70,17 @@ public class MetadataMirrorFactory extends MetadataFactory {
// Thing to note: persistence units can be reloaded. We do not however
// reload their associated projects. Once the project is created, it remains
// around for the lifecycle of the compiler.
private Map<String, PersistenceUnit> persistenceUnits;
private Map<String, MetadataProject> metadataProjects;
private final Map<String, PersistenceUnit> persistenceUnits;
private final Map<String, MetadataProject> metadataProjects;

// This is a map of element/metadata classes built per compile round. This
// map is cleared for each compile round.
private Map<Element, MetadataClass> roundElements;
private final Map<Element, MetadataClass> roundElements;

// This is a hash set of metadata classes per compile round. This set is
// cleared for each compile round.
private HashSet<MetadataClass> roundMetadataClasses;
private final Set<MetadataClass> roundMetadataClasses;
private final Set<Element> processedElements;

private ProcessingEnvironment processingEnv;

Expand All @@ -97,6 +99,7 @@ protected MetadataMirrorFactory(final MetadataLogger logger, final ClassLoader l
roundMetadataClasses = new HashSet<>();
persistenceUnits = new HashMap<>();
metadataProjects = new HashMap<>();
processedElements = new HashSet<>();
}

/**
Expand Down Expand Up @@ -291,6 +294,14 @@ public boolean isRoundElement(MetadataClass cls) {
return roundMetadataClasses.contains(cls);
}

void addProcessed(Element name) {
processedElements.add(name);
}

boolean isProcessed(Element name) {
return processedElements.contains(name);
}

/**
* INTERNAL:
*/
Expand All @@ -311,6 +322,7 @@ public void setEnvironments(ProcessingEnvironment processingEnvironment, RoundEn
processingEnv = processingEnvironment;
roundElements.clear();
roundMetadataClasses.clear();
processedElements.clear();

// Initialize the element visitor if it is null.
if (elementVisitor == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@

public class TestProcessor {

public TestProcessor() {}

@BeforeClass
public static void prepare() throws IOException {
File testRoot = new File(System.getProperty("run.dir"));
Expand Down

0 comments on commit 90d9115

Please sign in to comment.