ca.sqlpower.architect.ddl
Class TypeMap

java.lang.Object
  extended by ca.sqlpower.architect.ddl.TypeMap

public class TypeMap
extends java.lang.Object

Author:
jack TypeMap is a singleton which is used by SQLColumn to fix known weird metadata that comes from JDBC drivers. For example, database with unlimited character fields report the precision as -1, which totally messes up forward engineering. In the root directory of the Architect, there is a file called mappingrules.properties, which is a UNIX style whitespace delimited file that contains mapping rules for these strange situations. Rules are processed in the order in which they are found, so if two rules effect the same metadata field, then the second one will win. TODO: Eventually, these mapping rules should most likely be added to the User Settings to allow users to add their own custom rules. XXX: Once users are allowed to make their own rules, there may be some concurrency issues with the singleton class (i.e. concurrent modification exceptions on the Iterators which are used to grab lists of rules for particular database/nativeType). There is also some question about how thread safe pattern.matcher() is.

Nested Class Summary
 class TypeMap.MappingRule
           
 
Field Summary
protected static TypeMap mainInstance
           
 
Constructor Summary
protected TypeMap()
          populate the rules from mappingrules.properties
 
Method Summary
 boolean addRule(TypeMap.MappingRule rule)
          calls to getRulesForNative type create new database and native type entries on an as needed basis (it's called with createNew = true).
 boolean applyRules(SQLColumn col)
          applicable rules are applied in the order in which they are found.
static TypeMap getInstance()
           
protected  java.util.List getRules(SQLColumn col)
          Get the set of rules that apply for this SQLColumn.
protected  java.util.List getRulesForNativeType(java.lang.String database, java.lang.String nativeType, boolean createNew)
          only create new database and native type entries when createNew is true.
protected  java.util.List getRulesForNativeType(TypeMap.MappingRule rule, boolean createNew)
          Get a list of rules for a native type.
static void main(java.lang.String[] args)
           
 boolean removeRule(TypeMap.MappingRule rule)
          remove a mapping rule from the rules collection
protected  boolean satisfiesComparison(java.lang.Comparable c1, java.lang.Comparable c2, java.lang.String operator)
          convenience method for checking if a rule criteria is satisifed
 java.lang.String translateDatabaseName(java.lang.String name)
          change the upper case with spaces style name from SQLDatabase into a lowercase name with no spaces.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mainInstance

protected static TypeMap mainInstance
Constructor Detail

TypeMap

protected TypeMap()
populate the rules from mappingrules.properties

Method Detail

main

public static void main(java.lang.String[] args)

getInstance

public static TypeMap getInstance()
Returns:
singleton instance

addRule

public boolean addRule(TypeMap.MappingRule rule)
calls to getRulesForNative type create new database and native type entries on an as needed basis (it's called with createNew = true).

Parameters:
rule -
Returns:

removeRule

public boolean removeRule(TypeMap.MappingRule rule)
remove a mapping rule from the rules collection

Parameters:
rule -
Returns:
true if we removed something, false if we didn't find it

getRulesForNativeType

protected java.util.List getRulesForNativeType(TypeMap.MappingRule rule,
                                               boolean createNew)
Get a list of rules for a native type.

Returns:
arraylist of rules

getRulesForNativeType

protected java.util.List getRulesForNativeType(java.lang.String database,
                                               java.lang.String nativeType,
                                               boolean createNew)
only create new database and native type entries when createNew is true. this prevents bogus map entries from being created when doing lookups. notice that a SQLColumn is not passed in, so the rules list is not cut down to size.

Parameters:
database -
nativeType -
createNew -
Returns:
See Also:
for the method which determines which rules are in effect

getRules

protected java.util.List getRules(SQLColumn col)
Get the set of rules that apply for this SQLColumn. Grab the whole list that applies for this database/nativeType and based on the contents of SQLColumn, return a subset of the ones that apply. The rules are not processed here. You can't process rules as you find them because you'll get side effects as you try to apply other rules.

Parameters:
col -
Returns:
See Also:
for the code which actually processes the rules.

satisfiesComparison

protected boolean satisfiesComparison(java.lang.Comparable c1,
                                      java.lang.Comparable c2,
                                      java.lang.String operator)
convenience method for checking if a rule criteria is satisifed

Returns:
boolean to tell if the rule is satisfied. Works equally well with Strings and Integer.

applyRules

public boolean applyRules(SQLColumn col)
applicable rules are applied in the order in which they are found. The applicability of a rule is based on the original state of the SQLColumn, not the transitional state as rules are applied.

Parameters:
col -
Returns:
tell the caller if any rules were applied. this could also be an integer...

translateDatabaseName

public java.lang.String translateDatabaseName(java.lang.String name)
change the upper case with spaces style name from SQLDatabase into a lowercase name with no spaces. the mappingrules.properties file cannot have spaces in the values (whitespace is the delimiter!)

Parameters:
name -
Returns:
the translated string


Copyright © 2003-2007 SQL Power Group Inc. www.sqlpower.ca