Skip navigation links

Oracle TopLink Java API Reference
10g Release 3 (10.1.3.1)

B28219-01


oracle.toplink.descriptors
Class InheritancePolicy

java.lang.Object
  extended byoracle.toplink.publicinterface.InheritancePolicy
      extended byoracle.toplink.descriptors.InheritancePolicy

All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class InheritancePolicy
extends InheritancePolicy

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.

See Also:
Serialized Form

Method Summary
 void addClassIndicator(java.lang.Class childClass, java.lang.Object typeValue)
          PUBLIC: Add a class indicator for the root classes subclass.
 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.
 java.lang.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.
 java.lang.String getClassIndicatorFieldName()
          PUBLIC: Return the class indicator field name.
 Expression getOnlyInstancesExpression()
          ADVANCED: Return the 'only instances expression'.
 java.lang.Class getParentClass()
          PUBLIC: Return the parent class.
 java.lang.String getReadAllSubclassesViewName()
          ADVANCED: The view can be used to optimize/customize the query for all subclasses where they have multiple tables.
 Expression getWithAllSubclassesExpression()
          ADVANCED: Return the Expression which gets all subclasses.
 void readSubclassesOnQueries()
          PUBLIC: Set the descriptor to read instance of itself and its subclasses when queried.
 void setClassExtractionMethodName(java.lang.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 setClassIndicatorField(DatabaseField classIndicatorField)
          ADVANCED: To set the class indicator field.
 void setClassIndicatorFieldName(java.lang.String fieldName)
          PUBLIC: To set the class indicator field name.
 void setClassIndicatorMapping(java.util.Hashtable classIndicatorMapping)
          PUBLIC: Set the association of indicators and classes.
 void setOnlyInstancesExpression(Expression onlyInstancesExpression)
          ADVANCED: Sets the expression used to select instance of the class only.
 void setParentClass(java.lang.Class parentClass)
          PUBLIC: Set the parent class.
 void setReadAllSubclassesViewName(java.lang.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 setShouldUseClassNameAsIndicator(boolean shouldUseClassNameAsIndicator)
          PUBLIC: Set if the descriptor uses the classes fully qualified name as the indicator.
 void setWithAllSubclassesExpression(Expression withAllSubclassesExpression)
          ADVANCED: Sets the expression to be used for querying for a class and all its subclasses.
 boolean shouldReadSubclasses()
          PUBLIC: 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.
 void useClassNameAsIndicator()
          PUBLIC: Set the descriptor to use the classes full name as the indicator.

 

Methods inherited from class oracle.toplink.publicinterface.InheritancePolicy
setAlwaysUseOuterJoinForClassType, setClassIndicatorMapping, shouldAlwaysUseOuterJoin

 

Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait

 

Method Detail

addClassIndicator

public void addClassIndicator(java.lang.Class childClass,
                              java.lang.Object typeValue)
PUBLIC: Add a class indicator for the root classes subclass. The indicator is used to determine the class to use for a row read from the database, and to query only instances of a class from the database. Every concrete persistent subclass must have a single unique indicator defined for it. If the root class is concrete then it must also define an indicator. Only the root class's descriptor of the entire inheritance hierarchy can define the class indicator mapping.
Overrides:
addClassIndicator in class InheritancePolicy

dontReadSubclassesOnQueries

public void dontReadSubclassesOnQueries()
PUBLIC: Set the descriptor to only read instance of itself when queried. This is used with inheritance to configure the result of queries. By default this is true for root inheritance descriptors, and false for all others.
Overrides:
dontReadSubclassesOnQueries in class InheritancePolicy

dontUseClassNameAsIndicator

public void dontUseClassNameAsIndicator()
PUBLIC: Set the descriptor not to use the class' full name as the indicator. The class indicator is used with inheritance to determine the class from a row. By default a class indicator mapping is required, this can be set to true if usage of the class name is desired. The field must be of a large enough size to store the fully qualified class name.
Overrides:
dontUseClassNameAsIndicator in class InheritancePolicy

getClassExtractionMethodName

public java.lang.String getClassExtractionMethodName()
ADVANCED: A class extraction method can be registered with the descriptor to override the default inheritance mechanism. This allows for the class indicator field to not be used, and a user defined one instead. The method registered must be a static method on the class that the descriptor is for, the method must take DatabaseRow as argument, and must return the class to use for that row. This method will be used to decide which class to instantiate when reading from the database. It is the application's responsiblity to populate any typing information in the database required to determine the class from the row. If this method is used then the class indicator field and mapping cannot be used, also the descriptor's withAllSubclasses and onlyInstances expressions must also be setup correctly.
Overrides:
getClassExtractionMethodName in class InheritancePolicy
See Also:
setWithAllSubclassesExpression(Expression), setOnlyInstancesExpression(Expression)

getClassExtractor

public ClassExtractor getClassExtractor()
ADVANCED: A class extractor can be registered with the descriptor to override the default inheritance mechanism. This allows for the class indicator field to not be used, and a user defined one instead. The instance registered must extend the ClassExtractor class and implement the extractClass(Map) method, the method must take database row (Map) as argument, and must return the class to use for that row. This method will be used to decide which class to instantiate when reading from the database. It is the application's responsiblity to populate any typing information in the database required to determine the class from the row, such as usage of a direct or transformation mapping for the type fields. If this method is used then the class indicator field and mapping cannot be used, also the descriptor's withAllSubclasses and onlyInstances expressions must also be setup correctly.
Overrides:
getClassExtractor in class InheritancePolicy
See Also:
setWithAllSubclassesExpression(Expression), setOnlyInstancesExpression(Expression)

setClassExtractor

public void setClassExtractor(ClassExtractor classExtractor)
ADVANCED: A class extractor can be registered with the descriptor to override the default inheritance mechanism. This allows for the class indicator field to not be used, and a user defined one instead. The instance registered must extend the ClassExtractor class and implement the extractClass(Map) method, the method must take database row (Map) as argument, and must return the class to use for that row. This method will be used to decide which class to instantiate when reading from the database. It is the application's responsiblity to populate any typing information in the database required to determine the class from the row, such as usage of a direct or transformation mapping for the type fields. If this method is used then the class indicator field and mapping cannot be used, also the descriptor's withAllSubclasses and onlyInstances expressions must also be setup correctly.
Overrides:
setClassExtractor in class InheritancePolicy
See Also:
setWithAllSubclassesExpression(Expression), setOnlyInstancesExpression(Expression)

getClassIndicatorFieldName

public java.lang.String getClassIndicatorFieldName()
PUBLIC: Return the class indicator field name. This is the name of the field in the table that stores what type of object this is.
Overrides:
getClassIndicatorFieldName in class InheritancePolicy

getOnlyInstancesExpression

public Expression getOnlyInstancesExpression()
ADVANCED: Return the 'only instances expression'.
Overrides:
getOnlyInstancesExpression in class InheritancePolicy

getParentClass

public java.lang.Class getParentClass()
PUBLIC: Return the parent class.
Overrides:
getParentClass in class InheritancePolicy

getReadAllSubclassesViewName

public java.lang.String getReadAllSubclassesViewName()
ADVANCED: The view can be used to optimize/customize the query for all subclasses where they have multiple tables. This view can use outer joins or unions to combine the results of selecting from all of the subclass tables. If a view is not given then TopLink must make an individual call for each subclass.
Overrides:
getReadAllSubclassesViewName in class InheritancePolicy

getWithAllSubclassesExpression

public Expression getWithAllSubclassesExpression()
ADVANCED: Return the Expression which gets all subclasses.
Overrides:
getWithAllSubclassesExpression in class InheritancePolicy

readSubclassesOnQueries

public void readSubclassesOnQueries()
PUBLIC: Set the descriptor to read instance of itself and its subclasses when queried. This is used with inheritance to configure the result of queries. By default this is true for root inheritance descriptors, and false for all others.
Overrides:
readSubclassesOnQueries in class InheritancePolicy

setClassExtractionMethodName

public void setClassExtractionMethodName(java.lang.String staticClassClassExtractionMethod)
ADVANCED: A class extraction method can be registered with the descriptor to override the default inheritance mechanism. This allows for the class indicator field to not be used, and a user defined one instead. The method registered must be a static method on the class that the descriptor is for, the method must take DatabaseRow as argument, and must return the class to use for that row. This method will be used to decide which class to instantiate when reading from the database. It is the application's responsiblity to populate any typing information in the database required to determine the class from the row. If this method is used then the class indicator field and mapping cannot be used, also the descriptor's withAllSubclasses and onlyInstances expressions must also be setup correctly.
Overrides:
setClassExtractionMethodName in class InheritancePolicy
See Also:
setWithAllSubclassesExpression(Expression), setOnlyInstancesExpression(Expression)

setClassIndicatorField

public void setClassIndicatorField(DatabaseField classIndicatorField)
ADVANCED: To set the class indicator field. This can be used for advanced field types, such as XML nodes, or to set the field type.
Overrides:
setClassIndicatorField in class InheritancePolicy

setClassIndicatorFieldName

public void setClassIndicatorFieldName(java.lang.String fieldName)
PUBLIC: To set the class indicator field name. This is the name of the field in the table that stores what type of object this is.
Overrides:
setClassIndicatorFieldName in class InheritancePolicy

setClassIndicatorMapping

public void setClassIndicatorMapping(java.util.Hashtable classIndicatorMapping)
PUBLIC: Set the association of indicators and classes. This may be desired to be used by clients in strange inheritence models.

setOnlyInstancesExpression

public void setOnlyInstancesExpression(Expression onlyInstancesExpression)
ADVANCED: Sets the expression used to select instance of the class only. Can be used to customize the inheritance class indicator expression.
Overrides:
setOnlyInstancesExpression in class InheritancePolicy

setParentClass

public void setParentClass(java.lang.Class parentClass)
PUBLIC: Set the parent class. A descriptor can inherit from another descriptor through defining it as its parent. The root descriptor must define a class indicator field and mapping. All children must share the same table as their parent but can add additional tables. All children must share the root descriptor primary key.
Overrides:
setParentClass in class InheritancePolicy

setReadAllSubclassesViewName

public void setReadAllSubclassesViewName(java.lang.String readAllSubclassesViewName)
ADVANCED: The view can be used to optimize/customize the query for all subclasses where they have multiple tables. This view can use outer joins or unions to combine the results of selecting from all of the subclass tables. If a view is not given then TopLink must make an individual call for each subclass.
Overrides:
setReadAllSubclassesViewName in class InheritancePolicy

setShouldReadSubclasses

public void setShouldReadSubclasses(boolean shouldReadSubclasses)
PUBLIC: Set the descriptor to read instance of itself and its subclasses when queried. This is used with inheritence to configure the result of queries. By default this is true for root inheritence descriptors, and false for all others.
Overrides:
setShouldReadSubclasses in class InheritancePolicy

setShouldUseClassNameAsIndicator

public void setShouldUseClassNameAsIndicator(boolean shouldUseClassNameAsIndicator)
PUBLIC: Set if the descriptor uses the classes fully qualified name as the indicator. The class indicator is used with inheritence to determine the class from a row. By default a class indicator mapping is required, this can be set to true if usage of the class name is desired. The field must be of a large enough size to store the fully qualified class name.
Overrides:
setShouldUseClassNameAsIndicator in class InheritancePolicy

setWithAllSubclassesExpression

public void setWithAllSubclassesExpression(Expression withAllSubclassesExpression)
ADVANCED: Sets the expression to be used for querying for a class and all its subclasses. Can be used to customize the inheritence class indicator expression.
Overrides:
setWithAllSubclassesExpression in class InheritancePolicy

shouldReadSubclasses

public boolean shouldReadSubclasses()
PUBLIC: Return true if this descriptor should read instances of itself and subclasses on queries.
Overrides:
shouldReadSubclasses in class InheritancePolicy

shouldUseClassNameAsIndicator

public boolean shouldUseClassNameAsIndicator()
PUBLIC: Return true if the descriptor use the classes full name as the indicator. The class indicator is used with inheritance to determine the class from a row. By default a class indicator mapping is required, this can be set to true if usage of the class name is desired. The field must be of a large enough size to store the fully qualified class name.
Overrides:
shouldUseClassNameAsIndicator in class InheritancePolicy

useClassNameAsIndicator

public void useClassNameAsIndicator()
PUBLIC: Set the descriptor to use the classes full name as the indicator. The class indicator is used with inheritance to determine the class from a row. By default a class indicator mapping is required, this can be set to true if usage of the class name is desired. The field must be of a large enough size to store the fully qualified class name.
Overrides:
useClassNameAsIndicator in class InheritancePolicy

Skip navigation links

Copyright © 1998, 2006, Oracle. All Rights Reserved.