de.mguennewig.pobjects
Class PObjConstraintException

java.lang.Object
  extended by java.lang.Throwable
      extended by java.lang.Exception
          extended by de.mguennewig.pobjects.PObjException
              extended by de.mguennewig.pobjects.PObjConstraintException
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<PObjConstraintException.Entry>

public class PObjConstraintException
extends PObjException
implements java.lang.Iterable<PObjConstraintException.Entry>

Thrown when storing on an object fails (or would fail) because of a Constraint imposed on the object's data.

Constraint checks may be done based on information from the ClassDecl, by a Constraint that can be checked in-memory, or by the database.

Author:
Michael Günnewig
See Also:
PObject.checkConstraints(), CheckConstraint, PrimaryKeyConstraint, Serialized Form

Nested Class Summary
static class PObjConstraintException.Entry
          Helper class holding data on an exception entry.
 
Constructor Summary
PObjConstraintException(Record obj)
          Create a new exception for object obj.
PObjConstraintException(Record obj, Column column, java.lang.String msg)
          Create a new exception with details for object obj.
 
Method Summary
 void add(Column column, java.lang.String msg)
          Adds a new entry to this exception's list of constraint violations.
 void add(Column column, java.lang.String msg, Constraint constraint)
          Like add(Column,String), but also includes constraint in question.
 void add(PObjConstraintException e)
          Adds all entries of the exception e to this instance.
 void addAll(Column[] columns, java.lang.String msg, Constraint constraint)
          Like add(Column,String,Constraint), but for multiple columns, which all get the same message and constraint.
 java.lang.String errorMsgForColumn(Column column)
          If the exception contains an error for the column column, return the error message.
 java.lang.String getMessage()
          Returns a description text for this exception.
 Record getObject()
          Returns the object which violates some constraints.
 java.util.Iterator<PObjConstraintException.Entry> iterator()
          Returns an Iterator over the PObjConstraintException.Entry's.
 int size()
          Returns the number of entries in the exception's list.
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PObjConstraintException

public PObjConstraintException(Record obj)
Create a new exception for object obj.


PObjConstraintException

public PObjConstraintException(Record obj,
                               Column column,
                               java.lang.String msg)
Create a new exception with details for object obj.

Throws:
java.lang.IllegalArgumentException - if no message given.
See Also:
add(Column,String)
Method Detail

add

public final void add(Column column,
                      java.lang.String msg)
Adds a new entry to this exception's list of constraint violations.

Throws:
java.lang.IllegalArgumentException - if no message given.
See Also:
PObjConstraintException(Record,Column,String)

add

public final void add(Column column,
                      java.lang.String msg,
                      Constraint constraint)
Like add(Column,String), but also includes constraint in question.

Throws:
java.lang.IllegalArgumentException - if no message given.

addAll

public final void addAll(Column[] columns,
                         java.lang.String msg,
                         Constraint constraint)
Like add(Column,String,Constraint), but for multiple columns, which all get the same message and constraint.

Throws:
java.lang.IllegalArgumentException - if no message given.

add

public final void add(PObjConstraintException e)
Adds all entries of the exception e to this instance.

This method is used to merge different constraint exceptions.


getObject

public final Record getObject()
Returns the object which violates some constraints.


iterator

public final java.util.Iterator<PObjConstraintException.Entry> iterator()
Returns an Iterator over the PObjConstraintException.Entry's.

Specified by:
iterator in interface java.lang.Iterable<PObjConstraintException.Entry>

size

public final int size()
Returns the number of entries in the exception's list.

If the result is zero, then there aren't any complaints and the exception can be discarded.


errorMsgForColumn

public final java.lang.String errorMsgForColumn(Column column)
If the exception contains an error for the column column, return the error message. If there is no matching entry, result is null.


getMessage

public java.lang.String getMessage()
Returns a description text for this exception.

Overrides:
getMessage in class java.lang.Throwable
See Also:
Throwable.getMessage()