com.github.lontime.extjooq.configuration.RenderMappingMapper Maven / Gradle / Ivy
The newest version!
package com.github.lontime.extjooq.configuration;
import java.util.function.Function;
import java.util.regex.Pattern;
import com.github.lontime.shaded.io.helidon.config.Config;
import org.jooq.conf.MappedCatalog;
import org.jooq.conf.MappedSchema;
import org.jooq.conf.MappedTable;
import org.jooq.conf.RenderMapping;
/**
* RenderMappingMapper.
* @author lontime
* @since 1.0
*/
public class RenderMappingMapper implements Function {
@Override
public RenderMapping apply(Config config) {
final RenderMapping renderMapping = new RenderMapping();
config.get("defaultCatalog").asString().ifPresent(renderMapping::setDefaultCatalog);
config.get("defaultSchema").asString().ifPresent(renderMapping::setDefaultSchema);
config.get("catalogs").asList(new MappedCatalogMapper()).ifPresent(renderMapping::setCatalogs);
config.get("schemata").asList(new MappedSchemaMapper()).ifPresent(renderMapping::setSchemata);
return renderMapping;
}
static class MappedCatalogMapper implements Function {
@Override
public MappedCatalog apply(Config config) {
final MappedCatalog catalog = new MappedCatalog();
config.get("input").asString().ifPresent(catalog::setInput);
config.get("inputExpression").asString().map(s -> Pattern.compile(s)).ifPresent(catalog::setInputExpression);
config.get("output").asString().ifPresent(catalog::setOutput);
config.get("schemata").asList(new MappedSchemaMapper()).ifPresent(catalog::setSchemata);
return catalog;
}
}
static class MappedSchemaMapper implements Function {
@Override
public MappedSchema apply(Config config) {
final MappedSchema mappedSchema = new MappedSchema();
config.get("input").asString().ifPresent(mappedSchema::setInput);
config.get("inputExpression").asString().map(s -> Pattern.compile(s)).ifPresent(mappedSchema::setInputExpression);
config.get("output").asString().ifPresent(mappedSchema::setOutput);
config.get("tables").asList(new MappedTableMapper()).ifPresent(mappedSchema::setTables);
return mappedSchema;
}
}
static class MappedTableMapper implements Function {
@Override
public MappedTable apply(Config config) {
MappedTable mappedTable = new MappedTable();
config.get("input").asString().ifPresent(mappedTable::setInput);
config.get("inputExpression").asString().map(s -> Pattern.compile(s)).ifPresent(mappedTable::setInputExpression);
config.get("output").asString().ifPresent(mappedTable::setOutput);
return mappedTable;
}
}
}