Java Code Examples for com.google.protobuf.DescriptorProtos.FieldOptions#Builder

The following examples show how to use com.google.protobuf.DescriptorProtos.FieldOptions#Builder . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DescriptorGenerator.java    From api-compiler with Apache License 2.0 5 votes vote down vote up
private FieldOptions getFieldOptions(Field field) {
  FieldOptions.Builder builder = FieldOptions.newBuilder();
  if (field.getPacked()) {
    builder.setPacked(true);
  }
  setOptions(builder, field.getOptionsList(), FIELD_OPTION_NAME_PREFIX);
  return builder.build();
}
 
Example 2
Source File: AISToProtobuf.java    From sql-layer with GNU Affero General Public License v3.0 5 votes vote down vote up
protected void addColumn(Column column) {
    String fieldName = uniqueIdent(ident(column.getName(), false), fieldNames);
    fieldBuilder = messageBuilder.addFieldBuilder();
    fieldBuilder.setName(fieldName);
    fieldBuilder.setLabel(Label.LABEL_OPTIONAL);
    FieldOptions.Builder fieldBuilderOptions = FieldOptions.newBuilder();
    ColumnOptions.Builder columnOptions = ColumnOptions.newBuilder();
    if (!fieldName.equals(column.getName())) {
        columnOptions.setName(column.getName());
    }
    columnOptions.setSqlType(column.getTypeDescription().toUpperCase());
    columnOptions.setUuid(column.getUuid().toString());
    priorField = null;
    if (priorMessage != null) {
        for (FieldDescriptorProto field : priorMessage.getFieldList()) {
            FieldOptions options = field.getOptions();
            if ((options != null) &&
                (options.hasExtension(ColumnOptions.fdbsql))) {
                ColumnOptions coptions = options.getExtension(ColumnOptions.fdbsql);
                if (coptions.getUuid().equals(columnOptions.getUuid())) {
                    priorField = field;
                    break;
                }
            }
        }
    }
    setColumnType(column, columnOptions);
    setFieldNumber();
    fieldBuilderOptions.setExtension(ColumnOptions.fdbsql, columnOptions.build());
    fieldBuilder.setOptions(fieldBuilderOptions);
    if (column.getNullable() && 
        ((column.getDefaultValue() != null) ||
         (column.getDefaultFunction() != null))) {
        addNullForField(column.getName(), fieldBuilder.getNumber());
    }
}
 
Example 3
Source File: AISToProtobuf.java    From sql-layer with GNU Affero General Public License v3.0 5 votes vote down vote up
protected void addNullForField(String columnName, int forField) {
    String fieldName = uniqueIdent("_" + ident(columnName, false) + "_is_null", fieldNames);
    fieldBuilder = messageBuilder.addFieldBuilder();
    fieldBuilder.setName(fieldName);
    fieldBuilder.setType(Type.TYPE_BOOL);
    fieldBuilder.setLabel(Label.LABEL_OPTIONAL);
    FieldOptions.Builder fieldBuilderOptions = FieldOptions.newBuilder();
    ColumnOptions.Builder columnOptions = ColumnOptions.newBuilder();
    columnOptions.setNullForField(forField);
    priorField = null;
    if (priorMessage != null) {
        for (FieldDescriptorProto field : priorMessage.getFieldList()) {
            FieldOptions options = field.getOptions();
            if ((options != null) &&
                (options.hasExtension(ColumnOptions.fdbsql))) {
                ColumnOptions coptions = options.getExtension(ColumnOptions.fdbsql);
                if (coptions.hasNullForField() &&
                    (coptions.getNullForField() == forField)) {
                    priorField = field;
                    break;
                }
            }
        }
    }
    setFieldNumber();
    fieldBuilderOptions.setExtension(ColumnOptions.fdbsql, columnOptions.build());
    fieldBuilder.setOptions(fieldBuilderOptions);
}
 
Example 4
Source File: AISToProtobuf.java    From sql-layer with GNU Affero General Public License v3.0 5 votes vote down vote up
protected void addChildTable(Table table) {
    String fieldName = uniqueIdent(ident(table.getName().getTableName(), false), fieldNames);
    fieldBuilder = messageBuilder.addFieldBuilder();
    fieldBuilder.setName(fieldName);
    fieldBuilder.setLabel(Label.LABEL_REPEATED);
    fieldBuilder.setType(Type.TYPE_MESSAGE);
    fieldBuilder.setTypeName(tableMessageNames.get(table));
    FieldOptions.Builder fieldBuilderOptions = FieldOptions.newBuilder();
    ColumnOptions.Builder columnOptions = ColumnOptions.newBuilder();
    columnOptions.setUuid(table.getUuid().toString());
    priorField = null;
    if (priorMessage != null) {
        for (FieldDescriptorProto field : priorMessage.getFieldList()) {
            FieldOptions options = field.getOptions();
            if ((options != null) &&
                (options.hasExtension(ColumnOptions.fdbsql))) {
                ColumnOptions coptions = options.getExtension(ColumnOptions.fdbsql);
                if (coptions.getUuid().equals(columnOptions.getUuid())) {
                    priorField = field;
                    break;
                }
            }
        }
    }
    setFieldNumber();
    fieldBuilderOptions.setExtension(ColumnOptions.fdbsql, columnOptions.build());
    fieldBuilder.setOptions(fieldBuilderOptions);
}