Skip to content

Commit

Permalink
#1171 - Fix incorrect logging and log messages for verifying that ent…
Browse files Browse the repository at this point in the history
…ities underwent class transformation
  • Loading branch information
phillipuniverse committed Nov 26, 2014
1 parent d89088a commit 11e35f7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
Expand Up @@ -243,11 +243,16 @@ public void preparePersistenceUnitInfos() {
}

// If a class happened to be loaded by the ClassLoader before we had a chance to set up our instrumentation,
// it may not be in a consistent state. We'll detect that here and force the class to be reloaded
// it may not be in a consistent state
for (PersistenceUnitInfo pui : mergedPus.values()) {
for (String managedClassName : pui.getManagedClassNames()) {
if (!entityMarkerClassTransformer.getTransformedClassNames().contains(managedClassName)) {
LOG.error("Should have transformed " + managedClassName + " but didn't");
LOG.warn("The class " + managedClassName + " is a managed clas within the MergePersistenceUnitManager"
+ "but was not detected as being transformed by the EntityMarkerClassTransformer. This "
+ "might simply be because " + managedClassName + " is not annotated with @Entity, @MappedSuperclass or @Embeddable"
+ ", but is still referenced in a persistence.xml and is being transformed by"
+ " PersistenceUnit ClassTransformers. This class should likely be removed from your persistence.xml");

}
}
}
Expand Down
Expand Up @@ -21,6 +21,7 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.broadleafcommerce.common.extensibility.jpa.MergePersistenceUnitManager;
import org.broadleafcommerce.common.extensibility.jpa.copy.DirectCopyIgnorePattern;

import java.io.ByteArrayInputStream;
Expand All @@ -37,11 +38,18 @@
import javassist.bytecode.annotation.Annotation;

import javax.annotation.Resource;
import javax.persistence.Embeddable;
import javax.persistence.Entity;
import javax.persistence.MappedSuperclass;

/**
* This class transformer will check to see if there is an @Entity annotation on the given class, and if there is,
* it will add the fully qualified classname of that class to the transformedClassNames list.
* <p>
* This class transformer will check to see if there is class that should have been loaded by the {@link MergePersistenceUnitManager}
* (meaning, it has an @Entity, @MappedSuperclass or @Embeddable annotation on it and will be inside of a persistence.xml).
* If it it should have, it will add the fully qualified classname of that class to the transformedClassNames list.
*
* <p>
* This is a validation check to ensure that the class transformers are actually working properly
*
* @author Andre Azzolini (apazzolini)
*/
Expand Down Expand Up @@ -69,12 +77,11 @@ public byte[] transform(ClassLoader loader, String className, Class<?> classBein
while(itr.hasNext()) {
Object object = itr.next();
if (AnnotationsAttribute.class.isAssignableFrom(object.getClass())) {
for (Annotation annotation : ((AnnotationsAttribute) object).getAnnotations()) {
if (annotation.getTypeName().equals(Entity.class.getName())) {
LOG.trace("Marking " + convertedClassName + " as transformed");
transformedClassNames.add(convertedClassName);
break check;
}
boolean containsTypeLevelAnnotation = containsTypeLevelPersistenceAnnotation(((AnnotationsAttribute) object).getAnnotations());
if (containsTypeLevelAnnotation) {
LOG.debug("Marking " + convertedClassName + " as transformed");
transformedClassNames.add(convertedClassName);
break check;
}
}
}
Expand All @@ -88,6 +95,17 @@ public byte[] transform(ClassLoader loader, String className, Class<?> classBein
return null;
}

protected boolean containsTypeLevelPersistenceAnnotation(Annotation[] annotations) {
for (Annotation annotation : annotations) {
if (annotation.getTypeName().equals(Entity.class.getName())
|| annotation.getTypeName().equals(Embeddable.class.getName())
|| annotation.getTypeName().equals(MappedSuperclass.class.getName())) {
return true;
}
}
return false;
}

protected boolean isIgnored(String convertedClassName) {
boolean isValidPattern = true;
List<DirectCopyIgnorePattern> matchedPatterns = new ArrayList<DirectCopyIgnorePattern>();
Expand Down

0 comments on commit 11e35f7

Please sign in to comment.