Class MappingPolicy
java.lang.Object
com.sun.jdo.spi.persistence.generator.database.MappingPolicy
- All Implemented Interfaces:
Cloneable
Describes how Java classes and their fields are to be mapped to database
tables and columns
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringProperty name which indicates unique table names should be generated. -
Method Summary
Modifier and TypeMethodDescriptionprotected Objectclone()Clones the vendor-specific policy for generator session.getColumnName(String className, String fieldName, String tableName) Returns the name of a column for a given field in a given class.getConstraintColumnName(String tableName, String columnName) Returns the name of the column which represents a foreign key in the named table.getConstraintName(String relName, String uniqueId) Returns the name of a constraint corresponding to the named relationship.com.sun.jdo.spi.persistence.generator.database.JDBCInfogetJDBCInfo(String fieldName, String fieldType) Returns JDBC type information corresponding to the given field name and type.static StringgetJdbcTypeName(int type) Provide the String name of a JDBC type, as per java.sql.Types.getJoinTableName(String className1, String className2) Returns the name of a join table which joins the tables that correspond to the two named classes.static MappingPolicygetMappingPolicy(String databaseType) Returns a vendor-specifc MappingPolicy instance.static StringgetOverrideForLength(String className, String fieldName) Provides a String that can be recognized as a policy to override the default length of a field.static StringgetOverrideForNullability(String className, String fieldName) Provides a String that can be recognized as a policy to override the default nullability of a field.static StringgetOverrideForPrecision(String className, String fieldName) Provides a String that can be recognized as a policy to override the default precision of a field.static StringgetOverrideForScale(String className, String fieldName) Provides a String that can be recognized as a policy to override the default scale of a field.static StringgetOverrideForType(String className, String fieldName) Provides a String that can be recognized as a policy to override the default type of a field.getPrimaryKeyConstraintName(String tableName) Returns the name of a PK constraint, unique-ified as required.getSQLTypeName(int jdbcType) Returns the String name of the SQL type for a given JDBC type.getTableName(String name, String uniqueName) Returns the name of a table for a given class, as per current policy.voidsetUniqueTableName(boolean uniqueTableName) Sets whether or not unique table names should be generated.voidsetUserPolicy(Properties props) Sets user-provided policy to that provided in the given properties.toString()Debug support.
-
Field Details
-
USE_UNIQUE_TABLE_NAMES
Property name which indicates unique table names should be generated.- See Also:
-
-
Method Details
-
getMappingPolicy
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
Clones the vendor-specific policy for generator session. Replace the namespaces map in the clone, so that each instance has its own.- Overrides:
clonein classObject- Returns:
- clone of this MappingPolicy
- Throws:
CloneNotSupportedException- never thrown
-
setUserPolicy
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- Iftrue, tables names will be unique.
-
getSQLTypeName
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 isnullor 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
Provides a String that can be recognized as a policy to override the default length of a field.- Parameters:
className- name of a classfieldName- 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
Provides a String that can be recognized as a policy to override the default nullability of a field.- Parameters:
className- name of a classfieldName- 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
Provides a String that can be recognized as a policy to override the default precision of a field.- Parameters:
className- name of a classfieldName- 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
Provides a String that can be recognized as a policy to override the default scale of a field.- Parameters:
className- name of a classfieldName- 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
Provides a String that can be recognized as a policy to override the default type of a field.- Parameters:
className- name of a classfieldName- 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
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- iftypeis 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
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
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
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
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 ifuniqueTableNameis true.- Returns:
- Name of a constraint.
-
getPrimaryKeyConstraintName
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
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
Debug support.
-