Package org.apache.openjpa.jdbc.meta
Class Discriminator
- java.lang.Object
 - 
- org.apache.openjpa.jdbc.meta.Discriminator
 
 
- 
- All Implemented Interfaces:
 Serializable,DiscriminatorStrategy,Strategy,MetaDataContext,MetaDataModes
public class Discriminator extends Object implements DiscriminatorStrategy, MetaDataContext, MetaDataModes
Handles determining the object class of database records.- Author:
 - Abe White
 - See Also:
 - Serialized Form
 
 
- 
- 
Field Summary
Fields Modifier and Type Field Description static ObjectNULLNull discriminator value marker.- 
Fields inherited from interface org.apache.openjpa.meta.MetaDataModes
MODE_ALL, MODE_ANN_MAPPING, MODE_MAPPING, MODE_MAPPING_INIT, MODE_META, MODE_NONE, MODE_QUERY 
 - 
 
- 
Constructor Summary
Constructors Constructor Description Discriminator(ClassMapping mapping)Constructor. 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddClassConditions(Select sel, boolean subs, Joins joins)Add WHERE conditions to the given select limiting the returned results to our mapping type, possibly including subclasses.voidclearMapping()Clear mapping information, including strategy.voidcustomDelete(OpenJPAStateManager sm, JDBCStore store)Override this method to customize flushing this mapping.voidcustomInsert(OpenJPAStateManager sm, JDBCStore store)Override this method to customize flushing this mapping.voidcustomUpdate(OpenJPAStateManager sm, JDBCStore store)Override this method to customize flushing this mapping.voiddelete(OpenJPAStateManager sm, JDBCStore store, RowManager rm)Set the where values appropriately to delete the proper instance, and set all relations on non-secondary tables as updates.StringgetAlias()Return the alias of this strategy.Class<?>getClass(JDBCStore store, ClassMapping base, Result result)Return the class for the current result row.SQLBuffergetClassConditions(Select sel, Joins joins, ClassMapping base, boolean subs)Return SQL to limit the classes selected as much as possible to the given base class, and optionally its subclasses.ClassMappinggetClassMapping()Return the owning mapping.ColumnIOgetColumnIO()I/O information on the discriminator columns.Column[]getColumns()Columns used by this Discriminator.IndexgetIndex()Index on the Discriminator columns, or null if none.intgetJavaType()DiscriminatorMappingInfogetMappingInfo()Raw mapping data.MappingRepositorygetMappingRepository()MetaDataRepositorygetRepository()Access metadata repository.intgetResolve()Resolve mode.DiscriminatorStrategygetStrategy()The strategy used for class discrimination.booleangetSubclassesLoaded()Whether this Discriminator has loaded subclasses yet.ObjectgetValue()The discriminator value.booleanhasClassConditions(ClassMapping base, boolean subs)Whether any class conditions are necessary.voidinitialize()Perform caching and other initialization operations.voidinsert(OpenJPAStateManager sm, JDBCStore store, RowManager rm)Set values for the mapping into the proper rows.BooleanisCustomDelete(OpenJPAStateManager sm, JDBCStore store)ReturnBoolean.FALSEif this mapping does not customize the delete process,Boolean.TRUEif it does, or null if it does customize the delete, but also relies on the standard delete method being called.BooleanisCustomInsert(OpenJPAStateManager sm, JDBCStore store)ReturnBoolean.FALSEif this mapping does not customize the insert process,Boolean.TRUEif it does, or null if it does customize the insert, but also relies on the standard insert method being called.BooleanisCustomUpdate(OpenJPAStateManager sm, JDBCStore store)ReturnBoolean.FALSEif this mapping does not customize the update process,Boolean.TRUEif it does, or null if it does customize the update, but also relies on the standard update method being called.voidloadSubclasses(JDBCStore store)Load all subclasses of the owning class mapping into the JVM.voidmap(boolean adapt)Map the owning mapping using this strategy.voidrefSchemaComponents()Increment the reference count of used schema components.booleanresolve(int mode)Resolve mapping information.booleanselect(Select sel, ClassMapping mapping)Select the data for this Discriminator.voidsetColumnIO(ColumnIO io)I/O information on the discriminator columns.voidsetColumns(Column[] cols)Columns used by this Discriminator.voidsetDiscriminator(Discriminator owner)Set the Discriminator that uses this strategy.voidsetIndex(Index idx)Index on the Discriminator columns, or null if none.voidsetJavaType(int javaType)voidsetResolve(int mode)Resolve mode.voidsetResolve(int mode, boolean on)Resolve mode.voidsetStrategy(DiscriminatorStrategy strategy, Boolean adapt)The strategy used for class discrimination.voidsetSubclassesLoaded(boolean loaded)Whether this Discriminator has loaded subclasses yet.voidsetValue(Object value)The discriminator value.voidsyncMappingInfo()UpdateMappingInfowith our current mapping information.StringtoString()voidupdate(OpenJPAStateManager sm, JDBCStore store, RowManager rm)Set values for the mapping into the proper rows. 
 - 
 
- 
- 
Field Detail
- 
NULL
public static final Object NULL
Null discriminator value marker. 
 - 
 
- 
Constructor Detail
- 
Discriminator
public Discriminator(ClassMapping mapping)
Constructor. Supply owning mapping. 
 - 
 
- 
Method Detail
- 
getRepository
public MetaDataRepository getRepository()
Description copied from interface:MetaDataContextAccess metadata repository.- Specified by:
 getRepositoryin interfaceMetaDataContext
 
- 
getMappingRepository
public MappingRepository getMappingRepository()
 
- 
getClassMapping
public ClassMapping getClassMapping()
Return the owning mapping. 
- 
getStrategy
public DiscriminatorStrategy getStrategy()
The strategy used for class discrimination. 
- 
setStrategy
public void setStrategy(DiscriminatorStrategy strategy, Boolean adapt)
The strategy used for class discrimination. Theadaptparameter determines whether to adapt when mapping the strategy; use null if the strategy should not be mapped. 
- 
getValue
public Object getValue()
The discriminator value. 
- 
setValue
public void setValue(Object value)
The discriminator value. 
- 
getMappingInfo
public DiscriminatorMappingInfo getMappingInfo()
Raw mapping data. 
- 
getColumns
public Column[] getColumns()
Columns used by this Discriminator. 
- 
setColumns
public void setColumns(Column[] cols)
Columns used by this Discriminator. 
- 
getColumnIO
public ColumnIO getColumnIO()
I/O information on the discriminator columns. 
- 
setColumnIO
public void setColumnIO(ColumnIO io)
I/O information on the discriminator columns. 
- 
getIndex
public Index getIndex()
Index on the Discriminator columns, or null if none. 
- 
setIndex
public void setIndex(Index idx)
Index on the Discriminator columns, or null if none. 
- 
refSchemaComponents
public void refSchemaComponents()
Increment the reference count of used schema components. 
- 
clearMapping
public void clearMapping()
Clear mapping information, including strategy. 
- 
syncMappingInfo
public void syncMappingInfo()
UpdateMappingInfowith our current mapping information. 
- 
getResolve
public int getResolve()
Resolve mode. 
- 
setResolve
public void setResolve(int mode)
Resolve mode. 
- 
setResolve
public void setResolve(int mode, boolean on)Resolve mode. 
- 
resolve
public boolean resolve(int mode)
Resolve mapping information. 
- 
getSubclassesLoaded
public boolean getSubclassesLoaded()
Whether this Discriminator has loaded subclasses yet. 
- 
setSubclassesLoaded
public void setSubclassesLoaded(boolean loaded)
Whether this Discriminator has loaded subclasses yet. 
- 
addClassConditions
public boolean addClassConditions(Select sel, boolean subs, Joins joins)
Add WHERE conditions to the given select limiting the returned results to our mapping type, possibly including subclasses. 
- 
getAlias
public String getAlias()
Description copied from interface:StrategyReturn the alias of this strategy. For custom strategies, return the full class name. 
- 
map
public void map(boolean adapt)
Description copied from interface:StrategyMap the owning mapping using this strategy. 
- 
initialize
public void initialize()
Description copied from interface:StrategyPerform caching and other initialization operations. This method is called afterStrategy.map(boolean), and after all related components have been mapped as well.- Specified by:
 initializein interfaceStrategy
 
- 
insert
public void insert(OpenJPAStateManager sm, JDBCStore store, RowManager rm) throws SQLException
Description copied from interface:StrategySet values for the mapping into the proper rows. For class mappings, this method will be called only after the corresponding method has been called for all fields of this mapping.- Specified by:
 insertin interfaceStrategy- Throws:
 SQLException
 
- 
update
public void update(OpenJPAStateManager sm, JDBCStore store, RowManager rm) throws SQLException
Description copied from interface:StrategySet values for the mapping into the proper rows.- Specified by:
 updatein interfaceStrategy- Throws:
 SQLException- See Also:
 Strategy.insert(org.apache.openjpa.kernel.OpenJPAStateManager, org.apache.openjpa.jdbc.kernel.JDBCStore, org.apache.openjpa.jdbc.sql.RowManager)
 
- 
delete
public void delete(OpenJPAStateManager sm, JDBCStore store, RowManager rm) throws SQLException
Description copied from interface:StrategySet the where values appropriately to delete the proper instance, and set all relations on non-secondary tables as updates. This allows foreign key analysis.- Specified by:
 deletein interfaceStrategy- Throws:
 SQLException- See Also:
 Strategy.insert(org.apache.openjpa.kernel.OpenJPAStateManager, org.apache.openjpa.jdbc.kernel.JDBCStore, org.apache.openjpa.jdbc.sql.RowManager)
 
- 
isCustomInsert
public Boolean isCustomInsert(OpenJPAStateManager sm, JDBCStore store)
Description copied from interface:StrategyReturnBoolean.FALSEif this mapping does not customize the insert process,Boolean.TRUEif it does, or null if it does customize the insert, but also relies on the standard insert method being called. Implement theStrategy.customInsert(org.apache.openjpa.kernel.OpenJPAStateManager, org.apache.openjpa.jdbc.kernel.JDBCStore)method to implement the custom insertion behavior.- Specified by:
 isCustomInsertin interfaceStrategy
 
- 
isCustomUpdate
public Boolean isCustomUpdate(OpenJPAStateManager sm, JDBCStore store)
Description copied from interface:StrategyReturnBoolean.FALSEif this mapping does not customize the update process,Boolean.TRUEif it does, or null if it does customize the update, but also relies on the standard update method being called. Implement theStrategy.customUpdate(org.apache.openjpa.kernel.OpenJPAStateManager, org.apache.openjpa.jdbc.kernel.JDBCStore)method to override the default update behavior.- Specified by:
 isCustomUpdatein interfaceStrategy
 
- 
isCustomDelete
public Boolean isCustomDelete(OpenJPAStateManager sm, JDBCStore store)
Description copied from interface:StrategyReturnBoolean.FALSEif this mapping does not customize the delete process,Boolean.TRUEif it does, or null if it does customize the delete, but also relies on the standard delete method being called. Implement theStrategy.customDelete(org.apache.openjpa.kernel.OpenJPAStateManager, org.apache.openjpa.jdbc.kernel.JDBCStore)method to override the default deletion behavior.- Specified by:
 isCustomDeletein interfaceStrategy
 
- 
customInsert
public void customInsert(OpenJPAStateManager sm, JDBCStore store) throws SQLException
Description copied from interface:StrategyOverride this method to customize flushing this mapping. For classes, this method must also flush all fields. For fields, this method is called after the owning object is inserted, so if this field is in a row with other fields, that row will already exist.- Specified by:
 customInsertin interfaceStrategy- Throws:
 SQLException
 
- 
customUpdate
public void customUpdate(OpenJPAStateManager sm, JDBCStore store) throws SQLException
Description copied from interface:StrategyOverride this method to customize flushing this mapping. For classes, this method must also flush all fields.- Specified by:
 customUpdatein interfaceStrategy- Throws:
 SQLException
 
- 
customDelete
public void customDelete(OpenJPAStateManager sm, JDBCStore store) throws SQLException
Description copied from interface:StrategyOverride this method to customize flushing this mapping. For classes, this method must also flush all fields. For fields, this method will be called after the owning object is deleted.- Specified by:
 customDeletein interfaceStrategy- Throws:
 SQLException
 
- 
setDiscriminator
public void setDiscriminator(Discriminator owner)
Description copied from interface:DiscriminatorStrategySet the Discriminator that uses this strategy. This will be called before use.- Specified by:
 setDiscriminatorin interfaceDiscriminatorStrategy
 
- 
select
public boolean select(Select sel, ClassMapping mapping)
Description copied from interface:DiscriminatorStrategySelect the data for this Discriminator.- Specified by:
 selectin interfaceDiscriminatorStrategymapping- the known base class being selected; this may not be the base class in the inheritance hierarchy- Returns:
 - true if anything was selected; false otherwise
 
 
- 
loadSubclasses
public void loadSubclasses(JDBCStore store) throws SQLException, ClassNotFoundException
Description copied from interface:DiscriminatorStrategyLoad all subclasses of the owning class mapping into the JVM.- Specified by:
 loadSubclassesin interfaceDiscriminatorStrategy- Throws:
 SQLExceptionClassNotFoundException
 
- 
getClass
public Class<?> getClass(JDBCStore store, ClassMapping base, Result result) throws SQLException, ClassNotFoundException
Description copied from interface:DiscriminatorStrategyReturn the class for the current result row.- Specified by:
 getClassin interfaceDiscriminatorStrategy- Throws:
 SQLExceptionClassNotFoundException
 
- 
hasClassConditions
public boolean hasClassConditions(ClassMapping base, boolean subs)
Description copied from interface:DiscriminatorStrategyWhether any class conditions are necessary. 
- 
getClassConditions
public SQLBuffer getClassConditions(Select sel, Joins joins, ClassMapping base, boolean subs)
Description copied from interface:DiscriminatorStrategyReturn SQL to limit the classes selected as much as possible to the given base class, and optionally its subclasses. The select and joins instances are supplied in order to get column aliases.- Specified by:
 getClassConditionsin interfaceDiscriminatorStrategy
 
- 
setJavaType
public void setJavaType(int javaType)
 
- 
getJavaType
public int getJavaType()
 
 - 
 
 -