/*
* DemoBO.java - 3-Apr-2005
*
* Copyright (c) 2005 Sandoval Software Solutions Inc.
*
* All rights reserved.
*/
package com.josesandoval.demo.business;
import java.io.InputStream;
import java.util.List;
import java.util.Properties;
import ca.sandoval.util.DBUtil;
import ca.sandoval.util.PropertiesUtil;
import com.josesandoval.demo.Constants;
import com.josesandoval.demo.model.DemoVO;
/**
* DemoBO
*
*
*
*
*
*
* @author Sandoval Software Solutions Inc.
* @version 3-Apr-2005
*/
public class DemoBO {
// We need the SQL for the application
// Many different ways you can do this, however, doing in the BO makes sense
// and since it will not change for every user, make it static
private static final Properties propertiesSQL = new PropertiesUtil(Constants.SQL_DEMO_PROPERTIES);
/**
* Create record.
*
* @param vo
*/
public static void create(DemoVO vo) throws Exception {
// SQL looks like: INSERT INTO demo (name, lastName) VALUES (?, ?)
// Hence, params needs to hold the values we want in the '?' holders
Object[] params = new Object[] {vo.getName(), vo.getLastName()};
// Create record in the database via DBUtil
// Here is where DAO is taking place
DBUtil.update(Constants.POOL_NAME, propertiesSQL.getProperty(Constants.SQL_CREATE), params);
// Note that you don't have to worry about the implementation of the DB pool nor
// which DB you are using - Also note that you don't have to worry about open connection
// result sets, etc, etc.
}
/**
* Retrieve all records.
*
* @return
* @throws Exception
*/
public static List retrieve() throws Exception {
// SQL looks like: SELECT name, lastName FROM demo
// We need to retrieve all the records - Note there are no parameters in the SQL
// Note the DemoVO.class parameter - DBUtil will know how to process the ResultSet
// and convert them to DemoVO and fill up the List to return
return DBUtil.query(Constants.POOL_NAME, propertiesSQL.getProperty(Constants.SQL_RETRIEVE), DemoVO.class);
// Note that you don't have to worry about the implementation of the DB pool nor
// which DB you are using - Also note that you don't have to worry about open connection
// result sets, etc, etc.
}
}