List of usage examples for org.hibernate Session get
Object get(String entityName, Serializable id);
From source file:cimitero.rest.CemetryGroundRESTService.java
@POST public ResponseDto updateCemetryGround(CemetryGroundDto cemetryGroundDto) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();// ww w. j a va2s . com TCemetryGround tmpCemetryGround = new TCemetryGround(cemetryGroundDto.getCemetryGroundId(), cemetryGroundDto.getName(), cemetryGroundDto.getAddress()); TCemetry tmpCemetry = (TCemetry) session.get(TCemetry.class, cemetryGroundDto.getCemetryId()); tmpCemetryGround.setCemetry(tmpCemetry); if (cemetryGroundDto.getCemetryGroundId() == -1) tmpCemetryGround.setCemetryGroundId(null); session.saveOrUpdate(tmpCemetryGround); ResponseDto response = new ResponseDto(true); session.getTransaction().commit(); return response; }
From source file:cimitero.rest.CemetryGroundRESTService.java
@DELETE @Path("{id}") public ResponseDto removeCemetryGround(@PathParam("id") Integer id) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/* ww w. j av a 2 s . co m*/ TCemetryGround result = (TCemetryGround) session.get(TCemetryGround.class, id); session.delete(result); ResponseDto response = new ResponseDto(true); session.getTransaction().commit(); return response; }
From source file:cimitero.rest.CemetryGroundRESTService.java
@POST @Path("/{cemetryGroundId}/borders") public ResponseDto setCemetryGroundBorders(@PathParam("cemetryGroundId") Integer cemetryGroundId, List<CoordinateDto> coordinates) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();//from w w w . j a v a2 s . c o m TCemetryGround tmpCemetryGround = (TCemetryGround) session.get(TCemetryGround.class, cemetryGroundId); ResponseDto response = new ResponseDto(true); if (tmpCemetryGround == null) { response.setOk(false); response.addError(1, "there is no cemetry ground with id " + cemetryGroundId); } else { for (TCoordinate coordToDelete : tmpCemetryGround.getBoundaryCoordinates()) { session.delete(coordToDelete); } List<TCoordinate> coordinatesList = new ArrayList<TCoordinate>(); for (CoordinateDto coordinate : coordinates) { TCoordinate coord = new TCoordinate(coordinate.getX(), coordinate.getY()); coord.setCemetryGroundBoundary(tmpCemetryGround); session.save(coord); coordinatesList.add(coord); } tmpCemetryGround.setBoundaryCoordinates(coordinatesList); } session.getTransaction().commit(); return response; }
From source file:cimitero.rest.CemetryGroundRESTService.java
@GET @Path("/{cemetryGroundId}/borders") public ResponseDto getCemetryGroundBorders(@PathParam("cemetryGroundId") Integer cemetryGroundId) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/*w w w. j ava 2 s . c o m*/ TCemetryGround tmpCemetryGround = (TCemetryGround) session.get(TCemetryGround.class, cemetryGroundId); ResponseDto response = new ResponseDto(true); if (tmpCemetryGround == null) { response.setOk(false); response.addError(1, "there is no cemetry ground with id " + cemetryGroundId); } else { List<CoordinateDto> coordinatesList = new ArrayList<CoordinateDto>(); for (TCoordinate coordinate : tmpCemetryGround.getBoundaryCoordinates()) { coordinatesList.add(new CoordinateDto(coordinate.getX(), coordinate.getY())); } response.setItems(new ItemWrapper<CoordinateDto>(coordinatesList)); } session.getTransaction().commit(); return response; }
From source file:cimitero.rest.CemetryGroundRESTService.java
@POST @Path("/{cemetryGroundId}/track") public ResponseDto setCemetryGroundTrack(@PathParam("cemetryGroundId") Integer cemetryGroundId, List<CoordinateDto> coordinates) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();//from w w w . j a v a2 s .c om TCemetryGround tmpCemetryGround = (TCemetryGround) session.get(TCemetryGround.class, cemetryGroundId); ResponseDto response = new ResponseDto(true); if (tmpCemetryGround == null) { response.setOk(false); response.addError(1, "there is no cemetry ground with id " + cemetryGroundId); } else { for (TCoordinate coordToDelete : tmpCemetryGround.getTrackCoordinates()) { session.delete(coordToDelete); } List<TCoordinate> coordinatesList = new ArrayList<TCoordinate>(); for (CoordinateDto coordinate : coordinates) { TCoordinate coord = new TCoordinate(coordinate.getX(), coordinate.getY()); coord.setCemetryGroundTrack(tmpCemetryGround); session.save(coord); coordinatesList.add(coord); } tmpCemetryGround.setTrackCoordinates(coordinatesList); } session.getTransaction().commit(); return response; }
From source file:cimitero.rest.CemetryGroundRESTService.java
@GET @Path("/{cemetryGroundId}/track") public ResponseDto getCemetryGroundTrack(@PathParam("cemetryGroundId") Integer cemetryGroundId) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();// w w w . j a va2 s . c o m TCemetryGround tmpCemetryGround = (TCemetryGround) session.get(TCemetryGround.class, cemetryGroundId); ResponseDto response = new ResponseDto(true); if (tmpCemetryGround == null) { response.setOk(false); response.addError(1, "there is no cemetry ground with id " + cemetryGroundId); } else { List<CoordinateDto> coordinatesList = new ArrayList<CoordinateDto>(); for (TCoordinate coordinate : tmpCemetryGround.getTrackCoordinates()) { coordinatesList.add(new CoordinateDto(coordinate.getX(), coordinate.getY())); } response.setItems(new ItemWrapper<CoordinateDto>(coordinatesList)); } session.getTransaction().commit(); return response; }
From source file:cimitero.rest.CemetryGroundRESTService.java
@POST @Path("/{cemetryGroundId}/tombcoords") public ResponseDto setCemetryGroundTombCoords(@PathParam("cemetryGroundId") Integer cemetryGroundId, List<TombCoordinateDto> coordinates) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/*ww w .j ava2s .c om*/ TCemetryGround tmpCemetryGround = (TCemetryGround) session.get(TCemetryGround.class, cemetryGroundId); ResponseDto response = new ResponseDto(true); if (tmpCemetryGround == null) { response.setOk(false); response.addError(1, "there is no cemetry ground with id " + cemetryGroundId); } else { List<TTomb> tombs = tmpCemetryGround.getTombs(); if (!coordinates.isEmpty()) { for (TombCoordinateDto tomb : coordinates) { TTomb found = null; for (TTomb savedTomb : tombs) { if (savedTomb.getTombNo().equals(tomb.getTombNo())) found = savedTomb; } if (found != null) { if (found.getCoordinate() != null) { found.getCoordinate().setX(tomb.getX()); found.getCoordinate().setY(tomb.getY()); found.getCoordinate().setIsDouble(tomb.isIsSupersized()); } else { TCoordinate newCoord = new TCoordinate(tomb.getX(), tomb.getY()); newCoord.setIsDouble(tomb.isIsSupersized()); session.save(newCoord); found.setCoordinate(newCoord); } } else { TCoordinate tmpCoord = new TCoordinate(tomb.getX(), tomb.getY()); tmpCoord.setIsDouble(tomb.isIsSupersized()); session.save(tmpCoord); TTomb newTomb = new TTomb(tomb.getTombNo()); newTomb.setCoordinate(tmpCoord); newTomb.setCemetryGround(tmpCemetryGround); session.save(newTomb); } } } else { if (!tombs.isEmpty()) { for (TTomb tomb : tombs) { if (tomb.getCoordinate() != null) { tomb.getCoordinate().setTomb(null); } } } } } session.getTransaction().commit(); return response; }
From source file:cimitero.rest.CemetryGroundRESTService.java
@GET @Path("/{cemetryGroundId}/tombcoords") public ResponseDto getCemetryGroundTombCoords(@PathParam("cemetryGroundId") Integer cemetryGroundId) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();/* ww w.j av a 2 s .c om*/ TCemetryGround tmpCemetryGround = (TCemetryGround) session.get(TCemetryGround.class, cemetryGroundId); ResponseDto response = new ResponseDto(true); if (tmpCemetryGround == null) { response.setOk(false); response.addError(1, "there is no cemetry ground with id " + cemetryGroundId); } else { List<TombCoordinateDto> coordinatesList = new ArrayList<TombCoordinateDto>(); for (TTomb tomb : tmpCemetryGround.getTombs()) { if (tomb.getCoordinate() != null) { coordinatesList.add(new TombCoordinateDto(tomb.getCoordinate().getX(), tomb.getCoordinate().getY(), tomb.getTombNo(), tomb.getCoordinate().isIsDouble())); } } response.setItems(new ItemWrapper<TombCoordinateDto>(coordinatesList)); } session.getTransaction().commit(); return response; }
From source file:cimitero.rest.CemetryRESTService.java
@GET @Path("{id}") public ResponseDto getCemetryById(@PathParam("id") Integer id) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();//from w w w .ja v a 2 s . c om TCemetry result = (TCemetry) session.get(TCemetry.class, id); ResponseDto response = new ResponseDto(true); if (result == null) { response.setOk(false); response.addError(1, "cemetry with id " + id + " not found"); } else { List<TCemetry> results = new ArrayList<TCemetry>(); results.add(result); response.setItems(new ItemWrapper(results)); } session.getTransaction().commit(); return response; }
From source file:cimitero.rest.CemetryRESTService.java
@DELETE @Path("{id}") public ResponseDto removeCemetry(@PathParam("id") Integer id) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();// w w w . ja va 2s . c o m TCemetry result = (TCemetry) session.get(TCemetry.class, id); session.delete(result); ResponseDto response = new ResponseDto(true); session.getTransaction().commit(); return response; }