Class Adapter.As<T,U>

java.lang.Object
org.postgresql.pljava.Adapter<T,U>
org.postgresql.pljava.Adapter.As<T,U>
All Implemented Interfaces:
Adapter.ArrayProto<T[]>, SlotTester.Visible
Direct Known Subclasses:
Adapter.Array
Enclosing class:
Adapter<T,U>

public abstract static class Adapter.As<T,U> extends Adapter<T,U> implements Adapter.ArrayProto<T[]>
Superclass for adapters that fetch something and return it as a reference type T.

The type variable U for the thing consumed gets no enforcement from the compiler, because any extending adapter class provides its own T fetch(Attribute,something) method, with no abstract version inherited from this class to constrain it. The method will be found reflectively by name and parameter types, so the "something" only has to match the type of the accessor method specified with Via, or the type returned by an underlying adapter that this one will be composed over.

In particular, that means this is the class to extend even if using a primitive accessor method, or composing over an adapter that returns a primitive type, as long as this adapter will return a reference type T. Such an adapter simply declares that it extends As<T,Void> when based on a primitive accessor method, or As<T,boxed-class> when composed over another adapter of primitive type, where boxed-class is the boxed counterpart of the other adapter's primitive type.

When Java's reflection methods on generic types are used to compute the (non-erased) result type of a stack of composed adapters, the type variable U can be used in relating the input to the output type of each.

  • Constructor Details

    • As

      protected As(Adapter.Configuration c, Adapter<U,?> over, Class<T> witness)
      Constructor for a simple leaf Adapter, or a composing (non-leaf) Adapter when passed another adapter over which it should be composed.
      Parameters:
      c - Configuration instance generated for this class
      over - null for a leaf Adapter, otherwise another Adapter to compose this one over
      witness - if not null, the top type the resulting adapter will produce, if a Class object can specify that more precisely than the default typing rules.
    • As

      protected As(Adapter.Contract.Scalar<T> using, Class<T> witness, Adapter.Configuration c)
      Constructor for a leaf Adapter that is based on a Contract.
      Parameters:
      using - the scalar Contract that will be used to produce the value returned
      witness - if not null, the top type the resulting adapter will produce, if a Class object can specify that more precisely than the default typing rules.
      c - Configuration instance generated for this class
  • Method Details

    • fetch

      public final <B> T fetch(Datum.Accessor<B,?> acc, B buffer, int offset, Attribute a)
      Method invoked internally when this Adapter is used to fetch a value; not intended for use in application code.
    • canFetchNull

      public boolean canFetchNull()
      A default implementation of canFetchNull that unconditionally returns true.

      An adapter that extends this class, if it does not override fetchNull, will simply map any SQL null value to a Java null.

      Specified by:
      canFetchNull in class Adapter<T,U>
    • fetchNull

      public T fetchNull(Attribute a)
      Determines the value to which SQL null should be mapped.

      If not overridden, this implementation returns Java null.

    • arrayOf

      public T[] arrayOf(int length)
      Allocate an array of the given length with this adapter's result type as its component type.