
com.at.avro.AvroSchema Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of avro-schema-generator Show documentation
Show all versions of avro-schema-generator Show documentation
Library for generating avro schema files (.avsc) based on DB tables structure
The newest version!
package com.at.avro;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.StringJoiner;
import com.at.avro.config.AvroConfig;
import org.apache.commons.lang3.StringUtils;
import schemacrawler.schema.Column;
import schemacrawler.schema.Table;
/**
* @author [email protected]
*/
public class AvroSchema {
private final String name;
private final String namespace;
private final String doc;
private List fields;
private Map customProperties = new LinkedHashMap<>();
public AvroSchema(Table table, AvroConfig avroConfig) {
this.name = avroConfig.getSchemaNameMapper().apply(table.getName());
this.namespace = avroConfig.getNamespace();
this.doc = avroConfig.isUseSqlCommentsAsDoc() ? table.getRemarks() : null;
this.fields = new ArrayList<>(table.getColumns().size());
for (Column column : table.getColumns()) {
this.fields.add(new AvroField(column, avroConfig));
}
avroConfig.getAvroSchemaPostProcessor().accept(this, table);
}
public String getName() {
return name;
}
public String getNamespace() {
return namespace;
}
public String getDoc() {
return doc;
}
public boolean isDocSet() {
return StringUtils.isNotBlank(doc);
}
public List getFields() {
return fields;
}
public void addCustomProperty(String name, String value) {
customProperties.put(name, value);
}
public Map getCustomProperties() {
return customProperties;
}
@Override
public String toString() {
StringJoiner joiner = new StringJoiner(", ", AvroSchema.class.getSimpleName() + "[", "]")
.add("name='" + name + "'")
.add("namespace='" + namespace + "'");
if (isDocSet()) {
joiner.add("doc='" + doc + "'");
}
joiner
.add("fields=" + fields)
.add("customProperties=" + customProperties);
return joiner.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy