GATE
Version 3.1-2270

gate.persist
Class JDBCDataStore

java.lang.Object
  extended by gate.util.AbstractFeatureBearer
      extended by gate.persist.JDBCDataStore
All Implemented Interfaces:
DataStore, CreoleListener, DatabaseDataStore, FeatureBearer, NameBearer, Serializable, EventListener
Direct Known Subclasses:
OracleDataStore, PostgresDataStore

public abstract class JDBCDataStore
extends AbstractFeatureBearer
implements DatabaseDataStore, CreoleListener

See Also:
Serialized Form

Field Summary
protected  AccessController ac
          Security factory that contols access to objects in the datastore the security session is from this factory
protected  String datastoreComment
           
protected  String dbSchema
           
protected  int dbType
           
protected  Vector dependentResources
          resources that should be sync-ed if datastore is close()-d
protected  String iconName
           
protected  Connection jdbcConn
          jdbc connection, all access to the database is made through this connection
protected  String name
          datastore name?
protected  Session session
          security session identifying all access to the datastore
 
Fields inherited from class gate.util.AbstractFeatureBearer
features
 
Fields inherited from interface gate.DataStore
DATASTORE_FEATURE_NAME, LR_ID_FEATURE_NAME
 
Constructor Summary
protected JDBCDataStore()
          Do not use this class directly - use one of the subclasses
 
Method Summary
protected  LanguageResource _adopt(LanguageResource lr, SecurityInfo secInfo, boolean openNewTrans)
           
protected  void _sync(LanguageResource lr, boolean openNewTrans)
          Save: synchonise the in-memory image of the LR with the persistent image.
protected  void _syncAddedAnnotations(Document doc, AnnotationSet as, Collection changes)
          helper for sync() - never call directly
protected  void _syncAnnotations(Document doc)
          helper for sync() - never call directly
protected  void _syncAnnotationSets(Document doc, Collection removedSets, Collection addedSets)
          helper for sync() - never call directly
protected  void _syncChangedAnnotations(Document doc, AnnotationSet as, Collection changes)
          helper for sync() - never call directly
protected abstract  void _syncDocumentContent(Document doc)
          helper for sync() - never call directly
protected abstract  void _syncDocumentHeader(Document doc)
          helper for sync() - never call directly
protected abstract  void _syncFeatures(LanguageResource lr)
          helper for sync() - never call directly
protected abstract  void _syncLR(LanguageResource lr)
          helper for sync() NEVER call directly
protected  void _syncRemovedAnnotations(Document doc, AnnotationSet as, Collection changes)
          helper for sync() - never call directly
protected abstract  void _syncRemovedDocumentsFromCorpus(List docLRIDs, Long corpLRID)
          helper for sync() - never call directly
 void addDatastoreListener(DatastoreListener l)
          Registers a new DatastoreListener with this datastore
protected abstract  void addDocumentToCorpus(Long docID, Long corpID)
          adds document to corpus in the database if the document is already part of the corpus nothing changes
 LanguageResource adopt(LanguageResource lr, SecurityInfo secInfo)
          Adopt a resource for persistence.
 void beginTrans()
          starts a transaction note that if u're already in transaction context this will not open nested transaction i.e. many consecutive calls to beginTrans() make no difference if no commit/rollback is made meanwhile
protected  boolean canAccessLR(Long lrID, int mode)
          Checks if the user (identified by the sessionID) has some access (read/write) to the LR
 boolean canReadLR(Object lrID)
          Checks if the user (identified by the sessionID) has read access to the LR
 boolean canWriteLR(Object lrID)
          Checks if the user (identified by the sessionID) has write access to the LR
 void close()
          Close the data store.
 void commitTrans()
          commits transaction note that this will commit all the uncommited calls made so far
 void create()
          Create a new data store.
protected abstract  void createAnnotationSet(Long lrID, AnnotationSet aset)
           
protected  Corpus createCorpus(Corpus corp, SecurityInfo secInfo, boolean newTransPerDocument)
          creates a LR of type Corpus
protected abstract  Long createDoc(Long _lrID, URL _docURL, String _docEncoding, Long _docStartOffset, Long _docEndOffset, Boolean _docIsMarkupAware, Long _corpusID)
           
protected  Document createDocument(Document doc, Long corpusID, SecurityInfo secInfo)
          helper for adopt creates a LR of type Document
protected  Document createDocument(Document doc, SecurityInfo secInfo)
          helper for adopt creates a LR of type Document
protected abstract  void createFeatures(Long entityID, int entityType, FeatureMap features)
           
protected abstract  void createFeaturesBulk(Long entityID, int entityType, FeatureMap features)
           
protected abstract  Long createLR(String lrType, String lrName, SecurityInfo si, Long lrParentID)
           
 void datastoreClosed(CreoleEvent e)
          Called when a DataStore has been closed
 void datastoreCreated(CreoleEvent e)
          Called when a DataStore has been created
 void datastoreOpened(CreoleEvent e)
          Called when a DataStore has been opened
 void delete()
          Delete the data store.
 void delete(String lrClassName, Object lrId)
          Delete a resource from the data store.
protected abstract  void deleteCorpus(Long lrId)
          helper method for delete() never call it directly beause proper events will not be fired
protected abstract  void deleteDocument(Long lrId)
          helper method for delete() never call it directly beause proper events will not be fired
 void deleteSince(Long timestamp)
          not used
protected  int findFeatureType(Object value)
          ---
abstract  List findLrIds(List constraints)
          Get a list of LRs that satisfy some set or restrictions
abstract  List findLrIds(List constraints, String lrType)
          Get a list of LRs that satisfy some set or restrictions and are of a particular type
protected  void fireResourceAdopted(DatastoreEvent e)
           
protected  void fireResourceDeleted(DatastoreEvent e)
           
protected  void fireResourceWritten(DatastoreEvent e)
           
 String getComment()
          Save: synchonise the in-memory image of the LR with the persistent image.
 String getDatabaseID()
          ---
 String getIconName()
          Returns the name of the icon to be used when this datastore is displayed in the GUI
protected  User getLockingUser(LanguageResource lr)
          Releases the exlusive lock on a resource from the persistent store.
protected  User getLockingUser(Long lrID)
          Releases the exlusive lock on a resource from the persistent store.
 LanguageResource getLr(String lrClassName, Object lrPersistenceId)
          Get a resource from the persistent store.
 List getLrIds(String lrType)
          Get a list of the IDs of LRs of a particular type that are present.
 String getLrName(Object lrId)
          Get the name of an LR from its ID.
 List getLrNames(String lrType)
          Get a list of the names of LRs of a particular type that are present.
 List getLrTypes()
          Get a list of the types of LR that are present in the data store.
 String getName()
          Returns the name of this resource
 SecurityInfo getSecurityInfo(LanguageResource lr)
          get security information for LR .
 Session getSession(Session s)
          identify user using this datastore
 String getStorageUrl()
          Get the URL for the underlying storage mechanism.
 boolean isAutoSaving()
          Get the autosaving behaviour of the LR.
 void open()
          Open a connection to the data store.
protected  String readDatabaseID()
          reads the ID of the database every database should have unique string ID
protected abstract  FeatureMap readFeatures(Long entityID, int entityType)
          reads the features of an entity entities are of type LR or Annotation
 void removeDatastoreListener(DatastoreListener l)
          Removes a a previously registered DatastoreListener from the list listeners for this datastore
 void resourceLoaded(CreoleEvent e)
          Called when a new Resource has been loaded into the system
 void resourceRenamed(Resource resource, String oldName, String newName)
          Called when the creole register has renamed a resource.1
 void resourceUnloaded(CreoleEvent e)
          Called when a Resource has been removed from the system
 void rollbackTrans()
          rollsback a transaction
 void setAutoSaving(boolean autoSaving)
          Set method for the autosaving behaviour of the data store.
 void setName(String name)
          Sets the name of this resource
 void setSession(Session s)
          identify user using this datastore
 void setStorageUrl(String storageUrl)
          Set the URL for the underlying storage mechanism.
 void sync(LanguageResource lr)
          Save: synchonise the in-memory image of the LR with the persistent image.
protected  void syncCorpus(Corpus corp)
          helper for sync() - saves a Corpus in the database
protected  void syncDocument(Document doc)
          helper for sync() - saves a Document in the database
 Long timestamp()
          not used
protected  void unloadLR(Long lrID)
          unloads a LR from the GUI
protected abstract  void updateDocumentContent(Long docID, DocumentContent content)
           
 
Methods inherited from class gate.util.AbstractFeatureBearer
getFeatures, setFeatures
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gate.DataStore
lockLr, setSecurityInfo, unlockLr
 
Methods inherited from interface gate.util.FeatureBearer
getFeatures, setFeatures
 

Field Detail

dbSchema

protected String dbSchema

dbType

protected int dbType

datastoreComment

protected String datastoreComment

iconName

protected String iconName

session

protected Session session
security session identifying all access to the datastore


name

protected String name
datastore name?


jdbcConn

protected transient Connection jdbcConn
jdbc connection, all access to the database is made through this connection


ac

protected transient AccessController ac
Security factory that contols access to objects in the datastore the security session is from this factory


dependentResources

protected transient Vector dependentResources
resources that should be sync-ed if datastore is close()-d

Constructor Detail

JDBCDataStore

protected JDBCDataStore()
Do not use this class directly - use one of the subclasses

Method Detail

getComment

public String getComment()
Save: synchonise the in-memory image of the LR with the persistent image.

Specified by:
getComment in interface DataStore

getIconName

public String getIconName()
Returns the name of the icon to be used when this datastore is displayed in the GUI

Specified by:
getIconName in interface DataStore

getLrName

public String getLrName(Object lrId)
                 throws PersistenceException
Get the name of an LR from its ID.

Specified by:
getLrName in interface DataStore
Throws:
PersistenceException

setStorageUrl

public void setStorageUrl(String storageUrl)
                   throws PersistenceException
Set the URL for the underlying storage mechanism.

Specified by:
setStorageUrl in interface DataStore
Throws:
PersistenceException

getStorageUrl

public String getStorageUrl()
Get the URL for the underlying storage mechanism.

Specified by:
getStorageUrl in interface DataStore

create

public void create()
            throws PersistenceException,
                   UnsupportedOperationException
Create a new data store. NOTE: for some data stores creation is an system administrator task; in such cases this method will throw an UnsupportedOperationException.

Specified by:
create in interface DataStore
Throws:
PersistenceException
UnsupportedOperationException

open

public void open()
          throws PersistenceException
Open a connection to the data store.

Specified by:
open in interface DataStore
Throws:
PersistenceException

close

public void close()
           throws PersistenceException
Close the data store.

Specified by:
close in interface DataStore
Throws:
PersistenceException

delete

public void delete()
            throws PersistenceException,
                   UnsupportedOperationException
Delete the data store. NOTE: for some data stores deletion is an system administrator task; in such cases this method will throw an UnsupportedOperationException.

Specified by:
delete in interface DataStore
Throws:
PersistenceException
UnsupportedOperationException

delete

public void delete(String lrClassName,
                   Object lrId)
            throws PersistenceException,
                   SecurityException
Delete a resource from the data store.

Specified by:
delete in interface DataStore
Parameters:
lrId - a data-store specific unique identifier for the resource
lrClassName - class name of the type of resource
Throws:
PersistenceException
SecurityException

sync

public void sync(LanguageResource lr)
          throws PersistenceException,
                 SecurityException
Save: synchonise the in-memory image of the LR with the persistent image.

Specified by:
sync in interface DataStore
Throws:
PersistenceException
SecurityException

setAutoSaving

public void setAutoSaving(boolean autoSaving)
                   throws UnsupportedOperationException,
                          PersistenceException
Set method for the autosaving behaviour of the data store. NOTE: many types of datastore have no auto-save function, in which case this will throw an UnsupportedOperationException.

Specified by:
setAutoSaving in interface DataStore
Throws:
UnsupportedOperationException
PersistenceException

isAutoSaving

public boolean isAutoSaving()
Get the autosaving behaviour of the LR.

Specified by:
isAutoSaving in interface DataStore

adopt

public LanguageResource adopt(LanguageResource lr,
                              SecurityInfo secInfo)
                       throws PersistenceException,
                              SecurityException
Adopt a resource for persistence.

Specified by:
adopt in interface DataStore
Throws:
PersistenceException
SecurityException

_adopt

protected LanguageResource _adopt(LanguageResource lr,
                                  SecurityInfo secInfo,
                                  boolean openNewTrans)
                           throws PersistenceException,
                                  SecurityException
Throws:
PersistenceException
SecurityException

getLrTypes

public List getLrTypes()
                throws PersistenceException
Get a list of the types of LR that are present in the data store.

Specified by:
getLrTypes in interface DataStore
Throws:
PersistenceException

getLrIds

public List getLrIds(String lrType)
              throws PersistenceException
Get a list of the IDs of LRs of a particular type that are present.

Specified by:
getLrIds in interface DataStore
Throws:
PersistenceException

getLrNames

public List getLrNames(String lrType)
                throws PersistenceException
Get a list of the names of LRs of a particular type that are present.

Specified by:
getLrNames in interface DataStore
Throws:
PersistenceException

canReadLR

public boolean canReadLR(Object lrID)
                  throws PersistenceException,
                         SecurityException
Checks if the user (identified by the sessionID) has read access to the LR

Specified by:
canReadLR in interface DataStore
Throws:
PersistenceException
SecurityException

canWriteLR

public boolean canWriteLR(Object lrID)
                   throws PersistenceException,
                          SecurityException
Checks if the user (identified by the sessionID) has write access to the LR

Specified by:
canWriteLR in interface DataStore
Throws:
PersistenceException
SecurityException

canAccessLR

protected boolean canAccessLR(Long lrID,
                              int mode)
                       throws PersistenceException,
                              SecurityException
Checks if the user (identified by the sessionID) has some access (read/write) to the LR

Throws:
PersistenceException
SecurityException

beginTrans

public void beginTrans()
                throws PersistenceException,
                       UnsupportedOperationException
starts a transaction note that if u're already in transaction context this will not open nested transaction i.e. many consecutive calls to beginTrans() make no difference if no commit/rollback is made meanwhile

Specified by:
beginTrans in interface DatabaseDataStore
Throws:
PersistenceException
UnsupportedOperationException

commitTrans

public void commitTrans()
                 throws PersistenceException,
                        UnsupportedOperationException
commits transaction note that this will commit all the uncommited calls made so far

Specified by:
commitTrans in interface DatabaseDataStore
Throws:
PersistenceException
UnsupportedOperationException

rollbackTrans

public void rollbackTrans()
                   throws PersistenceException,
                          UnsupportedOperationException
rollsback a transaction

Specified by:
rollbackTrans in interface DatabaseDataStore
Throws:
PersistenceException
UnsupportedOperationException

timestamp

public Long timestamp()
               throws PersistenceException
not used

Specified by:
timestamp in interface DatabaseDataStore
Throws:
PersistenceException

deleteSince

public void deleteSince(Long timestamp)
                 throws PersistenceException
not used

Specified by:
deleteSince in interface DatabaseDataStore
Throws:
PersistenceException

setName

public void setName(String name)
Sets the name of this resource

Specified by:
setName in interface NameBearer

getName

public String getName()
Returns the name of this resource

Specified by:
getName in interface NameBearer

findFeatureType

protected int findFeatureType(Object value)
---


getDatabaseID

public String getDatabaseID()
---

Specified by:
getDatabaseID in interface DatabaseDataStore

readDatabaseID

protected String readDatabaseID()
                         throws PersistenceException
reads the ID of the database every database should have unique string ID

Throws:
PersistenceException

removeDatastoreListener

public void removeDatastoreListener(DatastoreListener l)
Removes a a previously registered DatastoreListener from the list listeners for this datastore

Specified by:
removeDatastoreListener in interface DataStore

addDatastoreListener

public void addDatastoreListener(DatastoreListener l)
Registers a new DatastoreListener with this datastore

Specified by:
addDatastoreListener in interface DataStore

fireResourceAdopted

protected void fireResourceAdopted(DatastoreEvent e)

fireResourceDeleted

protected void fireResourceDeleted(DatastoreEvent e)

fireResourceWritten

protected void fireResourceWritten(DatastoreEvent e)

resourceLoaded

public void resourceLoaded(CreoleEvent e)
Description copied from interface: CreoleListener
Called when a new Resource has been loaded into the system

Specified by:
resourceLoaded in interface CreoleListener

resourceRenamed

public void resourceRenamed(Resource resource,
                            String oldName,
                            String newName)
Description copied from interface: CreoleListener
Called when the creole register has renamed a resource.1

Specified by:
resourceRenamed in interface CreoleListener

resourceUnloaded

public void resourceUnloaded(CreoleEvent e)
Description copied from interface: CreoleListener
Called when a Resource has been removed from the system

Specified by:
resourceUnloaded in interface CreoleListener

datastoreOpened

public void datastoreOpened(CreoleEvent e)
Description copied from interface: CreoleListener
Called when a DataStore has been opened

Specified by:
datastoreOpened in interface CreoleListener

datastoreCreated

public void datastoreCreated(CreoleEvent e)
Description copied from interface: CreoleListener
Called when a DataStore has been created

Specified by:
datastoreCreated in interface CreoleListener

datastoreClosed

public void datastoreClosed(CreoleEvent e)
Description copied from interface: CreoleListener
Called when a DataStore has been closed

Specified by:
datastoreClosed in interface CreoleListener

setSession

public void setSession(Session s)
                throws SecurityException
identify user using this datastore

Specified by:
setSession in interface DataStore
Throws:
SecurityException

getSession

public Session getSession(Session s)
                   throws SecurityException
identify user using this datastore

Specified by:
getSession in interface DataStore
Throws:
SecurityException

findLrIds

public abstract List findLrIds(List constraints)
                        throws PersistenceException
Get a list of LRs that satisfy some set or restrictions

Specified by:
findLrIds in interface DataStore
Throws:
PersistenceException

findLrIds

public abstract List findLrIds(List constraints,
                               String lrType)
                        throws PersistenceException
Get a list of LRs that satisfy some set or restrictions and are of a particular type

Specified by:
findLrIds in interface DataStore
Throws:
PersistenceException

getSecurityInfo

public SecurityInfo getSecurityInfo(LanguageResource lr)
                             throws PersistenceException
get security information for LR .

Specified by:
getSecurityInfo in interface DataStore
Throws:
PersistenceException

createCorpus

protected Corpus createCorpus(Corpus corp,
                              SecurityInfo secInfo,
                              boolean newTransPerDocument)
                       throws PersistenceException,
                              SecurityException
creates a LR of type Corpus

Throws:
PersistenceException
SecurityException

createDocument

protected Document createDocument(Document doc,
                                  SecurityInfo secInfo)
                           throws PersistenceException,
                                  SecurityException
helper for adopt creates a LR of type Document

Throws:
PersistenceException
SecurityException

createDocument

protected Document createDocument(Document doc,
                                  Long corpusID,
                                  SecurityInfo secInfo)
                           throws PersistenceException,
                                  SecurityException
helper for adopt creates a LR of type Document

Throws:
PersistenceException
SecurityException

createLR

protected abstract Long createLR(String lrType,
                                 String lrName,
                                 SecurityInfo si,
                                 Long lrParentID)
                          throws PersistenceException,
                                 SecurityException
Throws:
PersistenceException
SecurityException

createDoc

protected abstract Long createDoc(Long _lrID,
                                  URL _docURL,
                                  String _docEncoding,
                                  Long _docStartOffset,
                                  Long _docEndOffset,
                                  Boolean _docIsMarkupAware,
                                  Long _corpusID)
                           throws PersistenceException
Throws:
PersistenceException

updateDocumentContent

protected abstract void updateDocumentContent(Long docID,
                                              DocumentContent content)
                                       throws PersistenceException
Throws:
PersistenceException

createAnnotationSet

protected abstract void createAnnotationSet(Long lrID,
                                            AnnotationSet aset)
                                     throws PersistenceException
Throws:
PersistenceException

createFeaturesBulk

protected abstract void createFeaturesBulk(Long entityID,
                                           int entityType,
                                           FeatureMap features)
                                    throws PersistenceException
Throws:
PersistenceException

createFeatures

protected abstract void createFeatures(Long entityID,
                                       int entityType,
                                       FeatureMap features)
                                throws PersistenceException
Throws:
PersistenceException

_sync

protected void _sync(LanguageResource lr,
                     boolean openNewTrans)
              throws PersistenceException,
                     SecurityException
Save: synchonise the in-memory image of the LR with the persistent image.

Throws:
PersistenceException
SecurityException

getLockingUser

protected User getLockingUser(LanguageResource lr)
                       throws PersistenceException,
                              SecurityException
Releases the exlusive lock on a resource from the persistent store.

Throws:
PersistenceException
SecurityException

getLockingUser

protected User getLockingUser(Long lrID)
                       throws PersistenceException,
                              SecurityException
Releases the exlusive lock on a resource from the persistent store.

Throws:
PersistenceException
SecurityException

syncCorpus

protected void syncCorpus(Corpus corp)
                   throws PersistenceException,
                          SecurityException
helper for sync() - saves a Corpus in the database

Throws:
PersistenceException
SecurityException

syncDocument

protected void syncDocument(Document doc)
                     throws PersistenceException,
                            SecurityException
helper for sync() - saves a Document in the database

Throws:
PersistenceException
SecurityException

_syncLR

protected abstract void _syncLR(LanguageResource lr)
                         throws PersistenceException,
                                SecurityException
helper for sync() NEVER call directly

Throws:
PersistenceException
SecurityException

_syncDocumentHeader

protected abstract void _syncDocumentHeader(Document doc)
                                     throws PersistenceException
helper for sync() - never call directly

Throws:
PersistenceException

_syncDocumentContent

protected abstract void _syncDocumentContent(Document doc)
                                      throws PersistenceException
helper for sync() - never call directly

Throws:
PersistenceException

_syncFeatures

protected abstract void _syncFeatures(LanguageResource lr)
                               throws PersistenceException
helper for sync() - never call directly

Throws:
PersistenceException

_syncAnnotationSets

protected void _syncAnnotationSets(Document doc,
                                   Collection removedSets,
                                   Collection addedSets)
                            throws PersistenceException
helper for sync() - never call directly

Throws:
PersistenceException

_syncAnnotations

protected void _syncAnnotations(Document doc)
                         throws PersistenceException
helper for sync() - never call directly

Throws:
PersistenceException

_syncAddedAnnotations

protected void _syncAddedAnnotations(Document doc,
                                     AnnotationSet as,
                                     Collection changes)
                              throws PersistenceException
helper for sync() - never call directly

Throws:
PersistenceException

_syncRemovedAnnotations

protected void _syncRemovedAnnotations(Document doc,
                                       AnnotationSet as,
                                       Collection changes)
                                throws PersistenceException
helper for sync() - never call directly

Throws:
PersistenceException

_syncChangedAnnotations

protected void _syncChangedAnnotations(Document doc,
                                       AnnotationSet as,
                                       Collection changes)
                                throws PersistenceException
helper for sync() - never call directly

Throws:
PersistenceException

getLr

public LanguageResource getLr(String lrClassName,
                              Object lrPersistenceId)
                       throws PersistenceException,
                              SecurityException
Get a resource from the persistent store. Don't use this method - use Factory.createResource with DataStore and DataStoreInstanceId parameters set instead.

Specified by:
getLr in interface DataStore
Throws:
PersistenceException
SecurityException

readFeatures

protected abstract FeatureMap readFeatures(Long entityID,
                                           int entityType)
                                    throws PersistenceException
reads the features of an entity entities are of type LR or Annotation

Throws:
PersistenceException

deleteDocument

protected abstract void deleteDocument(Long lrId)
                                throws PersistenceException
helper method for delete() never call it directly beause proper events will not be fired

Throws:
PersistenceException

deleteCorpus

protected abstract void deleteCorpus(Long lrId)
                              throws PersistenceException
helper method for delete() never call it directly beause proper events will not be fired

Throws:
PersistenceException

unloadLR

protected void unloadLR(Long lrID)
                 throws GateException
unloads a LR from the GUI

Throws:
GateException

_syncRemovedDocumentsFromCorpus

protected abstract void _syncRemovedDocumentsFromCorpus(List docLRIDs,
                                                        Long corpLRID)
                                                 throws PersistenceException
helper for sync() - never call directly

Throws:
PersistenceException

addDocumentToCorpus

protected abstract void addDocumentToCorpus(Long docID,
                                            Long corpID)
                                     throws PersistenceException,
                                            SecurityException
adds document to corpus in the database if the document is already part of the corpus nothing changes

Throws:
PersistenceException
SecurityException

GATE
Version 3.1-2270