gate.db
Class DocumentWrapper

java.lang.Object
  |
  +--gate.util.AbstractFeatureBearer
        |
        +--gate.creole.AbstractResource
              |
              +--gate.creole.AbstractLanguageResource
                    |
                    +--gate.corpora.DocumentImpl
                          |
                          +--gate.db.DocumentWrapper
All Implemented Interfaces:
Comparable, Document, FeatureBearer, LanguageResource, LRDBWrapper, Resource, Serializable

public class DocumentWrapper
extends DocumentImpl
implements LRDBWrapper

This class extends DocumentImpl adding database persistence via Jdbc.

See Also:
Serialized Form

Constructor Summary
DocumentWrapper(Connection con, Database db, DocumentImpl doc)
          Construction from Document.
DocumentWrapper(Connection con, Database ds, long id)
          Construction from ID.
DocumentWrapper(DataStore ds, DocumentImpl doc)
          Construction from Document.
DocumentWrapper(DataStore ds, long id)
          Construction from ID.
DocumentWrapper(DataStore ds, String urlString)
          Construction from String representing URL
DocumentWrapper(DataStore ds, URL u)
          Construction from URL; content read over the net.
DocumentWrapper(DataStore ds, URL u, Long start, Long end)
          Construction from URL and offsets.
DocumentWrapper(URL u, String encoding, Long start, Long end)
          Construction from URL and offsets.
 
Method Summary
 void beginTransaction()
          Starts a transaction
 void commit()
          Commits the reads/writes
 void disconnect()
          Disconnects from the Datastore object, i.e.
 DataStore getDataStore()
          Returns the Datastore object associated to this persistent document.
 long getId()
          Gets the database ID of this persistent object.
 boolean isNew()
          Can be used to check if this document is an old one that has been retrieved from the databse or is a new one that has just been saved.
 void rollback()
          Rolls back all the actions performed since the last beginTransaction call
static boolean setupDatabase(DataStore ds)
          Checks if the provided datastore id proper for storing persistent documents of this type.
 
Methods inherited from class gate.corpora.DocumentImpl
addDocumentListener, addGateListener, addStatusListener, compareTo, edit, equals, getAnnotations, getAnnotations, getContent, getEncoding, getFeatures, getMarkupAware, getNamedAnnotationSets, getNextAnnotationId, getNextNodeId, getSourceUrl, getSourceUrlEndOffset, getSourceUrlOffsets, getSourceUrlStartOffset, hashCode, init, isValidOffset, isValidOffsetRange, removeAnnotationSet, removeDocumentListener, removeGateListener, removeStatusListener, setContent, setEncoding, setFeatures, setMarkupAware, setSourceUrl, setSourceUrlEndOffset, setSourceUrlStartOffset, setStringContent, toString, toXml
 
Methods inherited from class gate.creole.AbstractLanguageResource
setDataStore, sync
 
Methods inherited from class gate.creole.AbstractResource
getName, setName
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface gate.LanguageResource
setDataStore, sync
 
Methods inherited from interface gate.Resource
init
 
Methods inherited from interface gate.util.FeatureBearer
getFeatures, getName, setFeatures, setName
 

Constructor Detail

DocumentWrapper

public DocumentWrapper(URL u,
                       String encoding,
                       Long start,
                       Long end)
                throws IOException
Construction from URL and offsets. Both offsets must be non-null, or they are both ignored. Content is read over the net between the offsets.

DocumentWrapper

public DocumentWrapper(DataStore ds,
                       URL u,
                       Long start,
                       Long end)
                throws IOException,
                       SQLException
Construction from URL and offsets. Both offsets must be non-null, or they are both ignored. Content is read over the net between the offsets.

DocumentWrapper

public DocumentWrapper(DataStore ds,
                       URL u)
                throws IOException,
                       SQLException
Construction from URL; content read over the net.

DocumentWrapper

public DocumentWrapper(DataStore ds,
                       String urlString)
                throws IOException,
                       SQLException
Construction from String representing URL

DocumentWrapper

public DocumentWrapper(DataStore ds,
                       DocumentImpl doc)
                throws IOException,
                       SQLException
Construction from Document. This is the recommended way for making a transient document become persistent.

DocumentWrapper

public DocumentWrapper(Connection con,
                       Database db,
                       DocumentImpl doc)
                throws IOException
Construction from Document. This is the recommended way for making a transient document become persistent. Unlike the other constructor that gets a document, thus one receives an open connection rather than a DataStore. This is useful for clients that want this document to be read/written to the database inside their open transaction.

DocumentWrapper

public DocumentWrapper(DataStore ds,
                       long id)
                throws IOException,
                       NoSuchObjectException,
                       SQLException
Construction from ID. This is the way to get the document when the Id is already known.

DocumentWrapper

public DocumentWrapper(Connection con,
                       Database ds,
                       long id)
                throws IOException,
                       NoSuchObjectException,
                       SQLException
Construction from ID. This is the way to get the document when the Id is already known.
Method Detail

rollback

public void rollback()
              throws SQLException
Rolls back all the actions performed since the last beginTransaction call
Specified by:
rollback in interface LRDBWrapper

beginTransaction

public void beginTransaction()
                      throws SQLException
Starts a transaction
Specified by:
beginTransaction in interface LRDBWrapper

commit

public void commit()
            throws SQLException
Commits the reads/writes
Specified by:
commit in interface LRDBWrapper

disconnect

public void disconnect()
                throws GateException
Disconnects from the Datastore object, i.e. returns the connection
Specified by:
disconnect in interface LRDBWrapper

getDataStore

public DataStore getDataStore()
Returns the Datastore object associated to this persistent document.
Specified by:
getDataStore in interface LanguageResource
Overrides:
getDataStore in class AbstractLanguageResource
Returns:
a value of type 'DataStore'

isNew

public boolean isNew()
Can be used to check if this document is an old one that has been retrieved from the databse or is a new one that has just been saved.
Returns:
a value of type 'boolean'

setupDatabase

public static boolean setupDatabase(DataStore ds)
Checks if the provided datastore id proper for storing persistent documents of this type.
Parameters:
ds - a value of type 'DataStore'
Returns:
a value of type 'boolean'

getId

public long getId()
Gets the database ID of this persistent object.
Returns:
a value of type 'long'