com.googlecode.jinahya.sql
Class AbstractDbAccessible<I>

java.lang.Object
  extended by com.googlecode.jinahya.sql.AbstractDbAccessible<I>
Type Parameters:
I - id type parameter
All Implemented Interfaces:
DbAccessible<I>, com.googlecode.jinahya.util.Accessible
Direct Known Subclasses:
DbAccessibleWithLong, DbAccessibleWithString

public abstract class AbstractDbAccessible<I>
extends java.lang.Object
implements DbAccessible<I>

Abstract implementation of DatabaseAccessible.

Author:
Jin Kwon

Field Summary
protected  java.lang.String idColumnName
          id column name.
protected  java.lang.String tableName
          table name.
 
Constructor Summary
AbstractDbAccessible(java.lang.String tableName, java.lang.String idColumnName, int idType)
          Creates a new instance.
 
Method Summary
 boolean delete(java.sql.Connection connection)
          Deletes this element.
protected static java.lang.Byte getByte(java.sql.ResultSet resultSet, java.lang.String columnLabel)
          Reads a Byte from given ResultSet.
protected static byte getByte(java.sql.ResultSet resultSet, java.lang.String columnLabel, byte defaultValue)
          Reads a byte value from given ResultSet.
protected static java.lang.Double getDouble(java.sql.ResultSet resultSet, java.lang.String columnLabel)
          Reads an Float from given ResultSet.
protected static double getDouble(java.sql.ResultSet resultSet, java.lang.String columnLabel, float defaultValue)
          Reads a double value from given ResultSet.
protected static java.lang.Float getFloat(java.sql.ResultSet resultSet, java.lang.String columnLabel)
          Reads an Float from given ResultSet.
protected static float getFloat(java.sql.ResultSet resultSet, java.lang.String columnLabel, float defaultValue)
          Reads a float value from given ResultSet.
 I getId()
          Returns id.
 java.lang.String getIdColumnName()
          Return id column name.
 int getIdType()
          Returns the type of id.
protected static java.lang.Integer getInt(java.sql.ResultSet resultSet, java.lang.String columnLabel)
          Reads an Integer from given ResultSet.
protected static int getInt(java.sql.ResultSet resultSet, java.lang.String columnLabel, int defaultValue)
          Reads an int value from given ResultSet.
protected static java.lang.Long getLong(java.sql.ResultSet resultSet, java.lang.String columnLabel)
          Reads a Long value from given ResultSet.
protected static long getLong(java.sql.ResultSet resultSet, java.lang.String columnLabel, long defaultValue)
          Reads a long value from given ResultSet.
protected static java.lang.Short getShort(java.sql.ResultSet resultSet, java.lang.String columnLabel)
          Reads a Short value from given ResultSet mapped to specified columnLabel.
protected static short getShort(java.sql.ResultSet resultSet, java.lang.String columnLabel, short defaultValue)
          Reads a short value from given resultSet.
 java.lang.String getTableName()
          Returns table name.
protected static java.util.Date getTimestamp(java.sql.ResultSet resultSet, java.lang.String columnLabel)
          Retrieves the value of the designated column in the current row of specified resultSet object as a java.util.Date object in the Java programming language.
protected static java.util.Date getTimestamp(java.sql.ResultSet resultSet, java.lang.String columnLabel, java.util.Calendar cal)
           
 void read(java.sql.ResultSet resultSet)
          Reads information from given resultSet.
 boolean select(java.sql.Connection connection)
          Selects this instance.
 void setId(I id)
          Sets id.
protected static void setTimestamp(java.sql.CallableStatement callableStatement, int parameterIndex, java.util.Date value)
           
protected static void setTimestamp(java.sql.CallableStatement callableStatement, int parameterIndex, java.lang.Long value)
           
protected static void setTimestamp(java.sql.PreparedStatement preparedStatement, int parameterIndex, java.util.Date value)
           
protected static void setTimestamp(java.sql.PreparedStatement preparedStatement, int parameterIndex, java.lang.Long value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.googlecode.jinahya.sql.DbAccessible
insert, read, update
 

Field Detail

tableName

protected final java.lang.String tableName
table name.


idColumnName

protected final java.lang.String idColumnName
id column name.

Constructor Detail

AbstractDbAccessible

public AbstractDbAccessible(java.lang.String tableName,
                            java.lang.String idColumnName,
                            int idType)
Creates a new instance.

Parameters:
tableName - table name
idColumnName - id column name
idType - id type
Method Detail

getByte

protected static java.lang.Byte getByte(java.sql.ResultSet resultSet,
                                        java.lang.String columnLabel)
                                 throws java.sql.SQLException
Reads a Byte from given ResultSet.

Parameters:
resultSet - result set
columnLabel - column label
Returns:
fetched Byte value or null if the column value is null
Throws:
java.sql.SQLException - if an SQL error occurs.

getByte

protected static byte getByte(java.sql.ResultSet resultSet,
                              java.lang.String columnLabel,
                              byte defaultValue)
                       throws java.sql.SQLException
Reads a byte value from given ResultSet.

Parameters:
resultSet - result set
columnLabel - column label
defaultValue - default value
Returns:
fetched byte value or defalutValue if the column value is null
Throws:
java.sql.SQLException - if an SQL error occurs.

getShort

protected static java.lang.Short getShort(java.sql.ResultSet resultSet,
                                          java.lang.String columnLabel)
                                   throws java.sql.SQLException
Reads a Short value from given ResultSet mapped to specified columnLabel.

Parameters:
resultSet - result set
columnLabel - column label
Returns:
fetched Short value or null if the column value is null.
Throws:
java.sql.SQLException - if an SQL error occurs.

getShort

protected static short getShort(java.sql.ResultSet resultSet,
                                java.lang.String columnLabel,
                                short defaultValue)
                         throws java.sql.SQLException
Reads a short value from given resultSet.

Parameters:
resultSet - result set
columnLabel - column label
defaultValue - default value
Returns:
fetched short value or defalutValue if the column value is null.
Throws:
java.sql.SQLException - if an SQL error occurs.

getInt

protected static java.lang.Integer getInt(java.sql.ResultSet resultSet,
                                          java.lang.String columnLabel)
                                   throws java.sql.SQLException
Reads an Integer from given ResultSet.

Parameters:
resultSet - result set
columnLabel - column label
Returns:
read Integer value or null if null
Throws:
java.sql.SQLException - if an SQL error occurs.

getInt

protected static int getInt(java.sql.ResultSet resultSet,
                            java.lang.String columnLabel,
                            int defaultValue)
                     throws java.sql.SQLException
Reads an int value from given ResultSet.

Parameters:
resultSet - result set
columnLabel - column label
defaultValue - default value
Returns:
read int value or defalutValue if null
Throws:
java.sql.SQLException - if an SQL error occurs.

getLong

protected static java.lang.Long getLong(java.sql.ResultSet resultSet,
                                        java.lang.String columnLabel)
                                 throws java.sql.SQLException
Reads a Long value from given ResultSet.

Parameters:
resultSet - result set
columnLabel - column label
Returns:
read Long value or null if null
Throws:
java.sql.SQLException - if an SQL error occurs.

getLong

protected static long getLong(java.sql.ResultSet resultSet,
                              java.lang.String columnLabel,
                              long defaultValue)
                       throws java.sql.SQLException
Reads a long value from given ResultSet.

Parameters:
resultSet - result set
columnLabel - column label
defaultValue - default value
Returns:
read long value or default value if null
Throws:
java.sql.SQLException - if an SQL error occurs.

getFloat

protected static java.lang.Float getFloat(java.sql.ResultSet resultSet,
                                          java.lang.String columnLabel)
                                   throws java.sql.SQLException
Reads an Float from given ResultSet.

Parameters:
resultSet - result set
columnLabel - column label
Returns:
read Float value or null if database value is null
Throws:
java.sql.SQLException - if an SQL error occurs.

getFloat

protected static float getFloat(java.sql.ResultSet resultSet,
                                java.lang.String columnLabel,
                                float defaultValue)
                         throws java.sql.SQLException
Reads a float value from given ResultSet.

Parameters:
resultSet - result set
columnLabel - column label
defaultValue - default value
Returns:
read float value or defalutValue if database value is null
Throws:
java.sql.SQLException - if an SQL error occurs.

getDouble

protected static java.lang.Double getDouble(java.sql.ResultSet resultSet,
                                            java.lang.String columnLabel)
                                     throws java.sql.SQLException
Reads an Float from given ResultSet.

Parameters:
resultSet - result set
columnLabel - column label
Returns:
read Double value or null if database value is null
Throws:
java.sql.SQLException - if an SQL error occurs.

getDouble

protected static double getDouble(java.sql.ResultSet resultSet,
                                  java.lang.String columnLabel,
                                  float defaultValue)
                           throws java.sql.SQLException
Reads a double value from given ResultSet.

Parameters:
resultSet - result set
columnLabel - column label
defaultValue - default value
Returns:
read double value or defalutValue if database value is null
Throws:
java.sql.SQLException - if an SQL error occurs.

getTimestamp

protected static java.util.Date getTimestamp(java.sql.ResultSet resultSet,
                                             java.lang.String columnLabel)
                                      throws java.sql.SQLException
Retrieves the value of the designated column in the current row of specified resultSet object as a java.util.Date object in the Java programming language.

Parameters:
resultSet - resultSet
columnLabel - the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
Returns:
the column value; if the value id SQL NULL, the value returned is null
Throws:
java.sql.SQLException - if the columnLabel is not valid; if a database access error occurs or this method is called on a closed result set

getTimestamp

protected static java.util.Date getTimestamp(java.sql.ResultSet resultSet,
                                             java.lang.String columnLabel,
                                             java.util.Calendar cal)
                                      throws java.sql.SQLException
Throws:
java.sql.SQLException

setTimestamp

protected static void setTimestamp(java.sql.CallableStatement callableStatement,
                                   int parameterIndex,
                                   java.lang.Long value)
                            throws java.sql.SQLException
Throws:
java.sql.SQLException

setTimestamp

protected static void setTimestamp(java.sql.PreparedStatement preparedStatement,
                                   int parameterIndex,
                                   java.lang.Long value)
                            throws java.sql.SQLException
Throws:
java.sql.SQLException

setTimestamp

protected static void setTimestamp(java.sql.CallableStatement callableStatement,
                                   int parameterIndex,
                                   java.util.Date value)
                            throws java.sql.SQLException
Throws:
java.sql.SQLException

setTimestamp

protected static void setTimestamp(java.sql.PreparedStatement preparedStatement,
                                   int parameterIndex,
                                   java.util.Date value)
                            throws java.sql.SQLException
Throws:
java.sql.SQLException

getId

public I getId()
Description copied from interface: DbAccessible
Returns id.

Specified by:
getId in interface DbAccessible<I>
Returns:
id

setId

public void setId(I id)
Description copied from interface: DbAccessible
Sets id.

Specified by:
setId in interface DbAccessible<I>
Parameters:
id - id

getIdType

public final int getIdType()
Description copied from interface: DbAccessible
Returns the type of id.

Specified by:
getIdType in interface DbAccessible<I>
Returns:
id type

getTableName

public final java.lang.String getTableName()
Description copied from interface: DbAccessible
Returns table name.

Specified by:
getTableName in interface DbAccessible<I>
Returns:
table name

getIdColumnName

public final java.lang.String getIdColumnName()
Description copied from interface: DbAccessible
Return id column name.

Specified by:
getIdColumnName in interface DbAccessible<I>
Returns:
id column name.

select

public boolean select(java.sql.Connection connection)
               throws java.sql.SQLException
Description copied from interface: DbAccessible
Selects this instance.

Specified by:
select in interface DbAccessible<I>
Parameters:
connection - connection
Returns:
true if successfully selected; false otherwise.
Throws:
java.sql.SQLException - if an SQL error occurs.

delete

public boolean delete(java.sql.Connection connection)
               throws java.sql.SQLException
Description copied from interface: DbAccessible
Deletes this element.

Specified by:
delete in interface DbAccessible<I>
Parameters:
connection - connection
Returns:
true if successfully deleted; false otherwise.
Throws:
java.sql.SQLException - if an SQL error occurs.

read

public void read(java.sql.ResultSet resultSet)
          throws java.sql.SQLException
Description copied from interface: DbAccessible
Reads information from given resultSet.

Specified by:
read in interface DbAccessible<I>
Parameters:
resultSet - result set
Throws:
java.sql.SQLException - if an SQL error occurs.


Copyright © 2011. All Rights Reserved.