List of usage examples for org.hibernate SessionFactory openSession
Session openSession() throws HibernateException;
From source file:co.udea.edu.proyectointegrador.gr11.parqueaderoapp.data.dao.implement.UsuarioDaoImplement.java
@Override public Usuario getUsuario(String id) { Usuario retornaUsu = null;/* w ww.jav a2 s .c o m*/ try { SessionFactory sf = HibernateUtil.getSessionFactory(); session = sf.openSession(); retornaUsu = (Usuario) session.get(Usuario.class, id); session.close(); } catch (Exception e) { System.out.println(e.getMessage()); System.out.println(e.getCause()); } return retornaUsu; }
From source file:co.udea.edu.proyectointegrador.gr11.parqueaderoapp.data.dao.implement.UsuarioVehiculoDaoImplement.java
@Override public void insertarUsuarioVehiculo(UsuarioVehiculo usuarioVehiculo) { //Comienzo la transaccion try {//from w w w . j a v a 2s . c om SessionFactory sf = HibernateUtil.getSessionFactory(); session = sf.openSession(); transaction = session.beginTransaction(); session.save("UsuarioVehiculo", usuarioVehiculo); transaction.commit(); session.close(); } catch (Exception e) { transaction.rollback(); System.out.println(e.getMessage()); System.out.println(e.getCause()); } }
From source file:co.udea.edu.proyectointegrador.gr11.parqueaderoapp.data.dao.implement.UsuarioVehiculoDaoImplement.java
@Override public List<UsuarioVehiculo> getUsuarioVehiculo(String identificacion) { List<UsuarioVehiculo> vehiculosUser = null;//vehiculos del usuario try {/*from w ww .j a v a 2s. c om*/ SessionFactory sf = HibernateUtil.getSessionFactory(); session = sf.openSession(); //Consulta vehiculos del usuario x String hql = "from UsuarioVehiculo u where u.id.usuarioIdentificacion=:identificacion"; vehiculosUser = session.createQuery(hql).setParameter("identificacion", identificacion).list(); session.close(); } catch (Exception e) { System.out.println(e.getMessage()); System.out.println(e.getCause()); } return vehiculosUser; }
From source file:co.udea.edu.proyectointegrador.gr11.parqueaderoapp.data.dao.implement.VehiculoDaoImplement.java
@Override public void insertarVehiculo(Vehiculo vehiculo) { //Comienzo la transaccion try {//from ww w. jav a2 s .c o m SessionFactory sf = HibernateUtil.getSessionFactory(); session = sf.openSession(); transaction = session.beginTransaction(); session.save("Vehiculo", vehiculo); transaction.commit(); session.close(); } catch (Exception e) { transaction.rollback(); System.out.println(e.getMessage()); System.out.println(e.getCause()); } }
From source file:co.udea.edu.proyectointegrador.gr11.parqueaderoapp.data.dao.implement.VehiculoDaoImplement.java
@Override public Vehiculo getVehiculo(String placa) { Vehiculo nuevoVehi = null;/*from ww w . ja v a 2 s.c om*/ try { SessionFactory sf = HibernateUtil.getSessionFactory(); session = sf.openSession(); nuevoVehi = (Vehiculo) session.get(Vehiculo.class, placa); session.close(); } catch (Exception e) { System.out.println(e.getMessage()); System.out.println(e.getCause()); } return nuevoVehi; }
From source file:com.abiquo.abiserver.abicloudws.InfrastructureWSTest.java
License:Mozilla Public License
private VirtualMachine getVirtualImageFromDb(int virtualMachineId) { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = sessionFactory.openSession(); Transaction transaction = session.getTransaction(); transaction.begin();/*from w ww . j a v a 2 s.c o m*/ VirtualmachineHB virtualMachinePojo = (VirtualmachineHB) session.get(VirtualmachineHB.class, virtualMachineId); VirtualMachine virtualMachine = new VirtualMachine(); virtualMachine.setCpu(virtualMachinePojo.getCpu()); virtualMachine.setDescription(virtualMachinePojo.getDescription()); virtualMachine.setHd(virtualMachine.getHd()); virtualMachine.setHighDisponibility(virtualMachinePojo.getHighDisponibility() != 0); virtualMachine.setId(virtualMachinePojo.getIdVm()); virtualMachine.setName(virtualMachinePojo.getName()); virtualMachine.setRam(virtualMachinePojo.getRam()); State state = new State(); state.setId(virtualMachinePojo.getState().getIdState()); state.setDescription(virtualMachinePojo.getState().getDescription()); virtualMachine.setState(state); virtualMachine.setUUID(virtualMachinePojo.getUuid()); virtualMachine.setVdrpIP(virtualMachinePojo.getVdrpIp()); virtualMachine.setVdrpPort(virtualMachinePojo.getVdrpPort()); VirtualimageHB virtualimagePojo = virtualMachinePojo.getImage(); VirtualImage virtualImage = new VirtualImage(); virtualImage.setName(virtualimagePojo.getName()); virtualImage.setPath(virtualimagePojo.getPathName()); virtualMachine.setVirtualImage(virtualImage); // Setting the hypervisor HypervisorHB hypervisorPojo = virtualMachinePojo.getHypervisor(); HyperVisor hypervisor = new HyperVisor(); hypervisor.setIp(hypervisorPojo.getIp()); hypervisor.setPort(hypervisorPojo.getPort()); hypervisor.setName(hypervisorPojo.getType().getName()); virtualMachine.setAssignedTo(hypervisor); transaction.commit(); return virtualMachine; }
From source file:com.abiquo.abiserver.commands.InfrastructureCommand.java
License:Mozilla Public License
/** * Deletes the virtual machine. 1. From the data base 2. Connect with AbiCloud WS to delete it * from the Physical Machine/*from w w w. j ava2 s . co m*/ * * @param virtualMachine * @return */ protected BasicResult deleteVirtualMachine(VirtualMachine virtualMachine) { // TODO Connect with database BasicResult basicResult = null; InfrastructureWS infrWS = null; VirtualmachineHB virtualMachinePojo = null; Transaction transaction = null; try { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = sessionFactory.openSession(); transaction = session.getTransaction(); transaction.begin(); infrWS = new InfrastructureWS(); virtualMachinePojo = (VirtualmachineHB) session.get(VirtualmachineHB.class, virtualMachine.getId()); session.delete(virtualMachinePojo); basicResult = infrWS.deleteVirtualMachine(virtualMachine); } catch (Exception e) { this.errorManager.reportError(resourceManager, basicResult, "deleteVirtualMachine", e); } if (basicResult.getSuccess()) { transaction.commit(); } return basicResult; }
From source file:com.Accenture.DAO.AssessmentDAO.java
public void updateforceA(AssessmentPojo a) { Session session = null;//from w ww. jav a 2 s. c om SessionFactory sessionFactory = new org.hibernate.cfg.Configuration().configure().buildSessionFactory(); session = sessionFactory.openSession(); session.beginTransaction(); session.update(a); session.getTransaction().commit(); session.flush(); session.close(); }
From source file:com.Accenture.DAO.AssessmentDAO.java
public void DeleteAssess(int id) { Session session;//from ww w .j a v a2 s . c om SessionFactory sessionfactory = new org.hibernate.cfg.Configuration().configure().buildSessionFactory(); session = sessionfactory.openSession(); session.beginTransaction(); String hgl = "delete from AssessmentPojo where assessID = :id"; org.hibernate.Query query = session.createQuery(hgl); query.setParameter("id", id); query.executeUpdate(); }
From source file:com.Accenture.DAO.feedbackDao.java
public void updateforceg(feedbackpojo f) { Session session = null;//from w w w. j a v a 2 s. co m SessionFactory sessionFactory = new org.hibernate.cfg.Configuration().configure().buildSessionFactory(); session = sessionFactory.openSession(); session.beginTransaction(); session.update(f); session.getTransaction().commit(); session.flush(); session.close(); }