gate.db
Class CorpusWrapper
java.lang.Object
|
+--java.util.AbstractCollection
|
+--java.util.AbstractSet
|
+--java.util.TreeSet
|
+--gate.corpora.CorpusImpl
|
+--gate.db.CorpusWrapper
- All Implemented Interfaces:
- Cloneable, Collection, Corpus, FeatureBearer, LanguageResource, LRDBWrapper, Resource, Serializable, Set, SortedSet
- public class CorpusWrapper
- extends CorpusImpl
- implements LRDBWrapper
This class extends CorpusImpl adding database persistence via Jdbc.
- See Also:
- Serialized Form
Method Summary |
(package private) static void |
()
|
void |
beginTransaction()
Starts a transaction. |
void |
commit()
Commits the reads/writes |
private void |
DBInit()
This method takes care of reading the a corpus from the databse or
creating a new one starting from the given name. |
void |
disconnect()
Disconnects from the Datastore object, that is returns the connection |
DataStore |
getDataStore()
Returns the datastore object used for the persistent store of this cropus |
long |
getId()
|
boolean |
isNew()
This method can be used to check whether the constructor read an old
corpus previously stored in in the database or it created a new corpus
starting from transient values. |
void |
rollback()
Rolls back all the actions performed since the last beginTransaction call |
static boolean |
setupDatabase(DataStore ds)
This method checks whether the provided datastore can be used for storing
persistent objects of this type(Corpus). |
Methods inherited from class java.util.TreeSet |
add, addAll, clear, clone, comparator, contains, first, headSet, isEmpty, iterator, last, readObject, remove, size, subSet, tailSet, writeObject |
Methods inherited from interface java.util.Set |
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray |
DEBUG
private static final boolean DEBUG
- Debug flag
id
protected long id
database
protected Database database
con
protected Connection con
stmt
protected Statement stmt
rsLR
protected ResultSet rsLR
rsCorpusDocument
protected ResultSet rsCorpusDocument
rsFeatures
protected ResultSet rsFeatures
isNew
protected boolean isNew
DDL
protected static Table[] DDL
- The definition for database requirements of persistent Corpora.
THis array contains (static)objects of type gate.db.Table which are used
to define the table structure of the database.
A Table object takes the following as paramateres at construction time:
-the name of the table;
-an array of Field objects (used to define the table columns);
-an array of String objects (used to define any suplemetary SQL
statements
needed to initialize the database (e.g. an INSERT statement which adds
some initial values in the table or an ALTER TABLE statement, etc)).
CorpusWrapper
public CorpusWrapper(DataStore db,
String name)
throws IOException
- Constructs a CorpusWrapper object retrieving the information from the
DataStore provided as parameter. If there is a corpus by that name in the
database it will be retrieved and used for the creation of the new object;
if not, a new corpus will be created.
- Parameters:
db
- An object of type gate.db.DataStore which this object will use
to retrieve/store data from/to.name
- The name of the new corpus that will be retrieved from the
database or created and stored in the DataStoreImpl.
CorpusWrapper
public CorpusWrapper(DataStore db,
String name,
FeatureMap features)
throws IOException
- Creates a persistent corpus with the given name and features.
- Parameters:
db
- the datastore this corpus is to be read/saved from/to.name
- the name of the new corpus.features
- the features of the corpus.
CorpusWrapper
public CorpusWrapper(DataStore db,
CorpusImpl corpus)
throws IOException
- Creates a persistent corpus starting from a transient one.
Note that this method can be used to create a persistent copy
of another persistent corpus located in a different database.
- Parameters:
db
- the datstore used for saving the new persistent corpus.corpus
- the transient corpus.
DBInit
private void DBInit()
throws IOException
- This method takes care of reading the a corpus from the databse or
creating a new one starting from the given name.
This method is actually the persistent part of any of the constructors.
First this method will try to read from the database the corpus with the
given name. If it cannot find such a corpus, it will create a new one
using the values from the transient members of this object, memebers that
have been set by the constructor before calling DBInit.
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. All database actions should be enclosed between a
beginTransaction() and a commit()/rollback() call.
- 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, that is returns the connection
- Specified by:
disconnect
in interface LRDBWrapper
getDataStore
public DataStore getDataStore()
- Returns the datastore object used for the persistent store of this cropus
- Specified by:
getDataStore
in interface LanguageResource
- Overrides:
getDataStore
in class CorpusImpl
isNew
public boolean isNew()
- This method can be used to check whether the constructor read an old
corpus previously stored in in the database or it created a new corpus
starting from transient values.
setupDatabase
public static boolean setupDatabase(DataStore ds)
- This method checks whether the provided datastore can be used for storing
persistent objects of this type(Corpus). If necessary, this method will
try to adapt the given datastore so it complies with the requirements
needed for storing corpora.
- Returns:
- true if the datastore is corpus-compliant or if the datastore has
been successfully adapted;
false otherwise.
getId
public long getId()
- Returns:
- the id used for this corpus in the database.
static void ()