edu.northwestern.at.wordhoard.swing.calculator.modelutils
Class QueryUtils

java.lang.Object
  extended by edu.northwestern.at.wordhoard.swing.calculator.modelutils.QueryUtils

public class QueryUtils
extends java.lang.Object

Query utilities.


Constructor Summary
protected QueryUtils()
          Don't allow instantiation but do allow overrides.
 
Method Summary
static WHQuery addQuery(java.lang.String title, java.lang.String description, java.lang.String webPageURL, boolean isPublic, int queryType, java.lang.String queryText)
          Add a new query.
static boolean deleteQueries(WHQuery[] queries)
          Delete multiple queries.
static boolean deleteQuery(java.lang.String title, int queryType)
          Delete a query by title.
static boolean deleteQuery(WHQuery query)
          Delete a query.
static WHQuery[] getQueries(int queryType)
          Get all available public queries as an array.
static WHQuery[] getQueries(java.lang.String owner, int queryType)
          Get all available queries for a specified owner as an array.
static int getQueriesCount(java.lang.String owner, int queryType)
          Get count of queries for a user.
static WHQuery[] getQueriesForLoggedInUser(int queryType)
          Get all available queries for the logged-in user.
static WHQuery getQuery(java.lang.String title, int queryType)
          Get a query by title.
static WHQuery getQuery(java.lang.String title, java.lang.String owner)
          Get a query by title.
static WHQuery getQuery(java.lang.String title, java.lang.String owner, int queryType)
          Get a query by title.
static WHQuery getQuery(WHQuery query)
          Get a query, loading it to current persistence manager if needed.
static WHQuery importFromDOMDocument(org.w3c.dom.Node queryNode)
          Import a specified query by name from a DOM document.
static WHQuery[] importQueries(org.w3c.dom.Document importDocument, int queryType)
          Import one or more queries from XML file.
static boolean isDuplicate(int queryType, java.lang.String title, java.lang.String owner, java.lang.Long id)
          Check for a duplicate query.
protected static WHQuery[] udosToQueries(UserDataObject[] udos)
          Copy UserDataObject array to WHQuery array.
static boolean updateQuery(WHQuery query, java.lang.String title, java.lang.String description, java.lang.String webPageURL, boolean isPublic, int queryType, java.lang.String queryText)
          Update a query.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QueryUtils

protected QueryUtils()
Don't allow instantiation but do allow overrides.

Method Detail

udosToQueries

protected static WHQuery[] udosToQueries(UserDataObject[] udos)
Copy UserDataObject array to WHQuery array.

Parameters:
udos - Array of user data objects, all actually WHQuery objects.
Returns:
Array of WHQuery objects.

addQuery

public static WHQuery addQuery(java.lang.String title,
                               java.lang.String description,
                               java.lang.String webPageURL,
                               boolean isPublic,
                               int queryType,
                               java.lang.String queryText)
                        throws DuplicateQueryException,
                               BadOwnerException
Add a new query.

Parameters:
title - Title for the new query.
description - Description for the new query.
webPageURL - Web page URL for the new query.
isPublic - True if query to be public.
queryType - The type of query.
queryText - The text of the query.
Returns:
Query object if query added, else null.
Throws:
DuplicateQueryException - if (title,owner,queryType) combination already exists.
BadOwnerException - if the owner null or empty.

deleteQuery

public static boolean deleteQuery(WHQuery query)
Delete a query.

Parameters:
query - The query to delete.
Returns:
true if query deleted, false otherwise.

A query may only be deleted by its owner.


deleteQuery

public static boolean deleteQuery(java.lang.String title,
                                  int queryType)
Delete a query by title.

Parameters:
title - The title of the query to delete.
queryType - Query type to retrieve.
Returns:
true if query deleted, false otherwise. If the query didn't exist, true is returned.

deleteQueries

public static boolean deleteQueries(WHQuery[] queries)
Delete multiple queries.

Parameters:
queries - The queries to delete.
Returns:
true if queries deleted, false otherwise.

getQuery

public static WHQuery getQuery(java.lang.String title,
                               java.lang.String owner,
                               int queryType)
Get a query by title.

Parameters:
title - The title of the query to fetch.
owner - The owner of the query to fetch.
queryType - Query type to retrieve.
Returns:
The query of the specified type with the requested title, or null if not found.

getQuery

public static WHQuery getQuery(java.lang.String title,
                               java.lang.String owner)
Get a query by title.

Parameters:
title - The title of the query to fetch.
owner - The owner of the query to fetch.
Returns:
The query with the requested title, or null if not found.

getQuery

public static WHQuery getQuery(java.lang.String title,
                               int queryType)
Get a query by title.

Parameters:
title - The title of the query to fetch.
queryType - Query type to retrieve.
Returns:
The query of the requested type with the requested title, or null if not found.

getQuery

public static WHQuery getQuery(WHQuery query)
Get a query, loading it to current persistence manager if needed.

Parameters:
query - The query.
Returns:
The query loaded into the current persistence manager context, or null if not found.

getQueries

public static WHQuery[] getQueries(int queryType)
Get all available public queries as an array.

Parameters:
queryType - Query type to retrieve.
Returns:
All available queries as an array of Query.

getQueries

public static WHQuery[] getQueries(java.lang.String owner,
                                   int queryType)
Get all available queries for a specified owner as an array.

Parameters:
owner - Owner of queries to retrieve.
queryType - Query type to retrieve.
Returns:
All available queries as an array of WHQuery. Null if owner is null or empty.

getQueriesForLoggedInUser

public static WHQuery[] getQueriesForLoggedInUser(int queryType)
Get all available queries for the logged-in user.

Parameters:
queryType - Query type to retrieve.
Returns:
All available queries of the specified type for the logged-in user. Returns null if the user is not logged in.

getQueriesCount

public static int getQueriesCount(java.lang.String owner,
                                  int queryType)
Get count of queries for a user.

Parameters:
owner - The owner.
Returns:
Count of queries owned by "owner".

isDuplicate

public static boolean isDuplicate(int queryType,
                                  java.lang.String title,
                                  java.lang.String owner,
                                  java.lang.Long id)
Check for a duplicate query.

Parameters:
queryType - The query type.
title - The query title.
owner - The query owner.
id - The query ID.
Returns:
true if a query of the specified type with the specified title and owner already exists, and has an object ID different from the specified ID.

updateQuery

public static boolean updateQuery(WHQuery query,
                                  java.lang.String title,
                                  java.lang.String description,
                                  java.lang.String webPageURL,
                                  boolean isPublic,
                                  int queryType,
                                  java.lang.String queryText)
                           throws DuplicateQueryException,
                                  BadOwnerException
Update a query.

Parameters:
query - The query to update.
title - Title for the query.
description - Description for the query.
webPageURL - Web page URL for the query.
isPublic - True if query is public.
queryType - The type of query.
queryText - The text of the query.
Returns:
true if update succeed, false otherwise.
Throws:
DuplicateQueryException
BadOwnerException

importQueries

public static WHQuery[] importQueries(org.w3c.dom.Document importDocument,
                                      int queryType)
Import one or more queries from XML file.

Parameters:
importDocument - The DOM document containing the queries to import.
Returns:
The imported queries. May be empty.

Note: The queries are not persisted here. That is the responsibility of the caller.


importFromDOMDocument

public static WHQuery importFromDOMDocument(org.w3c.dom.Node queryNode)
                                     throws BadOwnerException
Import a specified query by name from a DOM document.

Parameters:
queryNode - The DOM node which is the root of the query to import.
Returns:
The imported query, or null if the import fails.
Throws:
BadOwnerException