@Override public void prepareItemQuery(ItemSerializerState state) { final DetachedCriteria criteria = state.getItemQuery(); final ProjectionList projection = state.getItemProjection(); if( state.hasCategory(ItemSerializerService.CATEGORY_BASIC) ) { projection.add(Projections.property("name.id"), NAME_ALIAS); projection.add(Projections.property("description.id"), DESC_ALIAS); } if( state.hasCategory(ItemSerializerService.CATEGORY_METADATA) ) { criteria.createAlias("itemXml", "itemXml"); projection.add(Projections.property("itemXml.xml"), METADATA_ALIAS); } }
@SuppressWarnings ("unchecked") public List<T> listCriteria (DetachedCriteria detached, int skip, int top) { SessionFactory factory = getSessionFactory (); org.hibernate.classic.Session session = factory.getCurrentSession (); Criteria criteria = detached.getExecutableCriteria (session); if (skip > 0) criteria.setFirstResult (skip); if (top > 0) criteria.setMaxResults (top); return criteria.list (); }
@Override public List<?> findByCriteria(final DetachedCriteria criteria, final int firstResult, final int maxResults) throws DataAccessException { Assert.notNull(criteria, "DetachedCriteria must not be null"); return executeWithNativeSession(new HibernateCallback<List<?>>() { @Override @SuppressWarnings("unchecked") public List<?> doInHibernate(Session session) throws HibernateException { Criteria executableCriteria = criteria.getExecutableCriteria(session); prepareCriteria(executableCriteria); if (firstResult >= 0) { executableCriteria.setFirstResult(firstResult); } if (maxResults > 0) { executableCriteria.setMaxResults(maxResults); } return executableCriteria.list(); } }); }
private Object execute(FlowFinderCriteria flowFinderCriteria, DetachedCriteria flowStatusCriteria, Session session, boolean idProjection) { Criteria criteria = flowStatusCriteria.getExecutableCriteria(session); if (idProjection) { criteria.setProjection(Projections.id()); } int maxResults = flowFinderCriteria.getMaxResults(); if (maxResults != FlowFinderCriteria.DEFAULT_MAX_RESULTS) { criteria.setMaxResults(maxResults); } if (flowFinderCriteria.hasMessageQuery()) { FlowSearchCriteria flowSearchCriteria = new FlowSearchCriteria(); flowSearchCriteria.setHibernateCriteria(criteria); flowSearchCriteria.setInboundMessageQuery(flowFinderCriteria.getInboundMessageQuery()); flowSearchCriteria.setOutboundMessageQuery(flowFinderCriteria.getOutboundMessageQuery()); return flowSearchCallback.findFlows(session, flowSearchCriteria); } else { return criteria.list(); } }
private static DetachedCriteria createFlowsCriteria(FlowFinderCriteria finderCriteria) { DetachedCriteria criteria = DetachedCriteria.forClass(Flow.class) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) .setFetchMode("parts", FetchMode.JOIN) // eager .add(ge("creationTime", finderCriteria.getFrom())) .addOrder(Order.desc("identifier")); if (finderCriteria.getApplication() != null) { // constrain query to a certain application name criteria.add(eq("application", finderCriteria .getApplication())); } if (finderCriteria.getTo() != null) { // there's an upper limit to creationTime property criteria.add(Restrictions .le("creationTime", finderCriteria.getTo())); } return criteria; }
private static DetachedCriteria createPurgeCriteria(FlowPurgeCriteria purgeCriteria) { DetachedCriteria criteria = DetachedCriteria.forClass(Flow.class) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) // purge all flows with a creation time older than time limit .add(lt("creationTime", purgeCriteria.getTimeLimit())) // purge oldest flows first .addOrder(Order.asc("creationTime")); if (purgeCriteria.getApplication() != null) { criteria.add(eq("application", purgeCriteria.getApplication())); } if (purgeCriteria.getPurgeMode() == PurgeMode.CLEAN) { // omit flows with error status criteria.add( or( eq("derivedStatus", FlowStatus.CLEAN), isNull("derivedStatus") // old flows (both CLEAN and ERROR) ) ); } return criteria; }
@Override public QuotePE getLast(String sigle) { Session session = getSession(); DetachedCriteria maxDate = DetachedCriteria.forClass(QuotePE.class); maxDate.add(Restrictions.eq("symbol", sigle)); maxDate.setProjection(Projections.max("creationDateTime")); Criteria criteria = session.createCriteria(QuotePE.class); criteria.add(Restrictions.eq("symbol", sigle)); criteria.add(Property.forName("creationDateTime").eq(maxDate)); QuotePE pe = (QuotePE) criteria.uniqueResult(); session.close(); return pe; }
@Override public RpcGetAuthorizCustomer process(CmdParams cmdParams, String ipAdress, byte[] IP) { QLog.l().logQUser().debug("getClientAuthorization"); super.process(cmdParams, ipAdress, IP); // Вытащим из базы предварительного кастомера if (cmdParams.clientAuthId == null || cmdParams.clientAuthId.isEmpty()) { return new RpcGetAuthorizCustomer(null); } final List<QAuthorizationCustomer> authCusts = Spring.getInstance().getHt() .findByCriteria( DetachedCriteria.forClass(QAuthorizationCustomer.class) .add(Restrictions.eq("authId", cmdParams.clientAuthId).ignoreCase())); final QAuthorizationCustomer authCust; if (authCusts.isEmpty() || authCusts.get(0) == null || authCusts.get(0).getId() == null || authCusts.get(0).getName() == null) { QLog.l().logger() .trace("Не найден клиент по его ID = '" + cmdParams.clientAuthId + "'"); authCust = null; } else { authCust = authCusts.get(0); } return new RpcGetAuthorizCustomer(authCust); }
@SuppressWarnings("unchecked") public void deleteComponentProfileByControlId(String controlId, String name) { DetachedCriteria detachedCriteria = DetachedCriteria.forClass(ComponentConfig.class); detachedCriteria.add(Restrictions.eq("controlId", controlId)); detachedCriteria.add(Restrictions.eq("name", name)); Session session = this.getSessionFactory().openSession(); try { org.hibernate.Criteria criteria = detachedCriteria.getExecutableCriteria(session); List<ComponentConfig> list = criteria.list(); if (list.size() > 0) { String hql = "delete " + ComponentConfigMember.class.getName() + " m where m.componentConfig.id = :configId"; session.createQuery(hql).setString("configId", list.get(0).getId()).executeUpdate(); session.delete(list.get(0)); } } finally { session.flush(); session.close(); } }
public void loadMessageTemplates(Page<MessageTemplate> page,Criteria criteria,String type){ IUser user=ContextHolder.getLoginUser(); if(user==null){ throw new RuntimeException("Please login first!"); } String companyId=user.getCompanyId(); if(StringUtils.isNotEmpty(getFixedCompanyId())){ companyId=getFixedCompanyId(); } DetachedCriteria dc=this.buildDetachedCriteria(criteria, MessageTemplate.class); if(StringUtils.isNotEmpty(type)){ dc.add(Property.forName("type").eq(type)); } Property p=Property.forName("companyId"); dc.add(p.eq(companyId)); this.pagingQuery(page, dc); }
private static DetachedCriteria createEcrfFieldValueDetachedCriteria(org.hibernate.Criteria ecrfFieldValueCriteria, org.hibernate.Criteria ecrfFieldCriteria, org.hibernate.Criteria probandListEntryCriteria, Long probandListEntryId, Long ecrfFieldId) { DetachedCriteria subQuery = DetachedCriteria.forClass(ECRFFieldValueImpl.class, "ecrfFieldValue1"); // IMPL!!!! // subQuery.setProjection(Projections.max("id")); if (probandListEntryId == null) { if (probandListEntryCriteria == null) { probandListEntryCriteria = ecrfFieldValueCriteria.createCriteria("listEntry", "probandListEntry0"); } subQuery.add(Restrictions.eqProperty("listEntry.id", probandListEntryCriteria.getAlias() + ".id")); } else { subQuery.add(Restrictions.eq("listEntry.id", probandListEntryId.longValue())); } if (ecrfFieldId == null) { if (ecrfFieldCriteria == null) { ecrfFieldCriteria = ecrfFieldValueCriteria.createCriteria("ecrfField", "ecrfField0"); } subQuery.add(Restrictions.eqProperty("ecrfField.id", ecrfFieldCriteria.getAlias() + ".id")); } else { subQuery.add(Restrictions.eq("ecrfField.id", ecrfFieldId.longValue())); } return subQuery; }
private void buildCriterions(Collection<com.bstek.dorado.data.provider.Criterion> criterions, DetachedCriteria dc) { for (com.bstek.dorado.data.provider.Criterion c : criterions) { if (c instanceof SingleValueFilterCriterion) { SingleValueFilterCriterion fc = (SingleValueFilterCriterion) c; dc.add(this.buildCriterion(fc)); } if (c instanceof Junction) { Junction jun = (Junction) c; org.hibernate.criterion.Junction junction = null; if (jun instanceof Or) { junction = Restrictions.disjunction(); } else if (jun instanceof And) { junction = Restrictions.conjunction(); } Collection<com.bstek.dorado.data.provider.Criterion> subCriterions = jun.getCriterions(); if (subCriterions != null) { buildCriterions(subCriterions, junction); } dc.add(junction); } } }
private static DetachedCriteria createEcrfFieldStatusEntryDetachedCriteria(org.hibernate.Criteria ecrfFieldStatusEntryCriteria, org.hibernate.Criteria ecrfFieldCriteria, org.hibernate.Criteria probandListEntryCriteria, Long probandListEntryId, Long ecrfFieldId) { DetachedCriteria subQuery = DetachedCriteria.forClass(ECRFFieldStatusEntryImpl.class, "ecrfFieldStatusEntry1"); // IMPL!!!! // subQuery.setProjection(Projections.max("id")); if (probandListEntryId == null) { if (probandListEntryCriteria == null) { probandListEntryCriteria = ecrfFieldStatusEntryCriteria.createCriteria("listEntry", "probandListEntry0"); } subQuery.add(Restrictions.eqProperty("listEntry.id", probandListEntryCriteria.getAlias() + ".id")); } else { subQuery.add(Restrictions.eq("listEntry.id", probandListEntryId.longValue())); } if (ecrfFieldId == null) { if (ecrfFieldCriteria == null) { ecrfFieldCriteria = ecrfFieldStatusEntryCriteria.createCriteria("ecrfField", "ecrfField0"); } subQuery.add(Restrictions.eqProperty("ecrfField.id", ecrfFieldCriteria.getAlias() + ".id")); } else { subQuery.add(Restrictions.eq("ecrfField.id", ecrfFieldId.longValue())); } return subQuery; }
private static DetachedCriteria createEcrfFieldStatusEntryDetachedCriteriaMaxId(org.hibernate.Criteria ecrfFieldStatusEntryCriteria, org.hibernate.Criteria ecrfFieldCriteria, org.hibernate.Criteria probandListEntryCriteria, ECRFFieldStatusQueue queue, Long probandListEntryId, Long ecrfFieldId) { DetachedCriteria subQuery = createEcrfFieldStatusEntryDetachedCriteria(ecrfFieldStatusEntryCriteria, ecrfFieldCriteria, probandListEntryCriteria, probandListEntryId, ecrfFieldId); if (queue != null) { subQuery.add(Restrictions.eq("queue", queue)); subQuery.setProjection(Projections.max("id")); } else { ProjectionList proj = Projections.projectionList(); proj.add(Projections.sqlGroupProjection( "max({alias}.id) as maxId", "{alias}.queue", new String[] { "maxId" }, new org.hibernate.type.Type[] { Hibernate.LONG })); subQuery.setProjection(proj); } return subQuery; }
@SuppressWarnings ("unchecked") public T uniqueResult (DetachedCriteria criteria) { Criteria excrit = criteria.getExecutableCriteria(getSessionFactory().getCurrentSession()); excrit.setMaxResults(1); List<?> res = excrit.list(); return res.isEmpty() ? null : (T) res.get(0); }
public int count (DetachedCriteria detached) { Session session = getSessionFactory ().getCurrentSession (); Criteria criteria = detached.getExecutableCriteria (session); criteria.setProjection(Projections.rowCount()); Object result = criteria.uniqueResult (); return ((Number) result).intValue (); }
/** * Retrieves a datastore configuration by its name. * * @param name data store configuration name * @return a DataStoreConfiguration or null if not found */ public DataStoreConfiguration getDataStoreConfigurationByName(String name) { DetachedCriteria criteria = DetachedCriteria.forClass(DataStoreConfiguration.class); criteria.add(Restrictions.eq("name", name)); return super.uniqueResult(criteria); }
@Override protected Collection<Permission> handleFindByServiceMethodUser( String serviceMethod, Long userId, Boolean profilePermissionActive, Boolean userPermissionProfileActive) throws Exception { org.hibernate.Criteria permissionCritria = createPermissionCriteria(); if (serviceMethod != null) { permissionCritria.add(Restrictions.eq("serviceMethod", serviceMethod)); } if (userId != null || profilePermissionActive != null || userPermissionProfileActive != null) { org.hibernate.Criteria profilePermissionCritria = permissionCritria.createCriteria("profilePermissions", CriteriaSpecification.LEFT_JOIN); if (profilePermissionActive != null) { profilePermissionCritria.add(Restrictions.eq("active", profilePermissionActive.booleanValue())); } if (userId != null || userPermissionProfileActive != null) { DetachedCriteria subQuery = DetachedCriteria.forClass(UserPermissionProfileImpl.class, "userPermissionProfile"); // IMPL!!!! subQuery.setProjection(Projections.projectionList().add(Projections.property("profile"))); if (userId != null) { subQuery.add(Restrictions.eq("user.id", userId.longValue())); } if (userPermissionProfileActive != null) { subQuery.add(Restrictions.eq("active", userPermissionProfileActive.booleanValue())); } profilePermissionCritria.add(Subqueries.propertyIn("profile", subQuery)); } } return permissionCritria.list(); }
private org.hibernate.Criteria[] createEcrfFieldCriteria(Long probandListEntryId, Long ecrfId) { org.hibernate.Criteria ecrfFieldCriteria = this.getSession().createCriteria(ECRFField.class, ServiceUtil.ECRF_FIELD_VALUE_DAO_ECRF_FIELD_ALIAS); ecrfFieldCriteria.add(Restrictions.eq("ecrf.id", ecrfId.longValue())); org.hibernate.Criteria ecrfFieldValueCriteria = ecrfFieldCriteria.createCriteria("fieldValues", ServiceUtil.ECRF_FIELD_VALUE_DAO_ECRF_FIELD_VALUE_ALIAS, CriteriaSpecification.LEFT_JOIN, Restrictions.eq(ServiceUtil.ECRF_FIELD_VALUE_DAO_ECRF_FIELD_VALUE_ALIAS + ".listEntry.id", probandListEntryId.longValue())); // criteriaMap.createCriteria("ecrfField", CriteriaSpecification.LEFT_JOIN); // ecrfFieldValueCriteria.add(Restrictions.or(Restrictions.eq("listEntry.id", probandListEntryId.longValue()), // Restrictions.isNull("listEntry"))); // correlated - slow: DetachedCriteria subQuery = createEcrfFieldValueDetachedCriteriaMaxId(ecrfFieldValueCriteria, ecrfFieldCriteria, null, probandListEntryId, null); // DetachedCriteria subQuery = DetachedCriteria.forClass(ECRFFieldValueImpl.class, "ecrfFieldValue1"); // IMPL!!!! // subQuery.setProjection(Projections.max("id")); // subQuery.add(Restrictions.eq("listEntry.id", probandListEntryId.longValue())); // subQuery.add(Restrictions.eqProperty("ecrfField.id", "ecrfField0.id")); subQuery.add(Restrictions.or(Restrictions.isNull("index"), Restrictions.eqProperty("index", ServiceUtil.ECRF_FIELD_VALUE_DAO_ECRF_FIELD_VALUE_ALIAS + ".index"))); ecrfFieldValueCriteria.add(Restrictions.or( Restrictions.isNull("listEntry"), Restrictions.and( Restrictions.eq("listEntry.id", probandListEntryId.longValue()), Subqueries.propertyIn("id", subQuery) ) )); // System.out.println(CriteriaUtil.criteriaToSql(ecrfFieldCriteria)); return new org.hibernate.Criteria[] { ecrfFieldCriteria, ecrfFieldValueCriteria }; }
@Transactional(readOnly = true) public Product getProductByOrigin (final String origin) { DetachedCriteria criteria = DetachedCriteria.forClass (Product.class); criteria.add (Restrictions.eq ("origin", origin)); return productDao.uniqueResult (criteria); }
/** * Retrieve products ordered by it date of ingestion, updated. * The list of product is returned prior to the passed date argument. * Currently processed and locked products are not returned. * * @param max_date Maximum date to retrieve products * More recent product will not be returned * @param max_products Maximum products to return * @return a scrollable list of the products */ @Transactional(readOnly = true) public Iterator<Product> getProductsByCreationDate(Date max_date, int max_products) { DetachedCriteria criteria = DetachedCriteria.forClass(Product.class); criteria.add(Restrictions.and( Restrictions.lt("created", max_date), Restrictions.and( Restrictions.eq("processed", true), Restrictions.eq("locked", false)))); criteria.addOrder(Order.asc("created")); return productDao.listCriteria(criteria, 0, max_products).iterator(); }
@Override public String[] getAllUserNames() throws FtpException { DetachedCriteria criteria = DetachedCriteria.forClass ( fr.gael.dhus.database.object.User.class); criteria.add (Restrictions.eq ("deleted", false)); Iterator<fr.gael.dhus.database.object.User> it = userService.getUsers(null, 0); List<String> names = new LinkedList<> (); while (it.hasNext()) { names.add (it.next ().getUsername ()); } return names.toArray(new String[names.size()]); }
@Override protected Collection<Trial> handleFindBySignup(Long departmentId, boolean ignoreSignupInquiries, PSFVO psf) throws Exception { org.hibernate.Criteria trialCriteria = createTrialCriteria("trial0"); SubCriteriaMap criteriaMap = new SubCriteriaMap(Trial.class, trialCriteria); if (departmentId != null) { trialCriteria.add(Restrictions.eq("department.id", departmentId.longValue())); } org.hibernate.Criteria statusCriteria = trialCriteria.createCriteria("status", "trialStatus", CriteriaSpecification.INNER_JOIN); statusCriteria.add(Restrictions.eq("lockdown", false)); DetachedCriteria subQuery = DetachedCriteria.forClass(InquiryImpl.class, "inquiry"); // IMPL!!!! subQuery.setProjection(Projections.rowCount()); subQuery.add(Restrictions.eqProperty("trial.id", "trial0.id")); subQuery.add(Restrictions.eq("activeSignup", true)); trialCriteria.add( Restrictions.or( Restrictions.eq("signupProbandList", true), Restrictions.and( ignoreSignupInquiries ? Subqueries.lt(0l, subQuery) : Restrictions.and( Restrictions.eq("signupInquiries", true), Subqueries.lt(0l, subQuery) // Restrictions.sizeGt("inquiries", 0) ), Restrictions.eq("trialStatus.inquiryValueInputEnabled", true) ) ) ); // if (probandList != null) { // trialCriteria.add(Restrictions.eq("signupProbandList", probandList.booleanValue())); // } // if (inquiries != null) { // trialCriteria.add(Restrictions.eq("signupInquiries", inquiries.booleanValue())); // statusCriteria.add(Restrictions.eq("inquiryValueInputEnabled", true)); // trialCriteria.add(Restrictions.sizeGt("inquiries", 0)); // } CriteriaUtil.applyPSFVO(criteriaMap, psf); return trialCriteria.list(); }
@Override @SuppressWarnings("nls") public void changeUserId(String fromUserId, String toUserId) { DetachedCriteria dc = DetachedCriteria.forClass(PortletRecentContrib.class); dc.add(Restrictions.eq("userId", fromUserId)); dc.createCriteria("portlet").add(Restrictions.eq("institution", CurrentInstitution.get())); List<PortletRecentContrib> prcs = portletDao.findAnyByCriteria(dc, null, null); for( PortletRecentContrib prc : prcs ) { prc.setUserId(toUserId); portletDao.saveAny(prc); } }
@Override public void addWhere(ItemSerializerState state) { ProjectionList projections = state.getItemProjection(); DetachedCriteria criteria = state.getItemQuery(); criteria.add(Restrictions.eq("uuid", uuid)); criteria.addOrder(Order.asc(PROPERTY_VERSION)); projections.add(Projections.property(PROPERTY_VERSION), ALIAS_VERSION); }
@Override public void addWhere(ItemSerializerState state) { DetachedCriteria criteria = state.getItemQuery(); ProjectionList projections = state.getItemProjection(); criteria.add(Restrictions.eq("uuid", uuid)); if( live ) { criteria.add(Restrictions.eq("status", ItemStatus.LIVE.name())); } criteria.addOrder(Order.desc(PROPERTY_VERSION)); projections.add(Projections.property(PROPERTY_VERSION), ALIAS_VERSION); state.setMaxResults(1); }
@Override protected Collection<Proband> handleFindByMoneyTransferNoParticipation(Long trialId, PaymentMethod method, String costType, Boolean paid, boolean total, Boolean person, PSFVO psf) throws Exception { org.hibernate.Criteria probandCriteria = createProbandCriteria("proband0"); if (person != null) { probandCriteria.add(Restrictions.eq("person", person.booleanValue())); } SubCriteriaMap criteriaMap = new SubCriteriaMap(Proband.class, probandCriteria); Criteria moneyTransferCriteria = criteriaMap.createCriteria("moneyTransfers"); moneyTransferCriteria.add(Restrictions.eq("trial.id", trialId.longValue())); if (method != null) { moneyTransferCriteria.add(Restrictions.eq("method", method)); } if (paid != null) { moneyTransferCriteria.add(Restrictions.eq("paid", paid.booleanValue())); } CategoryCriterion.apply(moneyTransferCriteria, new CategoryCriterion(costType, "costType", MatchMode.EXACT, EmptyPrefixModes.ALL_ROWS)); DetachedCriteria subQuery = DetachedCriteria.forClass(ProbandListEntryImpl.class, "probandListEntry"); // IMPL!!!! subQuery.setProjection(Projections.rowCount()); subQuery.add(Restrictions.eqProperty("proband.id", "proband0.id")); subQuery.add(Restrictions.eq("trial.id", trialId.longValue())); if (!total) { subQuery.createCriteria("lastStatus", CriteriaSpecification.INNER_JOIN).createCriteria("status", CriteriaSpecification.INNER_JOIN) .add(Restrictions.eq("count", true)); } probandCriteria.add(Subqueries.eq(0l, subQuery)); return CriteriaUtil.listDistinctRootPSFVO(criteriaMap, psf, this); // return probandCriteria.list(); }
private Object execute(FlowPurgeCriteria flowPurgeCriteria, DetachedCriteria flowStatusCriteria, Session session) { Criteria criteria = flowStatusCriteria.getExecutableCriteria(session); int purgeCount = flowPurgeCriteria.getMaxPurgeCount(); if (purgeCount != FlowPurgeCriteria.DEFAULT_MAX_PURGE_COUNT) { // Setting max results adds "fetch first 100 rows only" to the select query // Works on Derby version 1.5.x and above with Hibernate version 3.5.x and above criteria.setMaxResults(purgeCount); } return criteria.list(); }
public List findByCriteria(DetachedCriteria dCriteria) { List list; final Session ses = getTxManager().getSessionFactory().openSession(); try { list = dCriteria.getExecutableCriteria(ses).list(); } finally { ses.close(); } return list; }
@Override protected LinkedList<QService> load() { return new LinkedList<>( Spring.getInstance().getHt().findByCriteria(DetachedCriteria.forClass(QService.class). setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY). add(Property.forName("deleted").isNull()). addOrder(Property.forName("seqId").asc()). addOrder(Property.forName("id").asc()))); }
@Override protected LinkedList<QRespItem> load() { return new LinkedList<>( Spring.getInstance().getHt().findByCriteria(DetachedCriteria.forClass(QRespItem.class). setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY). add(Property.forName("deleted").isNull()). addOrder(Property.forName("id").asc()))); }
private static DetachedCriteria createEcrfFieldValueDetachedCriteriaMaxId(org.hibernate.Criteria ecrfFieldValueCriteria, org.hibernate.Criteria ecrfFieldCriteria, org.hibernate.Criteria probandListEntryCriteria, Long probandListEntryId, Long ecrfFieldId) { DetachedCriteria subQuery = createEcrfFieldValueDetachedCriteria(ecrfFieldValueCriteria, ecrfFieldCriteria, probandListEntryCriteria, probandListEntryId, ecrfFieldId); subQuery.setProjection(Projections.max("id")); return subQuery; }
@Override protected LinkedList<QUser> load() { final LinkedList<QUser> users = new LinkedList<>( Spring.getInstance().getHt().findByCriteria( DetachedCriteria.forClass(QUser.class) .add(Property.forName("deleted").isNull()) .setResultTransformer((Criteria.DISTINCT_ROOT_ENTITY)))); users.stream().forEach((qUser) -> { qUser.setServicesCnt(qUser.getPlanServiceList().getSize()); }); return users; }
@Override protected LinkedList<QOffice> load() { final LinkedList<QOffice> offices = new LinkedList<>( Spring.getInstance().getHt().findByCriteria( DetachedCriteria.forClass(QOffice.class) .add(Property.forName("deleted").isNull()) .setResultTransformer((Criteria.DISTINCT_ROOT_ENTITY)))); return offices; }
@DataProvider public void loadDefinitions(Page<ReportDefinition> page,Criteria criteria){ DetachedCriteria dc=this.buildDetachedCriteria(criteria, ReportDefinition.class); dc.addOrder(Order.desc("createDate")); this.pagingQuery(page, dc); IFileService fileService=ContextHolder.getBean(IFileService.BEAN_ID); for(ReportDefinition report:page.getEntities()){ UploadDefinition uploadDefinition=fileService.getUploadDefinition(report.getReportFile()); if(uploadDefinition!=null){ report.setReportFileName(uploadDefinition.getFileName()); } } }
@SuppressWarnings("rawtypes") public List findByCriteria(final DetachedCriteria detachedCriteria) throws Exception { Session session=this.getSessionFactory(dataSourceRegisterName).openSession(); try{ org.hibernate.Criteria criteria = detachedCriteria.getExecutableCriteria(session); return criteria.list(); }finally{ session.flush(); session.close(); } }
public void loadExcelModels(Page<ExcelModel> page, DetachedCriteria detachedCriteria) throws Exception { boolean noCore=Configure.getBoolean("bdf2.noCore",false); String companyId=null; if(noCore){ companyId = "bstek"; }else{ companyId = ContextHolder.getLoginUser().getCompanyId(); } detachedCriteria.add(Restrictions.eq("companyId", companyId)); findPageByCriteria(detachedCriteria, page); }
@SuppressWarnings("rawtypes") public ExcelModel findExcelModelById(String excelModelId) throws Exception { DetachedCriteria detachedCriteria = DetachedCriteria.forClass(ExcelModel.class, "m"); detachedCriteria.add(Restrictions.eq("id", excelModelId)); List list = findByCriteria(detachedCriteria); if (list.isEmpty()) { return null; } else { return (ExcelModel) list.get(0); } }
@SuppressWarnings({ "rawtypes", "unchecked" }) public List<ExcelModelDetail> findExcelModelDetailByModelId(String modelId) throws Exception { DetachedCriteria detachedCriteria = DetachedCriteria.forClass(ExcelModelDetail.class, "m"); detachedCriteria.add(Restrictions.eq("excelModelId", modelId)); detachedCriteria.addOrder(Order.asc("excelColumn")); List list = findByCriteria(detachedCriteria); return list; }