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

io.polaris.builder.code.config.CodeTableBuilder Maven / Gradle / Ivy

There is a newer version: 3.2.1
Show newest version
package io.polaris.builder.code.config;

import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.function.Supplier;

/**
 * @author Qt
 * @since 1.8
 */
public class CodeTableBuilder {
	private final CodeGroupBuilder groupBuilder;
	private final CodeTable target;

	public CodeTableBuilder(CodeGroupBuilder groupBuilder, CodeTable target) {
		this.groupBuilder = groupBuilder;
		this.target = target;
	}

	public CodeTable build() {
		return target;
	}

	public CodeGroupBuilder end() {
		return groupBuilder;
	}

	public CodeTableBuilder name(String name) {
		target.setName(name);
		return this;
	}

	public CodeTableBuilder catalog(String catalog) {
		target.setCatalog(catalog);
		return this;
	}

	public CodeTableBuilder schema(String schema) {
		target.setSchema(schema);
		return this;
	}

	public CodeTableBuilder javaPackage(String javaPackage) {
		target.setJavaPackage(javaPackage);
		return this;
	}

	public CodeTableBuilder property(Map property) {
		target.setProperty(property);
		return this;
	}

	public CodeTableBuilder property(Supplier> property) {
		target.setProperty(property.get());
		return this;
	}

	public CodeTableBuilder property(String key, String value) {
		if (target.getProperty() == null) {
			target.setProperty(new HashMap<>());
		}
		target.getProperty().put(key, value);
		return this;
	}

	public CodeTableBuilder tablePrefix(String tablePrefix) {
		target.setTablePrefix(tablePrefix);
		return this;
	}

	public CodeTableBuilder tableSuffix(String tableSuffix) {
		target.setTableSuffix(tableSuffix);
		return this;
	}

	public CodeTableBuilder columnPrefix(String columnPrefix) {
		target.setColumnPrefix(columnPrefix);
		return this;
	}

	public CodeTableBuilder columnSuffix(String columnSuffix) {
		target.setColumnSuffix(columnSuffix);
		return this;
	}

	public CodeTableBuilder mappings(Set mappings) {
		target.setMappings(mappings);
		return this;
	}

	public CodeTableBuilder mappings(Supplier> mappings) {
		target.setMappings(mappings.get());
		return this;
	}

	public CodeTableBuilder mapping(String jdbcType, String javaType) {
		if (target.getMappings() == null) {
			target.setMappings(new LinkedHashSet<>());
		}
		target.getMappings().add(new TypeMapping(jdbcType, javaType));
		return this;
	}

	public CodeTableBuilder columns(Set columns) {
		target.setColumns(columns);
		return this;
	}

	public CodeTableBuilder columns(Supplier> columns) {
		target.setColumns(columns.get());
		return this;
	}

	public CodeTableBuilder column(String name, String javaType) {
		if (target.getColumns() == null) {
			target.setColumns(new LinkedHashSet<>());
		}
		target.getColumns().add(new ConfigColumn(name, javaType));
		return this;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy