List of usage examples for org.hibernate SessionFactory close
void close() throws HibernateException;
From source file:com.mycompany.controllers.LeagueController.java
@GetMapping("/remove/{idLeague}") public ModelAndView removeLeague(Model model, @PathVariable("idLeague") String idLeague) { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); //creating session object Session session = factory.openSession(); Transaction t = session.beginTransaction(); Liga league = session.find(Liga.class, Integer.parseInt(idLeague)); session.remove(league);//from ww w. j av a2 s.com t.commit(); session.close(); factory.close(); return new ModelAndView("redirect:/leagues/"); }
From source file:com.mycompany.controllers.MainController.java
@RequestMapping({ "/home", "/" }) public String homePage(Model model) { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); //creating session object Session session = factory.openSession(); List<Klub> clubList = session.createCriteria(Klub.class).list(); model.addAttribute("clubList", clubList); session.close();// www .ja v a 2s. co m factory.close(); return "/home_view"; }
From source file:com.mycompany.controllers.PlayerController.java
@GetMapping("/remove/{idPlayer}") public ModelAndView removePlayer(Model model, @PathVariable("idClub") String idClub, @PathVariable("idSection") String idSection, @PathVariable("idTeam") String idTeam, @PathVariable("idPlayer") String idPlayer) { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); Session session = factory.openSession(); Transaction t = session.beginTransaction(); Zawodnik player = session.find(Zawodnik.class, Integer.parseInt(idPlayer)); session.remove(player);/*from w w w . j av a 2 s . c o m*/ t.commit(); session.close(); factory.close(); return new ModelAndView( "redirect:/club/" + idClub + "/sections/" + idSection + "/teams/" + idTeam + "/players/"); }
From source file:com.mycompany.controllers.PlayerController.java
@RequestMapping(value = "/create", method = RequestMethod.POST) public ModelAndView createplayer(@Valid PlayerForm playerForm, @PathVariable("idClub") String idClub, @PathVariable("idSection") String idSection, @PathVariable("idTeam") String idTeam, Model model) throws ParseException { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); Session session = factory.openSession(); Transaction t = session.beginTransaction(); Druzyna team = session.find(Druzyna.class, Integer.parseInt(idTeam)); Zawodnik player = new Zawodnik(); player.setImie(playerForm.getName()); String year = playerForm.getYear(); String day = playerForm.getDay(); String month = playerForm.getMonth(); DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); StringBuilder s = new StringBuilder(year); s.append("-"); s.append(month);// w w w. j a v a2s .co m s.append("-"); s.append(day); Date myDate = formatter.parse(s.toString()); java.sql.Date sqlDate = new java.sql.Date(myDate.getTime()); player.setDataUrodzenia(sqlDate); player.setNazwisko(playerForm.getLastname()); player.setWaga(Integer.parseInt(playerForm.getWeight())); player.setWzrost(Integer.parseInt(playerForm.getHeight())); player.setIdDruzyna(team); session.persist(player); t.commit(); session.close(); factory.close(); return new ModelAndView( "redirect:/club/" + idClub + "/sections/" + idSection + "/teams/" + idTeam + "/players/"); }
From source file:com.mycompany.controllers.PlayerStatisticsController.java
@RequestMapping(value = "/", method = RequestMethod.GET) public String showPlayerStatistics(@PathVariable("idClub") String idClub, @PathVariable("idSection") String idSection, @PathVariable("idTeam") String idTeam, @PathVariable("idPlayer") String idPlayer, Model model) { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); Session session = factory.openSession(); Query query = session.createQuery("from ZawodnikStatystyki where id_zawodnik=:id"); query.setParameter("id", idPlayer); List<ZawodnikStatystyki> statisticsList = query.getResultList(); Zawodnik player = session.find(Zawodnik.class, Integer.parseInt(idPlayer)); model.addAttribute("statisticsList", statisticsList); model.addAttribute("Club", idClub); model.addAttribute("Team", idTeam); model.addAttribute("Section", idSection); model.addAttribute("Player", player); session.close();/*w ww . ja va 2s .c o m*/ factory.close(); return "player/show_concreteplayer_view"; }
From source file:com.mycompany.controllers.PlayerStatisticsController.java
@RequestMapping(value = "/edit/{idSeason}", method = RequestMethod.POST) public ModelAndView editPlayerStatistics(@Valid PlayerStatisticsForm playerStatisticsForm, @PathVariable("idClub") String idClub, @PathVariable("idSection") String idSection, @PathVariable("idTeam") String idTeam, Model model, @PathVariable("idPlayer") String idPlayer, @PathVariable("idSeason") String idSeason) throws ParseException { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); Session session = factory.openSession(); Transaction t = session.beginTransaction(); Query query = session.createQuery("from ZawodnikStatystyki where id_zawodnik=:id and id_sezon=:ids"); query.setParameter("id", idPlayer); query.setParameter("ids", idSeason); List<ZawodnikStatystyki> statistic = query.getResultList(); statistic.get(0).setCzerwoneKartki(Integer.parseInt(playerStatisticsForm.getRedCards())); statistic.get(0).setZolteKartki(Integer.parseInt(playerStatisticsForm.getYellowCards())); statistic.get(0).setRozegraneMinuty(Integer.parseInt(playerStatisticsForm.getMinutesPlayed())); statistic.get(0).setFaule(Integer.parseInt(playerStatisticsForm.getFaulsCommited())); statistic.get(0).setStrzeloneBramki(Integer.parseInt(playerStatisticsForm.getScoredGoals())); statistic.get(0).setStraconeBramki(Integer.parseInt(playerStatisticsForm.getLostGoals())); session.persist(statistic.get(0));// w w w . j av a 2 s . c om t.commit(); session.close(); factory.close(); return new ModelAndView("redirect:/club/" + idClub + "/sections/" + idSection + "/teams/" + idTeam + "/players/" + idPlayer + "/"); }
From source file:com.mycompany.controllers.PlayerStatisticsController.java
@GetMapping("/remove/{idSeason}") public ModelAndView removeStatitics(Model model, @PathVariable("idClub") String idClub, @PathVariable("idSection") String idSection, @PathVariable("idTeam") String idTeam, @PathVariable("idPlayer") String idPlayer, @PathVariable("idSeason") String idSeason) { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); Session session = factory.openSession(); Transaction t = session.beginTransaction(); Query query = session.createQuery("from ZawodnikStatystyki where id_zawodnik=:id and id_sezon=:ids"); query.setParameter("id", idPlayer); query.setParameter("ids", idSeason); List<ZawodnikStatystyki> statistic = query.getResultList(); session.remove(statistic.get(0));/*from ww w. java2s. c om*/ t.commit(); session.close(); factory.close(); return new ModelAndView("redirect:/club/" + idClub + "/sections/" + idSection + "/teams/" + idTeam + "/players/" + idPlayer + "/"); }
From source file:com.mycompany.controllers.PlayerStatisticsController.java
@GetMapping("/create/") public String createStatistics(PlayerStatisticsForm playerStatisticsForm, Model model, @PathVariable("idTeam") String idTeam, @PathVariable("idClub") String idClub, @PathVariable("idSection") String idSection, @PathVariable("idPlayer") String idPlayer) { model.addAttribute("Section", idSection); model.addAttribute("Club", idClub); model.addAttribute("Team", idTeam); model.addAttribute("Player", idPlayer); Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); Session session = factory.openSession(); Transaction t = session.beginTransaction(); List<Sezon> seasonList = session.createCriteria(Sezon.class).list(); System.out.println("" + seasonList.size()); model.addAttribute("seasonList", seasonList); t.commit();//from ww w .ja v a 2s .c o m session.close(); factory.close(); return "/player/create_playerstatistics_view"; }
From source file:com.mycompany.controllers.PlayerStatisticsController.java
@RequestMapping(value = "/create", method = RequestMethod.POST) public ModelAndView createstatistics(PlayerStatisticsForm playerStatisticsForm, Model model, @PathVariable("idTeam") String idTeam, @PathVariable("idClub") String idClub, @PathVariable("idSection") String idSection, @PathVariable("idPlayer") String idPlayer) { model.addAttribute("Section", idSection); model.addAttribute("Club", idClub); model.addAttribute("Team", idTeam); model.addAttribute("Player", idPlayer); Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); Session session = factory.openSession(); Transaction t = session.beginTransaction(); ZawodnikStatystyki playerStatistics = new ZawodnikStatystyki(); playerStatistics.setCzerwoneKartki(Integer.parseInt(playerStatisticsForm.getRedCards())); playerStatistics.setZolteKartki(Integer.parseInt(playerStatisticsForm.getYellowCards())); playerStatistics.setRozegraneMinuty(Integer.parseInt(playerStatisticsForm.getMinutesPlayed())); playerStatistics.setFaule(Integer.parseInt(playerStatisticsForm.getFaulsCommited())); playerStatistics.setStrzeloneBramki(Integer.parseInt(playerStatisticsForm.getScoredGoals())); playerStatistics.setStraconeBramki(Integer.parseInt(playerStatisticsForm.getLostGoals())); Query query = session.createQuery("from Sezon where rok=:rok"); query.setParameter("rok", Integer.parseInt(playerStatisticsForm.getSeason())); List<Sezon> seasonList = query.getResultList(); playerStatistics.setSezon(seasonList.get(0)); ZawodnikStatystykiPK zspk = new ZawodnikStatystykiPK(Integer.parseInt(idPlayer), seasonList.get(0).getIdSezon()); playerStatistics.setZawodnikStatystykiPK(zspk); session.persist(playerStatistics);//from w w w . j a v a 2 s. co m t.commit(); session.close(); factory.close(); return new ModelAndView("redirect:/club/" + idClub + "/sections/" + idSection + "/teams/" + idTeam + "/players/" + idPlayer + "/"); }
From source file:com.mycompany.controllers.SectionController.java
@GetMapping("/remove/{idSection}") public ModelAndView removeSection(Model model, @PathVariable("idClub") String idClub, @PathVariable("idSection") String idSection) { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); Session session = factory.openSession(); Transaction t = session.beginTransaction(); Sekcja section = session.find(Sekcja.class, Integer.parseInt(idSection)); session.remove(section);/* w w w .java 2 s. co m*/ t.commit(); session.close(); factory.close(); return new ModelAndView("redirect:/club/" + idClub + "/sections/"); }