public class InheritancePolicy extends Object implements Serializable, Cloneable
Purpose: Allows customization of an object's inheritance. The primary supported inheritance model uses a class type indicator column in the table that stores the object's class type. The class-to-type mapping is specified on this policy. The full class name can also be used for the indicator instead of the mapping.
Each subclass can either share their parents table, or in addition add their own table(s).
For legacy models a customized inheritance class-extractor can be provided. This allows Java code to be used to compute the class type to use for a row. When this customized inheritance model is used an only-instances and with-all-subclasses filter expression may be required for concrete and branch querying.
Modifier and Type | Field and Description |
---|---|
protected Vector |
allChildClassIndicators |
protected Vector |
allTables |
protected Vector |
childDescriptors |
protected Expression |
childrenJoinExpression |
protected List |
childrenTables |
protected Map |
childrenTablesJoinExpressions |
protected ClassExtractor |
classExtractor
Allow for class extraction method to be specified.
|
protected DatabaseField |
classIndicatorField |
protected Map |
classIndicatorMapping |
protected Map |
classNameIndicatorMapping |
protected ClassDescriptor |
descriptor |
protected boolean |
isJoinedStrategy |
protected Expression |
onlyInstancesExpression |
protected Class |
parentClass |
protected String |
parentClassName |
protected ClassDescriptor |
parentDescriptor |
protected DatabaseTable |
readAllSubclassesView |
protected boolean |
shouldAlwaysUseOuterJoin |
protected Boolean |
shouldReadSubclasses |
protected boolean |
shouldUseClassNameAsIndicator |
protected boolean |
useDescriptorsToValidateInheritedObjects |
protected Expression |
withAllSubclassesExpression |
Constructor and Description |
---|
InheritancePolicy()
INTERNAL:
Create a new policy.
|
InheritancePolicy(ClassDescriptor descriptor)
INTERNAL:
Create a new policy.
|
Modifier and Type | Method and Description |
---|---|
void |
addChildDescriptor(ClassDescriptor childDescriptor)
INTERNAL:
Add child descriptor to the parent descriptor.
|
protected void |
addChildTableJoinExpression(DatabaseTable table,
Expression expression)
INTERNAL:
childrenTablesJoinExpressions, childrenTables, allTables and childrenJoinExpression
are created simultaneously and kept in sync.
|
void |
addChildTableJoinExpressionToAllParents(DatabaseTable table,
Expression expression)
INTERNAL:
call addChildTableJoinExpression on all parents
|
void |
addClassIndicator(Class childClass,
Object typeValue)
PUBLIC:
Add a class indicator for the root classes subclass.
|
void |
addClassIndicatorFieldToInsertRow(AbstractRecord databaseRow)
INTERNAL:
Add abstract class indicator information to the database row.
|
void |
addClassIndicatorFieldToRow(AbstractRecord databaseRow)
INTERNAL:
Add abstract class indicator information to the database row.
|
protected void |
addClassIndicatorTypeToParent(Object indicator)
INTERNAL:
Post initialize the child descriptors
|
void |
addClassNameIndicator(String childClassName,
Object typeValue)
INTERNAL:
Add the class name reference by class name, used by the MW.
|
protected void |
addFieldsToParent(Vector fields)
INTERNAL:
Recursively adds fields to all the parents
|
void |
appendWithAllSubclassesExpression(SQLSelectStatement selectStatement)
INTERNAL:
Append the branch with all subclasses expression to the statement.
|
SQLSelectStatement |
buildClassIndicatorSelectStatement(ObjectLevelReadQuery query)
INTERNAL:
Return a select statement that will be used to query the class indicators required to query.
|
SQLSelectStatement |
buildViewSelectStatement(ObjectLevelReadQuery query)
INTERNAL:
Build a select statement for all subclasses on the view using the same
selection criteria as the query.
|
Class |
classFromRow(AbstractRecord rowFromDatabase,
AbstractSession session)
INTERNAL:
This method is invoked only for the abstract descriptors.
|
Object |
clone()
INTERNAL:
Clone the policy
|
void |
convertClassNamesToClasses(ClassLoader classLoader)
INTERNAL:
Convert all the class-name-based settings in this InheritancePolicy to actual class-based
settings.
|
void |
dontReadSubclassesOnQueries()
PUBLIC:
Set the descriptor to only read instance of itself when queried.
|
void |
dontUseClassNameAsIndicator()
PUBLIC:
Set the descriptor not to use the class' full name as the indicator.
|
protected Vector |
getAllChildClassIndicators()
INTERNAL:
Stores class indicators for all child and children's children.
|
Vector |
getAllChildDescriptors()
INTERNAL:
Returns all the child descriptors, even descriptors for subclasses of
subclasses.
|
protected Vector |
getAllChildDescriptors(Vector allChildDescriptors)
INTERNAL:
Recursive subroutine of getAllChildDescriptors.
|
Vector |
getAllTables()
INTERNAL:
all tables for reference class plus childrenTables
|
Vector |
getChildDescriptors()
INTERNAL:
Return all the immediate child descriptors.
|
Expression |
getChildrenJoinExpression()
INTERNAL:
all expressions from childrenTablesJoinExpressions ANDed together
|
List |
getChildrenTables()
INTERNAL:
if reads subclasses, all tables for all read subclasses (indirect included).
|
Map |
getChildrenTablesJoinExpressions()
INTERNAL:
join expression for each child table, keyed by the table
|
protected Method |
getClassExtractionMethod()
INTERNAL:
Return all the classExtractionMethod
|
String |
getClassExtractionMethodName()
ADVANCED:
A class extraction method can be registered with the descriptor to override the default inheritance mechanism.
|
ClassExtractor |
getClassExtractor()
ADVANCED:
A class extractor can be registered with the descriptor to override the default inheritance mechanism.
|
Vector |
getClassIndicatorAssociations()
INTERNAL:
Return the class indicator associations for XML.
|
DatabaseField |
getClassIndicatorField()
INTERNAL:
Returns field that the class type indicator is store when using inheritence.
|
String |
getClassIndicatorFieldName()
PUBLIC:
Return the class indicator field name.
|
Map |
getClassIndicatorMapping()
INTERNAL:
Return the association of indicators and classes
|
Map |
getClassIndicatorMapping(ConversionManager conversionManager)
INTERNAL:
Return the association of indicators and classes using specified ConversionManager
|
protected Object |
getClassIndicatorValue()
INTERNAL:
Returns value of the abstract class indicator for the Java class.
|
protected Object |
getClassIndicatorValue(Class javaClass)
INTERNAL:
Returns the indicator field value for the given class
If no abstract indicator mapping is specified, use the class name.
|
Map |
getClassNameIndicatorMapping()
INTERNAL:
Return the mapping from class name to indicator, used by MW.
|
ClassDescriptor |
getDescriptor()
INTERNAL:
Returns the descriptor which the policy belongs to.
|
Expression |
getOnlyInstancesExpression()
ADVANCED:
Return the 'only instances expression'.
|
Class |
getParentClass()
PUBLIC:
Return the parent class.
|
String |
getParentClassName()
INTERNAL:
Return the parent class name.
|
ClassDescriptor |
getParentDescriptor()
INTERNAL:
Return the parent descirptor
|
DatabaseTable |
getReadAllSubclassesView()
INTERNAL:
The view can be used to optimize/customize the query for all subclasses where they have multiple tables.
|
String |
getReadAllSubclassesViewName()
ADVANCED:
The view can be used to optimize/customize the query for all subclasses where they have multiple tables.
|
ClassDescriptor |
getRootParentDescriptor()
INTERNAL:
Return the root parent descriptor
|
ClassDescriptor |
getSubclassDescriptor(Class theClass)
INTERNAL:
use aggregate in inheritance
|
boolean |
getUseDescriptorsToValidateInheritedObjects()
INTERNAL:
return if we should use the descriptor inheritance to determine
if an object can be returned from the identity map or not.
|
Expression |
getWithAllSubclassesExpression()
ADVANCED:
Return the Expression which gets all subclasses.
|
boolean |
hasChildren()
INTERNAL:
Check if descriptor has children
|
boolean |
hasClassExtractor()
INTERNAL:
|
boolean |
hasClassIndicator()
INTERNAL:
Checks if the class is invloved in inheritence
|
boolean |
hasMultipleTableChild()
INTERNAL:
Return if any children of this descriptor require information from another table
not specified at the parent level.
|
boolean |
hasView()
INTERNAL:
Return if a view is used for inheritance reads.
|
void |
initialize(AbstractSession session)
INTERNAL:
Initialized the inheritence properties of the descriptor once the mappings are initialized.
|
protected void |
initializeClassExtractor(AbstractSession session)
INTERNAL:
Setup the default classExtractionMethod, or if one was specified by the user make sure it is valid.
|
protected void |
initializeOnlyInstancesExpression()
INTERNAL:
Initialize the expression to use to check the specific type field.
|
protected void |
initializeWithAllSubclassesExpression()
INTERNAL:
Initialize the expression to use for queries to the class and its subclasses.
|
boolean |
isChildDescriptor()
INTERNAL:
Check if it is a child descriptor.
|
boolean |
isJoinedStrategy()
INTERNAL:
Indicate whether a single table or joined inheritance strategy is being used.
|
boolean |
isRootParentDescriptor()
INTERNAL:
Return whether or not is root parent descriptor
|
void |
postInitialize(AbstractSession session)
INTERNAL:
Initialized the inheritence properties that cannot be initialized
unitl after the mappings have been.
|
void |
preInitialize(AbstractSession session)
INTERNAL:
Allow the inheritence properties of the descriptor to be initialized.
|
void |
readSubclassesOnQueries()
PUBLIC:
Set the descriptor to read instance of itself and its subclasses when queried.
|
boolean |
requiresMultipleTableSubclassRead()
INTERNAL:
Return if this descriptor has children that define additional tables and needs to read them.
|
protected Vector |
selectAllRowUsingCustomMultipleTableSubclassRead(ReadAllQuery query)
INTERNAL:
Select all rows from a abstract table descriptor.
|
protected Vector |
selectAllRowUsingDefaultMultipleTableSubclassRead(ReadAllQuery query)
INTERNAL:
Select all rows from a abstract table descriptor.
|
Vector |
selectAllRowUsingMultipleTableSubclassRead(ReadAllQuery query)
INTERNAL:
Select all rows from a abstract table descriptor.
|
protected AbstractRecord |
selectOneRowUsingCustomMultipleTableSubclassRead(ReadObjectQuery query)
INTERNAL:
Select one rows from a abstract table descriptor.
|
protected AbstractRecord |
selectOneRowUsingDefaultMultipleTableSubclassRead(ReadObjectQuery query)
INTERNAL:
Select one row of any concrete subclass,
This must use two selects, the first retreives the type field only.
|
AbstractRecord |
selectOneRowUsingMultipleTableSubclassRead(ReadObjectQuery query)
INTERNAL:
Select one row of any concrete subclass,
This must use two selects, the first retreives the type field only.
|
protected void |
setAllChildClassIndicators(Vector allChildClassIndicators)
INTERNAL:
|
void |
setAlwaysUseOuterJoinForClassType(boolean choice)
PUBLIC:
Sets the inheritance policy to always use an outer join when quering across a relationship of class.
|
void |
setChildDescriptors(Vector theChildDescriptors)
INTERNAL:
|
void |
setClassExtractionMethodName(String staticClassClassExtractionMethod)
ADVANCED:
A class extraction method can be registered with the descriptor to override the default inheritance mechanism.
|
void |
setClassExtractor(ClassExtractor classExtractor)
ADVANCED:
A class extractor can be registered with the descriptor to override the default inheritance mechanism.
|
void |
setClassIndicatorAssociations(Vector classIndicatorAssociations)
INTERNAL:
Set the class indicator associations from reading the deployment XML.
|
void |
setClassIndicatorField(DatabaseField classIndicatorField)
ADVANCED:
To set the class indicator field.
|
void |
setClassIndicatorFieldName(String fieldName)
PUBLIC:
To set the class indicator field name.
|
void |
setClassIndicatorMapping(Map classIndicatorMapping)
PUBLIC:
Set the association of indicators and classes.
|
void |
setClassNameIndicatorMapping(Map classNameIndicatorMapping)
INTERNAL:
Set the class name indicator mapping, used by the MW.
|
void |
setDescriptor(ClassDescriptor descriptor)
INTERNAL:
Set the descriptor.
|
void |
setJoinedStrategy()
INTERNAL:
Used to indicate a JOINED inheritance strategy.
|
void |
setOnlyInstancesExpression(Expression onlyInstancesExpression)
ADVANCED:
Sets the expression used to select instance of the class only.
|
void |
setParentClass(Class parentClass)
PUBLIC:
Set the parent class.
|
void |
setParentClassName(String parentClassName)
INTERNAL:
Set the parent class name, used by MW to avoid referencing the real class for
deployment XML generation.
|
void |
setParentDescriptor(ClassDescriptor parentDescriptor)
INTERNAL:
|
protected void |
setReadAllSubclassesView(DatabaseTable readAllSubclassesView)
INTERNAL:
The view can be used to optimize/customize the query for all subclasses where they have multiple tables.
|
void |
setReadAllSubclassesViewName(String readAllSubclassesViewName)
ADVANCED:
The view can be used to optimize/customize the query for all subclasses where they have multiple tables.
|
void |
setShouldReadSubclasses(boolean shouldReadSubclasses)
PUBLIC:
Set the descriptor to read instance of itself and its subclasses when queried.
|
void |
setShouldReadSubclasses(Boolean shouldReadSubclasses)
INTERNAL:
Set the descriptor to read instance of itself and its subclasses when queried.
|
void |
setShouldUseClassNameAsIndicator(boolean shouldUseClassNameAsIndicator)
PUBLIC:
Set if the descriptor uses the classes fully qualified name as the indicator.
|
void |
setSingleTableStrategy()
INTERNAL:
Used to indicate a SINGLE_TABLE inheritance strategy.
|
void |
setUseDescriptorsToValidateInheritedObjects(boolean useDescriptorsToValidateInheritedObjects)
INTERNAL:
Sets if we should use the descriptor inheritance to determine
if an object can be returned from the identity map or not.
|
void |
setWithAllSubclassesExpression(Expression withAllSubclassesExpression)
ADVANCED:
Sets the expression to be used for querying for a class and all its subclasses.
|
boolean |
shouldAlwaysUseOuterJoin()
PUBLIC:
returns if the inheritance policy will always use an outerjoin when selecting class type
|
boolean |
shouldReadSubclasses()
PUBLIC:
Return true if this descriptor should read instances of itself and subclasses on queries.
|
Boolean |
shouldReadSubclassesValue()
INTERNAL:
Return true if this descriptor should read instances of itself and subclasses on queries.
|
boolean |
shouldUseClassNameAsIndicator()
PUBLIC:
Return true if the descriptor use the classes full name as the indicator.
|
String |
toString()
INTERNAL:
|
void |
useClassNameAsIndicator()
PUBLIC:
Set the descriptor to use the classes full name as the indicator.
|
protected Class parentClass
protected String parentClassName
protected ClassDescriptor parentDescriptor
protected Vector childDescriptors
protected transient DatabaseField classIndicatorField
protected transient Map classIndicatorMapping
protected transient Map classNameIndicatorMapping
protected transient boolean shouldUseClassNameAsIndicator
protected transient Boolean shouldReadSubclasses
protected transient DatabaseTable readAllSubclassesView
protected transient Vector allChildClassIndicators
protected transient Expression onlyInstancesExpression
protected transient Expression withAllSubclassesExpression
protected transient Vector allTables
protected transient List childrenTables
protected transient Map childrenTablesJoinExpressions
protected transient Expression childrenJoinExpression
protected transient ClassExtractor classExtractor
protected ClassDescriptor descriptor
protected boolean shouldAlwaysUseOuterJoin
protected boolean useDescriptorsToValidateInheritedObjects
protected boolean isJoinedStrategy
public InheritancePolicy()
public InheritancePolicy(ClassDescriptor descriptor)
public void addChildDescriptor(ClassDescriptor childDescriptor)
protected void addChildTableJoinExpression(DatabaseTable table, Expression expression)
public void addChildTableJoinExpressionToAllParents(DatabaseTable table, Expression expression)
public void addClassIndicator(Class childClass, Object typeValue)
public void addClassNameIndicator(String childClassName, Object typeValue)
public void addClassIndicatorFieldToInsertRow(AbstractRecord databaseRow)
public void addClassIndicatorFieldToRow(AbstractRecord databaseRow)
protected void addClassIndicatorTypeToParent(Object indicator)
protected void addFieldsToParent(Vector fields)
public SQLSelectStatement buildClassIndicatorSelectStatement(ObjectLevelReadQuery query)
public void appendWithAllSubclassesExpression(SQLSelectStatement selectStatement)
public SQLSelectStatement buildViewSelectStatement(ObjectLevelReadQuery query)
public Class classFromRow(AbstractRecord rowFromDatabase, AbstractSession session) throws DescriptorException
DescriptorException
public void convertClassNamesToClasses(ClassLoader classLoader)
classLoader
- public void dontReadSubclassesOnQueries()
public void dontUseClassNameAsIndicator()
protected Vector getAllChildClassIndicators()
public Vector getAllChildDescriptors()
protected Vector getAllChildDescriptors(Vector allChildDescriptors)
public List getChildrenTables()
public Map getChildrenTablesJoinExpressions()
public Expression getChildrenJoinExpression()
public Vector getAllTables()
public Vector getChildDescriptors()
protected Method getClassExtractionMethod()
public String getClassExtractionMethodName()
public ClassExtractor getClassExtractor()
public void setClassExtractor(ClassExtractor classExtractor)
public Vector getClassIndicatorAssociations()
public DatabaseField getClassIndicatorField()
public String getClassIndicatorFieldName()
public Map getClassIndicatorMapping()
public Map getClassIndicatorMapping(ConversionManager conversionManager)
public Map getClassNameIndicatorMapping()
protected Object getClassIndicatorValue()
protected Object getClassIndicatorValue(Class javaClass)
public ClassDescriptor getDescriptor()
public Expression getOnlyInstancesExpression()
public Class getParentClass()
public String getParentClassName()
public ClassDescriptor getParentDescriptor()
public DatabaseTable getReadAllSubclassesView()
public String getReadAllSubclassesViewName()
public ClassDescriptor getRootParentDescriptor()
public ClassDescriptor getSubclassDescriptor(Class theClass)
public boolean getUseDescriptorsToValidateInheritedObjects()
public Expression getWithAllSubclassesExpression()
public boolean hasChildren()
public boolean hasClassExtractor()
public boolean hasClassIndicator()
public boolean hasMultipleTableChild()
public boolean hasView()
public void initialize(AbstractSession session)
protected void initializeClassExtractor(AbstractSession session) throws DescriptorException
DescriptorException
protected void initializeOnlyInstancesExpression() throws DescriptorException
DescriptorException
protected void initializeWithAllSubclassesExpression() throws DescriptorException
DescriptorException
public boolean isChildDescriptor()
public boolean isJoinedStrategy()
public boolean isRootParentDescriptor()
public void postInitialize(AbstractSession session)
public void preInitialize(AbstractSession session) throws DescriptorException
DescriptorException
public void readSubclassesOnQueries()
public boolean requiresMultipleTableSubclassRead()
protected Vector selectAllRowUsingCustomMultipleTableSubclassRead(ReadAllQuery query) throws DatabaseException
DatabaseException
- - an error has occurred on the database.protected Vector selectAllRowUsingDefaultMultipleTableSubclassRead(ReadAllQuery query) throws DatabaseException, QueryException
DatabaseException
- - an error has occurred on the database.QueryException
public Vector selectAllRowUsingMultipleTableSubclassRead(ReadAllQuery query) throws DatabaseException
DatabaseException
- - an error has occurred on the database.protected AbstractRecord selectOneRowUsingCustomMultipleTableSubclassRead(ReadObjectQuery query) throws DatabaseException
DatabaseException
- - an error has occurred on the database.protected AbstractRecord selectOneRowUsingDefaultMultipleTableSubclassRead(ReadObjectQuery query) throws DatabaseException, QueryException
DatabaseException
QueryException
public AbstractRecord selectOneRowUsingMultipleTableSubclassRead(ReadObjectQuery query) throws DatabaseException, QueryException
DatabaseException
QueryException
protected void setAllChildClassIndicators(Vector allChildClassIndicators)
public void setChildDescriptors(Vector theChildDescriptors)
public void setClassExtractionMethodName(String staticClassClassExtractionMethod)
public void setClassIndicatorAssociations(Vector classIndicatorAssociations)
public void setClassIndicatorField(DatabaseField classIndicatorField)
public void setClassIndicatorFieldName(String fieldName)
public void setClassIndicatorMapping(Map classIndicatorMapping)
public void setClassNameIndicatorMapping(Map classNameIndicatorMapping)
public void setDescriptor(ClassDescriptor descriptor)
public void setJoinedStrategy()
public void setOnlyInstancesExpression(Expression onlyInstancesExpression)
public void setParentClass(Class parentClass)
public void setParentClassName(String parentClassName)
public void setParentDescriptor(ClassDescriptor parentDescriptor)
protected void setReadAllSubclassesView(DatabaseTable readAllSubclassesView)
public void setReadAllSubclassesViewName(String readAllSubclassesViewName)
public void setShouldReadSubclasses(Boolean shouldReadSubclasses)
public void setShouldReadSubclasses(boolean shouldReadSubclasses)
public void setShouldUseClassNameAsIndicator(boolean shouldUseClassNameAsIndicator)
public void setAlwaysUseOuterJoinForClassType(boolean choice)
public void setSingleTableStrategy()
public void setUseDescriptorsToValidateInheritedObjects(boolean useDescriptorsToValidateInheritedObjects)
public void setWithAllSubclassesExpression(Expression withAllSubclassesExpression)
public boolean shouldReadSubclasses()
public Boolean shouldReadSubclassesValue()
public boolean shouldAlwaysUseOuterJoin()
public boolean shouldUseClassNameAsIndicator()
public void useClassNameAsIndicator()
Copyright © 2023. All rights reserved.