standup.joke
Class BackendJokeSetSQL

java.lang.Object
  extended by standup.joke.Backend
      extended by standup.joke.BackendJokeSetSQL
All Implemented Interfaces:
Profileable

public class BackendJokeSetSQL
extends Backend

A subclass of Backend that fulfills joke generation requests either by genuinely creating a new joke or by retrieving pre-generated jokes found in a 'joke cache' -- this value is determined by the current user profile's JokeCacheBehaviour. Regardless of this value, however, it will always attempt to establish a connection to the PostgreSQL database server.

The joke cache is contained in a file in the /standup/resources/xml/ subdirectory found within the STANDUP .jar file.

Author:
Ruli Manurung
See Also:
JokeCacheBehaviour, OptionsJokeGeneration.getJokeCacheBehaviour();

Field Summary
(package private)  JokeSet jokeCache
           
 
Fields inherited from class standup.joke.Backend
generator
 
Constructor Summary
BackendJokeSetSQL()
          Constructor that uses either /standup/resources/xml/jokecache.jokes or /standup/resources/xml/jokecache_corseford.jokes as the joke cache, depending on the value of CommandLineArguments#KEY_OLDCACHE.
 
Method Summary
(package private)  JokeStructure generateNewJoke(String newJokeID, JokeConstraints jcs)
          Obtains a joke, either by generating a new one or retrieving an existing one from the joke cache, which satisfies the given JokeConstraints and labels it with the given joke ID.
 boolean setProfile(Profile profile, boolean repeat)
          Sets this Backend to use the specified joke generation profile.
 
Methods inherited from class standup.joke.Backend
addToFavourites, buildUserProfileConstraints, createProfile, getCurrentUserUsedJokeTypes, getFavouriteJokes, getGenerator, getLexicalComponents, getNewJoke, getNewJoke, getNewJoke, getNewJoke, getNewJoke, getNewJoke, getOldJokes, getOldJokes, getOldJokes, getOldJokes, getOldJokes, getOldJokes, getProfile, getProfileFilename, getRootTopic, loadProfile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

jokeCache

JokeSet jokeCache
Constructor Detail

BackendJokeSetSQL

public BackendJokeSetSQL()
                  throws GeneratorException,
                         STANDUPSQLException
Constructor that uses either /standup/resources/xml/jokecache.jokes or /standup/resources/xml/jokecache_corseford.jokes as the joke cache, depending on the value of CommandLineArguments#KEY_OLDCACHE.

Parameters:
cla -
Throws:
GeneratorException
STANDUPSQLException
Method Detail

setProfile

public boolean setProfile(Profile profile,
                          boolean repeat)
Sets this Backend to use the specified joke generation profile. It also sets up the schema instantiation exclusion (temporary) tables on the SQL database.

Specified by:
setProfile in interface Profileable
Overrides:
setProfile in class Backend
Parameters:
profile - the Profile to be used
repeat - whether this is the first time a profile is being set for the current user during this session
Returns:
true if successful, false otherwise (e.g. if the given profile was not an instance of ProfileJokeGeneration.
See Also:
Generator.setupExclusionTable(JokeSet, String)

generateNewJoke

JokeStructure generateNewJoke(String newJokeID,
                              JokeConstraints jcs)
Obtains a joke, either by generating a new one or retrieving an existing one from the joke cache, which satisfies the given JokeConstraints and labels it with the given joke ID.

The decision is based on the current user's JokeCacheBehaviour.

Specified by:
generateNewJoke in class Backend
Parameters:
newJokeID - the joke ID for the retrieved/generated joke
jcs - the constraints on the joke to be retrieved/generated
Returns:
a joke that satisfies jcs, or null if none could be retrieved/generated
See Also:
JokeSet.getJokes(JokeConstraints), JokeSet.getRandom(), Generator.generateJoke(String, JokeConstraints), JokeCacheBehaviour, OptionsJokeGeneration.getJokeCacheBehaviour();