net.sf.jagzilla
Class BaseQuery

java.lang.Object
  extended bynet.sf.jagzilla.BaseQuery
Direct Known Subclasses:
BugQueryHibernateImpl, SystemQueryHibernateImpl

public class BaseQuery
extends java.lang.Object

base class to provide helper methods. This class is a holder for common code among jagzilla API implementations. This is only usefull for classes using the hibernate access api.

There are three kind of helper methods in this class

Author:
mike

Field Summary
protected  EventHandler eventHandler
           
protected  java.util.Properties hibernateProperties
           
protected  Session session
           
protected static SessionFactory sessionFactory
           
 
Constructor Summary
BaseQuery()
           
 
Method Summary
protected  boolean bugExists(int id)
          tells if the given bug exists.
protected  boolean componentExists(java.lang.String string)
          tells if the given components exists.
protected  void continueIfProductExists(java.lang.String product)
          validates the existance of product and throws NoSuchProductException if it does not exits.
protected  void continueIfResolutionExists(java.lang.String resolution)
          helper method for resolution parameter validation.
protected  void continueIfStatusExists(java.lang.String status)
          helper method for status parameter validation.
protected  void continueIfUsersExists(int profileId)
          validate a profile and throw exceptions on error or do nothing on sucess.
protected  EventHandler getEventHandler()
          gets the event handler.
protected  int getFieldId(java.lang.String field)
          gets the field id of a given field name.
 Session getNewSession()
          returns a new Hibernate session.
protected  Bug locateBug(int id)
          helper method for validating a bug.
protected  Component locateComponent(java.lang.String name)
          helper method for validating a component.
protected  Product locateProduct(java.lang.String name)
          Helper method for locating and validating a product.
protected  Profile locateProfile(int id)
          helper method for validating a profile.
protected  boolean milestoneExists(java.lang.String id)
          tells if the given milestone exists.
protected  boolean priorityExists(java.lang.String pri)
          tells if the given priority exists.
protected  boolean productExists(java.lang.String id)
          tells if the given product exists.
protected  int queryCountValue(java.lang.String qry)
          count the results in an hibernate query.
protected  boolean resolutionExists(java.lang.String resolution)
          tells if the given resolution exists.
 void setHibernateProperties(java.util.Properties p)
          sets the hibernate properties to use.
protected  boolean severityExists(java.lang.String sev)
          tells if the given severity exists.
protected  boolean statusExists(java.lang.String status)
          tells if the given status exists.
protected  boolean userExists(int id)
          tells if the given user(Profile) exists.
protected  boolean versionExists(java.lang.String id)
          tells if the given version exists.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

session

protected Session session

sessionFactory

protected static SessionFactory sessionFactory

hibernateProperties

protected java.util.Properties hibernateProperties

eventHandler

protected EventHandler eventHandler
Constructor Detail

BaseQuery

public BaseQuery()
Method Detail

getEventHandler

protected EventHandler getEventHandler()
gets the event handler.

Returns:
the event handler

setHibernateProperties

public void setHibernateProperties(java.util.Properties p)
sets the hibernate properties to use. on a running class, it will produce an hibernate reinitialization on the first call to getNewSession()

Parameters:
p - properties to use

queryCountValue

protected int queryCountValue(java.lang.String qry)
                       throws HibernateException
count the results in an hibernate query.

Parameters:
qry - the hibernate query to count
Returns:
an integer representing the number of rows in result
Throws:
HibernateException - if an error occurs

getNewSession

public Session getNewSession()
                      throws HibernateException
returns a new Hibernate session.

Returns:
a new hibernamte Session ready for use
Throws:
HibernateException - if an error occurs

componentExists

protected boolean componentExists(java.lang.String string)
                           throws HibernateException
tells if the given components exists.

Parameters:
string - the component to query
Returns:
true if there is more than zero components with the given name of false otherwise
Throws:
HibernateException - if an error occurs

milestoneExists

protected boolean milestoneExists(java.lang.String id)
                           throws HibernateException
tells if the given milestone exists.

Parameters:
id - of the milestone to query
Returns:
true if there is more than zero milestones with the given name of false otherwise
Throws:
HibernateException - if an error occurs

userExists

protected boolean userExists(int id)
                      throws HibernateException
tells if the given user(Profile) exists.

Parameters:
id - of the user to query
Returns:
true if there is more than zero profiles with the given name of false otherwise
Throws:
HibernateException - if an error occurs

productExists

protected boolean productExists(java.lang.String id)
                         throws HibernateException
tells if the given product exists.

Parameters:
id - of the product to query
Returns:
true if there is more than zero products with the given name of false otherwise
Throws:
HibernateException - if an error occurs

bugExists

protected boolean bugExists(int id)
                     throws HibernateException
tells if the given bug exists.

Parameters:
id - of the bug to query
Returns:
true if there is more than zero bugs with the given name of false otherwise
Throws:
HibernateException - if an error occurs

versionExists

protected boolean versionExists(java.lang.String id)
                         throws HibernateException
tells if the given version exists.

Parameters:
id - of the version to query
Returns:
true if there is more than zero versions with the given name of false otherwise
Throws:
HibernateException - if an error occurs

continueIfProductExists

protected void continueIfProductExists(java.lang.String product)
                                throws JagzillaException,
                                       NoSuchProductException
validates the existance of product and throws NoSuchProductException if it does not exits.

Parameters:
product -
Throws:
JagzillaException - if an error occurs
NoSuchProductException - if the product cannot be found

continueIfUsersExists

protected void continueIfUsersExists(int profileId)
                              throws JagzillaException,
                                     NoSuchProfileException
validate a profile and throw exceptions on error or do nothing on sucess. This it a type of helper methods to simplify parameter validation.

Parameters:
profileId - id of the profile to validate
Throws:
JagzillaException - if an error occurs
NoSuchProfileException - if the given profile cannot be found

statusExists

protected boolean statusExists(java.lang.String status)
tells if the given status exists.

Parameters:
status - of the status to query
Returns:
true if there is more than zero statuses with the given name of false otherwise

severityExists

protected boolean severityExists(java.lang.String sev)
tells if the given severity exists.

Parameters:
sev - of the severity to query
Returns:
true if there is more than zero severities with the given name of false otherwise

priorityExists

protected boolean priorityExists(java.lang.String pri)
tells if the given priority exists.

Parameters:
pri - of the priority to query
Returns:
true if there is more than zero priorities with the given name of false otherwise

resolutionExists

protected boolean resolutionExists(java.lang.String resolution)
tells if the given resolution exists.

Parameters:
resolution - of the resolution to query
Returns:
true if there is more than zero resolutions with the given name of false otherwise

continueIfStatusExists

protected void continueIfStatusExists(java.lang.String status)
                               throws BadStatusException
helper method for status parameter validation.

Parameters:
status - the status to validate
Throws:
BadStatusException - if the status is invalid

continueIfResolutionExists

protected void continueIfResolutionExists(java.lang.String resolution)
                                   throws BadResolutionException
helper method for resolution parameter validation.

Parameters:
resolution - the resolution to validate
Throws:
BadResolutionException - if the resolution is invalid

getFieldId

protected int getFieldId(java.lang.String field)
                  throws HibernateException,
                         JagzillaException
gets the field id of a given field name. This method queries the field_defs table in bugzilla.

Parameters:
field - name of the field to search
Returns:
an int with the field id
Throws:
HibernateException - if an error occurs
JagzillaException - if result set is smaller than 1, meaning the field was not found

locateComponent

protected Component locateComponent(java.lang.String name)
                             throws NoSuchComponentException,
                                    ComponentNotUniqueException,
                                    JagzillaException
helper method for validating a component. This method validates a component and returns if for later usage.

Parameters:
name - of the component to locate
Returns:
the component found
Throws:
NoSuchComponentException - if the component cannot be found
ComponentNotUniqueException - if there is more than one component with the given name
JagzillaException - if an error occurs

locateProduct

protected Product locateProduct(java.lang.String name)
                         throws NoSuchProductException,
                                JagzillaException
Helper method for locating and validating a product.

Parameters:
name - the product to locate
Returns:
the product found
Throws:
NoSuchProductException - if the product cannot be found
JagzillaException - if an error occurs

locateBug

protected Bug locateBug(int id)
                 throws NoSuchBugException,
                        JagzillaException
helper method for validating a bug.

Parameters:
id - the if of the bug to locate
Returns:
the bug found
Throws:
NoSuchBugException - if the bug cannot be found
JagzillaException - if an error occurs

locateProfile

protected Profile locateProfile(int id)
                         throws NoSuchProfileException,
                                JagzillaException
helper method for validating a profile.

Parameters:
id - the id of the profile to locate
Returns:
the profile found
Throws:
NoSuchProfileException - if the profile cannot be found
JagzillaException - if an error occurs


Distributed under the GPL. By Miguel Griffa. See the Jagzilla project page for more info.