private void createRoutines ( Collection < Routine > routines , SchemaDescriptor schemaDescriptor , Map < String , ColumnTypeDescriptor > columnTypes , Store store ) throws IOException { for ( Routine routine : routines ) { RoutineDescriptor routineDescriptor ; String returnType ; switch ( routine . getRoutineType ( ) ) { case procedure : routineDescriptor = store . create ( ProcedureDescriptor . class ) ; returnType = ( ( ProcedureReturnType ) routine . getReturnType ( ) ) . name ( ) ; schemaDescriptor . getProcedures ( ) . add ( ( ProcedureDescriptor ) routineDescriptor ) ; break ; case function : routineDescriptor = store . create ( FunctionDescriptor . class ) ; returnType = ( ( FunctionReturnType ) routine . getReturnType ( ) ) . name ( ) ; schemaDescriptor . getFunctions ( ) . add ( ( FunctionDescriptor ) routineDescriptor ) ; break ; case unknown : routineDescriptor = store . create ( RoutineDescriptor . class ) ; returnType = null ; schemaDescriptor . getUnknownRoutines ( ) . add ( routineDescriptor ) ; break ; default : throw new IOException ( "Unsupported routine type " + routine . getRoutineType ( ) ) ; } routineDescriptor . setName ( routine . getName ( ) ) ; routineDescriptor . setReturnType ( returnType ) ; routineDescriptor . setBodyType ( routine . getRoutineBodyType ( ) . name ( ) ) ; routineDescriptor . setDefinition ( routine . getDefinition ( ) ) ; for ( RoutineColumn < ? extends Routine > routineColumn : routine . getColumns ( ) ) { RoutineColumnDescriptor columnDescriptor = createColumnDescriptor ( routineColumn , RoutineColumnDescriptor . class , columnTypes , store ) ; routineDescriptor . getColumns ( ) . add ( columnDescriptor ) ; RoutineColumnType columnType = routineColumn . getColumnType ( ) ; if ( columnType instanceof ProcedureColumnType ) { ProcedureColumnType procedureColumnType = ( ProcedureColumnType ) columnType ; columnDescriptor . setType ( procedureColumnType . name ( ) ) ; } else if ( columnType instanceof FunctionColumnType ) { FunctionColumnType functionColumnType = ( FunctionColumnType ) columnType ; columnDescriptor . setType ( functionColumnType . name ( ) ) ; } else { throw new IOException ( "Unsupported routine column type " + columnType . getClass ( ) . getName ( ) ) ; } } } }
Create routines i . e . functions and procedures .