Moved Entity Listener constraints from MetaDataDefaults in kernel to JPA facade PersistenceMetaDataDefaults

git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@450731 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Pinaki Poddar 2006-09-28 07:24:11 +00:00
parent 24c51d9fe6
commit 98d1da1fba
5 changed files with 49 additions and 47 deletions

View File

@ -45,8 +45,6 @@ public abstract class AbstractMetaDataDefaults
private boolean _interface = true; private boolean _interface = true;
private boolean _pcRegistry = true; private boolean _pcRegistry = true;
private int _callback = CALLBACK_RETHROW; private int _callback = CALLBACK_RETHROW;
private boolean _allowsMultipleMethodsOnSameCallback = true;
private boolean _allowsMissingCallbackConstructor = true;
/** /**
* Whether to attempt to use the information from registered classes * Whether to attempt to use the information from registered classes
@ -354,22 +352,6 @@ public abstract class AbstractMetaDataDefaults
return UnsupportedOperationException.class; 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 * Helper method; returns true if the given class appears to be
* user-defined. * user-defined.

View File

@ -50,18 +50,6 @@ public interface MetaDataDefaults
*/ */
public boolean getCallbacksBeforeListeners(int type); 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 * Whether to ignore members which are not persistent by default
* during metadata population. Defaults to true. * during metadata population. Defaults to true.

View File

@ -122,12 +122,4 @@ public class NoneMetaDataFactory
public Class getUnimplementedExceptionType() { public Class getUnimplementedExceptionType() {
return null; return null;
} }
public boolean getAllowsMultipleMethodsOnSameCallback() {
return true;
}
public boolean getAllowsMissingCallbackConstructor() {
return true;
}
} }

View File

@ -843,8 +843,6 @@ public class AnnotationPersistenceMetaDataParser
boolean result = true; boolean result = true;
if (callbacks == null || callbacks.isEmpty()) if (callbacks == null || callbacks.isEmpty())
return true; return true;
MetaDataDefaults defaults = getRepository().getMetaDataFactory().
getDefaults();
for (LifecycleCallbacks lc: callbacks) { for (LifecycleCallbacks lc: callbacks) {
if (!(lc instanceof MethodLifecycleCallbacks)) if (!(lc instanceof MethodLifecycleCallbacks))
continue; continue;
@ -854,9 +852,10 @@ public class AnnotationPersistenceMetaDataParser
Object[] args = new Object[]{method.getDeclaringClass() Object[] args = new Object[]{method.getDeclaringClass()
.getName(), method.getName(), exists.getName(), .getName(), method.getName(), exists.getName(),
tag.toString()}; tag.toString()};
if (defaults.getAllowsMultipleMethodsOnSameCallback()) { PersistenceMetaDataDefaults defaults = getDefaults();
_log.warn(_loc.get("multiple-methods-on-callback", if (defaults == null ||
args)); defaults.getAllowsMultipleMethodsOnSameCallback()) {
_log.warn(_loc.get("multiple-methods-on-callback", args));
} else { } else {
throw new UserException( throw new UserException(
_loc.get("multiple-methods-on-callback-error", args)); _loc.get("multiple-methods-on-callback-error", args));
@ -867,14 +866,14 @@ public class AnnotationPersistenceMetaDataParser
} }
private boolean verifyHasNoArgConstructor(Class cls) { private boolean verifyHasNoArgConstructor(Class cls) {
MetaDataDefaults defaults = getRepository().getMetaDataFactory().
getDefaults();
try { try {
cls.getConstructor(new Class[]{}); cls.getConstructor(new Class[]{});
return true; return true;
} catch (Throwable t) { } catch (Throwable t) {
PersistenceMetaDataDefaults defaults = getDefaults();
Message msg = _loc.get("missing-no-arg-constructor", cls.getName()); Message msg = _loc.get("missing-no-arg-constructor", cls.getName());
if (defaults.getAllowsMissingCallbackConstructor()) if (defaults == null ||
defaults.getAllowsMissingCallbackConstructor())
_log.warn(msg); _log.warn(msg);
else else
throw new UserException(msg, t); throw new UserException(msg, t);
@ -882,6 +881,14 @@ public class AnnotationPersistenceMetaDataParser
return false; return false;
} }
private PersistenceMetaDataDefaults getDefaults() {
MetaDataDefaults defaults = getRepository().getMetaDataFactory().
getDefaults();
if (defaults instanceof PersistenceMetaDataDefaults)
return (PersistenceMetaDataDefaults)defaults;
return null;
}
/** /**
* Store lifecycle metadata. * Store lifecycle metadata.
*/ */

View File

@ -57,10 +57,14 @@ import org.apache.openjpa.util.MetaDataException;
* *
* @author Patrick Linskey * @author Patrick Linskey
* @author Abe White * @author Abe White
* @nojavadoc
*/ */
class PersistenceMetaDataDefaults public class PersistenceMetaDataDefaults
extends AbstractMetaDataDefaults { extends AbstractMetaDataDefaults {
private boolean _allowsMultipleMethodsOnSameCallback;
private boolean _allowsMissingCallbackConstructor;
private static Localizer _loc = Localizer.forPackage private static Localizer _loc = Localizer.forPackage
(PersistenceMetaDataDefaults.class); (PersistenceMetaDataDefaults.class);
@ -93,6 +97,8 @@ class PersistenceMetaDataDefaults
public PersistenceMetaDataDefaults() { public PersistenceMetaDataDefaults() {
setCallbackMode(CALLBACK_RETHROW | CALLBACK_ROLLBACK | setCallbackMode(CALLBACK_RETHROW | CALLBACK_ROLLBACK |
CALLBACK_FAIL_FAST); CALLBACK_FAIL_FAST);
_allowsMultipleMethodsOnSameCallback = true;
_allowsMissingCallbackConstructor = true;
} }
/** /**
@ -265,4 +271,31 @@ class PersistenceMetaDataDefaults
return false; return false;
return true; 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;
}
} }