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 _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.

View File

@ -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.

View File

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

View File

@ -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.
*/

View File

@ -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;
}
}