List of usage examples for org.hibernate Session evict
void evict(Object object);
From source file:agent_update.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from ww w. j a va2s . c om * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, FileUploadException { response.setContentType("text/html;charset=UTF-8"); HttpSession hs = request.getSession(); PrintWriter out = response.getWriter(); try { if (hs.getAttribute("user") != null) { Login ln = (Login) hs.getAttribute("user"); System.out.println(ln.getUId()); String fn = ""; String lastn = ""; String un = ""; String state = ""; String city = ""; String area = ""; String e = ""; String ad1 = ""; String ad2 = ""; String num = ""; String p = ""; String des = ""; String cmp = ""; String work = ""; String agentphoto = ""; String agentname = ""; int id = 0; // creates FileItem instances which keep their content in a temporary file on disk FileItemFactory factory = new DiskFileItemFactory(); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); //get the list of all fields from request List<FileItem> fields = upload.parseRequest(request); // iterates the object of list Iterator<FileItem> it = fields.iterator(); //getting objects one by one while (it.hasNext()) { //assigning coming object if list to object of FileItem FileItem fileItem = it.next(); //check whether field is form field or not boolean isFormField = fileItem.isFormField(); if (isFormField) { //get the filed name String fieldName = fileItem.getFieldName(); if (fieldName.equals("fname")) { fn = fileItem.getString(); } else if (fieldName.equals("id")) { id = Integer.parseInt(fileItem.getString()); } else if (fieldName.equals("lname")) { lastn = fileItem.getString(); } else if (fieldName.equals("uname")) { un = fileItem.getString(); } else if (fieldName.equals("state")) { state = fileItem.getString(); } else if (fieldName.equals("city")) { city = fileItem.getString(); } else if (fieldName.equals("area")) { area = fileItem.getString(); } else if (fieldName.equals("email")) { e = fileItem.getString(); } else if (fieldName.equals("address1")) { ad1 = fileItem.getString(); } else if (fieldName.equals("address2")) { ad2 = fileItem.getString(); } else if (fieldName.equals("number")) { num = fileItem.getString(); } else if (fieldName.equals("pwd")) { p = fileItem.getString(); } else if (fieldName.equals("descrip")) { des = fileItem.getString(); } else if (fieldName.equals("compname")) { cmp = fileItem.getString(); } else if (fieldName.equals("workx")) { work = fileItem.getString(); } } else { agentphoto = new File(fileItem.getName()).getName(); System.out.println(agentphoto); try { // FOR UBUNTU add GETRESOURCE and GETPATH String fp = "/home/rushin/NetBeansProjects/The_Asset_Consultancy/web/images/profilepic/"; // String filePath= this.getServletContext().getResource("/images/profilepic").getPath()+"//"; System.out.println("====" + fp); fileItem.write(new File(fp + agentphoto)); } catch (Exception ex) { out.println(ex.toString()); } } } SessionFactory sf = NewHibernateUtil.getSessionFactory(); Session ss = sf.openSession(); Transaction tr = ss.beginTransaction(); // // String state=""; // Criteria cr = ss.createCriteria(StateMaster.class); // cr.add(Restrictions.eq("sId", Integer.parseInt(stateid))); // ArrayList<StateMaster> ar = (ArrayList<StateMaster>)cr.list(); // System.out.println("----------"+ar.size()); // if(ar.isEmpty()){ // // }else{ // state = ar.get(0).getSName(); // System.out.println("-------"+ar.get(0)); // } // // String city=""; // Criteria cr2 = ss.createCriteria(CityMaster.class); // cr2.add(Restrictions.eq("cityId", Integer.parseInt(cityid))); // ArrayList<CityMaster> ar2 = (ArrayList<CityMaster>)cr2.list(); // System.out.println("----------"+ar2.size()); // if(ar2.isEmpty()){ // // }else{ // city = ar2.get(0).getCityName(); // System.out.println("-------"+city); // } // // String area=""; // Criteria cr3 = ss.createCriteria(AreaMaster.class); // cr3.add(Restrictions.eq("areaId", Integer.parseInt(areaid))); // ArrayList<AreaMaster> ar3 = (ArrayList<AreaMaster>)cr3.list(); // System.out.println("----------"+ar3.size()); // if(ar3.isEmpty()){ // // }else{ // area = ar3.get(0).getAreaName(); // System.out.println("-------"+area); // } // // Criteria crr=ss.createCriteria(AgentDetail.class); // crr.add(Restrictions.eq("uId", ln.getUId())); // ArrayList<AgentDetail> arr=(ArrayList<AgentDetail>)crr.list(); // if(arr.isEmpty()) // { // out.print("array empty"); // } // else // { // AgentDetail agd=arr.get(0); AgentDetail agd2 = (AgentDetail) ss.get(AgentDetail.class, id); AgentDetail agd = new AgentDetail(); agd.setUId(agd2.getUId()); agd.setAId(agd2.getAId()); agd.setACompanyname(cmp); agd.setADescription(des); agd.setAEmail(e); agd.setAFname(fn); agd.setAImg(agentphoto); agd.setALname(lastn); agd.setANo(num); agd.setAWorkx(work); agd.setACity(city); agd.setAArea(area); agd.setAState(state); agd.setAAddress1(ad1); agd.setAAddress2(ad2); agd.setAStatus(null); agd.setARating(null); agd.setAStatus("Accepted"); // agd.getUId().setPwd(p); // agd.getUId().setUName(un); ss.evict(agd2); ss.update(agd); tr.commit(); // } RequestDispatcher rd = request.getRequestDispatcher("agentprofile.jsp"); rd.forward(request, response); } } catch (HibernateException e) { out.println(e.getMessage()); } }
From source file:analysis_criteria.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*w w w . j a v a 2 s. c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { SessionFactory sf = NewHibernateUtil.getSessionFactory(); Session ss = sf.openSession(); Transaction tr = ss.beginTransaction(); String prstate = request.getParameter("state"); String prcity = request.getParameter("city"); String prarea = request.getParameter("area"); String ptype = request.getParameter("type"); String pbhk = request.getParameter("bhk"); String przip = ""; System.out.println("bhk is" + pbhk); System.out.println("type is" + ptype); String state = ""; Criteria cr = ss.createCriteria(StateMaster.class); cr.add(Restrictions.eq("sId", Integer.parseInt(prstate))); ArrayList<StateMaster> ar = (ArrayList<StateMaster>) cr.list(); if (ar.isEmpty()) { } else { StateMaster sm = ar.get(0); state = sm.getSName(); } String city = ""; Criteria cr2 = ss.createCriteria(CityMaster.class); cr2.add(Restrictions.eq("cityId", Integer.parseInt(prcity))); ArrayList<CityMaster> ar2 = (ArrayList<CityMaster>) cr2.list(); System.out.println("----------" + ar2.size()); if (ar2.isEmpty()) { } else { city = ar2.get(0).getCityName(); System.out.println("-------" + city); } String area = ""; Criteria cr3 = ss.createCriteria(AreaMaster.class); cr3.add(Restrictions.eq("areaId", Integer.parseInt(prarea))); ArrayList<AreaMaster> ar3 = (ArrayList<AreaMaster>) cr3.list(); System.out.println("----------" + ar3.size()); if (ar3.isEmpty()) { } else { area = ar3.get(0).getAreaName(); System.out.println("-------" + area); } Criteria cr4 = ss.createCriteria(AreaMaster.class); cr4.add(Restrictions.eq("areaId", Integer.parseInt(prarea))); ArrayList<AreaMaster> ar4 = (ArrayList<AreaMaster>) cr4.list(); System.out.println("----------" + ar4.size()); if (ar4.isEmpty()) { } else { przip = ar4.get(0).getZip(); System.out.println("-------" + przip); } out.print("after object 0"); // // String s="select * from the_asset_consultancy.Filter_criteria;"; // // SQLQuery query=ss.createSQLQuery(s); // List<Filtercriteria> l=query.list(); // Criteria cr5 = ss.createCriteria(Filtercriteria.class); ArrayList<Filtercriteria> l = (ArrayList<Filtercriteria>) cr5.list(); Filtercriteria old = l.get(0); System.out.println("this is old cr id:" + old.getCrId()); Filtercriteria f = new Filtercriteria(); f.setCrId(old.getCrId()); f.setArea(area); out.print("after object 1"); f.setBhk(pbhk); f.setType(ptype); f.setZip(przip); ss.evict(old); ss.update(f); out.print("after object 2"); tr.commit(); out.print("after object 3"); out.print("after object 4"); //for trial HadoopProcessingClass.Do_Process(); RequestDispatcher rd = request.getRequestDispatcher("show_growthrate"); rd.forward(request, response); //Original code // RequestDispatcher rd = request.getRequestDispatcher("analysis_search.jsp"); // rd.forward(request, response); } catch (HibernateException he) { out.print(he.getMessage()); } }
From source file:property_update.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// w w w.j a v a 2s . c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, FileUploadException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); HttpSession hs = request.getSession(); try { if (hs.getAttribute("user") != null) { Login ln = (Login) hs.getAttribute("user"); System.out.println(ln.getUId()); String pradd1 = ""; String pradd2 = ""; String prage = ""; String prbhk = ""; String prdescrip = ""; String prprice = ""; String state = ""; String city = ""; String area = ""; String prname = ""; String prtype = ""; String prphoto = ""; String prphoto1 = ""; String prphoto2 = ""; String prphoto3 = ""; String prfarea = ""; int prid = 0; FileItemFactory factory = new DiskFileItemFactory(); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); //get the list of all fields from request List<FileItem> fields = upload.parseRequest(request); // iterates the object of list Iterator<FileItem> it = fields.iterator(); //getting objects one by one while (it.hasNext()) { //assigning coming object if list to object of FileItem FileItem fileItem = it.next(); //check whether field is form field or not boolean isFormField = fileItem.isFormField(); if (isFormField) { //get the filed name String fieldName = fileItem.getFieldName(); if (fieldName.equals("pname")) { //getting value of field prname = fileItem.getString(); System.out.println(prname); } else if (fieldName.equals("price")) { //getting value of field prprice = fileItem.getString(); System.out.println(prprice); } else if (fieldName.equals("pid")) { prid = Integer.parseInt(fileItem.getString()); } else if (fieldName.equals("state")) { state = fileItem.getString(); } else if (fieldName.equals("city")) { city = fileItem.getString(); } else if (fieldName.equals("area")) { area = fileItem.getString(); } else if (fieldName.equals("pbhk")) { prbhk = fileItem.getString(); System.out.println(prbhk); } else if (fieldName.equals("pdescription")) { prdescrip = fileItem.getString(); System.out.println(prdescrip); } else if (fieldName.equals("ptype")) { prtype = fileItem.getString(); System.out.println(prtype); } else if (fieldName.equals("paddress1")) { pradd1 = fileItem.getString(); System.out.println(pradd1); } else if (fieldName.equals("paddress2")) { pradd2 = fileItem.getString(); System.out.println(pradd2); } else if (fieldName.equals("page")) { prage = fileItem.getString(); System.out.println(prage); } else if (fieldName.equals("pfarea")) { prfarea = fileItem.getString(); System.out.println(prfarea); } else if (fieldName.equals("prid")) { prid = Integer.parseInt(fileItem.getString()); System.out.println("prid is " + prid); } } else { String fieldName = fileItem.getFieldName(); if (fieldName.equals("pic1")) { //getting name of file prphoto = new File(fileItem.getName()).getName(); //get the extension of file by diving name into substring // String extension=custphoto.substring(custphoto.indexOf(".")+1,custphoto.length());; //rename file...concate name and extension // custphoto=ln.getUId()+"."+extension; try { // FOR UBUNTU add GETRESOURCE and GETPATH String fp = "/home/rushin/NetBeansProjects/The_Asset_Consultancy/web/images/property/"; // String filePath= this.getServletContext().getResource("/images/profilepic").getPath()+"\\"; System.out.println("====" + fp); fileItem.write(new File(fp + prphoto)); } catch (Exception ex) { out.println(ex.toString()); } } if (fieldName.equals("pic2")) { prphoto1 = new File(fileItem.getName()).getName(); try { String fp = "/home/rushin/NetBeansProjects/The_Asset_Consultancy/web/images/property/"; // String filePath= this.getServletContext().getResource("/images/profilepic").getPath()+"\\"; System.out.println("====" + fp); fileItem.write(new File(fp + prphoto1)); } catch (Exception ex) { out.println(ex.toString()); } } if (fieldName.equals("pic3")) { prphoto2 = new File(fileItem.getName()).getName(); try { String fp = "/home/rushin/NetBeansProjects/The_Asset_Consultancy/web/images/property/"; // String filePath= this.getServletContext().getResource("/images/profilepic").getPath()+"\\"; System.out.println("====" + fp); fileItem.write(new File(fp + prphoto2)); } catch (Exception ex) { out.println(ex.toString()); } } if (fieldName.equals("pic4")) { prphoto3 = new File(fileItem.getName()).getName(); try { String fp = "/home/rushin/NetBeansProjects/The_Asset_Consultancy/web/images/property/"; // String filePath= this.getServletContext().getResource("/images/profilepic").getPath()+"\\"; System.out.println("====" + fp); fileItem.write(new File(fp + prphoto3)); } catch (Exception ex) { out.println(ex.toString()); } } } } SessionFactory sf = NewHibernateUtil.getSessionFactory(); Session ss = sf.openSession(); Transaction tr = ss.beginTransaction(); // String state=""; // Criteria cr = ss.createCriteria(StateMaster.class); // cr.add(Restrictions.eq("sId", Integer.parseInt(stateid))); // ArrayList<StateMaster> ar = (ArrayList<StateMaster>)cr.list(); // System.out.println("----------"+ar.size()); // if(ar.isEmpty()){ // // }else{ // state = ar.get(0).getSName(); // System.out.println("-------"+ar.get(0)); // } // // String city=""; // Criteria cr2 = ss.createCriteria(CityMaster.class); // cr2.add(Restrictions.eq("cityId", Integer.parseInt(cityid))); // ArrayList<CityMaster> ar2 = (ArrayList<CityMaster>)cr2.list(); // System.out.println("----------"+ar2.size()); // if(ar2.isEmpty()){ // // }else{ // city = ar2.get(0).getCityName(); // System.out.println("-------"+city); // } // // String area=""; // Criteria cr3 = ss.createCriteria(AreaMaster.class); // cr3.add(Restrictions.eq("areaId", Integer.parseInt(areaid))); // ArrayList<AreaMaster> ar3 = (ArrayList<AreaMaster>)cr3.list(); // System.out.println("----------"+ar3.size()); // if(ar3.isEmpty()){ // // }else{ // area = ar3.get(0).getAreaName(); // System.out.println("-------"+area); // } // // Criteria crr=ss.createCriteria(AgentDetail.class); // crr.add(Restrictions.eq("uId", ln.getUId())); // ArrayList<AgentDetail> arr=(ArrayList<AgentDetail>)crr.list(); // if(arr.isEmpty()) // { // out.print("array empty"); // } // else // { // AgentDetail agd=arr.get(0); PropDetail prd = (PropDetail) ss.get(PropDetail.class, prid); System.out.println("old object id is " + prd.getPId()); PropDetail prd1 = new PropDetail(); prd1.setUId(prd.getUId()); prd1.setPId(prd.getPId()); prd1.setPDescription(prdescrip); prd1.setPImg1(prphoto1); prd1.setPImg2(prphoto2); prd1.setPImg3(prphoto3); prd1.setPImg4(prphoto); prd1.setPAdd1(pradd1); prd1.setPAdd2(pradd2); prd1.setPAge(Integer.parseInt(prage)); prd1.setPBhk(prbhk); prd1.setPFloor(Integer.parseInt(prfarea)); prd1.setPGmap(null); prd1.setPName(prname); prd1.setPPrice(Integer.parseInt(prprice)); prd1.setPStatus(null); prd1.setPCity(city); prd1.setPArea(area); prd1.setPState(state); prd1.setPType(prtype); ss.evict(prd); ss.update(prd1); tr.commit(); RequestDispatcher rd = request.getRequestDispatcher("getstate?id=9"); rd.forward(request, response); } } catch (HibernateException e) { out.println(e.getMessage()); } }
From source file:cust_update.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from ww w . j av a 2 s .co m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, FileUploadException { response.setContentType("text/html;charset=UTF-8"); HttpSession hs = request.getSession(); PrintWriter out = response.getWriter(); try { if (hs.getAttribute("user") != null) { Login ln = (Login) hs.getAttribute("user"); System.out.println(ln.getUId()); String firstn = ""; String lastn = ""; String un = ""; String state = ""; String city = ""; int id = 0; String e = ""; String num = ""; String p = ""; String custphoto = ""; String custname = ""; String area = ""; // creates FileItem instances which keep their content in a temporary file on disk FileItemFactory factory = new DiskFileItemFactory(); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); //get the list of all fields from request List<FileItem> fields = upload.parseRequest(request); // iterates the object of list Iterator<FileItem> it = fields.iterator(); //getting objects one by one while (it.hasNext()) { //assigning coming object if list to object of FileItem FileItem fileItem = it.next(); //check whether field is form field or not boolean isFormField = fileItem.isFormField(); if (isFormField) { //get the filed name String fieldName = fileItem.getFieldName(); if (fieldName.equals("fname")) { firstn = fileItem.getString(); System.out.println(firstn); } else if (fieldName.equals("id")) { id = Integer.parseInt(fileItem.getString()); } else if (fieldName.equals("lname")) { lastn = fileItem.getString(); System.out.println(lastn); } else if (fieldName.equals("uname")) { un = fileItem.getString(); System.out.println(un); } else if (fieldName.equals("state")) { state = fileItem.getString(); System.out.println(state); } else if (fieldName.equals("city")) { city = fileItem.getString(); System.out.println(city); } else if (fieldName.equals("area")) { area = fileItem.getString(); } else if (fieldName.equals("email")) { e = fileItem.getString(); System.out.println(e); } else if (fieldName.equals("number")) { num = fileItem.getString(); System.out.println(num); } else if (fieldName.equals("pwd")) { p = fileItem.getString(); System.out.println(p); } } else { //getting name of file custphoto = new File(fileItem.getName()).getName(); //get the extension of file by diving name into substring // String extension=custphoto.substring(custphoto.indexOf(".")+1,custphoto.length());; //rename file...concate name and extension // custphoto=ln.getUId()+"."+extension; System.out.println(custphoto); try { // FOR UBUNTU add GETRESOURCE and GETPATH String fp = "/home/rushin/NetBeansProjects/The_Asset_Consultancy/web/images/profilepic/"; // String filePath= this.getServletContext().getResource("/images/profilepic").getPath()+"\\"; System.out.println("====" + fp); fileItem.write(new File(fp + custphoto)); } catch (Exception ex) { out.println(ex.toString()); } } } SessionFactory sf = NewHibernateUtil.getSessionFactory(); Session ss = sf.openSession(); Transaction tr = ss.beginTransaction(); // // String op=""; // cr.add(Restrictions.eq("sId", Integer.parseInt(state))); // ArrayList<StateMaster> ar = (ArrayList<StateMaster>)cr.list(); // if(ar.isEmpty()){ // // }else{ // StateMaster sm = ar.get(0); // op=sm.getSName(); // // } CustomerDetail cd1 = (CustomerDetail) ss.get(CustomerDetail.class, id); System.out.println("cid is " + cd1.getCId()); CustomerDetail cd = new CustomerDetail(); cd.setUId(cd1.getUId()); cd.setCId(cd1.getCId()); cd.setCFname(firstn); cd.setCLname(lastn); cd.setCNum(num); cd.setCEmail(e); cd.setCState(state); cd.setCCity(city); cd.setCArea(area); cd.setCImg(custphoto); ss.evict(cd1); ss.update(cd); tr.commit(); RequestDispatcher rd = request.getRequestDispatcher("customerprofile.jsp"); rd.forward(request, response); } } catch (HibernateException e) { out.println(e.getMessage()); } }
From source file:agentstatus.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from www . j a v a 2 s. c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { SessionFactory sf = NewHibernateUtil.getSessionFactory(); Session ss = sf.openSession(); Transaction tr = ss.beginTransaction(); int id = Integer.parseInt(request.getParameter("id")); int agentid = Integer.parseInt(request.getParameter("aid")); // Touroperator to = (Touroperator)se.get(Touroperator.class, spid); AgentDetail ad = (AgentDetail) ss.get(AgentDetail.class, agentid); if (id == 0) { //Accepted out.print(agentid + "accepted"); AgentDetail ad2 = new AgentDetail(); ad2.setAAddress1(ad.getAAddress1()); ad2.setAAddress2(ad.getAAddress2()); ad2.setAArea(ad.getAArea()); ad2.setACity(ad.getACity()); ad2.setACompanyname(ad.getACompanyname()); ad2.setADescription(ad.getADescription()); ad2.setAEmail(ad.getAEmail()); ad2.setAFname(ad.getAFname()); ad2.setALname(ad.getALname()); ad2.setAId(ad.getAId()); ad2.setAImg(ad.getAImg()); ad2.setANo(ad.getANo()); ad2.setARating(ad.getARating()); ad2.setAState(ad.getAState()); ad2.setUId(ad.getUId()); ad2.setAWorkx(ad.getAWorkx()); ad2.setAStatus("Accepted"); ss.evict(ad); ss.update(ad2); tr.commit(); } else if (id == 1) { //Denied out.print(agentid + "denied"); ss.delete(ad); tr.commit(); } } catch (HibernateException e) { out.println(e.getMessage()); } }
From source file:au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.tests.RegisterLocalRigTester.java
License:Open Source License
/** * Test method for {@link au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.RegisterLocalRig#registerRig(java.lang.String, java.lang.String, java.lang.String, java.lang.String)}. *///from ww w .ja va 2s. c o m @Test public void testAddRigToSchedServerNewRigExistingTypeNewCaps() { Session ses = DataAccessActivator.getNewSession(); String name = "register1"; String type = "registertest"; String caps = "a,b,c,d,e,f"; String contactUrl = "http://lbremote1.eng.uts.edu.au:7070/services/RigClientService"; RigType existType = new RigType(type, 180, false); ses.beginTransaction(); ses.save(existType); ses.getTransaction().commit(); ses.flush(); ses.evict(existType); assertTrue(this.register.registerRig(name, type, caps, contactUrl)); assertNull(this.register.getFailedReason()); Rig rig = this.register.getRegisteredRig(); assertNotNull(rig); assertEquals(name, rig.getName()); assertEquals(type, rig.getRigType().getName()); assertEquals(contactUrl, rig.getContactUrl()); assertNotNull(rig.getRigCapabilities()); /* Default values. */ assertTrue(rig.isActive()); assertFalse(rig.isInSession()); assertFalse(rig.isOnline()); assertTrue(rig.isManaged()); assertNotNull(rig.getOfflineReason()); assertNull(rig.getMeta()); assertNull(rig.getSession()); assertTrue(new Date(System.currentTimeMillis()).after(rig.getLastUpdateTimestamp())); assertTrue(new Date(System.currentTimeMillis() - 10000).before(rig.getLastUpdateTimestamp())); /* Test caps record was created and added. */ RigCapabilities capsRec = new RigCapabilitiesDao(ses).findCapabilites(caps); assertNotNull(capsRec); assertEquals(caps, capsRec.getCapabilities()); /* Test type record was created and added. */ RigType typeRec = new RigTypeDao(ses).findByName(type); assertNotNull(typeRec); assertEquals(type, typeRec.getName()); assertEquals(180, typeRec.getLogoffGraceDuration()); assertFalse(typeRec.isCodeAssignable()); /* Test rig record was created and added. */ Rig rigRec = new RigDao(ses).findByName(name); assertNotNull(rigRec); assertNotNull(rigRec.getId()); assertEquals(name, rigRec.getName()); assertEquals(type, rigRec.getRigType().getName()); assertTrue(rigRec.isActive()); assertEquals(contactUrl, rigRec.getContactUrl()); assertFalse(rigRec.isInSession()); assertNotNull(rigRec.getLastUpdateTimestamp()); assertTrue(rigRec.isManaged()); assertNull(rigRec.getMeta()); assertNotNull(rigRec.getOfflineReason()); assertFalse(rigRec.isOnline()); assertEquals(caps, rigRec.getRigCapabilities().getCapabilities()); assertTrue(new Date(System.currentTimeMillis()).after(rigRec.getLastUpdateTimestamp())); assertTrue(new Date(System.currentTimeMillis() - 10000).before(rigRec.getLastUpdateTimestamp())); /* Cleanup. */ ses.beginTransaction(); ses.createQuery("DELETE FROM RigLog WHERE rig='" + rig.getId() + "'").executeUpdate(); ses.getTransaction().commit(); ses.beginTransaction(); ses.delete(rigRec); ses.delete(capsRec); ses.delete(typeRec); ses.getTransaction().commit(); }
From source file:au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.tests.RegisterLocalRigTester.java
License:Open Source License
/** * Test method for {@link au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.RegisterLocalRig#registerRig(java.lang.String, java.lang.String, java.lang.String, java.lang.String)}. *//* w w w . j a v a 2s. c om*/ @Test public void testAddRigToSchedServerNewRigExistingTypeExistingCaps() { Session ses = DataAccessActivator.getNewSession(); String name = "register1"; String type = "registertest"; String caps = "a,b,c,d,e,f"; String contactUrl = "http://lbremote1.eng.uts.edu.au:7070/services/RigClientService"; RigType existType = new RigType(type, 180, false); RigCapabilities existCaps = new RigCapabilities(caps); ses.beginTransaction(); ses.save(existType); ses.save(existCaps); ses.getTransaction().commit(); ses.flush(); ses.evict(existType); assertTrue(this.register.registerRig(name, type, caps, contactUrl)); assertNull(this.register.getFailedReason()); Rig rig = this.register.getRegisteredRig(); assertNotNull(rig); assertEquals(name, rig.getName()); assertEquals(type, rig.getRigType().getName()); assertEquals(contactUrl, rig.getContactUrl()); assertNotNull(rig.getRigCapabilities()); /* Default values. */ assertTrue(rig.isActive()); assertFalse(rig.isInSession()); assertFalse(rig.isOnline()); assertTrue(rig.isManaged()); assertNotNull(rig.getOfflineReason()); assertNull(rig.getMeta()); assertNull(rig.getSession()); assertTrue(new Date(System.currentTimeMillis()).after(rig.getLastUpdateTimestamp())); assertTrue(new Date(System.currentTimeMillis() - 10000).before(rig.getLastUpdateTimestamp())); /* Test caps record was created and added. */ RigCapabilities capsRec = new RigCapabilitiesDao(ses).findCapabilites(caps); assertNotNull(capsRec); assertEquals(caps, capsRec.getCapabilities()); /* Test type record was created and added. */ RigType typeRec = new RigTypeDao(ses).findByName(type); assertNotNull(typeRec); assertEquals(type, typeRec.getName()); assertEquals(180, typeRec.getLogoffGraceDuration()); assertFalse(typeRec.isCodeAssignable()); /* Test rig record was created and added. */ Rig rigRec = new RigDao(ses).findByName(name); assertNotNull(rigRec); assertNotNull(rigRec.getId()); assertEquals(name, rigRec.getName()); assertEquals(type, rigRec.getRigType().getName()); assertTrue(rigRec.isActive()); assertEquals(contactUrl, rigRec.getContactUrl()); assertFalse(rigRec.isInSession()); assertNotNull(rigRec.getLastUpdateTimestamp()); assertTrue(rigRec.isManaged()); assertNull(rigRec.getMeta()); assertNotNull(rigRec.getOfflineReason()); assertFalse(rigRec.isOnline()); assertEquals(caps, rigRec.getRigCapabilities().getCapabilities()); assertTrue(new Date(System.currentTimeMillis()).after(rigRec.getLastUpdateTimestamp())); assertTrue(new Date(System.currentTimeMillis() - 10000).before(rigRec.getLastUpdateTimestamp())); /* Cleanup. */ ses.beginTransaction(); ses.createQuery("DELETE FROM RigLog WHERE rig='" + rig.getId() + "'").executeUpdate(); ses.getTransaction().commit(); ses.beginTransaction(); ses.delete(rigRec); ses.delete(capsRec); ses.delete(typeRec); ses.getTransaction().commit(); }
From source file:au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.tests.RegisterLocalRigTester.java
License:Open Source License
/** * Test method for {@link au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.RegisterLocalRig#registerRig(java.lang.String, java.lang.String, java.lang.String, java.lang.String)}. *//* w w w . j a va2 s .c o m*/ @Test public void testAddRigToSchedServerInactiveRig() { Session ses = DataAccessActivator.getNewSession(); String name = "register1"; String type = "registertest"; String caps = "a,b,c,d,e,f"; String contactUrl = "http://lbremote1.eng.uts.edu.au:7070/services/RigClientService"; RigType existType = new RigType(type, 180, false); RigCapabilities existCaps = new RigCapabilities(caps); ses.beginTransaction(); ses.save(existType); ses.save(existCaps); ses.getTransaction().commit(); ses.flush(); ses.evict(existType); ses.evict(existCaps); Rig existRig = new Rig(existType, existCaps, name, contactUrl, new Date(), false, "Broken.", false, true, false); ses.beginTransaction(); ses.save(existRig); ses.getTransaction().commit(); ses.flush(); ses.evict(existRig); assertTrue(this.register.registerRig(name, type, caps, contactUrl)); assertNull(this.register.getFailedReason()); Rig rig = this.register.getRegisteredRig(); assertNotNull(rig); assertEquals(name, rig.getName()); assertEquals(type, rig.getRigType().getName()); assertEquals(contactUrl, rig.getContactUrl()); assertNotNull(rig.getRigCapabilities()); /* Default values. */ assertTrue(rig.isActive()); assertFalse(rig.isInSession()); assertFalse(rig.isOnline()); assertTrue(rig.isManaged()); assertNotNull(rig.getOfflineReason()); assertNull(rig.getMeta()); assertNull(rig.getSession()); assertTrue(new Date(System.currentTimeMillis()).after(rig.getLastUpdateTimestamp())); assertTrue(new Date(System.currentTimeMillis() - 10000).before(rig.getLastUpdateTimestamp())); /* Test caps record was created and added. */ RigCapabilities capsRec = new RigCapabilitiesDao(ses).findCapabilites(caps); assertNotNull(capsRec); assertEquals(caps, capsRec.getCapabilities()); /* Test type record was created and added. */ RigType typeRec = new RigTypeDao(ses).findByName(type); assertNotNull(typeRec); assertEquals(type, typeRec.getName()); assertEquals(180, typeRec.getLogoffGraceDuration()); assertFalse(typeRec.isCodeAssignable()); /* Test rig record was created and added. */ Rig rigRec = new RigDao(ses).findByName(name); assertNotNull(rigRec); assertNotNull(rigRec.getId()); assertEquals(name, rigRec.getName()); assertEquals(type, rigRec.getRigType().getName()); assertTrue(rigRec.isActive()); assertEquals(contactUrl, rigRec.getContactUrl()); assertFalse(rigRec.isInSession()); assertNotNull(rigRec.getLastUpdateTimestamp()); assertTrue(rigRec.isManaged()); assertNull(rigRec.getMeta()); assertNotNull(rigRec.getOfflineReason()); assertFalse(rigRec.isOnline()); assertEquals(caps, rigRec.getRigCapabilities().getCapabilities()); assertTrue(new Date(System.currentTimeMillis()).after(rigRec.getLastUpdateTimestamp())); assertTrue(new Date(System.currentTimeMillis() - 10000).before(rigRec.getLastUpdateTimestamp())); /* Cleanup. */ ses.beginTransaction(); ses.createQuery("DELETE FROM RigLog WHERE rig='" + rig.getId() + "'").executeUpdate(); ses.getTransaction().commit(); ses.beginTransaction(); ses.delete(rigRec); ses.delete(capsRec); ses.delete(typeRec); ses.getTransaction().commit(); }
From source file:au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.tests.RegisterLocalRigTester.java
License:Open Source License
/** * Test method for {@link au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.RegisterLocalRig#registerRig(java.lang.String, java.lang.String, java.lang.String, java.lang.String)}. *///from ww w .j av a 2 s .co m @Test public void testAddRigToSchedServerActiveRig() { Session ses = DataAccessActivator.getNewSession(); String name = "register1"; String type = "registertest"; String caps = "a,b,c,d,e,f"; String contactUrl = "http://lbremote1.eng.uts.edu.au:7070/services/RigClientService"; RigType existType = new RigType(type, 180, false); RigCapabilities existCaps = new RigCapabilities(caps); ses.beginTransaction(); ses.save(existType); ses.save(existCaps); ses.getTransaction().commit(); ses.flush(); ses.evict(existType); ses.evict(existCaps); Rig existRig = new Rig(existType, existCaps, name, contactUrl, new Date(), false, "Broken.", false, true, true); ses.beginTransaction(); ses.save(existRig); ses.getTransaction().commit(); ses.flush(); ses.evict(existRig); assertFalse(this.register.registerRig(name, type, caps, contactUrl)); RigCapabilities capsRec = new RigCapabilitiesDao(ses).findCapabilites(caps); RigType typeRec = new RigTypeDao(ses).findByName(type); Rig rigRec = new RigDao(ses).findByName(name); /* Cleanup. */ ses.beginTransaction(); ses.createQuery("DELETE FROM RigLog WHERE rig='" + rigRec.getId() + "'").executeUpdate(); ses.getTransaction().commit(); ses.beginTransaction(); ses.delete(rigRec); ses.delete(capsRec); ses.delete(typeRec); ses.getTransaction().commit(); assertEquals("Exists", this.register.getFailedReason()); }
From source file:beans.Driver.java
public static void main(String[] args) { Student s = new Student(); s.setId(4);/*from w ww . ja v a2 s . co m*/ s.setName("Amjad"); try { Configuration cf = new Configuration(); cf.configure("xml/hibernate.cfg.xml"); SessionFactory sf = cf.buildSessionFactory(); Session ses = sf.openSession(); ses.save(s); ses.beginTransaction().commit(); ses.evict(s); ses.close(); // // ses = sf.openSession(); // s = (Student)ses.get(Student.class, 1); // System.out.println("Name="+s.getName()); // System.out.println("Id="+s.getId()); } catch (Exception e) { e.printStackTrace(); } }