package inukisoft.patronesj2ee.facade;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
import javax.sql.DataSource;
import inukisoft.patronesj2ee.model.consulta.dao.SQLConsultaDAO;
import inukisoft.patronesj2ee.model.consulta.dao.SQLConsultaDAOFactory;
import inukisoft.patronesj2ee.model.consulta.vo.ConsultaVO;
import inukisoft.patronesj2ee.model.productosoftware.dao.SQLProductoSoftwareDAO;
import inukisoft.patronesj2ee.model.productosoftware.dao.SQLProductoSoftwareDAOFactory;
import inukisoft.patronesj2ee.model.productosoftware.vo.ProductoSoftwareVO;
import inukisoft.util.configuration.ConfigurationParametersManager;
import inukisoft.util.configuration.MissingConfigurationParameterException;
import inukisoft.util.exceptions.DataBaseException;
import inukisoft.util.exceptions.ExceptionFormatMessage;
import inukisoft.util.exceptions.InstanceNotFoundException;
import inukisoft.util.exceptions.InternalErrorException;
import inukisoft.util.sql.GeneralOperations;
import inukisoft.util.sql.SimpleDataSource;
/**
* @author Constantino Samuel Alarcón Mery
*
* La siguiente clase implementa el patrón Session Façade
* en su modalidad JDBC plain.
* En esta clase se centralizan todos los casos de uso del
* sistema, y será el punto de acceso común al sistema
*/
public class ProductoSoftwareFacade {
/**
* Caso de uso: Agregando producto de software
* Actor: Administrador
* Descripcion: Agrega un nuevo producto de software
* al catálogo de productos del sistema.
* @param vo Objeto Domain VO que encapsula los datos de la tabla
* ProductosSoftware
* @return Un Objeto Domain VO que incluye el identificador autonumético
* con el cual se ingresó
* @throws InternalErrorException Error interno de la capa MODELO
* @throws DataBaseException Error del tipo SQL o de conexión
*/
public ProductoSoftwareVO createProductoSoftware(ProductoSoftwareVO vo)
throws InternalErrorException,DataBaseException {
Connection connection = null;
try {
DataSource dataSource = new SimpleDataSource();
connection = dataSource.getConnection();
SQLProductoSoftwareDAO dao = SQLProductoSoftwareDAOFactory.getDAO();
return dao.create(connection,vo);
}
catch (SQLException e) {
ExceptionFormatMessage.printException(e);
throw new DataBaseException(e);
}
catch (InternalErrorException e) {
ExceptionFormatMessage.printException(e);
throw e;
}
finally {
GeneralOperations.closeConnection(connection);
}
}
/**
* Caso de uso: Enviando consulta de productos
* Actor: Cliente
* Descripcion: Realiza una consulta, la cual es registrada
* en el sistema
* @param vo Un Domain VO que encapsula los datos de la tabla Consulta
* @return vo que incluye el identificador generado para la consulta
* @throws InternalErrorException Error interno de la capa MODELO
* @throws DataBaseException Error del tipo SQL o de conexión
*/
public ConsultaVO createConsulta(ConsultaVO vo)
throws InternalErrorException,DataBaseException {
Connection connection = null;
try {
DataSource dataSource = new SimpleDataSource();
connection = dataSource.getConnection();
SQLConsultaDAO dao = SQLConsultaDAOFactory.getDAO();
return dao.create(connection,vo);
}
catch (SQLException e) {
ExceptionFormatMessage.printException(e);
throw new DataBaseException(e);
}
catch (InternalErrorException e) {
ExceptionFormatMessage.printException(e);
throw e;
}
finally {
GeneralOperations.closeConnection(connection);
}
}
/**
* Caso de uso: Listando consultas de clientes
* Actor: Administrador
* Descripcion: Se listan todas las consultas que han sido
* enviadas por los clientes
* @return Una colección de Domain VO de Consultas
* @throws InternalErrorException Un error interno de la capa MODELO
*/
public Collection listConsulta()
throws InternalErrorException {
Connection connection = null;
try {
DataSource dataSource = new SimpleDataSource();
connection = dataSource.getConnection();
SQLConsultaDAO dao = SQLConsultaDAOFactory.getDAO();
return dao.list(connection,1,dao.count(connection).intValue());
}
catch (SQLException e) {
e.printStackTrace();
return null;
}
catch (InternalErrorException e) {
e.printStackTrace();
return null;
}
catch (InstanceNotFoundException e) {
e.printStackTrace();
return null;
}
finally {
GeneralOperations.closeConnection(connection);
}
}
/**
* Caso de uso: Listando productos de sw
* Actor: Cliente
* Descripcion: Se listan todos los productos de software
* ingresados en el sistema
* @return Una colección de Domain VO de productos de software
* @throws InternalErrorException Un error interno de la capa MODELO
*/
public Collection listProductoSoftware()
throws InternalErrorException {
Connection connection = null;
try {
DataSource dataSource = new SimpleDataSource();
connection = dataSource.getConnection();
SQLProductoSoftwareDAO dao = SQLProductoSoftwareDAOFactory.getDAO();
return dao.list(connection,1,dao.count(connection).intValue());
}
catch (SQLException e) {
e.printStackTrace();
return null;
}
catch (InternalErrorException e) {
e.printStackTrace();
return null;
}
catch (InstanceNotFoundException e) {
e.printStackTrace();
return null;
}
finally {
GeneralOperations.closeConnection(connection);
}
}
/**
* Caso de uso: Eliminando producto
* Actor: Administrador
* Descripcion: Elimina un producto de software del sistema
* @param softwareIdentifier identificador del producto de software
* @throws InternalErrorException un error interno de la capa MODELO
*/
public void removeProductoSoftware(Long softwareIdentifier)
throws InternalErrorException {
Connection connection = null;
try {
DataSource dataSource = new SimpleDataSource();
connection = dataSource.getConnection();
SQLProductoSoftwareDAO dao = SQLProductoSoftwareDAOFactory.getDAO();
dao.remove(connection,softwareIdentifier);
}
catch (SQLException e) {
e.printStackTrace();
}
catch (InternalErrorException e) {
e.printStackTrace();
}
catch (InstanceNotFoundException e) {
e.printStackTrace();
}
finally {
GeneralOperations.closeConnection(connection);
}
}
/**
* Caso de uso: Sin Definir
* Actor: Sin Definir
* Descripcion: Elimina una consulta enviada por el cliente
* @param consultaIdentifier Identificador de la consulta
* @throws InternalErrorException Un error interno de la capa Modelo
*/
public void removeConsulta(Long consultaIdentifier)
throws InternalErrorException {
Connection connection = null;
try {
DataSource dataSource = new SimpleDataSource();
connection = dataSource.getConnection();
SQLConsultaDAO dao = SQLConsultaDAOFactory.getDAO();
dao.remove(connection,consultaIdentifier);
}
catch (SQLException e) {
e.printStackTrace();
}
catch (InternalErrorException e) {
e.printStackTrace();
}
catch (InstanceNotFoundException e) {
e.printStackTrace();
}
finally {
GeneralOperations.closeConnection(connection);
}
}
/**
* Caso de uso: Editando producto
* Actor: Administrador
* Descripcion: Edita un producto de software del sistema
* @param vo un objeto Domain vo con los datos que se deben modificar
* @throws InternalErrorException Un error interno de la capa MODELO
* @throws DataBaseException Un error del tipo SQL o de conexión
*/
public void updateProductoSoftware(ProductoSoftwareVO vo)
throws InternalErrorException, DataBaseException {
Connection connection = null;
try {
DataSource dataSource = new SimpleDataSource();
connection = dataSource.getConnection();
SQLProductoSoftwareDAO dao = SQLProductoSoftwareDAOFactory.getDAO();
dao.update(connection,vo);
}
catch (SQLException e) {
e.printStackTrace();
}
catch (InternalErrorException e) {
e.printStackTrace();
}
catch (InstanceNotFoundException e) {
e.printStackTrace();
}
finally {
GeneralOperations.closeConnection(connection);
}
}
/**
* Caso de uso: Viendo ficha producto
* Actor: Cliente
* Descripcion: La descripción completa del producto de software
* @param softwareIdentifier identificador del producto de software
* @return Domain vo con los datos del producto a ver
* @throws InternalErrorException Un error interno de la capa MODELO
* @throws DataBaseException Un error del tipo SQL o de conexion
*/
public ProductoSoftwareVO findProductoSoftware(Long softwareIdentifier)
throws InternalErrorException,DataBaseException {
Connection connection = null;
try {
DataSource dataSource = new SimpleDataSource();
connection = dataSource.getConnection();
SQLProductoSoftwareDAO dao = SQLProductoSoftwareDAOFactory.getDAO();
return dao.find(connection,softwareIdentifier);
}
catch (SQLException e) {
ExceptionFormatMessage.printException(e);
return null;
}
catch (InternalErrorException e) {
ExceptionFormatMessage.printException(e);
return null;
}
catch (InstanceNotFoundException e) {
ExceptionFormatMessage.printException(e);
return null;
}
finally {
GeneralOperations.closeConnection(connection);
}
}
/**
*
Obtiene un parametro del archivo PatronesJ2EEConfig.properties.
*Se aplica el patrón de diseño Proxy para acceder a un objeto * que puede ser implementado como remoto.
* @param parameter * @return */ public static String getParameter(String parameter) { try { return ConfigurationParametersManager.getParameter(parameter); } catch (MissingConfigurationParameterException e) { e.printStackTrace(); return null; } } }