List of usage examples for org.hibernate Session getSessionFactory
SessionFactory getSessionFactory();
From source file:com.conecta.sat.controller.CentroFinancieroVirtualController.java
@RequestMapping(value = "virtualCenterReportXls.do", method = RequestMethod.GET) public String virtualCenterReportXls(HttpServletRequest request, HttpServletResponse resp) throws JRException, SQLException, IOException, Exception { String url = request.getSession().getServletContext() .getRealPath("/resources/reports/CentroFinancieroVirtual.jasper"); DateFormat name = new SimpleDateFormat("ddMMyyyyhhmmss"); Map parameters = new HashMap(); StockTokenadmin soft = new StockTokenadmin(); soft = this.stockTokenAdminServiceImpl.getStockSoft(); parameters.put("stockUtilizado", soft.getStockUtilizado()); parameters.put("stockTotal", soft.getStockTotal()); Session session = em.unwrap(Session.class); SessionFactoryImplementor sfi = (SessionFactoryImplementor) session.getSessionFactory(); ConnectionProvider cp = sfi.getConnectionProvider(); Connection conn = cp.getConnection(); JasperPrint jasperPrint = JasperFillManager.fillReport(url, parameters, conn); JRXlsxExporter xlsxExporter = new JRXlsxExporter(); ByteArrayOutputStream os = new ByteArrayOutputStream(); xlsxExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); xlsxExporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "CentroFinancieroVirtual" + name.format(new Date()) + ".xlsx"); xlsxExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, os); xlsxExporter.exportReport();//from w w w . j a v a2 s.c om resp.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); resp.setHeader("Content-Disposition", "attachment; filename=CentroFinancieroVirtual" + name.format(new Date()) + ".xlsx"); resp.getOutputStream().write(os.toByteArray()); resp.getOutputStream().flush(); resp.getOutputStream().close(); resp.flushBuffer(); return null; }
From source file:com.conecta.sat.controller.ReportsController.java
@RequestMapping(value = "statusDeviceReport.do", method = RequestMethod.GET) public String statusDeviceReport(HttpServletRequest request, HttpServletResponse resp) throws JRException, SQLException, IOException { // logger.info("Path: "+ReportsController.class.get); String url = request.getSession().getServletContext() .getRealPath("/resources/reports/EstatusDispositivos.jasper"); logger.info("URL: " + url); HttpSession sessionUser = request.getSession(); // String fullPath = context.getRealPath("/WEB-INF/test/foo.txt"); Map parameters = new HashMap(); parameters.put("userName", sessionUser.getAttribute("userName").toString()); parameters.put("userNumber", sessionUser.getAttribute("userId").toString()); // byte[] bytes = JasperRunManager.runReportToPdf("/WEB-INF/resources/reports/EstatusDispositivos.jasper", parameters); try {// w w w .jav a2 s. co m // String path = request.getSession().getServletContext().getRealPath("\\WEB-INF\\reports\\xxx.jrxml"); // JasperReport jasperReport = JasperCompileManager.compileReport(url); Session session = em.unwrap(Session.class); SessionFactoryImplementor sfi = (SessionFactoryImplementor) session.getSessionFactory(); ConnectionProvider cp = sfi.getConnectionProvider(); Connection conn = cp.getConnection(); // JasperPrint jasperPrint = JasperFillManager.fillReport(url, parameters,); JasperPrint jasperPrint = JasperFillManager.fillReport(url, parameters, conn); byte[] pdfBytes = JasperExportManager.exportReportToPdf(jasperPrint); //uncomment this line to make browser download the file resp.setContentType("application/pdf"); resp.setHeader("Content-Disposition", "attachment;filename=EstatusDispositivos" + name.format(new Date()) + ".pdf"); resp.getOutputStream().write(pdfBytes); resp.getOutputStream().flush(); resp.getOutputStream().close(); resp.flushBuffer(); } catch (JRException ex) { logger.error(ex.getMessage(), ex.getCause()); } catch (IOException ex) { logger.error(ex.getMessage(), ex.getCause()); } // byte[] bytes = JasperRunManager.runReportToPdf(url, parameters); // resp.reset(); // resp.resetBuffer(); // resp.setContentType("application/pdf"); // resp.setContentLength(bytes.length); // ServletOutputStream ouputStream = resp.getOutputStream(); // ouputStream.write(bytes, 0, bytes.length); // ouputStream.flush(); // ouputStream.close(); return null; }
From source file:com.conecta.sat.controller.ReportsController.java
@RequestMapping(value = "statusDeviceReportXls.do", method = RequestMethod.GET) public String statusDeviceReportXls(HttpServletRequest request, HttpServletResponse resp) throws JRException, SQLException, IOException { String url = request.getSession().getServletContext() .getRealPath("/resources/reports/EstatusDispositivos.jasper"); DateFormat name = new SimpleDateFormat("ddMMyyyyhhmmss"); logger.info("URL: " + url); HttpSession sessionUser = request.getSession(); Map parameters = new HashMap(); parameters.put("userName", sessionUser.getAttribute("userName").toString()); parameters.put("userNumber", sessionUser.getAttribute("userId").toString()); Session session = em.unwrap(Session.class); SessionFactoryImplementor sfi = (SessionFactoryImplementor) session.getSessionFactory(); ConnectionProvider cp = sfi.getConnectionProvider(); Connection conn = cp.getConnection(); // JasperPrint jasperPrint = JasperFillManager.fillReport(url, parameters); JasperPrint jasperPrint = JasperFillManager.fillReport(url, parameters, conn); JRXlsxExporter xlsxExporter = new JRXlsxExporter(); ByteArrayOutputStream os = new ByteArrayOutputStream(); xlsxExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); xlsxExporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "EstatusDispositivos" + name.format(new Date()) + ".xlsx"); xlsxExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, os); xlsxExporter.exportReport();/*from w w w .j a v a2 s . co m*/ resp.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); resp.setHeader("Content-Disposition", "attachment; filename=EstatusDispositivos" + name.format(new Date()) + ".xlsx"); resp.getOutputStream().write(os.toByteArray()); resp.getOutputStream().flush(); resp.getOutputStream().close(); resp.flushBuffer(); return null; }
From source file:com.coroptis.coidi.op.view.util.AbstractIntegrationDaoTest.java
License:Apache License
/** * Get connections to real database./*www.j a v a2 s.com*/ * * @return connection to database * @throws Exception */ @Override protected IDatabaseConnection getConnection() throws Exception { Preconditions.checkNotNull(pageTester.getRegistry(), "registry"); Session session = pageTester.getRegistry().getService(Session.class); return new MockIDatabaseConnection(session.getSessionFactory()); }
From source file:com.court.controller.HomeFXMLController.java
private Map<String, Number> getLoanReleasedData() { LocalDate now = LocalDate.now(); Map<String, Number> map = new HashMap<>(); Session s = HibernateUtil.getSessionFactory().openSession(); Criteria c = s.createCriteria(MemberLoan.class); ProjectionList pList = Projections.projectionList(); ClassMetadata lpMeta = s.getSessionFactory().getClassMetadata(MemberLoan.class); pList.add(Projections.property(lpMeta.getIdentifierPropertyName())); for (String prop : lpMeta.getPropertyNames()) { pList.add(Projections.property(prop), prop); }//from w w w.j a v a2 s.c om c.add(Restrictions.eq("status", true)); c.add(Restrictions.between("grantedDate", FxUtilsHandler.getDateFrom(now.with(firstDayOfYear())), FxUtilsHandler.getDateFrom(now.with(lastDayOfYear())))); c.setProjection(pList .add(Projections.sqlGroupProjection("DATE_FORMAT(granted_date, '%Y-%m-01') AS groupPro", "groupPro", new String[] { "groupPro" }, new Type[] { StringType.INSTANCE })) .add(Projections.sqlProjection("SUM(loan_amount) AS lSum", new String[] { "lSum" }, new Type[] { DoubleType.INSTANCE }))); c.addOrder(Order.asc("grantedDate")); c.setResultTransformer(Transformers.aliasToBean(MemberLoan.class)); List<MemberLoan> list = (List<MemberLoan>) c.list(); for (MemberLoan ml : list) { map.put(ml.getGroupPro(), ml.getlSum()); } s.close(); return map; }
From source file:com.court.controller.HomeFXMLController.java
private Map<String, Number> getLoanCollectionData() { LocalDate now = LocalDate.now(); Map<String, Number> map = new HashMap<>(); Session s = HibernateUtil.getSessionFactory().openSession(); Criteria c = s.createCriteria(LoanPayment.class); ProjectionList pList = Projections.projectionList(); ClassMetadata lpMeta = s.getSessionFactory().getClassMetadata(LoanPayment.class); pList.add(Projections.property(lpMeta.getIdentifierPropertyName())); for (String prop : lpMeta.getPropertyNames()) { pList.add(Projections.property(prop), prop); }/*from w w w.j a v a 2 s . c o m*/ c.add(Restrictions.between("paymentDate", FxUtilsHandler.getDateFrom(now.with(firstDayOfYear())), FxUtilsHandler.getDateFrom(now.with(lastDayOfYear())))); c.setProjection(pList .add(Projections.sqlGroupProjection("DATE_FORMAT(payment_date, '%Y-%m-01') AS groupPro", "groupPro", new String[] { "groupPro" }, new Type[] { StringType.INSTANCE })) .add(Projections.sqlProjection("SUM(paid_amt) AS lSum", new String[] { "lSum" }, new Type[] { DoubleType.INSTANCE }))); c.addOrder(Order.asc("paymentDate")); c.setResultTransformer(Transformers.aliasToBean(LoanPayment.class)); List<LoanPayment> list = (List<LoanPayment>) c.list(); for (LoanPayment lp : list) { map.put(lp.getGroupPro(), lp.getlSum()); } s.close(); return map; }
From source file:com.court.controller.OldLoansFxmlController.java
private List<Member> getMembers() { Session s = HibernateUtil.getSessionFactory().openSession(); Criteria c = s.createCriteria(Member.class); c.add(Restrictions.eq("status", true)); ClassMetadata lpMeta = s.getSessionFactory().getClassMetadata(Member.class); c.setProjection(Projections.projectionList().add(Projections.property(lpMeta.getIdentifierPropertyName())) .add(Projections.property("memberId"), "memberId") .add(Projections.property("fullName"), "fullName")); c.setResultTransformer(Transformers.aliasToBean(Member.class)); List<Member> list = c.list(); s.close();/*w w w .ja v a2 s .c om*/ return list; }
From source file:com.daphne.es.common.repository.hibernate.HibernateUtils.java
License:Apache License
/** * ?jpa EntityManager ? hibernate SessionFactory API * * @param em//from w ww . j av a 2 s. c o m * @return * @see #getSessionFactory(javax.persistence.EntityManagerFactory) */ public static SessionFactory getSessionFactory(EntityManager em) { Session session = (Session) em.getDelegate(); SessionFactoryImpl sessionFactory = (SessionFactoryImpl) session.getSessionFactory(); return sessionFactory; }
From source file:com.dutchconnected.fruithuis.frames.Crud.java
public Query<E> selectAll(Session s) { CriteriaQuery<E> createQuery = s.getSessionFactory().getCriteriaBuilder().createQuery(getClazz()); createQuery.from(getClazz());/*w w w . ja v a2 s . c o m*/ return s.createQuery(createQuery); }
From source file:com.europabrewing.util.HibernateUtil.java
License:Open Source License
/** * Print all data that is held in this database * * @throws org.hibernate.HibernateException *//*www . j a v a 2s. co m*/ public static void printAllData() throws HibernateException { Session session = getSession(); try { System.out.println("querying all the managed entities..."); final Map<String, ClassMetadata> metadataMap = session.getSessionFactory().getAllClassMetadata(); for (String key : metadataMap.keySet()) { final ClassMetadata classMetadata = metadataMap.get(key); final String entityName = classMetadata.getEntityName(); final Query query = session.createQuery("from " + entityName); System.out.println("executing: " + query.getQueryString()); for (Object o : query.list()) { System.out.println(" " + o); } } } finally { session.close(); } }