@Test public void testCreateFunction() throws NoSuchMethodException, SecurityException { FunctionMethod fm = MetadataFactory.createFunctionFromMethod("x", TestMetadataFactory.class.getMethod("someFunction")); assertEquals(Boolean.class, fm.getOutputParameter().getJavaType()); fm = MetadataFactory.createFunctionFromMethod("x", TestMetadataFactory.class.getMethod("someArrayFunction")); assertEquals(String[].class, fm.getOutputParameter().getJavaType()); }
public static FunctionMethod createFunctionFromMethod(String name, Method method) { Class<?> returnTypeClass = method.getReturnType(); AggregateAttributes aa = null; if ((method.getModifiers() & Modifier.STATIC) == 0 && UserDefinedAggregate.class.isAssignableFrom(method.getDeclaringClass())) { aa = new AggregateAttributes(); Method m; try { m = method.getDeclaringClass().getMethod("getResult", CommandContext.class); } catch (NoSuchMethodException e) { throw new TeiidRuntimeException(e); } catch (SecurityException e) { throw new TeiidRuntimeException(e); } returnTypeClass = m.getReturnType(); } if (returnTypeClass.isPrimitive()) { returnTypeClass = TypeFacility.convertPrimitiveToObject(returnTypeClass); } String returnType = DataTypeManager.getDataTypeName(DataTypeManager.getRuntimeType(returnTypeClass)); Class<?>[] params = method.getParameterTypes(); String[] paramTypes = new String[params.length]; boolean nullOnNull = false; for (int i = 0; i < params.length; i++) { Class<?> clazz = params[i]; if (clazz.isPrimitive()) { nullOnNull = true; clazz = TypeFacility.convertPrimitiveToObject(clazz); } if (method.isVarArgs() && i == params.length -1) { paramTypes[i] = DataTypeManager.getDataTypeName(DataTypeManager.getRuntimeType(clazz.getComponentType())); } else { paramTypes[i] = DataTypeManager.getDataTypeName(DataTypeManager.getRuntimeType(clazz)); } } if (params.length > 0 && CommandContext.class.isAssignableFrom(params[0])) { paramTypes = Arrays.copyOfRange(paramTypes, 1, paramTypes.length); } FunctionMethod func = FunctionMethod.createFunctionMethod(name, null, null, returnType, paramTypes); func.setAggregateAttributes(aa); func.setInvocationMethod(method.getName()); func.setPushdown(PushDown.CAN_PUSHDOWN); func.setMethod(method); func.setInvocationClass(method.getDeclaringClass().getName()); func.setNullOnNull(nullOnNull); if (method.isVarArgs()) { func.setVarArgs(method.isVarArgs()); } return func; }
MetadataFactory extends NamespaceContainer { public static FunctionMethod createFunctionFromMethod(String name, Method method) { Class<?> returnTypeClass = method.getReturnType(); AggregateAttributes aa = null; if ((method.getModifiers() & Modifier.STATIC) == 0 && UserDefinedAggregate.class.isAssignableFrom(method.getDeclaringClass())) { aa = new AggregateAttributes(); Method m; try { m = method.getDeclaringClass().getMethod("getResult", CommandContext.class); } catch (NoSuchMethodException e) { throw new TeiidRuntimeException(e); } catch (SecurityException e) { throw new TeiidRuntimeException(e); } returnTypeClass = m.getReturnType(); } if (returnTypeClass.isPrimitive()) { returnTypeClass = TypeFacility.convertPrimitiveToObject(returnTypeClass); } String returnType = DataTypeManager.getDataTypeName(DataTypeManager.getRuntimeType(returnTypeClass)); Class<?>[] params = method.getParameterTypes(); String[] paramTypes = new String[params.length]; boolean nullOnNull = false; for (int i = 0; i < params.length; i++) { Class<?> clazz = params[i]; if (clazz.isPrimitive()) { nullOnNull = true; clazz = TypeFacility.convertPrimitiveToObject(clazz); } if (method.isVarArgs() && i == params.length -1) { paramTypes[i] = DataTypeManager.getDataTypeName(DataTypeManager.getRuntimeType(clazz.getComponentType())); } else { paramTypes[i] = DataTypeManager.getDataTypeName(DataTypeManager.getRuntimeType(clazz)); } } if (params.length > 0 && CommandContext.class.isAssignableFrom(params[0])) { paramTypes = Arrays.copyOfRange(paramTypes, 1, paramTypes.length); } FunctionMethod func = FunctionMethod.createFunctionMethod(name, null, null, returnType, paramTypes); func.setAggregateAttributes(aa); func.setInvocationMethod(method.getName()); func.setPushdown(PushDown.CAN_PUSHDOWN); func.setMethod(method); func.setInvocationClass(method.getDeclaringClass().getName()); func.setNullOnNull(nullOnNull); if (method.isVarArgs()) { func.setVarArgs(method.isVarArgs()); } return func; } }
MetadataFactory extends NamespaceContainer { public static FunctionMethod createFunctionFromMethod(String name, Method method) { Class<?> returnTypeClass = method.getReturnType(); AggregateAttributes aa = null; if ((method.getModifiers() & Modifier.STATIC) == 0 && UserDefinedAggregate.class.isAssignableFrom(method.getDeclaringClass())) { aa = new AggregateAttributes(); Method m; try { m = method.getDeclaringClass().getMethod("getResult", CommandContext.class); } catch (NoSuchMethodException e) { throw new TeiidRuntimeException(e); } catch (SecurityException e) { throw new TeiidRuntimeException(e); } returnTypeClass = m.getReturnType(); } if (returnTypeClass.isPrimitive()) { returnTypeClass = TypeFacility.convertPrimitiveToObject(returnTypeClass); } String returnType = DataTypeManager.getDataTypeName(DataTypeManager.getRuntimeType(returnTypeClass)); Class<?>[] params = method.getParameterTypes(); String[] paramTypes = new String[params.length]; boolean nullOnNull = false; for (int i = 0; i < params.length; i++) { Class<?> clazz = params[i]; if (clazz.isPrimitive()) { nullOnNull = true; clazz = TypeFacility.convertPrimitiveToObject(clazz); } if (method.isVarArgs() && i == params.length -1) { paramTypes[i] = DataTypeManager.getDataTypeName(DataTypeManager.getRuntimeType(clazz.getComponentType())); } else { paramTypes[i] = DataTypeManager.getDataTypeName(DataTypeManager.getRuntimeType(clazz)); } } if (params.length > 0 && CommandContext.class.isAssignableFrom(params[0])) { paramTypes = Arrays.copyOfRange(paramTypes, 1, paramTypes.length); } FunctionMethod func = FunctionMethod.createFunctionMethod(name, null, null, returnType, paramTypes); func.setAggregateAttributes(aa); func.setInvocationMethod(method.getName()); func.setPushdown(PushDown.CAN_PUSHDOWN); func.setMethod(method); func.setInvocationClass(method.getDeclaringClass().getName()); func.setNullOnNull(nullOnNull); if (method.isVarArgs()) { func.setVarArgs(method.isVarArgs()); } return func; } MetadataFactory();  MetadataFactory(String vdbName, Object vdbVersion, Map<String, Datatype> runtimeTypes, ModelMetaData model);  MetadataFactory(String vdbName, Object vdbVersion, String schemaName, Map<String, Datatype> runtimeTypes, Properties modelProperties, String rawMetadata); }
MetadataFactory extends NamespaceContainer { public static FunctionMethod createFunctionFromMethod(String name, Method method) { Class<?> returnTypeClass = method.getReturnType(); AggregateAttributes aa = null; if ((method.getModifiers() & Modifier.STATIC) == 0 && UserDefinedAggregate.class.isAssignableFrom(method.getDeclaringClass())) { aa = new AggregateAttributes(); Method m; try { m = method.getDeclaringClass().getMethod("getResult", CommandContext.class); } catch (NoSuchMethodException e) { throw new TeiidRuntimeException(e); } catch (SecurityException e) { throw new TeiidRuntimeException(e); } returnTypeClass = m.getReturnType(); } if (returnTypeClass.isPrimitive()) { returnTypeClass = TypeFacility.convertPrimitiveToObject(returnTypeClass); } String returnType = DataTypeManager.getDataTypeName(DataTypeManager.getRuntimeType(returnTypeClass)); Class<?>[] params = method.getParameterTypes(); String[] paramTypes = new String[params.length]; boolean nullOnNull = false; for (int i = 0; i < params.length; i++) { Class<?> clazz = params[i]; if (clazz.isPrimitive()) { nullOnNull = true; clazz = TypeFacility.convertPrimitiveToObject(clazz); } if (method.isVarArgs() && i == params.length -1) { paramTypes[i] = DataTypeManager.getDataTypeName(DataTypeManager.getRuntimeType(clazz.getComponentType())); } else { paramTypes[i] = DataTypeManager.getDataTypeName(DataTypeManager.getRuntimeType(clazz)); } } if (params.length > 0 && CommandContext.class.isAssignableFrom(params[0])) { paramTypes = Arrays.copyOfRange(paramTypes, 1, paramTypes.length); } FunctionMethod func = FunctionMethod.createFunctionMethod(name, null, null, returnType, paramTypes); func.setAggregateAttributes(aa); func.setInvocationMethod(method.getName()); func.setPushdown(PushDown.CAN_PUSHDOWN); func.setMethod(method); func.setInvocationClass(method.getDeclaringClass().getName()); func.setNullOnNull(nullOnNull); if (method.isVarArgs()) { func.setVarArgs(method.isVarArgs()); } return func; } MetadataFactory();  MetadataFactory(String vdbName, Object vdbVersion, Map<String, Datatype> runtimeTypes, ModelMetaData model);  MetadataFactory(String vdbName, Object vdbVersion, String schemaName, Map<String, Datatype> runtimeTypes, Properties modelProperties, String rawMetadata); static String hex(long val, int hexLength); @Deprecated Properties getImportProperties(); Properties getModelProperties(); @Deprecated String getRawMetadata(); Model getModel(); String getName(); Schema getSchema(); Table addTable(String name); Column addColumn(String name, String type, ColumnSet<?> table); Column renameColumn(String oldName, String name, ColumnSet<?> table); ProcedureParameter renameParameter(String oldName, String name, Procedure procedure); static Datatype setDataType(String type, BaseColumn column, Map<String, Datatype> dataTypes, boolean allowNull); KeyRecord addPrimaryKey(String name, List<String> columnNames, Table table); KeyRecord addAccessPattern(String name, List<String> columnNames, Table table); KeyRecord addIndex(String name, boolean nonUnique, List<String> columnNames, Table table); KeyRecord addFunctionBasedIndex(String name, List<String> expressions, List<Boolean> nonColumnExpressions, Table table); ForeignKey addForeignKey(String name, List<String> columnNames, String referenceTable, Table table); @Deprecated ForeignKey addForiegnKey(String name, List<String> columnNames, String referenceTable, Table table); ForeignKey addForeignKey(String name, List<String> columnNames, List<String> referencedColumnNames, String referenceTable, Table table); @Deprecated ForeignKey addForiegnKey(String name, List<String> columnNames, List<String> referencedColumnNames, String referenceTable, Table table); Procedure addProcedure(String name); ProcedureParameter addProcedureParameter(String name, String type, ProcedureParameter.Type parameterType, Procedure procedure); Column addProcedureResultSetColumn(String name, String type, Procedure procedure); FunctionMethod addFunction(String name); FunctionMethod addFunction(String name, String returnType, String... paramTypes); FunctionMethod addFunction(String name, Method method); static FunctionMethod createFunctionFromMethod(String name, Method method); void setAutoCorrectColumnNames(boolean autoCorrectColumnNames); void mergeInto(MetadataStore store); MetadataStore asMetadataStore(); void setSchema(Schema schema); Map<String, Datatype> getDataTypes(); void correctDatatypes(Map<String, Datatype> dt); String getVdbName(); String getVdbVersion(); void parse(Reader ddl); void setParser(Parser parser); void setModel(ModelMetaData model); Parser getParser(); Map<String, ? extends VDBResource> getVDBResources(); void setVdbResources(Map<String, ? extends VDBResource> vdbResources); @Deprecated void addPermission(String role, AbstractMetadataRecord resource, Boolean allowAlter, Boolean allowCreate, Boolean allowRead, Boolean allowUpdate,
            Boolean allowDelete, Boolean allowExecute, String condition, Boolean constraint); void addPermission(String role, AbstractMetadataRecord resource, Boolean allowAlter, Boolean allowCreate, Boolean allowRead, Boolean allowUpdate,
            Boolean allowDelete, Boolean allowExecute); void addSchemaPermission(String role, Boolean allowAlter, Boolean allowCreate, Boolean allowRead, Boolean allowUpdate,
            Boolean allowDelete, Boolean allowExecute); @Deprecated void addColumnPermission(String role, Column resource, Boolean allowCreate, Boolean allowRead, Boolean allowUpdate,
            String condition, String mask, Integer order); void addColumnPermission(String role, Column resource, Boolean allowCreate, Boolean allowRead, Boolean allowUpdate,
            String mask, Integer order); void addPolicy(String role, String policyName, AbstractMetadataRecord resource, String condition, Policy.Operation... operations); void addFunction(FunctionMethod functionMethod); @TranslatorProperty (display="Auto-correct Column Names", category=PropertyType.IMPORT, description="If true replace the . character with _ in the Teiid column name, otherwise an exception will be raised.") boolean isAutoCorrectColumnNames(); @TranslatorProperty (display="Rename All Duplicate Names", category=PropertyType.IMPORT, description="Provide a unique Teiid name for all duplicate names (typically due to Teiid's case insensitivity).") boolean isRenameAllDuplicates(); @TranslatorProperty (display="Rename Duplicate Columns", category=PropertyType.IMPORT, description="Provide a unique Teiid name for duplicate column names (typically due to Teiid's case insensitivity).") boolean isRenameDuplicateColumns(); @TranslatorProperty (display="Rename Duplicate Tables", category=PropertyType.IMPORT, description="Provide a unique Teiid name for duplicate table names (typically due to Teiid's case insensitivity).") boolean isRenameDuplicateTables(); void setRenameAllDuplicates(boolean renameAllDuplicates); void setRenameDuplicateColumns(boolean renameDuplicateColumns); void setRenameDuplicateTables(boolean renameDuplicateTables); @TranslatorProperty (display="Name Format", category=PropertyType.IMPORT, description="The Java String Format to manipulate table and procedure names.") String getNameFormat(); void setNameFormat(String nameFormat); @TranslatorProperty (display="Import Pushdown Functions", category=PropertyType.IMPORT, description="Expose translator pushdown functions on the source model, so that the functions are known to design environments.") boolean isImportPushdownFunctions(); void setImportPushdownFunctions(boolean importPushdownFunctions); void setVDBClassLoader(ClassLoader classLoader); ClassLoader getVDBClassLoader(); }
MetadataFactory extends NamespaceContainer { public static FunctionMethod createFunctionFromMethod(String name, Method method) { Class<?> returnTypeClass = method.getReturnType(); AggregateAttributes aa = null; if ((method.getModifiers() & Modifier.STATIC) == 0 && UserDefinedAggregate.class.isAssignableFrom(method.getDeclaringClass())) { aa = new AggregateAttributes(); Method m; try { m = method.getDeclaringClass().getMethod("getResult", CommandContext.class); } catch (NoSuchMethodException e) { throw new TeiidRuntimeException(e); } catch (SecurityException e) { throw new TeiidRuntimeException(e); } returnTypeClass = m.getReturnType(); } if (returnTypeClass.isPrimitive()) { returnTypeClass = TypeFacility.convertPrimitiveToObject(returnTypeClass); } String returnType = DataTypeManager.getDataTypeName(DataTypeManager.getRuntimeType(returnTypeClass)); Class<?>[] params = method.getParameterTypes(); String[] paramTypes = new String[params.length]; boolean nullOnNull = false; for (int i = 0; i < params.length; i++) { Class<?> clazz = params[i]; if (clazz.isPrimitive()) { nullOnNull = true; clazz = TypeFacility.convertPrimitiveToObject(clazz); } if (method.isVarArgs() && i == params.length -1) { paramTypes[i] = DataTypeManager.getDataTypeName(DataTypeManager.getRuntimeType(clazz.getComponentType())); } else { paramTypes[i] = DataTypeManager.getDataTypeName(DataTypeManager.getRuntimeType(clazz)); } } if (params.length > 0 && CommandContext.class.isAssignableFrom(params[0])) { paramTypes = Arrays.copyOfRange(paramTypes, 1, paramTypes.length); } FunctionMethod func = FunctionMethod.createFunctionMethod(name, null, null, returnType, paramTypes); func.setAggregateAttributes(aa); func.setInvocationMethod(method.getName()); func.setPushdown(PushDown.CAN_PUSHDOWN); func.setMethod(method); func.setInvocationClass(method.getDeclaringClass().getName()); func.setNullOnNull(nullOnNull); if (method.isVarArgs()) { func.setVarArgs(method.isVarArgs()); } return func; } MetadataFactory();  MetadataFactory(String vdbName, Object vdbVersion, Map<String, Datatype> runtimeTypes, ModelMetaData model);  MetadataFactory(String vdbName, Object vdbVersion, String schemaName, Map<String, Datatype> runtimeTypes, Properties modelProperties, String rawMetadata); static String hex(long val, int hexLength); @Deprecated Properties getImportProperties(); Properties getModelProperties(); @Deprecated String getRawMetadata(); Model getModel(); String getName(); Schema getSchema(); Table addTable(String name); Column addColumn(String name, String type, ColumnSet<?> table); Column renameColumn(String oldName, String name, ColumnSet<?> table); ProcedureParameter renameParameter(String oldName, String name, Procedure procedure); static Datatype setDataType(String type, BaseColumn column, Map<String, Datatype> dataTypes, boolean allowNull); KeyRecord addPrimaryKey(String name, List<String> columnNames, Table table); KeyRecord addAccessPattern(String name, List<String> columnNames, Table table); KeyRecord addIndex(String name, boolean nonUnique, List<String> columnNames, Table table); KeyRecord addFunctionBasedIndex(String name, List<String> expressions, List<Boolean> nonColumnExpressions, Table table); ForeignKey addForeignKey(String name, List<String> columnNames, String referenceTable, Table table); @Deprecated ForeignKey addForiegnKey(String name, List<String> columnNames, String referenceTable, Table table); ForeignKey addForeignKey(String name, List<String> columnNames, List<String> referencedColumnNames, String referenceTable, Table table); @Deprecated ForeignKey addForiegnKey(String name, List<String> columnNames, List<String> referencedColumnNames, String referenceTable, Table table); Procedure addProcedure(String name); ProcedureParameter addProcedureParameter(String name, String type, ProcedureParameter.Type parameterType, Procedure procedure); Column addProcedureResultSetColumn(String name, String type, Procedure procedure); FunctionMethod addFunction(String name); FunctionMethod addFunction(String name, String returnType, String... paramTypes); FunctionMethod addFunction(String name, Method method); static FunctionMethod createFunctionFromMethod(String name, Method method); void setAutoCorrectColumnNames(boolean autoCorrectColumnNames); void mergeInto(MetadataStore store); MetadataStore asMetadataStore(); void setSchema(Schema schema); Map<String, Datatype> getDataTypes(); void correctDatatypes(Map<String, Datatype> dt); String getVdbName(); String getVdbVersion(); void parse(Reader ddl); void setParser(Parser parser); void setModel(ModelMetaData model); Parser getParser(); Map<String, ? extends VDBResource> getVDBResources(); void setVdbResources(Map<String, ? extends VDBResource> vdbResources); @Deprecated void addPermission(String role, AbstractMetadataRecord resource, Boolean allowAlter, Boolean allowCreate, Boolean allowRead, Boolean allowUpdate,
            Boolean allowDelete, Boolean allowExecute, String condition, Boolean constraint); void addPermission(String role, AbstractMetadataRecord resource, Boolean allowAlter, Boolean allowCreate, Boolean allowRead, Boolean allowUpdate,
            Boolean allowDelete, Boolean allowExecute); void addSchemaPermission(String role, Boolean allowAlter, Boolean allowCreate, Boolean allowRead, Boolean allowUpdate,
            Boolean allowDelete, Boolean allowExecute); @Deprecated void addColumnPermission(String role, Column resource, Boolean allowCreate, Boolean allowRead, Boolean allowUpdate,
            String condition, String mask, Integer order); void addColumnPermission(String role, Column resource, Boolean allowCreate, Boolean allowRead, Boolean allowUpdate,
            String mask, Integer order); void addPolicy(String role, String policyName, AbstractMetadataRecord resource, String condition, Policy.Operation... operations); void addFunction(FunctionMethod functionMethod); @TranslatorProperty (display="Auto-correct Column Names", category=PropertyType.IMPORT, description="If true replace the . character with _ in the Teiid column name, otherwise an exception will be raised.") boolean isAutoCorrectColumnNames(); @TranslatorProperty (display="Rename All Duplicate Names", category=PropertyType.IMPORT, description="Provide a unique Teiid name for all duplicate names (typically due to Teiid's case insensitivity).") boolean isRenameAllDuplicates(); @TranslatorProperty (display="Rename Duplicate Columns", category=PropertyType.IMPORT, description="Provide a unique Teiid name for duplicate column names (typically due to Teiid's case insensitivity).") boolean isRenameDuplicateColumns(); @TranslatorProperty (display="Rename Duplicate Tables", category=PropertyType.IMPORT, description="Provide a unique Teiid name for duplicate table names (typically due to Teiid's case insensitivity).") boolean isRenameDuplicateTables(); void setRenameAllDuplicates(boolean renameAllDuplicates); void setRenameDuplicateColumns(boolean renameDuplicateColumns); void setRenameDuplicateTables(boolean renameDuplicateTables); @TranslatorProperty (display="Name Format", category=PropertyType.IMPORT, description="The Java String Format to manipulate table and procedure names.") String getNameFormat(); void setNameFormat(String nameFormat); @TranslatorProperty (display="Import Pushdown Functions", category=PropertyType.IMPORT, description="Expose translator pushdown functions on the source model, so that the functions are known to design environments.") boolean isImportPushdownFunctions(); void setImportPushdownFunctions(boolean importPushdownFunctions); void setVDBClassLoader(ClassLoader classLoader); ClassLoader getVDBClassLoader();  }