Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8014252

Generic accessors to SQLInput, SQLOutput

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P5 P5
    • None
    • None
    • core-libs
    • None

      A DESCRIPTION OF THE REQUEST :
      Currently, interfaces SQLInput, SQLOutput provide plenty accessors for distinct type, and one general read/writeObject().
      The latter could be generified to cover all other non-primitive types, with the effect pushing the root of a possible ClassCastException to the call site layer.
      The non-primitive distinct ones could be deprecated.

      JUSTIFICATION :
      - general convenience
      - save the additional external cast for readObject()
      - in the javax.sql.rowset.serial implementation, the dictinct accessors could internally cause a ClassCastException, which would be unfathomable for users
      - less code to maintain, especially for future extensions


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      E.G.:
      boolean b = sqlInput.readBoolean();
      Boolean b = sqlInput.readObject();
      String s = sqlInput.readObject();
      Blob b = sqlInput.readObject();
      ...

      ACTUAL -
      E.G.:
      boolean b = sqlInput.readBoolean();
      Boolean b = (Boolean)sqlInput.readObject();
      String s = sqlInput.readString();
      Blob b = sqlInput.readBlob();
      ...


      ---------- BEGIN SOURCE ----------
      proposed source changes for javax.sql.rowset.serial.SQLInputImpl

          private int idx = 0; // init with 0 instead -1

          private Object attribs[]; // rename attrib to attribs

          public boolean readBoolean() throws SQLException {
              Boolean attrib = readObject(); // replace old (Boolean)getNextAttribute()
              return (attrib == null) ? false : attrib.booleanValue();
          }

          public <T> T readObject() throws SQLException {
              if (idx >= attribs.length) {
                  throw new SQLException( " SQLInputImpl exception: Invalid read " +
                                          " position " );
              }
              T attrib = (T)attribs[idx++];
              lastValueWasNull = attrib == null;
              if (attrib instanceof Struct) {
                  ... // maybe move to extra method to enhance possibility
                  ... // for JIT to compile + inline the main path
                  ...
              }
              return attrib;
          }


      ---------- END SOURCE ----------

            lancea Lance Andersen
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: