Class MappingPolicy

java.lang.Object
com.sun.jdo.spi.persistence.generator.database.MappingPolicy
All Implemented Interfaces:
Cloneable

public class MappingPolicy extends Object implements Cloneable
Describes how Java classes and their fields are to be mapped to database tables and columns
  • Field Details

    • USE_UNIQUE_TABLE_NAMES

      public static final String USE_UNIQUE_TABLE_NAMES
      Property name which indicates unique table names should be generated.
      See Also:
  • Method Details

    • getMappingPolicy

      public static MappingPolicy getMappingPolicy(String databaseType) throws IOException
      Returns a vendor-specifc MappingPolicy instance. This method always returns a copy (clone) of the known MappingPolicy to allow for user-specific overrides.
      Parameters:
      databaseType - a database vendor name as a String.
      Returns:
      MappingPolicy instance corresponding to the provided database vendor name.
      Throws:
      IOException - if there are problems reading the vendor- specific mappinng policy file
    • clone

      protected Object clone() throws CloneNotSupportedException
      Clones the vendor-specific policy for generator session. Replace the namespaces map in the clone, so that each instance has its own.
      Overrides:
      clone in class Object
      Returns:
      clone of this MappingPolicy
      Throws:
      CloneNotSupportedException - never thrown
    • setUserPolicy

      public void setUserPolicy(Properties props)
      Sets user-provided policy to that provided in the given properties.
      Parameters:
      props - Properties which override built in defaults.
    • setUniqueTableName

      public void setUniqueTableName(boolean uniqueTableName)
      Sets whether or not unique table names should be generated.
      Parameters:
      uniqueTableName - If true, tables names will be unique.
    • getSQLTypeName

      public String getSQLTypeName(int jdbcType)
      Returns the String name of the SQL type for a given JDBC type.
      Parameters:
      jdbcType - One of the values from java.sql.Types.
      Returns:
      Name of SQL type corresponding to given jdbcType.
    • getJDBCInfo

      public com.sun.jdo.spi.persistence.generator.database.JDBCInfo getJDBCInfo(String fieldName, String fieldType)
      Returns JDBC type information corresponding to the given field name and type. If fieldName is null or there is no fieldName - specific information already existing, the default for the given fieldType is returned. Otherwise, information specific to the fieldName is returned. Note: It is possible to have a field in a class have the same name as another class; this mechanism is not robust in that case:
       class Foo { }
      
       class MyFoo {
           Foo Foo = new Foo();
       }
       
      We think this obfuscation unlikely to occur.
      Parameters:
      fieldName - Name of field for which information is needed. May be null, in which case only fieldType is used to determine returned information.
      fieldType - Name of a Java type.
      Returns:
      JDBCInfo representing the field or type.
    • getOverrideForLength

      public static String getOverrideForLength(String className, String fieldName)
      Provides a String that can be recognized as a policy to override the default length of a field.
      Parameters:
      className - name of a class
      fieldName - name of a field in that class
      Returns:
      a String that can be used as the name of a length override for a field in a class.
    • getOverrideForNullability

      public static String getOverrideForNullability(String className, String fieldName)
      Provides a String that can be recognized as a policy to override the default nullability of a field.
      Parameters:
      className - name of a class
      fieldName - name of a field in that class
      Returns:
      a String that can be used as the name of a nullability override for a field in a class.
    • getOverrideForPrecision

      public static String getOverrideForPrecision(String className, String fieldName)
      Provides a String that can be recognized as a policy to override the default precision of a field.
      Parameters:
      className - name of a class
      fieldName - name of a field in that class
      Returns:
      a String that can be used as the name of a precision override for a field in a class.
    • getOverrideForScale

      public static String getOverrideForScale(String className, String fieldName)
      Provides a String that can be recognized as a policy to override the default scale of a field.
      Parameters:
      className - name of a class
      fieldName - name of a field in that class
      Returns:
      a String that can be used as the name of a scale override for a field in a class.
    • getOverrideForType

      public static String getOverrideForType(String className, String fieldName)
      Provides a String that can be recognized as a policy to override the default type of a field.
      Parameters:
      className - name of a class
      fieldName - name of a field in that class
      Returns:
      a String that can be used as the name of a type override for a field in a class.
    • getJdbcTypeName

      public static String getJdbcTypeName(int type) throws IllegalArgumentException
      Provide the String name of a JDBC type, as per java.sql.Types.
      Parameters:
      type - A value from java.sql.Types
      Returns:
      the String name corresponding to type
      Throws:
      IllegalArgumentException - if type is not recognized as being a valid member of java.sql.Types. Note that only a subset of the types in java.sql.Types are recognized.
    • getTableName

      public String getTableName(String name, String uniqueName)
      Returns the name of a table for a given class, as per current policy.
      Parameters:
      name - Basis for what the returned table should be named, for example the unqualified name of a class.
      uniqueName - Used if the current policy is to return a unique name. Client must provide a name that is unique to them.
      Returns:
      Name to be used for table. Regardless of the current policy, the name is different from other names returned during the current run of DatabaseGenerator.generate(com.sun.jdo.api.persistence.model.Model, java.util.List, com.sun.jdo.spi.persistence.generator.database.MappingPolicy, java.lang.String, java.lang.String, boolean).
    • getColumnName

      public String getColumnName(String className, String fieldName, String tableName)
      Returns the name of a column for a given field in a given class. The column name will be unique within the table.
      Parameters:
      className - Name of the class containing the field.
      fieldName - Name of the field for which a column name is returned.
      tableName - Name of the table in which the column name is created.
      Returns:
      Name of a column that is unique within the named table.
    • getConstraintColumnName

      public String getConstraintColumnName(String tableName, String columnName)
      Returns the name of the column which represents a foreign key in the named table.
      Parameters:
      tableName - Name of the table in which the FK column will be created.
      columnName - Name of PK column in referenced table.
      Returns:
      Name of the FK column in the named table.
    • getConstraintName

      public String getConstraintName(String relName, String uniqueId)
      Returns the name of a constraint corresponding to the named relationship.
      Parameters:
      relName - Name of a relationship.
      uniqueId - Id that can be appened to relName to distinguish it from other relNames in the database. Will be appended only if uniqueTableName is true.
      Returns:
      Name of a constraint.
    • getPrimaryKeyConstraintName

      public String getPrimaryKeyConstraintName(String tableName)
      Returns the name of a PK constraint, unique-ified as required.
      Parameters:
      tableName - Name of a table on which a constraint is to be placed.
      Returns:
      Name of a constraint on named table.
    • getJoinTableName

      public String getJoinTableName(String className1, String className2)
      Returns the name of a join table which joins the tables that correspond to the two named classes.
      Parameters:
      className1 - Name of one class to join.
      className2 - Name of the other class to join.
      Returns:
      Name of a join table.
    • toString

      public String toString()
      Debug support.
      Overrides:
      toString in class Object
      Returns:
      A description of this MappingPolicy in string form. Basically, all it's "interesting" values.