Exemplo n.º 1
0
    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();
    }
Exemplo n.º 2
0
    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);
    }
Exemplo n.º 3
0
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((columns == null) ? 0 : columns.hashCode());
   result = prime * result + ((cursorFactory == null) ? 0 : cursorFactory.hashCode());
   result = prime * result + ((parameters == null) ? 0 : parameters.hashCode());
   result = prime * result + ((sql == null) ? 0 : sql.hashCode());
   return result;
 }
Exemplo n.º 4
0
    @Override
    public boolean equals(Object o) {
      if (o == this) {
        return true;
      }
      if (o instanceof Signature) {
        Signature other = (Signature) o;

        if (null == columns) {
          if (null != other.columns) {
            return false;
          }
        } else if (!columns.equals(other.columns)) {
          return false;
        }

        if (null == cursorFactory) {
          if (null != other.cursorFactory) {
            return false;
          }
        } else if (!cursorFactory.equals(other.cursorFactory)) {
          return false;
        }

        if (null == parameters) {
          if (null != other.parameters) {
            return false;
          }
        } else if (!parameters.equals(other.parameters)) {
          return false;
        }

        if (null == sql) {
          if (null != other.sql) {
            return false;
          }
        } else if (!sql.equals(other.sql)) {
          return false;
        }

        return true;
      }

      return false;
    }
Exemplo n.º 5
0
    public static CursorFactory fromProto(Common.CursorFactory proto) {
      // Reconstruct CursorFactory
      Class<?> clz = null;

      FieldDescriptor clzFieldDesc =
          proto
              .getDescriptorForType()
              .findFieldByNumber(Common.CursorFactory.CLASS_NAME_FIELD_NUMBER);

      if (proto.hasField(clzFieldDesc)) {
        try {
          clz = Class.forName(proto.getClassName());
        } catch (ClassNotFoundException e) {
          throw new RuntimeException(e);
        }
      }

      return CursorFactory.create(
          Style.fromProto(proto.getStyle()), clz, proto.getFieldNamesList());
    }