try
{
CompilerContext cc = (CompilerContext)
ContextService.getContext(CompilerContext.CONTEXT_ID);
ClassFactory classFactory = cc.getClassFactory();
TypeCompilerFactory tcf = cc.getTypeCompilerFactory();
Class<?> derbyAggregatorInterface = classFactory.loadApplicationClass( "org.apache.derby.agg.Aggregator" );
Class<?> userAggregatorClass = classFactory.loadApplicationClass( _alias.getJavaClassName() );
Class[][] typeBounds = classFactory.getClassInspector().getTypeBounds
( derbyAggregatorInterface, userAggregatorClass );
if (
(typeBounds == null) ||
(typeBounds.length != AGGREGATOR_PARAM_COUNT) ||
(typeBounds[ INPUT_TYPE ] == null) ||
(typeBounds[ RETURN_TYPE ] == null)
)
{
throw StandardException.newException
(
SQLState.LANG_ILLEGAL_UDA_CLASS,
_alias.getSchemaName(),
_alias.getName(),
userAggregatorClass.getName()
);
}
Class<?>[] genericParameterTypes =
classFactory.getClassInspector().getGenericParameterTypes(
derbyAggregatorInterface, userAggregatorClass);
if ( genericParameterTypes == null ) {
genericParameterTypes = new Class<?>[ AGGREGATOR_PARAM_COUNT ];
}
AggregateAliasInfo aai = (AggregateAliasInfo) _alias.getAliasInfo();
DataTypeDescriptor expectedInputType = DataTypeDescriptor.getType( aai.getForType() );
DataTypeDescriptor expectedReturnType = DataTypeDescriptor.getType( aai.getReturnType() );
Class<?> expectedInputClass = getJavaClass( classFactory, expectedInputType );
Class<?> expectedReturnClass = getJavaClass( classFactory, expectedReturnType );
// the input operand must be coercible to the expected input type of the aggregate
if ( !tcf.getTypeCompiler( expectedInputType.getTypeId() ).storable( inputType.getTypeId(), classFactory ) )
{ return null; }
//
// Make sure that the declared input type of the UDA actually falls within
// the type bounds of the Aggregator implementation.