org.javagen.revgen.mapping
Class Db2JavaMapper

java.lang.Object
  extended by org.javagen.revgen.mapping.Db2JavaMapper
All Implemented Interfaces:
Db2OOMapper

public class Db2JavaMapper
extends Object
implements Db2OOMapper

Maps DB elements to Java types and names.

TODO with a little more refactoring this class could be non-Java specific and renamed DefaultDb2OOMapper.

Author:
Richard Easterling

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.javagen.revgen.mapping.Db2OOMapper
Db2OOMapper.ReferenceNamingStrategy
 
Field Summary
static String DEFAULT_TYPE
           
protected  org.javagen.agile.oo.naming.OONamingService ooNamingService
           
 
Constructor Summary
Db2JavaMapper()
           
 
Method Summary
 String classNameSingular(org.javagen.agile.db.model.Table table)
          Uses camel-back naming conventions to convert table name to class name converting plural to singular names as specified in the OONamingService.
 String containerType(org.javagen.agile.db.model.FkConstraint fkConstraint)
          Given a foreign key constraint with a many-sided mapping, return container interface.
 org.javagen.agile.db.model.Cardinality determineCardinality(org.javagen.agile.db.model.FkConstraint fkConstraint)
          Determines the cardinality based on foreign key constraints as follows: If cardinality is already set just return it. if a link table is referenced, return MANY_TO_MANY. If foreign key is unique, return ONE_TO_ONE. Otherwise, return MANY_TO_ONE for the side that contains the foreign key and ONE_TO_MANY for the opposite side.
 org.javagen.agile.oo.naming.Collections getCollections()
           
 String getDefaultType()
           
 org.javagen.agile.oo.naming.OONamingService getOONamingService()
           
 boolean getPluralTableNames()
           
 org.javagen.agile.core.util.RegexRenamer getRegexRenamer()
           
 boolean isManyCardinality(org.javagen.agile.db.model.FkConstraint fkConstraint)
          This method calls determineCardinality as a side effect
 String propertyNameSingular(org.javagen.agile.db.model.Column column)
          Uses camel-back naming conventions to convert column name to property name.
 String propertyType(org.javagen.agile.db.model.Column column)
          Tries to find best Java type for column type.
 String referenceName(org.javagen.agile.db.model.FkConstraint fkConstraint)
          Name reference based on ReferenceNamingStrategy.
 org.javagen.agile.oo.model.Class referenceType(org.javagen.agile.db.model.FkConstraint fkConstraint)
          Given a foreign key constraint assign the property type based on the target class, including special handling needed for relations containing link tables.
 void setCollections(org.javagen.agile.oo.naming.Collections collections)
           
 void setDefaultType(String defaultType)
           
 void setOONamingService(org.javagen.agile.oo.naming.OONamingService ooNamingService)
           
 void setPluralTableNames(boolean pluralTableNames)
           
 void setReferenceNamingStrategy(Db2OOMapper.ReferenceNamingStrategy referenceNamingStrategy)
           
 void setReferenceNamingStrategyString(String referenceNamingStrategy)
           
 void setRegexRenamer(org.javagen.agile.core.util.RegexRenamer regexRenamer)
           
 void setRegexReplacePairs(String replacePatterns)
          Property file friendly means of adding regex-replacePattern pairs as comma-delineated list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_TYPE

public static final String DEFAULT_TYPE
See Also:
Constant Field Values

ooNamingService

protected org.javagen.agile.oo.naming.OONamingService ooNamingService
Constructor Detail

Db2JavaMapper

public Db2JavaMapper()
Method Detail

classNameSingular

public String classNameSingular(org.javagen.agile.db.model.Table table)
Uses camel-back naming conventions to convert table name to class name converting plural to singular names as specified in the OONamingService.

Applies regular expression renaming if a RegexRenamer is set.

Specified by:
classNameSingular in interface Db2OOMapper

propertyNameSingular

public String propertyNameSingular(org.javagen.agile.db.model.Column column)
Uses camel-back naming conventions to convert column name to property name.

Applies regular expression renaming if a RegexRenamer is set.

Specified by:
propertyNameSingular in interface Db2OOMapper

propertyType

public String propertyType(org.javagen.agile.db.model.Column column)
Tries to find best Java type for column type. The following rules are applied in order:
  1. if column size is 1 char and default is 'Y', 'N', 'T' or 'F' then convert to a boolean.
  2. If NUMERIC OR DECIMAL use the smallest possible Java type for the specified precision.
  3. If column is primary or foreign key, use wrapper types for numbers.
  4. For non-null simple types use primitives (byte, int, float), otherwise use the wrapper types (Byte, Integer, Float).
  5. Otherwise use default JDBC mapping types.
  6. If still no match is found use the defaultType, set by default to a String.

Specified by:
propertyType in interface Db2OOMapper

referenceType

public org.javagen.agile.oo.model.Class referenceType(org.javagen.agile.db.model.FkConstraint fkConstraint)
Given a foreign key constraint assign the property type based on the target class, including special handling needed for relations containing link tables.

Specified by:
referenceType in interface Db2OOMapper

referenceName

public String referenceName(org.javagen.agile.db.model.FkConstraint fkConstraint)
Name reference based on ReferenceNamingStrategy. Name will be plural or singular based on cardinality.

Applies regular expression renaming if a RegexRenamer is set.

Specified by:
referenceName in interface Db2OOMapper
Parameters:
fkConstraint -
Returns:
reference name for resulting Java property.

isManyCardinality

public boolean isManyCardinality(org.javagen.agile.db.model.FkConstraint fkConstraint)
This method calls determineCardinality as a side effect

Specified by:
isManyCardinality in interface Db2OOMapper
Returns:
true if target table cardinality is to-many.

determineCardinality

public org.javagen.agile.db.model.Cardinality determineCardinality(org.javagen.agile.db.model.FkConstraint fkConstraint)
Determines the cardinality based on foreign key constraints as follows:
  1. If cardinality is already set just return it.
  2. if a link table is referenced, return MANY_TO_MANY.
  3. If foreign key is unique, return ONE_TO_ONE.
  4. Otherwise, return MANY_TO_ONE for the side that contains the foreign key and ONE_TO_MANY for the opposite side.

Specified by:
determineCardinality in interface Db2OOMapper
Returns:
cardinality based on FkConstraint.

containerType

public String containerType(org.javagen.agile.db.model.FkConstraint fkConstraint)
Given a foreign key constraint with a many-sided mapping, return container interface.

Specified by:
containerType in interface Db2OOMapper
Returns:
name of type (LIST, SET, MAP, BAG) or null if to-one relationship
See Also:
org.javagen.agile.oo.namaing.Collections

setReferenceNamingStrategy

public void setReferenceNamingStrategy(Db2OOMapper.ReferenceNamingStrategy referenceNamingStrategy)
Specified by:
setReferenceNamingStrategy in interface Db2OOMapper

setReferenceNamingStrategyString

public void setReferenceNamingStrategyString(String referenceNamingStrategy)

getOONamingService

public org.javagen.agile.oo.naming.OONamingService getOONamingService()

setOONamingService

public void setOONamingService(org.javagen.agile.oo.naming.OONamingService ooNamingService)

getCollections

public org.javagen.agile.oo.naming.Collections getCollections()

setCollections

public void setCollections(org.javagen.agile.oo.naming.Collections collections)

getDefaultType

public String getDefaultType()

setDefaultType

public void setDefaultType(String defaultType)

getRegexRenamer

public org.javagen.agile.core.util.RegexRenamer getRegexRenamer()

setRegexRenamer

public void setRegexRenamer(org.javagen.agile.core.util.RegexRenamer regexRenamer)

setRegexReplacePairs

public void setRegexReplacePairs(String replacePatterns)
Property file friendly means of adding regex-replacePattern pairs as comma-delineated list.

See Also:
RegexRenamer.setRegexReplacePairs(String)

getPluralTableNames

public boolean getPluralTableNames()

setPluralTableNames

public void setPluralTableNames(boolean pluralTableNames)


Copyright 2006-2006-2007 Outsource Cafe Inc.. All Rights Reserved.