List of usage examples for org.hibernate.criterion DetachedCriteria getExecutableCriteria
public Criteria getExecutableCriteria(Session session)
From source file:com.wwinsoft.modules.orm.hibernate.HibernateDao.java
License:Apache License
public Page<T> findDetachedPage(final Page<T> page, final List<PropertyFilter> filters) { ResolveAlias ra = new ResolveAlias(); DetachedCriteria detachedCriteria = buildDetachedCriteriaByPropertyFilter(filters, ra); if (page.isOrderBySetted()) { String[] orderByArray = StringUtils.split(page.getOrderBy(), ','); List<String> orderByArrayNew = new ArrayList<String>(); for (int i = 0; i < orderByArray.length; i++) { String orderByNew = getRealPropertyName(orderByArray[i], ra); orderByArrayNew.add(orderByNew); }//from w ww.j av a2s . c o m page.setOrderBy(StringUtils.join(orderByArrayNew, ',')); } Criteria c = detachedCriteria.getExecutableCriteria(getSession()); if (page.isAutoCount()) { long totalCount = countCriteriaResult(c); page.setTotalCount(totalCount); } setPageParameterToCriteria(c, page); List result = c.list(); page.setResult(result); return page; }
From source file:com.yougou.api.service.impl.ApiServiceImpl.java
@Override public PageFinder<Api> queryApi(DetachedCriteria criteria, Query query) throws Exception { Session session = null;/* w w w. j av a 2 s . c o m*/ try { session = apiDao.getHibernateSession(); Criteria executableCriteria = criteria.getExecutableCriteria(session); return apiDao.pagedByCriteria(executableCriteria, query.getPage(), query.getPageSize()); } finally { apiDao.releaseHibernateSession(session); } }
From source file:com.zdtx.ifms.common.service.BaseManager.java
/** * public do print pdf interface/*from ww w . j av a2 s. c om*/ */ public void doPrintPdf(final String title, final Boolean hasSeq, final String headerArray, final String fieldsArray, final Map<String, String> convert, final Integer[] colWidth, final Integer pageSize, final String... paper) { DetachedCriteria criteria = (DetachedCriteria) Struts2Util.getSession().getAttribute("criteria_export"); Criteria criteria2 = criteria.getExecutableCriteria(baseDao.getSession()); criteria2.setFirstResult(0); criteria2.setMaxResults(1000); Utils.printPDF(title, hasSeq, criteria2.list(), headerArray, fieldsArray, convert, colWidth, pageSize, paper); }
From source file:com.zdtx.ifms.common.service.BaseManager.java
/** * public do export excel interface// ww w. j av a 2 s.co m */ public InputStream doExportExcel(final String title, final String headerArray, final String fieldsArray, final Map<String, String> convert) { DetachedCriteria detachedCriteria = (DetachedCriteria) Struts2Util.getSession() .getAttribute("criteria_export"); Criteria criteria = detachedCriteria.getExecutableCriteria(baseDao.getSession()); criteria.setFirstResult(0); criteria.setMaxResults(1000); return Utils.exportExcel(criteria.list(), title, headerArray, fieldsArray, convert); }
From source file:com.zdtx.ifms.specific.service.monitor.IpCamManager.java
public Page<Camera> getBatch(Page<Camera> page, IpCamVO vo) { DetachedCriteria criteria = DetachedCriteria.forClass(Camera.class); criteria.createAlias("modelID", "modelID"); criteria.add(Restrictions.eq("isDelete", "F")); criteria.add(Restrictions.in("deptid", (Long[]) Struts2Util.getSession().getAttribute("userDepartment"))); if (null != vo.getDepartmentid() && -1L != vo.getDepartmentid()) { criteria.add(Restrictions.eq("deptid", vo.getDepartmentid())); }/*from ww w. ja v a 2 s. co m*/ if (!Utils.isEmpty(vo.getModelID()) && vo.getModelID() != -1L) { criteria.add(Restrictions.eq("modelID.modelID", vo.getModelID())); } if (!Utils.isEmpty(vo.getCamName())) { criteria.add(Restrictions.ilike("cameraName", "%" + vo.getCamName() + "%")); } if (!Utils.isEmpty(vo.getCamCode())) { criteria.add(Restrictions.ilike("cameraCode", "%" + vo.getCamCode() + "%")); } if (!Utils.isEmpty(vo.getCamIP())) { criteria.add(Restrictions.ilike("ipAddress", "%" + vo.getCamIP() + "%")); } List<Order> orderList = new ArrayList<Order>(); orderList.add(Order.asc("cameraName")); // orders.add(Order.asc("modelID.modelID")); Page<Camera> pageResult = dao.getBatch(page, criteria.getExecutableCriteria(dao.getSession()), orderList); if (1 == pageResult.getCurrentPage()) { Utils.getSession().setAttribute("criteria_export", criteria); Utils.getSession().setAttribute("page_export", page); Utils.getSession().setAttribute("orderList_export", orderList); } return pageResult; }
From source file:com.zdtx.ifms.specific.service.monitor.IpCamManager.java
@SuppressWarnings("unchecked") public InputStream getExcel(String title) { List<Camera> data = new ArrayList<Camera>(); Page<Camera> page_export = (Page<Camera>) Utils.getSession().getAttribute("page_export"); DetachedCriteria criteria_export = (DetachedCriteria) Utils.getSession().getAttribute("criteria_export"); List<Order> orderList_export = (List<Order>) Utils.getSession().getAttribute("orderList_export"); page_export.setPageSize(page_export.getTotalCount()); Page<Camera> pageResult = dao.getBatch(page_export, criteria_export.getExecutableCriteria(dao.getSession()), orderList_export);//from w w w .j ava 2 s. c om if (null != pageResult) { if (0 != pageResult.getResult().size()) { data = pageResult.getResult(); } } ExportExcel ee = new ExportExcel() { @Override protected HSSFWorkbook disposeData(HSSFWorkbook wb, Object[] total, List<?> data) throws IOException { HSSFSheet sheet = wb.getSheetAt(0); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6)); HSSFRow rowss = sheet.createRow(0); rowss.setHeightInPoints(20); HSSFCell hssfCell = rowss.createCell(0); hssfCell = this.createCell(wb, hssfCell, total[0].toString()); HSSFCellStyle style = this.createStyle(wb); HSSFRow row2 = sheet.createRow(1); HSSFCell cellrow01 = row2.createCell(0); cellrow01.setCellStyle(style); HSSFCell cellrow02 = row2.createCell(1); cellrow02.setCellStyle(style); HSSFCell cellrow03 = row2.createCell(2); cellrow03.setCellStyle(style); HSSFCell cellrow04 = row2.createCell(3); cellrow04.setCellStyle(style); HSSFCell cellrow05 = row2.createCell(4); cellrow05.setCellStyle(style); HSSFCell cellrow06 = row2.createCell(5); cellrow06.setCellStyle(style); HSSFCell cellrow07 = row2.createCell(6); cellrow07.setCellStyle(style); cellrow01.setCellValue("No."); cellrow02.setCellValue("Camera Name"); cellrow03.setCellValue("Department"); cellrow04.setCellValue("Camera Model"); cellrow05.setCellValue("IP"); cellrow06.setCellValue("Login Username"); cellrow07.setCellValue("Login Password"); if (null != data && 0 != data.size()) { for (int i = 0; i < data.size(); i++) { Object[] o = (Object[]) data.get(i); CamModel cm = (CamModel) o[0]; Camera a = (Camera) o[1]; HSSFRow row = sheet.createRow(i + 2); HSSFCell cell001 = row.createCell(0); cell001.setCellStyle(style); cell001.setCellValue(i + 1); HSSFCell cell002 = row.createCell(1); cell002.setCellStyle(style); cell002.setCellValue(a.getCameraName()); HSSFCell cell003 = row.createCell(2); cell003.setCellStyle(style); cell003.setCellValue(a.getDeptname()); HSSFCell cell004 = row.createCell(3); cell004.setCellStyle(style); cell004.setCellValue(cm.getModelName()); HSSFCell cell005 = row.createCell(4); cell005.setCellStyle(style); cell005.setCellValue(a.getIpAddress()); HSSFCell cell006 = row.createCell(5); cell006.setCellStyle(style); cell006.setCellValue(a.getAdminName()); HSSFCell cell007 = row.createCell(6); cell007.setCellStyle(style); cell007.setCellValue(a.getAdminPass()); } } return wb; } }; Object[] total = new Object[1]; total[0] = title; String str = title; return ee.export(total, data, str); }
From source file:com.zdtx.ifms.specific.service.task.FuelMileageManager.java
public Page<Mileageoil> getBetch(Page<Mileageoil> page, FuelMileageVo fmvo) { DetachedCriteria criteria = DetachedCriteria.forClass(Mileageoil.class); if (fmvo.getVehicleid() != null && fmvo.getVehicleid() != -1) { criteria.add(Restrictions.eq("vehicleid", fmvo.getVehicleid())); }//from w w w . ja v a2 s . c om if (fmvo.getTypeid() != null && fmvo.getTypeid() != -1l) { criteria.add(Restrictions.eq("typeid", fmvo.getTypeid())); } if (fmvo.getStartdate() != null && !"".equals(fmvo.getStartdate())) { criteria.add(Restrictions.ge("riqi", fmvo.getStartdate())); } if (fmvo.getEnddate() != null && !"".equals(fmvo.getEnddate())) { criteria.add(Restrictions.le("riqi", fmvo.getEnddate())); } List<Order> orderList = new ArrayList<Order>(); orderList.add(Order.asc("riqi")); Page<Mileageoil> pageResult = baseDao.getBatch(page, criteria.getExecutableCriteria(baseDao.getSession()), orderList); if (1 == pageResult.getCurrentPage()) { Struts2Util.getSession().setAttribute("criteria_export", criteria); Struts2Util.getSession().setAttribute("page_export", page); Struts2Util.getSession().setAttribute("order_export", orderList); } return pageResult; }
From source file:com.zdtx.ifms.specific.service.task.FuelMileageManager.java
@SuppressWarnings("unchecked") public InputStream getData(Page<Mileageoil> page, List<Mileageoil> list, FuelMileageVo fmvo) { //Page<Mileageoil> pageResult = this.getBetch(page, fmvo); Page<Mileageoil> page_export = (Page<Mileageoil>) Struts2Util.getSession().getAttribute("page_export"); DetachedCriteria criteria_export = (DetachedCriteria) Struts2Util.getSession() .getAttribute("criteria_export"); List<Order> orderList_export = (List<Order>) Struts2Util.getSession().getAttribute("orderList_export"); page_export.setPageSize(page_export.getTotalCount()); Page<Mileageoil> pageResult = baseDao.getBatch(page_export, criteria_export.getExecutableCriteria(baseDao.getSession()), orderList_export); List<Mileageoil> data = new ArrayList<Mileageoil>(); if (null != pageResult) { if (0 != pageResult.getResult().size()) { data = pageResult.getResult(); }//from ww w.jav a2 s .c om } ExportExcel ee = new ExportExcel() { @Override protected HSSFWorkbook disposeData(HSSFWorkbook wb, Object[] total, List<?> data) throws IOException { HSSFSheet sheet = wb.getSheetAt(0); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6)); HSSFRow rowss = sheet.createRow(0); rowss.setHeightInPoints(20); HSSFCell hssfCell = rowss.createCell(0); hssfCell = this.createCell(wb, hssfCell, "Fuel Mileage"); HSSFCellStyle style = this.createStyle(wb); HSSFRow row2 = sheet.createRow(1); HSSFCell cellrow01 = row2.createCell(0); cellrow01.setCellStyle(style); HSSFCell cellrow02 = row2.createCell(1); cellrow02.setCellStyle(style); HSSFCell cellrow03 = row2.createCell(2); cellrow03.setCellStyle(style); HSSFCell cellrow04 = row2.createCell(3); cellrow04.setCellStyle(style); HSSFCell cellrow05 = row2.createCell(4); cellrow05.setCellStyle(style); HSSFCell cellrow06 = row2.createCell(5); cellrow06.setCellStyle(style); cellrow01.setCellValue("No."); cellrow02.setCellValue("Plate Number"); cellrow03.setCellValue("Vehicle Type"); cellrow04.setCellValue("Date"); cellrow05.setCellValue("Mileage"); cellrow06.setCellValue("Fuel consumption"); if (null != data && 0 != data.size()) { for (int i = 0; i < data.size(); i++) { HSSFRow row = sheet.createRow(i + 2); Mileageoil o = (Mileageoil) data.get(i); HSSFCell cell001 = row.createCell(0); cell001.setCellStyle(style); cell001.setCellValue(i + 1); HSSFCell cell002 = row.createCell(1); cell002.setCellStyle(style); cell002.setCellValue(o.getVehiclename()); HSSFCell cell003 = row.createCell(2); cell003.setCellStyle(style); cell003.setCellValue(o.getTypename()); HSSFCell cell004 = row.createCell(3); cell004.setCellStyle(style); cell004.setCellValue(o.getRiqi()); HSSFCell cell005 = row.createCell(4); cell005.setCellStyle(style); cell005.setCellValue(o.getMileage() + "m"); HSSFCell cell006 = row.createCell(5); cell006.setCellStyle(style); cell006.setCellValue(o.getOilcost() == null ? "0" : o.getOilcost() + "L"); } } return wb; } }; Object[] total = new Object[1]; total[0] = ""; String str = "Fuel Mileage"; return ee.export(total, data, str); }
From source file:com.zdtx.ifms.specific.service.vehicle.VehicleListManager.java
public Page<VehcileView> getBatch(Page<VehcileView> page, VehicleVO vo) { DetachedCriteria criteria = DetachedCriteria.forClass(VehcileView.class); criteria.add(Restrictions.in("fleetid", (Long[]) Struts2Util.getSession().getAttribute("userFleet"))); //add authority criteria.add(Restrictions.eq("isdelete", "F")); if (null != vo.getDeptID() && -1L != vo.getDeptID()) { criteria.add(Restrictions.eq("deptID", vo.getDeptID())); }/*from w ww . j ava 2 s. c o m*/ if (null != vo.getVehiclename() && !"".equals(vo.getVehiclename())) { criteria.add(Restrictions.like("vehiclename", "%" + vo.getVehiclename() + "%").ignoreCase()); } if (null != vo.getLicenseplate() && !"".equals(vo.getLicenseplate())) { criteria.add(Restrictions.like("licenseplate", "%" + vo.getLicenseplate() + "%").ignoreCase()); } if (null != vo.getCctvip() && !"".equals(vo.getCctvip())) { criteria.add(Restrictions.like("cctvip", "%" + vo.getCctvip() + "%").ignoreCase()); } if (null != vo.getDescription() && !"".equals(vo.getDescription())) { criteria.add(Restrictions.like("description", "%" + vo.getDescription() + "%").ignoreCase()); } if (null != vo.getTypeid() && -1L != vo.getTypeid()) { criteria.add(Restrictions.eq("typeid", vo.getTypeid())); } if (null != vo.getFleetid() && -1L != vo.getFleetid()) { criteria.add(Restrictions.eq("fleetid", vo.getFleetid())); } if (null != vo.getDeviceid() && -1L != vo.getDeviceid()) { criteria.add(Restrictions.eq("deviceid", vo.getDeviceid())); } if (null != vo.getBrand() && !"".equals(vo.getBrand())) { criteria.add(Restrictions.like("brandname", "%" + vo.getBrand() + "%").ignoreCase()); } if (null != vo.getKeyCode() && !"".equals(vo.getKeyCode())) { criteria.add(Restrictions.like("keycode", "%" + vo.getKeyCode() + "%").ignoreCase()); } List<Order> orderList = new ArrayList<Order>(); orderList.add(Order.asc("fleetname"));// orderList.add(Order.asc("typename"));// orderList.add(Order.asc("vehiclename"));// Page<VehcileView> pageResult = baseDao.getBatch(page, criteria.getExecutableCriteria(baseDao.getSession()), orderList); if (1 == pageResult.getCurrentPage()) { Utils.getSession().setAttribute("criteria_export", criteria); Utils.getSession().setAttribute("page_export", page); Utils.getSession().setAttribute("orderList_export", orderList); } return pageResult; }
From source file:com.zdtx.ifms.specific.service.vehicle.VehicleListManager.java
@SuppressWarnings("unchecked") public InputStream getExcel(String title) { List<VehcileView> data = new ArrayList<VehcileView>(); Page<VehcileView> page_export = (Page<VehcileView>) Utils.getSession().getAttribute("page_export"); DetachedCriteria criteria_export = (DetachedCriteria) Utils.getSession().getAttribute("criteria_export"); List<Order> orderList_export = (List<Order>) Utils.getSession().getAttribute("orderList_export"); page_export.setPageSize(page_export.getTotalCount()); Page<VehcileView> pageResult = baseDao.getBatch(page_export, criteria_export.getExecutableCriteria(baseDao.getSession()), orderList_export); if (null != pageResult) { if (0 != pageResult.getResult().size()) { data = pageResult.getResult(); }/*ww w. ja va 2 s . c o m*/ } ExportExcel ee = new ExportExcel() { @Override protected HSSFWorkbook disposeData(HSSFWorkbook wb, Object[] total, List<?> data) throws IOException { HSSFSheet sheet = wb.getSheetAt(0); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3)); HSSFRow rowss = sheet.createRow(0); rowss.setHeightInPoints(20); HSSFCell hssfCell = rowss.createCell(0); hssfCell = this.createCell(wb, hssfCell, total[0].toString()); HSSFCellStyle style = this.createStyle(wb); HSSFRow row2 = sheet.createRow(1); HSSFCell cellrow01 = row2.createCell(0); cellrow01.setCellStyle(style); HSSFCell cellrow02 = row2.createCell(1); cellrow02.setCellStyle(style); HSSFCell cellrow03 = row2.createCell(2); cellrow03.setCellStyle(style); HSSFCell cellrow04 = row2.createCell(3); cellrow04.setCellStyle(style); HSSFCell cellrow05 = row2.createCell(4); cellrow05.setCellStyle(style); HSSFCell cellrow06 = row2.createCell(5); cellrow06.setCellStyle(style); HSSFCell cellrow07 = row2.createCell(6); cellrow07.setCellStyle(style); HSSFCell cellrow08 = row2.createCell(7); cellrow08.setCellStyle(style); HSSFCell cellrow09 = row2.createCell(8); cellrow09.setCellStyle(style); HSSFCell cellrow10 = row2.createCell(9); cellrow10.setCellStyle(style); cellrow01.setCellValue("No."); cellrow02.setCellValue("Plate Number"); cellrow03.setCellValue("Fleet"); cellrow04.setCellValue("Department"); cellrow05.setCellValue("Device"); cellrow06.setCellValue("Vehicle Type"); cellrow07.setCellValue("Vehicle Brand"); cellrow08.setCellValue("Key Code"); cellrow09.setCellValue("IP"); cellrow10.setCellValue("Description"); if (null != data && 0 != data.size()) { for (int i = 0; i < data.size(); i++) { VehcileView a = (VehcileView) data.get(i); HSSFRow row = sheet.createRow(i + 2); HSSFCell cell001 = row.createCell(0); cell001.setCellStyle(style); cell001.setCellValue(i + 1); HSSFCell cell002 = row.createCell(1); cell002.setCellStyle(style); cell002.setCellValue(a.getVehiclename()); HSSFCell cell003 = row.createCell(2); cell003.setCellStyle(style); cell003.setCellValue(a.getFleetname()); HSSFCell cell004 = row.createCell(3); cell004.setCellStyle(style); cell004.setCellValue(a.getDeptname()); HSSFCell cell005 = row.createCell(4); cell005.setCellStyle(style); cell005.setCellValue(a.getDevicename()); HSSFCell cell006 = row.createCell(5); cell006.setCellStyle(style); cell006.setCellValue(a.getTypename()); HSSFCell cell007 = row.createCell(6); cell007.setCellStyle(style); cell007.setCellValue(a.getBrandname()); HSSFCell cell008 = row.createCell(7); cell008.setCellStyle(style); cell008.setCellValue(a.getKeycode()); HSSFCell cell009 = row.createCell(8); cell009.setCellStyle(style); cell009.setCellValue(a.getCctvip()); HSSFCell cell010 = row.createCell(9); cell010.setCellStyle(style); cell010.setCellValue(a.getDescription()); } } return wb; } }; Object[] total = new Object[1]; total[0] = title; String str = title; return ee.export(total, data, str); }