@Test public void testBigWork() throws Exception { PersistentTransaction transaction = PassPersistentManager.instance().getSession().beginTransaction(); System.out.println("BIGWORK"); for (int i = 0; i < 100; i++) { DefectClasses defectClass = DefectClassesFactory.createDefectClasses(); defectClass.setName("TEST-sample-x" + i); defectClass.save(); System.out.println("Saved " + i); Thread.sleep(10); } transaction.commit(); }
@Test public void testChainedTransactions() throws Exception { PersistentTransaction transaction = PassPersistentManager.instance().getSession().beginTransaction(); // Session session = // PassPersistentManager.instance().getSession().getSessionFactory().openSession(); // Transaction transaction2 = // PassPersistentManager.instance().getSession().getSessionFactory().openSession() // .beginTransaction(); try { System.out.println("Creating defect type 1..."); DefectTypes defectType = DefectTypesFactory.createDefectTypes(); defectType.setName("TEST-Мой тип"); defectType.setDefectImage(Utils.loadFromResource("resources/splash/slow.gif")); System.out.println("Creating defect class 1..."); DefectClasses defectClass = DefectClassesFactory.createDefectClasses(); assertEquals(0, defectClass.getIdDefectClass()); defectClass.setName("TEST-Новый отличный дефект"); defectClass.save(); // session.save(defectClass); assertFalse(0 == defectClass.getIdDefectClass()); System.out.println("Creating defect class 2..."); DefectClasses defectClass2 = DefectClassesFactory.createDefectClasses(); defectClass2.setName("TEST-Еще один прекрасный дефект"); defectClass2.save(); // session.save(defectClass2); assertFalse(0 == defectClass2.getIdDefectClass()); assertFalse(defectClass.getIdDefectClass() == defectClass2.getIdDefectClass()); // System.out.println("Commit classes..."); // transaction2.commit(); // assertTrue(transaction2.wasCommitted()); defectType.setDefectClass(defectClass); System.out.println("Saving type 1..."); defectType.save(); System.out.println("Creating defect type 2..."); DefectTypes defectType2 = DefectTypesFactory.createDefectTypes(); defectType2.setName("TEST-Мой второй тип дефекта"); defectType2.setDefectImage(Utils.loadFromResource("resources/splash/cool.jpg")); System.out.println("Creating defect class 3 auto..."); DefectClasses defectClass3 = DefectClassesFactory.createDefectClasses(); defectClass3.setName("TEST-Третий класс"); defectType2.setDefectClass(defectClass3); System.out.println("Saving type 2..."); defectType2.save(); System.out.println("Commit types..."); transaction.commit(); } catch (Exception e) { // transaction2.rollback(); transaction.rollback(); throw e; // } finally { // // //session.close(); // // transaction = PassPersistentManager.instance().getSession().beginTransaction(); // // DefectTypesCriteria tc = new DefectTypesCriteria(); // tc.name.ilike("TEST-%"); // for (DefectTypes t : DefectTypesFactory.listDefectTypesByCriteria(tc)) { // t.delete(); // } // // DefectClassesCriteria cc = new DefectClassesCriteria(); // cc.name.ilike("TEST-%"); // for (DefectClasses c : DefectClassesFactory.listDefectClassesByCriteria(cc)) { // c.delete(); // } // // transaction.commit(); } }