SPT RWT Application API

com.sptci.rwt
Class Queries

java.lang.Object
  extended by com.sptci.rwt.Queries
All Implemented Interfaces:
Serializable

public class Queries
extends Object
implements Serializable

A serializable wrapper used to represent saved SQL queries for the application. This class will be serialised to the following file and initialised from the same file during application load:

<sptrwt.data.directory>/queries.xml

© Copyright 2007 Sans Pareil Technologies, Inc.

Version:
$Id: Queries.java 4123 2008-05-25 21:49:01Z rakesh $
Author:
Rakesh Vidyadharan 2007-10-10
See Also:
Serialized Form

Field Summary
private  TreeMap<String,Category> categories
          A map used to quickly look up Query instances by their Category.name.
static String DIRECTORY
          The system property used to configure the location of the root directory under which persistent state information for the application is stored.
static String ENCODING
          The encoding to use to serialise and deserialise instances of this class.
static String FILE_NAME
          The name of the file to which this class will be serialised.
private  String fileName
          The fully qualified file name to use to serialise this instance into.
protected static XStream xstream
          The XStream instance used to serialise and deserialise instances of this class.
 
Constructor Summary
protected Queries()
          Default constructor.
 
Method Summary
 void add(String category, Query query)
          Add the specified query parameters value object to the application persistent state.
 void delete(String name)
          Remove the specified category from persistent state.
 void delete(String category, String name)
          Remove the specified query parameters from the application persistent state.
protected  void deserialise(String user)
          Deserialise the contents of FILE_NAME into this instance.
 Collection<Category> getCategories()
          Returns the names of the categories under which queries have been saved.
 Category getCategory(String name)
          Returns the category identified by the name specified.
static Queries getInstance(String user)
          Create a new instance of the class for the specified user.
 Query getQuery(String category, String name)
          Return a Query for the specified category and saved with the specified unique name.
protected  void serialise()
          Serialise this instance to the FILE_NAME.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENCODING

public static final String ENCODING
The encoding to use to serialise and deserialise instances of this class. "UTF-8"

See Also:
Constant Field Values

FILE_NAME

public static final String FILE_NAME
The name of the file to which this class will be serialised.

See Also:
Constant Field Values

DIRECTORY

public static final String DIRECTORY
The system property used to configure the location of the root directory under which persistent state information for the application is stored. "sptrwt.data.directory"

See Also:
Constant Field Values

xstream

protected static final XStream xstream
The XStream instance used to serialise and deserialise instances of this class.


categories

private final TreeMap<String,Category> categories
A map used to quickly look up Query instances by their Category.name.


fileName

private transient String fileName
The fully qualified file name to use to serialise this instance into.

Constructor Detail

Queries

protected Queries()
Default constructor. Cannot be instantiated.

Method Detail

getInstance

public static Queries getInstance(String user)
Create a new instance of the class for the specified user. Saved files are stored under a directory named after the user under DIRECTORY.

Returns:
The newly initialised instance of the class.
Throws:
RuntimeException - If errors are encountered while deserialising the persistent state of this instance.
See Also:
deserialise(java.lang.String)

getQuery

public Query getQuery(String category,
                      String name)
Return a Query for the specified category and saved with the specified unique name.

Parameters:
category - The category under which the query is saved.
name - The unique name used to identify the saved query.
Returns:
The SQL statement associated with the named query, or null if no such mapping exists.

add

public void add(String category,
                Query query)
Add the specified query parameters value object to the application persistent state.

Parameters:
category - The category to associate the query with.
query - The query to be saved.
See Also:
serialise()

delete

public void delete(String category,
                   String name)
Remove the specified query parameters from the application persistent state.

Parameters:
category - The category under which the query was saved.
name - The unique name to use to identify the saved query.
See Also:
serialise()

delete

public void delete(String name)
Remove the specified category from persistent state. This removes all saved queries for that category.

Parameters:
name - The name of the category to remove from saved state.
See Also:
serialise()

deserialise

protected void deserialise(String user)
                    throws RuntimeException
Deserialise the contents of FILE_NAME into this instance.

Parameters:
user - The name of the user to use to construct the full filename.
Throws:
RuntimeException - If errors are encountered while deserialising the persistent state. No exceptions are thrown if the file does not exist.

serialise

protected void serialise()
                  throws RuntimeException
Serialise this instance to the FILE_NAME.

Throws:
RuntimeException - If errors are encountered while serialising the instance.

getCategory

public Category getCategory(String name)
Returns the category identified by the name specified.

Parameters:
name - The name of the category.
Returns:
The category identified by the name specified, or null if no such category exists.

getCategories

public Collection<Category> getCategories()
Returns the names of the categories under which queries have been saved.

Returns:
A read only collection of category names.

SPT RWT Application API