All Downloads are FREE. Search and download functionalities are using the official Maven repository.

me.saro.sap.jco.SapFunctionResult Maven / Gradle / Ivy

There is a newer version: 3.0.14.7
Show newest version
package me.saro.sap.jco;

import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import com.sap.conn.jco.JCoField;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.JCoParameterList;
import com.sap.conn.jco.JCoTable;

import me.saro.commons.function.ThrowableBiConsumer;

/**
 * Sap Function Result
 * @author      PARK Yong Seo
 * @since       0.1
 */
public class SapFunctionResult {

    final JCoFunction function;

    /**
     * @param jCoFunction
     * @see SapFunctionFunction
     */
    SapFunctionResult(JCoFunction function) {
        this.function = function;
    }

    /**
     * get export parameters
     * @return
     */
    public JCoParameterList getExportParameterList() {
        return function.getExportParameterList();
    }
    
    /**
     * get result table count
     * @return
     */
    public int getTableCount() {
        return function.getTableParameterList().getFieldCount();
    }
    
    /**
     * get table by index
     * @param index
     * @return
     */
    public JCoTable getJCoTable(int index) {
        return function.getTableParameterList().getTable(index);
    }
    
    /**
     * get table by name
     * @param name
     * @return
     */
    public JCoTable getJCoTable(String name) {
        return function.getTableParameterList().getTable(name);
    }
    
    /**
     * get map list table
     * @param index
     * @return
     */
    public List> getTable(int index) {
        return SapUtils.toMapList(function.getTableParameterList().getTable(index));
    }
    
    /**
     * get map list table
     * @param name
     * @return
     */
    public List> getTable(String name) {
        return SapUtils.toMapList(function.getTableParameterList().getTable(name));
    }
    
    /**
     * get custom class table
     * @param index
     * @param createRow
     * @param bindField
     * @return
     */
    public  List getTable(int index, Supplier createRow, ThrowableBiConsumer bindField) {
        return SapUtils.toClass(function.getTableParameterList().getTable(index), createRow, bindField);
    }
    
    /**
     * get custom class table
     * @param name
     * @param createRow
     * @param bindField
     * @return
     */
    public  List getTable(String name, Supplier createRow, ThrowableBiConsumer bindField) {
        return SapUtils.toClass(function.getTableParameterList().getTable(name), createRow, bindField);
    }
    
    /**
     * get all tables
     * @return
     */
    public List>> getAllTables() {
        return IntStream.range(0, getTableCount()).mapToObj(e -> getTable(e)).collect(Collectors.toList());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy