net.sf.farrago.type
Class FarragoTypeFactoryImpl

java.lang.Object
  extended by org.eigenbase.reltype.RelDataTypeFactoryImpl
      extended by org.eigenbase.sql.type.SqlTypeFactoryImpl
          extended by org.eigenbase.oj.OJTypeFactoryImpl
              extended by net.sf.farrago.type.FarragoTypeFactoryImpl
All Implemented Interfaces:
FarragoTypeFactory, OJTypeFactory, RelDataTypeFactory
Direct Known Subclasses:
LucidDbTypeFactory

public class FarragoTypeFactoryImpl
extends OJTypeFactoryImpl
implements FarragoTypeFactory

FarragoTypeFactoryImpl is the Farrago-specific implementation of the RelDataTypeFactory interface.

Version:
$Id: //open/dev/farrago/src/net/sf/farrago/type/FarragoTypeFactoryImpl.java#54 $
Author:
John V. Sichi

Nested Class Summary
 
Nested classes/interfaces inherited from class org.eigenbase.reltype.RelDataTypeFactoryImpl
RelDataTypeFactoryImpl.JavaType
 
Nested classes/interfaces inherited from interface org.eigenbase.reltype.RelDataTypeFactory
RelDataTypeFactory.FieldInfo, RelDataTypeFactory.ListFieldInfo
 
Field Summary
private  Map<RelDataType,OJClass> mapTypeToOJClass
           
private  int nextGeneratedClassId
           
private  FarragoRepos repos
          Repos for type object definitions.
private static int unknownCharPrecision
           
 
Fields inherited from class org.eigenbase.oj.OJTypeFactoryImpl
mapOJClassToType
 
Constructor Summary
FarragoTypeFactoryImpl(FarragoRepos repos)
           
 
Method Summary
private  RelDataType addDefaultAttributes(RelDataType type)
           
 RelDataType createCwmElementType(FemAbstractTypedElement abstractElement)
          Creates a type which represents the datatype of a FemAbstractTypedElement.
 RelDataType createCwmType(CwmSqldataType cwmType)
          Creates a type which represents a CwmSqldataType.
protected  RelDataType createCwmTypeImpl(CwmClassifier classifier, FemSqltypedElement element)
           
 RelDataType createJavaType(Class clazz)
          Creates a type which corresponds to a Java class.
 RelDataType createJdbcColumnType(ResultSet getColumnsResultSet, boolean substitute)
          Creates a type which represents column metadata returned by the DatabaseMetaData.getColumns(java.lang.String, java.lang.String, java.lang.String, java.lang.String) call.
 RelDataType createJdbcColumnType(ResultSet getColumnsResultSet, boolean substitute, Properties typeMapping)
          Creates a type which represents column metadata returned by the DatabaseMetaData.getColumns(java.lang.String, java.lang.String, java.lang.String, java.lang.String) call.
private  RelDataType createJdbcType(int typeOrdinal, String dbSpecTypeName, int precision, int scale, boolean isNullable, boolean substitute, Properties typeMapping)
           
 RelDataType createJoinType(RelDataType[] types)
          Creates a cartesian product type.
 RelDataType createMofType(StructuralFeature feature)
          Creates a type which represents a MOF feature.
 RelDataType createResultSetType(ResultSetMetaData metaData, boolean substitute)
          Creates a type which represents the row datatype of a JDBC ResultSet.
 RelDataType createResultSetType(ResultSetMetaData metaData, boolean substitute, Properties typeMapping)
          Creates a type which represents the row datatype of a JDBC ResultSet.
 RelDataType createSqlType(SqlTypeName typeName)
          Creates a SQL type with no precision or scale.
 RelDataType createSqlType(SqlTypeName typeName, int precision)
          Creates a SQL type with length (precision) but no scale.
 RelDataType createSqlType(SqlTypeName typeName, int precision, int scale)
          Creates a SQL type with precision and scale.
 RelDataType createStructTypeFromClassifier(CwmClassifier classifier)
          Creates a type which represents a structured row based on a classifier definition from the catalog.
private  String extractDataTypeName(String mapping)
           
private  int extractPrecision(String mapping, int precision)
           
private  int extractScale(String mapping, int scale)
           
(package private)  int generateClassId()
           
private  MethodDeclaration generateGetter(TypeName returnType, String methodName, Expression value)
          Generates a protected getter method
 Class getClassForJavaParamStyle(RelDataType type)
          Looks up the Class specified by the JAVA parameter style for user-defined routines.
 Class getClassForPrimitive(RelDataType type)
          Looks up the Class representing a primitive used to hold a value of the given type.
 Charset getDefaultCharset()
           
private  int[] getMappedDataType(int ordinal, int precision, int scale, String dbSpecTypeName, Properties typeMapping)
           
 FarragoRepos getRepos()
           
private  RelDataTypeComparability getUserDefinedComparability(FemUserDefinedType type)
           
 Expression getValueAccessExpression(RelDataType type, Expression expr)
          Constructs an OpenJava expression to access a value of an atomic type.
private  boolean isKnownUnsupportedJdbcType(SqlTypeName type)
           
private  Expression lookupTimeUnit(SqlIntervalQualifier.TimeUnit timeUnit)
          Generates an expression for a SqlIntervalQualifier.TimeUnit.
private  OJClass newDatetimeOJClass(Class superclass, OJClass declarer, RelDataType type)
           
private  OJClass newDecimalOJClass(OJClass declarer, RelDataType type)
           
private  OJClass newHolderOJClass(Class superclass, MemberDeclarationList memberDecls, OJClass declarer, RelDataType type)
           
private  OJClass newIntervalOJClass(Class superclass, OJClass declarer, RelDataType type)
           
private  OJClass newOJClass(OJClass declarer, RelDataType type)
           
private  EigenbaseException newSqlTypeException(Throwable ex)
           
private  OJClass newStringOJClass(OJClass declarer, RelDataType type)
           
private  EigenbaseException newUnsupportedJdbcType(String tableName, String columnName, String typeName, int typeOrdinal, int precision, int scale, Throwable ex)
           
 OJClass toOJClass(OJClass declarer, RelDataType type)
           
 
Methods inherited from class org.eigenbase.oj.OJTypeFactoryImpl
createArrayType, createOJClassForRecordType, toType
 
Methods inherited from class org.eigenbase.sql.type.SqlTypeFactoryImpl
canonize, createMultisetType, createSqlIntervalType, createTypeWithCharsetAndCollation, createTypeWithNullability, leastRestrictive, shouldRaggedFixedLengthValueUnionBeVariable
 
Methods inherited from class org.eigenbase.reltype.RelDataTypeFactoryImpl
copyType, createDecimalProduct, createDecimalQuotient, createStructType, createStructType, createStructType, isJavaType, leastRestrictiveStructuredType, useDoubleMultiplication
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eigenbase.oj.OJTypeFactory
toType
 
Methods inherited from interface org.eigenbase.reltype.RelDataTypeFactory
copyType, createArrayType, createDecimalProduct, createDecimalQuotient, createMultisetType, createSqlIntervalType, createStructType, createStructType, createStructType, createTypeWithCharsetAndCollation, createTypeWithNullability, leastRestrictive, useDoubleMultiplication
 

Field Detail

unknownCharPrecision

private static final int unknownCharPrecision
See Also:
Constant Field Values

repos

private final FarragoRepos repos
Repos for type object definitions.


nextGeneratedClassId

private int nextGeneratedClassId

mapTypeToOJClass

private final Map<RelDataType,OJClass> mapTypeToOJClass
Constructor Detail

FarragoTypeFactoryImpl

public FarragoTypeFactoryImpl(FarragoRepos repos)
Method Detail

getRepos

public FarragoRepos getRepos()
Specified by:
getRepos in interface FarragoTypeFactory
Returns:
associated FarragoRepos

createJoinType

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

Specified by:
createJoinType in interface RelDataTypeFactory
Overrides:
createJoinType in class RelDataTypeFactoryImpl
Returns:
canonical join type descriptor

createCwmElementType

public RelDataType createCwmElementType(FemAbstractTypedElement abstractElement)
Description copied from interface: FarragoTypeFactory
Creates a type which represents the datatype of a FemAbstractTypedElement.

Specified by:
createCwmElementType in interface FarragoTypeFactory
Parameters:
abstractElement - CWM typed element
Returns:
generated type

createCwmType

public RelDataType createCwmType(CwmSqldataType cwmType)
Description copied from interface: FarragoTypeFactory
Creates a type which represents a CwmSqldataType.

Specified by:
createCwmType in interface FarragoTypeFactory
Parameters:
cwmType - CWM type instance
Returns:
generated type

createCwmTypeImpl

protected RelDataType createCwmTypeImpl(CwmClassifier classifier,
                                        FemSqltypedElement element)

getUserDefinedComparability

private RelDataTypeComparability getUserDefinedComparability(FemUserDefinedType type)

createStructTypeFromClassifier

public RelDataType createStructTypeFromClassifier(CwmClassifier classifier)
Description copied from interface: FarragoTypeFactory
Creates a type which represents a structured row based on a classifier definition from the catalog.

Specified by:
createStructTypeFromClassifier in interface FarragoTypeFactory
Parameters:
classifier - definition of classifier
Returns:
generated type, or null if classifier had no features

createResultSetType

public RelDataType createResultSetType(ResultSetMetaData metaData,
                                       boolean substitute)
Description copied from interface: FarragoTypeFactory
Creates a type which represents the row datatype of a JDBC ResultSet. Optionally, unsupported types can be replaced with substitutes. In the worst case, the substitute is VARCHAR(1024). Less drastic examples are ignoring datetime fractional seconds precision or capping numeric precision at our maximum.

Specified by:
createResultSetType in interface FarragoTypeFactory
Parameters:
metaData - metadata for JDBC ResultSet
substitute - if true, use substitutions; if false, throw exception for unsupported types or type attributes
Returns:
generated type

createResultSetType

public RelDataType createResultSetType(ResultSetMetaData metaData,
                                       boolean substitute,
                                       Properties typeMapping)
Description copied from interface: FarragoTypeFactory
Creates a type which represents the row datatype of a JDBC ResultSet. Optionally, unsupported types can be replaced with substitutes. In the worst case, the substitute is VARCHAR(1024). Less drastic examples are ignoring datetime fractional seconds precision or capping numeric precision at our maximum.

Specified by:
createResultSetType in interface FarragoTypeFactory
Parameters:
metaData - metadata for JDBC ResultSet
substitute - if true, use substitutions; if false, throw exception for unsupported types or type attributes
typeMapping - types to substitute
Returns:
generated type

createJdbcColumnType

public RelDataType createJdbcColumnType(ResultSet getColumnsResultSet,
                                        boolean substitute)
Description copied from interface: FarragoTypeFactory
Creates a type which represents column metadata returned by the DatabaseMetaData.getColumns(java.lang.String, java.lang.String, java.lang.String, java.lang.String) call. See FarragoTypeFactory.createResultSetType(java.sql.ResultSetMetaData, boolean) for details on type substitutions.

Specified by:
createJdbcColumnType in interface FarragoTypeFactory
Parameters:
getColumnsResultSet - ResultSet positioned on a row returned from the getColumns call; result set position is unchanged by this method
substitute - if true, use substitutions; if false, throw exception for unsupported types or type attributes
Returns:
generated type

createJdbcColumnType

public RelDataType createJdbcColumnType(ResultSet getColumnsResultSet,
                                        boolean substitute,
                                        Properties typeMapping)
Description copied from interface: FarragoTypeFactory
Creates a type which represents column metadata returned by the DatabaseMetaData.getColumns(java.lang.String, java.lang.String, java.lang.String, java.lang.String) call. See FarragoTypeFactory.createResultSetType(java.sql.ResultSetMetaData, boolean) for details on type substitutions.

Specified by:
createJdbcColumnType in interface FarragoTypeFactory
Parameters:
getColumnsResultSet - ResultSet positioned on a row returned from the getColumns call; result set position is unchanged by this method
substitute - if true, use substitutions; if false, throw exception for unsupported types or type attributes
typeMapping - types to substitute
Returns:
generated type

createJdbcType

private RelDataType createJdbcType(int typeOrdinal,
                                   String dbSpecTypeName,
                                   int precision,
                                   int scale,
                                   boolean isNullable,
                                   boolean substitute,
                                   Properties typeMapping)
                            throws Throwable
Throws:
Throwable

newSqlTypeException

private EigenbaseException newSqlTypeException(Throwable ex)

newUnsupportedJdbcType

private EigenbaseException newUnsupportedJdbcType(String tableName,
                                                  String columnName,
                                                  String typeName,
                                                  int typeOrdinal,
                                                  int precision,
                                                  int scale,
                                                  Throwable ex)

generateClassId

int generateClassId()

createMofType

public RelDataType createMofType(StructuralFeature feature)
Description copied from interface: FarragoTypeFactory
Creates a type which represents a MOF feature.

Specified by:
createMofType in interface FarragoTypeFactory
Parameters:
feature - MOF feature
Returns:
generated type

toOJClass

public OJClass toOJClass(OJClass declarer,
                         RelDataType type)
Specified by:
toOJClass in interface OJTypeFactory
Overrides:
toOJClass in class OJTypeFactoryImpl

newOJClass

private OJClass newOJClass(OJClass declarer,
                           RelDataType type)

newDecimalOJClass

private OJClass newDecimalOJClass(OJClass declarer,
                                  RelDataType type)

newDatetimeOJClass

private OJClass newDatetimeOJClass(Class superclass,
                                   OJClass declarer,
                                   RelDataType type)

newIntervalOJClass

private OJClass newIntervalOJClass(Class superclass,
                                   OJClass declarer,
                                   RelDataType type)

lookupTimeUnit

private Expression lookupTimeUnit(SqlIntervalQualifier.TimeUnit timeUnit)
Generates an expression for a SqlIntervalQualifier.TimeUnit.

Parameters:
timeUnit - Time unit
Returns:
expression for time unit

newStringOJClass

private OJClass newStringOJClass(OJClass declarer,
                                 RelDataType type)

newHolderOJClass

private OJClass newHolderOJClass(Class superclass,
                                 MemberDeclarationList memberDecls,
                                 OJClass declarer,
                                 RelDataType type)

generateGetter

private MethodDeclaration generateGetter(TypeName returnType,
                                         String methodName,
                                         Expression value)
Generates a protected getter method

Parameters:
returnType - type of value returned by the getter method
methodName - the name of the getter method
value - the value to be returned by the getter method
Returns:
getter method declaration

getValueAccessExpression

public Expression getValueAccessExpression(RelDataType type,
                                           Expression expr)
Description copied from interface: FarragoTypeFactory
Constructs an OpenJava expression to access a value of an atomic type.

Specified by:
getValueAccessExpression in interface FarragoTypeFactory
Parameters:
type - atomic type
expr - expression representing site to be accessed
Returns:
expression for accessing value

getClassForPrimitive

public Class getClassForPrimitive(RelDataType type)
Description copied from interface: FarragoTypeFactory
Looks up the Class representing a primitive used to hold a value of the given type.

Specified by:
getClassForPrimitive in interface FarragoTypeFactory
Parameters:
type - value type
Returns:
primitive Class, or null if a non-primitive Object is used at runtime to represent values of the given type

getClassForJavaParamStyle

public Class getClassForJavaParamStyle(RelDataType type)
Description copied from interface: FarragoTypeFactory
Looks up the Class specified by the JAVA parameter style for user-defined routines.

Specified by:
getClassForJavaParamStyle in interface FarragoTypeFactory
Parameters:
type - SQL type
Returns:
corresponding Java class, or null if no mapping is defined

createJavaType

public RelDataType createJavaType(Class clazz)
Description copied from interface: RelDataTypeFactory
Creates a type which corresponds to a Java class.

Specified by:
createJavaType in interface RelDataTypeFactory
Overrides:
createJavaType in class OJTypeFactoryImpl
Parameters:
clazz - the Java class used to define the type
Returns:
canonical Java type descriptor

createSqlType

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

Specified by:
createSqlType in interface RelDataTypeFactory
Overrides:
createSqlType in class SqlTypeFactoryImpl
Parameters:
typeName - Name of the type, for example SqlTypeName.BOOLEAN.
Returns:
canonical type descriptor

createSqlType

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

Specified by:
createSqlType in interface RelDataTypeFactory
Overrides:
createSqlType in class SqlTypeFactoryImpl
Parameters:
typeName - Name of the type, for example SqlTypeName.VARCHAR.
precision - maximum length of the value (non-numeric types) or the precision of the value (numeric/datetime types) requires both operands to have exact numeric types.
Returns:
canonical type descriptor

createSqlType

public RelDataType createSqlType(SqlTypeName typeName,
                                 int precision,
                                 int scale)
Description copied from interface: RelDataTypeFactory
Creates a SQL type with precision and scale.

Specified by:
createSqlType in interface RelDataTypeFactory
Overrides:
createSqlType in class SqlTypeFactoryImpl
Parameters:
typeName - Name of the type, for example SqlTypeName.DECIMAL.
precision - precision of the value
scale - scale of the values, i.e. 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:
canonical type descriptor

addDefaultAttributes

private RelDataType addDefaultAttributes(RelDataType type)

getDefaultCharset

public Charset getDefaultCharset()
Specified by:
getDefaultCharset in interface RelDataTypeFactory
Overrides:
getDefaultCharset in class RelDataTypeFactoryImpl
Returns:
the default Charset for string types

getMappedDataType

private int[] getMappedDataType(int ordinal,
                                int precision,
                                int scale,
                                String dbSpecTypeName,
                                Properties typeMapping)

extractDataTypeName

private String extractDataTypeName(String mapping)

extractPrecision

private int extractPrecision(String mapping,
                             int precision)

extractScale

private int extractScale(String mapping,
                         int scale)

isKnownUnsupportedJdbcType

private boolean isKnownUnsupportedJdbcType(SqlTypeName type)