<file_sep>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package service;

import entity.Company;
import vo.CompanyVO;
import dao.CompanyDAO;
import dao.DAOFactory;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;

/**
 *
 * @author ESTUDIANTE
 */
public class CompanyService extends BaseService {
    
    public CompanyVO newCompany(CompanyVO companyVO) {
        EntityManager em = this.getNewEntityManager();
        EntityTransaction trans = em.getTransaction();
        CompanyDAO companyDAO = DAOFactory.getCompanyDAO(em);
        Company company = companyVO.toEntity();
        try {
            trans.begin();
            companyDAO.save(company);
            trans.commit();
        } catch (Exception e) {
            System.err.println(e.getMessage());
        } finally {
            em.clear();
            em.close();                
        }
        if(company == null){
            return null;
        }
        return company.toVO();
    }

    public CompanyVO findCompany(Long id) {
        EntityManager em = this.getNewEntityManager();
        EntityTransaction trans = em.getTransaction();
        CompanyDAO companyDAO = DAOFactory.getCompanyDAO(em);
        Company company = null;
        try {
            trans.begin();
            company = companyDAO.find(id);
            trans.commit();
        } catch (Exception e) {
            System.err.println(e.getMessage());
        } finally {
            em.clear();
            em.close();                
        }
        if(company == null){
            return null;
        }
        return company.toVO();
    }

    public List<CompanyVO> allCompanies() {
        EntityManager em = this.getNewEntityManager();
        EntityTransaction trans = em.getTransaction();
        CompanyDAO companyDAO = DAOFactory.getCompanyDAO(em);
        List<Company> companies = null;
        List<CompanyVO> companysVO = new ArrayList<CompanyVO>();
        
        try {
            trans.begin();
            companies = companyDAO.getAll();
            trans.commit();
        } catch (Exception e) {
            System.err.println(e.getMessage());
        } finally {
            em.clear();
            em.close();
        }
        
        if(companies == null){
            return null;
        }
        
        for (Company company : companies) {
            companysVO.add(company.toVO());
        }
        
        return companysVO;       
        
    }

    public List<CompanyVO> findCompaniesByMarketId(int market_id) {
        EntityManager em = this.getNewEntityManager();
        EntityTransaction trans = em.getTransaction();
        CompanyDAO companyDAO = DAOFactory.getCompanyDAO(em);
        List<Company> comanies = null;
        List<CompanyVO> companysVO = new ArrayList<CompanyVO>();
        
        try {
            trans.begin();
            comanies = companyDAO.findByMarketId(market_id);
            trans.commit();
        } catch (Exception e) {
            System.err.println(e.getMessage());
        } finally {
            em.clear();
            em.close();
        }
        
        for (Company company : comanies) {
            companysVO.add(company.toVO());
        }
        
        return companysVO;       
    }
    
    public boolean updateCompany(CompanyVO companyVO) {
        EntityManager em = this.getNewEntityManager();
        EntityTransaction trans = em.getTransaction();
        CompanyDAO companyDAO = DAOFactory.getCompanyDAO(em);
        boolean flag = true;
        try {
            trans.begin();
            companyDAO.save(companyVO.toEntity());
            trans.commit();
        } catch (Exception e) {
            trans.rollback();
            flag = false;
            System.err.println(e.getMessage());
        } finally {
            em.clear();
            em.close();
        }   
        
        return flag;
    }
    
    public boolean deleteCompany(long id) {
        EntityManager em = this.getNewEntityManager();
        EntityTransaction trans = em.getTransaction();
        CompanyDAO companyDAO = DAOFactory.getCompanyDAO(em);
        boolean flag = true;
        try {
            trans.begin();
            companyDAO.delete(id);
            trans.commit();
        } catch (Exception e) {
            trans.rollback();
            flag = false;
            System.err.println(e.getMessage());
        } finally {
            em.clear();
            em.close();
        }   
        
        return flag;
    }

}
<file_sep>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import vo.DateVO;
import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;

/**
 *
 * @author LOPEZ
 */
@Entity
public class Date implements Serializable {

   // private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long date_id;
    private int date_day;
    private int date_month;
    private java.sql.Date date_string;
    private int date_year;

    @OneToMany(mappedBy = "date")
    private Collection<Quote> quoteCollection;

    public Long getId() {
        return getDate_id();
    }

    public void setId(Long id) {
        this.setDate_id(id);
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (getDate_id() != null ? getDate_id().hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Date)) {
            return false;
        }
        Date other = (Date) object;
        if ((this.getDate_id() == null && other.getDate_id() != null) || (this.getDate_id() != null && !this.date_id.equals(other.date_id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.Date[ id=" + getDate_id() + " ]";
    }

    /**
     * @return the date_id
     */
    public Long getDate_id() {
        return date_id;
    }

    /**
     * @param date_id the date_id to set
     */
    public void setDate_id(Long date_id) {
        this.date_id = date_id;
    }

    /**
     * @return the daet_Day
     */
    public int getDate_day() {
        return date_day;
    }

    /**
     * @param daet_Day the daet_Day to set
     */
    public void setDate_day(int daet_Day) {
        this.date_day = daet_Day;
    }

    /**
     * @return the date_month
     */
    public int getDate_month() {
        return date_month;
    }

    /**
     * @param date_month the date_month to set
     */
    public void setDate_month(int date_month) {
        this.date_month = date_month;
    }

    /**
     * @return the date_string
     */
    public java.sql.Date getDate_string() {
        return date_string;
    }

    /**
     * @param date_string the date_string to set
     */
    public void setDate_string(java.sql.Date date_string) {
        this.date_string = date_string;
    }

    /**
     * @return the date_year
     */
    public int getDate_year() {
        return date_year;
    }

    /**
     * @param date_year the date_year to set
     */
    public void setDate_year(int date_year) {
        this.date_year = date_year;
    }

    public DateVO toVO() {
        
        DateVO dateVO = new DateVO();
        dateVO.setDateDay(this.getDate_day());
        dateVO.setDateId(this.getDate_id());
        dateVO.setDateMonth(this.date_month);        
        dateVO.setDateString(this.getDate_string());
        dateVO.setDate_year(this.getDate_year());
        return dateVO;
    }

    

    public java.sql.Date StringtoDate(String strFecha) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        java.sql.Date fecha = null;

        try {

            java.util.Date parsed = format.parse(strFecha);
            fecha = new java.sql.Date(parsed.getTime());

        } catch (ParseException ex) {

            ex.printStackTrace();
        } catch (Exception ex) {

            ex.printStackTrace();
        }

        return fecha;
    }

}
<file_sep>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import vo.RoleVO;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

/**
 *
 * @author LOPEZ
 */
@Entity
public class Role implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "rol_id")
    private Long id;
    private String rol_name;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Role)) {
            return false;
        }
        Role other = (Role) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.Role[ id=" + id + " ]";
    }

    /**
     * @return the rol_name
     */
    public String getRol_name() {
        return rol_name;
    }

    /**
     * @param rol_name the rol_name to set
     */
    public void setRol_name(String rol_name) {
        this.rol_name = rol_name;
    }

    public RoleVO getVO() {
        RoleVO rolVO = new RoleVO();
        rolVO.setRolId(this.id.intValue());
        rolVO.setRolName(this.rol_name);

        return rolVO;

    }

    public Role setVO(RoleVO rolVO) {
        this.id = new Long(rolVO.getRolId());
        this.rol_name = rolVO.getRolName();
        return this;
    }
}
<file_sep>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import vo.UserVO;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

/**
 *
 * @author LOPEZ
 */
@Entity
public class User implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long user_id;

    private String name;
    private String pass;
    private int role_id;

    public Long getId() {
        return user_id;
    }

    public void setId(Long id) {
        this.user_id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (user_id != null ? user_id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof User)) {
            return false;
        }
        User other = (User) object;
        if ((this.user_id == null && other.user_id != null) || (this.user_id != null && !this.user_id.equals(other.user_id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.Usuario[ id=" + user_id + " ]";
    }

    public UserVO getVO() {

        UserVO userVO = new UserVO();
        userVO.setName(name);
        userVO.setPass(pass);
        userVO.setRole_id(role_id);
        userVO.setUser_id(this.user_id.intValue());

        return userVO;
    }

    public User setVO(UserVO userVO) {
        this.name = userVO.getName();
        this.pass = userVO.getPass();
        this.role_id = userVO.getRole_id();
        this.user_id = new Long(userVO.getUser_id());
        return this;
    }

}
<file_sep>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import entity.Company;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Query;

/**
 *
 * @author LOPEZ
 */
public class CompanyDAO extends BaseDAO<Company> {
    
    public CompanyDAO(EntityManager em) {
        super(em);
        
    } 

    public List<Company> findByMarketId(int marketId) {

        Query query = this.em.createQuery("SELECT e FROM Company e WHERE e.market_id=:market_id");
        query.setParameter("market_id", marketId);        
        List<Company> companies = query.getResultList();

        return companies;
    }

}
<file_sep>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package vo;

/**
 *
 * @author windows 7
 */
public class RoleVO {

    private int rolId;
    private String rolName;

   
    public int getRolId() {
        return rolId;
    }

   
    public void setRolId(int rolId) {
        this.rolId = rolId;
    }

   
    public String getRolName() {
        return rolName;
    }

    
    public void setRolName(String rolName) {
        this.rolName = rolName;
    }
    
    
}

<file_sep>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import vo.CompanyVO;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

/**
 *
 * @author LOPEZ
 */
@Entity
public class Company implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long company_id;
    private String company_description;
    private String company_name;
    private int market_id;
    private String company_symbol;
    
    public Long getId() {
        return company_id;
    }

    public void setId(Long id) {
        this.company_id = id;
    } 

    /**
     * @return the company_id
     */
    public Long getCompany_id() {
        return company_id;
    }

    /**
     * @param company_id the company_id to set
     */
    public void setCompany_id(Long company_id) {
        this.company_id = company_id;
    }

    /**
     * @return the company_description
     */
    public String getCompany_description() {
        return company_description;
    }

    /**
     * @param company_description the company_description to set
     */
    public void setCompany_description(String company_description) {
        this.company_description = company_description;
    }

    /**
     * @return the market_name
     */
    public String getCompany_name() {
        return company_name;
    }

    /**
     * @param market_name the market_name to set
     */
    public void setCompany_name(String market_name) {
        this.company_name = market_name;
    }

    /**
     * @return the market_id
     */
    public int getMarket_id() {
        return market_id;
    }

    /**
     * @param market_id the market_id to set
     */
    public void setMarket_id(int market_id) {
        this.market_id = market_id;
    }

    /**
     * @return the company_symbol
     */
    public String getCompany_symbol() {
        return company_symbol;
    }

    /**
     * @param company_symbol the company_symbol to set
     */
    public void setCompany_symbol(String company_symbol) {
        this.company_symbol = company_symbol;
    }
    
    @Override
    public String toString() {
        return "Entity.Company[ id=" + company_id + " ]";
    }
    
    
    
    public CompanyVO toVO(){
     CompanyVO companyVO = new CompanyVO();     
     companyVO.setCompanyDescription(this.getCompany_description());
     companyVO.setCompanyId(this.getCompany_id());
     companyVO.setCompanyName(this.getCompany_name());
     companyVO.setMarketId(this.getMarket_id());
     companyVO.setCompanySymbol(this.getCompany_symbol());
     return companyVO;
        
    }
    
}
<file_sep>package vo;

import entity.Date;
import entity.Quote;
import entity.Stock;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author ESTUDIANTE
 */
public class QuoteVO {
    
    private Long quoteId;    
    private double quote;
    private double quoteHigh;    
    private double quoteLow;
    private double quoteOpen;
    private double quoteClose;    
    private Stock stock;
    private Date date;
   

    /**
     * @return the quote
     */
    public double getQuote() {
        return quote;
    }

    /**
     * @param quote the quote to set
     */
    public void setQuote(double quote) {
        this.quote = quote;
    }

    /**
     * @return the quoteHigh
     */
    public double getQuoteHigh() {
        return quoteHigh;
    }

    /**
     * @param quoteHigh the quoteHigh to set
     */
    public void setQuoteHigh(double quoteHigh) {
        this.quoteHigh = quoteHigh;
    }

    public Long getQuoteId() {
        return quoteId;
    }

    public void setQuoteId(Long quoteId) {
        this.quoteId = quoteId;
    }

    public Stock getStock() {
        return stock;
    }

    public void setStock(Stock stock) {
        this.stock = stock;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    

    /**
     * @return the quoteLow
     */
    public double getQuoteLow() {
        return quoteLow;
    }

    /**
     * @param quoteLow the quoteLow to set
     */
    public void setQuoteLow(double quoteLow) {
        this.quoteLow = quoteLow;
    }

    /**
     * @return the quoteOpen
     */
    public double getQuoteOpen() {
        return quoteOpen;
    }

    /**
     * @param quoteOpen the quoteOpen to set
     */
    public void setQuoteOpen(double quoteOpen) {
        this.quoteOpen = quoteOpen;
    }
    

    /**
     * @return the quoteClose
     */
    public double getQuoteClose() {
        return quoteClose;
    }

    /**
     * @param quoteClose the quoteClose to set
     */
    public void setQuoteClose(double quoteClose) {
        this.quoteClose = quoteClose;
    }    

   
    
    public Quote toEntity(){
        Quote entity = new Quote();
        entity.setQuote_id(this.getQuoteId());
        entity.setQuote_open(this.getQuoteOpen());
        entity.setQuote_high(this.getQuoteHigh());
        entity.setQuote_low(this.getQuoteLow());
        entity.setQuote_close(this.getQuoteClose());
        entity.setDate(this.getDate());
        entity.setStock(this.getStock());
        return entity;
    }
    
}
<file_sep>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package service;

import dao.DAOFactory;
import entity.Market;
import vo.MarketVO;
import dao.MarketDAO;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;

/**
 *
 * @author ESTUDIANTE
 */
public class MarketService extends BaseService {
    
    public MarketVO newMarket(MarketVO marketVO) {
        EntityManager em = this.getNewEntityManager();
        EntityTransaction trans = em.getTransaction();
        MarketDAO marketDAO = DAOFactory.getMarketDAO(em);
        Market market = marketVO.toEntity();
        try {
            trans.begin();
            marketDAO.save(market);
            trans.commit();
        } catch (Exception e) {
            System.err.println(e.getMessage());
        } finally {
            em.clear();
            em.close();                
        }
        if(market == null){
            return null;
        }
        return market.toVO();
    }
    
    public MarketVO findMarket(Long id) {
        EntityManager em = this.getNewEntityManager();
        EntityTransaction trans = em.getTransaction();
        MarketDAO companyDAO = DAOFactory.getMarketDAO(em);
        Market market = null;
        try {
            trans.begin();
            market = companyDAO.find(id);
            trans.commit();
        } catch (Exception e) {
            System.err.println(e.getMessage());
        } finally {
            em.clear();
            em.close();                
        }
        if(market == null){
            return null;
        }
        return market.toVO();
    }
    
    public List<MarketVO> allMarkets() {
        EntityManager em = this.getNewEntityManager();
        EntityTransaction trans = em.getTransaction();
        MarketDAO companyDAO = DAOFactory.getMarketDAO(em);
        List<Market> markets = null;
        List<MarketVO> marketsVO = new ArrayList<MarketVO>();
        try {
            trans.begin();
            markets = companyDAO.getAll();
            trans.commit();
        } catch (Exception e) {
            System.err.println(e.getMessage());
        } finally {
            em.clear();
            em.close();                
        }
        if(markets == null){
            return null;
        }
        for (Market market : markets) {
            marketsVO.add(market.toVO());
        }
        
        return marketsVO;
    }
    
    public boolean updateMarket(MarketVO marketVO) {
        EntityManager em = this.getNewEntityManager();
        EntityTransaction trans = em.getTransaction();
        MarketDAO marketDAO = DAOFactory.getMarketDAO(em);
        boolean flag = true;
        Market market = marketVO.toEntity();
        try {
            trans.begin();
            marketDAO.update(market);
            trans.commit();
        } catch (Exception e) {
            trans.rollback();
            flag = false;
            System.err.println(e.getMessage());
        } finally {
            em.clear();
            em.close();
        }
        
        return flag;
    }
    
    public boolean deleteMarket(Long id) {
        EntityManager em = this.getNewEntityManager();
        EntityTransaction trans = em.getTransaction();
        MarketDAO marketDAO = DAOFactory.getMarketDAO(em);
        boolean flag = true;        
        try {
            trans.begin();
            marketDAO.delete(id);
            trans.commit();
        } catch (Exception e) {
            trans.rollback();
            flag = false;
            System.err.println(e.getMessage());
        } finally {
            em.clear();
            em.close();
        }
        
        return flag;
    }
}
<file_sep>package vo;


import entity.Date;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author ESTUDIANTE
 */
public class DateVO {
    
    private int dateDay;
    private Long dateId;
    private int dateMonth;
    private java.sql.Date dateString;
    private int date_year;

    /**
     * @return the dareDay
     */
    public int getDateDay() {
        return dateDay;
    }

    /**
     * @param dateDay the dareDay to set
     */
    public void setDateDay(int dateDay) {
        this.dateDay = dateDay;
    }

    public Long getDateId() {
        return dateId;
    }

    public void setDateId(Long dateId) {
        this.dateId = dateId;
    }

    

    /**
     * @return the dateMonth
     */
    public int getDateMonth() {
        return dateMonth;
    }

    /**
     * @param dateMonth the dateMonth to set
     */
    public void setDateMonth(int dateMonth) {
        this.dateMonth = dateMonth;
    }

    /**
     * @return the dateString
     */
    public java.sql.Date getDateString() {
      
        return dateString;
    }

    /**
     * @param dateString the dateString to set
     */
    public void setDateString(java.sql.Date dateString) {
        this.dateString = dateString;
    }

    /**
     * @return the date_year
     */
    public int getDate_year() {
        return date_year;
    }

    /**
     * @param date_year the date_year to set
     */
    public void setDate_year(int date_year) {
        this.date_year = date_year;
    }
    
    public Date toEntity(){
        Date entity = new Date();        
        entity.setDate_id(this.getDateId());
        entity.setDate_day(this.getDateDay());
        entity.setDate_month(this.getDateMonth());
        entity.setDate_year(this.getDate_year());
        entity.setDate_string(this.getDateString());
        return entity;
    }
}
<file_sep>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package service;

import dao.DAOFactory;
import entity.Date;
import vo.DateVO;
import dao.DateDAO;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;

/**
 *
 * @author ESTUDIANTE
 */
public class DateService extends BaseService {
    
    public DateVO findDate(Long id) {
        EntityManager em = this.getNewEntityManager();
        EntityTransaction trans = em.getTransaction();
        DateDAO dateDAO = DAOFactory.getDateDAO(em);
        Date date = null;
        try {
            trans.begin();
            date = dateDAO.find(id);
            trans.commit();
        } catch (Exception e) {
            System.err.println(e.getMessage());
        } finally {
            em.clear();
            em.close();                
        }
        if(date == null){
            return null;
        }
        return date.toVO();
    }
    
    public List<DateVO> allDates() {
        EntityManager em = this.getNewEntityManager();
        EntityTransaction trans = em.getTransaction();
        DateDAO dateDAO = DAOFactory.getDateDAO(em);
        List<Date> dates = null;
        List<DateVO> datesVO = new ArrayList<DateVO>();
        
        try {
            trans.begin();
            dates = dateDAO.getAll();
            trans.commit();
        } catch (Exception e) {
            System.err.println(e.getMessage());
        } finally {
            em.clear();
            em.close();
        }
        
        for (Date date : dates) {
            datesVO.add(date.toVO());
        }
        
        return datesVO;       
        
    }
    
    public DateVO newDate(DateVO dateVO) {
        EntityManager em = this.getNewEntityManager();
        EntityTransaction trans = em.getTransaction();
        DateDAO dateDAO = DAOFactory.getDateDAO(em);
        Date date = dateVO.toEntity();
        try {
            trans.begin();
            dateDAO.save(date);
            trans.commit();
        } catch (Exception e) {
            System.err.println(e.getMessage());
        } finally {
            em.clear();
            em.close();                
        }
        if(date == null){
            return null;
        }
        return date.toVO();
    }
    
    public boolean updateDate(DateVO dateVO) {
        EntityManager em = this.getNewEntityManager();
        EntityTransaction trans = em.getTransaction();
        DateDAO dateDAO = DAOFactory.getDateDAO(em);
        boolean flag = true;
        try {
            trans.begin();
            dateDAO.save(dateVO.toEntity());
            trans.commit();
        } catch (Exception e) {
            trans.rollback();
            flag = false;
            System.err.println(e.getMessage());
        } finally {
            em.clear();
            em.close();
        }   
        
        return flag;
    }
    public boolean deleteDate(Long id) {
        EntityManager em = this.getNewEntityManager();
        EntityTransaction trans = em.getTransaction();
        DateDAO dateDAO = DAOFactory.getDateDAO(em);
        boolean flag = true;
        try {
            trans.begin();
            dateDAO.delete(id);
            trans.commit();
        } catch (Exception e) {
            trans.rollback();
            flag = false;
            System.err.println(e.getMessage());
        } finally {
            em.clear();
            em.close();
        }   
        
        return flag;
    }
}
