referencing columns

Lukas Eder lukas.eder at gmail.com
Thu May 3 08:23:45 UTC 2018


 Hi Douglas,

This type would be very interesting. Akin to JDBC's ResultSetMetaData type,
but more object oriented. Mixed with JDBC's ResultSet's notion of being a
cursor with a current position.

Of course, this cursor-ness is precisely the "old JDBC ResultSet" model,
which is understandable from the perspective of a result set being a
flattened stream of column/value pairs, but I think that few people think
about result sets or records in this way. In JDBC, most people would like
to fetch a List<Row> style type. In ADBA, being asynchronous, a Consumer<Row>
style type (simplified Collector) seems appropriate. Putting the individual
column and its value at the top abstraction level might be surprising.

What would be the benefit of this approach?


2018-05-02 19:42 GMT+02:00 Douglas Surber <douglas.surber at oracle.com>:

> Here is another way to approach referencing columns. Replace ResultMap
> with  Column as defined below. This is not a fully thought out proposal. It
> is instead an attempt to look at the problem from another direction and not
> get stuck with the same old JDBC ResultSet model.
>
> Douglas
>
> /**
>  * A mutable handle to one value of an ordered sequence of columns or of
>  * out parameters. Columns have a 1-based index and optionally an
> identifier.
>  * Identifiers are not guaranteed to be unique.
>  */
> public interface Column extends Iterable<Column>, Iterator<Column>,
> Cloneable {
>
>   /**
>    * Return the value of this column as an instance of the given type.
>    *
>    * @param <T>
>    * @param type
>    * @return
>    */
>   public <T> T get(Class<T> type);
>
>   /**
>    * Return the identifier of this column. May be null.
>    *
>    * @return
>    */
>   public String identifier();
>
>   /**
>    * Return the 1-based index of this Column.
>    *
>    * @return
>    */
>   public int index();
>
>   /**
>    * Return the SQL type of the value of this column.
>    *
>    * @return
>    */
>   public SqlType type();
>
>   /**
>    * Modify this Column to point to the next value identified by id.
>    *
>    * @param id
>    * @return this Column
>    */
>   public Column at(String id);
>
>   /**
>    * Modify this Column to point to the value at index. The first value is
> at index 1.
>    * Negative numbers count back from the last value. The last value is at
>    * index -1.
>    *
>    * @param index
>    * @return this Column
>    */
>   public Column at(int index);
>
>   /**
>    * Return a new Column that is a handle to a subsequence of sequence of
> values
>    * referenced by this Column. The subsequence consists of the length
> values in
>    * order starting with the value this Column points to when this method
> is
>    * called. This Column is not modified.
>    *
>    * @param length
>    * @return a new Column.
>    */
>   public Column slice(int length);
>
>   /**
>    * Return a new Column that is a duplicate of this Column.
>    *
>    * @return a new Column
>    */
>   public Column clone();
>
>   /**
>    * Modify this Column to point to the next value in the sequence.
>    *
>    * @return this Column
>    */
>   @Override
>   public Column next();
>
>   @Override
>   public boolean hasNext();
>
>
>   static void sample(Column columns) {
>
>     Map map = new HashMap();
>     for (Column m : columns) {
>       map.put(m.identifier(), m.get(Integer.class));
>     }
>
>     List l = new ArrayList();
>     for (Column m : columns.at(3).slice(5)) {
>       l.add(m.get(String.class));
>     }
>
>     Column addr = columns.clone().at("street_address_1");
>     String streetAddress1 = addr.get(String.class);
>     String streetAddress2 = addr.next().get(String.class);
>     String city = addr.next().get(String.class);
>     String state = addr.next().get(String.class);
>     String postalCode = addr.next().get(String.class);
>
>     String givenName = columns.at("GIVEN_NAME").get(String.class);
>     String familyName = columns.at("FAMILY_NAME").get(String.class);
>
>   }
> }
>
>


More information about the jdbc-spec-discuss mailing list