public Common.Signature toProto() { Common.Signature.Builder builder = Common.Signature.newBuilder(); if (null != sql) { builder.setSql(sql); } if (null != cursorFactory) { builder.setCursorFactory(cursorFactory.toProto()); } if (null != columns) { for (ColumnMetaData column : columns) { builder.addColumns(column.toProto()); } } if (null != parameters) { for (AvaticaParameter parameter : parameters) { builder.addParameters(parameter.toProto()); } } return builder.build(); }
public static Signature fromProto(Common.Signature protoSignature) { List<ColumnMetaData> metadata = new ArrayList<>(protoSignature.getColumnsCount()); for (Common.ColumnMetaData protoMetadata : protoSignature.getColumnsList()) { metadata.add(ColumnMetaData.fromProto(protoMetadata)); } List<AvaticaParameter> parameters = new ArrayList<>(protoSignature.getParametersCount()); for (Common.AvaticaParameter protoParam : protoSignature.getParametersList()) { parameters.add(AvaticaParameter.fromProto(protoParam)); } final Descriptor desc = protoSignature.getDescriptorForType(); String sql = null; if (ProtobufService.hasField(protoSignature, desc, Common.Signature.SQL_FIELD_NUMBER)) { sql = protoSignature.getSql(); } CursorFactory cursorFactory = null; if (ProtobufService.hasField( protoSignature, desc, Common.Signature.CURSOR_FACTORY_FIELD_NUMBER)) { cursorFactory = CursorFactory.fromProto(protoSignature.getCursorFactory()); } return Signature.create(metadata, sql, parameters, cursorFactory); }