net.sf.saffron.core
Class SaffronTypeFactoryImpl

java.lang.Object
  |
  +--net.sf.saffron.core.SaffronTypeFactoryImpl
All Implemented Interfaces:
SaffronTypeFactory
Direct Known Subclasses:
OJTypeFactoryImpl

public class SaffronTypeFactoryImpl
extends Object
implements SaffronTypeFactory

Skeletal implementation of SaffronTypeFactory.

Since:
May 31, 2003
Version:
$Id: //open/saffron/src/net/sf/saffron/core/SaffronTypeFactoryImpl.java#6 $
Author:
jhyde

Nested Class Summary
protected  class SaffronTypeFactoryImpl.CrossType
          Type of the cartesian product of two or more sets of records.
protected static class SaffronTypeFactoryImpl.FieldImpl
          Simple implementation of SaffronField
protected  class SaffronTypeFactoryImpl.JavaType
          Type which is based upon a Java class.
protected  class SaffronTypeFactoryImpl.RecordType
          Type which is a set of named fields.
(package private)  class SaffronTypeFactoryImpl.SqlType
          SQL scalar type.
protected  class SaffronTypeFactoryImpl.TypeImpl
          Abstract implementation for SaffronType.
 
Nested classes inherited from class net.sf.saffron.core.SaffronTypeFactory
SaffronTypeFactory.FieldInfo
 
Field Summary
private  HashMap map
           
private static ThreadLocal threadInstances
           
 
Constructor Summary
SaffronTypeFactoryImpl()
           
 
Method Summary
private static void addFields(SaffronType type, ArrayList fieldList)
          Adds all fields in type to fieldList.
protected  SaffronType canonize(SaffronType type)
          Registers a type, or returns the existing type if it is already registered.
 SaffronType createJavaType(Class clazz)
          Creates a type which encapsulates a Java class.
 SaffronType createJoinType(SaffronType[] types)
          Creates a cartesian product type.
 SaffronType createProjectType(SaffronType[] types, String[] fieldNames)
          Creates a type which represents a projection of a set of fields.
 SaffronType createProjectType(SaffronTypeFactory.FieldInfo fieldInfo)
          Creates a type which represents a projection of a set fields, getting the field informatation from a callback.
 SaffronTypeFactoryImpl.SqlType createSqlType(SqlTypeName typeName)
          Creates a SQL type with no precision or scale.
 SaffronTypeFactoryImpl.SqlType createSqlType(SqlTypeName typeName, int length)
          Creates a SQL type with length (precision) but no scale.
 SaffronTypeFactoryImpl.SqlType createSqlType(SqlTypeName typeName, int length, int scale)
          Creates a SQL type with length (precision) and scale.
 SaffronType createTypeWithNullability(SaffronType type, boolean nullable)
          Creates a Type which is the same as another type but with possibily different nullability.
private  SaffronField[] fieldsOf(Class clazz)
           
 SaffronType getComponentType(SaffronType type)
           
private static SaffronField[] getFieldArray(SaffronType[] types)
          Returns an array of the fields in an array of types.
private static SaffronType[] getTypeArray(SaffronType[] types)
          Returns an array of all atomic types in an array.
private static void getTypeArray(SaffronType[] types, ArrayList typeList)
           
 SaffronType leastRestrictive(SaffronType[] types)
          Returns the most general of a set of types (that is, one type to which they can all be cast), or null if conversion is not possible.
static void setThreadInstance(SaffronTypeFactory typeFactory)
           
static SaffronTypeFactory threadInstance()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

threadInstances

private static ThreadLocal threadInstances

map

private HashMap map
Constructor Detail

SaffronTypeFactoryImpl

public SaffronTypeFactoryImpl()
Method Detail

setThreadInstance

public static void setThreadInstance(SaffronTypeFactory typeFactory)

createJavaType

public SaffronType createJavaType(Class clazz)
Description copied from interface: SaffronTypeFactory
Creates a type which encapsulates a Java class.

Specified by:
createJavaType in interface SaffronTypeFactory

createJoinType

public SaffronType createJoinType(SaffronType[] types)
Description copied from interface: SaffronTypeFactory
Creates a cartesian product type.

Specified by:
createJoinType in interface SaffronTypeFactory

createProjectType

public SaffronType createProjectType(SaffronType[] types,
                                     String[] fieldNames)
Description copied from interface: SaffronTypeFactory
Creates a type which represents a projection of a set of fields.

The return is canonical: if an equivalent type already exists, it is returned.

Specified by:
createProjectType in interface SaffronTypeFactory
Parameters:
types - Types of the fields
fieldNames - Names of the fields
Returns:
a type

createProjectType

public SaffronType createProjectType(SaffronTypeFactory.FieldInfo fieldInfo)
Description copied from interface: SaffronTypeFactory
Creates a type which represents a projection of a set fields, getting the field informatation from a callback.

Specified by:
createProjectType in interface SaffronTypeFactory

getComponentType

public SaffronType getComponentType(SaffronType type)

leastRestrictive

public SaffronType leastRestrictive(SaffronType[] types)
Description copied from interface: SaffronTypeFactory
Returns the most general of a set of types (that is, one type to which they can all be cast), or null if conversion is not possible.

Specified by:
leastRestrictive in interface SaffronTypeFactory

createTypeWithNullability

public SaffronType createTypeWithNullability(SaffronType type,
                                             boolean nullable)
Description copied from interface: SaffronTypeFactory
Creates a Type which is the same as another type but with possibily different nullability. For type systems without a concept of nullability, the return value is always the same as the input.

Specified by:
createTypeWithNullability in interface SaffronTypeFactory
Parameters:
type - input type
nullable - true to request a nullable type; false to request a NOT NULL type
Returns:
output type, same as input type except with specified nullability

threadInstance

public static SaffronTypeFactory threadInstance()

canonize

protected SaffronType canonize(SaffronType type)
Registers a type, or returns the existing type if it is already registered.


getFieldArray

private static SaffronField[] getFieldArray(SaffronType[] types)
Returns an array of the fields in an array of types.


getTypeArray

private static SaffronType[] getTypeArray(SaffronType[] types)
Returns an array of all atomic types in an array.


getTypeArray

private static void getTypeArray(SaffronType[] types,
                                 ArrayList typeList)

addFields

private static void addFields(SaffronType type,
                              ArrayList fieldList)
Adds all fields in type to fieldList.


fieldsOf

private SaffronField[] fieldsOf(Class clazz)

createSqlType

public SaffronTypeFactoryImpl.SqlType createSqlType(SqlTypeName typeName)
Description copied from interface: SaffronTypeFactory
Creates a SQL type with no precision or scale.

Specified by:
createSqlType in interface SaffronTypeFactory
Parameters:
typeName - Name of the type, for example SqlTypeName.Boolean.
Returns:
A type

createSqlType

public SaffronTypeFactoryImpl.SqlType createSqlType(SqlTypeName typeName,
                                                    int length)
Description copied from interface: SaffronTypeFactory
Creates a SQL type with length (precision) but no scale.

Specified by:
createSqlType in interface SaffronTypeFactory
Parameters:
typeName - Name of the type, for example SqlTypeName.Varchar.
length - Maximum length of the value (non-numeric types) or the precision of the value (numeric types)
Returns:
A type

createSqlType

public SaffronTypeFactoryImpl.SqlType createSqlType(SqlTypeName typeName,
                                                    int length,
                                                    int scale)
Description copied from interface: SaffronTypeFactory
Creates a SQL type with length (precision) and scale.

Specified by:
createSqlType in interface SaffronTypeFactory
Parameters:
typeName - Name of the type, for example SqlTypeName.Varchar.
length - Maximum length of the value (non-numeric types) or the precision of the value (numeric types)
scale - Scale of the values. The number of decimal places to shift the value. For example, a NUMBER(10,3) value of "123.45" is represented "123450" (that is, multiplied by 10^3). A negative scale is valid.
Returns:
A type

SourceForge.net_Logo