Spring StoredProcedure Object Возврат списка объектов

Я использую хранимую процедуру mysql, которая используется для получения списка объектов. Это возможно ?

Я следую этой статье

Вопрос:

  1. Как получить список объектов, как в операторе select, используя набор результатов?
  2. Как сопоставить набор результатов со списком объектов?

    CREATE DEFINER=root@localhost PROCEDURE generateLCRReport(IN countryCodeParam INT, OUT countryCode INT, OUT dialCode INT, OUT custPrefix VARCHAR(50), OUT vendorPrefix VARCHAR(50), OUT custPrice FLOAT, OUT vendorCost FLOAT, OUT profit FLOAT) ЯЗЫК SQL ДЕТЕРМИНИСТИЧЕСКИЙ СЧИТЫВАЕТ ДАННЫЕ SQL SQL SECURITY DEFINER COMMENT 'generateLCRReport' BEGIN выберите c.country_code как countryCode, c.dial_code как dialCode, c.customer_prefix как custPrefix, c.vendor_prefix как vendorPrefix, max(cust_rate.rate) как custPrice, min(ven_rate.rate) ) как vendorCost, round(max(cust_rate.rate) - min(ven_rate.rate), 3) как прибыль от cdr c

    внутреннее соединение (выберите a.id, r.rate, re.country_code, re.dial_code, ap.prefix from rate r Внутренний регион соединения re на r.region_id = re.id внутреннее соединение account_prefix ap на r.account_prefix_id = ap.id учетная запись внутреннего соединения a на a.id = ap.account_id, где ap.prefix_type = 0 ) как cust_rate

    на c.country_code = cust_rate.country_code и c.dial_code = cust_rate.dial_code и c.customer_prefix = cust_rate.prefix и c.customer_id = cust_rate.id

    внутреннее соединение (выберите a.id, r.rate, re.country_code, re.dial_code, ap.prefix from rate r Внутренний регион соединения re на r.region_id = re.id внутреннее соединение account_prefix ap на r.account_prefix_id = ap.id учетная запись внутреннего соединения a на a.id = ap.account_id, где ap.prefix_type = 1 ) как ven_rate

    на c.country_code = ven_rate.country_code и c.dial_code = ven_rate.dial_code и c.vendor_prefix = ven_rate.prefix и c.vendor_id = ven_rate.id, где c.country_code = countryCodeParam сгруппировать по c.country_code и c.dial_code упорядочить по c .country_code лимит возрастания 5000;

    КОНЕЦ

    открытый класс LCRReportSP расширяет StoredProcedure {

    /**
     * 
     */
    @Autowired
    public LCRReportSP(JdbcTemplate jdbcTemplate, String storedProcName, RowMapper<CostReport> mapper) {
        super(jdbcTemplate, storedProcName);
    
        SqlReturnResultSet rs = new SqlReturnResultSet("", mapper);
        SqlOutParameter outParam = new SqlOutParameter("countryCode", Types.INTEGER);
        SqlOutParameter outParam1 = new SqlOutParameter("dialCode", Types.INTEGER);
        SqlOutParameter outParam2 = new SqlOutParameter("custPrefix", Types.VARCHAR);
        SqlOutParameter outParam3 = new SqlOutParameter("vendorPrefix", Types.VARCHAR);
        SqlOutParameter outParam4 = new SqlOutParameter("custPrice", Types.FLOAT);
        SqlOutParameter outParam5 = new SqlOutParameter("vendorCost", Types.FLOAT);
        SqlOutParameter outParam6 = new SqlOutParameter("profit", Types.FLOAT);
    
        this.declareParameter(rs);
        this.declareParameter(outParam);
        this.declareParameter(outParam1);
        this.declareParameter(outParam2);
        this.declareParameter(outParam3);
        this.declareParameter(outParam4);
        this.declareParameter(outParam5);
        this.declareParameter(outParam6);
    
        this.setFunction(false);
        this.compile();
    }
    
    /**
     * @param countryCode
     * @return
     */
    public Map<String, ?> generateLCRReport(int countryCode) {
    
        Map<String, Object> inParam = new HashMap<String, Object>();
    
        inParam.put("countryCodeParam", new Integer(countryCode));
    
        return this.execute(inParam);
    }
    

    }

Пожалуйста помоги.

Спасибо.


person nicholas    schedule 12.03.2013    source источник
comment
Вы можете попробовать resultSetExtractor   -  person Anubhab    schedule 12.03.2013


Ответы (1)


Я использую RowMapper и объявляю параметр SqlReturnResultSet.

person nicholas    schedule 13.03.2013