FileDocCategorySizeDatePackage
ProductDAO.javaAPI DocJBoss 4.2.12367Fri Jul 13 20:55:58 BST 2007xpetstore.domain.catalog.dao

ProductDAO

public class ProductDAO extends Object
This is a DAO class for complex db queries that can't be resolved by finders
author
Herve Tchepannou

Fields Summary
private static final String
SQL_FIND_BY_KEY
private Connection
_cnn
Constructors Summary
public ProductDAO(Connection cnn)


    //~ Constructors -----------------------------------------------------------

        
    
        _cnn = cnn;
    
Methods Summary
public xpetstore.util.PagefindByKey(java.lang.String key, int start, int count)

		PreparedStatement stmt = null;
		ResultSet rs = null;
    	try
    	{
        stmt = _cnn.prepareStatement( SQL_FIND_BY_KEY, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY );

        stmt.setString( 1, key );
        stmt.setString( 2, key );
        stmt.setString( 3, key );

        rs = stmt.executeQuery(  );

        return toPage( rs, start, count );
    	}
    	finally
    	{
    		if ( stmt != null )
    		{
    			stmt.close();
    		}
    		if ( rs != null )
    		{
    			rs.close();
    		}
    	}
    
private xpetstore.util.PagetoPage(java.sql.ResultSet rs, int start, int count)

        int       i;
        int       size;
        int       imax = start + count;
        ArrayList lst = new ArrayList(  );

        for ( i = size = 0; rs.next(  ); i++, size++ )
        {
            if ( ( i >= start ) && ( i < imax ) )
            {
                lst.add( new Product( rs.getString( 1 ), rs.getString( 2 ), rs.getString( 3 ) ) );
            }
        }

        return new Page( lst, start, ( start + count ) < size );