SPT Object Database API

com.sptci.prevayler
Class ConstraintSystem

java.lang.Object
  extended by com.sptci.prevayler.StorageSystem
      extended by com.sptci.prevayler.IndexSystem
          extended by com.sptci.prevayler.ConstraintSystem
All Implemented Interfaces:
AbstractDatabase<PrevalentObject>, DatabaseSystem, Serializable
Direct Known Subclasses:
SearchSystem

abstract class ConstraintSystem
extends IndexSystem

System that abstracts all constraint enforcing rules for the prevalent system.

© Copyright 2008 Sans Pareil Technologies, Inc.

Version:
$Id: ConstraintSystem.java 22 2008-11-24 19:04:25Z sptrakesh $
Author:
Rakesh Vidyadharan 2008-05-23

Nested Class Summary
 
Nested classes/interfaces inherited from class com.sptci.prevayler.StorageSystem
StorageSystem.TaskQueue
 
Field Summary
private static long serialVersionUID
           
 
Fields inherited from class com.sptci.prevayler.StorageSystem
logger
 
Constructor Summary
ConstraintSystem()
           
 
Method Summary
private  void addReference(PrevalentObject object, ForeignKey key, String name)
          Maintain the reference relationships between the specified prevalent object and any other prevalent object the object references.
private  void cascadeDelete(String className, String field, PrevalentObject object, Date executionTime)
          Cascade delete all objects that hold a reference to the specified prevalent object.
protected  void checkFields(PrevalentObject object)
          Over-ridden to check for ForeignKey annotation and check for unique constraint violations.
private  void checkForeignKey(ForeignKey key, PrevalentObject object)
          Check the ForeignKey annotation and check for unique constraint violations.
private  void checkForeignKeys(PrevalentObject object)
          Check the ForeignKeys annotation for the prevalent class and perform actions as necessary.
private  void checkNull(PrevalentObject object)
          Check the NotNull annotation on the prevalent object and its fields and throw exceptions if necessary.
private  void checkNull(String member, PrevalentObject object)
          Check the value of the member identified by the name specified in the prevalent object for null value.
private  void checkNullFields(PrevalentObject object)
          Check all the fields in the prevalent object to see if they have been annotated with the NotNull annotation.
protected  void checkUnique(Field field, PrevalentObject parent, PrevalentObject child)
          Check the specified child prevalent object to see if a unique constraint is defined on the parent object.
protected  void checkUnique(PrevalentObject object)
          Over-ridden to process any ForeignKeys and ForeignKey annotations.
protected  void indexClass(PrevalentObject object)
          Over-ridden to process the foreign key annotations on the prevalent object and manage the @link StorageSystsem#indexMap} as appropriate.
protected  void indexFields(PrevalentObject object)
          Over-ridden to process ForeignKey annotations on the fields of the specified prevalent object and manage the StorageSystem.indexMap as appropriate.
private  void nullReference(String className, String field, PrevalentObject object)
          Set the field in className that refers to object to null.
protected  void preAdd(PrevalentObject object)
          Check the prevalent object specified to ensure that it may be safely added to the prevalent system.
protected  void preDelete(PrevalentObject object, Date executionTime)
          Process any delete constraints configured for the specified prevalent object.
protected  void preDelete(String className, PrevalentObject object, Date executionTime)
          Check the foreign key relationship from instances of the specified class to the prevalent object specified and process as necessary.
private  void processForeignKey(ForeignKey key, PrevalentObject object)
          Process the foreign key annotation for a field declared at the prevalent class level and manage the StorageSystem.indexMap as appropriate.
private  void processForeignKeys(PrevalentObject object)
          Process the foreign keys annotation for the prevalent class.
protected  void remove(PrevalentObject object)
          Over-ridden to remove the references to the prevalent object being removed from the system from the reference storage container.
 
Methods inherited from class com.sptci.prevayler.IndexSystem
index
 
Methods inherited from class com.sptci.prevayler.StorageSystem
generateOid, getIndexStorage, getIndexStorage, getPrimaryStorage, getPrimaryStorage, getReferenceStorage, getReferenceStorage, getRelationStorage, getRelationStorage, getTaskQueue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sptci.prevayler.DatabaseSystem
delete, save
 
Methods inherited from interface com.sptci.prevayler.AbstractDatabase
count, fetch, fetch, fetch, fetchIntersection, fetchUnion, search
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

ConstraintSystem

ConstraintSystem()
Method Detail

preAdd

protected void preAdd(PrevalentObject object)
               throws PrevalentException
Check the prevalent object specified to ensure that it may be safely added to the prevalent system.

Parameters:
object - The prevalent object to check.
Throws:
PrevalentException - If the checking fails.
See Also:
checkUnique(com.sptci.prevayler.PrevalentObject)

preDelete

protected void preDelete(PrevalentObject object,
                         Date executionTime)
                  throws PrevalentException
Process any delete constraints configured for the specified prevalent object.

Parameters:
object - The prevalent object that is to be deleted from the system.
executionTime - The datetime at which the transaction was executed.
Throws:
PrevalentException - If the object cannot be deleted due to constraints or other considerations.
See Also:
preDelete( String, PrevalentObject, Date )

preDelete

protected void preDelete(String className,
                         PrevalentObject object,
                         Date executionTime)
                  throws PrevalentException
Check the foreign key relationship from instances of the specified class to the prevalent object specified and process as necessary. The appropriate actions are defined by the ForeignKey.deleteAction() value.

Parameters:
className - The prevalent class that holds references to the prevalent object to be deleted.
object - The prevalent object to be deleted.
executionTime - The datetime at which the transaction was executed.
Throws:
DeleteException - If the object cannot be deleted due to references to it from other prevalent objects.
PrevalentException - If the prevalent object cannot be deleted.
See Also:
cascadeDelete(java.lang.String, java.lang.String, com.sptci.prevayler.PrevalentObject, java.util.Date), nullReference(java.lang.String, java.lang.String, com.sptci.prevayler.PrevalentObject)

cascadeDelete

private void cascadeDelete(String className,
                           String field,
                           PrevalentObject object,
                           Date executionTime)
                    throws PrevalentException
Cascade delete all objects that hold a reference to the specified prevalent object.

Parameters:
className - The fully qualified class name of the prevalent object that holds a reference to the specified prevalent object that is being deleted.
field - The name of the field in className that is a reference to the prevalent object being deleted.
object - The prevalent object that is being deleted from the system.
executionTime - The datetime at which the transaction was executed.
Throws:
PrevalentException - If errors are encountered while deleting the referencing object.
See Also:
IndexStorage.get(String, Object), AbstractDatabase.fetch(java.lang.Class, java.lang.Object), DatabaseSystem.delete(com.sptci.prevayler.PrevalentObject, java.util.Date)

nullReference

private void nullReference(String className,
                           String field,
                           PrevalentObject object)
                    throws PrevalentException
Set the field in className that refers to object to null. If the field is a Collection, then the object is removed from it.

Parameters:
className - The fully qualified class name of the prevalent object that holds a reference to the specified prevalent object being deleted.
field - The field in className that holds a reference to the prevalent object being deleted.
object - The prevalent object being deleted from the system.
Throws:
PrevalentException - If errors are encountered while setting the field to null.

checkUnique

protected void checkUnique(PrevalentObject object)
                    throws PrevalentException
Over-ridden to process any ForeignKeys and ForeignKey annotations.

Overrides:
checkUnique in class IndexSystem
Parameters:
object - The prevalent object to check.
Throws:
ConstraintException - If unique constraints are violated.
PrevalentException - If errors are encountered while processing the fields of the prevalent object.
See Also:
IndexSystem.checkUnique(com.sptci.prevayler.PrevalentObject), checkForeignKeys(com.sptci.prevayler.PrevalentObject), checkForeignKey(com.sptci.prevayler.annotations.ForeignKey, com.sptci.prevayler.PrevalentObject)

checkForeignKeys

private void checkForeignKeys(PrevalentObject object)
                       throws PrevalentException
Check the ForeignKeys annotation for the prevalent class and perform actions as necessary.

Parameters:
object - The prevalent object whose annotation is to be used to check constraints.
Throws:
ConstraintException - If a unique constraint is violated.
PrevalentException - If exceptions are encountered while processing the fields of the prevalent object.

checkForeignKey

private void checkForeignKey(ForeignKey key,
                             PrevalentObject object)
                      throws PrevalentException
Check the ForeignKey annotation and check for unique constraint violations.

Parameters:
key - The annotation to check for unique constraint.
object - The prevalent object being checked.
Throws:
ConstraintException - If a unique constraint is violated.
PrevalentException - If exceptions are encountered while processing the fields of the prevalent object.
See Also:
addReference(com.sptci.prevayler.PrevalentObject, com.sptci.prevayler.annotations.ForeignKey, java.lang.String)

checkFields

protected void checkFields(PrevalentObject object)
                    throws PrevalentException
Over-ridden to check for ForeignKey annotation and check for unique constraint violations. Super-class implementation is also applied.

Overrides:
checkFields in class IndexSystem
Parameters:
object - The prevalent object to check.
Throws:
ConstraintException - If a unique constraint is violated.
PrevalentException - If exceptions are encountered while processing the fields of the prevalent object.
See Also:
addReference(com.sptci.prevayler.PrevalentObject, com.sptci.prevayler.annotations.ForeignKey, java.lang.String), IndexSystem.checkFields(com.sptci.prevayler.PrevalentObject)

addReference

private void addReference(PrevalentObject object,
                          ForeignKey key,
                          String name)
                   throws PrevalentException
Maintain the reference relationships between the specified prevalent object and any other prevalent object the object references. This method adds support for managed relations.

Parameters:
object - The prevalent object whose references are to be processed.
key - The foreign key annotation for the field.
name - The name of the field that references a prevalent object. This is necessary since the key may not contain the name of the field it references if annotated at the field level.
Throws:
PrevalentException - If errors are encountered while accessing the field in object.

checkNull

private void checkNull(PrevalentObject object)
                throws PrevalentException
Check the NotNull annotation on the prevalent object and its fields and throw exceptions if necessary.

Parameters:
object - The prevalent object that is to be verified.
Throws:
NullException - If the field value is null.
PrevalentException - If errors are encountered while fetching the field value.
See Also:
checkNull( String, PrevalentObject ), checkNullFields(com.sptci.prevayler.PrevalentObject)

checkNull

private void checkNull(String member,
                       PrevalentObject object)
                throws PrevalentException
Check the value of the member identified by the name specified in the prevalent object for null value.

Parameters:
member - The name of the field that is to be checked.
object - The prevalent object to check.
Throws:
NullException - If the field value is null.
PrevalentException - If errors are encountered while fetching the field value.

checkNullFields

private void checkNullFields(PrevalentObject object)
                      throws PrevalentException
Check all the fields in the prevalent object to see if they have been annotated with the NotNull annotation. Annotated fields are checked to ensure that their value is non-null.

Parameters:
object - The prevalent object whose fields are to be checked.
Throws:
NullException - If the field value is null.
PrevalentException - If errors are encountered while fetching the field value.

checkUnique

protected void checkUnique(Field field,
                           PrevalentObject parent,
                           PrevalentObject child)
                    throws ConstraintException
Check the specified child prevalent object to see if a unique constraint is defined on the parent object.

Parameters:
field - The field in parent that the child represents.
parent - The parent prevalent object.
child - The referenced prevalent object in parent
Throws:
ConstraintException - If a unique constratint violation occurs.

indexFields

protected void indexFields(PrevalentObject object)
                    throws PrevalentException
Over-ridden to process ForeignKey annotations on the fields of the specified prevalent object and manage the StorageSystem.indexMap as appropriate. Also processes references from ReferenceStorage to ensure that foreign keys are indexed. Super-class impelementation is also invoked.

Overrides:
indexFields in class IndexSystem
Parameters:
object - The prevalent object to index.
Throws:
PrevalentException - If errors are encountered while processing the object fields.
See Also:
IndexSystem.indexFields(com.sptci.prevayler.PrevalentObject)

indexClass

protected void indexClass(PrevalentObject object)
                   throws PrevalentException
Over-ridden to process the foreign key annotations on the prevalent object and manage the @link StorageSystsem#indexMap} as appropriate. The ReferenceStorage is used to fetch the appropriate referenced prevalent object. The super-class implementation is also invoked.

Overrides:
indexClass in class IndexSystem
Parameters:
object - The prevalent object to process.
Throws:
PrevalentException - If errors are encountered while processing the field values of the prevalent object.
See Also:
processForeignKeys(com.sptci.prevayler.PrevalentObject), processForeignKey(com.sptci.prevayler.annotations.ForeignKey, com.sptci.prevayler.PrevalentObject), IndexSystem.indexClass(com.sptci.prevayler.PrevalentObject)

processForeignKeys

private void processForeignKeys(PrevalentObject object)
                         throws PrevalentException
Process the foreign keys annotation for the prevalent class.

Parameters:
object - The prevalent object that is to be indexed if necessary.
Throws:
PrevalentException - If errors are encountered while fetching the field value.
See Also:
processForeignKey(com.sptci.prevayler.annotations.ForeignKey, PrevalentObject)

processForeignKey

private void processForeignKey(ForeignKey key,
                               PrevalentObject object)
                        throws PrevalentException
Process the foreign key annotation for a field declared at the prevalent class level and manage the StorageSystem.indexMap as appropriate.

Parameters:
key - The annotation being processed.
object - The prevalent object that is to be indexed if necessary.
Throws:
PrevalentException - If errors are encountered while fetching the field value.

remove

protected void remove(PrevalentObject object)
               throws PrevalentException
Over-ridden to remove the references to the prevalent object being removed from the system from the reference storage container. Remove the index for the specified prevalent object. This is typically called prior to deleting a prevalent object.

Overrides:
remove in class IndexSystem
Parameters:
object - The prevalent object to de-index.
Throws:
PrevalentException - If errors are encountered while removing the index for the prevalent object.

SPT Object Database API