Class TemporaryClob.CharToBytePositionCache

java.lang.Object
org.apache.derby.impl.jdbc.TemporaryClob.CharToBytePositionCache
Enclosing class:
TemporaryClob

private static class TemporaryClob.CharToBytePositionCache extends Object
A simple class to hold the byte position for a character position.

The implementation is very simple and is basically intended to speed up writing a sequence of consequtive characters one character at a time. Even though this should be avoided if possible, the penalty of updating a large Clob this way and finding the correct byte position by navigating from the start of the byte stream each time is so severe that a simple caching mechanism should be in place. Note that for other encodings than UTF-8, this might not be a problem if the mapping between character position and byte position is one-to-one.

Note that to ensure consistency between character and byte positions, access to this class must be synchronized externally to avoid caller 1 getting the character position, then caller 2 updates the cached values and then caller 1 gets the updated byte position.

  • Field Details

    • charPos

      private long charPos
    • bytePos

      private long bytePos
  • Constructor Details

    • CharToBytePositionCache

      CharToBytePositionCache()
  • Method Details

    • getBytePos

      long getBytePos()
      Returns the last cached byte position.
      Returns:
      The byte position for the last cached character position.
    • getCharPos

      long getCharPos()
      Returns the last cached character position.
      Returns:
      The last cached character position.
    • updateCachedPos

      void updateCachedPos(long charPos, long bytePos)
      Updates the position cache.
      Parameters:
      charPos - the character position to cache the byte position for
      bytePos - byte position for the specified character position
    • reset

      void reset()
      Resets the position cache.