List of usage examples for org.hibernate SessionFactory getSessionFactoryOptions
SessionFactoryOptions getSessionFactoryOptions();
From source file:com.cms.dao.TermInformationDAO.java
License:Open Source License
public ResultDTO insertBatchTermInformations(List<TermInformationDTO> lstTermInformationDTO) { ResultDTO resultDTO = new ResultDTO(); try {//from w ww . j av a2s.com Session sessionBatch = sessionFactory.openSession(); Connection connection; SessionFactory sessionFactoryBatch = sessionBatch.getSessionFactory(); connection = sessionFactoryBatch.getSessionFactoryOptions().getServiceRegistry() .getService(ConnectionProvider.class).getConnection(); StringBuilder sql = new StringBuilder(); List params; sql.append(" INSERT INTO TERM_INFORMATION(ID,EMAIL,END_TIME,MINE_NAME," + "PHONE,PROVIDER,SERVICE,START_TIME,TAX_CODE,SOURCE_DATA, IS_CONTACT_INFO) " + "values(TERM_INFORMATION_SEQ.nextval, ?, to_date(?,'dd/MM/yyyy'), ?, ?, ?, ?, to_date(?,'dd/MM/yyyy') , ?, ?, ?) " + " LOG ERRORS REJECT LIMIT UNLIMITED "); //tao statement bang preparestatement PreparedStatement stm = connection.prepareStatement(sql.toString()); int numberNeedToCommit = 0; int numberOfSuccess = 0; int numberOfFail = 0; for (TermInformationDTO t : lstTermInformationDTO) { params = getParamsFromTermInfo(t); for (int idx = 0; idx < params.size(); idx++) { try { stm.setString(idx + 1, DataUtil.nvl(params.get(idx), "").toString()); } catch (Exception e) { System.out.println(idx); } } stm.addBatch(); numberNeedToCommit++; if (numberNeedToCommit >= 1000) { try { stm.executeBatch(); numberOfSuccess = numberOfSuccess + numberNeedToCommit; } catch (Exception ex) { numberOfFail = numberOfFail + numberNeedToCommit; } numberNeedToCommit = 0; } } if (numberNeedToCommit > 0) { try { stm.executeBatch(); numberOfSuccess += numberNeedToCommit; } catch (Exception ex) { numberOfFail += numberNeedToCommit; } } stm.close(); sessionBatch.close(); numberOfFail = getNumberOfErrorRecord(connection); connection.close(); numberOfSuccess -= numberOfFail; resultDTO.setKey(Constants.SUCCESS); resultDTO.setMessage(Constants.SUCCESS); resultDTO.setQuantityFail(numberOfFail); resultDTO.setQuantitySucc(numberOfSuccess); } catch (SQLException ex) { resultDTO.setKey(Constants.FAIL); resultDTO.setMessage(Constants.FAIL); Logger.getLogger(TermInformationDAO.class.getName()).log(Level.SEVERE, null, ex); } return resultDTO; }
From source file:com.court.controller.GeneralSettingsFxmlController.java
private String getMysqlServerV(SessionFactory sessionFactory) throws SQLException { String server_v;/* w ww . ja v a2s. c o m*/ try (Connection con = sessionFactory.getSessionFactoryOptions().getServiceRegistry() .getService(ConnectionProvider.class).getConnection()) { server_v = con.getMetaData().getDatabaseProductVersion().substring(0, con.getMetaData().getDatabaseProductVersion().lastIndexOf(".")); } return server_v; }
From source file:com.viettel.logistic.wms.service.SerialInventoryServiceImpl.java
License:Open Source License
@Override public ResultDTO insertListSerialInventoryBatch(List<SerialInventoryDTO> serialInventoryDTO) { ResultDTO resultDTO = new ResultDTO(); Transaction transaction;/* w ww .jav a 2 s.co m*/ Connection connection = null; Session session = sessionFactory.openSession(); transaction = session.getTransaction(); transaction.begin(); SessionFactory sessionFactoryBatch = session.getSessionFactory(); try { connection = sessionFactoryBatch.getSessionFactoryOptions().getServiceRegistry() .getService(ConnectionProvider.class).getConnection(); connection.setAutoCommit(false); } catch (SQLException ex) { Logger.getLogger(SerialInventoryServiceImpl.class.getName()).log(Level.SEVERE, null, ex); } resultDTO = serialInventoryBusiness2.insertListSerialInventoryBatch(serialInventoryDTO, connection); if (!resultDTO.getMessage().equals(ParamUtils.SUCCESS)) { rollback(session, transaction, connection); } commit(session, transaction, connection); return resultDTO; }
From source file:com.viettel.logistic.wms.service.StockGoodsSerialServiceImpl.java
License:Open Source License
@Override public List<GoodsSerialInforDTO> getGoodsBySerial(OrdersDTO ordersDTO, List<GoodsSerialInforDTO> lstGoodsSerialInforDTO) { Session session;// ww w . j ava 2 s . c o m Connection connection; session = sessionFactory.openSession(); List<GoodsSerialInforDTO> lstReturn = null; try { SessionFactory sessionFactoryBatch = session.getSessionFactory(); connection = sessionFactoryBatch.getSessionFactoryOptions().getServiceRegistry() .getService(ConnectionProvider.class).getConnection(); connection.setAutoCommit(false); lstReturn = stockGoodsSerialBusiness.getGoodsBySerial(ordersDTO, lstGoodsSerialInforDTO, connection); connection.close(); } catch (Exception ex) { ex.printStackTrace(); } return lstReturn; }
From source file:com.viettel.logistic.wms.service.StockGoodsSerialServiceImpl.java
License:Open Source License
@Override public List<GoodsSerialInforDTO> getGoodsBySerialInventory(OrdersDTO ordersDTO, List<GoodsSerialInforDTO> lstGoodsSerialInforDTO) { Session session;/*from w ww . j a va2 s . co m*/ Connection connection; session = sessionFactory.openSession(); List<GoodsSerialInforDTO> lstReturn = null; try { SessionFactory sessionFactoryBatch = session.getSessionFactory(); connection = sessionFactoryBatch.getSessionFactoryOptions().getServiceRegistry() .getService(ConnectionProvider.class).getConnection(); connection.setAutoCommit(false); lstReturn = stockGoodsSerialBusiness.getGoodsBySerialInventory(ordersDTO, lstGoodsSerialInforDTO, connection); connection.close(); } catch (Exception ex) { ex.printStackTrace(); } return lstReturn; }
From source file:com.viettel.logistic.wms.service.StockImportServiceImpl.java
@Override public ResultDTO importStockCust(StockTransDTO stockTransDTO, List<StockTransDetailDTO> lstStockTransDetailDTO, List<StockTransSerialDTO> lstStockTransSerialDTO) { String stockTransDetailId;/*from ww w . java 2 s . co m*/ List<StockTransSerialDTO> filterListStockTransSerialDTO; String stockTransCode; String stockTransSEQ; ResultDTO resultDTO = new ResultDTO(); resultDTO.setMessage(ParamUtils.SUCCESS); Map<String, GoodsDTO> mapGoodsDTO; Map<String, GoodsDTO> mapGoodsCode2DTO; // Double indexInsertSuccess = 0D; // int insertSuccess = 0; int insertFail = 0; Double amountIssue; // String stockTransId = ""; String sysdate; // Session session; Transaction transaction; Connection connection = null; session = sessionFactory.openSession(); transaction = session.getTransaction(); transaction.begin(); // sysdate = stockGoodsBusiness.getSysDate(formatDate); GoodsDTO goodsDTO; //du lieu cho dong bo bccs String previousOrderActionStatus = null; /* duyot: cap nhat 27/08: dong bo bccs - cap nhat partner id - cap nhat cac truong trong serial neu la tu kh vtt (id = 1) - Khoi tao list NHAP - NHAP DIEU CHUYEN */ //DuyOT OrderActionDTO orderActionDTO = null; OrdersDTO orders = null; try { //--------------------------------------------------------------------- //1. KHOI TAO CONNECTION //------------------------------------------------------------------- SessionFactory sessionFactoryBatch = session.getSessionFactory(); connection = sessionFactoryBatch.getSessionFactoryOptions().getServiceRegistry() .getService(ConnectionProvider.class).getConnection(); connection.setAutoCommit(false); //------------------------------------------------------------------- //KIEM TRA LENH DA DUOC NHAP HAY CHUA //1. KIEM TRA TRANG THAI LENH String orderIdList = stockTransDTO.getOrderIdList(); if (!StringUtils.isStringNullOrEmpty(orderIdList)) {//NEU LA NHAP THEO YC -> CHECK orders = WSOrders.findOrderById(orderIdList); if (orders == null) {//KHONG TIM DUOC YC HOP LE resultDTO.setMessage(ParamUtils.ERROR_MESSAGE.ORDER_NOT_FOUND); resultDTO.setKey(ParamUtils.ERROR_MESSAGE.ORDER_NOT_FOUND); rollback(session, transaction, connection); return resultDTO; } //LAY THONG TIN LENH List<ConditionBean> lstConditionBeanUpdateOrders = new ArrayList<>(); lstConditionBeanUpdateOrders.add(new ConditionBean("orderIdList", ParamUtils.NAME_EQUAL, orders.getOrderId(), ParamUtils.TYPE_STRING)); try { orderActionDTO = WSOrderAction.getListOrderActionByCondition(lstConditionBeanUpdateOrders, 0, Integer.MAX_VALUE, "", "id").get(0); } catch (Exception ex) { } if (orderActionDTO == null) {//KHONG TIM DUOC YC HOP LE resultDTO.setMessage(ParamUtils.ERROR_MESSAGE.ORDER_NOT_FOUND); resultDTO.setKey(ParamUtils.ERROR_MESSAGE.ORDER_NOT_FOUND); rollback(session, transaction, connection); return resultDTO; } //kiem tra co ai dang cung nhap k // if (lstCurrentOrderActionID.contains(orderActionDTO.getId())) { // resultDTO.setMessage(ParamUtils.ERROR_MESSAGE.SESSION_CONFLIC); // resultDTO.setKey(ParamUtils.ERROR_MESSAGE.SESSION_CONFLIC); // return resultDTO; // } else {//them vao current process // lstCurrentOrderActionID.add(orderActionDTO.getId()); // } if (orderActionDTO.getStatus().equalsIgnoreCase("3")) {//NEU TRANG THAI LENH = 3 -> DA NHAP -> THONG BAO LENH DA THUC NHAP resultDTO.setMessage(ParamUtils.ERROR_MESSAGE.ORDER_ACTION_UPDATED); resultDTO.setKey(ParamUtils.ERROR_MESSAGE.ORDER_ACTION_UPDATED); return resultDTO; } previousOrderActionStatus = orderActionDTO.getStatus(); String updateMessage = updateOrderAndOrderAction(orders, orderActionDTO); if (!updateMessage.equalsIgnoreCase(ParamUtils.SUCCESS)) {//NEU THONG TIN CAP NHAT LOI -> ROLLBACK resultDTO.setMessage(ParamUtils.FAIL); resultDTO.setKey(ParamUtils.ERROR_MESSAGE.UPDATE_ORDER_ACTION_FAIL); rollBackOrderAndOrderAction(orders, orderActionDTO, previousOrderActionStatus); rollback(session, transaction, connection); removeLock(orderActionDTO); return resultDTO; } } // if (!DataUtil.isListNullOrEmpty(lstStockTransDetailDTO)) { //INSERT GIAO DICH STOCK_TRANS stockTransSEQ = stockTransBusiness.getSequence("STOCK_TRANS_SEQ"); stockTransCode = ParamUtils.CODE_IMPORT_STOCK + stockTransSEQ; stockTransDTO.setStockTransCode(stockTransCode); stockTransDTO.setCreateDatetime(sysdate); stockTransDTO.setStockTransDate(sysdate); stockTransDTO.setStockTransId(stockTransSEQ); resultDTO = commonBusinessInterface.insertStockTrans(stockTransDTO, connection); stockTransId = stockTransDTO.getStockTransId(); stockTransDTO.setStockTransId(stockTransId); if (!resultDTO.getMessage().equals(ParamUtils.SUCCESS)) { removeLock(orderActionDTO); rollback(session, transaction, connection); rollBackOrderAndOrderAction(orders, orderActionDTO, previousOrderActionStatus); return resultDTO; } //DAY VAO MAP DANH SACH HANG HOA String goodsIdList = getGoodsIdList(lstStockTransDetailDTO); List<ConditionBean> lstConditionBean = new ArrayList<>(); lstConditionBean.add(new ConditionBean("custId", ParamUtils.OP_EQUAL, stockTransDTO.getCustId(), ParamUtils.TYPE_NUMBER)); lstConditionBean .add(new ConditionBean("goodsId", ParamUtils.OP_IN, goodsIdList, ParamUtils.TYPE_NUMBER)); List<GoodsDTO> lstGoodsDTO = goodsBusiness.searchByConditionBean(lstConditionBean, 0, Integer.MAX_VALUE, "", "code"); mapGoodsDTO = DataUtil.putGoodsToMap(lstGoodsDTO); //LOOP: CHI TIET CHO TUNG MAT HANG boolean firstWrong = false; Double pre = 0D; for (StockTransDetailDTO stockTransDetailDTO : lstStockTransDetailDTO) { //lay seq String stockTransDetailSEQ = stockTransDetailBusiness.getSequence("STOCK_TRANS_DETAIL_SEQ"); stockTransDetailDTO.setStockTransId(stockTransId); stockTransDetailDTO.setStockTransDetailId(stockTransDetailSEQ); stockTransDetailDTO.setStockTransDate(sysdate); stockTransDetailDTO.setCreateDatetime(sysdate); goodsDTO = mapGoodsDTO.get(stockTransDetailDTO.getGoodsId()); if (goodsDTO == null) { rollback(session, transaction, connection); resultDTO.setMessage(ParamUtils.FAIL); resultDTO.setKey(ParamUtils.GOODS_IS_NOT_EXIST); removeLock(orderActionDTO); rollBackOrderAndOrderAction(orders, orderActionDTO, previousOrderActionStatus); return resultDTO; } //INSERT CHI TIET GIAO DICH KHO STOCK_TRANS_DETAIL stockTransDetailDTO.setGoodsCode(goodsDTO.getCode()); stockTransDetailDTO.setGoodsName(goodsDTO.getName()); stockTransDetailDTO.setGoodsIsSerial(goodsDTO.getIsSerial()); stockTransDetailDTO.setGoodsIsSerialStrip(goodsDTO.getIsSerialStrip()); //------ resultDTO = commonBusinessInterface.insertStockTransDetail(stockTransDetailDTO, connection); //------------- stockTransDetailId = stockTransDetailSEQ; // if (!resultDTO.getMessage().equals(ParamUtils.SUCCESS)) { rollback(session, transaction, connection); resultDTO.setMessage(ParamUtils.FAIL); resultDTO.setKey(ParamUtils.SYSTEM_OR_DATA_ERROR); removeLock(orderActionDTO); rollBackOrderAndOrderAction(orders, orderActionDTO, previousOrderActionStatus); return resultDTO; } //MAT HANG K THEO SERIAL if (!stockTransDetailDTO.getGoodsIsSerial().equals(Constants.IS_SERIAL)) { //Cap nhat mat hang theo so luong STOCK_GOODS resultDTO = importStockGoods(stockTransDTO, stockTransDetailDTO, session, ParamUtils.GOODS_IMPORT_STATUS.IMPORTED); if (!resultDTO.getMessage().equals(ParamUtils.SUCCESS)) { rollback(session, transaction, connection); removeLock(orderActionDTO); rollBackOrderAndOrderAction(orders, orderActionDTO, previousOrderActionStatus); return resultDTO; } //Cap nhat so luong tong cong STOCK_GOODS_TOTAL resultDTO = importStockGoodsTotal(stockTransDTO, stockTransDetailDTO, session); if (!resultDTO.getMessage().equals(ParamUtils.SUCCESS)) { rollback(session, transaction, connection); removeLock(orderActionDTO); rollBackOrderAndOrderAction(orders, orderActionDTO, previousOrderActionStatus); return resultDTO; } } else //MAT HANG QUAN LY THEO SERIAL { //LAY RA DANH SACH SERIAL CUA HANG HOA TUONG UNG filterListStockTransSerialDTO = filterStockTransSerialDTO( stockTransDetailDTO.getTmpStockTransDetailId(), lstStockTransSerialDTO); if (filterListStockTransSerialDTO == null || filterListStockTransSerialDTO.size() < 1) { resultDTO.setMessage(ParamUtils.FAIL); resultDTO.setKey(ParamUtils.SYSTEM_OR_DATA_ERROR); rollback(session, transaction, connection); removeLock(orderActionDTO); rollBackOrderAndOrderAction(orders, orderActionDTO, previousOrderActionStatus); return resultDTO; } //Insert giao dich chi tiet serial //khoi tao list serial duoc nhap kho cho mat hang nay for (StockTransSerialDTO stockTransSerialDTO : filterListStockTransSerialDTO) { //Cap nhat Id giao dich, ID chi tiet giao dichj stockTransSerialDTO.setStockTransId(stockTransId); stockTransSerialDTO.setStockTransDetailId(stockTransDetailId); stockTransSerialDTO.setStockTransDate(sysdate); stockTransSerialDTO.setCreateDatetime(sysdate); stockTransSerialDTO.setGoodsCode(goodsDTO.getCode()); stockTransSerialDTO.setGoodsName(goodsDTO.getName()); } //Insert batch VAO KHO STOCK_GOODS_SERIAL resultDTO = importStockGoodsListSerial(stockTransDTO, (StockTransDetailDTO) DataUtil.cloneObject(stockTransDetailDTO), filterListStockTransSerialDTO, session, connection, ParamUtils.GOODS_IMPORT_STATUS.IMPORTED); insertSuccess = resultDTO.getQuantitySucc(); insertFail = resultDTO.getQuantityFail(); //amountIssue = resultDTO.getAmountIssue(); //kiem tra so luong thanh cong cua hang hoa if (stockTransDetailDTO.getGoodsIsSerialStrip().equals(Constants.IS_SERIAL_STRIP)) { amountIssue = resultDTO.getAmountIssue(); } else { if ((insertFail != 0 && !firstWrong) || (insertFail == 0)) { indexInsertSuccess = Double.parseDouble(insertSuccess + ""); pre = Double.parseDouble(insertFail + ""); firstWrong = true; } else if (insertFail != 0 && firstWrong) { indexInsertSuccess = insertSuccess + pre; pre = Double.parseDouble(insertFail + ""); } amountIssue = indexInsertSuccess; } //DUA VAO THONG TIN GIAO DICH: STOCK_TRANS_SERIAL if (!resultDTO.getMessage().equals(ParamUtils.SUCCESS)) { rollback(session, transaction, connection); removeLock(orderActionDTO); rollBackOrderAndOrderAction(orders, orderActionDTO, previousOrderActionStatus); return resultDTO; } //END FOR FILTER LIST //CAP NHAT LAI STOCK_TRANS_DETAIL VOI SO LUONG INSERT THANH CONG int isUpdate = stockGoodsSerialBusiness2.updateStockTransDetail(stockTransDetailId, amountIssue, connection); //neu update khong thanh cong if (isUpdate < 1) { resultDTO.setMessage(ParamUtils.FAIL); resultDTO.setKey("UPDATE_STOCK_TRANS_DETAIL_ERROR"); rollback(session, transaction, connection); removeLock(orderActionDTO); rollBackOrderAndOrderAction(orders, orderActionDTO, previousOrderActionStatus); return resultDTO; } // stockTransDetailDTO.setAmountReal(amountIssue.toString().replace(".0", "")); //CAP NHAT SO LUONG TONG CONG CUA HANG HOA resultDTO = importStockGoodsTotal(stockTransDTO, stockTransDetailDTO, session); if (!resultDTO.getMessage().equals(ParamUtils.SUCCESS)) { rollback(session, transaction, connection); removeLock(orderActionDTO); rollBackOrderAndOrderAction(orders, orderActionDTO, previousOrderActionStatus); return resultDTO; } } } } //neu hoan toan k co loi -> commit commit(session, transaction, connection); } catch (Exception e) { rollback(session, transaction, connection); Logger.getLogger(StockImportServiceImpl.class.getName()).log(Level.SEVERE, null, e); resultDTO.setMessage(e.getMessage()); resultDTO.setKey(ParamUtils.SYSTEM_OR_DATA_ERROR); rollBackOrderAndOrderAction(orders, orderActionDTO, previousOrderActionStatus); removeLock(orderActionDTO); return resultDTO; } finally { try { if (session.isOpen()) { session.close(); } if (connection != null && !connection.isClosed()) { connection.close(); } } catch (SQLException ex) { Logger.getLogger(StockImportServiceImpl.class.getName()).log(Level.SEVERE, null, ex); } } // resultDTO.setQuantitySucc(insertSuccess); resultDTO.setQuantityFail(insertFail); resultDTO.setId(stockTransId); removeLock(orderActionDTO); return resultDTO; }
From source file:com.viettel.logistic.wms.service.StockImportServiceImpl.java
@Override public ResultDTO synImportStockCust(StockTransDTO stockTransDTO) { //Do KPI//w w w. java 2s . c o m KpiLogDTO synKpiLog = new KpiLogDTO(); String sStartTime = DateUtil.sysdateString(); String functionCode; String reason; String strResult = ""; String descr; String transactionCode = null; synKpiLog.setStartTime(sStartTime); synKpiLog.setCreateDatetime(sStartTime); //Ket thuc khoi tao doi tuong do kpi String stockTransDetailId; List<StockTransSerialDTO> filterListStockTransSerialDTO; String stockTransCode; String stockTransSEQ; ResultDTO resultDTO = new ResultDTO(); resultDTO.setMessage(ParamUtils.SUCCESS); Map<String, GoodsDTO> mapGoodsDTO; int insertSuccess = 0; int insertFail = 0; Double amountIssue; // String stockTransId = ""; String sysdate; //INIT TRANSACTION Session session; Transaction transaction; Connection connection = null; session = sessionFactory.openSession(); transaction = session.getTransaction(); transaction.begin(); // sysdate = stockGoodsBusiness.getSysDate(formatDate); GoodsDTO goodsDTO; //du lieu cho dong bo bccs OrdersDTO ordersDTO = null; long startTime = System.currentTimeMillis(); long time; //===================================== List<StockTransDetailDTO> lstStockTransDetail = new ArrayList<>(); List<StockTransDetailDTO> lstStockTransDetailDTOsImportAndUpdate = new ArrayList<>(); //DUYOT: 27/01/2016: loc ra danh sach hang kit for (StockTransDetailDTO i : stockTransDTO.getLstStockTransDetailDTO()) { //Neu TH nhap kit --> se truyen vao transfersGoodsCode la code cua hang hoa sim--> Thuc hien xuat sim va nhap kit if (!DataUtil.isStringNullOrEmpty(i.getTransfersGoodsCode())) { lstStockTransDetailDTOsImportAndUpdate.add(i); } else { lstStockTransDetail.add(i); } } //DUYOT: 28/01/2016: check lai trang thai cua yeu cau - lenh--------------------- //CHECK THONG TIN YEU CAU - LENH CO TRANG THAI HOP LE------------------- String orderIdList = stockTransDTO.getOrderIdList(); if (orderIdList == null || orderIdList.equals("")) { resultDTO.setMessage(ParamUtils.FAIL); resultDTO.setKey(ParamUtils.ERROR_MESSAGE.ORDER_IE); return resultDTO; } try { ordersDTO = WSOrders.findOrderById(orderIdList); } catch (Exception ex) { Logger.getLogger(StockImportServiceImpl.class.getName()).log(Level.SEVERE, null, ex); } if (ordersDTO != null && ORDER_STATUS_IMPORTED_EXPORTED.equalsIgnoreCase(ordersDTO.getOrderStatus())) { resultDTO.setMessage(ParamUtils.FAIL); resultDTO.setKey(ParamUtils.ERROR_MESSAGE.ORDER_IE); return resultDTO; } //--------------------------------------------------------------------------------- // functionCode = "CREATE_BILL_IMPORT_LOG"; if (ordersDTO != null) { transactionCode = ordersDTO.getOrderCode(); } try { //------------------------------------------------------------------- //1. KHOI TAO CONNECTION //------------------------------------------------------------------- SessionFactory sessionFactoryBatch = session.getSessionFactory(); connection = sessionFactoryBatch.getSessionFactoryOptions().getServiceRegistry() .getService(ConnectionProvider.class).getConnection(); connection.setAutoCommit(false); //------------------------------------------------------------------- //THUC HIEN GIAO DICH THU HOI DOI VOI HANG KIT ( XUAT SIM -> NHAP KIT)----------------- if (!DataUtil.isListNullOrEmpty(lstStockTransDetailDTOsImportAndUpdate)) { System.out.println("LOG: BAT DAU THUC HIEN DONG BO NHAP KIT"); StockTransDTO exportStockTransDTO = (StockTransDTO) DataUtil.cloneObject(stockTransDTO); exportStockTransDTO.setStockTransStatus(ParamUtils.TRANS_STATUS.WAITING_IMPORT); //duyot 27/01/2016 //tao danh sach serial cho tat cat hang hoa -> loc sau List<StockTransSerialDTO> lstStockTransSerialDTO = new ArrayList<>(); int countTemp = 0; for (StockTransDetailDTO i : lstStockTransDetailDTOsImportAndUpdate) { //set lai lst temp de filter String temp = countTemp + ""; i.setTmpStockTransDetailId(temp); // List<StockTransSerialDTO> lstSerialInDetail = i.getLstStockTransSerialDTO(); for (StockTransSerialDTO j : lstSerialInDetail) { j.setTmpStockTransDetailId(temp); lstStockTransSerialDTO.add(j); } // lstStockTransSerialDTO.addAll(lstSerialInDetail); countTemp++; } // exportStockTransDTO.setStockTransType("2"); exportStockTransDTO.setStockTransId(null); //Lay danh sach goods code tu transfersGoodsCode String goodsCodeList = getGoodsCodeList(lstStockTransDetailDTOsImportAndUpdate); List<ConditionBean> lstConditionBean = new ArrayList<>(); lstConditionBean.add(new ConditionBean("custId", ParamUtils.OP_EQUAL, stockTransDTO.getCustId(), ParamUtils.TYPE_NUMBER)); lstConditionBean .add(new ConditionBean("code", ParamUtils.OP_IN, goodsCodeList, ParamUtils.TYPE_STRING)); List<GoodsDTO> lstGoodsDTO = goodsBusiness.searchByConditionBean(lstConditionBean, 0, Integer.MAX_VALUE, "", "code"); //DAY VAO MAP DANH SACH HANG HOA Map<String, GoodsDTO> mapGoodsCode2DTO = DataUtil.putGoodsCodeToMap(lstGoodsDTO); ResultDTO result; // Map giua hang da xuat -> danh sach stock_goods cua hang do Map<String, List<StockGoods>> mapStockgoods = new HashMap<>(); Map<String, List<StockGoodsSerialStrip>> mapSerialTrip = new HashMap<>(); //Danh sach sim trang se xuat kho List<StockTransDetailDTO> lstExportDetail = DataUtil .cloneList(lstStockTransDetailDTOsImportAndUpdate); GoodsDTO goods; for (StockTransDetailDTO o : lstExportDetail) { goods = mapGoodsCode2DTO.get(o.getTransfersGoodsCode()); o.setGoodsCode(goods.getCode()); o.setGoodsId(goods.getGoodsId()); o.setGoodsName(goods.getName()); } //1--> BEGIN TRANS /* - khi da xuat hang -> dua ra map hang da ban cho phan nhap */ //-->2 THUC HIEN GIAO DICH XUAT MAT HANG SIM TRANG result = exportStockGoodsTransfer(exportStockTransDTO, lstExportDetail, DataUtil.cloneList(lstStockTransSerialDTO), session, transaction, mapStockgoods, mapSerialTrip); if (!result.getMessage().equals(ParamUtils.SUCCESS)) { return result; } //-->3 THUC HIEN GIAO DICH NHAP KIT DUOC XUAT TU SIM TRANG //1. Cap nhat vao transaction //set fromstocktransid stockTransDTO.setFromStockTransId(result.getId()); // List<GoodsInTicketDTO> lstGoods = new ArrayList<>(); stockTransDTO.setStockTransStatus(ParamUtils.TRANS_STATUS.WAITING_IMPORT); result = importStockGoodsTransfer(stockTransDTO, lstStockTransDetailDTOsImportAndUpdate, lstExportDetail, DataUtil.cloneList(lstStockTransSerialDTO), DataUtil.cloneList(lstStockTransSerialDTO), session, transaction, mapStockgoods, mapSerialTrip, lstGoods); if (!result.getMessage().equals(ParamUtils.SUCCESS)) { return result; } stockTransId = result.getId(); } //END QUYENDM: KET THUC NHAP KIT------------------------------------------------------------- //Ghi log ra file KPI String synSys = Constants.TYPE_ORDERS_BCCS.equalsIgnoreCase(ordersDTO.getSourceOrder()) ? "BCCS" : "KTTS"; String description = "Viet phieu nhap dong bo " + synSys + "| YC: " + orderIdList; System.out.println(DateUtil.sysdateString() + " | " + description); //DOI VOI HANG HOA KHONG PHAI LA HANG KIT--------------------------------------------------- if (!DataUtil.isListNullOrEmpty(lstStockTransDetail)) { //Kiem tra xem giao dich nhap thu hoi hay nhap moi if (ordersDTO.getInputType() != null && !ordersDTO.getInputType().equalsIgnoreCase("1")) { //Begin - ThienNG1 - NEU LA GIAO DICH THU HOI // resultDTO = reSyncImportRecovered(stockTransDTO, Constants.STATUS_SERIAL_WAIT_STOCK, session, transaction); //Begin - QuyenDM 20160413 - VIET LAI GIAO DICH THU HOI //---------------------------------------- //1. KHOI TAO CONNECTION resultDTO = reSyncImportRecovered(stockTransDTO, Constants.STATUS_SERIAL_WAIT_STOCK, connection, session); if (!resultDTO.getMessage().equalsIgnoreCase(ParamUtils.SUCCESS)) { rollback(session, transaction, connection); return resultDTO; } //End - QuyenDM 20160413 - VIET LAI GIAO DICH THU HOI } else { //NEU LA NHAP HANG BT //INSERT GIAO DICH STOCK_TRANS stockTransSEQ = stockTransBusiness.getSequence("STOCK_TRANS_SEQ"); stockTransCode = ParamUtils.CODE_IMPORT_STOCK + stockTransSEQ; stockTransDTO.setStockTransCode(stockTransCode); stockTransDTO.setCreateDatetime(sysdate); stockTransDTO.setStockTransDate(sysdate); stockTransDTO.setStockTransId(stockTransSEQ); // resultDTO = stockTransBusiness.createObjectSession(stockTransDTO, session); resultDTO = commonBusinessInterface.insertStockTrans(stockTransDTO, connection); stockTransId = stockTransDTO.getStockTransId(); stockTransDTO.setStockTransId(stockTransId); if (!resultDTO.getMessage().equals(ParamUtils.SUCCESS)) { rollback(session, transaction, connection); return resultDTO; } //DAY VAO MAP DANH SACH HANG HOA String goodsIdList = getGoodsIdList(lstStockTransDetail); List<ConditionBean> lstConditionBean = new ArrayList<>(); lstConditionBean.add(new ConditionBean("custId", ParamUtils.OP_EQUAL, stockTransDTO.getCustId(), ParamUtils.TYPE_NUMBER)); lstConditionBean.add( new ConditionBean("goodsId", ParamUtils.OP_IN, goodsIdList, ParamUtils.TYPE_NUMBER)); List<GoodsDTO> lstGoodsDTO = goodsBusiness.searchByConditionBean(lstConditionBean, 0, Integer.MAX_VALUE, "", "code"); mapGoodsDTO = DataUtil.putGoodsToMap(lstGoodsDTO); //LOOP: CHI TIET CHO TUNG MAT HANG for (StockTransDetailDTO stockTransDetailDTO : lstStockTransDetail) { //lay seq String stockTransDetailSEQ = stockTransDetailBusiness.getSequence("STOCK_TRANS_DETAIL_SEQ"); stockTransDetailDTO.setStockTransId(stockTransId); stockTransDetailDTO.setStockTransDetailId(stockTransDetailSEQ); stockTransDetailDTO.setStockTransDate(sysdate); stockTransDetailDTO.setCreateDatetime(sysdate); goodsDTO = mapGoodsDTO.get(stockTransDetailDTO.getGoodsId()); if (goodsDTO == null) { rollback(session, transaction, connection); resultDTO.setMessage(ParamUtils.GOODS_IS_NOT_EXIST); resultDTO.setKey(ParamUtils.GOODS_IS_NOT_EXIST); return resultDTO; } //INSERT CHI TIET GIAO DICH KHO STOCK_TRANS_DETAIL stockTransDetailDTO.setGoodsCode(goodsDTO.getCode()); stockTransDetailDTO.setGoodsName(goodsDTO.getName()); stockTransDetailDTO.setGoodsIsSerial(goodsDTO.getIsSerial()); stockTransDetailDTO.setGoodsIsSerialStrip(goodsDTO.getIsSerialStrip()); //------ resultDTO = commonBusinessInterface.insertStockTransDetail(stockTransDetailDTO, connection); //------------- stockTransDetailDTO.setStockTransDetailId(stockTransDetailSEQ); stockTransDetailId = stockTransDetailSEQ; // if (!resultDTO.getMessage().equals(ParamUtils.SUCCESS)) { rollback(session, transaction, connection); resultDTO.setMessage(Constants.ERROR_MESSAGE.INSERT_STOCK_TRANS_DETAIL_ERROR); resultDTO.setKey(Constants.ERROR_MESSAGE.INSERT_STOCK_TRANS_DETAIL_ERROR); return resultDTO; } //MAT HANG K THEO SERIAL if (!stockTransDetailDTO.getGoodsIsSerial().equals(Constants.IS_SERIAL)) { //Cap nhat mat hang theo so luong STOCK_GOODS resultDTO = importStockGoods(stockTransDTO, stockTransDetailDTO, session, ParamUtils.GOODS_IMPORT_STATUS.WAITING_IMPORT); if (!resultDTO.getMessage().equals(ParamUtils.SUCCESS)) { rollback(session, transaction, connection); return resultDTO; } } else //MAT HANG QUAN LY THEO SERIAL { //LAY RA DANH SACH SERIAL CUA HANG HOA TUONG UNG filterListStockTransSerialDTO = stockTransDetailDTO.getLstStockTransSerialDTO(); if (filterListStockTransSerialDTO == null || filterListStockTransSerialDTO.size() < 1) { resultDTO.setMessage(ParamUtils.FAIL); resultDTO.setKey(ParamUtils.SYSTEM_OR_DATA_ERROR); rollback(session, transaction, connection); return resultDTO; } //Insert giao dich chi tiet serial amountIssue = 0D; //khoi tao list serial duoc nhap kho cho mat hang nay for (StockTransSerialDTO stockTransSerialDTO : filterListStockTransSerialDTO) { //Cap nhat Id giao dich, ID chi tiet giao dichj stockTransSerialDTO.setStockTransId(stockTransId); stockTransSerialDTO.setStockTransDetailId(stockTransDetailId); stockTransSerialDTO.setStockTransDate(sysdate); stockTransSerialDTO.setCreateDatetime(sysdate); stockTransSerialDTO.setGoodsCode(goodsDTO.getCode()); stockTransSerialDTO.setGoodsName(goodsDTO.getName()); } //Insert batch VAO KHO STOCK_GOODS_SERIAL resultDTO = importStockGoodsListSerial(stockTransDTO, stockTransDetailDTO, filterListStockTransSerialDTO, session, connection, ParamUtils.GOODS_IMPORT_STATUS.WAITING_IMPORT); insertSuccess = insertSuccess + resultDTO.getQuantitySucc(); insertFail = insertFail + resultDTO.getQuantityFail(); amountIssue = resultDTO.getAmountIssue(); // if (!resultDTO.getMessage().equals(ParamUtils.SUCCESS)) { rollback(session, transaction, connection); return resultDTO; } //KIEM TRA SO LUONG UPDATE SERIAL -> NEU CO LOI -> DAU RA THONG BAO if (insertFail > 0) { resultDTO.setQuantitySucc(insertSuccess); resultDTO.setQuantityFail(insertFail); resultDTO.setId(stockTransId); resultDTO.setMessage(Constants.ERROR_MESSAGE.IS_OVERLAP); rollback(session, transaction, connection); return resultDTO; } //END FOR FILTER LIST //CAP NHAT LAI STOCK_TRANS_DETAIL VOI SO LUONG INSERT THANH CONG stockTransDetailDTO.setAmountReal(amountIssue.toString().replace(".0", "")); int isUpdate = stockGoodsSerialBusiness2.updateStockTransDetail(stockTransDetailId, amountIssue, connection); //neu update khong thanh cong if (isUpdate < 1) { resultDTO.setMessage(ParamUtils.FAIL); resultDTO.setKey("UPDATE_STOCK_TRANS_DETAIL_ERROR"); rollback(session, transaction, connection); return resultDTO; } } } //KET THUC NHAP HANG BT // } //KET THUC NHHAP K PHAI KIT } //DUYOT: KET THUC: GOI HAM DONG BO-------------------------------------- /* duyot: dong bo sang bccs: gui thong tin thuc nhap 1. lay ra thong tin nhap kho theo format: billstock-listgoods-list serial 2. goi sang service bccs 3. check ket qua tra ve */ resultDTO = getListOrdersTicket(stockTransDTO, ordersDTO, connection, session); if (!ParamUtils.SUCCESS.equals(resultDTO.getMessage())) { rollback(session, transaction, connection); // resultDTO.setMessage(ParamUtils.FAIL); resultDTO.setKey(ParamUtils.ERROR_MESSAGE.SYNC_FAIL); return resultDTO; } //neu hoan toan k co loi -> commit commit(session, transaction, connection); } catch (Exception e) { rollback(session, transaction, connection); Logger.getLogger(StockImportServiceImpl.class.getName()).log(Level.SEVERE, null, e); resultDTO.setMessage(e.getMessage()); resultDTO.setKey(ParamUtils.SYSTEM_OR_DATA_ERROR); return resultDTO; } finally { time = System.currentTimeMillis() - startTime; //Ghi ra file KPI.log if (resultDTO.getMessage() != null) { strResult = resultDTO.getMessage().equalsIgnoreCase(null) ? resultDTO.getKey() : resultDTO.getMessage(); } //Ghi ra file Catalina.out //Ghi log ra file KPI synKpiLog.setFunctionCode(functionCode); synKpiLog.setTransactionCode(transactionCode); descr = "Tong thoi gian viet phieu nhap " + transactionCode + " : " + time; System.out.println(descr); KPILogger.createLogs(descr); if (!strResult.equalsIgnoreCase(ParamUtils.SUCCESS)) { reason = resultDTO.getMessage(); synKpiLog.setReason(reason); synKpiLog.setStockTransStatus(SYN_FAIL); } else { synKpiLog.setStockTransStatus(SYN_SUCC); } synKpiLog.setEndTime(DateUtil.sysdateString()); synKpiLog.setDuration(String.valueOf(time)); synKpiLog.setDescription("Tao phieu nhap dong bo tren HT LOG"); //Ghi ra bang kpi_log kpiLogBusiness.createKpiLog(synKpiLog); try { if (session.isOpen()) { session.close(); } if (connection != null && !connection.isClosed()) { connection.close(); } } catch (SQLException ex) { Logger.getLogger(StockImportServiceImpl.class.getName()).log(Level.SEVERE, null, ex); } } // resultDTO.setQuantitySucc(insertSuccess); resultDTO.setQuantityFail(insertFail); resultDTO.setId(stockTransId); return resultDTO; }
From source file:com.viettel.logistic.wms.service.StockTransServiceImpl.java
License:Open Source License
private void inventoryImportTransaction(Session session, Connection connection, SessionFactory sessionFactoryBatch, StockTransDTO tempStockTrans, String oldStockTranId) { try {/*from w w w. j a va 2s .c om*/ boolean isSuccess = false; connection = sessionFactoryBatch.getSessionFactoryOptions().getServiceRegistry() .getService(ConnectionProvider.class).getConnection(); connection.setAutoCommit(false); if (createStockTrans(tempStockTrans, connection)) { //Thuc hien them hang hoa giao dich va cac bang du lieu lien quan isSuccess = insertStockTransDetailsImport(oldStockTranId, tempStockTrans, session, connection); } //Neu thuc hien thanh cong thi commit if (isSuccess) { commit(null, null, connection); } else {//Neu khong rollback rollback(null, null, connection); } } catch (SQLException ex) { rollback(null, null, connection); Logger.getLogger(StockTransServiceImpl.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:edu.jhuapl.dorset.components.HibernateServiceTest.java
License:Open Source License
@Test public void testCreationOfSessionFactory() { Properties props = getProperties(); Config conf = ConfigFactory.parseProperties(props); hs = new HibernateService(conf); SessionFactory sf = hs.getSessionFactory(); assertNotNull(sf);/*from www . ja v a 2s . c o m*/ assertFalse(sf.isClosed()); // traverse through the session factory to get at configuration values SessionFactoryOptions sfo = sf.getSessionFactoryOptions(); StandardServiceRegistry ssr = sfo.getServiceRegistry(); ConfigurationService cs = ssr.getService(ConfigurationService.class); assertEquals(props.getProperty("hibernate.connection.driver_class"), cs.getSetting("hibernate.connection.driver_class", StandardConverters.STRING)); assertEquals(props.getProperty("hibernate.connection.url"), cs.getSetting("hibernate.connection.url", StandardConverters.STRING)); assertEquals(props.getProperty("hibernate.dialect"), cs.getSetting("hibernate.dialect", StandardConverters.STRING)); assertEquals(props.getProperty("hibernate.hbm2ddl.auto"), cs.getSetting("hibernate.hbm2ddl.auto", StandardConverters.STRING)); // check mapping ClassMetadata cm = sf.getClassMetadata(TestObject.class); String[] names = cm.getPropertyNames(); assertEquals(1, names.length); assertEquals("name", names[0]); assertEquals("string", cm.getPropertyType("name").getName()); }
From source file:org.springframework.orm.jpa.hibernate.HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests.java
License:Apache License
private ManagedBeanRegistry getManagedBeanRegistry() { SessionFactory sessionFactory = entityManagerFactory.unwrap(SessionFactory.class); ServiceRegistry serviceRegistry = sessionFactory.getSessionFactoryOptions().getServiceRegistry(); return serviceRegistry.requireService(ManagedBeanRegistry.class); }