use of com.squareup.protoparser.EnumElement in project teiid by teiid.
the class ProtobufMetadataProcessor method toTeiidSchema.
private void toTeiidSchema(String name, String contents, MetadataFactory mf, String cacheName) throws TranslatorException {
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Processing Proto file:", name, " with contents\n", contents);
ProtoFile protoFile = ProtoParser.parse(name, contents);
List<MessageElement> messageTypes = filter(protoFile.typeElements(), MessageElement.class);
List<EnumElement> enumTypes = filter(protoFile.typeElements(), EnumElement.class);
// add tables
HashSet<String> deleteTables = new HashSet<>();
for (MessageElement messageElement : messageTypes) {
Table t = addTable(mf, messageTypes, enumTypes, messageElement, null, deleteTables);
if (t != null) {
if (t.getAnnotation() != null && findFromAnnotation(AT_CACHE, t.getAnnotation(), "name") != null) {
t.setProperty(CACHE, findFromAnnotation(AT_CACHE, t.getAnnotation(), "name"));
} else {
// in metadata, as both parent child must be in single cache.
if (getParentTag(t) == -1) {
t.setProperty(CACHE, cacheName);
}
}
}
}
for (String tableName : deleteTables) {
mf.getSchema().removeTable(tableName);
}
}
use of com.squareup.protoparser.EnumElement in project teiid by teiid.
the class ProtobufMetadataProcessor method isEnum.
private boolean isEnum(List<MessageElement> messageTypes, List<EnumElement> enumTypes, DataType type) {
if (type instanceof DataType.NamedType) {
for (EnumElement element : enumTypes) {
if (element.name().equals(((DataType.NamedType) type).name())) {
return true;
}
}
// enum does not nest, messages nest
for (MessageElement element : messageTypes) {
List<MessageElement> childMessageTypes = filter(element.nestedElements(), MessageElement.class);
List<EnumElement> childEnumTypes = filter(element.nestedElements(), EnumElement.class);
if (isEnum(childMessageTypes, childEnumTypes, type)) {
return true;
}
}
}
return false;
}
use of com.squareup.protoparser.EnumElement in project teiid by teiid.
the class ProtobufMetadataProcessor method getEnumOrdinal.
private String getEnumOrdinal(List<MessageElement> messageTypes, List<EnumElement> enumTypes, String name, String value) {
for (EnumElement element : enumTypes) {
if (element.name().equals(name)) {
for (EnumConstantElement constant : element.constants()) {
if (constant.name().equals(value)) {
return String.valueOf(constant.tag());
}
}
}
}
// enum does not nest, messages nest
for (MessageElement element : messageTypes) {
List<MessageElement> childMessageTypes = filter(element.nestedElements(), MessageElement.class);
List<EnumElement> childEnumTypes = filter(element.nestedElements(), EnumElement.class);
String child = getEnumOrdinal(childMessageTypes, childEnumTypes, name, value);
if (child != null) {
return child;
}
}
return null;
}
Aggregations