SilverStream
Application Server 3.5

com.sssw.rt.util
Class AgoSystemDatabaseException

java.lang.Object
 |
 +--java.lang.Throwable
       |
       +--java.lang.Exception
             |
             +--com.sssw.rt.util.AgoException
                   |
                   +--com.sssw.rt.util.AgoApiException
                         |
                         +--com.sssw.rt.util.AgoSystemException
                               |
                               +--com.sssw.rt.util.AgoUnrecoverableSystemException
                                     |
                                     +--com.sssw.rt.util.AgoSystemDatabaseException
All Implemented Interfaces:
AgiParentedException, Serializable

public class AgoSystemDatabaseException
extends AgoUnrecoverableSystemException

The subclass of AgoUnrecoverableSystemException that indicates that the system exception occurred during a database operation, and conveys additional database status information. Most often, this additional status information is obtained from a JDBC SQL Exception.

See Also:
Serialized Form

Constructor Summary
AgoSystemDatabaseException(String message)
          AgoSystemDatabaseException constructor.
AgoSystemDatabaseException(Throwable parent, String message)
          AgoSystemDatabaseException constructor.
 
Method Summary
 char getCommandCode()
          Return the command code that describes the database command that was being performed when the exception occured.
 int getErrorCode()
          Get the database error code.
 String getFieldName()
          Return the name of the field that was being updated when the database exception occurred, if known.
 String getRowKey()
          Get the "row key" which identifies the data row on which an exception occurred.
 void setCommandCode(char commandCode)
          setCommandCode.
 void setErrorCode(int errorCode)
          Save the database error code
 void setFieldName(String f)
          Set the name of the field that was being updated when the database exception occurred, if known.
 void setRowKey(String rowKey)
          Set the "row key" which identifies the data row on which an exception occurred.
 
Methods inherited from class com.sssw.rt.util.AgoException
copyTo, getExceptionHTML, getExceptionMessage, getExceptionMessage, getHTML, getMessage, getMessage, getParentException, printStackTrace, printStackTrace, printStackTrace, setHTML
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getLocalizedMessage, printStackTrace, printStackTrace, printStackTrace, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods implemented from interface com.sssw.rt.util.AgiParentedException
getExceptionParent
 

Constructor Detail

AgoSystemDatabaseException

public AgoSystemDatabaseException(String message)
AgoSystemDatabaseException constructor.

AgoSystemDatabaseException

public AgoSystemDatabaseException(Throwable parent,
                                  String message)
AgoSystemDatabaseException constructor.
Method Detail

setErrorCode

public void setErrorCode(int errorCode)
Save the database error code
Parameters:
errorCode - the database error code, typically from a SQLException
Example:

This example might occur in a data source object.

 try {
     ResultSet rs = statement.executeUpdate("insert into atable set (id) values (5)");
 } catch (SQLException sqlX) {
     AgoSystemDatabaseException ex = new AgoSystemDatabaseException(sqlX, "Unable to perform insert");
     ex.setErrorCode(sqlX.getErrorCode());
     throw ex;
 }
 
See Also:
AgoSystemDatabaseException.getErrorCode()

getErrorCode

public int getErrorCode()
Get the database error code.
Example:
 try {
     agData.query("ID > 5", "ID asc");
 } catch (AgSystemDatabaseException ex) {
     System.out.println("A database exception occurred on the query: " +
                        ex.getMessage() +
                        "\nThe error code was " +
                        ex.getCommandCode());
 }
 
See Also:
AgoSystemDatabaseException.setErrorCode(int)

setRowKey

public void setRowKey(String rowKey)
Set the "row key" which identifies the data row on which an exception occurred.
Parameters:
rowKey - the row identifier for this data row, typically obtained from the data row's getRowKey() operation
Example:
 AgiDataRow nextRow;
 int colNo = 1;
 try {
     statement.setString(colNo+1, nextRow.getData(colNo));
 } catch (SQLException sqlX) {
     AgoSystemDatabaseException ex = new AgoSystemDatabaseException(sqlX, "Exception binding column value");
     ex.setRowKey(nextRow.getRowKey());
     throw ex;
 }
 
See Also:
AgoSystemDatabaseException.getRowKey()

getRowKey

public String getRowKey()
Get the "row key" which identifies the data row on which an exception occurred.
Example:
 try {
     agData.updateRows();
 } catch (AgSystemDatabaseException ex) {
     System.out.println("A database exception occurred while updating row " +
                        ex.getRowKey() +
                        "\nThe exception was " +
                        ex.getMessage());
 }
 
See Also:
AgoSystemDatabaseException.setRowKey(String)

setCommandCode

public void setCommandCode(char commandCode)
setCommandCode.
Parameters:
commandCode - the command code describing the database command being executed, from CommandCodes.
Example:

This example might occur in a data source object.

 try {
     ResultSet rs = statement.executeUpdate("insert into atable set (id) values (5)");
 } catch (SQLException sqlX) {
     AgoSystemDatabaseException ex = new AgoSystemDatabaseException(sqlX, "Unable to perform database update");
     ex.setCommandCode(CommandCodes.CCINSERT);
     throw ex;
 }
 
See Also:
AgoSystemDatabaseException.getCommandCode(), CommandCodes

getCommandCode

public char getCommandCode()
Return the command code that describes the database command that was being performed when the exception occured. The command codes are listed in CommandCodes.
Example:
 try {
     agData.updateRows();
 } catch (AgSystemDatabaseException ex) {
     System.out.println("A database exception during a " +
                        ex.getCommandCode() +
                        "operation.\nThe exception was: " +
                        ex.getMessage());
 }
 
See Also:
AgoSystemDatabaseException.setCommandCode(char), CommandCodes

getFieldName

public String getFieldName()
Return the name of the field that was being updated when the database exception occurred, if known. Normally what is returned is actually an integer giving the column number of the field on which the error occurred (0-based). The value will be "-1" if the field was not known.
Example:
 try {
     agData.updateRows();
 } catch (AgSystemDatabaseException ex) {
     System.out.println("A database exception occurred during update: " +
                        ex.getMessage());
     String field = ex.getFieldName();
     if (!field.equals("-1")) {
         System.out.println("The error occurred on column " +
             agData.getPropertyName(Integer.parseInt(field)));
     }
 }
 
See Also:
AgoSystemDatabaseException.setFieldName(String)

setFieldName

public void setFieldName(String f)
Set the name of the field that was being updated when the database exception occurred, if known. Normally what is returned is actually an integer giving the column number of the field on which the error occurred (0-based). The value will be "-1" if the field was not known.
Parameters:
f - the field name, should be "-1" if unknown
Example:
 int colNo = 1;
 try {
     statement.setString(colNo+1, "A fine kettle of fish");
 } catch (SQLException sqlX) {
     AgoSystemDatabaseException ex = new AgoSystemDatabaseException(sqlX, "Exception binding column value");
     ex.setFieldName(Integer.toString(colNo));
     throw ex;
 }
 
See Also:
AgoSystemDatabaseException.getFieldName()

SilverStream
Application Server 3.5