List of usage examples for org.hibernate Session getSessionFactory
SessionFactory getSessionFactory();
From source file:com.netsteadfast.greenstep.util.DataUtils.java
License:Apache License
public ClassMetadata getClassMetadataByEntityName(Session session, String name) throws Exception { return session.getSessionFactory().getClassMetadata(name); }
From source file:com.reignite.parser.MappedClassEntityResolver.java
License:Open Source License
@Override public String resolveName(Session session, String queryObj) { @SuppressWarnings("unchecked") Map<String, ClassMetadata> classMap = session.getSessionFactory().getAllClassMetadata(); for (String name : classMap.keySet()) { if (name.endsWith("." + queryObj)) { return name; }/* www.j a v a2 s .co m*/ } return queryObj; }
From source file:com.reignite.parser.MappedClassEntityResolver.java
License:Open Source License
@Override public ClassMetadata resolveMetadata(Session session, String queryObj) { String name = this.resolveName(session, queryObj); return session.getSessionFactory().getClassMetadata(name); }
From source file:com.turborep.turbotracker.banking.service.BankingServiceImpl.java
License:Open Source License
@Override public void printCheckDetails(HttpServletResponse theResponse, HttpServletRequest theRequest) throws BankingException { Session printBeanSession = itsSessionFactory.openSession(); SessionFactoryImplementor sessionFactoryImplementation = (SessionFactoryImplementor) printBeanSession .getSessionFactory();/*from w w w . j a va 2 s .c o m*/ ConnectionProvider connectionProvider = sessionFactoryImplementation.getConnectionProvider(); Map<String, Object> params = new HashMap<String, Object>(); //Rxaddress address = null; Connection connection = null; InputStream imageStream = null; try { Integer addressID = rxAddressID[0]; //address = (Rxaddress)printBeanSession.get(Rxaddress.class,addressID); params.put("Name", ""); params.put("Address2", ""); params.put("Address3", ""); itsLogger.info(billId.length); String count = billId.length + ""; params.put("BillCount", count); params.put("CheckDate", checkDate); TsUserSetting objtsusersettings = (TsUserSetting) printBeanSession.get(TsUserSetting.class, 1); Blob blob = objtsusersettings.getCompanyLogo(); imageStream = blob.getBinaryStream(); //params.put("companyLogo", imageStream); itsLogger.info("Check Date: " + checkDate); ServletOutputStream out = theResponse.getOutputStream(); String fileName = theRequest.getParameter("fileName"); theResponse.setHeader("Content-Disposition", "attachment; filename=" + fileName); theResponse.setContentType("application/pdf"); connection = connectionProvider.getConnection(); String path_JRXML = theRequest.getSession().getServletContext() .getRealPath("/resources/jasper_reports/PrintChecksfinal.jrxml"); //String path_JRXML = theRequest.getSession().getServletContext().getRealPath("/resources/jasper_reports/CheckMICR.jrxml"); JasperReport report = JasperCompileManager.compileReport(path_JRXML); JasperPrint print = JasperFillManager.fillReport(report, params, connection); ByteArrayOutputStream baos = new ByteArrayOutputStream(); JasperExportManager.exportReportToPdfStream(print, baos); out.write(baos.toByteArray()); out.flush(); out.close(); } catch (Exception e) { itsLogger.error(e.getMessage(), e); BankingException aBankingException = new BankingException(e.getMessage(), e); } finally { try { if (imageStream != null) { imageStream.close(); } if (connectionProvider != null) { connectionProvider.closeConnection(connection); connectionProvider = null; } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } printBeanSession.flush(); printBeanSession.close(); } }
From source file:com.turborep.turbotracker.banking.service.BankingServiceImpl.java
License:Open Source License
@Override public void newCheckDetails(HttpServletResponse theResponse, HttpServletRequest theRequest) throws BankingException { Session printBeanSession = itsSessionFactory.openSession(); SessionFactoryImplementor sessionFactoryImplementation = (SessionFactoryImplementor) printBeanSession .getSessionFactory();//w w w . jav a 2s . com ConnectionProvider connectionProvider = sessionFactoryImplementation.getConnectionProvider(); Map<String, Object> params = new HashMap<String, Object>(); Connection connection = null; try { itsLogger.info("Testing:--->" + theRequest.getParameter("moTransactionID")); params.put("traxID", Integer.parseInt(theRequest.getParameter("moTransactionID"))); ServletOutputStream out = theResponse.getOutputStream(); String fileName = theRequest.getParameter("fileName"); theResponse.setHeader("Content-Disposition", "attachment; filename=" + fileName); theResponse.setContentType("application/pdf"); connection = connectionProvider.getConnection(); String path_JRXML = theRequest.getSession().getServletContext() .getRealPath("/resources/jasper_reports/newcheck.jrxml"); JasperReport report = JasperCompileManager.compileReport(path_JRXML); JasperPrint print = JasperFillManager.fillReport(report, params, connection); ByteArrayOutputStream baos = new ByteArrayOutputStream(); JasperExportManager.exportReportToPdfStream(print, baos); out.write(baos.toByteArray()); out.flush(); out.close(); } catch (Exception e) { itsLogger.error(e.getMessage(), e); BankingException aBankingException = new BankingException(e.getMessage(), e); } finally { try { if (connectionProvider != null) { connectionProvider.closeConnection(connection); connectionProvider = null; } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } printBeanSession.flush(); printBeanSession.close(); } }
From source file:com.turborep.turbotracker.banking.service.BankingServiceImpl.java
License:Open Source License
@Override public void creditCheckDetails(HttpServletResponse theResponse, HttpServletRequest theRequest) throws BankingException { Session printBeanSession = itsSessionFactory.openSession(); SessionFactoryImplementor sessionFactoryImplementation = (SessionFactoryImplementor) printBeanSession .getSessionFactory();/* w ww . j a v a 2 s .c om*/ ConnectionProvider connectionProvider = sessionFactoryImplementation.getConnectionProvider(); Map<String, Object> params = new HashMap<String, Object>(); Connection connection = null; Rxaddress address = null; try { itsLogger.info("Testing:--->" + theRequest.getParameter("moTransactionID")); ServletOutputStream out = theResponse.getOutputStream(); String fileName = theRequest.getParameter("fileName"); theResponse.setHeader("Content-Disposition", "attachment; filename=" + fileName); theResponse.setContentType("application/pdf"); connection = connectionProvider.getConnection(); String path_JRXML = theRequest.getSession().getServletContext() .getRealPath("/resources/jasper_reports/CreditPayment.jrxml"); JasperReport report = JasperCompileManager.compileReport(path_JRXML); JasperPrint print = JasperFillManager.fillReport(report, params, connection); ByteArrayOutputStream baos = new ByteArrayOutputStream(); JasperExportManager.exportReportToPdfStream(print, baos); out.write(baos.toByteArray()); out.flush(); out.close(); } catch (Exception e) { itsLogger.error(e.getMessage(), e); BankingException aBankingException = new BankingException(e.getMessage(), e); // throw aBankingException; } finally { try { if (connectionProvider != null) { connectionProvider.closeConnection(connection); connectionProvider = null; } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } printBeanSession.flush(); printBeanSession.close(); } }
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;//from w ww .j a v a 2s. 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; Connection connection;/*from w w w. j a v a 2s . c om*/ 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; Connection connection;/*w ww . j a va2 s . co m*/ 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;// w w w. j a va 2 s .c o 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; }