diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataDefaults.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataDefaults.java index 2dc5e9c88..14dd20671 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataDefaults.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataDefaults.java @@ -45,8 +45,6 @@ public abstract class AbstractMetaDataDefaults private boolean _interface = true; private boolean _pcRegistry = true; private int _callback = CALLBACK_RETHROW; - private boolean _allowsMultipleMethodsOnSameCallback = true; - private boolean _allowsMissingCallbackConstructor = true; /** * Whether to attempt to use the information from registered classes @@ -354,22 +352,6 @@ public abstract class AbstractMetaDataDefaults return UnsupportedOperationException.class; } - public boolean getAllowsMultipleMethodsOnSameCallback() { - return _allowsMultipleMethodsOnSameCallback; - } - - public void setAllowsMultipleMethodsOnSameCallback(boolean flag) { - _allowsMultipleMethodsOnSameCallback = flag; - } - - public boolean getAllowsMissingCallbackConstructor() { - return _allowsMissingCallbackConstructor; - } - - public void setAllowsMissingCallbackConstructor(boolean flag) { - _allowsMissingCallbackConstructor = flag; - } - /** * Helper method; returns true if the given class appears to be * user-defined. diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java index 9c65c003c..077258fb4 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java @@ -50,18 +50,6 @@ public interface MetaDataDefaults */ public boolean getCallbacksBeforeListeners(int type); - /** - * Flags if multiple methods of the same class can handle the same - * callback event. - */ - public boolean getAllowsMultipleMethodsOnSameCallback(); - - /** - * Flags if it allowed for the callback listener class not to have a no-arg - * constructor. - */ - public boolean getAllowsMissingCallbackConstructor(); - /** * Whether to ignore members which are not persistent by default * during metadata population. Defaults to true. diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java index 5f4440903..2524f312a 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java @@ -122,12 +122,4 @@ public class NoneMetaDataFactory public Class getUnimplementedExceptionType() { return null; } - - public boolean getAllowsMultipleMethodsOnSameCallback() { - return true; - } - - public boolean getAllowsMissingCallbackConstructor() { - return true; - } } diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java index f9619cce0..7e8e85d43 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java @@ -843,8 +843,6 @@ public class AnnotationPersistenceMetaDataParser boolean result = true; if (callbacks == null || callbacks.isEmpty()) return true; - MetaDataDefaults defaults = getRepository().getMetaDataFactory(). - getDefaults(); for (LifecycleCallbacks lc: callbacks) { if (!(lc instanceof MethodLifecycleCallbacks)) continue; @@ -854,9 +852,10 @@ public class AnnotationPersistenceMetaDataParser Object[] args = new Object[]{method.getDeclaringClass() .getName(), method.getName(), exists.getName(), tag.toString()}; - if (defaults.getAllowsMultipleMethodsOnSameCallback()) { - _log.warn(_loc.get("multiple-methods-on-callback", - args)); + PersistenceMetaDataDefaults defaults = getDefaults(); + if (defaults == null || + defaults.getAllowsMultipleMethodsOnSameCallback()) { + _log.warn(_loc.get("multiple-methods-on-callback", args)); } else { throw new UserException( _loc.get("multiple-methods-on-callback-error", args)); @@ -867,14 +866,14 @@ public class AnnotationPersistenceMetaDataParser } private boolean verifyHasNoArgConstructor(Class cls) { - MetaDataDefaults defaults = getRepository().getMetaDataFactory(). - getDefaults(); try { cls.getConstructor(new Class[]{}); return true; } catch (Throwable t) { + PersistenceMetaDataDefaults defaults = getDefaults(); Message msg = _loc.get("missing-no-arg-constructor", cls.getName()); - if (defaults.getAllowsMissingCallbackConstructor()) + if (defaults == null || + defaults.getAllowsMissingCallbackConstructor()) _log.warn(msg); else throw new UserException(msg, t); @@ -882,6 +881,14 @@ public class AnnotationPersistenceMetaDataParser return false; } + private PersistenceMetaDataDefaults getDefaults() { + MetaDataDefaults defaults = getRepository().getMetaDataFactory(). + getDefaults(); + if (defaults instanceof PersistenceMetaDataDefaults) + return (PersistenceMetaDataDefaults)defaults; + return null; + } + /** * Store lifecycle metadata. */ diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java index b077d6819..7cec059c4 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java @@ -57,10 +57,14 @@ import org.apache.openjpa.util.MetaDataException; * * @author Patrick Linskey * @author Abe White + * @nojavadoc */ -class PersistenceMetaDataDefaults +public class PersistenceMetaDataDefaults extends AbstractMetaDataDefaults { + private boolean _allowsMultipleMethodsOnSameCallback; + private boolean _allowsMissingCallbackConstructor; + private static Localizer _loc = Localizer.forPackage (PersistenceMetaDataDefaults.class); @@ -93,6 +97,8 @@ class PersistenceMetaDataDefaults public PersistenceMetaDataDefaults() { setCallbackMode(CALLBACK_RETHROW | CALLBACK_ROLLBACK | CALLBACK_FAIL_FAST); + _allowsMultipleMethodsOnSameCallback = true; + _allowsMissingCallbackConstructor = true; } /** @@ -265,4 +271,31 @@ class PersistenceMetaDataDefaults return false; return true; } + + /** + * Flags if multiple methods of the same class can handle the same + * callback event. + */ + public boolean getAllowsMultipleMethodsOnSameCallback() { + return _allowsMultipleMethodsOnSameCallback; + } + + public void setAllowsMultipleMethodsOnSameCallback(boolean flag) { + _allowsMultipleMethodsOnSameCallback = flag; + } + + /** + * Flags if it allowed for the callback listener class not to have a no-arg + * constructor. + */ + + public boolean getAllowsMissingCallbackConstructor() { + return _allowsMissingCallbackConstructor; + } + + public void setAllowsMissingCallbackConstructor(boolean flag) { + _allowsMissingCallbackConstructor = flag; + } + + }