jp.gmo.zcom.ticket.dao.impl.BookTicketDaoImpl.java Source code

Java tutorial

Introduction

Here is the source code for jp.gmo.zcom.ticket.dao.impl.BookTicketDaoImpl.java

Source

/*
 * Copyright(C) 2016 GMO-Z.com RUNSYSTEM JSC. All rights reserved.
 *
 * (1)????GMO??? ????????
 * (2)??????GMO??? ??????
 *
 * This software is the confidential and proprietary information of
 * GMO-Z.com RUNSYSTEM. You shall not disclose such Confidential Information
 * and shall use it only in accordance with the terms of the license
 * agreement you entered into with GMO-Z.com RUNSYSTEM.
 */
package jp.gmo.zcom.ticket.dao.impl;

import java.util.Date;
import java.util.List;

import jp.gmo.zcom.ticket.constants.ConstValues;
import jp.gmo.zcom.ticket.dao.BookTicketDao;
import jp.gmo.zcom.ticket.entity.Floor;
import jp.gmo.zcom.ticket.entity.Gate;
import jp.gmo.zcom.ticket.entity.Match;
import jp.gmo.zcom.ticket.entity.Seat;
import jp.gmo.zcom.ticket.entity.Stadium;
import jp.gmo.zcom.ticket.entity.Stand;

import org.hibernate.CacheMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 * @author : thuyttt
 * @PG_ID : BookTicketDaoImpl
 * @createDate : 03.08.2016
 */
@Repository
public class BookTicketDaoImpl implements BookTicketDao {

    @Autowired
    private SessionFactory sessionFactory;

    /**
     * get list of match
     * 
     * @param matchDate
     * @return list match
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<Match> getListMatch(Date matchDate) {
        Session session = this.sessionFactory.getCurrentSession();
        // Query get lesson
        Query query = session.getNamedQuery("BookTicketDao.searchListMatch");
        query.setCacheable(true);
        //query.setCacheRegion("BookTicketDao.searchListMatch");

        // Set parameter
        query.setDate("matchDate", matchDate);
        query.setParameter("status", ConstValues.STATUS_VALUES_ON);

        List<Match> result = query.list();
        return result;
    }

    /**
     * get list of stand
     * 
     * @param stadiumId
     * @return list stand
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<Stand> getListStand(Integer stadiumId) {
        Session session = this.sessionFactory.getCurrentSession();
        // Query get lesson
        Query query = session.getNamedQuery("BookTicketDao.searchListStand");

        // Set parameter
        query.setParameter("stadiumId", stadiumId);
        query.setParameter("status", ConstValues.STATUS_VALUES_ON);

        List<Stand> result = query.list();
        return result;
    }

    /**
     * get list of floor
     * 
     * @param stadiumId
     * @param standId
     * @return list floor
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<Floor> getListFloor(Integer stadiumId, Integer standId) {
        Session session = this.sessionFactory.getCurrentSession();
        // Query get lesson
        Query query = session.getNamedQuery("BookTicketDao.searchListFloor");

        // Set parameter
        query.setParameter("stadiumId", stadiumId);
        query.setParameter("standId", standId);
        query.setParameter("status", ConstValues.STATUS_VALUES_ON);

        List<Floor> result = query.list();
        return result;
    }

    /**
     * get list of gate
     * 
     * @param stadiumId
     * @param standId
     * @param floorId
     * @return list gate
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<Gate> getListGate(Integer stadiumId, Integer standId, Integer floorId) {
        Session session = this.sessionFactory.getCurrentSession();
        // Query get lesson
        Query query = session.getNamedQuery("BookTicketDao.searchListGate");

        // Set parameter
        query.setParameter("stadiumId", stadiumId);
        query.setParameter("standId", standId);
        query.setParameter("floorId", floorId);
        query.setParameter("status", ConstValues.STATUS_VALUES_ON);

        List<Gate> result = query.list();
        return result;
    }

    /**
     * get list of seat
     * 
     * @param stadiumId
     * @param standId
     * @param floorId
     * @param gateId
     * @return list seat
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<Seat> getListSeat(Integer stadiumId, Integer standId, Integer floorId, Integer gateId) {
        Session session = this.sessionFactory.getCurrentSession();
        // Query get lesson
        Query query = session.getNamedQuery("BookTicketDao.searchListSeat");

        // Set parameter
        query.setParameter("stadiumId", stadiumId);
        query.setParameter("gateId", gateId);
        query.setParameter("standId", standId);
        query.setParameter("floorId", floorId);
        query.setParameter("gateId", gateId);
        query.setParameter("status", ConstValues.STATUS_VALUES_ON);

        List<Seat> result = query.list();
        return result;
    }

    /**
     * get stadium by id
     * 
     * @param stadiumId
     * @return stadium
     */
    @Override
    public Stadium getStadiumById(Integer stadiumId) {
        Session session = this.sessionFactory.getCurrentSession();
        // Query get lesson
        Query query = session.getNamedQuery("BookTicketDao.searchStadiumById");
        query.setCacheable(true);
        //query.setCacheRegion("BookTicketDao.searchListMatch");

        // Set parameter
        query.setParameter("stadiumId", stadiumId);

        return (Stadium) query.uniqueResult();
    }
}