it.polito.elite.doseWS.wrappers
Class DBWrapperImpl

java.lang.Object
  extended byit.polito.elite.doseWS.wrappers.DBWrapperImpl
All Implemented Interfaces:
DBWrapper

public class DBWrapperImpl
extends java.lang.Object
implements DBWrapper

This class implements DBWrapper
configuration parameters in config.conf

 dbDriver=COM.cloudscape.core.RmiJdbcDriver
 dbURI=jdbc:cloudscape:rmi:jGuru
 dbUser=sa
 dbPassword=admin


Field Summary
static int EAGAIN
          Operation failed for external causes
static int EBADSQL
          SQL-Level error (ie.
static int ENOENT
          Required key not found
static int EPARAM
          Wrong parameter
 
Constructor Summary
DBWrapperImpl(java.lang.String dbDriver, java.lang.String dbURI, java.lang.String dbUser, java.lang.String dbPassword)
          An Implementation of DBWrapper
 
Method Summary
 int countAnnotations()
          gives back the total number of annotations stored in the database
 int countAnnotations(java.lang.String topicURI)
          returns the number of annotation (unexpanded) for a given topic
 java.lang.String dbStatus()
          last database error
 java.lang.Integer deleteAuthor(java.lang.Integer idauthor)
          delete an author from the database given the key (and ALL the annotations synset that use it)
 java.lang.Integer deleteAuthor(java.lang.String author)
          delete an author from the database given the name (and ALL the annotations synset that use it)
 int deleteSpectrum(java.lang.String uri, java.lang.String xPath, java.lang.String author, java.lang.String type)
          delete an annotations block
 java.lang.Integer deleteSynset(java.lang.Integer i)
          Elimina un Synset, dato topicUri e linguaggio nella tabella sysnset
 java.lang.Integer deleteSynset(java.lang.String topicURI, java.lang.String lang)
          Elimina un Synset, dato topicUri e linguaggio nella tabella sysnset
 java.lang.Integer deleteSynset(Synset S)
          elimina un synset, data la chiave
 java.lang.Integer deleteTopic(java.lang.Integer idtopic)
          delete a topic, given the topic key
 java.lang.Integer deleteTopic(java.lang.String topic)
          delete a topic from the database given the URI (and ALL the annotations synset that use it)
 java.lang.Integer deleteType(java.lang.Integer idtype)
          delete an annotation type from the database given the key (and ALL the annotations synset that use it)
 java.lang.Integer deleteType(java.lang.String anntype)
          delete an annotation type from the database given the name (and ALL the annotations synset that use it)
 int deleteXSpectrum(java.lang.String uri, java.lang.String xPath, java.lang.String author, java.lang.String type)
          delete an expanded annotations block
 Synset[] getAnySynset(java.lang.String lang)
          Get all synset for a giveb language this is not optimized: will call multiple times getSynset
 boolean getCheckann()
          reads thre checkann boolean value
 Spectrum getSpectrum(java.lang.String uri, java.lang.String xPath, java.lang.String author, java.lang.String type)
          gives back the block of annotations, given fragment (author and type are optional)
 Synset getSynset(java.lang.String TopicURI, java.lang.String lang)
          Get a Sysnset given URI and language
 TopicCoverage getTopicsCoverage()
          For being able to implement the political of self-management of the conceptual cover of annotations it is necessary to introduce a method getTopicsCoverage.
 Spectrum getXSpectrum(java.lang.String uri, java.lang.String xPath, java.lang.String author, java.lang.String type)
          gives back the block of refined annotations, given fragment (author and type are optional)
 java.lang.Integer insertAuthor(java.lang.String author)
          Insert an author
 int insertSpectrum(Spectrum spectrum)
          Insert a block of annotations for a Spectrum
 java.lang.Integer insertSynset(java.lang.String topicURI, java.lang.String lang)
          Inssert a row into SynsetTable
 java.lang.Integer insertTopic(java.lang.String topic)
          insert a topic
 java.lang.Integer insertType(java.lang.String anntype)
          Insert an annotation type
 int insertXSpectrum(Spectrum spectrum)
          Insert a block of annotations for an expanded Spectrum
 java.lang.Integer loadSynset(Synset S)
          Carica un Synset nuovo.
 java.util.Vector searchXByTopic(java.util.Vector topicURIs, int level)
          give back the spectra that are compatible with the one of the given topicURI, ie.
 java.lang.Integer selectAuthor(java.lang.String author)
          Returns the key of the annotation author, null if not found
 java.lang.Integer selectSynset(java.lang.String topicURI, java.lang.String lang)
          Cerca una riga nella tabella sysnset
 java.lang.Integer selectTopic(java.lang.String topic)
          seleziona un topic dal database
 java.lang.Integer selectType(java.lang.String type)
          Returns the key of the annotation type, null if not found
 void setCheckann(boolean b)
          Set the checkann flag.
 int updateSpectrum(Spectrum spectrum)
          Updates a spectrum: the actual behaviour is to delete the existing specrum, then inset the new specrum
 java.lang.Integer updateSynset(Synset S, boolean addMode)
          Updates a Synset.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EBADSQL

public static int EBADSQL
SQL-Level error (ie. syntax errors in SQL, bad parameters...)


ENOENT

public static int ENOENT
Required key not found


EAGAIN

public static int EAGAIN
Operation failed for external causes


EPARAM

public static int EPARAM
Wrong parameter

Constructor Detail

DBWrapperImpl

public DBWrapperImpl(java.lang.String dbDriver,
                     java.lang.String dbURI,
                     java.lang.String dbUser,
                     java.lang.String dbPassword)
              throws java.lang.Exception
An Implementation of DBWrapper

Parameters:
dbDriver - JDBC driver to use
dbURI - DBMS URI to use
dbUser - DBMS user
dbPassword - DBMS password
Throws:
java.lang.Exception - in error
Method Detail

setCheckann

public void setCheckann(boolean b)
Set the checkann flag. If set to true, insering nuplicated annotation values will succeed (oder weights will be mantained) else will be generated an exception This behaviour is valid only if there is a RDBMS under

Parameters:
b - the checkann value

getCheckann

public boolean getCheckann()
reads thre checkann boolean value

Returns:
the value of checkann

insertSpectrum

public int insertSpectrum(Spectrum spectrum)
                   throws java.lang.Exception
Insert a block of annotations for a Spectrum

Specified by:
insertSpectrum in interface DBWrapper
Parameters:
spectrum - The specrum to be inserted
Returns:
<0 in error, otherwise the number of annotations
Throws:
java.lang.Exception - for serious errors

insertXSpectrum

public int insertXSpectrum(Spectrum spectrum)
                    throws java.lang.Exception
Insert a block of annotations for an expanded Spectrum

Specified by:
insertXSpectrum in interface DBWrapper
Parameters:
spectrum - The specrum to be inserted
Returns:
<0 in error, otherwise the number of annotations
Throws:
java.lang.Exception - for serious errors

getSpectrum

public Spectrum getSpectrum(java.lang.String uri,
                            java.lang.String xPath,
                            java.lang.String author,
                            java.lang.String type)
gives back the block of annotations, given fragment (author and type are optional)

Specified by:
getSpectrum in interface DBWrapper
Parameters:
uri - fragment's URI
xPath - fragment's xPath
author - fragment's author
type - e fragment's type
Returns:
the requested Spectrum

getXSpectrum

public Spectrum getXSpectrum(java.lang.String uri,
                             java.lang.String xPath,
                             java.lang.String author,
                             java.lang.String type)
gives back the block of refined annotations, given fragment (author and type are optional)

Specified by:
getXSpectrum in interface DBWrapper
Parameters:
uri - fragment's URI
xPath - fragment's xPath
author - fragment's author
type - e fragment's type
Returns:
the requested Spectrum

updateSpectrum

public int updateSpectrum(Spectrum spectrum)
                   throws java.lang.Exception
Updates a spectrum: the actual behaviour is to delete the existing specrum, then inset the new specrum

Specified by:
updateSpectrum in interface DBWrapper
Parameters:
spectrum - the Spectrum that will be updated
Returns:
Number of spectrum element inseted or a negative number in error
Throws:
java.lang.Exception - In case of error.

deleteSpectrum

public int deleteSpectrum(java.lang.String uri,
                          java.lang.String xPath,
                          java.lang.String author,
                          java.lang.String type)
delete an annotations block

Specified by:
deleteSpectrum in interface DBWrapper
Parameters:
uri - annotation's URI
xPath - annotation's xpath
author - annotation's author
type - annotation's type
Returns:
< 0 in case of error > 0 in succesful completion

deleteXSpectrum

public int deleteXSpectrum(java.lang.String uri,
                           java.lang.String xPath,
                           java.lang.String author,
                           java.lang.String type)
delete an expanded annotations block

Specified by:
deleteXSpectrum in interface DBWrapper
Parameters:
uri - annotation's URI
xPath - annotation's xpath
author - annotation's author
type - annotation's type
Returns:
< 0 in case of error > 0 in succesful completion

dbStatus

public java.lang.String dbStatus()
last database error

Specified by:
dbStatus in interface DBWrapper
Returns:
A string with the description of last database error

searchXByTopic

public java.util.Vector searchXByTopic(java.util.Vector topicURIs,
                                       int level)
give back the spectra that are compatible with the one of the given topicURI, ie. some or all of the values are present on the given topicURI spectra

Specified by:
searchXByTopic in interface DBWrapper
Parameters:
topicURIs - vector of tpocuri
level - number of occoureances respect the given fragment. A spectrum to be considered valid shoul have at least this number of occorrences. If level=1 will make OR of the terms. if level=topicURIs.lenght() will make an AND of terms
Returns:
Spectrum Vector of suitable data

selectTopic

public java.lang.Integer selectTopic(java.lang.String topic)
                              throws java.lang.Exception
seleziona un topic dal database

Specified by:
selectTopic in interface DBWrapper
Parameters:
topic - il topic da cercare (es: http://www.www#001/
Returns:
null se il topic non esiste, oppure l'idtopic se esiste
Throws:
java.lang.Exception - In caso di errore genera una Exception

selectType

public java.lang.Integer selectType(java.lang.String type)
                             throws java.lang.Exception
Returns the key of the annotation type, null if not found

Specified by:
selectType in interface DBWrapper
Parameters:
type - string representing the annotation type
Returns:
the key of the type
Throws:
java.lang.Exception - see selectGeneric

selectAuthor

public java.lang.Integer selectAuthor(java.lang.String author)
                               throws java.lang.Exception
Returns the key of the annotation author, null if not found

Specified by:
selectAuthor in interface DBWrapper
Parameters:
author - the author sting
Returns:
the author key
Throws:
java.lang.Exception - see selectGeneric

insertAuthor

public java.lang.Integer insertAuthor(java.lang.String author)
                               throws java.lang.Exception
Insert an author

Specified by:
insertAuthor in interface DBWrapper
Parameters:
author - the author name
Returns:
the key of the inserted row, or null if the operation fails
Throws:
java.lang.Exception - see insertGeneric

insertType

public java.lang.Integer insertType(java.lang.String anntype)
                             throws java.lang.Exception
Insert an annotation type

Specified by:
insertType in interface DBWrapper
Parameters:
anntype - the annotation type name
Returns:
the key of the inserted row, or null if the operation fails
Throws:
java.lang.Exception - see insertGeneric

insertTopic

public java.lang.Integer insertTopic(java.lang.String topic)
                              throws java.lang.Exception
insert a topic

Specified by:
insertTopic in interface DBWrapper
Parameters:
topic - the topic to insert (es: http://www.www#001/)
Returns:
null if the operation fails, the topic key otherwise
Throws:
java.lang.Exception - see insertGeneric

insertSynset

public java.lang.Integer insertSynset(java.lang.String topicURI,
                                      java.lang.String lang)
                               throws java.lang.Exception
Inssert a row into SynsetTable

Specified by:
insertSynset in interface DBWrapper
Parameters:
topicURI - Synset's topicURI
lang - synset's lagnuage (two characters)
Returns:
null in error, otherwise an integer representing the value of the key in the table (>0)
Throws:
java.lang.Exception - in error

selectSynset

public java.lang.Integer selectSynset(java.lang.String topicURI,
                                      java.lang.String lang)
                               throws java.lang.Exception
Cerca una riga nella tabella sysnset

Specified by:
selectSynset in interface DBWrapper
Parameters:
topicURI - URI referenced by the synset (must exist before insering the sysnset)
lang - two-charachet rapresentation of the synset language
Returns:
null if the operation fail, othewise the key of the row inserted
Throws:
java.lang.Exception - see selectGeneric

deleteSynset

public java.lang.Integer deleteSynset(java.lang.String topicURI,
                                      java.lang.String lang)
                               throws java.lang.Exception
Elimina un Synset, dato topicUri e linguaggio nella tabella sysnset

Specified by:
deleteSynset in interface DBWrapper
Parameters:
topicURI - l'uri a cui si riferisce il synset
lang - lingua del synset
Returns:
null in caso di errore altrimenti il valore della chiave in caso di successo
Throws:
java.lang.Exception - si` spara un'eccezione

deleteSynset

public java.lang.Integer deleteSynset(java.lang.Integer i)
                               throws java.lang.Exception
Elimina un Synset, dato topicUri e linguaggio nella tabella sysnset

Specified by:
deleteSynset in interface DBWrapper
Parameters:
i - chiave da eliminare
Returns:
null in caso di errore altrimenti il valore della chiave in caso di successo
Throws:
java.lang.Exception - eccezione in caso di errore

deleteSynset

public java.lang.Integer deleteSynset(Synset S)
                               throws java.lang.Exception
elimina un synset, data la chiave

Specified by:
deleteSynset in interface DBWrapper
Parameters:
S - da eliminare (ATTENZIONE: non elimina solo quello che si trova nelle occour ....)
Returns:
null in caso di errore
Throws:
java.lang.Exception - In caso di problemi al DB spara un'eccezione

loadSynset

public java.lang.Integer loadSynset(Synset S)
                             throws java.lang.Exception
Carica un Synset nuovo. Fallisce in caso di mword gia` presenti (ma non in caso di aggiunta di mword diverse)

Specified by:
loadSynset in interface DBWrapper
Parameters:
S - Synset da inserire
Returns:
null, in caso di errore
Throws:
java.lang.Exception - In caso di problemi al DB spara un'eccezione

updateSynset

public java.lang.Integer updateSynset(Synset S,
                                      boolean addMode)
                               throws java.lang.Exception
Updates a Synset.

Specified by:
updateSynset in interface DBWrapper
Parameters:
addMode - false new values will overwrite older ones, true the new occouurence wil be added to the old one (weight will be overwritten anyway)
S - Synset to insert/update
Returns:
null for errors, otherwise
Throws:
java.lang.Exception - In error

getSynset

public Synset getSynset(java.lang.String TopicURI,
                        java.lang.String lang)
                 throws java.lang.Exception
Get a Sysnset given URI and language

Parameters:
TopicURI - the synset's topic
lang - the synset's language
Returns:
the Synset requested
Throws:
java.lang.Exception - in error

getAnySynset

public Synset[] getAnySynset(java.lang.String lang)
                      throws java.lang.Exception
Get all synset for a giveb language this is not optimized: will call multiple times getSynset

Parameters:
lang - the language requested
Returns:
an array with all the synset for the given language
Throws:
java.lang.Exception - in error

countAnnotations

public int countAnnotations(java.lang.String topicURI)
                     throws java.lang.Exception
returns the number of annotation (unexpanded) for a given topic

Specified by:
countAnnotations in interface DBWrapper
Parameters:
topicURI - the topicuri to search
Returns:
the number of annotstion for the given topicuri
Throws:
java.lang.Exception - in error

countAnnotations

public int countAnnotations()
                     throws java.lang.Exception
gives back the total number of annotations stored in the database

Specified by:
countAnnotations in interface DBWrapper
Returns:
the total number of annotation
Throws:
java.lang.Exception - in error

deleteAuthor

public java.lang.Integer deleteAuthor(java.lang.String author)
                               throws java.lang.Exception
delete an author from the database given the name (and ALL the annotations synset that use it)

Specified by:
deleteAuthor in interface DBWrapper
Parameters:
author - the author name to delete
Returns:
see deleteGeneric
Throws:
java.lang.Exception - see deleteGeneric

deleteAuthor

public java.lang.Integer deleteAuthor(java.lang.Integer idauthor)
                               throws java.lang.Exception
delete an author from the database given the key (and ALL the annotations synset that use it)

Specified by:
deleteAuthor in interface DBWrapper
Parameters:
idauthor - the author to delete
Returns:
null in error else the number of topic deleted (1)
Throws:
java.lang.Exception - in error

deleteType

public java.lang.Integer deleteType(java.lang.Integer idtype)
                             throws java.lang.Exception
delete an annotation type from the database given the key (and ALL the annotations synset that use it)

Specified by:
deleteType in interface DBWrapper
Parameters:
idtype - the annotation type to delete
Returns:
null in error else the number of annotations deleted (1)
Throws:
java.lang.Exception - in error

deleteType

public java.lang.Integer deleteType(java.lang.String anntype)
                             throws java.lang.Exception
delete an annotation type from the database given the name (and ALL the annotations synset that use it)

Specified by:
deleteType in interface DBWrapper
Parameters:
anntype - the annotation type to delete
Returns:
see deleteGeneric
Throws:
java.lang.Exception - see deleteGeneric

deleteTopic

public java.lang.Integer deleteTopic(java.lang.Integer idtopic)
                              throws java.lang.Exception
delete a topic, given the topic key

Specified by:
deleteTopic in interface DBWrapper
Parameters:
idtopic - the topic to delete
Returns:
see deleteGeneric
Throws:
java.lang.Exception - see deleteGeneric

deleteTopic

public java.lang.Integer deleteTopic(java.lang.String topic)
                              throws java.lang.Exception
delete a topic from the database given the URI (and ALL the annotations synset that use it)

Specified by:
deleteTopic in interface DBWrapper
Parameters:
topic - the topic to delete
Returns:
null in error else the number of topic deleted (1)
Throws:
java.lang.Exception - in error

getTopicsCoverage

public TopicCoverage getTopicsCoverage()
                                throws java.lang.Exception
For being able to implement the political of self-management of the conceptual cover of annotations it is necessary to introduce a method getTopicsCoverage.

Specified by:
getTopicsCoverage in interface DBWrapper
Returns:
the object requested
Throws:
java.lang.Exception - in error case