/*
* IntegerColumn.java
*/
package org.ngbw.sdk.database;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
/**
* Represents an INTEGER
column from a database table.
*
* @author Paul Hoover
*
*/
class IntegerColumn extends Column {
// nested classes
/**
*
*/
private static class IntegerValue extends MemoryValue {
// public methods
/**
* Sets the value of the object using a row from a ResultSet
object. The row used
* is the one indicated by the current position of the ResultSet
object's cursor.
*
* @param value the ResultSet
object that contains the row
* @param index the offset in the row that indicates the column whose value will be assigned to this object
* @throws SQLException
*/
@Override
public void setValue(ResultSet value, int index) throws SQLException
{
Integer colValue = value.getInt(index);
if (value.wasNull())
colValue = null;
setValue(colValue);
}
/**
* Returns the current value of the object.
*
* @return the current value of the object, or 0
if the value is null
*/
@Override
public Integer getValue()
{
if (m_memValue == null)
return 0;
return m_memValue;
}
/**
* Sets the value of a parameter in a PreparedStatement
object using the current value of the object.
*
* @param statement the PreparedStatement
object for which a parameter will be set
* @param index the offset that indicates the parameter to set
* @throws SQLException
*/
@Override
public void setParamValue(PreparedStatement statement, int index) throws SQLException
{
statement.setInt(index, m_memValue);
}
}
// constructors
/**
* Constructs a column representation and assigns a null
value to it.
*
* @param name the name of the column
* @param nullable whether the column lacks or has a NOT NULL
constraint
*/
IntegerColumn(String name, boolean nullable)
{
super(name, nullable);
}
/**
* Constructs a column representation and assigns the given value to it.
*
* @param name the name of the column
* @param nullable whether the column lacks or has a NOT NULL
constraint
* @param value an initial value to assign to the object
*/
IntegerColumn(String name, boolean nullable, Integer value)
{
super(name, nullable, value);
}
// protected methods
/**
* Returns the SQL data type of the column
*
* @return the SQL data type of the column
*/
@Override
protected int getType()
{
return Types.INTEGER;
}
/**
*
* @return
*/
@Override
protected Value createValue()
{
return new IntegerValue();
}
}