Class KeyGeneratorTypeHandlerInteger
java.lang.Object
org.castor.cpa.persistence.sql.keygen.typehandler.KeyGeneratorTypeHandlerInteger
- All Implemented Interfaces:
KeyGeneratorTypeHandler<Integer>
public final class KeyGeneratorTypeHandlerInteger
extends Object
implements KeyGeneratorTypeHandler<Integer>
Class implementing the KeyGeneratorTypeHandler for Integer type.
- Version:
- $Revision$ $Date: 2009-07-13 17:22:43 (Tue, 28 Jul 2009) $
- Author:
- Ahmad Hassan, Ralf Joachim
-
Constructor Summary
ConstructorsConstructorDescriptionKeyGeneratorTypeHandlerInteger(boolean fail) Construct an type handler for integer values.KeyGeneratorTypeHandlerInteger(boolean fail, int allocationSize) -
Method Summary
Modifier and TypeMethodDescriptionAdds the new Type Handler of type T to the provided handler instance at the provided offset.voidbindValue(PreparedStatement stmt, int index, Integer value) Binds the value in the sql preparedstatement at the provided index location.Gets the value from resultset by calling getValue method and then calls the increment method to increment the extracted value.Reads the resultset and return the extracted typehandler value from the resultset.Increments the provided value by ONE.
-
Constructor Details
-
KeyGeneratorTypeHandlerInteger
public KeyGeneratorTypeHandlerInteger(boolean fail) Construct an type handler for integer values.- Parameters:
fail-trueif the type handler should fail when current row of the record set is not valid,falseotherwise.
-
KeyGeneratorTypeHandlerInteger
public KeyGeneratorTypeHandlerInteger(boolean fail, int allocationSize)
-
-
Method Details
-
getNextValue
Gets the value from resultset by calling getValue method and then calls the increment method to increment the extracted value.- Specified by:
getNextValuein interfaceKeyGeneratorTypeHandler<Integer>- 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,SQLException- If database error occurs.
-
getValue
Reads the resultset and return the extracted typehandler value from the resultset.- Specified by:
getValuein interfaceKeyGeneratorTypeHandler<Integer>- 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,SQLException- If database error occurs.
-
increment
Increments the provided value by ONE.- Specified by:
incrementin interfaceKeyGeneratorTypeHandler<Integer>- Parameters:
value- value to be incremented.- Returns:
- Modified TypeHandler object with incremented value..
-
add
Adds the new Type Handler of type T to the provided handler instance at the provided offset.- Specified by:
addin interfaceKeyGeneratorTypeHandler<Integer>- Parameters:
value- Handler instance in which new value will be addedoffset- Offset location. *- Returns:
- Modified object.
-
bindValue
Binds the value in the sql preparedstatement at the provided index location.- Specified by:
bindValuein interfaceKeyGeneratorTypeHandler<Integer>- Parameters:
stmt- A SQL PreparedStatement.index- Index location for binding parameter to statement.value- Value to be binded- Throws:
SQLException- If SQL error occurs in binding param to sql statement.
-