org.apache.openjpa.jdbc.meta
Class MappingInfo

java.lang.Object
  extended by org.apache.openjpa.jdbc.meta.MappingInfo
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
ClassMappingInfo, DiscriminatorMappingInfo, FieldMappingInfo, ValueMappingInfo, VersionMappingInfo

public abstract class MappingInfo
extends Object
implements Serializable

Base class storing raw mapping information; defines utility methods for converting raw mapping information to full mapping to the schema.

Author:
Abe White
See Also:
Serialized Form

Nested Class Summary
static interface MappingInfo.ForeignKeyDefaults
          Supplies default foreign key information.
static interface MappingInfo.TableDefaults
          Supplies default table information.
 
Field Summary
static int JOIN_FORWARD
           
static int JOIN_INVERSE
           
static int JOIN_NONE
           
 
Constructor Summary
MappingInfo()
           
 
Method Summary
 void assertNoForeignKey(MetaDataContext context, boolean die)
          Assert that the user did not try to place a foreign key on this mapping.
 void assertNoIndex(MetaDataContext context, boolean die)
          Assert that the user did not try to place an index on this mapping.
 void assertNoJoin(MetaDataContext context, boolean die)
          Assert that the user did not try to join.
 void assertNoSchemaComponents(MetaDataContext context, boolean die)
          Assert that the user did not supply any columns, index, unique constraint, or foreign key for this mapping.
 void assertNoUnique(MetaDataContext context, boolean die)
          Assert that the user did not try to place a unique constraint on this mapping.
 void assertStrategy(MetaDataContext context, Object contextStrat, Object expected, boolean die)
          Assert that this info has the given strategy or no strategy.
 boolean canForeignKey()
          The user can mark columns as explicitly not having a foreign key.
 boolean canIndex()
          The user can mark columns as explicitly non-indexable.
 boolean canUnique()
          The user can mark columns as explicitly not having a unique constraint.
 void clear()
          Clear all mapping information.
protected  void clear(boolean canFlags)
          Clear mapping information.
 void copy(MappingInfo info)
          Copy missing info from the instance to this one.
protected  Column[] createColumns(MetaDataContext context, String prefix, Column[] tmplates, Table table, boolean adapt)
          Retrieve/create columns on the given table by merging the given template information with any user-provided information.
protected  ForeignKey createForeignKey(MetaDataContext context, String prefix, List given, MappingInfo.ForeignKeyDefaults def, Table table, ClassMapping cls, ClassMapping rel, boolean inversable, boolean adapt)
          Retrieve/create a foreign key (possibly logical) on the given columns by merging the given template information with any user-provided information.
protected  Index createIndex(MetaDataContext context, String prefix, Index tmplate, Column[] cols, boolean adapt)
          Retrieve/create an index on the given columns by merging the given template information with any user-provided information.
 Table createTable(MetaDataContext context, MappingInfo.TableDefaults def, String schemaName, String given, boolean adapt)
          Find or generate a table for a mapping.
protected  Unique createUnique(MetaDataContext context, String prefix, Unique tmplate, Column[] cols, boolean adapt)
          Retrieve/create a unique constraint on the given columns by merging the given template information with any user-provided information.
 ColumnIO getColumnIO()
          I/O for the columns created by the last call to createColumns(org.apache.openjpa.meta.MetaDataContext, java.lang.String, org.apache.openjpa.jdbc.schema.Column[], org.apache.openjpa.jdbc.schema.Table, boolean), or for the foreign key created by the last call to createForeignKey(org.apache.openjpa.meta.MetaDataContext, java.lang.String, java.util.List, org.apache.openjpa.jdbc.meta.MappingInfo.ForeignKeyDefaults, org.apache.openjpa.jdbc.schema.Table, org.apache.openjpa.jdbc.meta.ClassMapping, org.apache.openjpa.jdbc.meta.ClassMapping, boolean, boolean).
 List getColumns()
          Raw column data.
 ForeignKey getForeignKey()
          Raw foreign key information.
 Index getIndex()
          Raw index.
 int getJoinDirection()
          Direction of the join that the columns of this mapping info form.
 String getStrategy()
          Mapping strategy name.
 Unique getUnique()
          Raw unique constraint information.
 boolean hasSchemaComponents()
          Return true if this info has columns, foreign key information, index information, etc.
protected static Column mergeColumn(MetaDataContext context, String prefix, Column tmplate, boolean compat, Column given, Table table, boolean adapt, boolean fill)
          Merge the given columns if possible.
 void setCanForeignKey(boolean fkable)
          The user can mark columns as explicitly not having a foreign key.
 void setCanIndex(boolean indexable)
          The user can mark columns as explicitly non-indexable.
 void setCanUnique(boolean uniquable)
          The user can mark columns as explicitly not having a unique constraint.
 void setColumnIO(ColumnIO io)
          I/O for the columns created by the last call to createColumns(org.apache.openjpa.meta.MetaDataContext, java.lang.String, org.apache.openjpa.jdbc.schema.Column[], org.apache.openjpa.jdbc.schema.Table, boolean), or for the foreign key created by the last call to createForeignKey(org.apache.openjpa.meta.MetaDataContext, java.lang.String, java.util.List, org.apache.openjpa.jdbc.meta.MappingInfo.ForeignKeyDefaults, org.apache.openjpa.jdbc.schema.Table, org.apache.openjpa.jdbc.meta.ClassMapping, org.apache.openjpa.jdbc.meta.ClassMapping, boolean, boolean).
 void setColumns(List cols)
          Raw column data.
 void setForeignKey(ForeignKey fk)
          Raw foreign key information.
 void setIndex(Index idx)
          Raw index.
 void setJoinDirection(int join)
          Direction of the join that the columns of this mapping info form.
 void setStrategy(String strategy)
          Mapping strategy name.
 void setUnique(Unique unq)
          Raw unique constraint information.
protected static Column syncColumn(MetaDataContext context, Column col, int num, boolean forceJDBCType, Table colTable, Table targetTable, Object target, boolean inverse)
          Create a copy of the given column with the raw mapping information set correctly, and without settings that match defaults.
protected  void syncColumns(MetaDataContext context, Column[] cols, boolean forceJDBCType)
          Sets internal column information to match the given mapped columns.
protected  void syncForeignKey(MetaDataContext context, ForeignKey fk, Table local, Table target)
          Sets internal constraint and column information to match given mapped constraint.
protected  void syncIndex(MetaDataContext context, Index idx)
          Sets internal index information to match given mapped index.
protected  void syncUnique(MetaDataContext context, Unique unq)
          Sets internal constraint information to match given mapped constraint.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JOIN_NONE

public static final int JOIN_NONE
See Also:
Constant Field Values

JOIN_FORWARD

public static final int JOIN_FORWARD
See Also:
Constant Field Values

JOIN_INVERSE

public static final int JOIN_INVERSE
See Also:
Constant Field Values
Constructor Detail

MappingInfo

public MappingInfo()
Method Detail

getStrategy

public String getStrategy()
Mapping strategy name.


setStrategy

public void setStrategy(String strategy)
Mapping strategy name.


getColumns

public List getColumns()
Raw column data.


setColumns

public void setColumns(List cols)
Raw column data.


getIndex

public Index getIndex()
Raw index.


setIndex

public void setIndex(Index idx)
Raw index.


canIndex

public boolean canIndex()
The user can mark columns as explicitly non-indexable.


setCanIndex

public void setCanIndex(boolean indexable)
The user can mark columns as explicitly non-indexable.


getForeignKey

public ForeignKey getForeignKey()
Raw foreign key information.


setForeignKey

public void setForeignKey(ForeignKey fk)
Raw foreign key information.


canForeignKey

public boolean canForeignKey()
The user can mark columns as explicitly not having a foreign key.


setCanForeignKey

public void setCanForeignKey(boolean fkable)
The user can mark columns as explicitly not having a foreign key.


getUnique

public Unique getUnique()
Raw unique constraint information.


setUnique

public void setUnique(Unique unq)
Raw unique constraint information.


canUnique

public boolean canUnique()
The user can mark columns as explicitly not having a unique constraint.


setCanUnique

public void setCanUnique(boolean uniquable)
The user can mark columns as explicitly not having a unique constraint.


getColumnIO

public ColumnIO getColumnIO()
I/O for the columns created by the last call to createColumns(org.apache.openjpa.meta.MetaDataContext, java.lang.String, org.apache.openjpa.jdbc.schema.Column[], org.apache.openjpa.jdbc.schema.Table, boolean), or for the foreign key created by the last call to createForeignKey(org.apache.openjpa.meta.MetaDataContext, java.lang.String, java.util.List, org.apache.openjpa.jdbc.meta.MappingInfo.ForeignKeyDefaults, org.apache.openjpa.jdbc.schema.Table, org.apache.openjpa.jdbc.meta.ClassMapping, org.apache.openjpa.jdbc.meta.ClassMapping, boolean, boolean). This is also expected to be set correctly prior to calls to syncColumns(org.apache.openjpa.meta.MetaDataContext, org.apache.openjpa.jdbc.schema.Column[], boolean) and syncForeignKey(org.apache.openjpa.meta.MetaDataContext, org.apache.openjpa.jdbc.schema.ForeignKey, org.apache.openjpa.jdbc.schema.Table, org.apache.openjpa.jdbc.schema.Table).


setColumnIO

public void setColumnIO(ColumnIO io)
I/O for the columns created by the last call to createColumns(org.apache.openjpa.meta.MetaDataContext, java.lang.String, org.apache.openjpa.jdbc.schema.Column[], org.apache.openjpa.jdbc.schema.Table, boolean), or for the foreign key created by the last call to createForeignKey(org.apache.openjpa.meta.MetaDataContext, java.lang.String, java.util.List, org.apache.openjpa.jdbc.meta.MappingInfo.ForeignKeyDefaults, org.apache.openjpa.jdbc.schema.Table, org.apache.openjpa.jdbc.meta.ClassMapping, org.apache.openjpa.jdbc.meta.ClassMapping, boolean, boolean). This is also expected to be set correctly prior to calls to syncColumns(org.apache.openjpa.meta.MetaDataContext, org.apache.openjpa.jdbc.schema.Column[], boolean) and syncForeignKey(org.apache.openjpa.meta.MetaDataContext, org.apache.openjpa.jdbc.schema.ForeignKey, org.apache.openjpa.jdbc.schema.Table, org.apache.openjpa.jdbc.schema.Table).


getJoinDirection

public int getJoinDirection()
Direction of the join that the columns of this mapping info form. This is usually automatically set by createForeignKey(org.apache.openjpa.meta.MetaDataContext, java.lang.String, java.util.List, org.apache.openjpa.jdbc.meta.MappingInfo.ForeignKeyDefaults, org.apache.openjpa.jdbc.schema.Table, org.apache.openjpa.jdbc.meta.ClassMapping, org.apache.openjpa.jdbc.meta.ClassMapping, boolean, boolean). This flag is also expected to be set correctly prior to calls to syncForeignKey(org.apache.openjpa.meta.MetaDataContext, org.apache.openjpa.jdbc.schema.ForeignKey, org.apache.openjpa.jdbc.schema.Table, org.apache.openjpa.jdbc.schema.Table) if the join is inversed.


setJoinDirection

public void setJoinDirection(int join)
Direction of the join that the columns of this mapping info form. This is usually automatically set by createForeignKey(org.apache.openjpa.meta.MetaDataContext, java.lang.String, java.util.List, org.apache.openjpa.jdbc.meta.MappingInfo.ForeignKeyDefaults, org.apache.openjpa.jdbc.schema.Table, org.apache.openjpa.jdbc.meta.ClassMapping, org.apache.openjpa.jdbc.meta.ClassMapping, boolean, boolean). This flag is also expected to be set correctly prior to calls to syncForeignKey(org.apache.openjpa.meta.MetaDataContext, org.apache.openjpa.jdbc.schema.ForeignKey, org.apache.openjpa.jdbc.schema.Table, org.apache.openjpa.jdbc.schema.Table) if the join is inversed.


clear

public void clear()
Clear all mapping information.


clear

protected void clear(boolean canFlags)
Clear mapping information.

Parameters:
canFlags - whether to clear information about whether we can place indexed, foreign keys, etc on this mapping

copy

public void copy(MappingInfo info)
Copy missing info from the instance to this one.


hasSchemaComponents

public boolean hasSchemaComponents()
Return true if this info has columns, foreign key information, index information, etc.


assertNoSchemaComponents

public void assertNoSchemaComponents(MetaDataContext context,
                                     boolean die)
Assert that the user did not supply any columns, index, unique constraint, or foreign key for this mapping.


assertStrategy

public void assertStrategy(MetaDataContext context,
                           Object contextStrat,
                           Object expected,
                           boolean die)
Assert that this info has the given strategy or no strategy.


assertNoIndex

public void assertNoIndex(MetaDataContext context,
                          boolean die)
Assert that the user did not try to place an index on this mapping.


assertNoUnique

public void assertNoUnique(MetaDataContext context,
                           boolean die)
Assert that the user did not try to place a unique constraint on this mapping.


assertNoForeignKey

public void assertNoForeignKey(MetaDataContext context,
                               boolean die)
Assert that the user did not try to place a foreign key on this mapping.


assertNoJoin

public void assertNoJoin(MetaDataContext context,
                         boolean die)
Assert that the user did not try to join.


createTable

public Table createTable(MetaDataContext context,
                         MappingInfo.TableDefaults def,
                         String schemaName,
                         String given,
                         boolean adapt)
Find or generate a table for a mapping.

Parameters:
context - the mapping that uses the table
def - default table name provider
schemaName - default schema if known, or null
given - given table name
adapt - whether we can alter the schema or mappings

createColumns

protected Column[] createColumns(MetaDataContext context,
                                 String prefix,
                                 Column[] tmplates,
                                 Table table,
                                 boolean adapt)
Retrieve/create columns on the given table by merging the given template information with any user-provided information.

Parameters:
context - the mapping we're retrieving columns for
prefix - localized error message key prefix
tmplates - template columns
table - the table for the columns
adapt - whether we can modify the existing mapping or schema

mergeColumn

protected static Column mergeColumn(MetaDataContext context,
                                    String prefix,
                                    Column tmplate,
                                    boolean compat,
                                    Column given,
                                    Table table,
                                    boolean adapt,
                                    boolean fill)
Merge the given columns if possible.

Parameters:
context - the mapping we're retrieving columns for
prefix - localized error message key prefix
tmplate - template for expected column information
compat - whether the existing column type must be compatible with the type of the template column
given - the given column information from mapping info
table - the table for the columns
adapt - whether we can modify the existing mapping or schema
fill - whether to default missing column information

createIndex

protected Index createIndex(MetaDataContext context,
                            String prefix,
                            Index tmplate,
                            Column[] cols,
                            boolean adapt)
Retrieve/create an index on the given columns by merging the given template information with any user-provided information.

Parameters:
context - the mapping we're retrieving an index for
prefix - localized error message key prefix
tmplate - template for expected index information
cols - the indexed columns
adapt - whether we can modify the existing mapping or schema

createUnique

protected Unique createUnique(MetaDataContext context,
                              String prefix,
                              Unique tmplate,
                              Column[] cols,
                              boolean adapt)
Retrieve/create a unique constraint on the given columns by merging the given template information with any user-provided information.

Parameters:
context - the mapping we're retrieving a constraint for
prefix - localized error message key prefix
tmplate - template for expected unique information
cols - the constraint columns
adapt - whether we can modify the existing mapping or schema

createForeignKey

protected ForeignKey createForeignKey(MetaDataContext context,
                                      String prefix,
                                      List given,
                                      MappingInfo.ForeignKeyDefaults def,
                                      Table table,
                                      ClassMapping cls,
                                      ClassMapping rel,
                                      boolean inversable,
                                      boolean adapt)
Retrieve/create a foreign key (possibly logical) on the given columns by merging the given template information with any user-provided information.

Parameters:
context - the mapping we're retrieving a key for
prefix - localized error message key prefix
given - the columns given by the user
def - defaults provider
table - the table for the key
cls - type we're joining from
rel - target type we're joining to
inversable - whether the foreign key can be inversed
adapt - whether we can modify the existing mapping or schema

syncColumns

protected void syncColumns(MetaDataContext context,
                           Column[] cols,
                           boolean forceJDBCType)
Sets internal column information to match the given mapped columns.

Parameters:
forceJDBCType - whether to force the jdbc-type of the columns to be set, even when it matches the default for the columns' java type

syncIndex

protected void syncIndex(MetaDataContext context,
                         Index idx)
Sets internal index information to match given mapped index.


syncUnique

protected void syncUnique(MetaDataContext context,
                          Unique unq)
Sets internal constraint information to match given mapped constraint.


syncForeignKey

protected void syncForeignKey(MetaDataContext context,
                              ForeignKey fk,
                              Table local,
                              Table target)
Sets internal constraint and column information to match given mapped constraint.

Parameters:
local - default local table
target - default target table

syncColumn

protected static Column syncColumn(MetaDataContext context,
                                   Column col,
                                   int num,
                                   boolean forceJDBCType,
                                   Table colTable,
                                   Table targetTable,
                                   Object target,
                                   boolean inverse)
Create a copy of the given column with the raw mapping information set correctly, and without settings that match defaults.

Parameters:
num - the number of columns for this mapping
forceJDBCType - whether the jdbc-type of the created column should be set, even if it matches the default for the given column's java type
colTable - expected table for the column
targetTable - expected target table for join column
target - target column or object for join column; for a constant null target, use NULL
inverse - whether join column is for inverse join


Copyright © 2006-2009 Apache Software Foundation. All Rights Reserved.