com.cinecolombia.common.utilcomponents
Class DAOUtil

java.lang.Object
  |
  +--com.cinecolombia.common.utilcomponents.DAOUtil

public final class DAOUtil
extends java.lang.Object

This utility class for EJB tier components.

Author:
CincoSOFT
Created:
Junio 2003

Constructor Summary
DAOUtil()
           
 
Method Summary
static void closeCallableStatement(java.sql.CallableStatement cstmt)
          Close a CallableStatement
static void closeConnection(java.sql.Connection dbConnection)
          Close database connection associated to dbConnection attribute
static void closePreparedStatement(java.sql.PreparedStatement stmt)
          Close a PreparedStatement statement
static void closeResultSet(java.sql.ResultSet result)
          Close a resultSet
static void closeStatement(java.sql.Statement stmt)
          Close a statement
static byte[] getBlobImage(java.sql.Blob blobRef, byte[] imageArray)
          Get BLOB image from DB
static java.sql.Blob getBlobReference(java.sql.PreparedStatement ps, java.sql.ResultSet rs)
          Obtain reference to BLOB field in the DB
static java.lang.String getBlobText(java.sql.Blob blobRef, byte[] textArray)
          Get BLOB text from DB
static javax.sql.DataSource getDataSource(java.lang.String dsName)
          Get the DataSource associated to a JNDIName
static java.sql.Connection getDBConnection(javax.sql.DataSource datasource)
          Get a database connection
static int getNullInt(java.sql.ResultSet rs, int index)
          metodo auxiliar que obtiene un valor int de un Resultset, posiblemente null,
static long getNullLong(java.sql.ResultSet rs, int index)
          metodo auxiliar que obtiene un valor long de un Resultset, posiblemente null,
static int inputStreamTobyte(java.io.InputStream is, byte[] array, byte[] buf)
          Get byte[] from InputStream
static CodeDescription[] loadCodeDescription(java.sql.PreparedStatement ps, java.sql.ResultSet rs)
          Auxiliary for load a CodeDescription[] from DB
static void rollback(java.sql.Connection dbConnection)
          Rollback current transaction
static void setNullDate(java.sql.PreparedStatement ps, java.sql.Date value, int index)
          metodo auxiliar que asigna un valor, posiblemente null, a un parametro Date de un PreparedStatement
static void setNullInt(java.sql.PreparedStatement ps, int value, int index)
          metodo auxiliar que asigna un valor, posiblemente null, a un parametro int de un PreparedStatement
static void setNullLong(java.sql.PreparedStatement ps, long value, int index)
          metodo auxiliar que asigna un valor, posiblemente null, a un parametro long de un PreparedStatement
static void setNullString(java.sql.PreparedStatement ps, java.lang.String value, int index)
          metodo auxiliar que asigna un valor, posiblemente null, a un parametro String de un PreparedStatement
static void showByteArray(byte[] array)
          Debug: Shows first and last bytes of a byte[]
static void writeBlobData(java.sql.Blob blobRef, java.io.InputStream is)
          Write BLOB data on the DB
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DAOUtil

public DAOUtil()
Method Detail

getDataSource

public static javax.sql.DataSource getDataSource(java.lang.String dsName)
                                          throws DAOException
Get the DataSource associated to a JNDIName

Parameters:
dsName - Description of the Parameter
Returns:
The dataSource value
Throws:
DAOException

getDBConnection

public static java.sql.Connection getDBConnection(javax.sql.DataSource datasource)
                                           throws DAOException
Get a database connection

Parameters:
datasource - Description of the Parameter
Returns:
The dBConnection value
Throws:
DAOException

closeConnection

public static void closeConnection(java.sql.Connection dbConnection)
                            throws DAOException
Close database connection associated to dbConnection attribute

Parameters:
dbConnection - Description of the Parameter
Throws:
DAOException

closeResultSet

public static void closeResultSet(java.sql.ResultSet result)
                           throws DAOException
Close a resultSet

Parameters:
result - is the ResultSet to close
Throws:
DAOException

closeStatement

public static void closeStatement(java.sql.Statement stmt)
                           throws DAOException
Close a statement

Parameters:
stmt - is the Statement to close
Throws:
DAOException

closePreparedStatement

public static void closePreparedStatement(java.sql.PreparedStatement stmt)
                                   throws DAOException
Close a PreparedStatement statement

Parameters:
stmt - is the PreparedStatement to close
Throws:
DAOException

closeCallableStatement

public static void closeCallableStatement(java.sql.CallableStatement cstmt)
                                   throws DAOException
Close a CallableStatement

Parameters:
cstmt - is the PreparedStatement to close
Throws:
DAOException

rollback

public static void rollback(java.sql.Connection dbConnection)
                     throws DAOException
Rollback current transaction

Parameters:
dbConnection - is the connection with the DB
Throws:
DAOException

loadCodeDescription

public static CodeDescription[] loadCodeDescription(java.sql.PreparedStatement ps,
                                                    java.sql.ResultSet rs)
                                             throws java.lang.Exception
Auxiliary for load a CodeDescription[] from DB

Parameters:
ps - auxiliary PreparedStatement
rs - auxiliary ResultSet
Returns:
CodeDescription[]
Throws:
java.lang.Exception

getBlobReference

public static java.sql.Blob getBlobReference(java.sql.PreparedStatement ps,
                                             java.sql.ResultSet rs)
                                      throws java.lang.Exception
Obtain reference to BLOB field in the DB

Parameters:
ps - auxiliary PreparedStatement
rs - auxiliary ResultSet
Returns:
Blob reference to a Blob field
Throws:
java.lang.Exception

writeBlobData

public static void writeBlobData(java.sql.Blob blobRef,
                                 java.io.InputStream is)
                          throws java.lang.Exception
Write BLOB data on the DB

Parameters:
blobRef - reference to a Blob field
is - data (InputStream) to write in the Blob field
Throws:
java.lang.Exception

getBlobText

public static java.lang.String getBlobText(java.sql.Blob blobRef,
                                           byte[] textArray)
                                    throws java.lang.Exception
Get BLOB text from DB

Parameters:
blobRef - reference to a Blob text field
textArray - is an auxiliary byte[] to receive the text from the Blob field
Returns:
String is the gotten text
Throws:
java.lang.Exception

getBlobImage

public static byte[] getBlobImage(java.sql.Blob blobRef,
                                  byte[] imageArray)
                           throws java.lang.Exception
Get BLOB image from DB

Parameters:
blobRef - reference to a Blob text field
imageArray - is an auxiliary byte[] to receive the image from the Blob field
Returns:
byte[] bytes of image
Throws:
java.lang.Exception

inputStreamTobyte

public static int inputStreamTobyte(java.io.InputStream is,
                                    byte[] array,
                                    byte[] buf)
Get byte[] from InputStream

Parameters:
is - InputStream
array - byte[] for storing all the bytes of is
buf - auxiliary byte[] for reading from is
Returns:
number of bytes of is (int)

showByteArray

public static void showByteArray(byte[] array)
Debug: Shows first and last bytes of a byte[]

Parameters:
array - array of bytes

getNullInt

public static int getNullInt(java.sql.ResultSet rs,
                             int index)
                      throws java.lang.Exception
metodo auxiliar que obtiene un valor int de un Resultset, posiblemente null,

Parameters:
rs - el Resultset
index - indice del parametro a obtener.
Returns:
valor int obtenido: si viene e null de la BD se transforma en UNDEF
Throws:
java.lang.Exception

getNullLong

public static long getNullLong(java.sql.ResultSet rs,
                               int index)
                        throws java.lang.Exception
metodo auxiliar que obtiene un valor long de un Resultset, posiblemente null,

Parameters:
rs - el Resultset
index - indice del parametro a obtener.
Returns:
valor long obtenido: si viene e null de la BD se transforma en UNDEF
Throws:
java.lang.Exception

setNullDate

public static void setNullDate(java.sql.PreparedStatement ps,
                               java.sql.Date value,
                               int index)
                        throws java.lang.Exception
metodo auxiliar que asigna un valor, posiblemente null, a un parametro Date de un PreparedStatement

Parameters:
ps - el PreparedStatement
value - el Date posiblemente null
index - indice del parametro a asignar.
Throws:
java.lang.Exception

setNullLong

public static void setNullLong(java.sql.PreparedStatement ps,
                               long value,
                               int index)
                        throws java.lang.Exception
metodo auxiliar que asigna un valor, posiblemente null, a un parametro long de un PreparedStatement

Parameters:
ps - el PreparedStatement
value - si es UNDEF, se asignara null a ps, si no el value
index - indice del parametro a asignar.
Throws:
java.lang.Exception

setNullInt

public static void setNullInt(java.sql.PreparedStatement ps,
                              int value,
                              int index)
                       throws java.lang.Exception
metodo auxiliar que asigna un valor, posiblemente null, a un parametro int de un PreparedStatement

Parameters:
ps - el PreparedStatement
value - si es UNDEF, se asignara null a ps, si no el value
index - indice del parametro a asignar.
Throws:
java.lang.Exception

setNullString

public static void setNullString(java.sql.PreparedStatement ps,
                                 java.lang.String value,
                                 int index)
                          throws java.lang.Exception
metodo auxiliar que asigna un valor, posiblemente null, a un parametro String de un PreparedStatement

Parameters:
ps - el PreparedStatement
value - el String posiblemente null
index - indice del parametro a asignar.
Throws:
java.lang.Exception