org.jaffa.persistence.util
Class PersistentHelper

java.lang.Object
  extended byorg.jaffa.persistence.util.PersistentHelper

public class PersistentHelper
extends Object

Helper methods for persistent objects.


Constructor Summary
PersistentHelper()
           
 
Method Summary
static void checkMandatoryFields(IPersistent object)
          This will check all the mandatory fields of the persistent object.
static boolean exists(UOW uow, IPersistent object)
          This will query the database to see if the primary-key of the input persistent object is already in use.
static String generateSerializedKey(IPersistent object)
          This will generate a unique string for the input persistent object, based on the persistent class name and its key values.
static FieldMetaData[] getFieldMetaData(String persistentClassName)
          This returns an array of meta information for all the fields of the persistent class.
static FieldMetaData getFieldMetaData(String persistentClassName, String fieldName)
          Returns the FieldMetaData object from the meta class for the input persistent class for the input field.
static FieldMetaData[] getKeyFields(String persistentClassName)
          This returns an array of meta information for all the key fields of the persistent class.
static String getLabelToken(String persistentClassName)
          This returns the labelToken for a persistent class.
static String getLabelToken(String persistentClassName, String fieldName)
          This returns the labelToken for a field in a persistent class.
static FieldMetaData[] getMandatoryFields(String persistentClassName)
          This returns an array of meta information for all the mandatory fields of the persistent class.
static Class getMetaClass(String persistentClassName)
          This returns the corresponding meta class for the input persistent class.
static IPersistent loadFromSerializedKey(UOW uow, String serializedKey)
          This will load the persistent object from the input serialized key, by invoking the findByPK() method of the persistent class encoded in the input String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PersistentHelper

public PersistentHelper()
Method Detail

getMetaClass

public static Class getMetaClass(String persistentClassName)
                          throws ClassNotFoundException
This returns the corresponding meta class for the input persistent class. It assumes the name of the meta class by appending 'Meta' to the input persistent class.

Parameters:
persistentClassName - The persistent class.
Returns:
the meta class.
Throws:
ClassNotFoundException - if the Meta class for the input persistent class is not found.

getKeyFields

public static FieldMetaData[] getKeyFields(String persistentClassName)
                                    throws ClassNotFoundException,
                                           NoSuchMethodException,
                                           IllegalAccessException,
                                           InvocationTargetException
This returns an array of meta information for all the key fields of the persistent class.

Parameters:
persistentClassName - The name of the persistent class.
Throws:
ClassNotFoundException - if the Meta class for the input persistent class is not found.
NoSuchMethodException - if the Meta class does not have the 'public static FieldMetaData[] getKeyFields()' method.
IllegalAccessException - if the 'public static FieldMetaData[] getKeyFields()' method of the Meta class enforces Java language access control and the underlying method is inaccessible.
InvocationTargetException - if the 'public static FieldMetaData[] getKeyFields()' method of the Meta class throws an exception.

getMandatoryFields

public static FieldMetaData[] getMandatoryFields(String persistentClassName)
                                          throws ClassNotFoundException,
                                                 NoSuchMethodException,
                                                 IllegalAccessException,
                                                 InvocationTargetException
This returns an array of meta information for all the mandatory fields of the persistent class.

Parameters:
persistentClassName - The name of the persistent class.
Throws:
ClassNotFoundException - if the Meta class for the input persistent class is not found.
NoSuchMethodException - if the Meta class does not have the 'public static FieldMetaData[] getMandatoryFields()' method.
IllegalAccessException - if the 'public static FieldMetaData[] getMandatoryFields()' method of the Meta class enforces Java language access control and the underlying method is inaccessible.
InvocationTargetException - if the 'public static FieldMetaData[] getMandatoryFields()' method of the Meta class throws an exception.

getFieldMetaData

public static FieldMetaData[] getFieldMetaData(String persistentClassName)
                                        throws ClassNotFoundException,
                                               NoSuchMethodException,
                                               IllegalAccessException,
                                               InvocationTargetException
This returns an array of meta information for all the fields of the persistent class.

Parameters:
persistentClassName - The name of the persistent class.
Throws:
ClassNotFoundException - if the Meta class for the input persistent class is not found.
NoSuchMethodException - if the Meta class does not have the 'public static FieldMetaData[] getFieldMetaData()' method.
IllegalAccessException - if the 'public static FieldMetaData[] getFieldMetaData()' method of the Meta class enforces Java language access control and the underlying method is inaccessible.
InvocationTargetException - if the 'public static FieldMetaData[] getFieldMetaData()' method of the Meta class throws an exception.

getFieldMetaData

public static FieldMetaData getFieldMetaData(String persistentClassName,
                                             String fieldName)
                                      throws ClassNotFoundException,
                                             NoSuchMethodException,
                                             IllegalAccessException,
                                             InvocationTargetException
Returns the FieldMetaData object from the meta class for the input persistent class for the input field.

Parameters:
persistentClassName - The name of the persistent class.
fieldName - the field name.
Throws:
ClassNotFoundException - if the Meta class for the input persistent class is not found.
NoSuchMethodException - if the Meta class does not have the 'public static FieldMetaData[] getFieldMetaData(String fieldName)' method.
IllegalAccessException - if the 'public static FieldMetaData[] getFieldMetaData(String fieldName)' method of the Meta class enforces Java language access control and the underlying method is inaccessible.
InvocationTargetException - if the 'public static FieldMetaData[] getFieldMetaData(String fieldName)' method of the Meta class throws an exception.

getLabelToken

public static String getLabelToken(String persistentClassName)
                            throws ClassNotFoundException,
                                   NoSuchMethodException,
                                   IllegalAccessException,
                                   InvocationTargetException
This returns the labelToken for a persistent class. It will look for the persistent meta class and invoke its getLabelToken method to determine the value to return.

Parameters:
persistentClassName - The persistent class.
Returns:
the labelToken for a persistent class.
Throws:
ClassNotFoundException - If the persistent meta class is not found.
NoSuchMethodException - If there is no 'public static String getLabelToken()' method in the persistent meta class.
IllegalAccessException - if the method is inaccessible.
InvocationTargetException - if the method throws an exception.

getLabelToken

public static String getLabelToken(String persistentClassName,
                                   String fieldName)
                            throws ClassNotFoundException,
                                   NoSuchMethodException,
                                   IllegalAccessException,
                                   InvocationTargetException
This returns the labelToken for a field in a persistent class. It will look for the persistent meta class and invoke its getFieldMetaData method to determine the appropriate FieldMetaData object. It will finally return the labelToken as specified in the FieldMetaData object.

Parameters:
persistentClassName - The persistent class.
fieldName - The field name.
Returns:
the labelToken for a field in a domain class.
Throws:
ClassNotFoundException - If the persistent meta class is not found.
NoSuchMethodException - If there is no 'public static FieldMetaData getFieldMetaData(String fieldName)' method in the persistent meta class.
IllegalAccessException - if the method is inaccessible.
InvocationTargetException - if the method throws an exception.

checkMandatoryFields

public static void checkMandatoryFields(IPersistent object)
                                 throws ApplicationExceptions,
                                        FrameworkException
This will check all the mandatory fields of the persistent object. It utilises the corresponding Meta class for determining the mandatory fields.

Parameters:
object - The persistent object.
Throws:
ApplicationExceptions - Will contain a collection of MandatoryFieldExceptions for the all the mandatory fields which do not have values.
FrameworkException - If any framework error occurs.

exists

public static boolean exists(UOW uow,
                             IPersistent object)
                      throws ClassNotFoundException,
                             NoSuchMethodException,
                             IllegalAccessException,
                             InvocationTargetException,
                             IllegalArgumentException,
                             FrameworkException
This will query the database to see if the primary-key of the input persistent object is already in use. It'll invoke the exists() method of the persistent class perform the check. Note: This method will determine the key fields by looking up the getKeyFields method in the corresponding meta class for the input persistent object.

Parameters:
uow - The UOW object. If null, then a UOW will be created implicitly by the exists() method to load the persistent object.
object - The persistent object.
Returns:
true if the primary-key is already in use. A false will be returned if the key is not in use or if any of the key fields is null.
Throws:
ClassNotFoundException - if the Meta class for the input persistent class is not found.
NoSuchMethodException - if the Meta class does not have the 'public static FieldMetaData[] getKeyFields()' method.
IllegalAccessException - if the 'public static FieldMetaData[] getKeyFields()' method of the Meta class enforces Java language access control and the underlying method is inaccessible.
InvocationTargetException - if the 'public static FieldMetaData[] getKeyFields()' method of the Meta class throws an exception.
IllegalArgumentException - if the input persistent class does not have any key-fields
FrameworkException - if the exists() method of the persistent class fails.

generateSerializedKey

public static String generateSerializedKey(IPersistent object)
                                    throws ClassNotFoundException,
                                           NoSuchMethodException,
                                           IllegalAccessException,
                                           InvocationTargetException,
                                           IllegalArgumentException
This will generate a unique string for the input persistent object, based on the persistent class name and its key values. The format of the generated key will be: package.classname;key1value;key2value;key3value For eg: For a Person persistent object having a primary key PersonId, the serialized key could be "org.example.Person;P0021" For an EventEntry persistent object having a composite primary key of EventId and PersonId primary, the serialized key could be "org.example.EventEntry;E01;P0021" The back-slash '\' will be the escape character. Hence, if the key-value contains a '\', then it'll be replaced by '\\' If the key value contains a semi-colon, then it'll be replaced by '\;' Note: This method will determine the key fields by looking up the getKeyFields method in the corresponding meta class for the input persistent object.

Parameters:
object - The persistent object.
Returns:
a unique String for identifying the persistent object.
Throws:
ClassNotFoundException - if the Meta class for the input persistent class is not found.
NoSuchMethodException - if the Meta class does not have the 'public static FieldMetaData[] getKeyFields()' method.
IllegalAccessException - if the 'public static FieldMetaData[] getKeyFields()' method of the Meta class enforces Java language access control and the underlying method is inaccessible.
InvocationTargetException - if the 'public static FieldMetaData[] getKeyFields()' method of the Meta class throws an exception.
IllegalArgumentException - if the input persistent class does not have any key-fields or if any of the key-fields is null.

loadFromSerializedKey

public static IPersistent loadFromSerializedKey(UOW uow,
                                                String serializedKey)
                                         throws ClassNotFoundException,
                                                NoSuchMethodException,
                                                IllegalAccessException,
                                                InvocationTargetException,
                                                IllegalArgumentException,
                                                IntrospectionException,
                                                FrameworkException
This will load the persistent object from the input serialized key, by invoking the findByPK() method of the persistent class encoded in the input String.

Parameters:
uow - The UOW object. If null, then a UOW will be created implicitly by the findByPK method to load the persistent object.
serializedKey - The serialized key which will have the right information to load the persistent object.
Returns:
a Persistent object.
Throws:
ClassNotFoundException - if the Persistent class or its Meta class are not found.
NoSuchMethodException - if the Persistent class does not have the 'public static IPersistent findByPK(UOW uow, KeyField1...)' method or the Meta class does not have the 'public static FieldMetaData[] getKeyFields()' method.
IllegalAccessException - if the 'public static FieldMetaData[] getKeyFields()' method of the Meta class enforces Java language access control and the underlying method is inaccessible.
InvocationTargetException - if the 'public static FieldMetaData[] getKeyFields()' method of the Meta class throws an exception.
IllegalArgumentException - if the input persistent class does not have any key-fields or if any of the key-fields is null.
IntrospectionException - if an exception occurs during introspection.
FrameworkException - if the findByPK() method of the persistent class fails.


Copyright © 2002-2004 JAFFA Project.