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

com.github.rrsunhome.excelsql.DefaultSqlGenerator Maven / Gradle / Ivy

There is a newer version: 2.1.2
Show newest version
package com.github.rrsunhome.excelsql;

import com.github.rrsunhome.excelsql.config.BaseParserConfig;
import com.github.rrsunhome.excelsql.config.SqlFormatConfig;
import com.github.rrsunhome.excelsql.format.ResultSet;
import com.github.rrsunhome.excelsql.format.RowFormatter;
import com.github.rrsunhome.excelsql.format.SqlRowFormatter;
import com.github.rrsunhome.excelsql.io.Resource;
import com.github.rrsunhome.excelsql.parser.FileParser;
import com.github.rrsunhome.excelsql.parser.FileParserManager;
import com.github.rrsunhome.excelsql.parser.RowDefinition;

import java.util.List;

/**
 * @author : wangqijia
 * create at:  2021/10/27  上午10:24
 */
public class DefaultSqlGenerator implements SqlGenerator {

    private Resource resource;

    private BaseParserConfig parserConfig;

    private FileParser fileParser;

    private RowFormatter rowFormatter;

    public DefaultSqlGenerator(Resource resource, BaseParserConfig parserConfig, FileParser tableParser, RowFormatter rowFormatter) {
        this.resource = resource;
        this.parserConfig = parserConfig;
        this.fileParser = tableParser;
        this.rowFormatter = rowFormatter;
    }


    public DefaultSqlGenerator(Resource resource, BaseParserConfig parserConfig, SqlFormatConfig sqlFormatConfig) {
        this.resource = resource;
        this.parserConfig = parserConfig;
        this.fileParser = findFileParser(resource);
        this.rowFormatter = new SqlRowFormatter(sqlFormatConfig);
    }


    private FileParser findFileParser(Resource resource) {
        FileParserManager fileParserManager = new FileParserManager();
        return fileParserManager.findFileParser(resource.getExtension());
    }


    @Override
    public ResultSet execute() throws Exception {
        List rowDefinitions = fileParser.parse(resource.getInputStream(), parserConfig);

        return rowFormatter.format(rowDefinitions);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy