Class PgArray

  • All Implemented Interfaces:
    java.sql.Array

    public class PgArray
    extends java.lang.Object
    implements java.sql.Array

    Array is used collect one column of query result data.

    Read a field of type Array into either a natively-typed Java array object or a ResultSet. Accessor methods provide the ability to capture array slices.

    Other than the constructor all methods are direct implementations of those specified for java.sql.Array. Please refer to the javadoc for java.sql.Array for detailed descriptions of the functionality and parameters of the methods of this class.

    See Also:
    ResultSet.getArray(int)
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  PgArray.PgArrayList
      Array list implementation specific for storing PG array elements.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private PgArray​(BaseConnection connection, int oid)  
        PgArray​(BaseConnection connection, int oid, byte[] fieldBytes)
      Create a new Array.
        PgArray​(BaseConnection connection, int oid, java.lang.String fieldString)
      Create a new Array.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private java.lang.Object buildArray​(PgArray.PgArrayList input, int index, int count)
      Convert ArrayList to array.
      private void buildArrayList()
      Build ArrayList from field's string input.
      private int calcRemainingDataLength​(int[] dims, int pos, int elementOid, int thisDimension)  
      private java.lang.Class<?> elementOidToClass​(int oid)  
      static void escapeArrayElement​(java.lang.StringBuilder b, java.lang.String s)  
      void free()  
      java.lang.Object getArray()  
      java.lang.Object getArray​(long index, int count)  
      java.lang.Object getArray​(long index, int count, java.util.Map<java.lang.String,​java.lang.Class<?>> map)  
      java.lang.Object getArray​(java.util.Map<java.lang.String,​java.lang.Class<?>> map)  
      java.lang.Object getArrayImpl​(long index, int count, java.util.Map<java.lang.String,​java.lang.Class<?>> map)  
      java.lang.Object getArrayImpl​(java.util.Map<java.lang.String,​java.lang.Class<?>> map)  
      int getBaseType()  
      java.lang.String getBaseTypeName()  
      java.sql.ResultSet getResultSet()  
      java.sql.ResultSet getResultSet​(long index, int count)  
      java.sql.ResultSet getResultSet​(long index, int count, java.util.Map<java.lang.String,​java.lang.Class<?>> map)  
      java.sql.ResultSet getResultSet​(java.util.Map<java.lang.String,​java.lang.Class<?>> map)  
      java.sql.ResultSet getResultSetImpl​(long index, int count, java.util.Map<java.lang.String,​java.lang.Class<?>> map)  
      java.sql.ResultSet getResultSetImpl​(java.util.Map<java.lang.String,​java.lang.Class<?>> map)  
      boolean isBinary()  
      private java.lang.Object readBinaryArray​(int index, int count)  
      private java.sql.ResultSet readBinaryResultSet​(int index, int count)  
      private int storeValues​(java.lang.Object[] arr, int elementOid, int[] dims, int pos, int thisDimension, int index)  
      private int storeValues​(java.util.List<Tuple> rows, Field[] fields, int elementOid, int[] dims, int pos, int thisDimension, int index)  
      byte[] toBytes()  
      java.lang.String toString()  
      private java.lang.String toString​(PgArray.PgArrayList list)
      Convert array list to PG String representation (e.g.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • connection

        protected BaseConnection connection
        A database connection.
      • oid

        private int oid
        The OID of this field.
      • fieldString

        protected java.lang.String fieldString
        Field value as String.
      • useObjects

        private final boolean useObjects
        Whether Object[] should be used instead primitive arrays. Object[] can contain null elements. It should be set to true if BaseConnection#haveMinimumCompatibleVersion(String) returns true for argument "8.3".
      • fieldBytes

        protected byte[] fieldBytes
    • Constructor Detail

      • PgArray

        private PgArray​(BaseConnection connection,
                        int oid)
                 throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • PgArray

        public PgArray​(BaseConnection connection,
                       int oid,
                       java.lang.String fieldString)
                throws java.sql.SQLException
        Create a new Array.
        Parameters:
        connection - a database connection
        oid - the oid of the array datatype
        fieldString - the array data in string form
        Throws:
        java.sql.SQLException - if something wrong happens
      • PgArray

        public PgArray​(BaseConnection connection,
                       int oid,
                       byte[] fieldBytes)
                throws java.sql.SQLException
        Create a new Array.
        Parameters:
        connection - a database connection
        oid - the oid of the array datatype
        fieldBytes - the array data in byte form
        Throws:
        java.sql.SQLException - if something wrong happens
    • Method Detail

      • getArray

        public java.lang.Object getArray()
                                  throws java.sql.SQLException
        Specified by:
        getArray in interface java.sql.Array
        Throws:
        java.sql.SQLException
      • getArray

        public java.lang.Object getArray​(long index,
                                         int count)
                                  throws java.sql.SQLException
        Specified by:
        getArray in interface java.sql.Array
        Throws:
        java.sql.SQLException
      • getArrayImpl

        public java.lang.Object getArrayImpl​(java.util.Map<java.lang.String,​java.lang.Class<?>> map)
                                      throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • getArray

        public java.lang.Object getArray​(java.util.Map<java.lang.String,​java.lang.Class<?>> map)
                                  throws java.sql.SQLException
        Specified by:
        getArray in interface java.sql.Array
        Throws:
        java.sql.SQLException
      • getArray

        public java.lang.Object getArray​(long index,
                                         int count,
                                         java.util.Map<java.lang.String,​java.lang.Class<?>> map)
                                  throws java.sql.SQLException
        Specified by:
        getArray in interface java.sql.Array
        Throws:
        java.sql.SQLException
      • getArrayImpl

        public java.lang.Object getArrayImpl​(long index,
                                             int count,
                                             java.util.Map<java.lang.String,​java.lang.Class<?>> map)
                                      throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • readBinaryArray

        private java.lang.Object readBinaryArray​(int index,
                                                 int count)
                                          throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • storeValues

        private int storeValues​(java.lang.Object[] arr,
                                int elementOid,
                                int[] dims,
                                int pos,
                                int thisDimension,
                                int index)
                         throws java.sql.SQLException,
                                java.io.IOException
        Throws:
        java.sql.SQLException
        java.io.IOException
      • readBinaryResultSet

        private java.sql.ResultSet readBinaryResultSet​(int index,
                                                       int count)
                                                throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • storeValues

        private int storeValues​(java.util.List<Tuple> rows,
                                Field[] fields,
                                int elementOid,
                                int[] dims,
                                int pos,
                                int thisDimension,
                                int index)
                         throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • calcRemainingDataLength

        private int calcRemainingDataLength​(int[] dims,
                                            int pos,
                                            int elementOid,
                                            int thisDimension)
      • elementOidToClass

        private java.lang.Class<?> elementOidToClass​(int oid)
                                              throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • buildArrayList

        private void buildArrayList()
                             throws java.sql.SQLException
        Build ArrayList from field's string input. As a result of this method arrayList is build. Method can be called many times in order to make sure that array list is ready to use, however arrayList will be set only once during first call.
        Throws:
        java.sql.SQLException
      • buildArray

        private java.lang.Object buildArray​(PgArray.PgArrayList input,
                                            int index,
                                            int count)
                                     throws java.sql.SQLException
        Convert ArrayList to array.
        Parameters:
        input - list to be converted into array
        Throws:
        java.sql.SQLException
      • getBaseType

        public int getBaseType()
                        throws java.sql.SQLException
        Specified by:
        getBaseType in interface java.sql.Array
        Throws:
        java.sql.SQLException
      • getBaseTypeName

        public java.lang.String getBaseTypeName()
                                         throws java.sql.SQLException
        Specified by:
        getBaseTypeName in interface java.sql.Array
        Throws:
        java.sql.SQLException
      • getResultSet

        public java.sql.ResultSet getResultSet()
                                        throws java.sql.SQLException
        Specified by:
        getResultSet in interface java.sql.Array
        Throws:
        java.sql.SQLException
      • getResultSet

        public java.sql.ResultSet getResultSet​(long index,
                                               int count)
                                        throws java.sql.SQLException
        Specified by:
        getResultSet in interface java.sql.Array
        Throws:
        java.sql.SQLException
      • getResultSet

        public java.sql.ResultSet getResultSet​(java.util.Map<java.lang.String,​java.lang.Class<?>> map)
                                        throws java.sql.SQLException
        Specified by:
        getResultSet in interface java.sql.Array
        Throws:
        java.sql.SQLException
      • getResultSet

        public java.sql.ResultSet getResultSet​(long index,
                                               int count,
                                               java.util.Map<java.lang.String,​java.lang.Class<?>> map)
                                        throws java.sql.SQLException
        Specified by:
        getResultSet in interface java.sql.Array
        Throws:
        java.sql.SQLException
      • getResultSetImpl

        public java.sql.ResultSet getResultSetImpl​(java.util.Map<java.lang.String,​java.lang.Class<?>> map)
                                            throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • getResultSetImpl

        public java.sql.ResultSet getResultSetImpl​(long index,
                                                   int count,
                                                   java.util.Map<java.lang.String,​java.lang.Class<?>> map)
                                            throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toString

        private java.lang.String toString​(PgArray.PgArrayList list)
                                   throws java.sql.SQLException
        Convert array list to PG String representation (e.g. {0,1,2}).
        Throws:
        java.sql.SQLException
      • escapeArrayElement

        public static void escapeArrayElement​(java.lang.StringBuilder b,
                                              java.lang.String s)
      • isBinary

        public boolean isBinary()
      • toBytes

        public byte[] toBytes()
      • free

        public void free()
                  throws java.sql.SQLException
        Specified by:
        free in interface java.sql.Array
        Throws:
        java.sql.SQLException