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

com.github.rrsunhome.excelsql.SqlGeneratorBuilder 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.RowFormatter;
import com.github.rrsunhome.excelsql.format.SqlRowFormatter;
import com.github.rrsunhome.excelsql.io.ClassPathResource;
import com.github.rrsunhome.excelsql.io.FileSystemResource;
import com.github.rrsunhome.excelsql.io.Resource;
import com.github.rrsunhome.excelsql.parser.FileParser;
import com.github.rrsunhome.excelsql.parser.FileParserManager;

/**
 * @author : wangqijia
 * create at:  2021/11/9  上午11:29
 */
public class SqlGeneratorBuilder {

    private Resource resource;

    private BaseParserConfig parserConfig;

    private FileParser fileParser;

    private RowFormatter rowFormatter;

    public SqlGeneratorBuilder setResource(Resource resource) {
        this.resource = resource;
        return this;
    }

    public SqlGeneratorBuilder setFileSystemResourcePath(String path) {
        this.resource = new FileSystemResource(path);
        return this;
    }

    public SqlGeneratorBuilder setClassPathResourcePath(String path) {
        this.resource = new ClassPathResource(path);
        return this;
    }

    public SqlGeneratorBuilder setParserConfig(BaseParserConfig parserConfig) {
        this.parserConfig = parserConfig;
        return this;
    }

    public SqlGeneratorBuilder setFileParser(FileParser fileParser) {
        this.fileParser = fileParser;
        return this;
    }

    public SqlGeneratorBuilder setSqlFormatConfig(SqlFormatConfig sqlFormatConfig) {
        this.rowFormatter = new SqlRowFormatter(sqlFormatConfig);
        return this;
    }

    public SqlGenerator build() {
        String extension = resource.getExtension();

        if (fileParser == null) {
            fileParser = new FileParserManager().findFileParser(extension);
        }

        if (parserConfig == null) {
            parserConfig = fileParser.getDefaultParserConfig();
        }

        if (!parserConfig.getClass().equals(fileParser.getDefaultParserConfig().getClass())) {
            throw new RuntimeException("解析配置类型不正确");
        }
        return new DefaultSqlGenerator(resource, parserConfig, fileParser, rowFormatter);
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy