Example usage for org.hibernate.criterion Restrictions in

List of usage examples for org.hibernate.criterion Restrictions in

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions in.

Prototype

public static Criterion in(String propertyName, Collection values) 

Source Link

Document

Apply an "in" constraint to the named property.

Usage

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

License:Open Source License

public List<SourceOverviewDto> getAsOverviewDtos(final SharedSessionContract ssc, final Long userId,
        final Long projectId, final Long sourceId, final Collection<Long> sourceTypeIds) {
    if (projectId == null) {
        return Collections.emptyList();
    }/*from w ww  . ja v  a2  s  .  c  o  m*/

    // Restrict to user
    final Collection<Long> projectIdsForUser = projectDao.getIdsForUser(ssc, userId);
    if (projectIdsForUser.isEmpty()) {
        return Collections.emptyList();
    }

    // Query: Project2Source
    Collection<Long> sourceIds = null;
    final EntityQuery<Project2Source> project2SourceQuery = new EntityQuery<>(Project2Source.class);
    project2SourceQuery.addRestriction(Restrictions.eq("projectId", projectId));
    project2SourceQuery.addRestriction(Restrictions.in("projectId", projectIdsForUser));
    sourceIds = project2SourceQuery.listIdsForProperty(ssc, "sourceId");
    if (sourceIds.isEmpty()) {
        return Collections.emptyList();
    }

    // Query: Source2SourceType
    Collection<Long> sourceIds2 = null;
    if (CollectionUtils.isNotEmpty(sourceTypeIds)) {
        final EntityQuery<Source2SourceType> source2SourceTypeQuery = new EntityQuery<>(
                Source2SourceType.class);
        source2SourceTypeQuery.addRestriction(Restrictions.in("sourceTypeId", sourceTypeIds));
        sourceIds2 = source2SourceTypeQuery.listIdsForProperty(ssc, "sourceId");
        if (sourceIds2.isEmpty()) {
            return Collections.emptyList();
        }
    }

    // Query: Source
    final EntityWithIdQuery<Source> sourceQuery = new EntityWithIdQuery<>(Source.class);
    if (sourceId != null) {
        sourceQuery.addRestriction(Restrictions.idEq(sourceId));
    }
    if (sourceIds != null) {
        sourceQuery.addRestriction(Restrictions.in("id", sourceIds));
    }
    if (sourceIds2 != null) {
        sourceQuery.addRestriction(Restrictions.in("id", sourceIds2));
    }
    sourceQuery.addOrder(Order.asc("name"));

    // Done
    final List<Source> sources = sourceQuery.listObjects(ssc);

    // Transform
    final List<SourceOverviewDto> dtos = Lists.transform(sources, s -> sourceToOverviewDto(ssc, s));
    return Lists.newArrayList(dtos);
}

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

License:Open Source License

public List<Source> getOfProject(final SharedSessionContract ssc, final Long projectId) {
    if (projectId == null) {
        return Collections.emptyList();
    }//ww  w. ja v a  2  s.c o m

    // Query: Project2Source
    final EntityQuery<Project2Source> project2SourceQuery = new EntityQuery<>(Project2Source.class);
    project2SourceQuery.addRestriction(Restrictions.eq("projectId", projectId));
    final Collection<Long> sourceIds = project2SourceQuery.listIdsForProperty(ssc, "sourceId");
    if (sourceIds.isEmpty()) {
        return Collections.emptyList();
    }

    // Query: Source
    final EntityWithIdQuery<Source> sourceQuery = new EntityWithIdQuery<>(Source.class);
    sourceQuery.addRestriction(Restrictions.in("id", sourceIds));
    sourceQuery.addOrder(Order.asc("name"));

    // Done
    final List<Source> sources = sourceQuery.listObjects(ssc);
    return sources;
}

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();
    }/*ww w  .  ja v a 2  s .  c  o  m*/

    // 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.query.document.DocumentFilterSettingsQuery.java

License:Open Source License

private void addInRestrictionForIds(final EntityQuery<?> query, final String propertyName,
        final Collection<Long> ids) {
    if (ids == null) {
        return;/* w  ww.ja va2  s  .  c  o m*/
    }

    if (ids.isEmpty()) {
        query.addRestriction(Restrictions.eq(propertyName, -1L));
    } else {
        query.addRestriction(Restrictions.in(propertyName, ids));
    }
}

From source file:com.romeikat.datamessie.core.base.query.entity.entities.DocumentQuery.java

License:Open Source License

private void addRestrictions() {
    // Published//ww  w  .  j  a v  a 2 s.com
    if (dfs.getFromDate() != null) {
        addRestriction(Restrictions.ge("published", LocalDateTime.of(dfs.getFromDate(), LocalTime.MIDNIGHT)));
    }
    if (dfs.getToDate() != null) {
        addRestriction(Restrictions.lt("published",
                LocalDateTime.of(dfs.getToDate(), LocalTime.MIDNIGHT).plusDays(1)));
    }

    // States
    if (!CollectionUtils.isEmpty(dfs.getStates())) {
        addRestriction(Restrictions.in("state", dfs.getStates()));
    }

    // Document IDs from DFS
    final Collection<Long> documentIds = dfs.getDocumentIds();
    final boolean documentIdsApply = documentIds != null;
    if (documentIdsApply) {
        addIdRestriction(documentIds);
    }

    // Additional document IDs
    for (final Collection<Long> idRestriction : idRestrictions) {
        addIdRestriction(idRestriction);
    }
}

From source file:com.romeikat.datamessie.core.base.query.entity.entities.SourceTypeQuery.java

License:Open Source License

private void addRestrictions() {
    if (!CollectionUtils.isEmpty(dfs.getSourceTypeIds())) {
        addRestriction(Restrictions.in("id", dfs.getSourceTypeIds()));
    }/* www . j av  a2s  . c o m*/
}

From source file:com.romeikat.datamessie.core.base.query.entity.execute.AbstractEntityQueryExecutor.java

License:Open Source License

public void applyIdRestriction(final Collection<Long> ids, final Criteria criteria) {
    if (ids == null) {
        return;/*  w w w .j a v  a2 s.c o m*/
    }

    if (ids.isEmpty()) {
        criteria.add(Restrictions.idEq(-1l));
    } else {
        criteria.add(Restrictions.in("id", ids));
    }
}

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

License:Open Source License

public List<Document> getToProcess(final SharedSessionContract ssc, final LocalDate downloaded,
        final int maxResults) {
    final LocalDateTime minDownloaded = LocalDateTime.of(downloaded, LocalTime.MIDNIGHT);
    final LocalDateTime maxDownloaded = LocalDateTime.of(downloaded.plusDays(1), LocalTime.MIDNIGHT);

    // Query: Project
    final EntityWithIdQuery<Project> projectQuery = new EntityWithIdQuery<>(Project.class);
    projectQuery.addRestriction(Restrictions.eq("preprocessingEnabled", true));
    final Collection<Long> projectIds = projectQuery.listIds(ssc);
    if (projectIds.isEmpty()) {
        return Collections.emptyList();
    }//  w ww  .ja v a2s  .c  o  m
    // Query: Project2Source
    final Project2SourceQuery project2SourceQuery = new Project2SourceQuery();
    project2SourceQuery.addRestriction(Restrictions.in("projectId", projectIds));
    final Collection<Long> sourceIds = project2SourceQuery.listIdsForProperty(ssc, "sourceId");
    if (sourceIds.isEmpty()) {
        return Collections.emptyList();
    }

    // Query: Document
    final EntityWithIdQuery<Document> documentQuery = new EntityWithIdQuery<>(Document.class);
    documentQuery.addRestriction(Restrictions.in("sourceId", sourceIds));
    documentQuery.addRestriction(Restrictions.ge("downloaded", minDownloaded));
    documentQuery.addRestriction(Restrictions.lt("downloaded", maxDownloaded));
    final Object[] statesForProcessing = new DocumentProcessingState[] { DocumentProcessingState.DOWNLOADED,
            DocumentProcessingState.REDIRECTED, DocumentProcessingState.CLEANED };
    documentQuery.addRestriction(Restrictions.in("state", statesForProcessing));
    documentQuery.setMaxResults(maxResults);

    // Done
    final List<Document> entities = documentQuery.listObjects(ssc);
    return entities;
}

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

/**
 * // w ww  . java  2s.co 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.ViolationDataServiceImpl.java

/**
 * /*  ww  w.  j a va 2  s.  com*/
 * Gets a list of violations by the statusIds and plate details provided
 * 
 * @author Eldon Barrows
 * @param dsContext
 * @param retrieveArabicData
 * @param List<violationStatusId>
 * @param vehiclePlateDetails
 * @return List<VsdViolation>
 * @throws VSDDataAccessException
 */
public List<VsdViolation> getViolationsByStatusIdAndVehiclePlateDetails(DataServiceContext dsContext,
        boolean retrieveArabicData, List<Long> violationStatusIds, VehiclePlate vehiclePlateDetails)
        throws VSDDataAccessException {
    logger.info("getViolationsByStatusIdAndVehiclePlateDetails -- START");
    List<VsdViolation> violations = null;
    try {
        Session session = (Session) dsContext.getInternalContext();
        violations = session.createCriteria(VsdViolation.class, "violations")
                .add(Restrictions.in("violations.vsdViolationStatus.violationStatusId", violationStatusIds))
                .add(Restrictions.eq("violations.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())
                .addOrder(Order.desc("violations.reportedDate"))
                .createCriteria("violations.vsdSeverityLevel", "sl", Criteria.LEFT_JOIN)
                .add(Restrictions.eq("sl.isDeleted", IDataService.BOOL_FALSE))
                .createCriteria("violations.vsdChannelDefects", "channelDefects", Criteria.LEFT_JOIN,
                        Restrictions.eq("channelDefects.isDeleted", IDataService.BOOL_FALSE))
                .createCriteria("channelDefects.vsdDefect", "defect", Criteria.LEFT_JOIN,
                        Restrictions.eq("defect.isDeleted", IDataService.BOOL_FALSE))
                .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list();
    } catch (Exception ex) {
        logger.error("An error occured in getViolationsByStatusIdAndVehiclePlateDetails()");
        throw new VSDDataAccessException(ex.getMessage(), ex);
    }
    logger.info("getViolationsByStatusIdAndVehiclePlateDetails -- END");
    return violations;
}