Class ClassMapping

All Implemented Interfaces:
Serializable, Comparable<ClassMetaData>, ClassStrategy, Strategy, ValueListener, SourceTracker, Commentable, MetaDataContext, MetaDataModes

public class ClassMapping extends ClassMetaData implements ClassStrategy
Specialization of metadata for relational databases.
Author:
Abe White
See Also:
  • Field Details

    • EMPTY_MAPPINGS

      public static final ClassMapping[] EMPTY_MAPPINGS
  • Constructor Details

    • ClassMapping

      protected ClassMapping(Class type, MappingRepository repos)
      Constructor. Supply described type and owning repository.
    • ClassMapping

      protected ClassMapping(ValueMetaData vmd)
      Embedded constructor. Supply embedding value and owning repository.
  • Method Details

    • getDiscriminator

      public Discriminator getDiscriminator()
      The class discriminator.
    • getVersion

      public Version getVersion()
      The version indicator.
    • getObjectId

      public Object getObjectId(JDBCStore store, Result res, ForeignKey fk, boolean subs, Joins joins) throws SQLException
      Return the oid value stored in the result. This implementation will recurse until it finds an ancestor class who uses oid values for its primary key.
      Parameters:
      fk - if non-null, use the local columns of the given foreign key in place of this class' primary key columns
      Throws:
      SQLException
      See Also:
    • toDataStoreValue

      public Object toDataStoreValue(Object obj, Column[] cols, JDBCStore store)
      Return the given column value(s) for the given object. The given columns will be primary key columns of this mapping, but may be in any order. If there is only one column, return its value. If there are multiple columns, return an object array of their values, in the same order the columns are given.
    • assertJoinable

      public Joinable assertJoinable(Column col)
      Return the joinable for the given column, or throw an exception if none is available.
    • getJoinable

      public Joinable getJoinable(Column col)
      Return the Joinable for the given column. Any column that another mapping joins to must be controlled by a joinable.
    • setJoinable

      public void setJoinable(Column col, Joinable joinable)
      Add the given column-to-joinable mapping.
    • isForeignKeyObjectId

      public Boolean isForeignKeyObjectId(ForeignKey fk)
      Return whether the columns of the given foreign key to this mapping can be used to construct an object id for this type. This is a relatively expensive operation; its results should be cached.
      Returns:
      Boolean.TRUE if the foreign key contains all oid columns, null if it contains only some columns, or Boolean.FALSE if it contains non-oid columns
    • getMappingInfo

      public ClassMappingInfo getMappingInfo()
      Raw mapping data.
    • getStrategy

      public ClassStrategy getStrategy()
      The strategy used to map this mapping.
    • setStrategy

      public void setStrategy(ClassStrategy strategy, Boolean adapt)
      The strategy used to map this mapping. The adapt parameter determines whether to adapt when mapping the strategy; use null if the strategy should not be mapped.
    • getTable

      public Table getTable()
      The mapping's primary table.
    • setTable

      public void setTable(Table table)
      The mapping's primary table.
    • getPrimaryKeyColumns

      public Column[] getPrimaryKeyColumns()
      The columns this mapping uses to uniquely identify an object. These will typically be the primary key columns or the columns this class uses to link to its superclass table.
    • setPrimaryKeyColumns

      public void setPrimaryKeyColumns(Column[] cols)
      The columns this mapping uses to uniquely identify an object. These will typically be the primary key columns or the columns this class uses to link to its superclass table.
    • getColumnIO

      public ColumnIO getColumnIO()
      I/O information on the key columns / join key.
    • setColumnIO

      public void setColumnIO(ColumnIO io)
      I/O information on the key columns / join key.
    • getJoinForeignKey

      public ForeignKey getJoinForeignKey()
      Foreign key linking the primary key columns to the superclass table, or null if none.
    • setJoinForeignKey

      public void setJoinForeignKey(ForeignKey fk)
      Foreign key linking the primary key columns to the superclass table, or null if none.
    • refSchemaComponents

      public void refSchemaComponents()
    • clearMapping

      public void clearMapping()
      Clear mapping information, including strategy.
    • syncMappingInfo

      public void syncMappingInfo()
      Update MappingInfo with our current mapping information.
    • setDescribedType

      protected void setDescribedType(Class type)
      ///////////////////
      Overrides:
      setDescribedType in class ClassMetaData
    • getSubclassFetchMode

      public int getSubclassFetchMode()
      The subclass fetch mode, as one of the eager constants in JDBCFetchConfiguration.
    • setSubclassFetchMode

      public void setSubclassFetchMode(int mode)
      The subclass fetch mode, as one of the eager constants in JDBCFetchConfiguration.
    • getMappingRepository

      public MappingRepository getMappingRepository()
      Convenience method to perform cast from ClassMetaData.getRepository().
    • getEmbeddingMapping

      public ValueMapping getEmbeddingMapping()
      Convenience method to perform cast from ClassMetaData.getEmbeddingMetaData()
    • isMapped

      public boolean isMapped()
      Returns true if this class does not use the "none" strategy (including if it has a null strategy, and therefore is probably in the process of being mapped).
      Overrides:
      isMapped in class ClassMetaData
    • getPCSuperclassMapping

      public ClassMapping getPCSuperclassMapping()
      Convenience method to perform cast from ClassMetaData.getPCSuperclassMetaData().
    • getMappedPCSuperclassMapping

      public ClassMapping getMappedPCSuperclassMapping()
      Convenience method to perform cast from ClassMetaData.getMappedPCSuperclassMetaData().
    • getJoinablePCSuperclassMapping

      public ClassMapping getJoinablePCSuperclassMapping()
      Return the nearest mapped superclass that can join to this class.
    • getPCSubclassMappings

      public ClassMapping[] getPCSubclassMappings()
      Convenience method to perform cast from ClassMetaData.getPCSubclassMetaDatas().
    • getMappedPCSubclassMappings

      public ClassMapping[] getMappedPCSubclassMappings()
      Convenience method to perform cast from ClassMetaData.getMappedPCSubclassMetaDatas().
    • getJoinablePCSubclassMappings

      public ClassMapping[] getJoinablePCSubclassMappings()
      Return mapped subclasses that are reachable via joins.
    • getIndependentAssignableMappings

      public ClassMapping[] getIndependentAssignableMappings()
      Returns the closest-derived list of non-inter-joinable mapped types assignable to this type. May return this mapping.
    • getFieldMappings

      public FieldMapping[] getFieldMappings()
      Convenience method to perform cast from ClassMetaData.getFields().
    • getDeclaredFieldMappings

      public FieldMapping[] getDeclaredFieldMappings()
      Convenience method to perform cast from ClassMetaData.getDeclaredFields().
    • getPrimaryKeyFieldMappings

      public FieldMapping[] getPrimaryKeyFieldMappings()
      Convenience method to perform cast from ClassMetaData.getPrimaryKeyFields().
    • getVersionFieldMapping

      public FieldMapping getVersionFieldMapping()
      Convenience method to perform cast from ClassMetaData.getVersionField().
    • getDefaultFetchGroupFieldMappings

      public FieldMapping[] getDefaultFetchGroupFieldMappings()
      Convenience method to perform cast from ClassMetaData.getDefaultFetchGroupFields().
    • getDefinedFieldMappings

      public FieldMapping[] getDefinedFieldMappings()
      Convenience method to perform cast from ClassMetaData.getDefinedFields().
    • getFieldMappingsInListingOrder

      public FieldMapping[] getFieldMappingsInListingOrder()
      Convenience method to perform cast from ClassMetaData.getFieldsInListingOrder().
    • getDefinedFieldMappingsInListingOrder

      public FieldMapping[] getDefinedFieldMappingsInListingOrder()
      Convenience method to perform cast from ClassMetaData.getDefinedFieldsInListingOrder().
    • getFieldMapping

      public FieldMapping getFieldMapping(int index)
      Convenience method to perform cast from ClassMetaData.getField(int).
    • getDeclaredFieldMapping

      public FieldMapping getDeclaredFieldMapping(int index)
      Convenience method to perform cast from ClassMetaData.getDeclaredField(int).
    • getFieldMapping

      public FieldMapping getFieldMapping(String name)
      Convenience method to perform cast from ClassMetaData.getField(int).
    • getDeclaredFieldMapping

      public FieldMapping getDeclaredFieldMapping(String name)
      Convenience method to perform cast from ClassMetaData.getDeclaredField(int).
    • getDeclaredUnmanagedFieldMappings

      public FieldMapping[] getDeclaredUnmanagedFieldMappings()
      Convenience method to perform cast from ClassMetaData.getDeclaredUnmanagedFields().
    • addDeclaredFieldMapping

      public FieldMapping addDeclaredFieldMapping(String name, Class type)
      Convenience method to perform cast from ClassMetaData.addDeclaredField(String, Class).
    • resolveMapping

      protected void resolveMapping(boolean runtime)
      Description copied from class: ClassMetaData
      Resolve mapping data. Logs resolve message and resolves super by default.
      Overrides:
      resolveMapping in class ClassMetaData
    • ensureSecondaryTables

      public void ensureSecondaryTables(MappingRepository targetRepos)
      Ensures that secondary tables declared via @SecondaryTable are created in the given repository's schema group with PK join columns and FK constraints. This is used by MappingTool to ensure secondary tables exist in the current schema group even when metadata is cached from a previous EMF.
    • initializeMapping

      protected void initializeMapping()
      Description copied from class: ClassMetaData
      Initialize mapping. Logs init message by default.
      Overrides:
      initializeMapping in class ClassMetaData
    • clearDefinedFieldCache

      protected void clearDefinedFieldCache()
      Description copied from class: ClassMetaData
      Clear defined field data.
      Overrides:
      clearDefinedFieldCache in class ClassMetaData
    • clearSubclassCache

      protected void clearSubclassCache()
      Description copied from class: ClassMetaData
      Clear cached subclass data.
      Overrides:
      clearSubclassCache in class ClassMetaData
    • copy

      public void copy(ClassMetaData cls)
      Description copied from class: ClassMetaData
      Copy the metadata from the given instance to this one. Do not copy mapping information.
      Overrides:
      copy in class ClassMetaData
    • validateDataStoreExtensionPrefix

      protected boolean validateDataStoreExtensionPrefix(String prefix)
      Description copied from class: Extensions
      Return true if extensions starting with the given official datastore prefix should be validated for this runtime.
      Overrides:
      validateDataStoreExtensionPrefix in class Extensions
    • getAlias

      public String getAlias()
      /////////////////////////////
      Specified by:
      getAlias in interface Strategy
    • map

      public void map(boolean adapt)
      Description copied from interface: Strategy
      Map the owning mapping using this strategy.
      Specified by:
      map in interface Strategy
      Parameters:
      adapt - if true, use the owning mapping's raw mapping info to set its ORM data; if false, ORM data will already be set
    • initialize

      public void initialize()
      Description copied from interface: Strategy
      Perform caching and other initialization operations. This method is called after Strategy.map(boolean), and after all related components have been mapped as well.
      Specified by:
      initialize in interface Strategy
    • insert

      public void insert(OpenJPAStateManager sm, JDBCStore store, RowManager rm) throws SQLException
      Description copied from interface: Strategy
      Set 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:
      insert in interface Strategy
      Throws:
      SQLException
    • update

      public void update(OpenJPAStateManager sm, JDBCStore store, RowManager rm) throws SQLException
      Description copied from interface: Strategy
      Set values for the mapping into the proper rows.
      Specified by:
      update in interface Strategy
      Throws:
      SQLException
      See Also:
    • delete

      public void delete(OpenJPAStateManager sm, JDBCStore store, RowManager rm) throws SQLException
      Description copied from interface: Strategy
      Set 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:
      delete in interface Strategy
      Throws:
      SQLException
      See Also:
    • isCustomInsert

      public Boolean isCustomInsert(OpenJPAStateManager sm, JDBCStore store)
      Description copied from interface: Strategy
      Return Boolean.FALSE if this mapping does not customize the insert process, Boolean.TRUE if it does, or null if it does customize the insert, but also relies on the standard insert method being called. Implement the Strategy.customInsert(OpenJPAStateManager, JDBCStore) method to implement the custom insertion behavior.
      Specified by:
      isCustomInsert in interface Strategy
    • isCustomUpdate

      public Boolean isCustomUpdate(OpenJPAStateManager sm, JDBCStore store)
      Description copied from interface: Strategy
      Return Boolean.FALSE if this mapping does not customize the update process, Boolean.TRUE if it does, or null if it does customize the update, but also relies on the standard update method being called. Implement the Strategy.customUpdate(OpenJPAStateManager, JDBCStore) method to override the default update behavior.
      Specified by:
      isCustomUpdate in interface Strategy
    • isCustomDelete

      public Boolean isCustomDelete(OpenJPAStateManager sm, JDBCStore store)
      Description copied from interface: Strategy
      Return Boolean.FALSE if this mapping does not customize the delete process, Boolean.TRUE if it does, or null if it does customize the delete, but also relies on the standard delete method being called. Implement the Strategy.customDelete(OpenJPAStateManager, JDBCStore) method to override the default deletion behavior.
      Specified by:
      isCustomDelete in interface Strategy
    • customInsert

      public void customInsert(OpenJPAStateManager sm, JDBCStore store) throws SQLException
      Description copied from interface: Strategy
      Override 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:
      customInsert in interface Strategy
      Throws:
      SQLException
    • customUpdate

      public void customUpdate(OpenJPAStateManager sm, JDBCStore store) throws SQLException
      Description copied from interface: Strategy
      Override this method to customize flushing this mapping. For classes, this method must also flush all fields.
      Specified by:
      customUpdate in interface Strategy
      Throws:
      SQLException
    • customDelete

      public void customDelete(OpenJPAStateManager sm, JDBCStore store) throws SQLException
      Description copied from interface: Strategy
      Override 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:
      customDelete in interface Strategy
      Throws:
      SQLException
    • setClassMapping

      public void setClassMapping(ClassMapping owner)
      Description copied from interface: ClassStrategy
      Set the class mapping using this strategy. This will be called before use.
      Specified by:
      setClassMapping in interface ClassStrategy
    • isPrimaryKeyObjectId

      public boolean isPrimaryKeyObjectId(boolean hasAll)
      Description copied from interface: ClassStrategy
      Return true if the this class' primary key columns correspond to the base class' primary key columns used to construct oid values. Base classes always return true. Classes that join to the base class table, though, may not always join using the same columns the base class uses for oid values, or may not use all the columns. When performing a select, we will join down to the most-derived class that is identified by oid values. We cannot use non-primary key field values for joining during selects, because the field values to join on might be the ones we're trying to select! Similarly, we can only reconstruct oid values for selected objects using classes whose primary keys store oid values.
      Specified by:
      isPrimaryKeyObjectId in interface ClassStrategy
      Parameters:
      hasAll - if true, there must be a primary key column for every base class primary key column; if false the primary key must only match a subset of the base class primary key columns
    • joinSuperclass

      public Joins joinSuperclass(Joins joins, boolean toThis)
      Description copied from interface: ClassStrategy
      Join the mapping and its superclass.
      Specified by:
      joinSuperclass in interface ClassStrategy
      Parameters:
      toThis - if false, inner join to the superclass table; if true, outer join from the superclass table to this table
    • supportsEagerSelect

      public boolean supportsEagerSelect(Select sel, OpenJPAStateManager sm, JDBCStore store, ClassMapping base, JDBCFetchConfiguration fetch)
      Description copied from interface: ClassStrategy
      Return true if this strategy can perform the given select from the given base mapping. The given state manager may be null if selecting multiple instances.
      Specified by:
      supportsEagerSelect in interface ClassStrategy
    • customLoad

      public ResultObjectProvider customLoad(JDBCStore store, boolean subclasses, JDBCFetchConfiguration fetch, long startIdx, long endIdx) throws SQLException
      Description copied from interface: ClassStrategy
      Implement this method to customize obtaining a result containing all instances of this class. Return null for standard loading.
      Specified by:
      customLoad in interface ClassStrategy
      Throws:
      SQLException
    • customLoad

      public boolean customLoad(OpenJPAStateManager sm, JDBCStore store, PCState state, JDBCFetchConfiguration fetch) throws SQLException, ClassNotFoundException
      Description copied from interface: ClassStrategy
      Implement this method to load the state of a given object, without a previous Result. Return true if this method handles the load. If the object does not exist in the data store, simply take no action on it (but still return true). Return false to use default loading.
      Specified by:
      customLoad in interface ClassStrategy
      Parameters:
      state - if non-null, then you must initialize the state and persistent object of the given state manager (after determining the actual class of the object from the database, if there are possible persistent subclasses); initialization looks like this: sm.initialize (pcClass, state)
      Throws:
      SQLException
      ClassNotFoundException
    • customLoad

      public boolean customLoad(OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch, Result result) throws SQLException
      Description copied from interface: ClassStrategy
      Implement this method to customize loading from a Result into an instance. Return true if this mapping handles the load; false if normal loading should proceed after calling this method.
      Specified by:
      customLoad in interface ClassStrategy
      Throws:
      SQLException
    • isVerticalStrategy

      public boolean isVerticalStrategy()