Package org.apache.openjpa.meta
Class AbstractMetaDataDefaults
- java.lang.Object
-
- org.apache.openjpa.meta.AbstractMetaDataDefaults
-
- All Implemented Interfaces:
CallbackModes
,MetaDataDefaults
- Direct Known Subclasses:
PersistenceMetaDataDefaults
public abstract class AbstractMetaDataDefaults extends java.lang.Object implements MetaDataDefaults
Abstract implementation provides a set of generic utilities for detecting persistence meta-data of Field/Member. Also provides bean-style properties such as access style or identity type to be used by default when such information is not derivable from available meta-data.- Author:
- Abe White, Pinaki Poddar
-
-
Field Summary
-
Fields inherited from interface org.apache.openjpa.event.CallbackModes
CALLBACK_FAIL_FAST, CALLBACK_IGNORE, CALLBACK_LOG, CALLBACK_RETHROW, CALLBACK_ROLLBACK
-
-
Constructor Summary
Constructors Constructor Description AbstractMetaDataDefaults()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.lang.reflect.Member
getBackingMember(FieldMetaData fmd)
Gets the backing member of the given field.int
getCallbackMode()
What to do on lifecycle callback exceptions.boolean
getCallbacksBeforeListeners(int type)
If callbacks are fired before listeners for the given event type.int
getDefaultAccessType()
The default access type for base classes with ACCESS_UNKNOWN.int
getDefaultIdentityType()
The default identity type for unmapped classes without primary key fields.protected java.util.List<java.lang.String>
getFieldAccessNames(ClassMetaData meta)
Return the list of fields inmeta
that use field access, ornull
if a list of fields is unobtainable.static java.lang.String
getFieldName(java.lang.reflect.Member member)
Return the field name for the given member.boolean
getIgnoreNonPersistent()
protected abstract java.util.List<java.lang.reflect.Member>
getPersistentMembers(ClassMetaData meta, boolean ignoreTransient)
protected java.util.List<java.lang.String>
getPropertyAccessNames(ClassMetaData meta)
Return the list of methods inmeta
that use property access, ornull
if a list of methods is unobtainable.java.lang.Class<?>
getUnimplementedExceptionType()
Return a runtime exception class to throw for un-implemented managed interface methods.boolean
getUsePCRegistry()
Whether to attempt to use the information from registered classes to populate metadata defaults.static boolean
isBoolean(java.lang.Class<?> cls)
static boolean
isBooleanGetter(java.lang.reflect.Method method)
Affirms if the given method matches the following signaturepublic boolean isXXX()
public Boolean isXXX()
boolean
isDataStoreObjectIdFieldUnwrapped()
Whether the field in the object id class corresponding to a datastore id persistence-capable primary key field is the simple datastore id value of the related instance.boolean
isDeclaredInterfacePersistent()
Whether declared interfaces of a class are treated as persistent types.protected abstract boolean
isDefaultPersistent(ClassMetaData meta, java.lang.reflect.Member member, java.lang.String name, boolean ignoreTransient)
Return true if the given member is persistent by default.static boolean
isGetter(java.lang.reflect.Method method, boolean includePrivate)
Affirms if the given method signature matches bean-style getter method signature.
public T getXXX()
where T is any non-void type.
or
public T isXXX()
where T is boolean or Boolean.static boolean
isNormalGetter(java.lang.reflect.Method method)
Affirms if the given method matches the following signaturepublic T getXXX()
where T is any non-void type.protected boolean
isReservedFieldName(java.lang.String name)
Returns true if the given field name is reserved for unmanaged fields.protected static boolean
isUserDefined(java.lang.Class<?> cls)
Helper method; returns true if the given class appears to be user-defined.void
populate(ClassMetaData meta, int access)
Populate the given metadata with default settings.void
populate(ClassMetaData meta, int access, boolean ignoreTransient)
Populate the given metadata with default settings.protected void
populate(FieldMetaData fmd)
void
setCallbackMode(int mode)
void
setCallbackMode(int mode, boolean on)
void
setDataStoreObjectIdFieldUnwrapped(boolean unwrapped)
void
setDeclaredInterfacePersistent(boolean pers)
void
setDefaultAccessType(int access)
The default access type for base classes with ACCESS_UNKNOWN.void
setDefaultIdentityType(int identity)
The default identity type for unmapped classes without primary key fields.void
setIgnoreNonPersistent(boolean ignore)
Whether to ignore members which are not persistent by default during metadata population.void
setUsePCRegistry(boolean pcRegistry)
Whether to attempt to use the information from registered classes to populate metadata defaults.static boolean
startsWith(java.lang.String full, java.lang.String head)
Affirms if the given full string starts with the given head.static java.util.List<java.lang.String>
toNames(java.util.List<? extends java.lang.reflect.Member> members)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.openjpa.meta.MetaDataDefaults
getDefaultSchema, getMemberByProperty, isAbstractMappingUniDirectional, isDefaultCascadePersistEnabled, isNonDefaultMappingAllowed, setDefaultCascadePersistEnabled, setDefaultSchema
-
-
-
-
Method Detail
-
getUsePCRegistry
public boolean getUsePCRegistry()
Whether to attempt to use the information from registered classes to populate metadata defaults. Defaults to true.
-
setUsePCRegistry
public void setUsePCRegistry(boolean pcRegistry)
Whether to attempt to use the information from registered classes to populate metadata defaults. Defaults to true.
-
getDefaultAccessType
public int getDefaultAccessType()
The default access type for base classes with ACCESS_UNKNOWN. ACCESS_FIELD by default.- Specified by:
getDefaultAccessType
in interfaceMetaDataDefaults
-
setDefaultAccessType
public void setDefaultAccessType(int access)
The default access type for base classes with ACCESS_UNKNOWN. ACCESS_FIELD by default.
-
getDefaultIdentityType
public int getDefaultIdentityType()
The default identity type for unmapped classes without primary key fields. ID_UNKNOWN by default.- Specified by:
getDefaultIdentityType
in interfaceMetaDataDefaults
-
setDefaultIdentityType
public void setDefaultIdentityType(int identity)
The default identity type for unmapped classes without primary key fields. ID_UNKNOWN by default.
-
getCallbackMode
public int getCallbackMode()
Description copied from interface:MetaDataDefaults
What to do on lifecycle callback exceptions.- Specified by:
getCallbackMode
in interfaceMetaDataDefaults
-
setCallbackMode
public void setCallbackMode(int mode)
-
setCallbackMode
public void setCallbackMode(int mode, boolean on)
-
getCallbacksBeforeListeners
public boolean getCallbacksBeforeListeners(int type)
Description copied from interface:MetaDataDefaults
If callbacks are fired before listeners for the given event type. Defaults to false.- Specified by:
getCallbacksBeforeListeners
in interfaceMetaDataDefaults
-
isDeclaredInterfacePersistent
public boolean isDeclaredInterfacePersistent()
Description copied from interface:MetaDataDefaults
Whether declared interfaces of a class are treated as persistent types. Defaults to true.- Specified by:
isDeclaredInterfacePersistent
in interfaceMetaDataDefaults
-
setDeclaredInterfacePersistent
public void setDeclaredInterfacePersistent(boolean pers)
-
isDataStoreObjectIdFieldUnwrapped
public boolean isDataStoreObjectIdFieldUnwrapped()
Description copied from interface:MetaDataDefaults
Whether the field in the object id class corresponding to a datastore id persistence-capable primary key field is the simple datastore id value of the related instance. Defaults to false.- Specified by:
isDataStoreObjectIdFieldUnwrapped
in interfaceMetaDataDefaults
-
setDataStoreObjectIdFieldUnwrapped
public void setDataStoreObjectIdFieldUnwrapped(boolean unwrapped)
-
getIgnoreNonPersistent
public boolean getIgnoreNonPersistent()
-
setIgnoreNonPersistent
public void setIgnoreNonPersistent(boolean ignore)
Description copied from interface:MetaDataDefaults
Whether to ignore members which are not persistent by default during metadata population. Defaults to true.- Specified by:
setIgnoreNonPersistent
in interfaceMetaDataDefaults
-
populate
public void populate(ClassMetaData meta, int access)
Description copied from interface:MetaDataDefaults
Populate the given metadata with default settings.- Specified by:
populate
in interfaceMetaDataDefaults
access
- access type constant fromClassMetaData
-
populate
public void populate(ClassMetaData meta, int access, boolean ignoreTransient)
Description copied from interface:MetaDataDefaults
Populate the given metadata with default settings.- Specified by:
populate
in interfaceMetaDataDefaults
access
- access type constant fromClassMetaData
-
getPersistentMembers
protected abstract java.util.List<java.lang.reflect.Member> getPersistentMembers(ClassMetaData meta, boolean ignoreTransient)
-
populate
protected void populate(FieldMetaData fmd)
-
getFieldAccessNames
protected java.util.List<java.lang.String> getFieldAccessNames(ClassMetaData meta)
Return the list of fields inmeta
that use field access, ornull
if a list of fields is unobtainable. An empty list should be returned if the list of fields is obtainable, but there happens to be no field access inmeta
. This is used for error reporting purposes only, so need not be efficient. This implementation returnsnull
.
-
getPropertyAccessNames
protected java.util.List<java.lang.String> getPropertyAccessNames(ClassMetaData meta)
Return the list of methods inmeta
that use property access, ornull
if a list of methods is unobtainable. An empty list should be returned if the list of methods is obtainable, but there happens to be no property access inmeta
. This is used for error reporting purposes only, so need not be efficient. This implementation returnsnull
.
-
getFieldName
public static java.lang.String getFieldName(java.lang.reflect.Member member)
Return the field name for the given member. This will only be invoked on members of the right type (field vs. method). Return null if the member cannot be managed. Default behavior: For fields, returns the field name. For getter methods, returns the minus "get" or "is" with the next letter lower-cased. For other methods, returns null.
-
isReservedFieldName
protected boolean isReservedFieldName(java.lang.String name)
Returns true if the given field name is reserved for unmanaged fields.
-
isDefaultPersistent
protected abstract boolean isDefaultPersistent(ClassMetaData meta, java.lang.reflect.Member member, java.lang.String name, boolean ignoreTransient)
Return true if the given member is persistent by default. This will only be invoked on members of the right type (field vs. method). Returns false if member is static or final by default.- Parameters:
name
- the field name fromgetFieldName(java.lang.reflect.Member)
-
getBackingMember
public java.lang.reflect.Member getBackingMember(FieldMetaData fmd)
Gets the backing member of the given field. If the field has not been assigned a backing member then get either the instance field or the getter method depending upon the access style of the defining class.
Defining class is used instead of declaring class because this method may be invoked during parsing phase when declaring metadata may not be available.- Specified by:
getBackingMember
in interfaceMetaDataDefaults
-
getUnimplementedExceptionType
public java.lang.Class<?> getUnimplementedExceptionType()
Description copied from interface:MetaDataDefaults
Return a runtime exception class to throw for un-implemented managed interface methods.- Specified by:
getUnimplementedExceptionType
in interfaceMetaDataDefaults
-
isUserDefined
protected static boolean isUserDefined(java.lang.Class<?> cls)
Helper method; returns true if the given class appears to be user-defined.
-
isNormalGetter
public static boolean isNormalGetter(java.lang.reflect.Method method)
Affirms if the given method matches the following signaturepublic T getXXX()
where T is any non-void type.
-
isBooleanGetter
public static boolean isBooleanGetter(java.lang.reflect.Method method)
Affirms if the given method matches the following signaturepublic boolean isXXX()
public Boolean isXXX()
-
isGetter
public static boolean isGetter(java.lang.reflect.Method method, boolean includePrivate)
Affirms if the given method signature matches bean-style getter method signature.
public T getXXX()
where T is any non-void type.
or
public T isXXX()
where T is boolean or Boolean.
-
startsWith
public static boolean startsWith(java.lang.String full, java.lang.String head)
Affirms if the given full string starts with the given head.
-
isBoolean
public static boolean isBoolean(java.lang.Class<?> cls)
-
toNames
public static java.util.List<java.lang.String> toNames(java.util.List<? extends java.lang.reflect.Member> members)
-
-