List of usage examples for org.hibernate Criteria setResultTransformer
public Criteria setResultTransformer(ResultTransformer resultTransformer);
From source file:com.rosy.bill.dao.hibernate.HibernateDao.java
License:Apache License
/** * countCriteria./*ww w . j av a 2s . c o m*/ */ @SuppressWarnings("unchecked") protected long countCriteriaResult(final Criteria c) { CriteriaImpl impl = (CriteriaImpl) c; // Projection?ResultTransformer?OrderBy??,??Count? Projection projection = impl.getProjection(); ResultTransformer transformer = impl.getResultTransformer(); List<CriteriaImpl.OrderEntry> orderEntries = null; try { orderEntries = (List<OrderEntry>) ReflectionUtils.getFieldValue(impl, "orderEntries"); ReflectionUtils.setFieldValue(impl, "orderEntries", new ArrayList<T>()); } catch (Exception e) { logger.error("??:{}", e.getMessage()); } // Count Long totalCountObject = (Long) c.setProjection(Projections.rowCount()).uniqueResult(); long totalCount = (totalCountObject != null) ? totalCountObject : 0; // ?Projection,ResultTransformerOrderBy?? c.setProjection(projection); if (projection == null) { c.setResultTransformer(CriteriaSpecification.ROOT_ENTITY); } if (transformer != null) { c.setResultTransformer(transformer); } try { ReflectionUtils.setFieldValue(impl, "orderEntries", orderEntries); } catch (Exception e) { logger.error("??:{}", e.getMessage()); } return totalCount; }
From source file:com.rta.vsd.data.service.impl.InspectionDataServiceImpl.java
/** * //from w w w .j a v a2s . com * Gets a list of inspection from the plate details specified * * @author Eldon Barrows * @param dsContext * @param retrieveArabicData * @param vehiclePlateDetails * @param paginationValues * @return List<VsdInspection> * @throws VSDDataAccessException */ public List<VsdInspection> getInspectionsByPlateDetails(final DataServiceContext dsContext, boolean retrieveArabicData, VehiclePlate vehiclePlateDetails, PaginationParam paginationValues) throws VSDDataAccessException { logger.info("getInspectionsByPlateDetails -- START"); List<VsdInspection> inspections = null; try { Session session = (Session) dsContext.getInternalContext(); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.property("inspections.inspectionId"), "inspectionId"); Criteria crit = session.createCriteria(VsdInspection.class, "inspections") .add(Restrictions.eq("inspections.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("inspections.vsdLocation", "loc", Criteria.LEFT_JOIN, Restrictions.eq("loc.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("loc.vsdLocation", "area", Criteria.LEFT_JOIN, Restrictions.eq("area.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("inspections.vsdVehicleInfo", "vehicleInfo", Criteria.LEFT_JOIN, Restrictions.eq("vehicleInfo.isDeleted", IDataService.BOOL_FALSE)) .add(Restrictions.eq("vehicleInfo.vehiclePlateCategory", vehiclePlateDetails.getPlateCategory()) .ignoreCase()) .add(Restrictions.eq("vehicleInfo.vehiclePlateCode", vehiclePlateDetails.getPlateCode()) .ignoreCase()) .add(Restrictions.eq("vehicleInfo.vehiclePlateSource", vehiclePlateDetails.getPlateSource()) .ignoreCase()) .add(Restrictions.eq("vehicleInfo.vehiclePlateNumber", vehiclePlateDetails.getPlateNumber()) .ignoreCase()) .addOrder(Order.desc("inspections.inspectionId")) .setProjection(Projections.distinct(projectionList)); crit.setResultTransformer(new AliasToBeanResultTransformer(VsdInspection.class)); if (paginationValues.getFirstResult() != null && paginationValues.getFirstResult().longValue() != -1) { crit.setFirstResult(paginationValues.getFirstResult().intValue()); } if (paginationValues.getFetchedSize() != null && paginationValues.getFetchedSize().longValue() != -1) { crit.setMaxResults(paginationValues.getFetchedSize().intValue()); } List list = crit.list(); logger.debug("list.size() : " + list.size()); Set resultSet = new HashSet(list); logger.debug("resultSet.size() : " + resultSet.size()); if (resultSet.size() == 0) return new ArrayList(); Iterator iterator = resultSet.iterator(); ArrayList innerQueryList = new ArrayList<Long>(); while (iterator.hasNext()) { VsdInspection inspection = (VsdInspection) iterator.next(); innerQueryList.add(inspection.getInspectionId()); } Criteria main = session.createCriteria(VsdInspection.class, "inspections") .add(Property.forName("inspections.inspectionId").in(innerQueryList)) .add(Restrictions.eq("inspections.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("inspections.vsdLocation", "loc", Criteria.LEFT_JOIN, Restrictions.eq("loc.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("loc.vsdLocation", "area", Criteria.LEFT_JOIN, Restrictions.eq("area.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("inspections.vsdVehicleInfo", "vehicleInfo", Criteria.LEFT_JOIN, Restrictions.eq("vehicleInfo.isDeleted", IDataService.BOOL_FALSE)) .add(Restrictions.eq("vehicleInfo.vehiclePlateCategory", vehiclePlateDetails.getPlateCategory()) .ignoreCase()) .add(Restrictions.eq("vehicleInfo.vehiclePlateCode", vehiclePlateDetails.getPlateCode()) .ignoreCase()) .add(Restrictions.eq("vehicleInfo.vehiclePlateSource", vehiclePlateDetails.getPlateSource()) .ignoreCase()) .add(Restrictions.eq("vehicleInfo.vehiclePlateNumber", vehiclePlateDetails.getPlateNumber()) .ignoreCase()) .addOrder(Order.desc("inspections.inspectionId")); inspections = main.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); logger.info("getInspectionsByPlateDetails -- END"); return inspections; } catch (Exception ex) { logger.error("An error occured in getInspectionsByPlateDetails()"); throw new VSDDataAccessException(ex.getMessage(), ex); } }
From source file:com.rta.vsd.data.service.impl.InspectionDataServiceImpl.java
/** * //from w w w .j av a2 s . c o m * Gets all the inspections for vehicles owned by the owner with the specified trade license number * * @author Eldon Barrows * @param dsContext * @param retrieveArabicData * @param tradeLicenseNumber * @param paginationValues * @return List<VsdInspection> * @throws VSDDataAccessException */ public List<VsdInspection> getInspectionsByTradeLicenseNumber(final DataServiceContext dsContext, boolean retrieveArabicData, String tradeLicenseNumber, PaginationParam paginationValues) throws VSDDataAccessException { logger.info("getInspectionsByTradeLicenseNumber -- START"); List<VsdInspection> inspections = null; try { Session session = (Session) dsContext.getInternalContext(); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.property("inspections.inspectionId"), "inspectionId"); Criteria crit = session.createCriteria(VsdInspection.class, "inspections") .add(Restrictions.eq("inspections.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("inspections.vsdLocation", "loc", Criteria.LEFT_JOIN, Restrictions.eq("loc.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("loc.vsdLocation", "area", Criteria.LEFT_JOIN, Restrictions.eq("area.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("inspections.vsdVehicleInfo", "vehicleInfo", Criteria.LEFT_JOIN, Restrictions.eq("vehicleInfo.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("vehicleInfo.vsdOwnerInfos", "ownerInfo", Criteria.LEFT_JOIN, Restrictions.eq("ownerInfo.isDeleted", IDataService.BOOL_FALSE)) .add(Restrictions.eq("ownerInfo.tradeLicenseNumber", tradeLicenseNumber).ignoreCase()) .addOrder(Order.desc("inspections.inspectionId")); crit.setResultTransformer(new AliasToBeanResultTransformer(VsdInspection.class)); if (paginationValues.getFirstResult() != null && paginationValues.getFirstResult().longValue() != -1) { crit.setFirstResult(paginationValues.getFirstResult().intValue()); } if (paginationValues.getFetchedSize() != null && paginationValues.getFetchedSize().longValue() != -1) { crit.setMaxResults(paginationValues.getFetchedSize().intValue()); } List list = crit.list(); logger.debug("list.size() : " + list.size()); Set resultSet = new HashSet(list); logger.debug("resultSet.size() : " + resultSet.size()); if (resultSet.size() == 0) return new ArrayList(); Iterator iterator = resultSet.iterator(); ArrayList innerQueryList = new ArrayList<Long>(); while (iterator.hasNext()) { VsdInspection inspection = (VsdInspection) iterator.next(); innerQueryList.add(inspection.getInspectionId()); } Criteria main = session.createCriteria(VsdInspection.class, "inspections") .add(Property.forName("inspections.inspectionId").in(innerQueryList)) .add(Restrictions.eq("inspections.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("inspections.vsdLocation", "loc", Criteria.LEFT_JOIN, Restrictions.eq("loc.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("loc.vsdLocation", "area", Criteria.LEFT_JOIN, Restrictions.eq("area.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("inspections.vsdVehicleInfo", "vehicleInfo", Criteria.LEFT_JOIN, Restrictions.eq("vehicleInfo.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("vehicleInfo.vsdOwnerInfos", "ownerInfo", Criteria.LEFT_JOIN, Restrictions.eq("ownerInfo.isDeleted", IDataService.BOOL_FALSE)) .add(Restrictions.eq("ownerInfo.tradeLicenseNumber", tradeLicenseNumber).ignoreCase()) .addOrder(Order.desc("inspections.inspectionId")); inspections = main.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); logger.info("getInspectionsByTradeLicenseNumber -- END"); return inspections; } catch (Exception ex) { logger.error("An error occured in getInspectionsByTradeLicenseNumber()"); throw new VSDDataAccessException(ex.getMessage(), ex); } }
From source file:com.rta.vsd.data.service.impl.VehicleDataServiceImpl.java
/** * search vehicles.//from w w w .ja v a 2 s . c om * * @author Eldon Barrows * @param dsContext * @param retrieveArabicData * @param vehicleSearchCriteria * @param paginationValues * @return List<VsdVehicle> * @throws VSDDataAccessException */ public List<VsdVehicle> searchVehicle(DataServiceContext dsContext, boolean retrieveArabicData, VehicleSearchCriteria vehicleSearchCriteria, PaginationParam paginationValues) throws VSDDataAccessException { logger.info("searchVehicle -- START"); List<VsdVehicle> vehicles = null; try { Session session = (Session) dsContext.getInternalContext(); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.property("v.vehicleId"), "vehicleId"); projectionList.add(Projections.property("vo.ownerName"), "chassisNumber"); projectionList.add(Projections.property("vo.ownerNameA"), "chassisNumber"); projectionList.add(Projections.property("v.vehiclePlateNumber"), "chassisNumber"); Criteria criteria = session.createCriteria(VsdVehicle.class, "v") .add(Restrictions.eq("v.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("v.vsdVehPlateCatCode", "vpcc", Criteria.LEFT_JOIN, Restrictions.eq("vpcc.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("vpcc.vsdVehPlateCatCode", "vpcc2", Criteria.LEFT_JOIN, Restrictions.eq("vpcc2.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("v.vsdVehicleOwner", "vo", Criteria.LEFT_JOIN, Restrictions.eq("vo.isDeleted", IDataService.BOOL_FALSE)); /* * if (vehicleSearchCriteria.getPlateNumber() != null && !vehicleSearchCriteria.getPlateNumber().equals("")) criteria.add(Restrictions.eq("v.vehiclePlateNumber", vehicleSearchCriteria.getPlateNumber()).ignoreCase()); if (vehicleSearchCriteria.getPlateCode() != null && !vehicleSearchCriteria.getPlateCode().equals("")) criteria.add(Restrictions.eq("vpcc.categoryName", vehicleSearchCriteria.getPlateCode()).ignoreCase()); if (vehicleSearchCriteria.getPlateCategory() != null && !vehicleSearchCriteria.getPlateCategory().equals("")) criteria.add(Restrictions.eq("vpcc2.categoryName", vehicleSearchCriteria.getPlateCategory()).ignoreCase()); if (vehicleSearchCriteria.getOperatorName() != null && !vehicleSearchCriteria.getOperatorName().equals("")) criteria.add(Restrictions.eq("vo.ownerName", vehicleSearchCriteria.getOperatorName()).ignoreCase()); if (vehicleSearchCriteria.getOperatorNameA() != null && !vehicleSearchCriteria.getOperatorNameA().equals("")) criteria.add(Restrictions.eq("vo.ownerNameA", vehicleSearchCriteria.getOperatorNameA()).ignoreCase()); */ if (vehicleSearchCriteria.getEmirateCode() != null && !vehicleSearchCriteria.getEmirateCode().equals("")) criteria.add( Restrictions.eq("v.vehicleCountry", vehicleSearchCriteria.getEmirateCode()).ignoreCase()); if (vehicleSearchCriteria.getPlateNumber() != null && !vehicleSearchCriteria.getPlateNumber().equals("")) criteria.add(Restrictions.eq("v.vehiclePlateNumber", vehicleSearchCriteria.getPlateNumber()) .ignoreCase()); if (vehicleSearchCriteria.getPlateCode() != null && !vehicleSearchCriteria.getPlateCode().equals("")) criteria.add(Restrictions.eq("vpcc.vehPlateCatCodeId", vehicleSearchCriteria.getPlateCode())); if (vehicleSearchCriteria.getPlateCategory() != null && !vehicleSearchCriteria.getPlateCategory().equals("")) criteria.add(Restrictions.eq("vpcc2.vehPlateCatCodeId", vehicleSearchCriteria.getPlateCategory())); if (vehicleSearchCriteria.getOperatorName() != null && !vehicleSearchCriteria.getOperatorName().equals("")) criteria.add(Restrictions.like("vo.ownerName", "%" + vehicleSearchCriteria.getOperatorName() + "%") .ignoreCase()); if (vehicleSearchCriteria.getOperatorNameA() != null && !vehicleSearchCriteria.getOperatorNameA().equals("")) criteria.add(Restrictions .like("vo.ownerNameA", "%" + vehicleSearchCriteria.getOperatorNameA() + "%").ignoreCase()); criteria.setProjection(Projections.distinct(projectionList)); criteria.setResultTransformer(new AliasToBeanResultTransformer(VsdVehicle.class)); criteria.setFirstResult(paginationValues.getFirstResult().intValue()); criteria.setMaxResults(paginationValues.getFetchedSize().intValue()); if (paginationValues.getPageLocale().equalsIgnoreCase(Constant.LOCALE_ENGLISH)) { criteria.addOrder(Order.asc("vo.ownerName").ignoreCase()); criteria.addOrder(Order.asc("v.vehiclePlateNumber").ignoreCase()); } else { criteria.addOrder(Order.asc("vo.ownerNameA").ignoreCase()); criteria.addOrder(Order.asc("v.vehiclePlateNumber").ignoreCase()); } List list = criteria.list(); logger.debug("list.size() : " + list.size()); if (list.size() == 0) return new ArrayList(); Iterator iterator = list.iterator(); ArrayList innerQueryList = new ArrayList<Long>(); while (iterator.hasNext()) { VsdVehicle vehicle = (VsdVehicle) iterator.next(); innerQueryList.add(vehicle.getVehicleId()); } Criteria main = session.createCriteria(VsdVehicle.class, "v") .add(Restrictions.eq("v.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("v.vsdVehPlateCatCode", "vpcc", Criteria.LEFT_JOIN, Restrictions.eq("vpcc.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("vpcc.vsdVehPlateCatCode", "vpcc2", Criteria.LEFT_JOIN, Restrictions.eq("vpcc2.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("v.vsdVehicleOwner", "vo", Criteria.LEFT_JOIN, Restrictions.eq("vo.isDeleted", IDataService.BOOL_FALSE)) .add(Property.forName("v.vehicleId").in(innerQueryList)); if (vehicleSearchCriteria.getEmirateCode() != null && !vehicleSearchCriteria.getEmirateCode().equals("")) main.add(Restrictions.eq("v.vehicleCountry", vehicleSearchCriteria.getEmirateCode()).ignoreCase()); if (vehicleSearchCriteria.getPlateNumber() != null && !vehicleSearchCriteria.getPlateNumber().equals("")) main.add(Restrictions.eq("v.vehiclePlateNumber", vehicleSearchCriteria.getPlateNumber()) .ignoreCase()); if (vehicleSearchCriteria.getPlateCode() != null && !vehicleSearchCriteria.getPlateCode().equals("")) main.add(Restrictions.eq("vpcc.vehPlateCatCodeId", vehicleSearchCriteria.getPlateCode())); if (vehicleSearchCriteria.getPlateCategory() != null && !vehicleSearchCriteria.getPlateCategory().equals("")) main.add(Restrictions.eq("vpcc2.vehPlateCatCodeId", vehicleSearchCriteria.getPlateCategory())); if (vehicleSearchCriteria.getOperatorName() != null && !vehicleSearchCriteria.getOperatorName().equals("")) main.add(Restrictions.like("vo.ownerName", "%" + vehicleSearchCriteria.getOperatorName() + "%") .ignoreCase()); if (vehicleSearchCriteria.getOperatorNameA() != null && !vehicleSearchCriteria.getOperatorNameA().equals("")) main.add(Restrictions.like("vo.ownerNameA", "%" + vehicleSearchCriteria.getOperatorNameA() + "%") .ignoreCase()); if (paginationValues.getPageLocale().equalsIgnoreCase(Constant.LOCALE_ENGLISH)) { main.addOrder(Order.asc("vo.ownerName").ignoreCase()); main.addOrder(Order.asc("v.vehiclePlateNumber").ignoreCase()); } else { main.addOrder(Order.asc("vo.ownerNameA").ignoreCase()); main.addOrder(Order.asc("v.vehiclePlateNumber").ignoreCase()); } vehicles = main.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); logger.info("searchVehicle -- END"); return vehicles; } catch (Exception ex) { logger.error("An error occured in searchVehicle()"); throw new VSDDataAccessException(ex.getMessage(), ex); } }
From source file:com.rta.vsd.data.service.impl.VehicleDataServiceImpl.java
public List<VsdVehicle> getVehiclesWithRiskRatingManufacturerPlateCategoryCodeDetailsByTrficFileNumber( DataServiceContext dsContext, boolean retrieveArabicData, String traficFileNo, PaginationParam paginationValues) throws VSDDataAccessException { logger.info("getVehiclesWithRiskRatingManufacturerPlateCategoryCodeDetailsByTradeLicenseNumber -- START"); List<VsdVehicle> vehicles = null; try {//from www. j ava 2 s.co m Session session = (Session) dsContext.getInternalContext(); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.property("v.vehicleId"), "vehicleId"); Criteria crit = session.createCriteria(VsdVehicle.class, "v") .add(Restrictions.eq("v.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("v.vsdVehicleOwner", "vo", Criteria.LEFT_JOIN, Restrictions.eq("vo.isDeleted", IDataService.BOOL_FALSE)) .add(Restrictions.eq("vo.trafficFileNumber", traficFileNo).ignoreCase()) .createCriteria("v.vsdRRProfilings", "rrp", Criteria.LEFT_JOIN, Restrictions.eq("rrp.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("rrp.vsdRiskRating", "rr", Criteria.LEFT_JOIN, Restrictions.eq("rr.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("v.vsdVehicleManufacturers", "m", Criteria.LEFT_JOIN, Restrictions.eq("m.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("v.vsdVehPlateCatCode", "vpcc", Criteria.LEFT_JOIN, Restrictions.eq("vpcc.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("vpcc.vsdVehPlateCatCode", "pvpcc", Criteria.LEFT_JOIN, Restrictions.eq("pvpcc.isDeleted", IDataService.BOOL_FALSE)) .addOrder(Order.desc("v.vehicleId")).setProjection(Projections.distinct(projectionList)); crit.setResultTransformer(new AliasToBeanResultTransformer(VsdVehicle.class)); if (paginationValues.getFirstResult() != null && paginationValues.getFirstResult().longValue() != -1) { crit.setFirstResult(paginationValues.getFirstResult().intValue()); } if (paginationValues.getFetchedSize() != null && paginationValues.getFetchedSize().longValue() != -1) { crit.setMaxResults(paginationValues.getFetchedSize().intValue()); } List list = crit.list(); logger.debug("list.size() : " + list.size()); Set resultSet = new HashSet(list); logger.debug("resultSet.size() : " + resultSet.size()); if (resultSet.size() == 0) return new ArrayList(); Iterator iterator = resultSet.iterator(); ArrayList innerQueryList = new ArrayList<Long>(); while (iterator.hasNext()) { VsdVehicle vehicle = (VsdVehicle) iterator.next(); innerQueryList.add(vehicle.getVehicleId()); } Criteria main = session.createCriteria(VsdVehicle.class, "v") .add(Property.forName("v.vehicleId").in(innerQueryList)) .add(Restrictions.eq("v.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("v.vsdVehicleOwner", "vo", Criteria.LEFT_JOIN, Restrictions.eq("vo.isDeleted", IDataService.BOOL_FALSE)) .add(Restrictions.eq("vo.trafficFileNumber", traficFileNo).ignoreCase()) .createCriteria("v.vsdRRProfilings", "rrp", Criteria.LEFT_JOIN, Restrictions.eq("rrp.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("rrp.vsdRiskRating", "rr", Criteria.LEFT_JOIN, Restrictions.eq("rr.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("v.vsdVehicleManufacturers", "m", Criteria.LEFT_JOIN, Restrictions.eq("m.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("v.vsdVehPlateCatCode", "vpcc", Criteria.LEFT_JOIN, Restrictions.eq("vpcc.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("vpcc.vsdVehPlateCatCode", "pvpcc", Criteria.LEFT_JOIN, Restrictions.eq("pvpcc.isDeleted", IDataService.BOOL_FALSE)) .addOrder(Order.desc("v.vehicleId")); vehicles = main.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); logger.info("getVehiclesWithRiskRatingManufacturerPlateCategoryCodeDetailsByTradeLicenseNumber -- END"); return vehicles; } catch (Exception ex) { logger.error( "An error occured in getVehiclesWithRiskRatingManufacturerPlateCategoryCodeDetailsByTradeLicenseNumber()"); throw new VSDDataAccessException(ex.getMessage(), ex); } }
From source file:com.rta.vsd.data.service.impl.VehicleDataServiceImpl.java
/** * //w w w . ja v a 2s .co m * Gets a list of vehicles having an owner with the provided trade license number. The manufacturer(VsdVehicleManufaceturer), risk rating (VsdRRProfiling,VsdRiskRating) and plate category code(VsdVehPlateCatCode) details will also be populated * * @author Eldon Barrows * @param dsContext * @param retrieveArabicData * @param tradeLicenseNumber * @param paginationValues * @return List<VsdVehicle> * @throws VSDDataAccessException */ public List<VsdVehicle> getVehiclesWithRiskRatingManufacturerPlateCategoryCodeDetailsByTradeLicenseNumber( DataServiceContext dsContext, boolean retrieveArabicData, String tradeLicenseNumber, PaginationParam paginationValues) throws VSDDataAccessException { logger.info("getVehiclesWithRiskRatingManufacturerPlateCategoryCodeDetailsByTradeLicenseNumber -- START"); List<VsdVehicle> vehicles = null; try { Session session = (Session) dsContext.getInternalContext(); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.property("v.vehicleId"), "vehicleId"); Criteria crit = session.createCriteria(VsdVehicle.class, "v") .add(Restrictions.eq("v.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("v.vsdVehicleOwner", "vo", Criteria.LEFT_JOIN, Restrictions.eq("vo.isDeleted", IDataService.BOOL_FALSE)) .add(Restrictions.eq("vo.tradeLicenseNumber", tradeLicenseNumber).ignoreCase()) .createCriteria("v.vsdRRProfilings", "rrp", Criteria.LEFT_JOIN, Restrictions.eq("rrp.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("rrp.vsdRiskRating", "rr", Criteria.LEFT_JOIN, Restrictions.eq("rr.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("v.vsdVehicleManufacturers", "m", Criteria.LEFT_JOIN, Restrictions.eq("m.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("v.vsdVehPlateCatCode", "vpcc", Criteria.LEFT_JOIN, Restrictions.eq("vpcc.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("vpcc.vsdVehPlateCatCode", "pvpcc", Criteria.LEFT_JOIN, Restrictions.eq("pvpcc.isDeleted", IDataService.BOOL_FALSE)) .addOrder(Order.desc("v.vehicleId")).setProjection(Projections.distinct(projectionList)); crit.setResultTransformer(new AliasToBeanResultTransformer(VsdVehicle.class)); if (paginationValues.getFirstResult() != null && paginationValues.getFirstResult().longValue() != -1) { crit.setFirstResult(paginationValues.getFirstResult().intValue()); } if (paginationValues.getFetchedSize() != null && paginationValues.getFetchedSize().longValue() != -1) { crit.setMaxResults(paginationValues.getFetchedSize().intValue()); } List list = crit.list(); logger.debug("list.size() : " + list.size()); Set resultSet = new HashSet(list); logger.debug("resultSet.size() : " + resultSet.size()); if (resultSet.size() == 0) return new ArrayList(); Iterator iterator = resultSet.iterator(); ArrayList innerQueryList = new ArrayList<Long>(); while (iterator.hasNext()) { VsdVehicle vehicle = (VsdVehicle) iterator.next(); innerQueryList.add(vehicle.getVehicleId()); } Criteria main = session.createCriteria(VsdVehicle.class, "v") .add(Property.forName("v.vehicleId").in(innerQueryList)) .add(Restrictions.eq("v.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("v.vsdVehicleOwner", "vo", Criteria.LEFT_JOIN, Restrictions.eq("vo.isDeleted", IDataService.BOOL_FALSE)) .add(Restrictions.eq("vo.tradeLicenseNumber", tradeLicenseNumber).ignoreCase()) .createCriteria("v.vsdRRProfilings", "rrp", Criteria.LEFT_JOIN, Restrictions.eq("rrp.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("rrp.vsdRiskRating", "rr", Criteria.LEFT_JOIN, Restrictions.eq("rr.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("v.vsdVehicleManufacturers", "m", Criteria.LEFT_JOIN, Restrictions.eq("m.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("v.vsdVehPlateCatCode", "vpcc", Criteria.LEFT_JOIN, Restrictions.eq("vpcc.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("vpcc.vsdVehPlateCatCode", "pvpcc", Criteria.LEFT_JOIN, Restrictions.eq("pvpcc.isDeleted", IDataService.BOOL_FALSE)) .addOrder(Order.desc("v.vehicleId")); vehicles = main.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); logger.info("getVehiclesWithRiskRatingManufacturerPlateCategoryCodeDetailsByTradeLicenseNumber -- END"); return vehicles; } catch (Exception ex) { logger.error( "An error occured in getVehiclesWithRiskRatingManufacturerPlateCategoryCodeDetailsByTradeLicenseNumber()"); throw new VSDDataAccessException(ex.getMessage(), ex); } }
From source file:com.rta.vsd.data.service.impl.ViolationDataServiceImpl.java
/** * /*w w w . j a v a 2 s . c o m*/ * Gets a list of all the violations based on the plate details provided * * @author Eldon Barrows * @param dsContext * @param retrieveArabicData * @param vehiclePlateDetails * @param paginationValues * @return List<VsdViolation> * @throws VSDDataAccessException */ public List<VsdViolation> getViolationsByPlateDetails(final DataServiceContext dsContext, boolean retrieveArabicData, VehiclePlate vehiclePlateDetails, PaginationParam paginationValues) throws VSDDataAccessException { logger.info("getViolationsByPlateDetails -- START"); List<VsdViolation> violations = null; try { Session session = (Session) dsContext.getInternalContext(); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.property("violaton.violationId"), "violationId"); projectionList.add(Projections.property("violaton.reportedDate"), "reportedDate"); Criteria crit = session.createCriteria(VsdViolation.class, "violaton") .add(Restrictions.eq("violaton.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("vsdInspections", "inspections", Criteria.LEFT_JOIN, Restrictions.eq("inspections.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("vsdVehicleInfo", "vehicleInfo", Criteria.LEFT_JOIN, Restrictions.eq("vehicleInfo.isDeleted", IDataService.BOOL_FALSE)) .add(Restrictions.eq("vehicleInfo.vehiclePlateCategory", vehiclePlateDetails.getPlateCategory()) .ignoreCase()) .add(Restrictions.eq("vehicleInfo.vehiclePlateCode", vehiclePlateDetails.getPlateCode()) .ignoreCase()) .add(Restrictions.eq("vehicleInfo.vehiclePlateSource", vehiclePlateDetails.getPlateSource()) .ignoreCase()) .add(Restrictions.eq("vehicleInfo.vehiclePlateNumber", vehiclePlateDetails.getPlateNumber()) .ignoreCase()) .createCriteria("violaton.vsdSeverityLevel", "vsl", Criteria.LEFT_JOIN, Restrictions.eq("vsl.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("violaton.vsdViolationStatus", "vs", Criteria.LEFT_JOIN, Restrictions.eq("vs.isDeleted", IDataService.BOOL_FALSE)) .addOrder(Order.desc("violaton.reportedDate")) .setProjection(Projections.distinct(projectionList)); crit.setResultTransformer(new AliasToBeanResultTransformer(VsdViolation.class)); if (paginationValues.getFirstResult() != null && paginationValues.getFirstResult().longValue() != -1) { crit.setFirstResult(paginationValues.getFirstResult().intValue()); } if (paginationValues.getFetchedSize() != null && paginationValues.getFetchedSize().longValue() != -1) { crit.setMaxResults(paginationValues.getFetchedSize().intValue()); } List list = crit.list(); logger.debug("list.size() : " + list.size()); Set resultSet = new HashSet(list); logger.debug("resultSet.size() : " + resultSet.size()); if (resultSet.size() == 0) return new ArrayList(); Iterator iterator = resultSet.iterator(); ArrayList innerQueryList = new ArrayList<Long>(); while (iterator.hasNext()) { VsdViolation violation = (VsdViolation) iterator.next(); innerQueryList.add(violation.getViolationId()); } Criteria main = session.createCriteria(VsdViolation.class, "violaton") .add(Property.forName("violaton.violationId").in(innerQueryList)) .add(Restrictions.eq("violaton.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("vsdInspections", "inspections", Criteria.LEFT_JOIN, Restrictions.eq("inspections.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("vsdVehicleInfo", "vehicleInfo", Criteria.LEFT_JOIN, Restrictions.eq("vehicleInfo.isDeleted", IDataService.BOOL_FALSE)) .add(Restrictions.eq("vehicleInfo.vehiclePlateCategory", vehiclePlateDetails.getPlateCategory())) .add(Restrictions.eq("vehicleInfo.vehiclePlateCode", vehiclePlateDetails.getPlateCode())) .add(Restrictions.eq("vehicleInfo.vehiclePlateSource", vehiclePlateDetails.getPlateSource())) .add(Restrictions.eq("vehicleInfo.vehiclePlateNumber", vehiclePlateDetails.getPlateNumber())) .createCriteria("violaton.vsdSeverityLevel", "vsl", Criteria.LEFT_JOIN, Restrictions.eq("vsl.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("violaton.vsdViolationStatus", "vs", Criteria.LEFT_JOIN, Restrictions.eq("vs.isDeleted", IDataService.BOOL_FALSE)) .addOrder(Order.desc("violaton.reportedDate")); violations = main.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); logger.info("getViolationsByPlateDetails -- END"); return violations; } catch (Exception ex) { logger.error("An error occured in getViolationsByPlateDetails()"); throw new VSDDataAccessException(ex.getMessage(), ex); } }
From source file:com.rta.vsd.data.service.impl.ViolationDataServiceImpl.java
/** * /* w ww. j a v a2 s .co m*/ * Gets a list of violations based on the size details and sorting order * * @author Eldon Barrows * @param dsContext * @param retrieveArabicData * @param firstResult * @param FetchSize * @param sortColumnAttribute * @param sort * @return List<VsdViolation> * @throws VSDDataAccessException */ public List<VsdViolation> getViolations(DataServiceContext dsContext, boolean retrieveArabicData, int firstResult, int maxResults, String sortColumnAttribute, Sort sort) throws VSDDataAccessException { logger.info("getViolationList -- START"); List<VsdViolation> violationList = null; if (firstResult < 0 || maxResults < 1) { throw new IllegalArgumentException(); } try { Session session = (Session) dsContext.getInternalContext(); Criteria criteria = session.createCriteria(VsdViolation.class, "v") .add(Restrictions.eq("v.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("v.vsdViolationStatus", "vs", Criteria.LEFT_JOIN) .add(Restrictions.eq("vs.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("v.vsdSeverityLevel", "sl", Criteria.LEFT_JOIN) .add(Restrictions.eq("sl.isDeleted", IDataService.BOOL_FALSE)); criteria.setFirstResult(firstResult); criteria.setMaxResults(maxResults); sortColumnAttribute = "v." + sortColumnAttribute; if (sort == IDataService.Sort.DESCENDING) criteria.addOrder(Order.desc(sortColumnAttribute)); else criteria.addOrder(Order.asc(sortColumnAttribute)); violationList = (List<VsdViolation>) criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) .list(); } catch (Exception ex) { logger.error("An error occured in getViolationList()"); throw new VSDDataAccessException(ex.getMessage(), ex); } logger.info("getViolationList -- END"); return violationList; }
From source file:com.rta.vsd.data.service.impl.ViolationDataServiceImpl.java
/** * // w w w . j a v a 2s. co m * Gets a list of all violations and its associated inspections * * @author Eldon Barrows * @param dsContext * @param retrieveArabicData * @param paginationValues * @return List<VsdViolation> * @throws VSDException */ public List<VsdViolation> getViolationsWithInspections(final DataServiceContext dsContext, boolean retrieveArabicData, PaginationParam paginationValues) throws VSDDataAccessException { logger.info("getViolationsWithInspections -- START"); List<VsdViolation> violations = null; try { Session session = (Session) dsContext.getInternalContext(); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.property("v.violationId"), "violationId"); Criteria crit = session.createCriteria(VsdViolation.class, "v") .add(Restrictions.eq("v.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("v.vsdInspections", "i", Criteria.LEFT_JOIN, Restrictions.eq("i.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("v.vsdViolationStatus", "vs", Criteria.LEFT_JOIN, Restrictions.eq("vs.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("v.vsdSeverityLevel", "vSev", Criteria.LEFT_JOIN, Restrictions.eq("vSev.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("i.vsdVehicleInfo", "vi", Criteria.LEFT_JOIN, Restrictions.eq("vi.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("i.vsdChannelPartInst", "cpi", Criteria.LEFT_JOIN, Restrictions.eq("cpi.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("i.vsdLocation", "l", Criteria.LEFT_JOIN, Restrictions.eq("l.isDeleted", IDataService.BOOL_FALSE)); if (paginationValues.getFirstResult() != null && paginationValues.getFirstResult().longValue() != -1) { crit.setFirstResult(paginationValues.getFirstResult().intValue()); } if (paginationValues.getFetchedSize() != null && paginationValues.getFetchedSize().longValue() != -1) { crit.setMaxResults(paginationValues.getFetchedSize().intValue()); } if (paginationValues.getOrderBy() != null && !paginationValues.getOrderBy().equals("")) { if (paginationValues.getSortOrder() != null && !paginationValues.getSortOrder().equals("")) { String columnAttrib = ""; if (paginationValues.getOrderBy().equalsIgnoreCase( SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.VIOLATION_ID.toString())) { columnAttrib = "v." + SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.VIOLATION_ID; projectionList.add(Projections.property(columnAttrib), "violationTicketCode"); } else if (paginationValues.getOrderBy() .equalsIgnoreCase(SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.SEVERITY.toString())) { columnAttrib = "vSev." + SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.SEVERITY; projectionList.add(Projections.property(columnAttrib), "violationTicketCode"); } else if (paginationValues.getOrderBy() .equalsIgnoreCase(SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.STATUS.toString())) { columnAttrib = "vs." + SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.STATUS; projectionList.add(Projections.property(columnAttrib), "violationTicketCode"); } else if (paginationValues.getOrderBy() .equalsIgnoreCase(SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.DATE_TIME.toString())) { columnAttrib = "i." + SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.DATE_TIME; projectionList.add(Projections.property(columnAttrib), "ownerSuspensionDate"); } else if (paginationValues.getOrderBy().equalsIgnoreCase( SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.PLATE_DETAIL.toString())) { //columnAttrib = "vSev." + SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.SEVERITY; } else if (paginationValues.getOrderBy() .equalsIgnoreCase(SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.SEVERITY_A.toString())) { columnAttrib = "vSev." + SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.SEVERITY_A; projectionList.add(Projections.property(columnAttrib), "violationTicketCode"); } else if (paginationValues.getOrderBy() .equalsIgnoreCase(SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.STATUS_A.toString())) { columnAttrib = "vs." + SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.STATUS_A; projectionList.add(Projections.property(columnAttrib), "violationTicketCode"); } else { columnAttrib = "v.violationId"; projectionList.add(Projections.property(columnAttrib), "violationId"); } if (paginationValues.getSortOrder().equalsIgnoreCase(IDataService.Sort.DESCENDING.toString())) { if (paginationValues.getOrderBy().equalsIgnoreCase( SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.PLATE_DETAIL.toString())) { crit.addOrder(Order.desc("vi.vehiclePlateNumber").ignoreCase()); crit.addOrder(Order.desc("vi.vehiclePlateCategory").ignoreCase()); crit.addOrder(Order.desc("vi.vehiclePlateCode").ignoreCase()); crit.addOrder(Order.desc("vi.vehiclePlateSource").ignoreCase()); projectionList.add(Projections.property("vi.vehiclePlateNumber"), "violationTicketCode"); projectionList.add(Projections.property("vi.vehiclePlateCategory"), "violationTicketCode"); projectionList.add(Projections.property("vi.vehiclePlateCode"), "violationTicketCode"); projectionList.add(Projections.property("vi.vehiclePlateSource"), "violationTicketCode"); } else crit.addOrder(Order.desc(columnAttrib).ignoreCase()); } else { if (paginationValues.getOrderBy().equalsIgnoreCase( SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.PLATE_DETAIL.toString())) { crit.addOrder(Order.asc("vi.vehiclePlateNumber").ignoreCase()); crit.addOrder(Order.asc("vi.vehiclePlateCategory").ignoreCase()); crit.addOrder(Order.asc("vi.vehiclePlateCode").ignoreCase()); crit.addOrder(Order.asc("vi.vehiclePlateSource").ignoreCase()); projectionList.add(Projections.property("vi.vehiclePlateNumber"), "violationTicketCode"); projectionList.add(Projections.property("vi.vehiclePlateCategory"), "violationTicketCode"); projectionList.add(Projections.property("vi.vehiclePlateCode"), "violationTicketCode"); projectionList.add(Projections.property("vi.vehiclePlateSource"), "violationTicketCode"); } else crit.addOrder(Order.asc(columnAttrib).ignoreCase()); } } } else { crit.addOrder(Order.desc("v.violationId").ignoreCase()); } List list = crit.setProjection(Projections.distinct(projectionList)) .setResultTransformer(new AliasToBeanResultTransformer(VsdViolation.class)).list(); logger.debug("list.size() : " + list.size()); Set resultSet = new HashSet(list); logger.debug("resultSet.size() : " + resultSet.size()); if (resultSet.size() == 0) return new ArrayList(); Iterator iterator = resultSet.iterator(); ArrayList innerQueryList = new ArrayList<Long>(); while (iterator.hasNext()) { VsdViolation violation = (VsdViolation) iterator.next(); innerQueryList.add(violation.getViolationId()); } Criteria main = session.createCriteria(VsdViolation.class, "v") .add(Restrictions.eq("v.isDeleted", IDataService.BOOL_FALSE)) .add(Property.forName("v.violationId").in(innerQueryList)) .createCriteria("v.vsdInspections", "i", Criteria.LEFT_JOIN, Restrictions.eq("i.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("v.vsdViolationStatus", "vs", Criteria.LEFT_JOIN, Restrictions.eq("vs.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("v.vsdSeverityLevel", "vSev", Criteria.LEFT_JOIN, Restrictions.eq("vSev.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("i.vsdVehicleInfo", "vi", Criteria.LEFT_JOIN, Restrictions.eq("vi.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("i.vsdChannelPartInst", "cpi", Criteria.LEFT_JOIN, Restrictions.eq("cpi.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("i.vsdLocation", "l", Criteria.LEFT_JOIN, Restrictions.eq("l.isDeleted", IDataService.BOOL_FALSE)); if (paginationValues.getOrderBy() != null && !paginationValues.getOrderBy().equals("")) { if (paginationValues.getSortOrder() != null && !paginationValues.getSortOrder().equals("")) { String columnAttrib = ""; if (paginationValues.getOrderBy().equalsIgnoreCase( SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.VIOLATION_ID.toString())) { columnAttrib = "v." + SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.VIOLATION_ID; } else if (paginationValues.getOrderBy() .equalsIgnoreCase(SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.SEVERITY.toString())) { columnAttrib = "vSev." + SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.SEVERITY; } else if (paginationValues.getOrderBy() .equalsIgnoreCase(SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.STATUS.toString())) { columnAttrib = "vs." + SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.STATUS; } else if (paginationValues.getOrderBy() .equalsIgnoreCase(SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.DATE_TIME.toString())) { columnAttrib = "i." + SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.DATE_TIME; } else if (paginationValues.getOrderBy().equalsIgnoreCase( SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.PLATE_DETAIL.toString())) { //columnAttrib = "vSev." + SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.SEVERITY; } else if (paginationValues.getOrderBy() .equalsIgnoreCase(SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.SEVERITY_A.toString())) { columnAttrib = "vSev." + SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.SEVERITY_A; } else if (paginationValues.getOrderBy() .equalsIgnoreCase(SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.STATUS_A.toString())) { columnAttrib = "vs." + SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.STATUS_A; } else { columnAttrib = "v.violationId"; } if (paginationValues.getSortOrder().equalsIgnoreCase(IDataService.Sort.DESCENDING.toString())) { if (paginationValues.getOrderBy().equalsIgnoreCase( SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.PLATE_DETAIL.toString())) { main.addOrder(Order.desc("vi.vehiclePlateNumber").ignoreCase()); main.addOrder(Order.desc("vi.vehiclePlateCategory").ignoreCase()); main.addOrder(Order.desc("vi.vehiclePlateCode").ignoreCase()); main.addOrder(Order.desc("vi.vehiclePlateSource").ignoreCase()); } else main.addOrder(Order.desc(columnAttrib).ignoreCase()); } else { if (paginationValues.getOrderBy().equalsIgnoreCase( SORT_COLUMN_GET_VIOLATIONS_WITH_INSPECTIONS.PLATE_DETAIL.toString())) { main.addOrder(Order.asc("vi.vehiclePlateNumber").ignoreCase()); main.addOrder(Order.asc("vi.vehiclePlateCategory").ignoreCase()); main.addOrder(Order.asc("vi.vehiclePlateCode").ignoreCase()); main.addOrder(Order.asc("vi.vehiclePlateSource").ignoreCase()); } else main.addOrder(Order.asc(columnAttrib).ignoreCase()); } } } else { main.addOrder(Order.desc("v.violationId").ignoreCase()); } violations = main.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); logger.info("getViolationsWithInspections -- END"); return violations; } catch (Exception ex) { logger.error("An error occured in getViolationsWithInspections()"); throw new VSDDataAccessException(ex.getMessage(), ex); } }
From source file:com.rta.vsd.data.service.impl.ViolationDataServiceImpl.java
/** * /* ww w . ja v a2s . c o m*/ * Gets all the violations for vehicles owned by the owner with the specified trade license number * * @author Eldon Barrows * @param dsContext * @param retrieveArabicData * @param tradeLicenseNumber * @param paginationValues * @return List<VsdViolation> * @throws VSDDataAccessException */ public List<VsdViolation> getViolationsByTradeLicenseNumber(final DataServiceContext dsContext, boolean retrieveArabicData, String tradeLicenseNumber, PaginationParam paginationValues) throws VSDDataAccessException { logger.info("getViolationsByTradeLicenseNumber -- START"); List<VsdViolation> violations = null; try { Session session = (Session) dsContext.getInternalContext(); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.property("v.violationId"), "violationId"); Criteria crit = session.createCriteria(VsdViolation.class, "v") .add(Restrictions.eq("v.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("v.vsdInspections", "i", Criteria.LEFT_JOIN, Restrictions.eq("i.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("i.vsdVehicleInfo", "vi", Criteria.LEFT_JOIN, Restrictions.eq("vi.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("vi.vsdOwnerInfos", "oi", Criteria.LEFT_JOIN, Restrictions.eq("oi.isDeleted", IDataService.BOOL_FALSE)) .add(Restrictions.eq("oi.tradeLicenseNumber", tradeLicenseNumber).ignoreCase()) .addOrder(Order.desc("v.violationId")).setProjection(Projections.distinct(projectionList)); crit.setResultTransformer(new AliasToBeanResultTransformer(VsdViolation.class)); if (paginationValues.getFirstResult() != null && paginationValues.getFirstResult().longValue() != -1) { crit.setFirstResult(paginationValues.getFirstResult().intValue()); } if (paginationValues.getFetchedSize() != null && paginationValues.getFetchedSize().longValue() != -1) { crit.setMaxResults(paginationValues.getFetchedSize().intValue()); } List list = crit.list(); logger.debug("list.size() : " + list.size()); Set resultSet = new HashSet(list); logger.debug("resultSet.size() : " + resultSet.size()); if (resultSet.size() == 0) return new ArrayList(); Iterator iterator = resultSet.iterator(); ArrayList innerQueryList = new ArrayList<Long>(); while (iterator.hasNext()) { VsdViolation violation = (VsdViolation) iterator.next(); innerQueryList.add(violation.getViolationId()); } Criteria main = session.createCriteria(VsdViolation.class, "v") .add(Property.forName("v.violationId").in(innerQueryList)) .add(Restrictions.eq("v.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("v.vsdInspections", "i", Criteria.LEFT_JOIN, Restrictions.eq("i.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("i.vsdVehicleInfo", "vi", Criteria.LEFT_JOIN, Restrictions.eq("vi.isDeleted", IDataService.BOOL_FALSE)) .createCriteria("vi.vsdOwnerInfos", "oi", Criteria.LEFT_JOIN, Restrictions.eq("oi.isDeleted", IDataService.BOOL_FALSE)) .add(Restrictions.eq("oi.tradeLicenseNumber", tradeLicenseNumber).ignoreCase()) .addOrder(Order.desc("v.violationId")); violations = main.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); logger.info("getViolationsByTradeLicenseNumber -- END"); return violations; } catch (Exception ex) { logger.error("An error occured in getViolationsByTradeLicenseNumber()"); throw new VSDDataAccessException(ex.getMessage(), ex); } }