Package org.intermine.objectstore.query
Class ClobAccess
- java.lang.Object
-
- org.intermine.objectstore.query.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.
-
Field Summary
Fields Modifier and Type Field Description protected Clob
clob
protected int
length
protected int
offset
protected ObjectStore
os
protected SingletonResults
results
protected boolean
subSequence
-
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.
-
-
-
Field Detail
-
os
protected ObjectStore os
-
results
protected SingletonResults results
-
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 inclob
- 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 interfacejava.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 interfacejava.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 interfacejava.lang.CharSequence
- Parameters:
start
- the start index, inclusiveend
- 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 interfaceLazy
- 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 interfacejava.lang.CharSequence
- Overrides:
toString
in classjava.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 indescription
- the description from the database- Returns:
- a ClobAccess object, or a subclass
-
-