List of usage examples for org.hibernate.criterion Restrictions sqlRestriction
public static Criterion sqlRestriction(String sql)
From source file:com.sccl.attech.modules.sys.service.DictService.java
License:Open Source License
public List<Dict> findChildren(String id) { DetachedCriteria dc = dictDao.createDetachedCriteria(); dc.add(Restrictions.sqlRestriction("parent_id = '" + id + "'"));//?id? return dictDao.find(dc); }
From source file:com.sccl.attech.modules.sys.service.DictService.java
License:Open Source License
/** * /*from www.jav a 2 s. c om*/ * param dictID? * dict type? */ public List<AllTreeVo> getTreeList(Dict dict, String companyId) { List<Dict> list = null; DetachedCriteria dc = dictDao.createDetachedCriteria(); if (!"".equals(StrUtils.null2String(dict.getType()))) { dc.add(Restrictions.eq("type", dict.getType())); } if (!"".equals(StrUtils.null2String(dict.getId()))) { // dc.add(Restrictions.eq("parent", dict)); dc.add(Restrictions.sqlRestriction("parent_id = '" + dict.getId() + "'")); } else { // dc.add(Restrictions.isNull("parent")); dc.add(Restrictions.sqlRestriction("parent_id is null")); } dc.add(Restrictions.or(Restrictions.isNull("companyId"), Restrictions.eq("companyId", "0"), Restrictions.eq("companyId", StrUtils.null2String(companyId)))); dc.add(Restrictions.eq("delFlag", "0")); list = dictDao.find(dc); List<AllTreeVo> listAllTreeVos = new ArrayList<AllTreeVo>(); if (null != list && list.size() > 0) { for (Dict dicts : list) { AllTreeVo allTreeVo = new AllTreeVo(); allTreeVo.setLabel(dicts.getLabel()); allTreeVo.setId(dicts.getId()); //?? List<Dict> dictChildren = findChildren(dicts.getId());//?id? // if(null != dicts.getChildren() && dicts.getChildren().size() > 0){ // allTreeVo.setHasChild(true); // } if (null != dictChildren && dictChildren.size() > 0) {//????? allTreeVo.setHasChild(true); } listAllTreeVos.add(allTreeVo); } } return listAllTreeVos; }
From source file:com.sccl.attech.modules.sys.service.GroupService.java
License:Open Source License
public Page<Grouping> findGroup(Page<Grouping> page, Grouping group) { DetachedCriteria dc = groupDao.createDetachedCriteria(); dc.add(Restrictions.sqlRestriction("del_flag=0")); return groupDao.find(page, dc); }
From source file:com.segundo.piso.daos.impl.DAOAttendenceImpl.java
private void addFilters(Filters filters, Criteria criteria) { if (filters.getClases() > 0) { criteria.add(Restrictions.eq("idClase.id", filters.getClases())); }/*from ww w .ja va 2s.c o m*/ if (filters.getFechaInicio() != null) { String fechaInicio = DateUtil.formatDate(filters.getFechaInicio(), DateUtil.YYYY_MM_DD_HH_MM_SS); criteria.add(Restrictions.sqlRestriction("DATE(fecha) >= '" + fechaInicio + "' ")); } if (filters.getFechaFin() != null) { String fechaFin = DateUtil.formatDate(filters.getFechaFin(), DateUtil.YYYY_MM_DD_HH_MM_SS); criteria.add(Restrictions.sqlRestriction("DATE(fecha) <= '" + fechaFin + "' ")); } if (filters.getMaestro() > 0) { criteria.add(Restrictions.eq("idMaestro.id", filters.getMaestro())); } if (filters.getAlumno() > 0) { criteria.add(Restrictions.eq("idAlumno.id", filters.getAlumno())); } }
From source file:com.segundo.piso.daos.impl.DAOReportImpl.java
@Override @Transactional//from w ww . ja v a 2 s . c om public List<ReporteAlumno> getStudentsByExpiredMovement(int clasesRestantes) { System.out.println(sessionFactory); StringBuilder restriction = new StringBuilder(); restriction.append("date_add(movimiento1_.fecha_inicio, interval 31 day) > curdate() ").append( "and date_add(movimiento1_.fecha_inicio, interval 31 day) < date_add(current_date(), interval 10 day)") .append("and movimiento1_.id_movimiento = asistencia2_.id_movimiento "); return this.sessionFactory.getCurrentSession().createCriteria(Alumno.class, "alumno") .createAlias("alumno.movimientoList", "movimiento") .createAlias("alumno.asistenciaList", "asistencia").createAlias("movimiento.idEvento", "evento") .setProjection(Projections.projectionList().add(Projections.property("alumno.codigo"), "codigo") .add(Projections.property("alumno.nombre"), "nombre") .add(Projections.min("asistencia.diasRestantes"), "clasesRestantes") .add(Projections.max("movimiento.idMovimiento")) .add(Projections.property("alumno.idAlumno"), "idAlumno") .add(Projections.max("movimiento.fechaInicio"), "fecha") .add(Projections.groupProperty("alumno.idAlumno"))) .add(Restrictions.sqlRestriction(restriction.toString())) .add(Restrictions.eq("movimiento.activo", true)).add(Restrictions.gt("evento.diasMes", 1)) .setResultTransformer(Transformers.aliasToBean(ReporteAlumno.class)) .addOrder(Order.desc("asistencia.diasRestantes")).list(); }
From source file:com.segundo.piso.daos.impl.DAOReportImpl.java
private void addFilters(Filters filters, Criteria criteria) { if (filters.getClases() > 0) { criteria.add(Restrictions.eq("idClase.id", filters.getClases())); }/*from w w w . ja v a2s. c o m*/ if (filters.getFechaInicio() != null) { String fechaInicio = DateUtil.formatDate(filters.getFechaInicio(), DateUtil.YYYY_MM_DD_HH_MM_SS); criteria.add(Restrictions.sqlRestriction("DATE(fecha) >= '" + fechaInicio + "' ")); } if (filters.getFechaFin() != null) { String fechaFin = DateUtil.formatDate(filters.getFechaFin(), DateUtil.YYYY_MM_DD_HH_MM_SS); criteria.add(Restrictions.sqlRestriction("DATE(fecha) <= '" + fechaFin + "' ")); } if (filters.getMaestro() > 0) { criteria.add(Restrictions.eq("idMaestro.id", filters.getMaestro())); } }
From source file:com.selfsoft.baseinformation.service.impl.TbCarInfoServiceImpl.java
public List<TbCarInfo> findByTbCarInfo(TbCarInfo tbCarInfo) { DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TbCarInfo.class); if (null != tbCarInfo) { if (null != tbCarInfo.getId()) { detachedCriteria.add(Restrictions.eq("id", tbCarInfo.getId())); }/*from w w w. j a v a 2s.c om*/ if (null != tbCarInfo.getLicenseCode() && !"".equals(tbCarInfo.getLicenseCode())) { //? detachedCriteria.add(Restrictions.like("licenseCode", "%" + tbCarInfo.getLicenseCode() + "%")); } if (null != tbCarInfo.getInsureCardCode() && !"".equals(tbCarInfo.getInsureCardCode())) { detachedCriteria .add(Restrictions.like("insureCardCode", "%" + tbCarInfo.getInsureCardCode() + "%")); } if (null != tbCarInfo.getTmCarModelType()) { detachedCriteria.createAlias("tmCarModelType", "tmCarModelType"); if (null != tbCarInfo.getTmCarModelType().getId()) { detachedCriteria .add(Restrictions.eq("tmCarModelType.id", tbCarInfo.getTmCarModelType().getId())); } } if (null != tbCarInfo.getTbCustomer()) { detachedCriteria.createAlias("tbCustomer", "tbCustomer"); if (null != tbCarInfo.getTbCustomer().getId()) { detachedCriteria.add(Restrictions.eq("tbCustomer.id", tbCarInfo.getTbCustomer().getId())); } if (null != tbCarInfo.getTbCustomer().getCustomerCode()) { detachedCriteria.add(Restrictions.like("tbCustomer.customerCode", "%" + tbCarInfo.getTbCustomer().getCustomerCode() + "%")); } if (null != tbCarInfo.getTbCustomer().getCustomerName()) { detachedCriteria.add(Restrictions.like("tbCustomer.customerName", "%" + tbCarInfo.getTbCustomer().getCustomerName() + "%")); } if (null != tbCarInfo.getTbCustomer().getTelephone()) { detachedCriteria.add(Restrictions.like("tbCustomer.telephone", "%" + tbCarInfo.getTbCustomer().getTelephone() + "%")); } } if (StringUtils.isNotBlank(tbCarInfo.getBeginLicenseDate())) { detachedCriteria.add(Restrictions.ge("licenseDate", Date.valueOf(tbCarInfo.getBeginLicenseDate()))); } if (StringUtils.isNotBlank(tbCarInfo.getEndLicenseDate())) { detachedCriteria.add(Restrictions.le("licenseDate", Date.valueOf(tbCarInfo.getEndLicenseDate()))); } if (StringUtils.isNotBlank(tbCarInfo.getBeginPurchaseDate())) { detachedCriteria .add(Restrictions.ge("purchaseDate", Date.valueOf(tbCarInfo.getBeginPurchaseDate()))); } if (StringUtils.isNotBlank(tbCarInfo.getEndPurchaseDate())) { detachedCriteria.add(Restrictions.le("purchaseDate", Date.valueOf(tbCarInfo.getEndPurchaseDate()))); } if (StringUtils.isNotBlank(tbCarInfo.getChassisCode())) { detachedCriteria.add(Restrictions.like("chassisCode", "%" + tbCarInfo.getChassisCode() + "%")); } if (tbCarInfo.getCarProperty() != null) { detachedCriteria.add(Restrictions.eq("carProperty", tbCarInfo.getCarProperty())); } if (StringUtils.isNotBlank(tbCarInfo.getLicenseMonth())) { detachedCriteria .add(Restrictions.sqlRestriction("month(LICENSE_DATE)=" + tbCarInfo.getLicenseMonth())); } if (tbCarInfo.getMaxKilo() != null && tbCarInfo.getMinKilo() != null) { detachedCriteria.add(Restrictions.between("kilo", tbCarInfo.getMinKilo(), tbCarInfo.getMaxKilo())); } } return tbCarInfoDao.findByCriteria(detachedCriteria, tbCarInfo); }
From source file:com.tripad.cootrack.erpCommon.upload.TMC_UpdateBusinessPartner.java
public BaseOBObject updateDataBPartner(final String organization, //rowOrganization final String sKey, final String commercialName, final String alamat, final String kota, final String negara, final String kodePos, final String phoneCompany, final String fax, final String priceList, final String paymentmethod, final String paymentTerm, final String financialAccount, final String firstName, final String lastName, final String email, final String phone ) throws Exception { SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); //Customer : C_BPartner - cuma 1 record //Location : C_BPartner_Location - multiple //Contact : AD_USER - multiple final OBCriteria<BusinessPartner> businessPartnerCriteria = OBDal.getInstance() .createCriteria(BusinessPartner.class); businessPartnerCriteria.add(Restrictions.eq(BusinessPartner.PROPERTY_SEARCHKEY, sKey)); //businessPartnerCriteria.add(Restrictions.eq(BusinessPartner.PROPERTY_CLIENT, OBContext.getOBContext().getCurrentClient())); businessPartnerCriteria// w w w .j a v a2s.c o m .add(Restrictions.eq(BusinessPartner.PROPERTY_CREATEDBY, OBContext.getOBContext().getUser())); if (businessPartnerCriteria.list().isEmpty()) { throw new OBException("BusinessPartner Not Found ! (" + sKey + ")"); } for (BusinessPartner businessPartner : businessPartnerCriteria.list()) { businessPartnerData = businessPartner; businessPartnerData.setName(commercialName); //Customer if (isEdit(priceList)) { PriceList priceListExist = findDALInstance(false, PriceList.class, new Value(PriceList.PROPERTY_NAME, priceList)); if (priceListExist == null) { throw new OBException("Price List \"" + priceList + "\" doesn't exists"); } businessPartnerData.setPriceList(priceListExist); } else { businessPartnerData.setPriceList(null); } if (isEdit(paymentmethod)) { FIN_PaymentMethod paymentmethodExist = findDALInstance(false, FIN_PaymentMethod.class, new Value(FIN_PaymentMethod.PROPERTY_NAME, paymentmethod)); if (paymentmethodExist == null) { throw new OBException("Payment Method \"" + paymentmethod + "\" doesn't exists"); } businessPartnerData.setPaymentMethod(paymentmethodExist); } else { businessPartnerData.setPaymentMethod(null); } if (isEdit(paymentTerm)) { PaymentTerm paymentTermExist = findDALInstance(false, PaymentTerm.class, new Value(PaymentTerm.PROPERTY_SEARCHKEY, paymentTerm)); if (paymentTermExist == null) { throw new OBException("Payment Term \"" + paymentTerm + "\" doesn't exists"); } businessPartnerData.setPaymentTerms(paymentTermExist); } else { businessPartnerData.setPaymentTerms(null); } if (isEdit(financialAccount)) { FIN_FinancialAccount accountExist = findDALInstance(false, FIN_FinancialAccount.class, new Value(FIN_FinancialAccount.PROPERTY_NAME, financialAccount)); if (accountExist == null) { throw new OBException("Financial Account \"" + financialAccount + "\" doesn't exists"); } businessPartnerData.setAccount(accountExist); } else { businessPartnerData.setAccount(null); } //Country countryExist = null; Country countryExist = findDALInstance(false, Country.class, new Value(Country.PROPERTY_NAME, WordUtils.capitalizeFully(negara.trim()))); if (countryExist == null) { throw new OBException("Country \"" + negara.trim() + "\" doesn't exists"); } //} OBCriteria<Location> locationBpCrit = OBDal.getInstance().createCriteria(Location.class); locationBpCrit.add(Restrictions.eq(Location.PROPERTY_CREATEDBY, OBContext.getOBContext().getUser())); locationBpCrit .add(Restrictions.eq(Location.PROPERTY_NAME, getBPLocationName(kota.trim(), alamat.trim()))); locationBpCrit.add(Restrictions.eq(Location.PROPERTY_BUSINESSPARTNER, businessPartnerData)); if (locationBpCrit.list().isEmpty()) { //check apakah Bisnis Partner location dengan nama yg sama sudah ada ? samakan yg alama dengan excel : buat baru locationBpartnerData = OBProvider.getInstance().get(Location.class); locationBpartnerData.setActive(true); OBCriteria<org.openbravo.model.common.geography.Location> locationCrit = OBDal.getInstance() .createCriteria(org.openbravo.model.common.geography.Location.class); locationCrit.add(Restrictions.eq(org.openbravo.model.common.geography.Location.PROPERTY_CREATEDBY, OBContext.getOBContext().getUser())); locationCrit.add(Restrictions .sqlRestriction("UPPER(TRIM(address1)) = UPPER(TRIM('" + alamat.trim() + "'))"));//eq(org.openbravo.model.common.geography.Location.PROPERTY_ADDRESSLINE1, alamat)); locationCrit .add(Restrictions.sqlRestriction("UPPER(TRIM(city)) = UPPER(TRIM('" + kota.trim() + "'))"));//locationCrit.add(Restrictions.eq(org.openbravo.model.common.geography.Location.PROPERTY_CITYNAME, kota)); locationCrit.add( Restrictions.sqlRestriction("UPPER(TRIM(postal)) = UPPER(TRIM('" + kodePos.trim() + "'))")); locationCrit.add(Restrictions.eq(org.openbravo.model.common.geography.Location.PROPERTY_COUNTRY, countryExist)); if (locationCrit.list().isEmpty()) { //check apakah Location dengan alamat di atas sudah ada ? : update yg lama, samakan dengan excel : buat baru locationData = OBProvider.getInstance() .get(org.openbravo.model.common.geography.Location.class); locationData.setActive(true); locationData.setAddressLine1(alamat.trim()); locationData.setCityName(kota.trim()); locationData.setCountry(countryExist); locationData.setPostalCode(kodePos.trim()); OBDal.getInstance().save(locationData); } else { locationData = locationCrit.list().get(0); locationData.setAddressLine1(alamat.trim()); locationData.setCityName(kota.trim()); locationData.setCountry(countryExist); locationData.setPostalCode(kodePos.trim()); } if (locationData != null) { locationBpartnerData.setLocationAddress(locationData); } else { throw new OBException("Error : locationData variable is null"); } locationBpartnerData.setBusinessPartner(businessPartnerData); locationBpartnerData.setName(getBPLocationName(kota.trim(), alamat.trim())); locationBpartnerData.setPhone(phoneCompany); locationBpartnerData.setFax(fax); OBDal.getInstance().save(locationBpartnerData); } else { for (Location locBPExisting : locationBpCrit.list()) { //for (org.openbravo.model.common.geography.Location locExisting : locBPExisting.getLocationAddress().getBusinessPartnerLocationList()) { locBPExisting.getLocationAddress().setAddressLine1(alamat.trim()); locBPExisting.getLocationAddress().setCityName(kota.trim()); locBPExisting.getLocationAddress().setCountry(countryExist); locBPExisting.getLocationAddress().setPostalCode(kodePos.trim()); //locBPExisting.setBusinessPartner(businessPartnerData); locBPExisting.setName(getBPLocationName(kota.trim(), alamat.trim())); locBPExisting.setPhone(phoneCompany); locBPExisting.setFax(fax); OBDal.getInstance().save(locBPExisting); //} } } //Contact OBCriteria<User> contactCrit = OBDal.getInstance().createCriteria(User.class); contactCrit.add(Restrictions.eq(User.PROPERTY_CREATEDBY, OBContext.getOBContext().getUser())); contactCrit.add(Restrictions.eq(User.PROPERTY_BUSINESSPARTNER, businessPartnerData)); contactCrit.add(Restrictions .sqlRestriction("UPPER(TRIM(firstname)) = UPPER(TRIM('" + firstName.trim() + "'))")); contactCrit.add( Restrictions.sqlRestriction("UPPER(TRIM(lastname)) = UPPER(TRIM('" + lastName.trim() + "'))")); contactCrit .add(Restrictions.sqlRestriction("UPPER(TRIM(email)) = UPPER(TRIM('" + email.trim() + "'))")); contactCrit .add(Restrictions.sqlRestriction("UPPER(TRIM(phone)) = UPPER(TRIM('" + phone.trim() + "'))")); if (contactCrit.list().isEmpty()) { //bila kosong / blm ada sebelumnya ? buat baru : edit yg lama, sesuaikan dengan excel contactData = OBProvider.getInstance().get(User.class); contactData.setActive(true); contactData.setFirstName(firstName.trim()); contactData.setLastName(lastName.trim()); contactData.setEmail(email.trim()); contactData.setPhone(phone.trim()); contactData.setName(firstName.trim() + " " + lastName.trim()); contactData.setBusinessPartner(businessPartnerData); OBDal.getInstance().save(contactData); } else { for (User existingUser : contactCrit.list()) { existingUser.setFirstName(firstName.trim()); existingUser.setLastName(lastName.trim()); existingUser.setEmail(email.trim()); existingUser.setPhone(phone.trim()); existingUser.setName(firstName.trim() + " " + lastName.trim()); OBDal.getInstance().save(existingUser); } } //sHRLeaveEncash = OBProvider.getInstance().get(SHRLeaveEncash.class); //sHRLeaveEncash.setActive(true); OBDal.getInstance().save(businessPartnerData); OBDal.getInstance().flush(); } return businessPartnerData; }
From source file:com.tysanclan.site.projectewok.entities.dao.hibernate.UserDAOImpl.java
License:Open Source License
/** * @see com.tysanclan.site.projectewok.dataaccess.EwokHibernateDAO#createCriteria(com.tysanclan.site.projectewok.dataaccess.SearchFilter) *//*w w w .j a v a 2 s . co m*/ @Override protected Criteria createCriteria(SearchFilter<User> filter) { Criteria criteria = getSession().createCriteria(User.class); if (filter instanceof UserFilter) { UserFilter userFilter = (UserFilter) filter; if (userFilter.getGroup() != null) { criteria.createCriteria("groups").add(Restrictions.eq("group_id", userFilter.getGroup().getId())); } if (userFilter.getUsername() != null) { Criterion eq = Restrictions.eq("username", userFilter.getUsername()); if (eq instanceof SimpleExpression) { eq = ((SimpleExpression) eq).ignoreCase(); } criteria.add(eq); } if (userFilter.getRanks() != null) { criteria.add(Restrictions.in("rank", userFilter.getRanks())); } if (userFilter.getPassword() != null) { criteria.add(Restrictions.eq("password", userFilter.getPassword())); } if (userFilter.getActiveSince() != null) { criteria.add(Restrictions.ge("lastAction", userFilter.getActiveSince())); } if (userFilter.getActiveBefore() != null) { criteria.add(Restrictions.lt("lastAction", userFilter.getActiveBefore())); } if (userFilter.getEmail() != null) { criteria.add(Restrictions.eq("eMail", userFilter.getEmail())); } if (userFilter.getRetired() != null) { criteria.add(Restrictions.eq("retired", userFilter.getRetired())); } if (userFilter.getVacation() != null) { criteria.add(Restrictions.eq("vacation", userFilter.getVacation())); } if (userFilter.getRealm() != null) { Criteria sc = criteria.createCriteria("playedGames"); sc.add(Restrictions.eq("realm", userFilter.getRealm())); } if (userFilter.getBugReportMaster() != null) { criteria.add(Restrictions.eq("bugReportMaster", userFilter.getBugReportMaster())); } if (userFilter.getTruthsayerNominated() != null) { List<TruthsayerNomination> nominated = truthsayerNominationDAO.findAll(); Set<Long> userids = new HashSet<Long>(); for (TruthsayerNomination nomination : nominated) { userids.add(nomination.getUser().getId()); } if (userFilter.getTruthsayerNominated()) { criteria.add(userids.isEmpty() ? Restrictions.sqlRestriction(" 1 = 2") : Restrictions.in("id", userids)); } else { if (!userids.isEmpty()) { criteria.add(Restrictions.not(Restrictions.in("id", userids))); } } } } return criteria; }
From source file:com.viettel.vsaadmin.database.DAOHibernate.DepartmentDAOHE.java
License:Open Source License
/** * * @return// w w w .ja va2 s. co m */ public List<Department> getParentDeptForTree(Boolean isCheckStatus) { Criterion[] criterion = new Criterion[3]; criterion[0] = Restrictions.isNull("parentId"); if (isCheckStatus) { criterion[1] = Restrictions.eq("status", 1L); } else { criterion[1] = Restrictions.isNotNull("deptId"); } criterion[2] = Restrictions .sqlRestriction(" 1 = 1 order by nlssort(lower({alias}.DEPT_NAME),'nls_sort = Vietnamese') "); return this.findByCriteria(0, -1, criterion); }