List of usage examples for org.hibernate Session flush
void flush() throws HibernateException;
From source file:com.abiquo.abiserver.persistence.dao.workload.hibernate.EnterpriseExclusionRuleDAOTest.java
License:Open Source License
@Test public void test_findMachinesWithVMsFromExcludedEnterprises() { Session session = createSessionInTransaction(); DatacenterHB datacenter = TestEntityGenerationUtils.createDatacenter("datacenter1"); RackHB rack = TestEntityGenerationUtils.createRack(datacenter, "rack1"); PhysicalmachineHB machine = TestEntityGenerationUtils.createMachine(rack, "machine1"); HypervisorHB hypervisor = TestEntityGenerationUtils.createHypervisor("hypervisorDesc", machine, HypervisorType.VBOX);//from w w w . j a v a 2 s . co m EnterpriseHB enterprise = TestEntityGenerationUtils.createEnterprise("enterprise1"); EnterpriseHB enterprise2 = TestEntityGenerationUtils.createEnterprise("enterprise2"); EnterpriseHB enterprise3 = TestEntityGenerationUtils.createEnterprise("enterprise3"); SessionUtils.saveAndFlush(session, datacenter, rack, machine, hypervisor, enterprise, enterprise2, enterprise3); // We have a machine that might fit, but...it has no VMs => not returned EnterpriseExclusionRuleDAO dao = TestDAOHelper.createEnterpriseExclusionRuleDAO(session); Assert.assertTrue(dao.findMachinesWithVMsFromExcludedEnterprises(enterprise).isEmpty()); // We have a machine with a VM, but does not belong to 'excluded' enterprise VirtualmachineHB vm = TestEntityGenerationUtils.createVirtualmachine("vm1"); vm.setHypervisor(hypervisor); vm.setEnterpriseHB(enterprise2); SessionUtils.saveAndFlush(session, vm); Assert.assertTrue(dao.findMachinesWithVMsFromExcludedEnterprises(enterprise).isEmpty()); // We have a machine with a VM, but belongs to 'excluded' enterprise: return it EnterpriseExclusionRuleHB rule = new EnterpriseExclusionRuleHB(enterprise, enterprise2); SessionUtils.saveAndFlush(session, rule); AssertUtils.assertContainsAllAndOnly(dao.findMachinesWithVMsFromExcludedEnterprises(enterprise), machine); // We add another machine, associated to a non-excluded enterprise: do not return it PhysicalmachineHB machine2 = TestEntityGenerationUtils.createMachine(rack, "machine2"); VirtualmachineHB vm2 = TestEntityGenerationUtils.createVirtualmachine("vm2"); HypervisorHB hypervisor2 = TestEntityGenerationUtils.createHypervisor("hypervisor2Desc", machine2, HypervisorType.VMX_04); vm2.setHypervisor(hypervisor2); vm2.setEnterpriseHB(enterprise3); SessionUtils.saveAndFlush(session, machine2, hypervisor2, vm2); AssertUtils.assertContainsAllAndOnly(dao.findMachinesWithVMsFromExcludedEnterprises(enterprise), machine); // Exclude enterprise to which machine2 belongs: then it will be one of the forbidden // machines EnterpriseExclusionRuleHB rule2 = new EnterpriseExclusionRuleHB(enterprise3, enterprise); SessionUtils.saveAndFlush(session, rule2); AssertUtils.assertContainsAllAndOnly(dao.findMachinesWithVMsFromExcludedEnterprises(enterprise), machine, machine2); // Remove VM deployed in machine2: it will not appear in query session.delete(vm); session.flush(); AssertUtils.assertContainsAllAndOnly(dao.findMachinesWithVMsFromExcludedEnterprises(enterprise), machine2); }
From source file:com.abiquo.abiserver.persistence.dao.workload.hibernate.EnterpriseExclusionRuleDAOTest.java
License:Open Source License
/** This test makes completely sure we have everything well worked out */ @Test// ww w . ja va 2 s. co m public void test_save() throws PersistenceException { Session session = createSessionInTransaction(); EnterpriseHB enterprise1 = TestEntityGenerationUtils.createEnterprise("enterprise1"); EnterpriseHB enterprise2 = TestEntityGenerationUtils.createEnterprise("enterprise2"); EnterpriseExclusionRuleHB rule = new EnterpriseExclusionRuleHB(enterprise1, enterprise2); EnterpriseExclusionRuleDAO dao = TestDAOHelper.createEnterpriseExclusionRuleDAO(session); SessionUtils.saveAndFlush(session, enterprise1, enterprise2); dao.makePersistent(rule); session.flush(); Assert.assertTrue(SessionUtils.entityExists(session, EnterpriseExclusionRuleHB.class, rule.getId())); }
From source file:com.abiquo.abiserver.persistence.dao.workload.hibernate.MachineLoadRuleDAOTest.java
License:Open Source License
/** This test makes completely sure we have everything well mapped */ @Test/* www. j a v a 2s . c o m*/ public void test_save() throws PersistenceException { Session session = createSessionInTransaction(); DatacenterHB datacenter = TestEntityGenerationUtils.createDatacenter("datacenter1"); MachineLoadRuleHB rule = new MachineLoadRuleHB(datacenter, null, null, 90, 90); MachineLoadRuleDAO dao = TestDAOHelper.createMachineLoadRuleDAO(session); SessionUtils.saveAndFlush(session, datacenter); dao.makePersistent(rule); session.flush(); Assert.assertTrue(SessionUtils.entityExists(session, MachineLoadRuleHB.class, rule.getId())); }
From source file:com.abiquo.abiserver.persistence.SessionUtils.java
License:Open Source License
public static void saveAndFlush(Session session, Object... entities) { assert session != null; assert entities != null; for (Object entity : entities) { assert entity != null; session.save(entity);/*from w w w . j ava 2s.c o m*/ } session.flush(); }
From source file:com.Accenture.DAO.AssessmentDAO.java
public void updateforceA(AssessmentPojo a) { Session session = null; SessionFactory sessionFactory = new org.hibernate.cfg.Configuration().configure().buildSessionFactory(); session = sessionFactory.openSession(); session.beginTransaction();// www . ja v a 2 s . com session.update(a); session.getTransaction().commit(); session.flush(); session.close(); }
From source file:com.Accenture.DAO.feedbackDao.java
public void updateforceg(feedbackpojo f) { Session session = null; SessionFactory sessionFactory = new org.hibernate.cfg.Configuration().configure().buildSessionFactory(); session = sessionFactory.openSession(); session.beginTransaction();/* w w w.j a va 2 s. c o m*/ session.update(f); session.getTransaction().commit(); session.flush(); session.close(); }
From source file:com.Accenture.DAO.feedbackDao.java
public void deleteforceg(feedbackpojo f) { Session session = null; SessionFactory sessionFactory = new org.hibernate.cfg.Configuration().configure().buildSessionFactory(); session = sessionFactory.openSession(); session.beginTransaction();/*from w w w . j a va 2 s . c o m*/ session.delete(f); session.getTransaction().commit(); session.flush(); session.close(); }
From source file:com.Accenture.DAO.groupDao.java
public void updateforceg(grouppojo e) { Session session = null; SessionFactory sessionFactory = new org.hibernate.cfg.Configuration().configure().buildSessionFactory(); session = sessionFactory.openSession(); session.beginTransaction();// w w w.j av a 2 s . co m session.update(e); session.getTransaction().commit(); session.flush(); session.close(); }
From source file:com.Accenture.DAO.groupDao.java
public void deleteforceg(grouppojo e) { Session session = null; SessionFactory sessionFactory = new org.hibernate.cfg.Configuration().configure().buildSessionFactory(); session = sessionFactory.openSession(); session.beginTransaction();/*from ww w .jav a 2s.co m*/ session.delete(e); session.getTransaction().commit(); session.flush(); session.close(); }
From source file:com.Accenture.DAO.LearnerAssessmentDAO.java
public void updateforce(LearnerAssessmentPojo l) { Session session = null; SessionFactory sessionFactory = new org.hibernate.cfg.Configuration().configure().buildSessionFactory(); session = sessionFactory.openSession(); session.beginTransaction();/*from w w w . j av a2s. co m*/ session.update(l); session.getTransaction().commit(); session.flush(); session.close(); }