List of usage examples for org.hibernate.cfg Configuration Configuration
public Configuration()
From source file:com.mycompany.controllers.BuildingController.java
@RequestMapping(value = "/edit/{idBuilding}", method = RequestMethod.POST) public ModelAndView buildingedit(@Valid BuildingForm buildingForm, @PathVariable("idBuilding") String idBuilding, @PathVariable("idClub") String idClub, Model model) { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); //creating session object Session session = factory.openSession(); Transaction t = session.beginTransaction(); Budynek building = session.find(Budynek.class, Integer.parseInt(idBuilding)); if (building.getStadion() != null) { Stadion arena = session.find(Stadion.class, Integer.parseInt(idBuilding)); arena.setDyscyplina(buildingForm.getDiscipline()); arena.setIloscMiejsc(Integer.parseInt(buildingForm.getCapacity())); arena.setNazwa(buildingForm.getName()); session.update(arena);// w w w .ja va 2 s.c om } if (building.getObiektTreningowy() != null) { model.addAttribute("bTrainingObject", building.getObiektTreningowy()); } building.setKodPocztowy(buildingForm.getPostcode()); building.setMiejscowosc(buildingForm.getCity()); building.setUlicanumer(buildingForm.getStreet()); session.update(building); t.commit(); session.close(); factory.close(); return new ModelAndView("redirect:/club/" + idClub + "/buildings/"); }
From source file:com.mycompany.controllers.BuildingController.java
@GetMapping("/remove/{idBuilding}") public ModelAndView removeClub(Model model, @PathVariable("idClub") String idClub, @PathVariable("idBuilding") String idBuilding) { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); //creating session object Session session = factory.openSession(); Transaction t = session.beginTransaction(); Budynek building = session.find(Budynek.class, Integer.parseInt(idBuilding)); session.remove(building);//from www . j a va 2 s . c o m t.commit(); log.info("dziaa"); session.close(); factory.close(); return new ModelAndView("redirect:/club/" + idClub + "/buildings/"); }
From source file:com.mycompany.controllers.BuildingController.java
@RequestMapping(value = "/create", method = RequestMethod.POST) public ModelAndView createbuilding(@Valid BuildingForm buildingForm, @PathVariable("idClub") String idClub, Model model) {/*from w w w.j a va 2s . c om*/ Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); //creating session object Session session = factory.openSession(); Transaction t = session.beginTransaction(); Klub klub = session.find(Klub.class, Integer.parseInt(idClub)); Budynek building = new Budynek(); building.setKodPocztowy(buildingForm.getPostcode()); building.setMiejscowosc(buildingForm.getCity()); building.setUlicanumer(buildingForm.getStreet()); building.setIdKlub(klub); session.persist(building); if (buildingForm.getCapacity() != null) { Stadion arena = new Stadion(building.getIdbudynek()); arena.setDyscyplina(buildingForm.getDiscipline()); arena.setIloscMiejsc(Integer.parseInt(buildingForm.getCapacity())); arena.setNazwa(buildingForm.getName()); arena.setBudynek(building); session.persist(arena); } else if (buildingForm.getDiscipline() != null) { ObiektTreningowy ot = new ObiektTreningowy(building.getIdbudynek()); ot.setBudynek(building); session.persist(ot); } else { BudynekAdministracyjny ba = new BudynekAdministracyjny(building.getIdbudynek()); ba.setBudynek(building); session.persist(ba); } t.commit(); session.close(); factory.close(); return new ModelAndView("redirect:/club/" + idClub + "/buildings/"); }
From source file:com.mycompany.controllers.ClubController.java
@RequestMapping(value = "/{id}", method = RequestMethod.GET) public String clubPage(@PathVariable("id") String id, Model model) { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); //creating session object Session session = factory.openSession(); Klub club = session.find(Klub.class, Integer.parseInt(id)); model.addAttribute("club", club); session.close();//from ww w. j ava 2 s . co m factory.close(); return "/club/show_club_view"; }
From source file:com.mycompany.controllers.ClubController.java
@RequestMapping(value = "/image/{id}", method = RequestMethod.GET) @ResponseBody/* ww w. ja va 2 s . c o m*/ public byte[] clubPhoto(@PathVariable("id") String id) throws SQLException { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); //creating session object Session session = factory.openSession(); Klub club = session.find(Klub.class, Integer.parseInt(id)); session.close(); factory.close(); return club.getByteLogo(); }
From source file:com.mycompany.controllers.ClubController.java
@PostMapping("/create") @ResponseBody// w ww.j a v a 2 s . co m public ModelAndView createClub(@Valid ClubForm clubForm, BindingResult result, Model model) throws IOException { if (result.hasErrors()) { return new ModelAndView("redirect:/club/create"); } byte[] bytes; bytes = clubForm.getLogo().getBytes(); bytes = LogoConvertion(bytes); Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); Session session = factory.openSession(); Transaction t = session.beginTransaction(); Klub club = new Klub(); club.setNazwa(clubForm.getName()); LobCreator lcreator = Hibernate.getLobCreator(session); Blob blob = (Blob) lcreator.createBlob(bytes); club.setLogo(blob); session.persist(club); t.commit(); session.close(); factory.close(); model.addAttribute("club", club); return new ModelAndView("redirect:/club/" + club.getIdKlub()); }
From source file:com.mycompany.controllers.ClubController.java
@GetMapping("/{id}/edit") public String editClub(ClubForm clubForm, Model model, @PathVariable("id") String id) { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); //creating session object Session session = factory.openSession(); Klub club = session.find(Klub.class, Integer.parseInt(id)); model.addAttribute("club", club); session.close();/* ww w .j av a2s . co m*/ factory.close(); return "/club/edit_club_view"; }
From source file:com.mycompany.controllers.ClubController.java
@PostMapping("/{id}/edit") @ResponseBody/*from w w w. j a va 2 s . co m*/ public ModelAndView editClub(@Valid ClubForm clubForm, BindingResult result, Model model, @PathVariable("id") String id) throws IOException { if (result.hasErrors()) { return new ModelAndView("redirect:/club/" + id + "/edit"); } byte[] bytes; bytes = clubForm.getLogo().getBytes(); bytes = LogoConvertion(bytes); Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); Session session = factory.openSession(); Transaction t = session.beginTransaction(); Klub club = session.find(Klub.class, Integer.parseInt(id)); club.setNazwa(clubForm.getName()); LobCreator lcreator = Hibernate.getLobCreator(session); Blob blob = (Blob) lcreator.createBlob(bytes); club.setLogo(blob); session.update(club); t.commit(); session.close(); factory.close(); model.addAttribute("club", club); return new ModelAndView("redirect:/club/" + club.getIdKlub()); }
From source file:com.mycompany.controllers.ClubController.java
@GetMapping("/{id}/remove") public ModelAndView removeClub(Model model, @PathVariable("id") String id) { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); //creating session object Session session = factory.openSession(); Transaction t = session.beginTransaction(); Klub club = session.find(Klub.class, Integer.parseInt(id)); session.remove(club);/*from ww w. ja va 2s . c o m*/ t.commit(); session.close(); factory.close(); return new ModelAndView("redirect:/home"); }
From source file:com.mycompany.controllers.LeagueController.java
@RequestMapping(value = "/", method = RequestMethod.GET) public String leaguePage(Model model) { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); //creating session object Session session = factory.openSession(); List<Liga> leagueList = session.createCriteria(Liga.class).list(); model.addAttribute("leagueList", leagueList); session.close();/* w w w .j av a 2s.com*/ return "/league/show_leagues_view"; }