Class ClobAccess

  • All Implemented Interfaces:
    java.lang.CharSequence, Lazy
    Direct Known Subclasses:
    PendingClob

    public class ClobAccess
    extends java.lang.Object
    implements java.lang.CharSequence, Lazy
    Class used to read a Clob from the ObjectStore.
    Author:
    Matthew Wakeling
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  ClobAccess.ClobAccessSubclassFactory
      Class to provide fast access to the constructor of plugin subclasses of ClobAccess.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected ClobAccess()
      Protected constructor for use by PendingClob only.
        ClobAccess​(ObjectStore os, Clob clob)
      Construct a ClobAccess object from an ObjectStore and a Clob.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      char charAt​(int index)
      Return a character from the specified index.
      static ClobAccess decodeDbDescription​(ObjectStore os, java.lang.String description)
      Decodes a String from the database representing a clob object.
      void drainToPrintStream​(java.io.PrintStream out)
      Sends the entire contents of the Clob into the given PrintStream.
      Clob getClob()
      Return the Clob that this object is accessing.
      java.lang.String getDbDescription()
      Returns a String that describes this object sufficiently for it to be recreated given an ObjectStore.
      int getLengthWithoutInit()
      Returns the (possibly uninitialised) length internal parameter in this object, for use by subclass constructors.
      ObjectStore getObjectStore()
      Returns the ObjectStore that this object will use to access data.
      int getOffset()
      Return the offset into the underlying clob that this object is using.
      ObjectStore getOs()
      Returns the ObjectStore that this object uses.
      SingletonResults getResultsWithoutInit()
      Returns the (possibly uninitialised) results object used internally by this object, for use by subclass constructors.
      boolean getSubSequence()
      Returns true if this object is a subsequence of a main Clob.
      protected void init()
      Initialises the state of this object.
      int length()
      Returns the length of this character sequence.
      ClobAccess subSequence​(int start, int end)
      Returns a new CharSequence that is a subsequence of this sequence, from start (inclusive) to end (exclusive).
      java.lang.String toString()
      Converts the Clob into a String.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.CharSequence

        chars, codePoints
    • Field Detail

      • clob

        protected Clob clob
      • offset

        protected int offset
      • length

        protected int length
      • subSequence

        protected boolean subSequence
    • Constructor Detail

      • ClobAccess

        protected ClobAccess()
        Protected constructor for use by PendingClob only.
      • ClobAccess

        public ClobAccess​(ObjectStore os,
                          Clob clob)
        Construct a ClobAccess object from an ObjectStore and a Clob. This method will detect the size of the Clob.
        Parameters:
        os - the ObjectStore that the Clob is stored in
        clob - the Clob to access
    • Method Detail

      • init

        protected void init()
        Initialises the state of this object. This is done lazily, because it requires the use of a database connection to discover the length of the clob, and that cannot be done while inside the ObjectStoreWriter while it has exclusive use of the connection.
      • getClob

        public Clob getClob()
        Return the Clob that this object is accessing.
        Returns:
        a Clob object
      • getOffset

        public int getOffset()
        Return the offset into the underlying clob that this object is using.
        Returns:
        an int
      • charAt

        public char charAt​(int index)
        Return a character from the specified index.
        Specified by:
        charAt in interface java.lang.CharSequence
        Parameters:
        index - the position from which to return a character
        Returns:
        a character
        Throws:
        java.lang.IndexOutOfBoundsException - if the index argument is negative or not less than length()
      • length

        public int length()
        Returns the length of this character sequence.
        Specified by:
        length in interface java.lang.CharSequence
        Returns:
        the number of chars in this sequence
      • subSequence

        public ClobAccess subSequence​(int start,
                                      int end)
        Returns a new CharSequence that is a subsequence of this sequence, from start (inclusive) to end (exclusive).
        Specified by:
        subSequence in interface java.lang.CharSequence
        Parameters:
        start - the start index, inclusive
        end - the end index, exclusive
        Returns:
        the specified sequence
        Throws:
        java.lang.IndexOutOfBoundsException - if the start or end are negative, if end is greater than length(), or if start is greater than end
      • getObjectStore

        public ObjectStore getObjectStore()
        Returns the ObjectStore that this object will use to access data.
        Specified by:
        getObjectStore in interface Lazy
        Returns:
        an ObjectStore
      • toString

        public java.lang.String toString()
        Converts the Clob into a String. Be careful that it can fit in memory!
        Specified by:
        toString in interface java.lang.CharSequence
        Overrides:
        toString in class java.lang.Object
        Returns:
        a String
      • drainToPrintStream

        public void drainToPrintStream​(java.io.PrintStream out)
        Sends the entire contents of the Clob into the given PrintStream. This method should be used in preference to toString() in order to save memory with large Clobs.
        Parameters:
        out - a PrintStream to write the Clob value to
      • getDbDescription

        public java.lang.String getDbDescription()
        Returns a String that describes this object sufficiently for it to be recreated given an ObjectStore. This format is stored in the database.
        Returns:
        a String
      • getOs

        public ObjectStore getOs()
        Returns the ObjectStore that this object uses.
        Returns:
        an ObjectStore
      • getLengthWithoutInit

        public int getLengthWithoutInit()
        Returns the (possibly uninitialised) length internal parameter in this object, for use by subclass constructors.
        Returns:
        an int
      • getResultsWithoutInit

        public SingletonResults getResultsWithoutInit()
        Returns the (possibly uninitialised) results object used internally by this object, for use by subclass constructors.
        Returns:
        a SingletonResults object
      • getSubSequence

        public boolean getSubSequence()
        Returns true if this object is a subsequence of a main Clob.
        Returns:
        a boolean
      • decodeDbDescription

        public static ClobAccess decodeDbDescription​(ObjectStore os,
                                                     java.lang.String description)
        Decodes a String from the database representing a clob object. See getDbDescription().
        Parameters:
        os - an ObjectStore that the clob is stored in
        description - the description from the database
        Returns:
        a ClobAccess object, or a subclass