Example usage for org.hibernate.criterion ProjectionList add

List of usage examples for org.hibernate.criterion ProjectionList add

Introduction

In this page you can find the example usage for org.hibernate.criterion ProjectionList add.

Prototype

public ProjectionList add(Projection projection, String alias) 

Source Link

Document

Adds a projection to this list of projections after wrapping it with an alias

Usage

From source file:com.romeikat.datamessie.core.base.dao.impl.ProjectDao.java

License:Open Source License

public ProjectDto getAsDto(final SharedSessionContract ssc, final long projectId, final Long userId) {
    // Restrict to user
    final Collection<Long> projectIdsForUser = getIdsForUser(ssc, userId);
    if (projectIdsForUser.isEmpty()) {
        return null;
    }/*from w  w w.j  a  va 2  s. c  o m*/

    // Query: Project
    final EntityWithIdQuery<Project> projectQuery = new EntityWithIdQuery<>(Project.class);
    projectQuery.addRestriction(Restrictions.idEq(projectId));
    projectQuery.addIdRestriction(projectIdsForUser);
    projectQuery.addOrder(Order.desc("started"));
    projectQuery.setResultTransformer(new AliasToBeanResultTransformer(ProjectDto.class));

    // Done
    final ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("id"), "id");
    projectionList.add(Projections.property("name"), "name");
    projectionList.add(Projections.property("crawlingEnabled"), "crawlingEnabled");
    projectionList.add(Projections.property("crawlingInterval"), "crawlingInterval");
    projectionList.add(Projections.property("preprocessingEnabled"), "preprocessingEnabled");
    final ProjectDto dto = (ProjectDto) projectQuery.uniqueForProjection(ssc, projectionList);
    return dto;
}

From source file:com.romeikat.datamessie.core.base.dao.impl.RedirectingRuleDao.java

License:Open Source License

public List<RedirectingRuleDto> getAsDtos(final SharedSessionContract ssc, final long sourceId) {
    // Query: RedirectingRule
    final EntityWithIdQuery<RedirectingRule> redirectingRuleQuery = new EntityWithIdQuery<>(
            RedirectingRule.class);
    redirectingRuleQuery.addRestriction(Restrictions.eq("sourceId", sourceId));
    redirectingRuleQuery.addOrder(Order.asc("activeFrom"));
    redirectingRuleQuery.setResultTransformer(new AliasToBeanResultTransformer(RedirectingRuleDto.class));

    // Done//from  w  w  w .  jav  a  2 s  .  co m
    final ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("id"), "id");
    projectionList.add(Projections.property("regex"), "regex");
    projectionList.add(Projections.property("regexGroup"), "regexGroup");
    projectionList.add(Projections.property("activeFrom"), "activeFrom");
    projectionList.add(Projections.property("activeTo"), "activeTo");
    @SuppressWarnings("unchecked")
    final List<RedirectingRuleDto> dtos = (List<RedirectingRuleDto>) redirectingRuleQuery.listForProjection(ssc,
            projectionList);
    return dtos;
}

From source file:com.romeikat.datamessie.core.base.dao.impl.SourceTypeDao.java

License:Open Source License

public List<SourceTypeDto> getAsDtos(final SharedSessionContract ssc) {
    // Query: SourceType
    final EntityWithIdQuery<SourceType> sourceQuery = new EntityWithIdQuery<>(SourceType.class);
    sourceQuery.addOrder(Order.asc("name"));
    sourceQuery.setResultTransformer(new AliasToBeanResultTransformer(SourceTypeDto.class));

    // Done//from   w w  w  .  j ava 2s .  c o m
    final ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("id"), "id");
    projectionList.add(Projections.property("name"), "name");
    @SuppressWarnings("unchecked")
    final List<SourceTypeDto> dtos = (List<SourceTypeDto>) sourceQuery.listForProjection(ssc, projectionList);
    return dtos;
}

From source file:com.romeikat.datamessie.core.base.dao.impl.SourceTypeDao.java

License:Open Source License

public List<SourceTypeDto> getAsDtos(final SharedSessionContract ssc, final long sourceId) {
    // Query: Source2SourceType
    final EntityQuery<Source2SourceType> project2SourceQuery = new EntityQuery<>(Source2SourceType.class);
    project2SourceQuery.addRestriction(Restrictions.eq("sourceId", sourceId));
    final List<Long> sourceTypeIds = project2SourceQuery.listIdsForProperty(ssc, "sourceTypeId");
    if (sourceTypeIds.isEmpty()) {
        return Collections.emptyList();
    }//www  . jav  a  2  s  . c  om

    // Query: SourceType
    final EntityQuery<SourceType> sourceTypeQuery = new EntityQuery<>(SourceType.class);
    sourceTypeQuery.addRestriction(Restrictions.in("id", sourceTypeIds));
    sourceTypeQuery.addOrder(Order.asc("name"));
    sourceTypeQuery.setResultTransformer(new AliasToBeanResultTransformer(SourceTypeDto.class));

    // Done
    final ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("id"), "id");
    projectionList.add(Projections.property("name"), "name");
    @SuppressWarnings("unchecked")
    final List<SourceTypeDto> dtos = (List<SourceTypeDto>) sourceTypeQuery.listForProjection(ssc,
            projectionList);
    return dtos;
}

From source file:com.romeikat.datamessie.core.base.dao.impl.TagSelectingRuleDao.java

License:Open Source License

public List<TagSelectingRuleDto> getAsDtos(final SharedSessionContract ssc, final long sourceId) {
    // Query: TagSelectingRule
    final EntityWithIdQuery<TagSelectingRule> tagSelectingRuleQuery = new EntityWithIdQuery<>(
            TagSelectingRule.class);
    tagSelectingRuleQuery.addRestriction(Restrictions.eq("sourceId", sourceId));
    tagSelectingRuleQuery.addOrder(Order.asc("activeFrom"));
    tagSelectingRuleQuery.setResultTransformer(new AliasToBeanResultTransformer(TagSelectingRuleDto.class));

    // Done/*from w w  w.  ja va2  s .  co m*/
    final ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("id"), "id");
    projectionList.add(Projections.property("tagSelector"), "tagSelector");
    projectionList.add(Projections.property("activeFrom"), "activeFrom");
    projectionList.add(Projections.property("activeTo"), "activeTo");
    @SuppressWarnings("unchecked")
    final List<TagSelectingRuleDto> dtos = (List<TagSelectingRuleDto>) tagSelectingRuleQuery
            .listForProjection(ssc, projectionList);
    return dtos;
}

From source file:com.romeikat.datamessie.core.base.service.SourceService.java

License:Open Source License

public String getNewName(final SharedSessionContract ssc) {
    // Get all names
    final EntityWithIdQuery<Source> sourceQuery = new EntityWithIdQuery<>(Source.class);
    final ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("name"), "name");
    final List<String> names = (List<String>) sourceQuery.listForProjection(ssc, projectionList);

    // Determine new name
    int counter = 1;
    while (true) {
        final String candidateName = "New source #" + counter;
        if (!stringUtil.containsIgnoreCase(names, candidateName)) {
            return candidateName;
        } else {//  w  w  w.  j a  va  2  s.c  o m
            counter++;
        }
    }
}

From source file:com.romeikat.datamessie.core.statistics.dao.DocumentDao.java

License:Open Source License

public List<DocumentStatisticsDto> getAsDocumentStatisticsDtos(final SharedSessionContract ssc,
        final Long sourceId, final LocalDate published) {
    final LocalDateTime minPublished = published == null ? null
            : LocalDateTime.of(published, LocalTime.MIDNIGHT);
    final LocalDateTime maxPublished = published == null ? null
            : LocalDateTime.of(published.plusDays(1), LocalTime.MIDNIGHT);

    // Query: Document
    final EntityWithIdQuery<Document> documentQuery = new EntityWithIdQuery<>(Document.class);
    if (sourceId != null) {
        documentQuery.addRestriction(Restrictions.eq("sourceId", sourceId));
    }/*from   w  ww  . j a  va 2s . co  m*/
    if (minPublished != null) {
        documentQuery.addRestriction(Restrictions.ge("published", minPublished));
    }
    if (maxPublished != null) {
        documentQuery.addRestriction(Restrictions.lt("published", maxPublished));
    }
    documentQuery.setResultTransformer(new AliasToBeanResultTransformer(DocumentStatisticsDto.class));

    // Done
    final ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("id"), "documentId");
    projectionList.add(Projections.property("sourceId"), "sourceId");
    projectionList.add(Projections.property("published"), "published");
    projectionList.add(Projections.property("state"), "state");
    @SuppressWarnings("unchecked")
    final List<DocumentStatisticsDto> dtos = (List<DocumentStatisticsDto>) documentQuery.listForProjection(ssc,
            projectionList);
    return dtos;
}

From source file:com.rta.vsd.data.service.impl.InspectionDataServiceImpl.java

/**
 * /*from w ww .ja  v  a 2 s .  c  om*/
 * 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

/**
 * //  www.  j a  v  a  2s. 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 traficFileNo
 * @param paginationParam
 * @return List<VsdInspection>
 * @throws VSDDataAccessException
 */
public List<VsdInspection> getInspectionsByTraficFileNumber(final DataServiceContext dsContext,
        boolean retrieveArabicData, String traficFileNo, PaginationParam param) throws VSDDataAccessException {
    logger.info("getInspectionsByTraficFileNumber -- START");
    List<VsdInspection> inspections;
    try {
        Session session = (Session) dsContext.getInternalContext();
        ProjectionList projectionList = Projections.projectionList();
        projectionList.add(Projections.property("inspections.inspectionId"), "inspectionId");
        projectionList.add(Projections.property("inspections.createdTimestamp"), "createdTimestamp");
        inspections = 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.trafficFileNumber", traficFileNo).ignoreCase())
                .addOrder(Order.desc("inspections.createdTimestamp"))
                .setProjection(Projections.distinct(projectionList))
                .setFirstResult(param.getFirstResult().intValue())
                .setMaxResults(param.getFetchedSize().intValue())
                .setResultTransformer(new AliasToBeanResultTransformer(VsdInspection.class)).list();
        if (inspections.size() == 0)
            return new ArrayList();
        Iterator iterator = inspections.iterator();
        ArrayList innerQueryList = new ArrayList<Long>();
        while (iterator.hasNext()) {
            VsdInspection inspection = (VsdInspection) iterator.next();
            innerQueryList.add(inspection.getInspectionId());
        }
        inspections = 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.trafficFileNumber", traficFileNo).ignoreCase())
                .add(Restrictions.in("inspections.inspectionId", innerQueryList))
                .addOrder(Order.desc("inspections.createdTimestamp")).list();
    } catch (Exception ex) {
        logger.error("An error occured in getInspectionsByTraficFileNumber()");
        throw new VSDDataAccessException(ex.getMessage(), ex);
    }
    logger.info("getInspectionsByTraficFileNumber -- END");
    return inspections;
}

From source file:com.rta.vsd.data.service.impl.InspectionDataServiceImpl.java

/**
 * //from   w w w.  j a  v  a2  s.c  om
 * 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);
    }
}