com.sun.jdo.spi.persistence.generator.database
Class MappingPolicy

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

public class MappingPolicy
extends java.lang.Object
implements java.lang.Cloneable

Describes how Java classes and their fields are to be mapped to database tables and columns


Field Summary
static java.lang.String USE_UNIQUE_TABLE_NAMES
          Property name which indicates unique table names should be generated.
 
Method Summary
protected  java.lang.Object clone()
          Clones the vendor-specific policy for generator session.
 java.lang.String getColumnName(java.lang.String className, java.lang.String fieldName, java.lang.String tableName)
          Returns the name of a column for a given field in a given class.
 java.lang.String getConstraintColumnName(java.lang.String tableName, java.lang.String columnName)
          Returns the name of the column which represents a foreign key in the named table.
 java.lang.String getConstraintName(java.lang.String relName, java.lang.String uniqueId)
          Returns the name of a constraint corresponding to the named relationship.
 com.sun.jdo.spi.persistence.generator.database.JDBCInfo getJDBCInfo(java.lang.String fieldName, java.lang.String fieldType)
          Returns JDBC type information corresponding to the given field name and type.
static java.lang.String getJdbcTypeName(int type)
          Provide the String name of a JDBC type, as per java.sql.Types.
 java.lang.String getJoinTableName(java.lang.String className1, java.lang.String className2)
          Returns the name of a join table which joins the tables that correspond to the two named classes.
static MappingPolicy getMappingPolicy(java.lang.String databaseType)
          Returns a vendor-specifc MappingPolicy instance.
static java.lang.String getOverrideForLength(java.lang.String className, java.lang.String fieldName)
          Provides a String that can be recognized as a policy to override the default length of a field.
static java.lang.String getOverrideForNullability(java.lang.String className, java.lang.String fieldName)
          Provides a String that can be recognized as a policy to override the default nullability of a field.
static java.lang.String getOverrideForPrecision(java.lang.String className, java.lang.String fieldName)
          Provides a String that can be recognized as a policy to override the default precision of a field.
static java.lang.String getOverrideForScale(java.lang.String className, java.lang.String fieldName)
          Provides a String that can be recognized as a policy to override the default scale of a field.
static java.lang.String getOverrideForType(java.lang.String className, java.lang.String fieldName)
          Provides a String that can be recognized as a policy to override the default type of a field.
 java.lang.String getPrimaryKeyConstraintName(java.lang.String tableName)
          Returns the name of a PK constraint, unique-ified as required.
 java.lang.String getSQLTypeName(int jdbcType)
          Returns the String name of the SQL type for a given JDBC type.
 java.lang.String getTableName(java.lang.String name, java.lang.String uniqueName)
          Returns the name of a table for a given class, as per current policy.
 void setUniqueTableName(boolean uniqueTableName)
          Sets whether or not unique table names should be generated.
 void setUserPolicy(java.util.Properties props)
          Sets user-provided policy to that provided in the given properties.
 java.lang.String toString()
          Debug support.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

USE_UNIQUE_TABLE_NAMES

public static final java.lang.String USE_UNIQUE_TABLE_NAMES
Property name which indicates unique table names should be generated.

See Also:
Constant Field Values
Method Detail

getMappingPolicy

public static MappingPolicy getMappingPolicy(java.lang.String databaseType)
                                      throws java.io.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:
java.io.IOException - if there are problems reading the vendor- specific mappinng policy file

clone

protected java.lang.Object clone()
                          throws java.lang.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 java.lang.Object
Returns:
clone of this MappingPolicy
Throws:
java.lang.CloneNotSupportedException - never thrown

setUserPolicy

public void setUserPolicy(java.util.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 java.lang.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(java.lang.String fieldName,
                                                                           java.lang.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 java.lang.String getOverrideForLength(java.lang.String className,
                                                    java.lang.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 java.lang.String getOverrideForNullability(java.lang.String className,
                                                         java.lang.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 java.lang.String getOverrideForPrecision(java.lang.String className,
                                                       java.lang.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 java.lang.String getOverrideForScale(java.lang.String className,
                                                   java.lang.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 java.lang.String getOverrideForType(java.lang.String className,
                                                  java.lang.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 java.lang.String getJdbcTypeName(int type)
                                        throws java.lang.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:
java.lang.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 java.lang.String getTableName(java.lang.String name,
                                     java.lang.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 java.lang.String getColumnName(java.lang.String className,
                                      java.lang.String fieldName,
                                      java.lang.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 java.lang.String getConstraintColumnName(java.lang.String tableName,
                                                java.lang.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 java.lang.String getConstraintName(java.lang.String relName,
                                          java.lang.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 java.lang.String getPrimaryKeyConstraintName(java.lang.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 java.lang.String getJoinTableName(java.lang.String className1,
                                         java.lang.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 java.lang.String toString()
Debug support.

Overrides:
toString in class java.lang.Object
Returns:
A description of this MappingPolicy in string form. Basically, all it's "interesting" values.


Copyright © 2012 GlassFish Community. All Rights Reserved.