edu.northwestern.at.wordhoard.model
Class PersistenceManager

java.lang.Object
  extended by edu.northwestern.at.utils.db.hibernate.HibernatePersistenceManager
      extended by edu.northwestern.at.wordhoard.model.PersistenceManager

public class PersistenceManager
extends HibernatePersistenceManager

WordHoard persistence manager.

The "getxxx" and "findxxx" methods fetch objects and collections of objects by various criteria. They are implemented using Hibernate queries, which in turn become SQL select statements.


Field Summary
 
Fields inherited from class edu.northwestern.at.utils.db.hibernate.HibernatePersistenceManager
JDBC_BATCH_SIZE, session, sessionFactory, stackTracesEnabled, t, threadPM
 
Constructor Summary
PersistenceManager()
          Creates a new persistence manager.
 
Method Summary
 java.lang.Object clone(PersistentObject obj)
          Clones an object.
static void closePM()
          Close persistence manager for the current thread.
 java.util.Collection findAuthorsByNamePrefix(java.lang.String prefix)
          Finds authors by name prefix.
 java.util.Collection findLemmasByTagPrefix(java.lang.String prefix, Corpus corpus)
          Finds lemmas by tag prefix.
 java.util.Collection findSpeakerNamesbyPrefix(java.lang.String prefix, Corpus corpus)
          Finds speaker names by prefix.
 Word findWord(WorkPart workPart, int lineIndex, int startOffset, int endOffset)
          Finds a word in a work part.
static java.lang.StringBuffer generateInPhrase(java.lang.String objectName, java.util.Collection objects)
          Generates "item in (:items)" query phrase.
static java.lang.StringBuffer generateInPhrase(java.lang.String objectName, PersistentObject[] objects)
          Generates "item in (:items)" query phrase.
static java.lang.StringBuffer generateInPhrase2(java.lang.String objectName, java.util.Collection objects)
          Generates "item in (:items)" query phrase.
 java.util.Collection getAllAuthors()
          Gets all the authors.
 java.util.Collection getAllAuthors(Corpus corpus)
          Gets all the authors.
 java.util.Collection getAllCorpora()
          Gets all the corpora.
 java.util.Collection getAllLemmas()
          Gets all the lemmas.
 java.util.Collection getAllLemPos()
          Gets all the LemPos objects.
 java.util.Collection getAllMajorWordClasses()
          Gets all the major word classes.
 java.util.Collection getAllMetricalShapes()
          Gets all the metrical shapes.
 java.util.Collection getAllPos()
          Gets all the parts of speech.
 java.util.Collection getAllWordClasses()
          Gets all the word classes.
 java.util.Collection getAllWorkParts()
          Gets all the work parts.
 java.util.Collection getAllWorks()
          Gets all the works.
 AnnotationCategory getAnnotationCategoryByName(java.lang.String name)
          Gets an annotation category by name.
 java.util.Collection getAnnotationsForWorkPart(WorkPart workPart)
          Gets the annotations for a work part.
 Author getAuthorByName(java.lang.String name)
          Gets an author by name.
 java.util.Collection getColocates(java.util.Collection words, int distance)
          Gets colocates for a collection of words.
 Corpus getCorpusByTag(java.lang.String tag)
          Gets a corpus by tag.
 Lemma getLemmaByTag(java.lang.String tag)
          Gets a lemma by tag.
 LemmaCorpusCounts getLemmaCorpusCounts(Lemma lemma, Corpus corpus)
          Gets lemma/corpus counts.
 java.util.Collection getLemmaPosSpellingCounts(Lemma lemma, Corpus corpus)
          Gets lemma/pos/spelling counts.
 LemmaWorkCounts getLemmaWorkCounts(Lemma lemma, Work work)
          Gets lemma/work counts.
 java.util.Collection getLexicon(Corpus corpus)
          Gets the lexicon for a corpus.
 Line getLineByTag(java.lang.String tag)
          Gets a line by tag.
 java.util.Collection getLinesInWork(Work work)
          Gets the lines in a work.
 java.util.Collection getLinesInWorkPart(WorkPart workPart)
          Gets the lines in a work part.
static PersistenceManager getPM()
          Gets a persistence manager for the current thread.
 Word getWordByTag(java.lang.String tag)
          Gets a word by tag.
 java.util.Collection getWordsInWork(Work work)
          Gets the words in a work.
 java.util.Collection getWordsInWorkPart(WorkPart workPart)
          Gets the words in a work part.
 java.util.Collection getWordsInWorkPartWithPreloading(WorkPart workPart)
          Gets the words in a work part with preloading.
 WorkPart getWorkPartByTag(java.lang.String tag)
          Gets a work part by tag.
 java.util.Collection getWorkParts(Work work)
          Gets all the work parts for a work.
 WorkPart[] getWorkPartsByTag(java.util.Collection tags)
          Gets work parts by their tags.
static void init(boolean cache2)
          Initializes Hibernate for WordHoard using default properties file.
static void init(java.lang.String url, java.lang.String username, java.lang.String password, boolean cache2)
          Initializes Hibernate for WordHoard using specified parameters.
 void preloadAdjacentInfo(java.util.Collection words, boolean preceding)
          Preloads adjacent words information.
 void preloadConcordanceInfo(java.util.Collection words)
          Preloads concordance information.
 java.util.List searchLemmata(SearchCriteriaLemmaSearch sq)
          Searches for lemmmata.
 java.util.List searchWords(SearchCriteria sq)
          Searches for words.
 java.util.List searchWorks(SearchWorkCriteria sq)
          Searches for works.
 
Methods inherited from class edu.northwestern.at.utils.db.hibernate.HibernatePersistenceManager
begin, clear, close, closePM, commit, contains, countQuery, delete, delete, deleteViaQuery, deleteViaQuery, deleteViaSQL, doClear, doContains, doCountQuery, doDelete, doDelete, doEvict, doEvict, doGet, doInsertViaSQL, doLoad, doQuery, doQuery, doQuery, doQuery, doQuery, doQuery, doRefresh, doSave, doSave, doScrollableQuery, doScrollableQuery, doScrollableQuery, doScrollableQuery, doScrollableQuery, doUpdate, doUpdate, enableStackTraces, evict, evict, flush, get, getBatchSize, getConnection, getConnectionProvider, getHPM, getSession, init, init, init, init, insertViaSQL, load, performBatchInserts, query, query, query, query, query, refresh, rollback, save, save, scrollableQuery, scrollableQuery, scrollableQuery, scrollableQuery, scrollableQuery, setQueryParams, update, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PersistenceManager

public PersistenceManager()
                   throws PersistenceException
Creates a new persistence manager.

Throws:
PersistenceException
Method Detail

init

public static void init(boolean cache2)
                 throws PersistenceException
Initializes Hibernate for WordHoard using default properties file.

Parameters:
cache2 - True to enable second-level cache.
Throws:
PersistenceException

init

public static void init(java.lang.String url,
                        java.lang.String username,
                        java.lang.String password,
                        boolean cache2)
                 throws PersistenceException
Initializes Hibernate for WordHoard using specified parameters.

Parameters:
url - URL for MySQL database, or null to use the "hibernate.properties" file for setting the Hibernate parameters.
username - Username for MySQL database access. Ignored if url = null.
password - Password for MySQL database access. Ignored if url = null.
cache2 - True to enable second-level cache.
Throws:
PersistenceException

getPM

public static PersistenceManager getPM()
                                throws PersistenceException
Gets a persistence manager for the current thread.

Returns:
The current persistence manager.
Throws:
PersistenceException

closePM

public static void closePM()
Close persistence manager for the current thread.


clone

public java.lang.Object clone(PersistentObject obj)
                       throws PersistenceException
Clones an object.

Loads a new copy of a persistent object in this persistence manager.

Parameters:
obj - Persistent object.
Throws:
PersistenceException

getAllCorpora

public java.util.Collection getAllCorpora()
                                   throws PersistenceException
Gets all the corpora.

In addition to loading and returning all the corpora, all the works, table of contents views, authors, and work child parts are preloaded.

Returns:
A collection of all the corpora.
Throws:
PersistenceException

getAllWorkParts

public java.util.Collection getAllWorkParts()
                                     throws PersistenceException
Gets all the work parts.

Returns:
A collection of all the work parts.
Throws:
PersistenceException

getWorkParts

public java.util.Collection getWorkParts(Work work)
                                  throws PersistenceException
Gets all the work parts for a work.

Parameters:
work - Work.
Returns:
A collection of all the work parts for the work.
Throws:
PersistenceException

getAllWorks

public java.util.Collection getAllWorks()
                                 throws PersistenceException
Gets all the works.

Returns:
A collection of all the works.
Throws:
PersistenceException

getAllAuthors

public java.util.Collection getAllAuthors()
                                   throws PersistenceException
Gets all the authors.

Returns:
A collection of all the authors.
Throws:
PersistenceException

getAllAuthors

public java.util.Collection getAllAuthors(Corpus corpus)
                                   throws PersistenceException
Gets all the authors.

Parameters:
corpus - Corpus, or null.
Returns:
A collection of all the authors, in increasing case-insensitive alphabetical order by name. If the corpus argument is not null, the collection is limited to authors in the spcecified corpus.
Throws:
PersistenceException

getAllPos

public java.util.Collection getAllPos()
                               throws PersistenceException
Gets all the parts of speech.

Returns:
A collection of all the parts of speech.
Throws:
PersistenceException

getAllWordClasses

public java.util.Collection getAllWordClasses()
                                       throws PersistenceException
Gets all the word classes.

Returns:
A collection of all the word classes.
Throws:
PersistenceException

getAllLemmas

public java.util.Collection getAllLemmas()
                                  throws PersistenceException
Gets all the lemmas.

Returns:
A collection of all the lemmas.
Throws:
PersistenceException

getAllLemPos

public java.util.Collection getAllLemPos()
                                  throws PersistenceException
Gets all the LemPos objects.

Returns:
A collection of all the LemPos objects.
Throws:
PersistenceException

getAllMajorWordClasses

public java.util.Collection getAllMajorWordClasses()
                                            throws PersistenceException
Gets all the major word classes.

Returns:
A collection of all the major word class strings, in increasing alphabetical order.
Throws:
PersistenceException

getAllMetricalShapes

public java.util.Collection getAllMetricalShapes()
                                          throws PersistenceException
Gets all the metrical shapes.

Returns:
A collection of all the metrical shapes, in increasing alphabetical order.
Throws:
PersistenceException

getCorpusByTag

public Corpus getCorpusByTag(java.lang.String tag)
                      throws PersistenceException
Gets a corpus by tag.

Parameters:
tag - Corpus tag.
Returns:
The corpus, or null if none found.
Throws:
PersistenceException

getWordByTag

public Word getWordByTag(java.lang.String tag)
                  throws PersistenceException
Gets a word by tag.

Parameters:
tag - tag.
Returns:
The word with the specified tag, or null if none found.
Throws:
PersistenceException

getWorkPartByTag

public WorkPart getWorkPartByTag(java.lang.String tag)
                          throws PersistenceException
Gets a work part by tag.

Parameters:
tag - tag.
Returns:
The work part with the specified tag, or null if none found.
Throws:
PersistenceException

getWorkPartsByTag

public WorkPart[] getWorkPartsByTag(java.util.Collection tags)
                             throws PersistenceException
Gets work parts by their tags.

Parameters:
tags - Collection of work part tags.
Returns:
Array of work parts with the specified tags. Empty if none found.
Throws:
PersistenceException

getLemmaByTag

public Lemma getLemmaByTag(java.lang.String tag)
                    throws PersistenceException
Gets a lemma by tag.

Parameters:
tag - tag.
Returns:
The lemma with the specified tag, or null if none found.
Throws:
PersistenceException

getLineByTag

public Line getLineByTag(java.lang.String tag)
                  throws PersistenceException
Gets a line by tag.

Parameters:
tag - tag.
Returns:
The line with the specified tag, or null if none found.
Throws:
PersistenceException

getAuthorByName

public Author getAuthorByName(java.lang.String name)
                       throws PersistenceException
Gets an author by name.

Parameters:
name - English name.
Returns:
The author with the specified name, or null if none found.
Throws:
PersistenceException

getAnnotationCategoryByName

public AnnotationCategory getAnnotationCategoryByName(java.lang.String name)
                                               throws PersistenceException
Gets an annotation category by name.

Parameters:
name - Catgegory name.
Returns:
The annotation category with the specified name, or null if none found.
Throws:
PersistenceException

getWordsInWorkPart

public java.util.Collection getWordsInWorkPart(WorkPart workPart)
                                        throws PersistenceException
Gets the words in a work part.

Parameters:
workPart - Work part.
Returns:
All of the words for this work part.
Throws:
PersistenceException

getWordsInWorkPartWithPreloading

public java.util.Collection getWordsInWorkPartWithPreloading(WorkPart workPart)
                                                      throws PersistenceException
Gets the words in a work part with preloading.

All related morphology and speech objects are preloaded.

Parameters:
workPart - Work part.
Returns:
All of the words for this work part.
Throws:
PersistenceException

getLinesInWorkPart

public java.util.Collection getLinesInWorkPart(WorkPart workPart)
                                        throws PersistenceException
Gets the lines in a work part.

Parameters:
workPart - Work part.
Returns:
All of the lines in the work part.
Throws:
PersistenceException

getLinesInWork

public java.util.Collection getLinesInWork(Work work)
                                    throws PersistenceException
Gets the lines in a work.

Parameters:
work - Work.
Returns:
All of the lines in the work.
Throws:
PersistenceException

getWordsInWork

public java.util.Collection getWordsInWork(Work work)
                                    throws PersistenceException
Gets the words in a work.

Parameters:
work - Work.
Returns:
All of the words in the work.
Throws:
PersistenceException

getAnnotationsForWorkPart

public java.util.Collection getAnnotationsForWorkPart(WorkPart workPart)
                                               throws PersistenceException
Gets the annotations for a work part.

Parameters:
workPart - Work part.
Returns:
All of the text annotations for the work part.
Throws:
PersistenceException

getLemmaWorkCounts

public LemmaWorkCounts getLemmaWorkCounts(Lemma lemma,
                                          Work work)
                                   throws PersistenceException
Gets lemma/work counts.

Parameters:
lemma - Lemma.
work - Work.
Returns:
Lemma/work counts, or null if there are no counts for this lemma and work.
Throws:
PersistenceException

getLemmaCorpusCounts

public LemmaCorpusCounts getLemmaCorpusCounts(Lemma lemma,
                                              Corpus corpus)
                                       throws PersistenceException
Gets lemma/corpus counts.

Parameters:
lemma - Lemma.
corpus - Corpus.
Returns:
Lemma/corpus counts, or null if there are no counts for this lemma and corpus.
Throws:
PersistenceException

getLexicon

public java.util.Collection getLexicon(Corpus corpus)
                                throws PersistenceException
Gets the lexicon for a corpus.

Parameters:
corpus - Corpus.
Returns:
The lexicon: a collection of all the lemma/corpus counts objects for the corpus, in no particular order.
Throws:
PersistenceException

getLemmaPosSpellingCounts

public java.util.Collection getLemmaPosSpellingCounts(Lemma lemma,
                                                      Corpus corpus)
                                               throws PersistenceException
Gets lemma/pos/spelling counts.

Parameters:
lemma - Lemma.
corpus - Corpus.
Returns:
A collection of all the lemma/pos/spelling counts for this lemma and corpus.
Throws:
PersistenceException

findWord

public Word findWord(WorkPart workPart,
                     int lineIndex,
                     int startOffset,
                     int endOffset)
              throws PersistenceException
Finds a word in a work part.

Parameters:
workPart - Work part.
lineIndex - Index of line containing word.
startOffset - Starting offset of word in line.
endOffset - Ending offset of word in line.
Returns:
The word, or null if none found.
Throws:
PersistenceException

findLemmasByTagPrefix

public java.util.Collection findLemmasByTagPrefix(java.lang.String prefix,
                                                  Corpus corpus)
                                           throws PersistenceException
Finds lemmas by tag prefix.

Parameters:
prefix - Tag prefix.
corpus - Corpus, or null.
Returns:
A collection of up to the first 100 lemmas which have tags that start with the prefix string, in case-insenstive increasing alphabetical order by tag. If the corpus argument is not null, the collection is limited to lemmas in the specified corpus.
Throws:
PersistenceException

findSpeakerNamesbyPrefix

public java.util.Collection findSpeakerNamesbyPrefix(java.lang.String prefix,
                                                     Corpus corpus)
                                              throws PersistenceException
Finds speaker names by prefix.

Parameters:
prefix - Speaker name prefix.
corpus - Corpus, or null.
Returns:
A collection of up to the first 100 speaker names which start with the prefix string, ordered by name. If the corpus argument is not null, the collection is limited to speakers in the specified corpus.
Throws:
PersistenceException

findAuthorsByNamePrefix

public java.util.Collection findAuthorsByNamePrefix(java.lang.String prefix)
                                             throws PersistenceException
Finds authors by name prefix.

Parameters:
prefix - name prefix.
Returns:
A collection of up to the first 100 authors which have name that start with the prefix string, ordered by name.
Throws:
PersistenceException

getColocates

public java.util.Collection getColocates(java.util.Collection words,
                                         int distance)
                                  throws PersistenceException
Gets colocates for a collection of words.

Parameters:
words - Collection of words.
distance - Max distance.
Returns:
A collection of all the words which are within "distance" words of one of the specified words.
Throws:
PersistenceException

preloadConcordanceInfo

public void preloadConcordanceInfo(java.util.Collection words)
                            throws PersistenceException
Preloads concordance information.

This method is a performance optimization for concordance displays. Given a collection of words, we preload all the related objects for the words that might be needed in a concordance display.

Parameters:
words - Collection of words.
Throws:
PersistenceException

preloadAdjacentInfo

public void preloadAdjacentInfo(java.util.Collection words,
                                boolean preceding)
                         throws PersistenceException
Preloads adjacent words information.

This method is a performance optimization for the concordance grouping options for preceding word forms and following word forms. Given a collection of words, we preload all the adjacent word objects and their word part, lempos, lemma, and pos objects.

Parameters:
words - Collection of words.
preceding - True to preload objects for adjacent words, false for following words.
Throws:
PersistenceException

searchLemmata

public java.util.List searchLemmata(SearchCriteriaLemmaSearch sq)
                             throws PersistenceException
Searches for lemmmata.

Parameters:
sq - Search criteria.
Returns:
A list of all the search results which match the search criteria,
Throws:
PersistenceException

searchWords

public java.util.List searchWords(SearchCriteria sq)
                           throws PersistenceException
Searches for words.

Parameters:
sq - Search criteria.
Returns:
A list of all the search results which match the search criteria, ordered by location (by work tag, then by ordinal within work).
Throws:
PersistenceException

searchWorks

public java.util.List searchWorks(SearchWorkCriteria sq)
                           throws PersistenceException
Searches for works.

Parameters:
sq - Work search criteria.
Returns:
A list of all the works which match the search criteria, ordered by full title.
Throws:
PersistenceException

generateInPhrase

public static java.lang.StringBuffer generateInPhrase(java.lang.String objectName,
                                                      PersistentObject[] objects)
Generates "item in (:items)" query phrase.

Parameters:
objectName - The name of the object.
objects - Array of PersistentObject objects.
Returns:
The HQL "where" clause query phrase as a StringBuffer.

Hibernate exhibits extremely poor performance when asked to create a where clause phrase of the form:

object in (:objects)

For example, when "items" is an array of the 29,350 Word objects for the words in Hamlet, and all the Word objects are already loaded, creating the simple query "from Word where word in (:words)" takes nearly eight minutes on a 2.5 Ghz Pentium system. Note: this is not the execution time for the query, just the time to construct the query.

This method takes a parameter name, e.g., "word", and an array of PersistentObject objects, e.g., "words", and generates the correponding HQL "where" clause phrase for "word in (:words)" by expanding this to "word.id in (id1, id2, id3 ... )". This process only a fraction of a second for the Hamlet example.


generateInPhrase

public static java.lang.StringBuffer generateInPhrase(java.lang.String objectName,
                                                      java.util.Collection objects)
Generates "item in (:items)" query phrase.

Parameters:
objectName - The name of the object.
objects - Collection of PersistentObject objects.
Returns:
The HQL "where" clause query phrase as a StringBuffer.

Hibernate exhibits extremely poor performance when asked to create a where clause phrase of the form:

object in (:objects)

For example, when "items" is a collection of the 29,350 Word objects for the words in Hamlet, and all the Word objects are already loaded, creating the simple query "from Word where word in (:words)" takes nearly eight minutes on a 2.5 Ghz Pentium system. Note: this is not the execution time for the query, just the time to construct the query.

This method takes a parameter name, e.g., "word", and a collection of PersistentObject objects, e.g., "words", and generates the correponding HQL "where" clause phrase for "word in (:words)" by expanding this to "word.id in (id1, id2, id3 ... )". This process only a fraction of a second for the Hamlet example.


generateInPhrase2

public static java.lang.StringBuffer generateInPhrase2(java.lang.String objectName,
                                                       java.util.Collection objects)
Generates "item in (:items)" query phrase.

Parameters:
objectName - The name of the object.
objects - Collection of String objects.
Returns:
The HQL "where" clause query phrase as a StringBuffer.

This method takes a parameter name, e.g., "word.tag", and a collection of objects with toString() methods, e.g., "wordTags", and generates the correponding HQL "where" clause phrase for "word.tag in (:wordTags)",