| java.lang.Object org.jaffa.persistence.util.PersistentHelper
PersistentHelper | public class PersistentHelper (Code) | | Helper methods for persistent objects.
|
Method Summary | |
public static void | checkMandatoryFields(IPersistent object) This will check all the mandatory fields of the persistent object. | public 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.
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. | public 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.
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. throws: ClassNotFoundException - if the Meta class for the input persistent class is not found. throws: NoSuchMethodException - if the Meta class does not have the 'public static FieldMetaData[] getKeyFields()' method. throws: IllegalAccessException - if the 'public static FieldMetaData[] getKeyFields()' method of the Meta class enforces Java language access control and the underlying method is inaccessible. throws: InvocationTargetException - if the 'public static FieldMetaData[] getKeyFields()' method of the Meta class throws an exception. throws: IllegalArgumentException - if the input persistent class does not have any key-fields or if any of the key-fields is null. | public static FieldMetaData[] | getFieldMetaData(String persistentClassName) This returns an array of meta information for all the fields of the persistent class. | public static FieldMetaData | getFieldMetaData(String persistentClassName, String fieldName) Returns the FieldMetaData object from the meta class for the input persistent class for the input field. | public static FieldMetaData[] | getKeyFields(String persistentClassName) This returns an array of meta information for all the key fields of the persistent class. | public static String | getLabelToken(String persistentClassName) This returns the labelToken for a persistent class. | public static String | getLabelToken(String persistentClassName, String fieldName) This returns the labelToken for a field in a persistent class. | public static FieldMetaData[] | getMandatoryFields(String persistentClassName) This returns an array of meta information for all the mandatory fields of the persistent class. | public static Class | getMetaClass(String persistentClassName) 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. | public 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.
Parameters: uow - The UOW object. |
checkMandatoryFields | public static void checkMandatoryFields(IPersistent object) throws ApplicationExceptions, FrameworkException(Code) | | 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. throws: FrameworkException - If any framework error occurs. |
exists | public static boolean exists(UOW uow, IPersistent object) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, IllegalArgumentException, FrameworkException(Code) | | 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. Parameters: object - The persistent object. throws: ClassNotFoundException - if the Meta class for the input persistent class is not found. throws: NoSuchMethodException - if the Meta class does not have the 'public static FieldMetaData[] getKeyFields()' method. throws: IllegalAccessException - if the 'public static FieldMetaData[] getKeyFields()' method of the Meta class enforces Java language access control and the underlying method is inaccessible. throws: InvocationTargetException - if the 'public static FieldMetaData[] getKeyFields()' method of the Meta class throws an exception. throws: IllegalArgumentException - if the input persistent class does not have any key-fields throws: FrameworkException - if the exists() method of the persistent class fails. 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. |
generateSerializedKey | public static String generateSerializedKey(IPersistent object) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, IllegalArgumentException(Code) | | 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. throws: ClassNotFoundException - if the Meta class for the input persistent class is not found. throws: NoSuchMethodException - if the Meta class does not have the 'public static FieldMetaData[] getKeyFields()' method. throws: IllegalAccessException - if the 'public static FieldMetaData[] getKeyFields()' method of the Meta class enforces Java language access control and the underlying method is inaccessible. throws: InvocationTargetException - if the 'public static FieldMetaData[] getKeyFields()' method of the Meta class throws an exception. throws: IllegalArgumentException - if the input persistent class does not have any key-fields or if any of the key-fields is null. a unique String for identifying the persistent object. |
getMetaClass | public static Class getMetaClass(String persistentClassName) throws ClassNotFoundException(Code) | | 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. the meta class. throws: ClassNotFoundException - if the Meta class for the input persistent class is not found. |
loadFromSerializedKey | public static IPersistent loadFromSerializedKey(UOW uow, String serializedKey) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, IllegalArgumentException, IntrospectionException, FrameworkException(Code) | | 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. Parameters: serializedKey - The serialized key which will have the right information to load the persistent object. throws: ClassNotFoundException - if the Persistent class or its Meta class are not found. throws: 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. throws: IllegalAccessException - if the 'public static FieldMetaData[] getKeyFields()' method of the Meta class enforces Java language access control and the underlying method is inaccessible. throws: InvocationTargetException - if the 'public static FieldMetaData[] getKeyFields()' method of the Meta class throws an exception. throws: IllegalArgumentException - if the input persistent class does not have any key-fields or if any of the key-fields is null. throws: IntrospectionException - if an exception occurs during introspection. throws: FrameworkException - if the findByPK() method of the persistent class fails. a Persistent object. |
|
|