use of org.apache.derby.iapi.services.loader.ClassFactory in project derby by apache.
the class GenericAggregateResultSet method getSortAggregators.
/**
* For each AggregatorInfo in the list, generate a
* GenericAggregator and stick it in an array of
* GenericAggregators.
*
* @param list the list of aggregators to set up
* @param eliminateDistincts should distincts be ignored.
* Used to toss out distinct aggregates for a prelim
* sort.
* @param lcc the lcc
* @param inputResultSet the incoming result set
*
* @return the array of GenericAggregators
*
* @exception StandardException on error
*/
@SuppressWarnings("UseOfObsoleteCollectionType")
protected final GenericAggregator[] getSortAggregators(AggregatorInfoList list, boolean eliminateDistincts, LanguageConnectionContext lcc, NoPutResultSet inputResultSet) throws StandardException {
GenericAggregator[] aggregators;
Vector<GenericAggregator> tmpAggregators = new Vector<GenericAggregator>();
ClassFactory cf = lcc.getLanguageConnectionFactory().getClassFactory();
for (AggregatorInfo aggInfo : list) {
if (!(eliminateDistincts && aggInfo.isDistinct())) // if (eliminateDistincts == aggInfo.isDistinct())
{
tmpAggregators.addElement(new GenericAggregator(aggInfo, cf));
}
}
aggregators = new GenericAggregator[tmpAggregators.size()];
tmpAggregators.copyInto(aggregators);
return aggregators;
}
use of org.apache.derby.iapi.services.loader.ClassFactory in project derby by apache.
the class ClassLoadingTest method test_01_6654.
/**
* Test that you can't use Derby's custom class loader to load arbitrary
* class files. See DERBY-6654.
*/
public void test_01_6654() throws Exception {
ByteArray classBytes = new ByteArray(new byte[] { (byte) 1 });
Connection conn = getConnection();
LanguageConnectionContext lcc = ConstraintCharacteristicsTest.getLCC(conn);
ClassFactory classFactory = lcc.getLanguageConnectionFactory().getClassFactory();
String className1 = "BadClassName";
String className2 = "bad.class.Name";
vet6654(classFactory, className1, classBytes);
vet6654(classFactory, className2, classBytes);
}
use of org.apache.derby.iapi.services.loader.ClassFactory in project derby by apache.
the class UserAggregateDefinition method getAggregator.
/**
* Determines the result datatype and verifies that the input datatype is correct.
*
* @param inputType the input type
* @param aggregatorClass (Output arg) the name of the Derby execution-time class which wraps the aggregate logic
*
* @return the result type of the user-defined aggregator
*/
public final DataTypeDescriptor getAggregator(DataTypeDescriptor inputType, StringBuffer aggregatorClass) throws StandardException {
try {
CompilerContext cc = (CompilerContext) QueryTreeNode.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.
//
Class[] inputBounds = typeBounds[INPUT_TYPE];
for (int i = 0; i < inputBounds.length; i++) {
vetCompatibility((Class<?>) inputBounds[i], expectedInputClass, SQLState.LANG_UDA_WRONG_INPUT_TYPE);
}
if (genericParameterTypes[INPUT_TYPE] != null) {
vetCompatibility(genericParameterTypes[INPUT_TYPE], expectedInputClass, SQLState.LANG_UDA_WRONG_INPUT_TYPE);
}
//
// Make sure that the declared return type of the UDA actually falls within
// the type bounds of the Aggregator implementation.
//
Class[] returnBounds = typeBounds[RETURN_TYPE];
for (int i = 0; i < returnBounds.length; i++) {
vetCompatibility(returnBounds[i], expectedReturnClass, SQLState.LANG_UDA_WRONG_RETURN_TYPE);
}
if (genericParameterTypes[RETURN_TYPE] != null) {
vetCompatibility(genericParameterTypes[RETURN_TYPE], expectedReturnClass, SQLState.LANG_UDA_WRONG_RETURN_TYPE);
}
aggregatorClass.append(ClassName.UserDefinedAggregator);
return expectedReturnType;
} catch (ClassNotFoundException cnfe) {
throw aggregatorInstantiation(cnfe);
}
}
Aggregations