org.castor.cpa.persistence.sql.keygen
Class KeyGeneratorTypeHandlerString

java.lang.Object
  extended by org.castor.cpa.persistence.sql.keygen.KeyGeneratorTypeHandlerString
All Implemented Interfaces:
KeyGeneratorTypeHandler<java.lang.String>

public final class KeyGeneratorTypeHandlerString
extends java.lang.Object
implements KeyGeneratorTypeHandler<java.lang.String>

Class implementing the KeyGeneratorTypeHandler for String type.

Version:
$Revision$ $Date: 2009-07-13 17:22:43 (Tue, 28 Jul 2009) $
Author:
Ahmad Hassan, Ralf Joachim

Constructor Summary
KeyGeneratorTypeHandlerString(boolean fail, int length)
          Construct an type handler for string values.
 
Method Summary
 java.lang.String add(java.lang.String value, int offset)
          Adds the new Type Handler of type T to the provided handler instance at the provided offset.
 void bindValue(java.sql.PreparedStatement stmt, int index, java.lang.String value)
          Binds the value in the sql preparedstatement at the provided index location.
 java.lang.String getNextValue(java.sql.ResultSet rs)
          Gets the value from resultset by calling getValue method and then calls the increment method to increment the extracted value.
 java.lang.String getValue(java.sql.ResultSet rs)
          Reads the resultset and return the extracted typehandler value from the resultset.
 java.lang.String increment(java.lang.String value)
          Increments the provided value by ONE.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KeyGeneratorTypeHandlerString

public KeyGeneratorTypeHandlerString(boolean fail,
                                     int length)
Construct an type handler for string values.

Parameters:
fail - true if the type handler should fail when current row of the record set is not valid, false otherwise.
length - Length of the string.
Method Detail

getNextValue

public java.lang.String getNextValue(java.sql.ResultSet rs)
                              throws PersistenceException,
                                     java.sql.SQLException
Gets the value from resultset by calling getValue method and then calls the increment method to increment the extracted value.

Specified by:
getNextValue in interface KeyGeneratorTypeHandler<java.lang.String>
Parameters:
rs - A ResultSet object.
Returns:
Returns the new value after incrementing it.
Throws:
PersistenceException - If ResultSet is empty or if the type handler should fail when current row of the record set is not valid,
java.sql.SQLException - If database error occurs.

getValue

public java.lang.String getValue(java.sql.ResultSet rs)
                          throws PersistenceException,
                                 java.sql.SQLException
Reads the resultset and return the extracted typehandler value from the resultset.

Specified by:
getValue in interface KeyGeneratorTypeHandler<java.lang.String>
Parameters:
rs - ResultSet object
Returns:
Value extracted from the ResultSet.
Throws:
PersistenceException - If ResultSet is empty or if the type handler should fail when current row of the record set is not valid,
java.sql.SQLException - If database error occurs.

increment

public java.lang.String increment(java.lang.String value)
Increments the provided value by ONE.

Specified by:
increment in interface KeyGeneratorTypeHandler<java.lang.String>
Parameters:
value - value to be incremented.
Returns:
Modified TypeHandler object with incremented value..

add

public java.lang.String add(java.lang.String value,
                            int offset)
Adds the new Type Handler of type T to the provided handler instance at the provided offset.

Specified by:
add in interface KeyGeneratorTypeHandler<java.lang.String>
Parameters:
value - Handler instance in which new value will be added
offset - Offset location. *
Returns:
Modified object.

bindValue

public void bindValue(java.sql.PreparedStatement stmt,
                      int index,
                      java.lang.String value)
               throws java.sql.SQLException
Binds the value in the sql preparedstatement at the provided index location.

Specified by:
bindValue in interface KeyGeneratorTypeHandler<java.lang.String>
Parameters:
stmt - A SQL PreparedStatement.
index - Index location for binding parameter to statement.
value - Value to be binded
Throws:
java.sql.SQLException - If SQL error occurs in binding param to sql statement.


Intalio Inc. (C) 1999-2008. All rights reserved http://www.intalio.com