Search in sources :

Example 1 with ProtoFile

use of com.squareup.protoparser.ProtoFile 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);
    }
}
Also used : Table(org.teiid.metadata.Table) ProtoFile(com.squareup.protoparser.ProtoFile) MessageElement(com.squareup.protoparser.MessageElement) EnumElement(com.squareup.protoparser.EnumElement) HashSet(java.util.HashSet)

Aggregations

EnumElement (com.squareup.protoparser.EnumElement)1 MessageElement (com.squareup.protoparser.MessageElement)1 ProtoFile (com.squareup.protoparser.ProtoFile)1 HashSet (java.util.HashSet)1 Table (org.teiid.metadata.Table)1