Package net.helipilot50.stocktrade.server.dao

Source Code of net.helipilot50.stocktrade.server.dao.CustomerDAOImpl

package net.helipilot50.stocktrade.server.dao;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.persistence.EntityManagerFactory;

import net.helipilot50.stocktrade.shared.Customer;
import net.helipilot50.stocktrade.shared.Holding;
import net.helipilot50.stocktrade.shared.NoSuchCustomerException;
import net.helipilot50.stocktrade.shared.NoSuchHoldingException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@SuppressWarnings("deprecation")
@Repository("customerDAO")
public class CustomerDAOImpl extends JpaDAO<String, Customer> implements CustomerDAO {

 
  @Autowired
  EntityManagerFactory entityManagerFactory;
 
  @Override
  @PostConstruct
  public void init(){
    super.setEntityManagerFactory(entityManagerFactory);
  }

    /**
     * SQLDeleteHolding<p>
     * <p>
     * @param pHolding Type: Holding
     */
  @Override
  @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
    public void SQLDeleteHolding(Holding pHolding) {
        // -- =============== Original SQL ===============
        // delete from Holding
        // where CustomerName=:pHolding.CustomerName and
        //    StockName=:pHolding.StockName
        // on session DBConnection
        // -- ============================================
    getJpaTemplate().remove(pHolding);
    }

    /**
     * SQLInsertHolding<p>
     * <p>
     * @param pHolding Type: Holding
     */
    @Override
  @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
    public void SQLInsertHolding(Holding pHolding) {
     

        // -- =============== Original SQL ===============
        // insert into Holding (CustomerName, StockName, Quantity, Price)
        // values (:pHolding.CustomerName, :pHolding.StockName,
        //        :pHolding.Quantity, :pHolding.Price)
        // on session DBConnection
        // -- ============================================
      getJpaTemplate().persist(pHolding);
    }

    /**
     * SQLSelectCustomer<p>
     * <p>
     * @param pName Type: TextData
     * @return Customer
     */
    @Override
  public Customer SQLSelectCustomer(String pName) {
      
//    Customer aCustomer = (Customer) getJpaTemplate().find("from customer where customerName = ?", pName);
    Customer aCustomer = (Customer) getJpaTemplate().find(Customer.class, pName);
        if (aCustomer == null) {
            NoSuchCustomerException noSuchCust = new NoSuchCustomerException("Customer "+pName+" does not exist ");
            throw noSuchCust;
        }
        return aCustomer;
    }

    /**
     * SQLSelectHolding<p>
     * <p>
     * @param pSelHoldCustName Type: TextData
     * @param pSelHoldStockName Type: String
     * @return Holding
     */
    @Override
  public Holding SQLSelectHolding(String pSelHoldCustName, String pSelHoldStockName) {
        // -- =============== Original SQL ===============
        // select * into :aHolding from Holding
        //           where CustomerName = :pSelHoldCustName
        //           and StockName = :pSelHoldStockName
        //           on session DBConnection
        // -- ============================================
        Holding aHolding = (Holding) getJpaTemplate().find("from holding where customerName = ? and StockName = ?", pSelHoldCustName, pSelHoldStockName);
        if (aHolding == null){
            NoSuchHoldingException noHolding = new NoSuchHoldingException("Customer " + pSelHoldCustName + " does not own this stock");
            throw noHolding;
        }
        return aHolding;
    }

    /**
     * SQLSelectHoldingList<p>
     * <p>
     * @param pName Type: TextData
     * @return Array_Of_Holding<Holding>
     */
    @Override
  @SuppressWarnings("unchecked")
  public List<Holding> SQLSelectHoldingList(String pName) {
        // -- =============== Original SQL ===============
        // select * into :aCustomersHoldingList
        // from Holding
        // where CustomerName = :pName
        // on session DBConnection
        // -- ============================================
        List<Holding> aCustomersHoldingList = getJpaTemplate().find("from holding where customerName = ?", pName);


        return aCustomersHoldingList;
    }

    /**
     * SQLUpdateCashBal<p>
     * <p>
     * @param pCustomerName Type: TextData
     * @param pCashBalance Type: float
     */
    @Override
  @Transactional(readOnly = false, propagation = Propagation.NESTED)
    public void SQLUpdateCashBal(String pCustomerName, float pCashBalance) {

        // -- =============== Original SQL ===============
        // update Customer
        // set CashBalance = :pCashBalance
        // where CustomerName = :pCustomerName
        // on session DBConnection
        // -- ============================================
        Customer customer = SQLSelectCustomer(pCustomerName);
        customer.setCashBalance(pCashBalance);
        getJpaTemplate().persist(customer);
    }
 
    /**
     * updateHolding<p>
     * <p>
     * @param pHolding Type: Holding
     */
    @Override
  @Transactional(readOnly = false, propagation = Propagation.NESTED)
    public void SQLUpdateHolding(Holding pHolding) {

        // -- =============== Original SQL ===============
        // update Holding set Quantity = :pHolding.Quantity
        // where CustomerName=:pHolding.CustomerName and
        // StockName=:pHolding.StockName
        // on session DBConnection
        // -- ============================================
      getJpaTemplate().persist(pHolding);
    }

//  HibernateTemplate template;
// 
//  @Autowired
//  public void setSessionFactory(SessionFactory sessionFactory) {
//    this.template = new HibernateTemplate(sessionFactory);
//  }
//  @SuppressWarnings("unchecked")
//  public List<String> stockList(){
//        // -- =============== Original SQL ===============
//        // select StockName from Stock
//        //         on session DBConnection
//        // -- ============================================
//    return template.find("from stock");
//  }
//    /**
//     * SQLDeleteHolding<p>
//     * <p>
//     * @param pHolding Type: Holding
//     */
//  @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
//    public void SQLDeleteHolding(Holding pHolding) {
//        // -- =============== Original SQL ===============
//        // delete from Holding
//        // where CustomerName=:pHolding.CustomerName and
//        //    StockName=:pHolding.StockName
//        // on session DBConnection
//        // -- ============================================
//    template.delete(pHolding);
//    }
//
//    /**
//     * SQLInsertHolding<p>
//     * <p>
//     * @param pHolding Type: Holding
//     */
//    @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
//    public void SQLInsertHolding(Holding pHolding) {
//     
//
//        // -- =============== Original SQL ===============
//        // insert into Holding (CustomerName, StockName, Quantity, Price)
//        // values (:pHolding.CustomerName, :pHolding.StockName,
//        //        :pHolding.Quantity, :pHolding.Price)
//        // on session DBConnection
//        // -- ============================================
//      template.persist(pHolding);
//    }
//
//    /**
//     * SQLSelectCustomer<p>
//     * <p>
//     * @param pName Type: TextData
//     * @return Customer
//     */
//    public Customer SQLSelectCustomer(String pName) {
//      
//    Customer aCustomer = (Customer) template.find("from customer where customerName = ?", pName);
//        if (aCustomer == null) {
//            NoSuchCustomerException noSuchCust = new NoSuchCustomerException("Customer "+pName+" does not exist ");
//            throw noSuchCust;
//        }
//        return aCustomer;
//    }
//
//    /**
//     * SQLSelectHolding<p>
//     * <p>
//     * @param pSelHoldCustName Type: TextData
//     * @param pSelHoldStockName Type: String
//     * @return Holding
//     */
//    public Holding SQLSelectHolding(String pSelHoldCustName, String pSelHoldStockName) {
//        // -- =============== Original SQL ===============
//        // select * into :aHolding from Holding
//        //           where CustomerName = :pSelHoldCustName
//        //           and StockName = :pSelHoldStockName
//        //           on session DBConnection
//        // -- ============================================
//        Holding aHolding = (Holding) template.find("from holding where customerName = ? and StockName = ?", pSelHoldCustName, pSelHoldStockName);
//        if (aHolding == null){
//            NoSuchHoldingException noHolding = new NoSuchHoldingException("Customer " + pSelHoldCustName + " does not own this stock");
//            throw noHolding;
//        }
//        return aHolding;
//    }
//
//    /**
//     * SQLSelectHoldingList<p>
//     * <p>
//     * @param pName Type: TextData
//     * @return Array_Of_Holding<Holding>
//     */
//    @SuppressWarnings("unchecked")
//  public List<Holding> SQLSelectHoldingList(String pName) {
//        // -- =============== Original SQL ===============
//        // select * into :aCustomersHoldingList
//        // from Holding
//        // where CustomerName = :pName
//        // on session DBConnection
//        // -- ============================================
//        List<Holding> aCustomersHoldingList = template.find("from holding where customerName = ?", pName);
//
//
//        return aCustomersHoldingList;
//    }
//
//    /**
//     * SQLUpdateCashBal<p>
//     * <p>
//     * @param pCustomerName Type: TextData
//     * @param pCashBalance Type: float
//     */
//    @Transactional(readOnly = false, propagation = Propagation.NESTED)
//    public void SQLUpdateCashBal(String pCustomerName, float pCashBalance) {
//
//        // -- =============== Original SQL ===============
//        // update Customer
//        // set CashBalance = :pCashBalance
//        // where CustomerName = :pCustomerName
//        // on session DBConnection
//        // -- ============================================
//        Customer customer = SQLSelectCustomer(pCustomerName);
//        customer.setCashBalance(pCashBalance);
//        template.persist(customer);
//    }
// 
//    /**
//     * updateHolding<p>
//     * <p>
//     * @param pHolding Type: Holding
//     */
//    @Transactional(readOnly = false, propagation = Propagation.NESTED)
//    public void SQLUpdateHolding(Holding pHolding) {
//
//        // -- =============== Original SQL ===============
//        // update Holding set Quantity = :pHolding.Quantity
//        // where CustomerName=:pHolding.CustomerName and
//        // StockName=:pHolding.StockName
//        // on session DBConnection
//        // -- ============================================
//      template.persist(pHolding);
//    }
 


}
TOP

Related Classes of net.helipilot50.stocktrade.server.dao.CustomerDAOImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.