OPENJPA-293. More-eager failures.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@567889 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Patrick Linskey 2007-08-21 00:54:44 +00:00
parent dda1e8ef6f
commit ede9dcbd61
3 changed files with 28 additions and 18 deletions

View File

@ -19,24 +19,25 @@
package org.apache.openjpa.enhance;
import java.io.IOException;
import java.util.Map;
import java.util.HashMap;
import java.util.Collection;
import java.util.List;
import java.util.Collections;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.openjpa.conf.OpenJPAConfiguration;
import org.apache.openjpa.lib.util.JavaVersions;
import org.apache.openjpa.lib.util.BytecodeWriter;
import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.lib.log.Log;
import org.apache.openjpa.util.GeneratedClasses;
import org.apache.openjpa.util.InternalException;
import org.apache.openjpa.lib.util.BytecodeWriter;
import org.apache.openjpa.lib.util.JavaVersions;
import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.meta.ClassMetaData;
import org.apache.openjpa.meta.FieldMetaData;
import org.apache.openjpa.meta.JavaTypes;
import org.apache.openjpa.util.GeneratedClasses;
import org.apache.openjpa.util.InternalException;
import org.apache.openjpa.util.UserException;
import serp.bytecode.BCClass;
/**
@ -62,9 +63,10 @@ public class ManagedClassSubclasser {
* will need to do state comparisons to detect changes to newly inserted
* instances after a flush has been called.
*
* @return the new subclasses, or <code>null</code> if subclassing is
* disabled in <code>conf</code> or <code>classes</code> is
* <code>null</code>.
* @return the new subclasses, or <code>null</code> if <code>classes</code>
* is <code>null</code>.
* @throws UserException if <code>conf</code> requires build-time
* enhancement and <code>classes</code> includes unenhanced types.
*
* @since 1.0.0
*/
@ -76,8 +78,16 @@ public class ManagedClassSubclasser {
return null;
if (classes.size() == 0)
return Collections.EMPTY_LIST;
if (!conf.getRuntimeClassOptimization())
if (!conf.getRuntimeClassOptimization()) {
Collection unenhanced = new ArrayList();
for (Class cls : classes)
if (!PersistenceCapable.class.isAssignableFrom(cls))
unenhanced.add(cls);
if (unenhanced.size() > 0)
throw new UserException(_loc.get(
"runtime-optimization-disabled", unenhanced));
return null;
}
Log log = conf.getLog(OpenJPAConfiguration.LOG_ENHANCE);
boolean redefine = ClassRedefiner.canRedefineClasses();

View File

@ -38,6 +38,9 @@ detach-custom-extern: Type "{0}" is set to detach on serialize, but implements \
a custom readExternal and/or writeExternal method. You cannot use custom \
serialization with detachment.
enhance-start: Enhancing type "{0}".
runtime-optimization-disabled: This configuration disallows runtime \
optimization, but the following listed types were not enhanced at build \
time or at class load time with a javaagent: "{0}".
enhance-and-subclass-and-redef-start: Creating subclass and redefining methods \
for "{0}". This means that your application will be less efficient \
than it would if you ran the OpenJPA enhancer.

View File

@ -33,10 +33,7 @@ public class TestEnhancementConfiguration
UnenhancedFieldAccess.class, CLEAR_TABLES);
assertFalse(ImplHelper.isManagedType(emf.getConfiguration(),
UnenhancedFieldAccess.class));
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.persist(new UnenhancedFieldAccess());
em.getTransaction().rollback();
emf.createEntityManager().close();
fail("should not be possible to fully-initialize a system " +
"that depends on unenhanced types but disables runtime" +
"redefinition.");