Package org.mifosplatform.mix.service

Source Code of org.mifosplatform.mix.service.MixTaxonomyMappingReadPlatformServiceImpl

/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.mix.service;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
import org.mifosplatform.mix.data.MixTaxonomyMappingData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

@Service
public class MixTaxonomyMappingReadPlatformServiceImpl implements MixTaxonomyMappingReadPlatformService {

    private final JdbcTemplate jdbcTemplate;

    @Autowired
    public MixTaxonomyMappingReadPlatformServiceImpl(final RoutingDataSource dataSource) {
        this.jdbcTemplate = new JdbcTemplate(dataSource);
    }

    private static final class TaxonomyMappingMapper implements RowMapper<MixTaxonomyMappingData> {

        public String schema() {
            return "identifier, config " + "from mix_taxonomy_mapping";
        }

        @Override
        public MixTaxonomyMappingData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
            final String identifier = rs.getString("identifier");
            final String config = rs.getString("config");
            return new MixTaxonomyMappingData(identifier, config);
        }

    }

    @Override
    public MixTaxonomyMappingData retrieveTaxonomyMapping() {
        try {
            final TaxonomyMappingMapper rm = new TaxonomyMappingMapper();
            final String sqlString = "select " + rm.schema();
            return this.jdbcTemplate.queryForObject(sqlString, rm);
        } catch (final EmptyResultDataAccessException e) {
            return null;
        }

    }
}
TOP

Related Classes of org.mifosplatform.mix.service.MixTaxonomyMappingReadPlatformServiceImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.
[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-20639858-1', 'auto'); ga('send', 'pageview');