Class TypeBridge<S>


  • public abstract class TypeBridge<S>
    extends Object
    Encapsulate some information about Java object classes and their possible mappings to PostgreSQL types.

    This may be a temporary class that goes away entirely in a future major release of PL/Java that revamps how type mappings are determined. Or, it may evolve and take on greater responsibility in a revamped scheme: type mapping information is, at present, diffused and duplicated a lot of places in PL/Java, and bringing it into one place would not be a bad thing.

    For now, in the 1.5.x series, this is a simple stopgap so that the few places in PL/Java where an object type can be passed to PostgreSQL (SingleRowWriter, TriggerResultSet, SQLOutputToTuple, PreparedStatement) are able to pass an object that isn't of the class expected by default, and have the right native conversion get selected. All of those sites currently work by some variant of putting supplied objects into an Object array or list later passed to the native code, and when an object will not be of the expected class, what is stored in the array should be a TypeBridge.Holder for it.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      class  TypeBridge.Holder
      Class that holds an object reference being passed from Java to PG, when the object is of one of the known classes that were not accepted by PL/Java's JDBC driver before PL/Java 1.5.1.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected Class<S> m_cachedClass
      If the Java class associated with the TypeBridge is loaded and available, it can be cached here.
      protected String m_canonName
      Canonical name of the Java class or interface that this TypeBridge 'captures'.
      protected int m_defaultOid
      Oid of the PostgreSQL type to be associated by default with this Java class or interface.
    • Field Detail

      • m_canonName

        protected final String m_canonName
        Canonical name of the Java class or interface that this TypeBridge 'captures'.

        Held as a string so that the class does not need to be loaded for a TypeBridge to be made for it. There can be TypeBridges for classes that not all supported JRE versions provide.

      • m_defaultOid

        protected final int m_defaultOid
        Oid of the PostgreSQL type to be associated by default with this Java class or interface.

        Stored as a simple int here, not a PL/Java Oid object, which I am tempted to deprecate.

      • m_cachedClass

        protected Class<S> m_cachedClass
        If the Java class associated with the TypeBridge is loaded and available, it can be cached here.

        That will always be the case after a captures(java.lang.Class<?>) method has returned true.

    • Method Detail

      • setCachedClass

        protected void setCachedClass​(Class<?> cls)
      • wrap

        public static <T,​U extends T> TypeBridge.Holder wrap​(U o)
        Return an object wrapped, if it is of any type captured by a known TypeBridge.
        Parameters:
        o - An object, representing a value to be presented to PostgreSQL.
        Returns:
        A Holder wrapping o, or null if no known TypeBridge captures the type of o, or o itself is null.
      • captures

        public final boolean captures​(Class<?> c)
        Determine whether this TypeBridge 'captures' a given Class.

        If the class this TypeBridge represents has already been loaded and is cached here, the test is a simple isAssignableFrom. Otherwise, the test is conducted by climbing the superclasses or superinterfaces, as appropriate, of the passed Class, comparing canonical names. If a match is found, the winning Class object is cached before returning true.

      • virtuallyCaptures

        protected abstract boolean virtuallyCaptures​(Class<?> c)
        Method the two subclasses implement to conduct the "Class-less" superclass or superinterface check, respectively.