com.instantbank.common.utilcomponents
Class DAOUtil

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

public final class DAOUtil
extends java.lang.Object

This utility class for EJB tier components.

Author:
Instant-bank (Consuelo Franky)

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 java.lang.String getUserId(javax.ejb.SessionContext context)
          get the current user from the context
static int inputStreamTobyte(java.io.InputStream is, byte[] array, byte[] buf)
          Get byte[] from InputStream
static boolean isUserInRole(javax.ejb.SessionContext context, java.lang.String rol)
          determine if the current user belongs to a role
static CodeDescription[] loadCodeDescription(java.sql.PreparedStatement ps, java.sql.ResultSet rs)
          Auxiliary for load a CodeDescription[] from DB
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, registerNatives, toString, wait, wait, wait
 

Constructor Detail

DAOUtil

public DAOUtil()
Method Detail

getUserId

public static java.lang.String getUserId(javax.ejb.SessionContext context)
                                  throws java.lang.Exception
get the current user from the context
Parameters:
context - is the context
Returns:
The userId value
Throws:
java.lang.Exception -  

isUserInRole

public static boolean isUserInRole(javax.ejb.SessionContext context,
                                   java.lang.String rol)
                            throws java.lang.Exception
determine if the current user belongs to a role
Parameters:
context - is the context
rol - role of sistem
Returns:
The userInRole value
Throws:
java.lang.Exception -  

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 -  

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