List of usage examples for org.hibernate.criterion Restrictions not
public static Criterion not(Criterion expression)
From source file:com.tony.DaoImpl.UsuarioInternoImpl.java
@Override public List<Usuario_interno> All_usuarios_internos(Usuario_interno Usuario_gerente, int inicio, int Final) { EntityManager em = Entidad.getEntidad().getEntidadManager(); List<Usuario_interno> user_internos = null; Session s = null;//from w w w . j a v a2 s.c om try { em.getTransaction().begin(); s = (Session) em.getDelegate(); Usuario_interno UsergerenteEntity = em.find(Usuario_interno.class, Usuario_gerente.getId_persona()); if (UsergerenteEntity.getPerfil().getTipoPerfil() .compareTo(Tipo_Perfil_UsuarioInterno.Administrador) == 0) { user_internos = (List<Usuario_interno>) s.createCriteria(Usuario_interno.class) .add(Restrictions.not(Restrictions.idEq(Usuario_gerente.getId_persona()))) .createAlias("area", "areatotal").setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) .add(Restrictions.eq("areatotal.tipoArea", UsergerenteEntity.getArea().getTipoArea())) .createAlias("perfil", "perfiluser").setResultTransformer(Criteria.ROOT_ENTITY) .add(Restrictions.eq("perfiluser.tipoPerfil", Tipo_Perfil_UsuarioInterno.Profesional)) .setFirstResult(inicio).list(); } em.getTransaction().commit(); System.out.println(user_internos); } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } System.out.println("Error en mensaje All_usuarios_internos" + e.getMessage()); } finally { em.close(); } return user_internos; }
From source file:com.tripad.cootrack.utility.ResponseResultToDB.java
public void validateBPList(JSONObject hasilRetrieve, Category bpCatParam, ArrayList<String> tempIdDataServerParam, ArrayList<String> tempImeiServerParam) throws Exception, OBException, JSONException, CustomJsonErrorResponseException, Throwable { //System.out.println("terpanggil"); ArrayList<String> tempIdDataServer = null; ArrayList<String> tempImeiServer = null; Category bpCat = null;//from ww w. j a v a 2s .co m BusinessPartner rootBP = null; ArrayList<BusinessPartner> validBP = null; //cek apakah hasil pemanggilan rekursif?, bila iya maka set variable arraylist berdasarkan nilai sebelumnya if (tempIdDataServerParam == null) { tempIdDataServer = new ArrayList<String>(); //bila null / pemanggilan pertama pada method ini, inialisasi BP untuk root user rootBP = validateRootBP(hasilRetrieve); if (rootBP == null) throw new Throwable("Error Validate Root BP"); tempIdDataServer.add(rootBP.getTmcOpenapiIdent()); //end c1 } else { tempIdDataServer = tempIdDataServerParam; } if (tempImeiServerParam == null) { tempImeiServer = new ArrayList<String>(); } else { tempImeiServer = tempImeiServerParam; } ArrayList<HashMap<JSONObject, Category>> tempChildJsonObject = new ArrayList<HashMap<JSONObject, Category>>(); //debug // if (bpCatParam != null) { // System.out.println("Parent : " + bpCatParam.getName()); // } //System.out.println("Awal :h " + hasilRetrieve.toString()); JSONArray childList = (JSONArray) hasilRetrieve.get("children"); String rslt = ""; OBCriteria<BusinessPartner> tmcListChildAcc = null; // OBCriteria<TmcListChildAcc> tmcNotExsListChildAcc = null; // var mobil JSONObject hasilTarget; JSONArray carList; for (int i = 0; i < childList.length(); i++) { String id = childList.getJSONObject(i).get("id").toString(); String name = childList.getJSONObject(i).get("name").toString(); String showname = childList.getJSONObject(i).get("showname").toString(); tmcListChildAcc = OBDal.getInstance().createCriteria(BusinessPartner.class); if (ISBYVALUE) { tmcListChildAcc.add(Restrictions.eq(BusinessPartner.PROPERTY_SEARCHKEY, name)); } else { tmcListChildAcc.add(Restrictions.eq(BusinessPartner.PROPERTY_TMCOPENAPIIDENT, id)); } tmcListChildAcc.add(Restrictions.eq(BusinessPartner.PROPERTY_CREATEDBY, COOTRACK_USER)); //Pembuatan Business Partner Criteria if (bpCatParam == null) { //pakai nama dari AD_User //panggil method pembuat bp cat //System.out.println("dari null"); bpCat = getBPCategory(COOTRACK_USER.getName(), COOTRACK_USER.getUsername()); } else { bpCat = bpCatParam; } if (tmcListChildAcc.list().isEmpty()) { // bila tidak ada maka insert BusinessPartner newBusinessPartner = OBProvider.getInstance().get(BusinessPartner.class); newBusinessPartner.setActive(true); newBusinessPartner.setTmcOpenapiIdent(id); // newBusinessPartner.setTmcOpenapiUser(name); newBusinessPartner.setSearchKey(name); newBusinessPartner.setName(showname); //tambah isTmcIsexpired = false karena ini baru newBusinessPartner.setTmcIsexpired(false); newBusinessPartner.setConsumptionDays(Long.getLong("0")); newBusinessPartner.setCreditLimit(BigDecimal.ZERO); newBusinessPartner.setBusinessPartnerCategory(bpCat); OBDal.getInstance().save(newBusinessPartner); //OBDal.getInstance().flush(); // get car list hasilTarget = utils.requestListChildAccount(name); //di rubah jadi pakai method tempImeiServer = validateCar(hasilTarget, newBusinessPartner); } else { // bila BP SUdah adaa, maka edit tmcListChildAcc.list().get(0).setTmcOpenapiIdent(id); tmcListChildAcc.list().get(0).setSearchKey(name); //edit : komen line di bawah, untuk memenuhi syarat BP yg namenya di edit, namanya tidak ikut server cootrack // tmcListChildAcc.list().get(0).setName(showname); //tambah isTmcIsexpired = false karena ini update, dan menyatakan bahwa bp ini sinkron (ada di server) tmcListChildAcc.list().get(0).setTmcIsexpired(false); tmcListChildAcc.list().get(0).setBusinessPartnerCategory(bpCat); OBDal.getInstance().save(tmcListChildAcc.list().get(0)); //OBDal.getInstance().flush(); // edit line hasilTarget = utils.requestListChildAccount(name); //di rubah jadi pakai method tempImeiServer = validateCar(hasilTarget, tmcListChildAcc.list().get(0)); //System.out.println("Jumlah line car : "+tempImeiServer.size()+", BP : "+tmcListChildAcc.list().get(0).getName()); // adegan menghapus LINE Bila tidak ada yg seragam if (tempImeiServer.size() > 0) { OBCriteria<TmcCar> tmcListCarRemove = OBDal.getInstance().createCriteria(TmcCar.class); tmcListCarRemove.add(Restrictions.eq(TmcCar.PROPERTY_BPARTNER, tmcListChildAcc.list().get(0))); tmcListCarRemove.add(Restrictions.eq(TmcCar.PROPERTY_CREATEDBY, COOTRACK_USER)); tmcListCarRemove.add(Restrictions.not(Restrictions.in(TmcCar.PROPERTY_IMEI, tempImeiServer))); for (TmcCar removeRecord : tmcListCarRemove.list()) { for (TmcDocumentUpdateLine tmcListChildCar : removeRecord.getTmcDocumentUpdateLineList()) { OBDal.getInstance().remove(tmcListChildCar); //OBDal.getInstance().flush(); } OBDal.getInstance().remove(removeRecord); //OBDal.getInstance().flush(); } } //end check jumlah banyaknya line } tempIdDataServer.add(id); // cek apakah dia punya anak lagi ? try { JSONArray childListChild = (JSONArray) hasilTarget.get("children"); if (childListChild.length() > 0) { //validateBPList(hasilTarget);s // System.out.println("ANAK : "+hasilTarget.toString()); HashMap<JSONObject, Category> map = new HashMap<JSONObject, Category>(); Category passingCategory = getBPCategory(showname, name); System.out.println("CAT : " + passingCategory.getName()); map.put(hasilTarget, passingCategory); tempChildJsonObject.add(map); } } catch (JSONException jex) { System.out.println("Jex1 : " + hasilTarget.toString()); //skip, berarti tidak punya anak System.out.println("Jex1 : " + jex.getMessage()); } /*catch (Throwable t) { //skip, berarti tidak punya anak System.out.println("Err1 : "+t.getMessage()); }*/ //Though, mungkin setiap JSONObject (hasilTarget) yg memiliki children, di simpan dulu //di ArrayList, lalu di eksekusi setelah tahap adegan menghapus record } //end loop utama //end flush mungkin OBDal.getInstance().flush(); System.out.println("End akhir : "); /* @Deprecated // adegan menghapus record yg ada di local tapi tidak ada di server open api ||Jangan LUPA // DELETE LINENYA DULU // header tmcListChildAcc = OBDal.getInstance().createCriteria(BusinessPartner.class); tmcListChildAcc.add(Restrictions .not(Restrictions.in(BusinessPartner.PROPERTY_TMCOPENAPIIDENT, tempIdDataServer))); // tmcListChildAcc.add(Restrictions.eq(BusinessPartner.PROPERTY_CREATEDBY, COOTRACK_USER)); tmcListChildAcc.add(Restrictions.eq(BusinessPartner.PROPERTY_ACTIVE, true)); tmcListChildAcc.add(Restrictions.eq(BusinessPartner.PROPERTY_BUSINESSPARTNERCATEGORY, bpCat)); for (BusinessPartner removeRecord : tmcListChildAcc.list()) { for (TmcCar removeLine : removeRecord.getTmcCarList()) { for (TmcDocumentUpdateLine tmcListChildCar : removeLine.getTmcDocumentUpdateLineList()) { OBDal.getInstance().remove(tmcListChildCar); } OBDal.getInstance().remove(removeLine); } OBDal.getInstance().remove(removeRecord); } /* end delete bp yg nga ada @Deprecated */ //get child from child try { //JSONArray childListChild = (JSONArray) hasilTarget.get("children"); //System.out.println("tempChildJsonObject : "+tempChildJsonObject.size()); for (HashMap<JSONObject, Category> map : tempChildJsonObject) { for (Map.Entry<JSONObject, Category> entry : map.entrySet()) { // System.out.println("hasilTarget : "+entry.getKey().toString()); validateBPList(entry.getKey(), entry.getValue(), tempIdDataServer, tempImeiServer); } } } catch (JSONException jex) { //skip, berarti tidak punya anak //System.out.println("Jex2 : "+hasilTarget.toString()); System.out.println("Jex2 : " + jex.getMessage()); /* */ } /*catch (Throwable t) { //skip, berarti tidak punya anak System.out.println("Err2 : "+t.getMessage()); }*/ //Revisi Commit pada get BPartner // OBDal.getInstance().flush(); // OBDal.getInstance().commitAndClose(); }
From source file:com.tripad.cootrack.utility.ResponseResultToDB.java
public void validateCarStatusList(String header_id, JSONObject hasilRetrieve) throws Exception, OBException, JSONException, Throwable, CustomJsonErrorResponseException { List<String> tempValidDocumentUpdateLine = new ArrayList<String>(); JSONArray carList = (JSONArray) hasilRetrieve.get("data"); // OBCriteria<TmcListChildAcc> tmcNotExsListChildAcc = null; for (int i = 0; i < carList.length(); i++) { String imei = carList.getJSONObject(i).get("imei").toString(); String device_info = carList.getJSONObject(i).get("device_info").toString(); // String gps_time = carList.getJSONObject(i).get("gps_time").toString(); String sys_time = carList.getJSONObject(i).get("sys_time").toString(); String heart_time = carList.getJSONObject(i).get("heart_time").toString(); String server_time = carList.getJSONObject(i).get("server_time").toString(); // String lng = carList.getJSONObject(i).get("lng").toString(); // String lat = carList.getJSONObject(i).get("lat").toString(); // String course = carList.getJSONObject(i).get("course").toString(); String speed = carList.getJSONObject(i).get("speed").toString(); // String acc = carList.getJSONObject(i).get("acc").toString(); // String acc_seconds = carList.getJSONObject(i).get("acc_seconds").toString(); // String seconds = carList.getJSONObject(i).get("seconds").toString(); //ini ACC 0 = OFF, 1= ? , empty / -1 = Expired String aCC = ""; try {// w w w . ja v a 2s . c o m if (carList.getJSONObject(i).has("acc")) { aCC = carList.getJSONObject(i).get("acc").toString(); } } catch (JSONException z) { aCC = ""; } //System.out.println("Fase 1/4 : "+imei); OBCriteria<TmcCar> tmcCarCriteria = OBDal.getInstance().createCriteria(TmcCar.class); tmcCarCriteria.add(Restrictions.eq(TmcCar.PROPERTY_IMEI, imei)); //filter dari bp yg is expirednya tidak di centang /* OBCriteria<BusinessPartner> bpNotExpiredCrit = OBDal.getInstance().createCriteria(BusinessPartner.class); bpNotExpiredCrit.add(Restrictions.eq(BusinessPartner.PROPERTY_ISEXPIRED, false)); tmcCarCriteria.add(Restrictions.eq(TmcCar.PROPERTY_BPARTNER, imei));*/ //[TMC_CAR tanpa filter created by 1/2] tmcCarCriteria.add(Restrictions.eq(TmcCar.PROPERTY_CREATEDBY, COOTRACK_USER)); if (tmcCarCriteria.count() > 0) { // bila ada maka data tersebut sinkron, tinggal tentukan if (!tmcCarCriteria.list().get(0).getBpartner().isTmcIsexpired()) { //System.out.println("Fase 2/4"); // update atau insert // perhitungan status disini String statusCategory = ""; int hourInterval = utils.getIntervalFromUnix(Long.parseLong(sys_time.trim()), Long.parseLong(server_time.trim()), "hours"); // int minInterval = new OpenApiUtils().getIntervalFromUnix(Long.parseLong(sys_time.trim()), // Long.parseLong(server_time.trim()), "minutes"); int dayInterval = utils.getIntervalFromUnix(Long.parseLong(sys_time.trim()), Long.parseLong(server_time.trim()), "days"); int heartDayInterval = utils.getIntervalFromUnix(Long.parseLong(heart_time.trim()), Long.parseLong(server_time.trim()), "days"); int nearExpired = utils.getIntervalFromUnix(Long.parseLong(server_time.trim()), tmcCarCriteria.list().get(0).getOUTTime(), "days"); if ((server_time.trim()).equals("0")) { nearExpired = -1; } //System.out.println("Fase 3/4"); //debug imei 864717003511874 // System.out.println("IMEI & Expired : "+imei+" & "+nearExpired); // if (imei.equals("868120100610069")) { // //System.out.println("Server time & get out TIME : "+server_time.trim()+" & "+tmcCarCriteria.list().get(0).getOUTTime()); // System.out.println("IMEI & heart day : "+imei+" & "+heartDayInterval); // } //System.out.println("IMEI & Expired : "+imei+" & "+nearExpired); statusCategory = getStatusCategory(device_info, dayInterval, heartDayInterval, hourInterval, speed, nearExpired); aCC = getStatusAcc(aCC); //System.out.println("Fase 4/4 "+aCC); //modify baru [Historical 2/4 ] //cek statusCategory ada atau tidak if (statusCategory != null) { TmcDocumentUpdate header = getHeaderInstance(header_id); OBCriteria<TmcDocumentUpdateLine> tmcDocumentUpdateLine = OBDal.getInstance() .createCriteria(TmcDocumentUpdateLine.class); tmcDocumentUpdateLine .add(Restrictions.eq(TmcDocumentUpdateLine.PROPERTY_CREATEDBY, COOTRACK_USER)); tmcDocumentUpdateLine.add(Restrictions.eq(TmcDocumentUpdateLine.PROPERTY_TMCCAR, tmcCarCriteria.list().get(0))); if (tmcDocumentUpdateLine.list().isEmpty()) { // data belum ada // ini insert TmcDocumentUpdateLine newTmcDocumentUpdateLine = OBProvider.getInstance() .get(TmcDocumentUpdateLine.class); newTmcDocumentUpdateLine.setActive(true); newTmcDocumentUpdateLine.setTMCDocumentupdate(header);// set header nya newTmcDocumentUpdateLine.setCustomerName(tmcCarCriteria.list().get(0).getBpartner()); //Tambahan Sementara Bisnis partner kategori, karena computed column tidak dapat filter dropdown newTmcDocumentUpdateLine.setBpGroup( tmcCarCriteria.list().get(0).getBpartner().getBusinessPartnerCategory()); newTmcDocumentUpdateLine.setTMCCar(tmcCarCriteria.list().get(0)); newTmcDocumentUpdateLine.setStatus(statusCategory); newTmcDocumentUpdateLine.setMaintenanceDateFrom(null); newTmcDocumentUpdateLine.setMaintenanceDateTo(null); //penambahan 18-Maret-2016 newTmcDocumentUpdateLine.setTGLIsiPulsaReg(null); newTmcDocumentUpdateLine.setTGLIsiPulsaQuota(null); newTmcDocumentUpdateLine.setACC(aCC); OBDal.getInstance().save(newTmcDocumentUpdateLine); //OBDal.getInstance().flush(); tempValidDocumentUpdateLine.add(newTmcDocumentUpdateLine.getId()); // untuk data yg sinkron berdasar static 8 jam, dll dan ada //end insert } else { //insert berdasar data sebelumnya TmcDocumentUpdateLine newTmcDocumentUpdateLine = OBProvider.getInstance() .get(TmcDocumentUpdateLine.class); newTmcDocumentUpdateLine.setActive(true); newTmcDocumentUpdateLine.setTMCDocumentupdate(header);// set header nya newTmcDocumentUpdateLine.setCustomerName(tmcCarCriteria.list().get(0).getBpartner()); //Tambahan Sementara Bisnis partner kategori, karena computed column tidak dapat filter dropdown newTmcDocumentUpdateLine.setBpGroup( tmcCarCriteria.list().get(0).getBpartner().getBusinessPartnerCategory()); newTmcDocumentUpdateLine.setTMCCar(tmcCarCriteria.list().get(0)); newTmcDocumentUpdateLine.setStatus(statusCategory); //isi maintenance date from dan to isiMaintenanceDateFromTo(tmcCarCriteria, newTmcDocumentUpdateLine); //isi pengisianke isiPengisianKe(tmcCarCriteria, newTmcDocumentUpdateLine); //isi tanggal dan nominal pulsa Reguler isiTanggalNominalPulsaReguler(tmcCarCriteria, newTmcDocumentUpdateLine); // //isi tanggal dan nominal pulsa Quota isiTanggalNominalPulsaQuota(tmcCarCriteria, newTmcDocumentUpdateLine); newTmcDocumentUpdateLine.setACC(aCC); OBDal.getInstance().save(newTmcDocumentUpdateLine); tempValidDocumentUpdateLine.add(newTmcDocumentUpdateLine.getId()); // untuk data yg sinkron berdasar static 8 jam, dll dan ada } } } } } TmcDocumentUpdate header = getHeaderInstance(header_id); // // adegan menghapus record yg tidak valid berdasarkan status yg ditentukan /* [Historical 1/4 ] batal */ // OBCriteria<TmcDocumentUpdateLine> delNotinCritTmcDocumentUpdateLine = OBDal.getInstance() // .createCriteria(TmcDocumentUpdateLine.class); // // delNotinCritTmcDocumentUpdateLine // .add(Restrictions.eq(TmcDocumentUpdateLine.PROPERTY_TMCDOCUMENTUPDATE, header)); // delNotinCritTmcDocumentUpdateLine // .add(Restrictions.eq(TmcDocumentUpdateLine.PROPERTY_CREATEDBY, COOTRACK_USER)); // // delNotinCritTmcDocumentUpdateLine // .add(Restrictions.isNull(TmcDocumentUpdateLine.PROPERTY_STATUS)); // // for (TmcDocumentUpdateLine removeTmcDocumentUpdateLine : delNotinCritTmcDocumentUpdateLine // .list()) { // OBDal.getInstance().remove(removeTmcDocumentUpdateLine); // //OBDal.getInstance().flush(); // } // // adegan menghapus record yg ada table TMC_DocumentUpdateLine tapi tidak ada di TMC_Car OBCriteria<TmcDocumentUpdateLine> delTmcDocumentUpdateLine = OBDal.getInstance() .createCriteria(TmcDocumentUpdateLine.class); // filter headernya [ok] delTmcDocumentUpdateLine.add(Restrictions.eq(TmcDocumentUpdateLine.PROPERTY_TMCDOCUMENTUPDATE, header)); delTmcDocumentUpdateLine.add(Restrictions.eq(TmcDocumentUpdateLine.PROPERTY_CREATEDBY, COOTRACK_USER)); OBCriteria<TmcCar> seluruhMobilDiTmcCar = OBDal.getInstance().createCriteria(TmcCar.class); //[TMC_CAR tanpa filter created by 2/2] seluruhMobilDiTmcCar.add(Restrictions.eq(TmcCar.PROPERTY_CREATEDBY, COOTRACK_USER)); delTmcDocumentUpdateLine.add(Restrictions .not(Restrictions.in(TmcDocumentUpdateLine.PROPERTY_TMCCAR, seluruhMobilDiTmcCar.list()))); // for (TmcDocumentUpdateLine removeTmcDocumentUpdateLine : delTmcDocumentUpdateLine.list()) { OBDal.getInstance().remove(removeTmcDocumentUpdateLine); //OBDal.getInstance().flush(); } // [Historical 4/4 ] // OBDal.getInstance().flush(); // OBDal.getInstance().commitAndClose(); }
From source file:com.tripad.cootrack.utility.ResponseResultToDB.java
private BusinessPartner validateRootBP(JSONObject hasilTarget) throws CustomJsonErrorResponseException, Throwable { BusinessPartner result = null;/*from ww w. j a v a2 s . c o m*/ System.out.println("buat root bp"); // if (hasilTarget.get("ret").toString().equals("5555")) { // new Throwable(hasilTarget.get("msg").toString()); // } try { ArrayList<String> tempImeiServer = null; OBCriteria<BusinessPartner> listBP = OBDal.getInstance().createCriteria(BusinessPartner.class); String id = COOTRACK_USER.getUsername(); if (id.length() > 32) { id = id.substring(0, 32); } //revisi stelah go live yang error pas retrieve customer if (ISBYVALUE) { //tmcListChildAcc.add(Restrictions.eq(BusinessPartner.PROPERTY_SEARCHKEY, name)); listBP.add(Restrictions.eq(BusinessPartner.PROPERTY_SEARCHKEY, id)); } else { //tmcListChildAcc.add(Restrictions.eq(BusinessPartner.PROPERTY_TMCOPENAPIIDENT, id)); listBP.add(Restrictions.eq(BusinessPartner.PROPERTY_TMCOPENAPIIDENT, id)); } //bila masih bermasalah dalam penarikan customer -> create rootBP, komen baris dibawah ini listBP.add(Restrictions.eq(BusinessPartner.PROPERTY_CREATEDBY, COOTRACK_USER)); if (listBP.list().isEmpty()) { // Kosong, maka Insert BusinessPartner newBusinessPartner = OBProvider.getInstance().get(BusinessPartner.class); newBusinessPartner.setActive(true); newBusinessPartner.setTmcOpenapiIdent(id); // newBusinessPartner.setTmcOpenapiUser(name); newBusinessPartner.setSearchKey(id); newBusinessPartner.setName(COOTRACK_USER.getName()); newBusinessPartner.setTmcIsexpired(false); newBusinessPartner.setConsumptionDays(Long.getLong("0")); newBusinessPartner.setCreditLimit(BigDecimal.ZERO); newBusinessPartner.setBusinessPartnerCategory( getBPCategory(COOTRACK_USER.getName(), COOTRACK_USER.getUsername())); OBDal.getInstance().save(newBusinessPartner); //OBDal.getInstance().flush(); // get car list tempImeiServer = validateCar(hasilTarget, newBusinessPartner); result = newBusinessPartner; } else { listBP.list().get(0).setSearchKey(id); listBP.list().get(0).setName(COOTRACK_USER.getName()); listBP.list().get(0).setTmcIsexpired(false); listBP.list().get(0).setBusinessPartnerCategory( getBPCategory(COOTRACK_USER.getName(), COOTRACK_USER.getUsername())); OBDal.getInstance().save(listBP.list().get(0)); //OBDal.getInstance().flush(); // edit line //di rubah jadi pakai method tempImeiServer = validateCar(hasilTarget, listBP.list().get(0)); if (tempImeiServer.size() > 0) { OBCriteria<TmcCar> tmcListCarRemove = OBDal.getInstance().createCriteria(TmcCar.class); tmcListCarRemove.add(Restrictions.eq(TmcCar.PROPERTY_BPARTNER, listBP.list().get(0))); tmcListCarRemove.add(Restrictions.eq(TmcCar.PROPERTY_CREATEDBY, COOTRACK_USER)); tmcListCarRemove.add(Restrictions.not(Restrictions.in(TmcCar.PROPERTY_IMEI, tempImeiServer))); for (TmcCar removeRecord : tmcListCarRemove.list()) { for (TmcDocumentUpdateLine tmcListChildCar : removeRecord.getTmcDocumentUpdateLineList()) { OBDal.getInstance().remove(tmcListChildCar); //OBDal.getInstance().flush(); } OBDal.getInstance().remove(removeRecord); //OBDal.getInstance().flush(); } } //end check jumlah banyaknya line result = listBP.list().get(0); } OBDal.getInstance().flush(); } catch (Throwable xe) { System.out.println("Error Buat Root BP : " + xe.getMessage()); xe.printStackTrace(); return null; } return result; }
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) *//*from ww w . ja va2s .c o 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.tysanclan.site.projectewok.entities.dao.hibernate.UserDAOImpl.java
License:Open Source License
/** * @see com.tysanclan.site.projectewok.entities.dao.UserDAO#getTrialMembersReadyForVote() *//*w w w .j ava 2 s. c o m*/ @SuppressWarnings("unchecked") @Override public List<User> getTrialMembersReadyForVote() { Criteria criteria = getSession().createCriteria(User.class); Calendar cal = DateUtil.getCalendarInstance(); cal.add(Calendar.DAY_OF_YEAR, -14); criteria.add(Restrictions.eq("rank", Rank.TRIAL)); criteria.add(Restrictions.le("joinDate", cal.getTime())); Criteria reverse = getSession().createCriteria(AcceptanceVote.class); reverse.createAlias("trialMember", "user"); reverse.setProjection(Projections.property("user.id")); List<?> activeVotes = reverse.list(); if (!activeVotes.isEmpty()) { criteria.add(Restrictions.not(Restrictions.in("id", activeVotes))); } return criteria.list(); }
From source file:com.ut.healthelink.dao.impl.transactionInDAOImpl.java
@SuppressWarnings("unchecked") @Override// w w w. jav a 2 s .co m @Transactional public List<batchUploads> getuploadedBatches(int userId, int orgId, Date fromDate, Date toDate, List<Integer> excludedStatusIds) throws Exception { /* Get a list of connections the user has access to */ Criteria connections = sessionFactory.getCurrentSession() .createCriteria(configurationConnectionSenders.class); connections.add(Restrictions.eq("userId", userId)); List<configurationConnectionSenders> userConnections = connections.list(); List<Integer> configIdList = new ArrayList<Integer>(); if (userConnections.isEmpty()) { configIdList.add(0); } else { for (configurationConnectionSenders userConnection : userConnections) { Criteria connection = sessionFactory.getCurrentSession() .createCriteria(configurationConnection.class); connection.add(Restrictions.eq("id", userConnection.getconnectionId())); configurationConnection connectionInfo = (configurationConnection) connection.uniqueResult(); if (!configIdList.contains(connectionInfo.getsourceConfigId())) { configIdList.add(connectionInfo.getsourceConfigId()); } } } // multiconfig is 0 so we need to add configIdList.add(0); Criteria findBatches = sessionFactory.getCurrentSession().createCriteria(batchUploads.class); findBatches.add(Restrictions.eq("orgId", orgId)); findBatches.add(Restrictions.not(Restrictions.in("statusId", excludedStatusIds))); findBatches.add(Restrictions.in("configId", configIdList)); findBatches.add(Restrictions.ne("transportMethodId", 2)); if (!"".equals(fromDate)) { findBatches.add(Restrictions.ge("dateSubmitted", fromDate)); } if (!"".equals(toDate)) { findBatches.add(Restrictions.lt("dateSubmitted", toDate)); } findBatches.addOrder(Order.desc("dateSubmitted")); return findBatches.list(); }
From source file:com.webbfontaine.valuewebb.search.custom.UserCriterion.java
License:Open Source License
public Criterion getCriterion() throws Exception { if (condition.equals(EQ)) { if (value == null || value.toString().trim().length() == 0) { return Restrictions.isNull(fullKey); } else {/*ww w. ja v a 2 s .com*/ return Restrictions.eq(fullKey, value); } } if (condition.equals(NE)) { if (value == null || value.toString().trim().length() == 0) { return Restrictions.isNotNull(fullKey); } else { return Restrictions.ne(fullKey, value); } } if (condition.equals(GT)) { assertNonNullity(value); return Restrictions.gt(fullKey, value); } if (condition.equals(GE)) { assertNonNullity(value); return Restrictions.ge(fullKey, value); } if (condition.equals(LT)) { assertNonNullity(value); return Restrictions.lt(fullKey, value); } if (condition.equals(LE)) { assertNonNullity(value); return Restrictions.le(fullKey, value); } if (condition.equals(IN_A_RANGE)) { assertNonNullity(value); assertNonNullity(diff); return getPercentRange(); } if (condition.equals(ENDS_WITH)) { return Restrictions.like(fullKey, "%" + StringUtils.trim(value.toString())); } if (condition.equals(STARTS_WITH)) { return Restrictions.like(fullKey, StringUtils.trim(value.toString()) + "%"); } if (condition.equals(CONTAINS)) { return Restrictions.like(fullKey, "%" + StringUtils.trim(value.toString()) + '%'); } if (condition.equals(NOT_CONTAIN)) { return Restrictions.not(Restrictions.like(fullKey, "%" + StringUtils.trim(value.toString()) + '%')); } LOGGER.error( "Undefined User Criteria [key:{0}, value:{1}, condition:{3}] couldn't be transformed to search criterion", fullKey, value, condition); throw new RuntimeException("Undefined User Criteria: " + name); }
From source file:com.yahoo.elide.datastores.hibernate3.filter.CriterionFilterOperation.java
License:Apache License
@Override public Criterion apply(FilterPredicate filterPredicate) { List<FilterPredicate.PathElement> path = filterPredicate.getPath(); /* If the predicate refers to a nested association, the restriction should be 'alias.fieldName' */ String alias;//from w w w.j av a 2 s .c om if (path.size() > 1) { alias = getAlias(path); alias = alias + "." + path.get(path.size() - 1).getFieldName(); /* If the predicate refers to the root entity, the restriction should be 'fieldName' */ } else { alias = path.get(0).getFieldName(); } switch (filterPredicate.getOperator()) { case IN: if (filterPredicate.getValues().isEmpty()) { return Restrictions.sqlRestriction("(false)"); } return Restrictions.in(alias, filterPredicate.getValues()); case NOT: if (filterPredicate.getValues().isEmpty()) { return Restrictions.sqlRestriction("(true)"); } return Restrictions.not(Restrictions.in(alias, filterPredicate.getValues())); case PREFIX: return Restrictions.like(alias, filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER) + MATCHALL_CHARACTER); case PREFIX_CASE_INSENSITIVE: return Restrictions.ilike(alias, filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER) + MATCHALL_CHARACTER); case POSTFIX: return Restrictions.like(alias, MATCHALL_CHARACTER + filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER)); case POSTFIX_CASE_INSENSITIVE: return Restrictions.ilike(alias, MATCHALL_CHARACTER + filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER)); case INFIX: return Restrictions.like(alias, MATCHALL_CHARACTER + filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER) + MATCHALL_CHARACTER); case INFIX_CASE_INSENSITIVE: return Restrictions.ilike(alias, MATCHALL_CHARACTER + filterPredicate.getStringValueEscaped(SPECIAL_CHARACTER, ESCAPE_CHARACTER) + MATCHALL_CHARACTER); case ISNULL: return Restrictions.isNull(alias); case NOTNULL: return Restrictions.isNotNull(alias); case LT: return Restrictions.lt(alias, filterPredicate.getValues().get(0)); case LE: return Restrictions.le(alias, filterPredicate.getValues().get(0)); case GT: return Restrictions.gt(alias, filterPredicate.getValues().get(0)); case GE: return Restrictions.ge(alias, filterPredicate.getValues().get(0)); case TRUE: return Restrictions.sqlRestriction("(true)"); case FALSE: return Restrictions.sqlRestriction("(false)"); default: throw new InvalidPredicateException("Operator not implemented: " + filterPredicate.getOperator()); } }
From source file:com.zc.orm.hibernate.HibernateDao.java
License:Apache License
/** * ???.//from ww w .j a v a2 s. c o m * * @param uniquePropertyNames * POJO???,? "name,loginid,password" */ public boolean isUnique(T entity, String uniquePropertyNames) { Criteria criteria = getSession().createCriteria(entityClass).setProjection(Projections.rowCount()); String[] nameList = uniquePropertyNames.split(","); try { // for (int i = 0; i < nameList.length; i++) { criteria.add(Restrictions.eq(nameList[i], PropertyUtils.getProperty(entity, nameList[i]))); } // ?update,entity. String idName = getSessionFactory().getClassMetadata(entity.getClass()).getIdentifierPropertyName(); if (idName != null) { // ?entity Serializable id = (Serializable) PropertyUtils.getProperty(entity, idName); // id!=null,,?update, if (id != null) criteria.add(Restrictions.not(Restrictions.eq(idName, id))); } } catch (Exception e) { Reflector.convertReflectionExceptionToUnchecked(e); } return ((Number) criteria.uniqueResult()).intValue() == 0; }