List of usage examples for org.hibernate.cfg Configuration Configuration
public Configuration()
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 w w. j av a 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));//from w ww . j a v a 2s. 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 w w w . jav 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.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();/* w ww .j av a 2 s .c om*/ 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. c o 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
@RequestMapping(value = "/", method = RequestMethod.GET) public String sectionPage(@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(); Query query = session.createQuery("from Sekcja where Id_Klub=:id"); query.setParameter("id", idClub); List<Sekcja> sectionList = query.getResultList(); model.addAttribute("sectionList", sectionList); model.addAttribute("Club", idClub); session.close();/*ww w. j a va 2 s . c om*/ return "/section/show_section_view"; }
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);/*from w w w. java2s.c o m*/ t.commit(); session.close(); factory.close(); return new ModelAndView("redirect:/club/" + idClub + "/sections/"); }
From source file:com.mycompany.controllers.SectionController.java
@RequestMapping(value = "/create", method = RequestMethod.POST) public ModelAndView createsection(@Valid SectionForm sectionForm, @PathVariable("idClub") String idClub, Model model) {/* w w w. j a v a 2s. com*/ 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(idClub)); Sekcja section = new Sekcja(); section.setDyscyplina(sectionForm.getDiscipline()); section.setPlec(sectionForm.getSex()); section.setIdKlub(club); session.persist(section); t.commit(); session.close(); factory.close(); return new ModelAndView("redirect:/club/" + idClub + "/sections/"); }
From source file:com.mycompany.controllers.SectionController.java
@RequestMapping(value = "/edit/{idSection}", method = RequestMethod.GET) public String sectionEdit(SectionForm sectionForm, @PathVariable("idSection") String idSection, Model model) { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); //creating session object Session session = factory.openSession(); Sekcja section = session.find(Sekcja.class, Integer.parseInt(idSection)); model.addAttribute("section", section); session.close();/*from w w w . j a v a2 s. c o m*/ factory.close(); return "/section/edit_section_view"; }
From source file:com.mycompany.controllers.SectionController.java
@RequestMapping(value = "/edit/{idSection}", method = RequestMethod.POST) public ModelAndView sectionedit(@Valid SectionForm sectionForm, @PathVariable("idSection") String idSection, @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(); Sekcja section = session.find(Sekcja.class, Integer.parseInt(idSection)); section.setDyscyplina(sectionForm.getDiscipline()); section.setPlec(sectionForm.getSex()); session.update(section);//from ww w.j a va 2 s. c o m t.commit(); session.close(); factory.close(); return new ModelAndView("redirect:/club/" + section.getIdKlub() + "/sections/"); }